diff --git a/Rocksolid_Light/rocksolid/article-flat.php b/Rocksolid_Light/rocksolid/article-flat.php index 2b302b7..2ab9c78 100644 --- a/Rocksolid_Light/rocksolid/article-flat.php +++ b/Rocksolid_Light/rocksolid/article-flat.php @@ -1,79 +1,82 @@ prepare('SELECT * FROM overview WHERE msgid=:messageid'); - $articles_query->execute(['messageid' => $id]); - $found = 0; - while ($row = $articles_query->fetch()) { - $id = $row['number']; - $group = $row['newsgroup']; - $found = 1; - break; - } - $dbh = null; - if($found) { - $newurl = 'article-flat.php?id='.$id.'&group='.$group.'#'.$id; - header("Location: $newurl"); - die(); - } + $link = "https"; + else + $link = "http"; + $link .= "://"; + $link .= $_SERVER['HTTP_HOST']; + $link .= $_SERVER['REQUEST_URI']; + $newurl = preg_replace("|/$config_name/|", "/$findsection/", $link); + header("Location:$newurl"); + die(); +} +if (strpos($id, '@') !== false) { + if ($CONFIG['article_database'] == '1') { + $database = $spooldir . '/articles-overview.db3'; + $articles_dbh = overview_db_open($database); + $articles_query = $articles_dbh->prepare('SELECT * FROM overview WHERE msgid=:messageid'); + $articles_query->execute([ + 'messageid' => $id + ]); + $found = 0; + while ($row = $articles_query->fetch()) { + $id = $row['number']; + $group = $row['newsgroup']; + $found = 1; + break; + } + $dbh = null; + if ($found) { + $newurl = 'article-flat.php?id=' . $id . '&group=' . $group . '#' . $id; + header("Location: $newurl"); + die(); + } } - } +} - if(isset($_REQUEST["first"])) - $first=$_REQUEST["first"]; +if (isset($_REQUEST["first"])) + $first = $_REQUEST["first"]; - $_SESSION['rsactive'] = true; +$_SESSION['rsactive'] = true; - if(!isset($_SERVER['REQUEST_STRING'])) { - $_SERVER['REQUEST_STRING'] = ''; - } - $location = $_SERVER['REQUEST_URI'].$_SERVER['REQUEST_STRING']; - $_SESSION['return_page'] = $location.'#'.$id; +if (! isset($_SERVER['REQUEST_STRING'])) { + $_SERVER['REQUEST_STRING'] = ''; +} +$location = $_SERVER['REQUEST_URI'] . $_SERVER['REQUEST_STRING']; +$_SESSION['return_page'] = $location . '#' . $id; -// file_put_contents($accessfile, "\n".format_log_date()." ".$config_name." ".$group.":".$id, FILE_APPEND); - if($userdata) { +// file_put_contents($accessfile, "\n".format_log_date()." ".$config_name." ".$group.":".$id, FILE_APPEND); +if ($userdata) { $userdata[$group] = time(); file_put_contents($userfile, serialize($userdata)); - } - -if(isset($frames_on) && $frames_on === true) { -?> +} + +if (isset($frames_on) && $frames_on === true) { + ?> '.basename(getcwd()).''; +echo '
'; - echo ''; echo ' | '; - } else { -// echo htmlspecialchars($CONFIG['title_full']); - } +} else { + // echo htmlspecialchars($CONFIG['title_full']); +} // Search button - echo ''; - echo ''; - echo ' | '; - echo '
' . $text_error["error:"] . " " . $text_error["connection_failed"] . '.
'; - echo 'Please wait a few moments and try again. If you see the same error, notify the owner that their Message Server is offline.
'; - echo '' . $text_error["error:"] . " " . $text_error["connection_failed"] . '.
'; + echo 'Please wait a few moments and try again. If you see the same error, notify the owner that their Message Server is offline.
'; + 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."
"; + $weg = line_read($ns); // kill the first line + if (substr($weg, 0, 2) != "20") { + echo "" . $text_error["error:"] . $weg . "
"; fclose($ns); - $ns=false; - } + $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 */ + // NNTP Response NOT 281 (Authorization failed) + if (substr($weg, 0, 3) != "281" && ! (isset($post_server)) && ($post_server != "")) { + echo "" . $text_error["error:"] . "
"; + echo "" . $text_error["auth_error"] . "
"; + } + } } - 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 */ - // NNTP Response NOT 281 (Authorization failed) - 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; + 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."
"; - if($ns) { - fclose($ns); + // $ns=@fsockopen($nserver,$nport); + $weg = line_read($ns); // kill the first line + if (substr($weg, 0, 2) != "20") { + echo "" . $text_error["error:"] . $weg . "
"; + if ($ns) { + 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"] . "
"; + } + } } - $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; + if ($ns == false) + echo "" . $text_error["connection_failed"] . "
"; + return $ns; } function fsocks4asockopen($proxyHostname, $proxyPort, $targetHostname, $targetPort) { $sock = fsockopen($proxyHostname, $proxyPort); - if($sock === false) + if ($sock === false) return false; - fwrite($sock, pack("CCnCCCCC", 0x04, 0x01, $targetPort, 0x00, 0x00, 0x00, 0x01, 0x00).$targetHostname.pack("C", 0x00)); + 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 - { + if ($values["ret"] == 0x5a) + return $sock; + else { fclose($sock); return false; } @@ -177,11 +178,12 @@ function fsocks4asockopen($proxyHostname, $proxyPort, $targetHostname, $targetPo * * $ns: the handle of the connection */ -function nntp_close(&$ns) { - if ($ns != false) { - fputs($ns,"QUIT\r\n"); - fclose($ns); - } +function nntp_close(&$ns) +{ + if ($ns != false) { + fputs($ns, "QUIT\r\n"); + fclose($ns); + } } /* @@ -193,21 +195,22 @@ function nntp_close(&$ns) { */ function validate_email($address) { - global $validate_email; - $return=true; - if (($validate_email >= 1) && ($return == true)) + 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); + 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); } /* @@ -215,36 +218,38 @@ function validate_email($address) * 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)); +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; } - $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; + $decoded = substr($decoded, 0, $length); + return $decoded; } /* @@ -254,12 +259,13 @@ function uudecode_line($line) { * * 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(is_file($filename)) { - $lastarticleinfo = unserialize(file_get_contents($filename)); - } else { - $lastarticleinfo['date'] = 0; - } - - // Look up last article info for group (np does not write this file sometimes for some reason) - $database = $spooldir.'/articles-overview.db3'; - $table = 'overview'; - $articles_dbh = overview_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; - } - $articles_dbh = null; - if($found == 1) { - $lastarticleinfo['date'] = $row['date']; - } - if(isset($userdata[$g->name])) { - $groupdisplay.=''; - $groupdisplay.='(unsubscribe)'; -// TESTING HERE -/* - file_put_contents($logfile, "\n".format_log_date()." ".$config_name." ".$g->name." is subscribed for ".$_COOKIE['mail_name'], FILE_APPEND); - file_put_contents($logfile, "\n".format_log_date()." ".$config_name." userdata=".$userdata[$g->name]." lastarticleinfo=".$lastarticleinfo['date'], FILE_APPEND); - file_put_contents($logfile, "\n".format_log_date()." ".$config_name." ".$g->name." ".($userdata[$g->name] - $lastarticleinfo['date']), FILE_APPEND); -*/ - 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.=' | ';
-
- if($found == 1) {
-// $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];
+function groups_show($gruppen)
+{
+ global $gl_age, $frame, $spooldir, $logdir, $CONFIG, $spoolnews;
+ if ($gruppen == false)
+ return;
+ global $file_thread, $text_groups;
+ $logfile = $logdir . '/debug.log';
+ write_access_log();
+ $c = count($gruppen);
+ $acttype = "keins";
+ 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; +function parse_header($hdr, $number = "") +{ + for ($i = count($hdr) - 1; $i > 0; $i --) + if (preg_match("/^(\x09|\x20)/", $hdr[$i])) + $hdr[$i - 1] = $hdr[$i - 1] . " " . ltrim($hdr[$i]); + $header = new headerType(); + $header->isAnswer = false; + for ($count = 0; $count < count($hdr); $count ++) { + $variable = substr($hdr[$count], 0, strpos($hdr[$count], " ")); + $value = trim(substr($hdr[$count], strpos($hdr[$count], " ") + 1)); + switch (strtolower($variable)) { + case "from:": + $fromline = address_decode(headerDecode($value), "nowhere"); + if (! isset($fromline[0]["host"])) + $fromline[0]["host"] = ""; + $header->from = $fromline[0]["mailbox"] . "@" . $fromline[0]["host"]; + $header->username = $fromline[0]["mailbox"]; + if (! isset($fromline[0]["personal"])) { + $header->name = ""; + } else { + $header->name = $fromline[0]["personal"]; + } + break; + case "message-id:": + $header->id = $value; + break; + case "subject:": + $header->subject = headerDecode($value); + break; + case "newsgroups:": + $header->newsgroups = $value; + break; + case "organization:": + $header->organization = headerDecode($value); + break; + case "content-transfer-encoding:": + $header->content_transfer_encoding = trim(strtolower($value)); + break; + case "content-type:": + $header->content_type = array(); + $subheader = explode(";", $value); + $header->content_type[0] = strtolower(trim($subheader[0])); + for ($i = 1; $i < count($subheader); $i ++) { + $gleichpos = strpos($subheader[$i], "="); + if ($gleichpos) { + $subvariable = trim(substr($subheader[$i], 0, $gleichpos)); + $subvalue = trim(substr($subheader[$i], $gleichpos + 1)); + if (($subvalue[0] == '"') && ($subvalue[strlen($subvalue) - 1] == '"')) + $subvalue = substr($subvalue, 1, strlen($subvalue) - 2); + switch ($subvariable) { + case "charset": + $header->content_type_charset = array( + strtolower($subvalue) + ); + break; + case "name": + $header->content_type_name = array( + $subvalue + ); + break; + case "boundary": + $header->content_type_boundary = $subvalue; + break; + case "format": + $header->content_type_format = array( + $subvalue + ); + } + } + } + break; + case "references:": + $ref = trim($value); + while (strpos($ref, "> <") != false) { + $header->references[] = substr($ref, 0, strpos($ref, " ")); + $ref = substr($ref, strpos($ref, "> <") + 2); + } + $header->references[] = trim($ref); + break; + case "date:": + $header->date = getTimestamp(trim($value)); + break; + case "followup-to:": + $header->followup = trim($value); + break; + case "x-newsreader:": + case "x-mailer:": + case "x-rslight-to:": + $header->rslight_to = trim($value); + break; + case "x-rslight-site:": + $header->rslight_site = trim($value); + break; + case "user-agent:": + $header->user_agent = trim($value); + break; + case "x-face:": // not ready + // 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 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); - } +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; + return $body; } /* @@ -959,68 +993,69 @@ function decode_body($body,$encoding) { * 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; - } +function html_parse($text) +{ + global $frame_externallink; + if ((isset($frame_externallink)) && ($frame_externallink != "")) { + $target = ' TARGET="' . $frame_externallink . '" '; + } else { + $target = ' '; } - // add the spaces between the words - if($i>0) - $ntext.=" "; - if($is_link) { - $word = preg_replace('/\[\/url\]/', '', $word); + $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; } - $ntext.=$word; - } - return($ntext); + 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); +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)); } - return explode("\n",str_replace("\r\n","\n",$body)); - } } /* @@ -1032,405 +1067,423 @@ function readPlainHeader(&$ns,$group,$articleNumber) { * $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'; - echo ''; - echo ' | '; - } - if (!$CONFIG['readonly'] && - (!function_exists("npreg_group_has_write_access") || - npreg_group_has_write_access($group))) - { -// New Thread button - echo ''; - echo ''; - echo ' | '; - } -// Search button - echo ''; - echo ''; - echo ' | '; -// Newsgroups button (hidden) - if(isset($frames_on) && $frames_on === true) { - echo ''; - echo ''; - echo ' | '; - } -// $ns=nntp_open($server,$port); - flush(); - $headers = thread_load($group); - if($headers) { - $article_count=count($headers); - } - if ($articles_per_page != 0) { - if ((!isset($first)) || (!isset($last))) { - if ($startpage=="first") { - $first=1; - $last=$articles_per_page; - } else { - $first=$article_count - (($article_count -1) % $articles_per_page); - $last=$article_count; - } +'; - // Show the replies to an article in the thread view? - if($thread_show["replies"]) { - // yes, so the counting of the shown articles is very easy - $pagecount=count($headers); - } else { - // oh no, the replies will not be shown, this makes life hard... - $pagecount=0; - if(($headers) && (count($headers) > 0 && is_array($headers))) { - foreach($headers as $h) { - if($h->isAnswer==false) - $pagecount++; + if ($userdata) { + $userdata[$group] = time(); + file_put_contents($userfile, serialize($userdata)); + } + if (! isset($_SERVER['REQUEST_STRING'])) { + $_SERVER['REQUEST_STRING'] = ''; + } + $_SESSION['return_page'] = $_SERVER['REQUEST_URI'] . $_SERVER['REQUEST_STRING']; + + echo ''; + echo '
'; + echo ''; + echo ' | '; + } + if (! $CONFIG['readonly'] && (! function_exists("npreg_group_has_write_access") || npreg_group_has_write_access($group))) { + // New Thread button + echo ''; + echo ''; + echo ' | '; + } + // Search button + echo ''; + echo ''; + echo ' | '; + // Newsgroups button (hidden) + if (isset($frames_on) && $frames_on === true) { + echo ''; + echo ''; + echo ' | '; + } + // $ns=nntp_open($server,$port); + flush(); + $headers = thread_load($group); + if ($headers) { + $article_count = count($headers); + } + if ($articles_per_page != 0) { + if ((! isset($first)) || (! isset($last))) { + if ($startpage == "first") { + $first = 1; + $last = $articles_per_page; + } else { + $first = $article_count - (($article_count - 1) % $articles_per_page); + $last = $article_count; + } } - } + echo ''; + // Show the replies to an article in the thread view? + if ($thread_show["replies"]) { + // yes, so the counting of the shown articles is very easy + $pagecount = count($headers); + } else { + // oh no, the replies will not be shown, this makes life hard... + $pagecount = 0; + if (($headers) && (count($headers) > 0 && is_array($headers))) { + foreach ($headers as $h) { + if ($h->isAnswer == false) + $pagecount ++; + } + } + } + + thread_pageselect($group, $pagecount, $first); + echo ' | '; + } else { + $first = 0; + $last = $article_count; } - - thread_pageselect($group,$pagecount,$first); - echo ''; - } else { - $first=0; - $last=$article_count; - } - echo '
'; - thread_pageselect($group,$pagecount,$first); - echo ' |
'; + thread_pageselect($group, $pagecount, $first); + echo ' |
'; - echo ''; - echo ' | '; +echo ''; +echo ''; +echo ' | '; // Upload button - echo ''; - echo ''; - echo ' | '; - echo '
Filename | File Type | Date |
Filename | File Type | Date |
'; + echo ''; + echo ' | '; + echo '' . $mime . ' | '; + echo '' . $newdate . ' | '; + echo '
'; - echo ''; - echo ' | '; - echo ''.$mime.' | '; - echo ''.$newdate.' | '; - echo '
'; - echo ''; - echo ' | '; - } -// Delete Message button - if(isset($_POST['command']) && $_POST['command'] == 'Message') { - echo ''; - echo ''; - echo ' | '; - } - echo '
Subject | From | To | Date | |||||||||
'; - } else { - echo ' | ||||||||||||
';
- }
- $button_link = 'np_mail_button_link';;
- if(($row['mail_from'] == $user) && ($row['mail_viewed'] == 'true')) {
- $button_link = 'np_mail_button_read';
- } elseif(($row['rcpt_to'] == $user) && ($row['rcpt_viewed'] == 'true')) {
- $button_link = 'np_mail_button_read';
}
-// Use local timezone if possible
- $ts = new DateTime(date("D, j M Y H:i T", $row["date"]), new DateTimeZone('UTC'));
- $ts->add(DateInterval::createFromDateString($offset.' minutes'));
-
- if($offset != 0) {
- $newdate = $ts->format('D, j M Y H:i');
+}
+if ($logged_in !== true) {
+ echo ' '; + echo ' ';
+ echo 'Subject: ' . $row['subject'] . ' ';
+
+ echo ''; + echo 'From: ' . $row['mail_from'] . ' '; + echo 'To: ' . $row['rcpt_to'] . ' '; + echo 'Date: ' . $newdate . ' '; + echo ' ';
+ echo $body;
+ echo '';
+ echo ' ';
+ if ($row['mail_from'] == $user) {
+ $sql_update = $dbh->prepare('UPDATE messages SET mail_viewed=? WHERE msgid=?');
+ $sql_update->execute(array(
+ 'true',
+ $row['msgid']
+ ));
+ }
+ if ($row['rcpt_to'] == $user) {
+ $sql_update = $dbh->prepare('UPDATE messages SET rcpt_viewed=? WHERE msgid=?');
+ $sql_update->execute(array(
+ 'true',
+ $row['msgid']
+ ));
+ }
+ }
+ $dbh = null;
+}
+if (isset($_POST['sendMessage'])) {
+ if (isset($_POST['to']) && $_POST['to'] != '' && isset($_POST['from']) && $_POST['from'] != '' && isset($_POST['message']) && $_POST['message'] != '') {
+ if (($to = get_config_value('aliases.conf', strtolower($_POST['to']))) == false) {
+ $to = strtolower($_POST['to']);
+ }
+ $userlist = scandir($config_dir . '/users/');
+ $found = 0;
+ foreach ($userlist as $user) {
+ if (trim($to) == trim($user)) {
+ $found = 1;
+ }
+ }
+ // Check if target is remote. If user enters @ our own domain, strip it (it's local)
+ $remote_target = 0;
+ if (strpos($to, '@') !== false) {
+ $info = preg_split('/@/', $to, 2);
+ if ($info[1] == $rslight_gpg['domain_name']) { // domain is our domain
+ $to = $info[0];
+ foreach ($userlist as $user) {
+ if (($to = get_config_value('aliases.conf', strtolower($info[0]))) == false) {
+ $to = strtolower($info[0]);
+ }
+ if (trim($to) == trim($user)) {
+ $found = 1;
+ }
+ }
+ } else { // domain is remote
+ $found = 1;
+ $remote_target = 1;
+ }
+ }
+ if ($found == 0) {
+ echo 'User not found: ' . $to;
+ } else {
+ $database = $spooldir . '/mail.db3';
+ $dbh = mail_db_open($database);
+ $from = $_POST['from'];
+ $subject = $_POST['subject'];
+ $message = $_POST['message'];
+ $date = time();
+ $message = $_POST['message'];
+ $msgid = '<' . md5(strtolower($to) . strtolower($from) . strtolower($subject) . strtolower($message)) . '>';
+ $sql = 'INSERT OR IGNORE INTO messages(msgid, mail_from, rcpt_to, rcpt_target, date, subject, message, from_hide, to_hide, mail_viewed, rcpt_viewed) VALUES(?,?,?,?,?,?,?,?,?,?,?)';
+ $stmt = $dbh->prepare($sql);
+ // For possible future use ($target is currently unused)
+ $target = "local";
+ $mail_viewed = "true";
+ $rcpt_viewed = null;
+ // $remote_target is handled here
+ if ($q = $stmt->execute([
+ $msgid,
+ $from,
+ $to,
+ $target,
+ $date,
+ $subject,
+ $message,
+ null,
+ null,
+ $mail_viewed,
+ $rcpt_viewed
+ ])) {
+ if ($remote_target == 1) {
+ $remote_result = send_external_mail($from, $to, $date, $subject, $message);
+ if ($remote_result == true) {
+ $return_val = "Message sent.";
+ } else {
+ $return_val = "Failed to Send. No Key for Destination";
+ }
+ }
+ $return_val = "Message sent.";
+ } else {
+ $return_val = "Failed to Send. Database Error";
+ }
+ // Act on return values for response to user
+ echo $return_val;
+ $dbh = null;
+ $user = $from;
+ }
+ }
+}
+if (isset($_POST['command']) && $_POST['command'] == 'Send') {
+ if (isset($_POST['id'])) {
+ $database = $spooldir . '/mail.db3';
+ $dbh = mail_db_open($database);
+ $query = $dbh->prepare('SELECT * FROM messages where id=:id');
+ $query->execute([
+ 'id' => $_POST['id']
+ ]);
+ while (($row = $query->fetch()) !== false) {
+ $mail_to = $row['mail_from'];
+ if (strpos($row['subject'], 'Re: ') !== 0) {
+ $subject = 'Re: ' . $row['subject'];
+ } else {
+ $subject = $row['subject'];
+ }
+ $body = explode("\n", $row['message']);
+ $message = $row['mail_from'] . " wrote:\n\n";
+ foreach ($body as $line) {
+ if (trim($line) !== '') {
+ $line = '>' . $line;
+ }
+ $message .= $line;
+ }
+ }
+ $dbh = null;
+ }
+ echo 'Send Message:'; + echo "'; +} +// Show My Messages +$database = $spooldir . '/mail.db3'; +$dbh = mail_db_open($database); +echo 'My Messages:'; +echo '
'; - include "tail.inc"; - - function send_external_mail($sender, $recipient, $date, $subject, $message) { - global $rslight_gpg, $config_name, $spooldir, $rslight_version; - putenv("GNUPGHOME=".$rslight_gpg['gnupghome']); - $res = gnupg_init(); - - // Get target domain (then get key if necessary) - $info = preg_split('/@/', $recipient, 2); - $target['domain'] = $info[1]; - if(gnupg_keyinfo($res, "rslight@".$target['domain']) == false) { // We don't have the key - $retrieve = retrieve_key($res, $target['domain']); - if($retrieve == false) { // We can't get the key - return false; - } - } - $cwd = getcwd(); - $keydir = preg_replace('/spoolnews/','pubkey/',$cwd); - $key_location = "/pubkey/server_pubkey.txt"; - $signing_key = trim(file_get_contents($keydir.'/server_fingerprint.txt')); - $fingerprint_clean = preg_replace('/\ /', '', $signing_key); - gnupg_addsignkey($res,$fingerprint_clean); - gnupg_adddecryptkey($res,$fingerprint_clean, ''); - - $keyinfo = gnupg_keyinfo($res, "rslight@".$target['domain']); - $target['fingerprint'] = $keyinfo[0]['subkeys'][0]['fingerprint']; - $encrypt_to_key = $target['fingerprint']; - gnupg_addencryptkey($res,$encrypt_to_key); - - $mydate = gmdate("D, d M Y H:i:s \U\T\C",$date); - - $outgoing_dir = $spooldir.'/'.$config_name.'/outgoing'; - if(!is_dir($outgoing_dir)) { - mkdir($outgoing_dir, 0700, true); - } - $domain = $rslight_gpg['domain_name']; - $organization = $CONFIG['organization']; - $from = $rslight_gpg['from_email']; - $contact = $rslight_gpg['contact']; - - $outgoing_file = tempnam($outgoing_dir, 'bbsmail-'); - - $start="@@BEGIN BBSMAIL HEADERS"; - $begin="@@BEGIN BBSMAIL BODY"; - $end="@@END BBSMAIL BODY"; - - $body=''; - $body.="You may use this to import MAIL for $domain.\n\n"; - - $body.="This message was signed using the following key:\n"; - $body.="$signing_key\n\n"; - - $body.="The GPG key needed to verify the signature of messages\n"; - $body.="issued by $from is available at:\n"; - $body.="$domain$key_location\n\n"; - - $body.="For information contact $contact.\n\n"; - - $body.=$start."\n"; - $body.=' Version: '.$rslight_version."\n"; - $body.=' From: '.$from."\n"; - $hashtail = hash('crc32', $domain.$organization.$sender.$rslight_gpg['nntp_group']); - $thishash = hash('crc32', $message.$hashtail).hash('crc32', $signing_key); - $body.=" Notice-ID: ".$thishash."\n"; - $body.=" Key: ".$signing_key."\n"; - $body.=" Location: ".$domain.$key_location."\n"; - $body.=" Domain: ".$domain."\n"; - - $body.=$begin."\n"; - $body.=" Sender: ".$sender."\n"; - $body.=" Recipient: ".$recipient."\n"; - $body.=" Date: ".$mydate."\n"; - $body.=" Subject: ".$subject."\n"; - $body.=" Body: ".$message."\n"; - $body.=$end."\n"; - - $header=''; - $header.="From: $from\n"; - $header.="Newsgroups: ".$rslight_gpg['nntp_group']."\n"; - $header.="Subject: @@RSL BBSMAIL notice ".$thishash."\n"; - $header.="Date: ".$mydate."\n"; - $header.="Message-ID: <$thishash@$domain>\n"; - $header.="Content-Type: text/plain; charset=utf-8; format=flowed\n"; - $header.="Content-Transfer-Encoding: 8bit\n"; - $header.="Organization: $organization\n\n"; - - $encrypted_text = gnupg_encryptsign($res, $body); - - file_put_contents($outgoing_file, $header.$encrypted_text); - return true; - } - - function retrieve_key($res, $domain) { - global $config_name, $logfile; - // Let's try to get the key - file_put_contents($logfile, "\n".format_log_date()." ".$config_name." No KEY for posting. Trying to retrieve for ".$domain, FILE_APPEND); + echo ' | ' . $row["mail_from"] . ' | ' . $row["rcpt_to"] . ' | ' . $newdate . ' |
'; - echo ''; - echo ' | '; +echo ''; +echo ''; +echo ' | '; // Upload button - echo ''; - echo ''; - echo ' | '; - echo '