HTTP Gateway
* 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 | |
'; $groupdisplay.=''; if (file_exists('../common/themes/'.$_SESSION['theme'].'/images/latest.png')) { $latest_image='../common/themes/'.$_SESSION['theme'].'/images/latest.png'; } else { $latest_image='../common/images/latest.png'; } $groupdisplay.=''; $groupdisplay.=''; $groupdisplay.=' | '; $groupdisplay.='';
$groupdisplay.='';
$groupdisplay.='name).'">'.group_display_name($g->name)."\n";
if($g->description!="-")
$groupdisplay.=' '.$g->description.' '; // Subscribed features $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($userdata[$g->name])) { $groupdisplay.=''; $groupdisplay.='(unsubscribe)'; if($userdata[$g->name] < $lastarticleinfo->date) { $groupdisplay.='(new) '; } $groupdisplay.=' | '; if($gl_age) $datecolor=thread_format_date_color($g->age); $groupdisplay.=''; if($datecolor!="") $groupdisplay.=''.$g->count.''; else $groupdisplay.=$g->count; $groupdisplay.=''; /* Display latest article info */ $groupdisplay.=' | ';
// Handle newsportal errors in lastarticleinfo.dat
if($lastarticleinfo->date == 0) {
$database = $spooldir.'/articles-overview.db3';
$table = 'overview';
$articles_dbh = rslight_db_open($database);
$articles_query = $articles_dbh->prepare('SELECT * FROM overview WHERE newsgroup=:group ORDER BY date DESC LIMIT 2');
$articles_query->execute(['group' => $g->name]);
$found = 0;
while ($row = $articles_query->fetch()) {
$found = 1;
break;
}
$dbh = null;
if($found) {
$lastarticleinfo->date = $row['date'];
// Put this in a function already!
$fromoutput = explode("<", html_entity_decode($row['name']));
// Just an email address?
if(strlen($fromoutput[0]) < 2) {
preg_match("/\<([^\)]*)\@/", html_entity_decode($row['name']), $fromaddress);
$fromoutput[0] = $fromaddress[1];
}
if(strpos($fromoutput[0], "(")) {
preg_match("/\(([^\)]*)\)/", html_entity_decode($row['name']), $fromaddress);
$fromoutput[0] = $fromaddress[1];
}
if((isset($CONFIG['hide_email']) && $CONFIG['hide_email'] == true) && (strpos($fromoutput[0], '@') !== false)) {
$lastarticleinfo->name = truncate_email($fromoutput[0]);
} else {
$lastarticleinfo->name = $fromoutput[0];
}
}
}
$groupdisplay.=get_date_interval(date("D, j M Y H:i T",$lastarticleinfo->date));
$groupdisplay.='
|
-".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=' '; } $ntext=""; // split every line into it's words $words=explode(" ",$text); $n=count($words); $is_link = 0; for($i=0; $i<$n; $i++) { $word=$words[$i]; if(preg_match('/(https?|ftp|news|gopher|telnet)\:\/\/[^\",]+/i', $word)) { $is_link = 1; $nlink = trim($word, '().,'); $nlink = preg_replace('/(\<|\>|\ );/', '', $nlink); $nlink = preg_replace('/\[url=/', '', $nlink); $bbnlink = explode(']', $nlink); $nlink = $bbnlink[0]; $nword = ''.$nlink.''; if(isset($bbnlink[1])) { $nword.=' '.$bbnlink[1]; } if($nword!=$word && substr($nlink, strlen($nlink) - 3) != "://") { $word=$nword; } } // add the spaces between the words if($i>0) $ntext.=" "; if($is_link) { $word = preg_replace('/\[\/url\]/', '', $word); } $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