diff options
| author | czaks <marcin@6irc.net> | 2016-08-15 00:56:06 +0200 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2016-08-15 00:56:06 +0200 |
| commit | a779b96370d3353c8409d64b70c724fa783ad219 (patch) | |
| tree | 0ef37aebac141cb0857caeaddde2a393159ce843 /post.php | |
| parent | 1c24c69999db67ebbc13fef7c53e37d08768008f (diff) | |
second iteration of nntpchan implementation
Diffstat (limited to 'post.php')
| -rw-r--r-- | post.php | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -13,7 +13,12 @@ if ((!isset($_POST['mod']) || !$_POST['mod']) && $config['board_locked']) { $dropped_post = false; +// Is it a post coming from NNTP? Let's extract it and pretend it's a normal post. if (isset($_GET['Newsgroups']) && $config['nntpchan']['enabled']) { + if ($_SERVER['REMOTE_ADDR'] != $config['nntpchan']['trusted_peer']) { + error("NNTPChan: Forbidden. $_SERVER[REMOTE_ADDR] is not a trusted peer"); + } + $_POST = array(); $_POST['json_response'] = true; @@ -1057,7 +1062,31 @@ if (isset($_POST['delete'])) { $query->bindValue(':message_id_digest', sha1($dropped_post['msgid'])); $query->bindValue(':headers', $dropped_post['headers']); $query->execute() or error(db_error($query)); + } // ^^^^^ For inbound posts ^^^^^ + elseif ($config['nntpchan']['enabled'] && $config['nntpchan']['group']) { + // vvvvv For outbound posts vvvvv + + require_once('inc/nntpchan/nntpchan.php'); + $msgid = gen_msgid($post['board'], $post['id']); + + list($headers, $files) = post2nntp($post, $msgid); + + $message = gen_nntp($headers, $files); + + $query = prepare("INSERT INTO ``nntp_references`` (`board`, `id`, `message_id`, `message_id_digest`, `own`, `headers`) VALUES ". + "(:board , :id , :message_id , :message_id_digest , true , :headers)"); + + $query->bindValue(':board', $post['board']); + $query->bindValue(':id', $post['id']); + $query->bindValue(':message_id', $msgid); + $query->bindValue(':message_id_digest', sha1($msgid)); + $query->bindValue(':headers', json_encode($headers)); + $query->execute() or error(db_error($query)); + + // Let's broadcast it! + nntp_publish($message, $msgid); } + insertFloodPost($post); // Handle cyclical threads |
