diff --git a/inc/anti-bot.php b/inc/anti-bot.php index ac61fe54..0054ee50 100644 --- a/inc/anti-bot.php +++ b/inc/anti-bot.php @@ -12,7 +12,12 @@ $logfile = "/tmp/lainchan_err.out"; function print_err($s) { global $logfile; - file_put_contents($logfile, $s . "\n", FILE_APPEND); + $datetime = new Datetime(); + file_put_contents( + $logfile, + $datetime->format(DateTime::ATOM) . " " . $s . "\n", + FILE_APPEND + ); } function getStackTraceAsString() { @@ -217,6 +222,13 @@ class AntiBot { // Use SHA1 for the hash return sha1($hash . $this->salt); } + + public function printErrVars() { //DELETE ME + $inputs = $this->inputs; + ksort($inputs); + + print_err("Antibot " . $this->hash() . " inputs: " . json_encode($inputs)); + } } function _create_antibot($board, $thread) { @@ -245,15 +257,44 @@ function _create_antibot($board, $thread) { $query->bindValue(':thread', $thread); $query->bindValue(':hash', $antibot->hash()); $query->execute() or error(db_error($query)); + + $antibot->printErrVars(); return $antibot; } +function dumpVars($extra_salt) { + global $config; + + print_err("Check Spam POST data: " . json_encode($_POST)); + + /* + foreach ($_POST as $name => $value) { + $is_valid_input = in_array($name, $config['spam']['valid_inputs']) ? "valid" : "invalid"; + print_err(" $name: $value ($is_valid_input)"); + } + */ + + if (!empty($extra_salt)) { + $extra_salt = implode(':', $extra_salt); + } else { + $extra_salt = ''; + } + + print_err("extra_salt: $extra_salt"); +} + function checkSpam(array $extra_salt = array()) { global $config, $pdo; - if (!isset($_POST['hash'])) + #print_err("checkSpam start"); + $extra_salt_orig = $extra_salt; + + if (!isset($_POST['hash'])) { + print_err("checkSpam: _POST array doesn't have key 'hash', check failed."); + dumpVars($extra_salt_orig); return true; + } $hash = $_POST['hash']; @@ -291,6 +332,8 @@ function checkSpam(array $extra_salt = array()) { $_hash = sha1($_hash . $extra_salt); if ($hash != $_hash) { + print_err("checkSpam: Hash values do not match! submitted hash value from POST data: $hash ; Computed hash value: $_hash"); + dumpVars($extra_salt_orig); return true; } @@ -299,6 +342,8 @@ function checkSpam(array $extra_salt = array()) { $query->execute() or error(db_error($query)); if ((($passed = $query->fetchColumn(0)) === false) || ($passed > $config['spam']['hidden_inputs_max_pass'])) { // there was no database entry for this hash. most likely expired. + print_err("checkSpam: there was no database entry for this hash. most likely expired. $hash"); + dumpVars($extra_salt_orig); return true; } diff --git a/inc/instance-config.php b/inc/instance-config.php index 6761e72b..adfb254d 100644 --- a/inc/instance-config.php +++ b/inc/instance-config.php @@ -132,7 +132,7 @@ $config['post_date'] = '%F (%a) %T'; $config['thread_subject_in_title'] = true; -$config['spam']['enabled'] = false; +$config['spam']['enabled'] = true; $config['spam_noticer']['enabled'] = true; $config['spam_noticer']['base_url'] = 'http://localhost:8300'; $config['spam_noticer']['ui_url'] = 'https://spamnoticer.leftychan.net/static/index.html'; diff --git a/post.php b/post.php index 22932166..2017746f 100644 --- a/post.php +++ b/post.php @@ -579,9 +579,11 @@ function handle_post(){ ); //$post['antispam_hash'] = checkSpam(); + /* if ($post['antispam_hash'] === true) { error($config['error']['spam']); } + */ } if ($config['robot_enable'] && $config['robot_mute']) {