annotate server.php @ 14:372f4e195986 draft default tip

Added article blacklist function, switch to binary-safe latin1 character set for database
author Ivo Smits <Ivo@UCIS.nl>
date Thu, 17 Jul 2014 23:24:17 +0200
parents cccd73f72bf6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
1 #!/usr/bin/php
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
2 <?php
8
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
3 /* Copyright 2010 Ivo Smits <Ivo@UCIS.nl>. All rights reserved.
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
4 Redistribution and use in source and binary forms, with or without modification, are
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
5 permitted provided that the following conditions are met:
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
6
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
7 1. Redistributions of source code must retain the above copyright notice, this list of
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
8 conditions and the following disclaimer.
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
9
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
10 2. Redistributions in binary form must reproduce the above copyright notice, this list
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
11 of conditions and the following disclaimer in the documentation and/or other materials
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
12 provided with the distribution.
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
13
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
14 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
15 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
18 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
19 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
20 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
21 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
22 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
23
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
24 The views and conclusions contained in the software and documentation are those of the
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
25 authors and should not be interpreted as representing official policies, either expressed
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
26 or implied, of Ivo Smits.*/
005339a1b2ce Added copyright notice
Ivo Smits <Ivo@UCIS.nl>
parents: 7
diff changeset
27
2
40e545510a57 Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
28 chdir(__DIR__);
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
29 require_once './common.php';
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
30
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
31 $logfile = fopen('./server.log', 'w');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
32 $currentgroup = NULL;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
33 $currentarticle = NULL;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
34
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
35 function exception_handler($exception) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
36 nntp_writeline(STDOUT, '');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
37 nntp_writeline(STDOUT, '590 Exception: '.$exception->getMessage());
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
38 die();
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
39 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
40 function error_handler($errno, $errstr, $errfile, $errline) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
41 nntp_writeline(STDOUT, '');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
42 nntp_writeline(STDOUT, '590 Error in file '.$errfile.' line '.$errline.' error '.$errno.' '.$errstr);
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
43 die();
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
44 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
45 set_exception_handler('exception_handler');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
46 set_error_handler("error_handler");
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
47
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
48 nntp_writeline(STDOUT, '200 pNewss ready');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
49 while (TRUE) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
50 $line = nntp_readline(STDIN);
2
40e545510a57 Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
51 if ($line === FALSE || $line === NULL) break;
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
52 $cmd = strtoupper(strtok($line, " \t"));
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
53 switch ($cmd) {
12
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
54 case '':
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
55 break;
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
56 case 'MODE':
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
57 $mode = strtok(" \t");
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
58 switch (strtoupper($mode)) {
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
59 case 'READER': nntp_writeline(STDOUT, '200 Hello, you can post'); break;
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
60 case 'STREAM': nntp_writeline(STDOUT, '203 Streaming permitted'); break;
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
61 default: nntp_writeline(STDOUT, '501 Unknown MODE variant'); break;
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
62 }
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
63 break;
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
64 case 'CAPABILITIES':
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
65 nntp_writeline(STDOUT, '101 Capability list:');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
66 nntp_writeline_data(STDOUT, 'VERSION 2');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
67 nntp_writeline_data(STDOUT, 'IMPLEMENTATION pNewss [http://wiki.ucis.nl/pNewss]');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
68 nntp_writeline_data(STDOUT, 'POST');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
69 nntp_writeline_data(STDOUT, 'READER');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
70 nntp_writeline_data(STDOUT, 'IHAVE');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
71 nntp_writeline_data(STDOUT, 'LIST ACTIVE');
12
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
72 nntp_writeline_data(STDOUT, 'MODE-READER');
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
73 nntp_writeline_data(STDOUT, 'STREAMING');
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
74 nntp_writeline(STDOUT, '.');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
75 break;
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
76 case 'DATE':
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
77 nntp_writeline(STDOUT, '111 '.gmdate('YmdHis'));
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
78 break;
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
79 case 'HELP':
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
80 nntp_writeline(STDOUT, '100 Help text follows:');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
81 nntp_writeline_data(STDOUT, 'Supported commands: CAPABILITIES,DATE,HELP,LIST,GROUP,LISTGROUP,STAT,HEAD,BODY,ARTICLE,LAST,NEXT,POST,IHAVE,QUIT');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
82 nntp_writeline(STDOUT, '.');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
83 break;
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
84 case 'LIST':
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
85 nntp_writeline(STDOUT, '215 list of groups follows');
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
86 foreach ($db->evalAllAssoc('SELECT * FROM `groups`') as $group) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
87 $groupmessages = $db->evalRow('SELECT MIN(`number`), MAX(`number`) FROM `groupmessages` WHERE `group` = ?', $group['id']);
12
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
88 nntp_writeline_data(STDOUT, $group['name'].' '.intval($groupmessages[1]).' '.intval($groupmessages[0]).' y');
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
89 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
90 nntp_writeline(STDOUT, '.');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
91 break;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
92 case 'GROUP':
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
93 case 'LISTGROUP':
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
94 $groupname = strtok(" \t");
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
95 if ($groupname === FALSE) {
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
96 $group = $currentgroup;
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
97 } else {
13
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
98 $group = $db->evalRowAssoc('SELECT * FROM `groups` WHERE `name` = ?', array($groupname));
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
99 }
13
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
100 if (!$group) {
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
101 nntp_writeline(STDOUT, '411 No such group '.$groupname);
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
102 } else {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
103 $currentgroup = $group;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
104 $groupmessages = $db->evalRow('SELECT MIN(`number`), MAX(`number`), COUNT(`number`) FROM `groupmessages` WHERE `group` = ?', $group['id']);
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
105 nntp_writeline(STDOUT, '211 '.intval($groupmessages[2]).' '.intval($groupmessages[0]).' '.intval($groupmessages[1]).' '.$group['name']);
14
372f4e195986 Added article blacklist function, switch to binary-safe latin1 character set for database
Ivo Smits <Ivo@UCIS.nl>
parents: 13
diff changeset
106 $currentarticle = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `message` IS NOT NULL ORDER BY `number` ASC LIMIT 1', $group['id']);
372f4e195986 Added article blacklist function, switch to binary-safe latin1 character set for database
Ivo Smits <Ivo@UCIS.nl>
parents: 13
diff changeset
107 if ($currentarticle === FALSE) $currentarticle = NULL;
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
108 if ($cmd == 'LISTGROUP') {
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
109 $range = strtok(" \t");
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
110 if ($range !== FALSE) {
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
111 $parts = explode('-', $range);
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
112 if (count($parts) == 1 || !strlen($parts[1])) {
14
372f4e195986 Added article blacklist function, switch to binary-safe latin1 character set for database
Ivo Smits <Ivo@UCIS.nl>
parents: 13
diff changeset
113 $query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `number` >= ? AND `message` IS NOT NULL';
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
114 $queryargs = array($group['id'], $parts[0]);
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
115 } else {
14
372f4e195986 Added article blacklist function, switch to binary-safe latin1 character set for database
Ivo Smits <Ivo@UCIS.nl>
parents: 13
diff changeset
116 $query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `number` BETWEEN ? AND ? AND `message` IS NOT NULL';
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
117 $queryargs = array($group['id'], $parts[0], $parts[1]);
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
118 }
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
119 } else {
14
372f4e195986 Added article blacklist function, switch to binary-safe latin1 character set for database
Ivo Smits <Ivo@UCIS.nl>
parents: 13
diff changeset
120 $query = 'SELECT `number` FROM `groupmessages` WHERE `group` = ? AND `message` IS NOT NULL';
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
121 $queryargs = array($group['id']);
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
122 }
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
123 foreach ($db->evalColumn($query, $queryargs) as $number) nntp_writeline_data(STDOUT, $number);
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
124 nntp_writeline(STDOUT, '.');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
125 }
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
126 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
127 break;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
128 case 'STAT':
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
129 case 'HEAD':
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
130 case 'BODY':
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
131 case 'ARTICLE':
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
132 $article = nntp_get_article(strtok(" \t"));
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
133 if ($article === NULL) break;
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
134 switch ($cmd) {
5
5d62af5270dd Small bugfix in server STAT command (no data follows, so don't send a dot)
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
135 case 'ARTICLE': nntp_writeline(STDOUT, '220 '.$article['messagenumber'].' <'.$article['messageid'].'> article'); break;
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
136 case 'HEAD': nntp_writeline(STDOUT, '221 '.$article['messagenumber'].' <'.$article['messageid'].'> head'); break;
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
137 case 'BODY': nntp_writeline(STDOUT, '222 '.$article['messagenumber'].' <'.$article['messageid'].'> body'); break;
5
5d62af5270dd Small bugfix in server STAT command (no data follows, so don't send a dot)
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
138 case 'STAT': nntp_writeline(STDOUT, '223 '.$article['messagenumber'].' <'.$article['messageid'].'> stat'); break;
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
139 default: throw new Exception('Internal error');
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
140 }
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
141 if ($cmd == 'HEAD' || $cmd == 'ARTICLE') foreach (explode("\r\n", $article['header']) as $line) nntp_writeline_data(STDOUT, $line);
10
ca88deec5352 Add Xref header when sending messages to client (seems to fix message corruption issues in Thunderbird)
Ivo Smits <Ivo@UCIS.nl>
parents: 8
diff changeset
142 if ($cmd == 'HEAD' || $cmd == 'ARTICLE') {
ca88deec5352 Add Xref header when sending messages to client (seems to fix message corruption issues in Thunderbird)
Ivo Smits <Ivo@UCIS.nl>
parents: 8
diff changeset
143 $grouprefsh = array('localhost');
ca88deec5352 Add Xref header when sending messages to client (seems to fix message corruption issues in Thunderbird)
Ivo Smits <Ivo@UCIS.nl>
parents: 8
diff changeset
144 foreach ($db->evalAllAssoc('SELECT * FROM `groupmessages` WHERE `message` = ?', $article['id']) as $groupref) {
ca88deec5352 Add Xref header when sending messages to client (seems to fix message corruption issues in Thunderbird)
Ivo Smits <Ivo@UCIS.nl>
parents: 8
diff changeset
145 $groupname = $db->eval('SELECT `name` FROM `groups` WHERE `id` = ?', $groupref['group']);
ca88deec5352 Add Xref header when sending messages to client (seems to fix message corruption issues in Thunderbird)
Ivo Smits <Ivo@UCIS.nl>
parents: 8
diff changeset
146 $grouprefsh[] = $groupname.':'.$groupref['number'];
ca88deec5352 Add Xref header when sending messages to client (seems to fix message corruption issues in Thunderbird)
Ivo Smits <Ivo@UCIS.nl>
parents: 8
diff changeset
147 }
ca88deec5352 Add Xref header when sending messages to client (seems to fix message corruption issues in Thunderbird)
Ivo Smits <Ivo@UCIS.nl>
parents: 8
diff changeset
148 nntp_writeline_data(STDOUT, 'Xref: '.implode(' ', $grouprefsh));
ca88deec5352 Add Xref header when sending messages to client (seems to fix message corruption issues in Thunderbird)
Ivo Smits <Ivo@UCIS.nl>
parents: 8
diff changeset
149 }
ca88deec5352 Add Xref header when sending messages to client (seems to fix message corruption issues in Thunderbird)
Ivo Smits <Ivo@UCIS.nl>
parents: 8
diff changeset
150 if ($cmd == 'ARTICLE') nntp_writeline_data(STDOUT, '');
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
151 if ($cmd == 'BODY' || $cmd == 'ARTICLE') foreach (explode("\r\n", $article['body']) as $line) nntp_writeline_data(STDOUT, $line);
5
5d62af5270dd Small bugfix in server STAT command (no data follows, so don't send a dot)
Ivo Smits <Ivo@UCIS.nl>
parents: 3
diff changeset
152 if ($cmd != 'STAT') nntp_writeline(STDOUT, '.');
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
153 break;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
154 case 'LAST':
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
155 case 'NEXT':
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
156 if ($currentarticle === NULL) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
157 nntp_writeline(STDOUT, '420 no current article has been selected');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
158 break;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
159 }
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
160 switch ($cmd) {
14
372f4e195986 Added article blacklist function, switch to binary-safe latin1 character set for database
Ivo Smits <Ivo@UCIS.nl>
parents: 13
diff changeset
161 case 'LAST': $query = 'SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` < ? AND `message` IS NOT NULL ORDER BY `number` DESC LIMIT 1'; break;
372f4e195986 Added article blacklist function, switch to binary-safe latin1 character set for database
Ivo Smits <Ivo@UCIS.nl>
parents: 13
diff changeset
162 case 'NEXT': $query = 'SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` > ? AND `message` IS NOT NULL ORDER BY `number` ASC LIMIT 1'; break;
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
163 default: throw new Exception('Internal error');
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
164 }
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
165 $article = $db->evalRowAssoc($query, array($currentarticle['group'], $currentarticle['number']));
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
166 if ($article === FALSE) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
167 nntp_writeline(STDOUT, '422 no previous article in this group');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
168 } else {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
169 $articlea = $db->evalRowAssoc('SELECT * FROM `messages` WHERE `id` = ?', $article['message']);
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
170 if ($articlea === FALSE) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
171 nntp_writeline(STDOUT, '430 no such article found');
13
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
172 } else {
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
173 $currentarticle = $article;
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
174 nntp_writeline(STDOUT, '223 '.$article['number'].' <'.$articlea['messageid'].'> ok');
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
175 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
176 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
177 break;
2
40e545510a57 Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
178 case 'POST':
40e545510a57 Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
179 nntp_writeline(STDOUT, '340 Ok, recommended message-ID <'.md5(time().rand()).'@pNews.Core.UCIS.nl>');
40e545510a57 Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
180 $lines = nntp_readlines(STDIN);
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
181 try {
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
182 $messageid = nntp_article_store($lines);
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
183 nntp_writeline(STDOUT, '240 Article received <'.$messageid.'>');
3
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
184 } catch (Exception $ex) {
0dcdb73cbcbf Increased article body length to 16MB in database scheme, cleaned up the code, added a script to forcefully reload an individual article
Ivo Smits <Ivo@UCIS.nl>
parents: 2
diff changeset
185 nntp_writeline(STDOUT, '441 '.$ex->getMessage());
2
40e545510a57 Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
186 }
40e545510a57 Added support for POSTing to the server, added readme and todo, added support for upstream synchronization using POST
Ivo Smits <Ivo@UCIS.nl>
parents: 0
diff changeset
187 break;
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
188 case 'IHAVE':
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
189 $messageid = strtok(" \t");
12
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
190 if ($messageid === FALSE || strlen($messageid) <= 2 || $messageid[0] != '<' || $messageid[strlen($messageid)-1] != '>') {
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
191 nntp_writeline(STDOUT, '435 Argument error');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
192 break;
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
193 }
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
194 $messageid = substr($messageid, 1, -1);
13
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
195 if (!nntp_article_wanted($messageid)) {
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
196 nntp_writeline(STDOUT, '435 Duplicate or filtered');
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
197 break;
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
198 }
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
199 nntp_writeline(STDOUT, '335 Send article to be transferred');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
200 $lines = nntp_readlines(STDIN);
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
201 try {
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
202 $messageid = nntp_article_store($lines);
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
203 nntp_writeline(STDOUT, '235 Article received <'.$messageid.'>');
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
204 } catch (Exception $ex) {
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
205 nntp_writeline(STDOUT, '437 '.$ex->getMessage());
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
206 }
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
207 break;
12
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
208 case 'CHECK':
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
209 $messageid = strtok(" \t");
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
210 if ($messageid === FALSE || strlen($messageid) <= 2 || $messageid[0] != '<' || $messageid[strlen($messageid)-1] != '>') {
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
211 nntp_writeline(STDOUT, '435 Argument error');
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
212 break;
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
213 }
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
214 $messageid = substr($messageid, 1, -1);
13
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
215 if (!nntp_article_wanted($messageid)) {
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
216 nntp_writeline(STDOUT, '438 <'.$messageid.'> Duplicate or filtered');
12
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
217 break;
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
218 }
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
219 nntp_writeline(STDOUT, '238 <'.$messageid.'> Send article to be transferred');
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
220 break;
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
221 case 'TAKETHIS':
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
222 $messageid = strtok(" \t");
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
223 $lines = nntp_readlines(STDIN);
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
224 if ($messageid === FALSE || strlen($messageid) <= 2 || $messageid[0] != '<' || $messageid[strlen($messageid)-1] != '>') {
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
225 nntp_writeline(STDOUT, '435 Argument error');
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
226 break;
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
227 }
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
228 $messageid = substr($messageid, 1, -1);
13
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
229 if (!nntp_article_wanted($messageid)) {
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
230 nntp_writeline(STDOUT, '439 <'.$messageid.'> Duplicate or filtered');
12
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
231 break;
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
232 }
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
233 try {
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
234 $messageid = nntp_article_store($lines);
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
235 nntp_writeline(STDOUT, '239 <'.$messageid.'> Article stored');
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
236 } catch (Exception $ex) {
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
237 nntp_writeline(STDOUT, '437 '.$ex->getMessage());
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
238 }
7917bd536187 Added hook for new articles, detect send/write failures, fixed handling of multiline headers, add Date header if it doesn't exist, add option to disable peers, fixes for synchronization with INN, added streaming mode support, small fixes
Ivo Smits <Ivo@UCIS.nl>
parents: 10
diff changeset
239 break;
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
240 case 'QUIT':
7
01dc7eeaf5df Added some more checks to article data, added some commands, added 'dot stuffing' for block transfers
Ivo Smits <Ivo@UCIS.nl>
parents: 5
diff changeset
241 nntp_writeline(STDOUT, '205 Bye.');
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
242 return;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
243 default:
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
244 nntp_writeline(STDOUT, '500 Command not understood');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
245 break;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
246 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
247 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
248
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
249 function nntp_get_article($article) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
250 global $currentgroup, $currentarticle, $db;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
251 if ($article === FALSE) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
252 if ($currentarticle === NULL) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
253 nntp_writeline(STDOUT, '420 no current article has been selected');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
254 return NULL;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
255 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
256 $messagenumber = $currentarticle['number'];
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
257 $article = $db->evalRowAssoc('SELECT * FROM `messages` WHERE `id` = ?', $currentarticle['message']);
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
258 if ($article === FALSE) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
259 nntp_writeline(STDOUT, '430 no such article found');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
260 return NULL;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
261 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
262 } elseif (strlen($article) > 2 && $article[0] == '<' && $article[strlen($article)-1] == '>') {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
263 $messagenumber = 0;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
264 $article = substr($article, 1, -1);
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
265 $article = $db->evalRowAssoc('SELECT * FROM `messages` WHERE `messageid` = ?', $article);
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
266 if ($article === FALSE) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
267 nntp_writeline(STDOUT, '430 no such article found');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
268 return NULL;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
269 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
270 } elseif (is_numeric($article)) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
271 if ($currentgroup === NULL) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
272 nntp_writeline(STDOUT, '412 no newsgroup has been selected');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
273 return NULL;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
274 }
14
372f4e195986 Added article blacklist function, switch to binary-safe latin1 character set for database
Ivo Smits <Ivo@UCIS.nl>
parents: 13
diff changeset
275 $article = $db->evalRowAssoc('SELECT * FROM `groupmessages` WHERE `group` = ? AND `number` = ? AND `message` IS NOT NULL', array($currentgroup['id'], $article));
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
276 if ($article === FALSE) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
277 nntp_writeline(STDOUT, '423 no such article number in this group');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
278 return NULL;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
279 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
280 $currentarticle = $article;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
281 $messagenumber = $article['number'];
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
282 $article = $db->evalRowAssoc('SELECT * FROM `messages` WHERE `id` = ?', $article['message']);
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
283 if ($article === FALSE) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
284 nntp_writeline(STDOUT, '430 no such article found');
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
285 return NULL;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
286 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
287 } else {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
288 nntp_writeline(STDOUT, '500 Error in arguments');
13
cccd73f72bf6 Added filtering support and several bugfixes
Ivo Smits <Ivo@UCIS.nl>
parents: 12
diff changeset
289 return NULL;
0
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
290 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
291 $article['messagenumber'] = $messagenumber;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
292 return $article;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
293 }
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
294
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
295 function writelog($line) {
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
296 global $logfile;
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
297 fwrite($logfile, $line."\n");
d7ab68b71c74 Initial commit
Ivo Smits <Ivo@UCIS.nl>
parents:
diff changeset
298 }