HTTP Gateway
* Version: 0.6.x
* Download: https://news.novabbs.com/getrslight
*
* Based on Newsportal by Florian Amrhein
*
* E-Mail: retroguy@novabbs.com
* Web: https://news.novabbs.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if(file_exists("lib/types.inc.php"))
include "lib/types.inc.php";
if(file_exists("lib/thread.inc.php"))
include "lib/thread.inc.php";
if(file_exists("lib/message.inc.php"))
include "lib/message.inc.php";
if(file_exists("lib/post.inc.php"))
include "lib/post.inc.php";
$CONFIG = include($config_file);
/*
* opens the connection to the NNTP-Server
*
* $server: adress of the NNTP-Server
* $port: port of the server
*/
function nntp_open($nserver=0,$nport=0) {
global $text_error,$CONFIG;
global $server,$port;
// echo "
NNTP OPEN
";
if(!isset($CONFIG['enable_nntp']) || $CONFIG['enable_nntp'] != true) {
$CONFIG['server_auth_user'] = $CONFIG['remote_auth_user'];
$CONFIG['server_auth_pass'] = $CONFIG['remote_auth_pass'];
}
$authorize=((isset($CONFIG['server_auth_user'])) && (isset($CONFIG['server_auth_pass'])) &&
($CONFIG['server_auth_user'] != ""));
if ($nserver==0) $nserver=$server;
if ($nport==0) $nport=$port;
$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['server_auth_user'])) && (isset($CONFIG['server_auth_pass'])) && ($CONFIG['server_auth_user'] != "")) { fputs($ns,"AUTHINFO USER ".$CONFIG['server_auth_user']."\r\n"); $weg=line_read($ns); fputs($ns,"AUTHINFO PASS ".$CONFIG['server_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 nntp2_open($nserver=0,$nport=0) { global $text_error,$CONFIG; // 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 * * $ns: the handle of the connection */ function nntp_close(&$ns) { if ($ns != false) { fputs($ns,"QUIT\r\n"); fclose($ns); } } /* * Validates an email adress * * $address: a string containing the email-address to be validated * * returns true if the address passes the tests, false otherwise. */ function validate_email($address) { global $validate_email; $return=true; if (($validate_email >= 1) && ($return == true)) /* Need to clean up this regex to work properly with preg_match $return = (preg_match('^[-!#$%&\'*+\\./0-9=?A-Z^_A-z{|}~]+'.'@'. '[-!#$%&\'*+\\/0-9=?A-Z^_A-z{|}~]+\.'. '[-!#$%&\'*+\\./0-9=?A-Z^_A-z{|}~]+$',$address)); */ $return = 1; if (($validate_email >= 2) && ($return == true)) { $addressarray=address_decode($address,"garantiertungueltig"); $return=checkdnsrr($addressarray[0]["host"],"MX"); if (!$return) $return=checkdnsrr($addressarray[0]["host"],"A"); } return($return); } /* * decodes a block of 7bit-data in uuencoded format to it's original * 8bit format. * The headerline containing filename and permissions doesn't have to * be included. * * $data: The uuencoded data as a string * * returns the 8bit data as a string * * Note: this function is very slow and doesn't recognize incorrect code. */ function uudecode_line($line) { $data=substr($line,1); $length=ord($line[0])-32; $decoded=""; for ($i=0; $i<(strlen($data)>>2); $i++) { $pack=substr($data,$i<<2,4); $upack=""; $bitmaske=0; for ($o=0; $o<4; $o++) { $g=((ord($pack[3-$o])-32)); if ($g==64) $g=0; $bitmaske=$bitmaske | ($g << (6*$o)); } $schablone=255; for ($o=0; $o<3; $o++) { $c=($bitmaske & $schablone) >> ($o << 3); $schablone=($schablone << 8); $upack=chr($c).$upack; } $decoded.=$upack; } $decoded=substr($decoded,0,$length); return $decoded; } /* * decodes uuencoded Attachments. * * $data: the encoded data * * returns the decoded data */ function uudecode($data) { $d=explode("\n",$data); $u=""; for ($i=0; $i'; echo 'Latest | Newsgroup | Messages | Last Message | |
'; echo ''; if(is_file("../common/mods/images/latest.png")) { echo ''; } else { echo ''; } echo ''; echo ' | '; echo '';
echo '';
echo 'name).'">'.group_display_name($g->name)."\n";
if($g->description!="-")
echo ' '.$g->description.' '; /* Display article count */ echo ' | '; if($gl_age) $datecolor=thread_format_date_color($g->age); echo ''; if($datecolor!="") echo ''.$g->count.''; else echo $g->count; echo ''; /* Display latest article info */ echo ' | ';
$filename = $spooldir."/".$g->name."-lastarticleinfo.dat";
if($file=@fopen($filename,"r")) {
$lastarticleinfo=unserialize(fread($file,filesize($filename)));
fclose($file);
} else {
$lastarticleinfo->date = 0;
}
if((isset($spoolnews)) && ($spoolnews === true)) {
$ovfp=popen($CONFIG['tac'].' '.$spooldir.'/'.$g->name.'-overview', 'r');
$lastpost=fgets($ovfp);
pclose($ovfp);
$lastdata = explode("\t", $lastpost);
echo get_date_interval(date("D, j M Y H:i T",strtotime($lastdata[3])));
$fromline=address_decode(headerDecode($lastdata[2]),"nirgendwo");
if (!isset($fromline[0]["personal"])) {
$lastname=$fromline[0]["mailbox"];;
} else {
$lastname=$fromline[0]["personal"];
}
} else {
echo get_date_interval(date("D, j M Y H:i T",$lastarticleinfo->date));
$lastarticleinfo->name = ltrim($lastarticleinfo->name, "<");
$lastname = $lastarticleinfo->name;
}
echo '
|
-".base64_decode($value)."-
"; break; case "x-no-archive:": $header->xnoarchive=strtolower(trim($value)); } } if (!isset($header->content_type[0])) $header->content_type[0]="text/plain"; if (!isset($header->content_transfer_encoding)) $header->content_transfer_encoding="8bit"; if ($number != "") $header->number=$number; return $header; } /* * convert the charset of a text */ function recode_charset($text,$source=false,$dest=false) { global $iconv_enable,$www_charset; if($dest==false) $dest=$www_charset; if(($iconv_enable) && ($source!=false)) { $return=iconv($source, $dest."//TRANSLIT",$text); if($return!="") return $return; else return $text; } else { return $text; } } function decode_body($body,$encoding) { $bodyzeile=""; switch ($encoding) { case "base64": $body=base64_decode($body); break; case "quoted-printable": $body=Quoted_printable_decode($body); $body=str_replace("=\n","",$body); // default: // $body=str_replace("\n..\n","\n.\n",$body); } return $body; } /* * makes URLs clickable * * $text: A text-line probably containing links. * * the function returns the text-line with HTML-Links to the links or * email-adresses. */ function html_parse($text) { global $frame_externallink; if ((isset($frame_externallink)) && ($frame_externallink != "")) { $target=' TARGET="'.$frame_externallink.'" '; } else { $target=' '; } // regular expressions that will be applied to every word in the text $regexp_replace=array( 'http://((\.*([-a-z0-9_/~@?=%#;+]|&)+)+)' => 'http://\1', '(www\.[-a-z]+\.(de|pl|cz|sk|tk|tv|cc|cx|biz|us|uk|info|int|eu|dk|org|net|at|ch|com))' => '\1', 'https://([-a-z0-9_./~@?=%#&;\n]+)' => 'https://\1', 'gopher://([-a-z0-9_./~@?=%\n]+)' => 'gopher://\1', 'news://([-a-z0-9_./~@?=%\n]+)' => 'news://\1', 'ftp://([-a-z0-9_./~@?=%\n]+)' => 'ftp://\1', //'([-a-z0-9_./n]+)@([-a-z0-9_.]+)' => // $_SESSION["loggedin"]!==true ? '(e-Mail)' : // '\1@\2' ); $ntext=""; // split every line into it's words $words=explode(" ",$text); $n=count($words); for($i=0; $i<$n; $i++) { $word=$words[$i]; // test, if we need the slow walk through all the regular expressions if(preg_match('/www|\:|@/i',$word)) { // apply the regular expressions to the word until a matching // expression is found foreach ($regexp_replace as $key => $value) { $nword=preg_replace('/{$key}/i',$value,$word); if($nword!=$word) { $word=$nword; break; } } } // add the spaces between the words if($i>0) $ntext.=" "; $ntext.=$word; } return($ntext); } /* * read the header of an article in plaintext into an array * $articleNumber can be the number of an article or its message-id. */ function readPlainHeader(&$ns,$group,$articleNumber) { fputs($ns,"GROUP $group\r\n"); $line=line_read($ns); fputs($ns,"HEAD $articleNumber\r\n"); $line=line_read($ns); if (substr($line,0,3) != "221") { echo $text_error["article_not_found"]; $header=false; } else { $line=line_read($ns); $body=""; while(strcmp(trim($line),".") != 0) { $body .= $line."\n"; $line=line_read($ns); } return explode("\n",str_replace("\r\n","\n",$body)); } } /* * cancel an article on the newsserver * * DO NOT USE THIS FUNCTION, IF YOU DON'T KNOW WHAT YOU ARE DOING! * * $ns: The handler of the NNTP-Connection * $group: The group of the article * $id: the Number of the article inside the group or the message-id */ function message_cancel($subject,$from,$newsgroups,$ref,$body,$id) { global $server,$port,$send_poster_host,$CONFIG,$text_error; global $www_charset; flush(); $ns=nntp_open($server,$port); if ($ns != false) { fputs($ns,"POST\r\n"); $weg=line_read($ns); fputs($ns,'Subject: '.quoted_printable_encode($subject)."\r\n"); fputs($ns,'From: '.$from."\r\n"); fputs($ns,'Newsgroups: '.$newsgroups."\r\n"); fputs($ns,"Mime-Version: 1.0\r\n"); fputs($ns,"Content-Type: text/plain; charset=".$www_charset."\r\n"); fputs($ns,"Content-Transfer-Encoding: 8bit\r\n"); if ($send_poster_host) fputs($ns,'X-HTTP-Posting-Host: '.gethostbyaddr(getenv("REMOTE_ADDR"))."\r\n"); if ($ref!=false) fputs($ns,'References: '.$ref."\r\n"); if (isset($CONFIG['organization'])) fputs($ns,'Organization: '.quoted_printable_encode($CONFIG['organization'])."\r\n"); fputs($ns,"Control: cancel ".$id."\r\n"); $body=str_replace("\n.\r","\n..\r",$body); $body=str_replace("\r",'',$body); $b=explode("\n",$body); $body=""; for ($i=0; $i