From 7d6b551cb4baea4981a98c7e890910e9879664d4 Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Wed, 27 Jan 2021 17:17:50 -0700 Subject: [PATCH] Add ability to peer via socks4a (works for tor) --- Rocksolid_Light/rocksolid/newsportal.php | 67 ++++++++++++++++++- Rocksolid_Light/rslight/rslight.inc.php | 2 + Rocksolid_Light/rslight/scripts/send.php | 46 ------------- .../rslight/scripts/setuphelper.php | 2 + Rocksolid_Light/rslight/scripts/spoolnews.php | 46 ------------- 5 files changed, 70 insertions(+), 93 deletions(-) diff --git a/Rocksolid_Light/rocksolid/newsportal.php b/Rocksolid_Light/rocksolid/newsportal.php index bf5d720..7350e11 100644 --- a/Rocksolid_Light/rocksolid/newsportal.php +++ b/Rocksolid_Light/rocksolid/newsportal.php @@ -86,6 +86,72 @@ function nntp_open($nserver=0,$nport=0) { return $ns; } +function nntp2_open($nserver=0,$nport=0) { + global $text_error,$CONFIG; + // echo "
NNTP OPEN
"; + $authorize=((isset($CONFIG['remote_auth_user'])) && (isset($CONFIG['remote_auth_pass'])) && + ($CONFIG['remote_auth_user'] != "")); + if ($nserver==0) $nserver=$CONFIG['remote_server']; + if ($nport==0) $nport=$CONFIG['remote_port']; + if($CONFIG['remote_ssl']) { + $ns=@fsockopen('ssl://'.$nserver.":".$nport); + } else { + if($CONFIG['socks_host'] !== '') { + $ns=fsocks4asockopen($CONFIG['socks_host'], $CONFIG['socks_port'], $nserver, $nport); + } else { + $ns=@fsockopen('tcp://'.$nserver.":".$nport); + } + } +// $ns=@fsockopen($nserver,$nport); + $weg=line_read($ns); // kill the first line + if (substr($weg,0,2) != "20") { + echo "

".$text_error["error:"].$weg."

"; + fclose($ns); + $ns=false; + } else { + if ($ns != false) { + fputs($ns,"MODE reader\r\n"); + $weg=line_read($ns); // and once more + if ((substr($weg,0,2) != "20") && + ((!$authorize) || ((substr($weg,0,3) != "480") && ($authorize)))) { + echo "

".$text_error["error:"].$weg."

"; + fclose($ns); + $ns=false; + } + } + if ((isset($CONFIG['remote_auth_user'])) && (isset($CONFIG['remote_auth_pass'])) && + ($CONFIG['remote_auth_user'] != "")) { + fputs($ns,"AUTHINFO USER ".$CONFIG['remote_auth_user']."\r\n"); + $weg=line_read($ns); + fputs($ns,"AUTHINFO PASS ".$CONFIG['remote_auth_pass']."\r\n"); + $weg=line_read($ns); +/* Only check auth if reading and posting same server */ + if (substr($weg,0,3) != "281" && !(isset($post_server)) && ($post_server!="")) { + echo "

".$text_error["error:"]."

"; + echo "

".$text_error["auth_error"]."

"; + } + } + } + if ($ns==false) echo "

".$text_error["connection_failed"]."

"; + return $ns; +} + +function fsocks4asockopen($proxyHostname, $proxyPort, $targetHostname, $targetPort) +{ + $sock = fsockopen($proxyHostname, $proxyPort); + if($sock === false) + return false; + fwrite($sock, pack("CCnCCCCC", 0x04, 0x01, $targetPort, 0x00, 0x00, 0x00, 0x01, 0x00).$targetHostname.pack("C", 0x00)); + $response = fread($sock, 16); + $values = unpack("xnull/Cret/nport/Nip", $response); + if($values["ret"] == 0x5a) return $sock; + else + { + fclose(sock); + return false; + } +} + /* * Close a NNTP connection * @@ -1279,7 +1345,6 @@ function np_get_db_article($article, $group, $makearray=1, $dbh=null) { file_put_contents($logfile, "\n".format_log_date()." ".$config_name." DEBUG: fetched: ".$article." from ".$group, FILE_APPEND); if($makearray == 1) { $thisarticle = preg_split("/\r\n|\n|\r/", trim($msg2)); - array_pop($thisarticle); return $thisarticle; } else { return trim($msg2); diff --git a/Rocksolid_Light/rslight/rslight.inc.php b/Rocksolid_Light/rslight/rslight.inc.php index df906fa..998af8c 100644 --- a/Rocksolid_Light/rslight/rslight.inc.php +++ b/Rocksolid_Light/rslight/rslight.inc.php @@ -3,6 +3,8 @@ return [ 'remote_server' => 'news.example.com', 'remote_port' => '119', 'remote_ssl' => '', + 'socks_host' => '', + 'socks_port' => '', 'remote_auth_user' => 'username', 'remote_auth_pass' => 'password', 'enable_nntp' => '1', diff --git a/Rocksolid_Light/rslight/scripts/send.php b/Rocksolid_Light/rslight/scripts/send.php index f08488e..b8c611f 100755 --- a/Rocksolid_Light/rslight/scripts/send.php +++ b/Rocksolid_Light/rslight/scripts/send.php @@ -91,50 +91,4 @@ function post_articles($ns, $spooldir) { } return "Messages sent\r\n"; } - -function nntp2_open($nserver=0,$nport=0) { - global $text_error,$CONFIG; - // echo "
NNTP OPEN
"; - $authorize=((isset($CONFIG['remote_auth_user'])) && (isset($CONFIG['remote_auth_pass'])) && - ($CONFIG['remote_auth_user'] != "")); - if ($nserver==0) $nserver=$CONFIG['remote_server']; - if ($nport==0) $nport=$CONFIG['remote_port']; - if($CONFIG['remote_ssl']) { - $ns=@fsockopen('ssl://'.$nserver.":".$nport); - } else { - $ns=@fsockopen('tcp://'.$nserver.":".$nport); - } -// $ns=@fsockopen($nserver,$nport); - $weg=line_read($ns); // kill the first line - if (substr($weg,0,2) != "20") { - echo "

".$text_error["error:"].$weg."

"; - fclose($ns); - $ns=false; - } else { - if ($ns != false) { - fputs($ns,"MODE reader\r\n"); - $weg=line_read($ns); // and once more - if ((substr($weg,0,2) != "20") && - ((!$authorize) || ((substr($weg,0,3) != "480") && ($authorize)))) { - echo "

".$text_error["error:"].$weg."

"; - fclose($ns); - $ns=false; - } - } - if ((isset($CONFIG['remote_auth_user'])) && (isset($CONFIG['remote_auth_pass'])) && - ($CONFIG['remote_auth_user'] != "")) { - fputs($ns,"AUTHINFO USER ".$CONFIG['remote_auth_user']."\r\n"); - $weg=line_read($ns); - fputs($ns,"AUTHINFO PASS ".$CONFIG['remote_auth_pass']."\r\n"); - $weg=line_read($ns); -/* Only check auth if reading and posting same server */ - if (substr($weg,0,3) != "281" && !(isset($post_server)) && ($post_server!="")) { - echo "

".$text_error["error:"]."

"; - echo "

".$text_error["auth_error"]."

"; - } - } - } - if ($ns==false) echo "

".$text_error["connection_failed"]."

"; - return $ns; -} ?> diff --git a/Rocksolid_Light/rslight/scripts/setuphelper.php b/Rocksolid_Light/rslight/scripts/setuphelper.php index f226ef2..c5001b9 100644 --- a/Rocksolid_Light/rslight/scripts/setuphelper.php +++ b/Rocksolid_Light/rslight/scripts/setuphelper.php @@ -11,6 +11,8 @@ return [ 'remote_ssl' => 'Enable if connecting to remote server using ssl (1=true, blank=false)', 'remote_auth_user' => 'Username to authenticate to remote server', 'remote_auth_pass' => 'Password to authenticate to remote server', +'socks_host' => 'ip address of your socks4a server (use this for tor)', +'socks_port' => 'port for your socks4a server', # LOCAL server configuration 'enable_nntp' => 'Enable local nntp server (1=true, blank=false)', diff --git a/Rocksolid_Light/rslight/scripts/spoolnews.php b/Rocksolid_Light/rslight/scripts/spoolnews.php index 3e23e69..0c792f2 100755 --- a/Rocksolid_Light/rslight/scripts/spoolnews.php +++ b/Rocksolid_Light/rslight/scripts/spoolnews.php @@ -417,52 +417,6 @@ function create_spool_groups($in_groups, $out_groups) { return; } -function nntp2_open($nserver=0,$nport=0) { - global $text_error,$CONFIG; - // echo "
NNTP OPEN
"; - $authorize=((isset($CONFIG['remote_auth_user'])) && (isset($CONFIG['remote_auth_pass'])) && - ($CONFIG['remote_auth_user'] != "")); - if ($nserver==0) $nserver=$CONFIG['remote_server']; - if ($nport==0) $nport=$CONFIG['remote_port']; - if($CONFIG['remote_ssl']) { - $ns=@fsockopen('ssl://'.$nserver.":".$nport); - } else { - $ns=@fsockopen('tcp://'.$nserver.":".$nport); - } -// $ns=@fsockopen($nserver,$nport); - $weg=line_read($ns); // kill the first line - if (substr($weg,0,2) != "20") { - echo "

".$text_error["error:"].$weg."

"; - fclose($ns); - $ns=false; - } else { - if ($ns != false) { - fputs($ns,"MODE reader\r\n"); - $weg=line_read($ns); // and once more - if ((substr($weg,0,2) != "20") && - ((!$authorize) || ((substr($weg,0,3) != "480") && ($authorize)))) { - echo "

".$text_error["error:"].$weg."

"; - fclose($ns); - $ns=false; - } - } - if ((isset($CONFIG['remote_auth_user'])) && (isset($CONFIG['remote_auth_pass'])) && - ($CONFIG['remote_auth_user'] != "")) { - fputs($ns,"AUTHINFO USER ".$CONFIG['remote_auth_user']."\r\n"); - $weg=line_read($ns); - fputs($ns,"AUTHINFO PASS ".$CONFIG['remote_auth_pass']."\r\n"); - $weg=line_read($ns); -/* Only check auth if reading and posting same server */ - if (substr($weg,0,3) != "281" && !(isset($post_server)) && ($post_server!="")) { - echo "

".$text_error["error:"]."

"; - echo "

".$text_error["auth_error"]."

"; - } - } - } - if ($ns==false) echo "

".$text_error["connection_failed"]."

"; - return $ns; -} - function get_high_watermark($group) { global $local_groupfile;