"; if ($from == "" || $from == "Anonymous") $from = "Anonymous "; // // 'nntp_close()' - Close a news server thing... // function nntp_close($stream) // I - Socket stream { nntp_command($stream, "QUIT", 205); fclose($stream); } // // 'nntp_command()' - Send a command and get the response... // function // O - NNTP response nntp_command($stream, // I - Socket stream $command = "QUIT", // I - NNTP command $expect = 200) // I - Expected status { // print("

nntp_command(stream=$stream, command='$command', expect=$expect)

\n"); fwrite($stream, "$command\r\n"); $status = fgets($stream, 1024); // print("

status='$status'

\n"); if ((int)$status != $expect) { print("

Error: $status

\n"); return (NULL); } else return ($status); } // // 'nntp_connect()' - Connect to the news server. // function // O - Socket stream nntp_connect() { global $NNTPSERVER, $NNTPPORT; $stream = fsockopen($NNTPSERVER, $NNTPPORT, &$errno, &$errstr); if ($stream) { if ($line = fgets($stream, 1024)) { if ((int)$line != 200) { print("

Error: $line

\n"); fclose($stream); return (FALSE); } } else { print("

Error: No response from NNTP server!

\n"); fclose($stream); return (FALSE); } } else print("

Error: $errstr ($errno)

\n"); return ($stream); } // // 'nntp_search()' - Do a header search... // function // O - Matching message headers... nntp_search($stream, // I - Socket stream $group, // I - NNTP group $search) // I - Search text { // print("

nntp_search(stream=$stream, group='$group', search='$search'

\n"); $status = nntp_command($stream, "GROUP $group", 211); if (!$status) return (NULL); $fields = explode(" ", $status); $status = nntp_command($stream, "XOVER $fields[2]-$fields[3]", 224); if (!$status) return (NULL); $words = explode(" ", $search); $num_matches = 0; $matches = NULL; while ($line = fgets($stream, 1024)) { $line = rtrim($line); if ($line == ".") break; if ($search == "") { // Return all matches... $matches[$num_matches] = $line; $num_matches ++; } else { // Search for words... reset($words); while (list($key, $word) = each($words)) { if (stristr($line, $word)) { $matches[$num_matches] = $line; $num_matches ++; break; } } } } // print("

num_matches=$num_matches

\n"); return ($matches); } // // 'show_prevnext_page()' - Show the prev/next links for the messages list... // function show_prevnext_page($group, // I - Group $group_filter, // I - Group filter $start, // I - Start message $end, // I - End message $count) // I - Number of messages { global $PHP_SELF, $PAGE_MAX; print("

\n" ."\n" ."
"); if ($start > 1) { $i = $start - $PAGE_MAX; if ($i < 1) $i = 1; $j = $i + $PAGE_MAX - 1; if ($j > $count) $j = $count; html_start_links(); html_link("Show Messages $i - $j", "$PHP_SELF?s$i+g$group+G$group_filter"); html_end_links(); } print(""); html_start_links(); html_link("All Groups", "$PHP_SELF?G$group_filter"); if (!ereg(".*\.announce", $group) && !ereg(".*\.cvs", $group)) html_link("New Message", "$PHP_SELF?s$i+g$group+G$group_filter+n"); html_end_links(); print(""); if ($end < $count) { $i = $start + $PAGE_MAX; $j = $i + $PAGE_MAX - 1; if ($j > $count) $j = $count; html_start_links(); html_link("Show Messages $i - $j", "$PHP_SELF?s$i+g$group+G$group_filter"); } print("

\n"); } // // 'show_messages()' - Show messages in the named group... // function show_messages($group, // I - Group $group_filter, // I - Group filter $start, // I - Start message $search) // I - Search string { global $PHP_SELF, $PAGE_MAX; // Figure out which messages to show... $error = ""; $stream = nntp_connect(); $matches = nntp_search($stream, $group, $search); $count = count($matches); nntp_close($stream); if (!$matches) { $count = 0; $error = "No matches found for '" . htmlspecialchars($search, ENT_QUOTES) . "'..."; } if ($start == 0) $start = $count - 9; if ($start > ($count - $PAGE_MAX + 1)) $start = $count - $PAGE_MAX + 1; if ($start < 1) $start = 1; $end = $start + $PAGE_MAX - 1; if ($end > $count) $end = $count; // Show the standard header... html_header("$group ($start - $end of $count)"); $temp = htmlspecialchars($search, ENT_QUOTES); print("
\n" ."

\n" ."
\n"); if ($error != "") print("

$error

\n"); show_prevnext_page($group, $group_filter, $start, $end, $count); html_start_table(array("Subject", "Author", "Date")); for ($i = $start; $i <= $end; $i ++) { $fields = explode("\t", $matches[$i - 1]); $msg = (int)$fields[0]; $subject = htmlspecialchars($fields[1], ENT_QUOTES); $author = sanitize_email($fields[2]); $date = htmlspecialchars($fields[3], ENT_QUOTES); html_start_row(); print("" ."$subject" ."$author" ."$date"); html_end_row(); } html_end_table(); show_prevnext_page($group, $group_filter, $start, $end, $count); html_footer(); } // // 'show_groups()' - Show groups... // function show_groups($group_filter, // I - Group filter $search) // I - Search string { global $PHP_SELF; html_header("Newsgroups"); // Figure out which messages to show... $stream = nntp_connect(); // Search stuff... print("
\n" ."

\n" ."
\n"); // Show the standard header... html_start_table(array("Group", "Messages", "")); $status = nntp_command($stream, "LIST", 215); $num_groups = 0; $groups = array(); if ($status) { while ($line = fgets($stream, 1024)) { $line = rtrim($line); if ($line == ".") break; $fields = explode(" ", $line); $groups[$num_groups] = $fields[0]; $num_groups ++; } } sort($groups); while (list($key, $group) = each($groups)) { if (ereg("(linuxprinting|private)\\..*", $group)) continue; if ($group_filter && !ereg("${group_filter}\\.*", $group)) continue; $status = nntp_command($stream, "GROUP $group", 211); if (!$status) continue; $fields = explode(" ", $status); $total = (int)$fields[1]; if ($search != "") { $matches = nntp_search($stream, $group, $search); $count = count($matches); } else $count = $total; html_start_row(); print("$group" ."$count"); if ($search != "") print("/$total"); print(""); html_start_links(); html_link("View", "$PHP_SELF?g$group+G$group_filter"); if (!ereg(".*\.announce", $group) && !ereg(".*\.cvs", $group)) html_link("New Message", "$PHP_SELF?g$group+G$group_filter+n"); html_end_links(); print(""); html_end_row(); } html_start_row("header"); print("Newsgroups and Mailing Lists"); html_end_row(); html_start_row(); print("" ."

Point your news reader at " ."news.easysw.com to view these groups directly.

\n" ."

Go to " ."http://lists.easysw.com/mailman/listinfo " ."to subscribe to or unsubcribe from the mailing lists that mirror " ."these groups.

" .""); html_end_row(); html_end_table(); nntp_close($stream); html_footer(); } // // 'show_prevnext_msg()' - Show the prev/next links for the messages list... // function show_prevnext_msg($group, // I - Group $group_filter, // I - Group filter $start, // I - Start message $count, // I - Number of messages $msg) // I - Current message { global $PHP_SELF; print("

\n" ."\n" ."
"); if ($msg > 1) { $i = $msg - 1; html_start_links(); html_link("Previous Message", "$PHP_SELF?s$start+g$group+G$group_filter+v$i"); html_end_links(); } print(""); html_start_links(); html_link("All Groups", "$PHP_SELF?G$group_filter"); html_link("Back to $group", "$PHP_SELF?s$msg+g$group+G$group_filter"); if (!ereg(".*\.announce", $group) && !ereg(".*\.cvs", $group)) { html_link("Reply", "$PHP_SELF?s$start+g$group+G$group_filter+r$msg"); html_link("New Message", "$PHP_SELF?s$i+g$group+G$group_filter+n"); } html_end_links(); print(""); if ($msg < $count) { $i = $msg + 1; html_start_links(); html_link("Next Message", "$PHP_SELF?s$start+g$group+G$group_filter+v$i"); html_end_links(); } print("

\n"); } // // 'show_message()' - Show a single message... // function show_message($group, // I - Group $group_filter, // I - Group filter $start, // I - Start message $msg, // I - Current message $search) // I - Search string { global $PHP_SELF; // Figure out which messages to show... $stream = nntp_connect(); $matches = nntp_search($stream, $group, $search); $count = count($matches); if ($msg < 1 || $msg > $count) { nntp_close($stream); return; } $fields = explode("\t", $matches[$msg - 1]); $msgnum = (int)$fields[0]; $subject = str_replace(":", ":", htmlspecialchars($fields[1], ENT_QUOTES)); $author = str_replace(":", ":", sanitize_email($fields[2])); $date = str_replace(":", ":", htmlspecialchars($fields[3], ENT_QUOTES)); $status = nntp_command($stream, "BODY $msgnum", 222); if (!$status) { nntp_close($stream); return; } $body = ""; while ($line = fgets($stream, 1024)) { $line = rtrim($line); if ($line == ".") break; $body = $body . $line . "\n"; } nntp_close($stream); $body = quote_text($body); html_header("$subject"); show_prevnext_msg($group, $group_filter, $start, $count, $msg); html_start_table(array($subject, $author, $date)); html_start_row(); print("$body"); html_end_row(); html_end_table(); show_prevnext_msg($group, $group_filter, $start, $count, $msg); html_footer(); } // // 'post_message()' - Post a message... // function post_message($group, // I - Group $group_filter, // I - Group filter $start, // I - Start message $msg, // I - Current message $search) // I - Search string { global $PHP_SELF, $_POST; if (array_key_exists("FROM", $_POST)) $from = $_POST["FROM"]; else $from = ""; if (array_key_exists("SUBJECT", $_POST)) $subject = $_POST["SUBJECT"]; else $subject = ""; if (array_key_exists("BODY", $_POST)) $body = $_POST["BODY"]; else $body = ""; if (!validate_email($from) || $subject == "" || $body == "") { new_message($group, $group_filter, $start, $from, $subject, $body); return; } $stream = nntp_connect(); if (!$stream) { return; } $id = ""; if ($msg > 0) { $matches = nntp_search($stream, $group, $search); $count = count($matches); if ($msg <= $count) { $fields = explode("\t", $matches[$msg - 1]); $id = $fields[4]; } } $status = nntp_command($stream, "POST", 340); if (!$status) { nntp_close($stream); return; } fwrite($stream, "From: $from\r\n"); fwrite($stream, "Subject: $subject\r\n"); fwrite($stream, "Newsgroups: $group\r\n"); if ($id != "") fwrite($stream, "In-Reply-To: $id\r\n"); fwrite($stream, "\r\n"); $lines = explode("\n", $body); $count = count($lines); for ($i = 0; $i < $count; $i ++) { $line = rtrim($lines[$i]); if ($line == ".") fwrite($stream, ". \r\n"); else fwrite($stream, "$line\r\n"); } $status = nntp_command($stream, ".", 240); if ($status) { if ($msg == 0) header("Location: $PHP_SELF?s$start+g$group+G$group_filter"); else header("Location: $PHP_SELF?s$start+g$group+G$group_filter+v$msg"); } nntp_close($stream); } // // 'reply_message()' - Reply to a message... // function reply_message($group, // I - Group to reply to $group_filter, // I - Group filter $start, // I - First message in the display $msg, // I - Message to reply to $search, // I - Search string $sender) // I - Sender address { global $PHP_SELF; // Figure out which messages to show... $stream = nntp_connect(); $matches = nntp_search($stream, $group, $search); $count = count($matches); if ($msg < 1 || $msg > $count) { nntp_close($stream); return; } $fields = explode("\t", $matches[$msg - 1]); $msgnum = (int)$fields[0]; $subject = htmlspecialchars($fields[1], ENT_QUOTES); $author = sanitize_email($fields[2]); $date = htmlspecialchars($fields[3], ENT_QUOTES); if (strncasecmp($subject, "re:", 3)) $subject = "Re: " . $subject; $status = nntp_command($stream, "BODY $msgnum", 222); if (!$status) { nntp_close($stream); return; } $body = ""; while ($line = fgets($stream, 1024)) { $line = rtrim($line); if ($line == ".") break; $body = $body . "> " . $line . "\n"; } nntp_close($stream); new_message($group, $group_filter, $start, $subject, $sender, $body); } // // 'new_message()' - Post a new message... // function new_message($group, // I - Group to post to $group_filter, // I - Group filter $start, // I - First message $subject, // I - Subject of message $sender, // I - Sender address $body) // I - Message body { global $PHP_SELF, $NNTPSPEC; $subject = htmlspecialchars($subject, ENT_QUOTES); $sender = htmlspecialchars($sender, ENT_QUOTES); $body = htmlspecialchars($body, ENT_QUOTES); html_header("Post Message to $group"); html_start_links(1); html_link("All Groups", "$PHP_SELF?G$group_filter"); html_link("Back to $group", "$PHP_SELF?s$start+g$group+G$group_filter"); html_end_links(1); print("

Post Message to $group

"); print("
\n"); print("
\n"); print("" ."\n"); print("" ."\n"); print("" ."\n"); print("" ."\n"); print("
Subject:
From:
Body:
\n"); print("
\n"); html_footer(); } // Parse command-line options... $start = 0; $group = ""; $op = 'l'; $msg = ""; for ($i = 0; $i < $argc; $i ++) { switch ($argv[$i][0]) { case 'g' : $group = substr($argv[$i], 1); break; case 'G' : $groups = substr($argv[$i], 1); break; case 'n' : case 'p' : case 'r' : case 'v' : $op = $argv[$i][0]; $msg = (int)substr($argv[$i], 1); break; case 's' : $start = (int)substr($argv[$i], 1); break; } } // Now handle the request... switch ($op) { case 'l' : // List if ($group) show_messages($group, $PROJECT_MODULE, $start, $search); else show_groups($PROJECT_MODULE, $search); break; case 'n' : // New message new_message($group, $PROJECT_MODULE, $start, "", $from, ""); break; case 'p' : // Post message if (ereg(".*\.announce", $group) || ereg(".*\.cvs", $group)) { html_header("Newsgroup Posting Error"); print("

We are sorry, but we could not post your message for the " ."following reason:\n" ."

Group $group is read-only.
\n"); html_footer(); } else post_message($group, $PROJECT_MODULE, $start, $msg, $search); break; case 'r' : // Reply message reply_message($group, $PROJECT_MODULE, $start, $msg, $search, $from); break; case 'v' : // View message show_message($group, $PROJECT_MODULE, $start, $msg, $search); break; } // // End of "$Id: newsgroups.php,v 1.1 2004/06/10 02:40:05 mike Exp $". // ?>