Commit:    ab0843889b24fb00d76e08be2eda73db1a499ee5
Author:    Ben Ramsey <[email protected]>         Thu, 2 Jul 2015 12:05:44 
-0500
Parents:   a5f0c304d0b9eb6945305a1e99ef126e6ca1a172
Branches:  master

Link:       
http://git.php.net/?p=web/news.git;a=commitdiff;h=ab0843889b24fb00d76e08be2eda73db1a499ee5

Log:
Provides ability to run news.php.net locally with the built-in webserver

There is an issue with any post that contains references, since the
second NNTP connection to news.php.net times out, even though the first
connection succeeds.

Changed paths:
  A  .router.php
  D  README
  A  README.md
  M  common.php


Diff:
diff --git a/.router.php b/.router.php
new file mode 100644
index 0000000..22f2c15
--- /dev/null
+++ b/.router.php
@@ -0,0 +1,31 @@
+<?php
+
+error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
+
+$requestUri = $_SERVER['REQUEST_URI'];
+$matches = array();
+
+// Paging through group messages
+if (preg_match('#^/(php|svn|ug.+)/start/([0-9]+)#', $requestUri, $matches)) {
+    $_GET['group'] = $matches[1];
+    $_GET['i'] = $matches[2];
+    include 'group.php';
+    return true;
+}
+
+// Individual post
+if (preg_match('#^/(php|svn|ug.+)/([0-9]+)#', $requestUri, $matches)) {
+    $_GET['group'] = $matches[1];
+    $_GET['article'] = $matches[2];
+    include 'article.php';
+    return true;
+}
+
+// Newsgroup main page
+if (preg_match('#^/(php|svn|ug[^/]+)(/)?$#', $requestUri, $matches)) {
+    $_GET['group'] = $matches[1];
+    include 'group.php';
+    return true;
+}
+
+return false;
diff --git a/README b/README
deleted file mode 100644
index bd0c20e..0000000
--- a/README
+++ /dev/null
@@ -1,49 +0,0 @@
-this is all very ugly. just proof-of-concept, really.
-
-the biggest thing to do would be to do something smart with
-mime-encoded messages. but keeping the current property of <b>not</b>
-slurping the whole damn message into memory just to do so.
-
-another thing to do would be to support posting. to avoid
-completely anonymous posting, this could require confirming the
-email address before allowing posts. to do this without actually
-having to maintain a database of users, we could send an email
-containing md5(md5("email:timestamp").$secret) (where $secret is
-some value that is kept secret. duh.) and then let the user "log
-in" by supplying their email address and this code, and storing
-that in a cookie. depends on a secret for 'security', but like i
-said, it avoids having to maintain any sort of state on the server
-side. blocking email addresses for posting will be easy enough
-if anyone ever abuses the system.
-
-should also probably protect email addresses from harvesters.
-then again, anyone who wanted to harvest email addresses could just
-crawl the nntp server directly. or they can crawl any of the other
-mail archives that don't protect the addresses.
-
-keeping track of a .newsrc-like state for users would be cool,
-too. too bad there's no Set::IntSpan for php.
-
-perhaps chasing up the references: chain to display the
-thread when displaying an article would be interesting. i
-have a feeling that building some sort of index is going
-to be desirable at some point. should use jwz's threading
-algorithm. http://www.jwz.org/doc/threading.html
-
-ftp://ftp.isi.edu/in-notes/rfc2047.txt explains how to decode encoded
-header fields. handling utf-8 and iso-8859-1 should be pretty easy.
-could use the gnu recode functions to do this in a general way,
-i think.
-
-oh, and this uses direct socket functions instead of the php imap
-extension because nntp is a drop-dead-easy protocol, and i'm allergic
-to the c-client code.
-
----
-SC.2004.09.03:
-Here are the appropriate Rewrite rules for apache:
-  RewriteEngine on
-  RewriteRule ^/(php.+)/start/([0-9]+) /group.php?group=$1&i=$2 [L]
-  RewriteRule ^/(php.+)/([0-9]+)       /article.php?group=$1&article=$2 [L]
-  RewriteRule ^/(php[^/]+)(/)?$        /group.php?group=$1 [L]
-
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..9118771
--- /dev/null
+++ b/README.md
@@ -0,0 +1,65 @@
+# PHP.net News Server Web Interface
+
+You may run this project using PHP's [built-in web server][webserver]
+for local development.
+
+```
+git clone https://git.php.net/repository/web/news.git web-news
+cd web-news/
+NNTP_HOST=news.php.net php -S localhost:8080 .router.php
+```
+
+-----
+
+this is all very ugly. just proof-of-concept, really.
+
+the biggest thing to do would be to do something smart with
+mime-encoded messages. but keeping the current property of <b>not</b>
+slurping the whole damn message into memory just to do so.
+
+another thing to do would be to support posting. to avoid
+completely anonymous posting, this could require confirming the
+email address before allowing posts. to do this without actually
+having to maintain a database of users, we could send an email
+containing md5(md5("email:timestamp").$secret) (where $secret is
+some value that is kept secret. duh.) and then let the user "log
+in" by supplying their email address and this code, and storing
+that in a cookie. depends on a secret for 'security', but like i
+said, it avoids having to maintain any sort of state on the server
+side. blocking email addresses for posting will be easy enough
+if anyone ever abuses the system.
+
+should also probably protect email addresses from harvesters.
+then again, anyone who wanted to harvest email addresses could just
+crawl the nntp server directly. or they can crawl any of the other
+mail archives that don't protect the addresses.
+
+keeping track of a .newsrc-like state for users would be cool,
+too. too bad there's no Set::IntSpan for php.
+
+perhaps chasing up the references: chain to display the
+thread when displaying an article would be interesting. i
+have a feeling that building some sort of index is going
+to be desirable at some point. should use jwz's threading
+algorithm. http://www.jwz.org/doc/threading.html
+
+ftp://ftp.isi.edu/in-notes/rfc2047.txt explains how to decode encoded
+header fields. handling utf-8 and iso-8859-1 should be pretty easy.
+could use the gnu recode functions to do this in a general way,
+i think.
+
+oh, and this uses direct socket functions instead of the php imap
+extension because nntp is a drop-dead-easy protocol, and i'm allergic
+to the c-client code.
+
+---
+SC.2004.09.03:
+Here are the appropriate Rewrite rules for apache:
+
+    RewriteEngine on
+    RewriteRule ^/(php.+)/start/([0-9]+) /group.php?group=$1&i=$2 [L]
+    RewriteRule ^/(php.+)/([0-9]+)       /article.php?group=$1&article=$2 [L]
+    RewriteRule ^/(php[^/]+)(/)?$        /group.php?group=$1 [L]
+
+
+[webserver]: http://php.net/manual/en/features.commandline.webserver.php
diff --git a/common.php b/common.php
index f90ecc4..ff50470 100644
--- a/common.php
+++ b/common.php
@@ -1,6 +1,11 @@
 <?php
 
-define('NNTP_HOST', 'localhost');
+$NNTP_HOST = 'localhost';
+if (getenv('NNTP_HOST')) {
+       $NNTP_HOST = getenv('NNTP_HOST');
+}
+
+define('NNTP_HOST', $NNTP_HOST);
 
 function nntp_connect($server, $port = 119) {
        $s = @fsockopen($server, $port, $errno, $errstr, 30);


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to