bindValue(':username', $username); $query->bindValue(':password', $password); $query->execute() or error(db_error($query)); if ($user = $query->fetch()) { return $mod = Array( 'id' => $user['id'], 'type' => $user['type'], 'username' => $username, 'hash' => mkhash($username, $password), 'boards' => explode(',', $user['boards']) ); } else return false; } function setCookies() { global $mod, $config; if (!$mod) error('setCookies() was called for a non-moderator!'); setcookie($config['cookies']['mod'], $mod['username'] . // username ':' . $mod['hash'][0] . // password ':' . $mod['hash'][1], // salt time() + $config['cookies']['expire'], $config['cookies']['jail'] ? $config['cookies']['path'] : '/', null, false, true); } function destroyCookies() { global $config; // Delete the cookies setcookie($config['cookies']['mod'], 'deleted', time() - $config['cookies']['expire'], $config['cookies']['jail']?$config['cookies']['path'] : '/', null, false, true); } function modLog($action, $_board=null) { global $mod, $board, $config; $query = prepare("INSERT INTO `modlogs` VALUES (:id, :ip, :board, :time, :text)"); $query->bindValue(':id', $mod['id'], PDO::PARAM_INT); $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); $query->bindValue(':time', time(), PDO::PARAM_INT); $query->bindValue(':text', $action); if (isset($_board)) $query->bindValue(':board', $_board); elseif (isset($board)) $query->bindValue(':board', $board['uri']); else $query->bindValue(':board', null, PDO::PARAM_NULL); $query->execute() or error(db_error($query)); if ($config['syslog']) _syslog(LOG_INFO, '[mod/' . $mod['username'] . ']: ' . $action); } // Validate session if (isset($_COOKIE[$config['cookies']['mod']])) { // Should be username:hash:salt $cookie = explode(':', $_COOKIE[$config['cookies']['mod']]); if (count($cookie) != 3) { destroyCookies(); error($config['error']['malformed']); } $query = prepare("SELECT `id`, `type`, `boards`, `password` FROM `mods` WHERE `username` = :username LIMIT 1"); $query->bindValue(':username', $cookie[0]); $query->execute() or error(db_error($query)); $user = $query->fetch(); // validate password hash if ($cookie[1] != mkhash($cookie[0], $user['password'], $cookie[2])) { // Malformed cookies destroyCookies(); error($config['error']['malformed']); } $mod = Array( 'id' => $user['id'], 'type' => $user['type'], 'username' => $cookie[0], 'boards' => explode(',', $user['boards']) ); } function create_pm_header() { global $mod, $config; if ($config['cache']['enabled'] && ($header = cache::get('pm_unread_' . $mod['id'])) !== false) { if ($header === true) return false; return $header; } $query = prepare("SELECT `id` FROM `pms` WHERE `to` = :id AND `unread` = 1"); $query->bindValue(':id', $mod['id'], PDO::PARAM_INT); $query->execute() or error(db_error($query)); if ($pm = $query->fetch()) $header = Array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1); else $header = true; if ($config['cache']['enabled']) cache::set('pm_unread_' . $mod['id'], $header); if ($header === true) return false; return $header; } function make_secure_link_token($uri) { global $mod, $config; return substr(sha1($config['cookies']['salt'] . '-' . $uri . '-' . $mod['id']), 0, 8); }