diff --git a/inc/config.php b/inc/config.php index 164c1f1a..3bb24b85 100644 --- a/inc/config.php +++ b/inc/config.php @@ -67,6 +67,9 @@ define('ERROR_INVALID', 'Invalid username and/or password.', true); define('ERROR_INVALIDAFTER', 'Invalid username and/or password. Your user may have been deleted or changed.'); define('ERROR_MALFORMED','Invalid/malformed cookies.', true); + define('ERROR_MISSEDAFIELD', 'Your browser didn\'t submit an input when it should have.', true); + define('ERROR_REQUIRED', 'The %s field is required.', true); + define('ERROR_INVALIDFIELD', 'The %s field was invalid.', true); // For resizing, max values define('THUMB_WIDTH', 200, true); @@ -132,6 +135,10 @@ // The page that is first shown when a moderator logs in. Defaults to the dashboard. define('MOD_DEFAULT', '/', true); + define('MOD_JANITOR', 0, true); + define('MOD_MOD', 1, true); + define('MOD_ADMIN', 2, true); + // A small file in the main directory indicating that the script has been ran and the board(s) have been generated. // This keeps the script from querying the database and causing strain when not needed. define('HAS_INSTALLED', '.installed', true); @@ -139,7 +146,7 @@ // Name of the boards. Typically '/%s/' (/b/, /mu/, etc) // BOARD_ABBREVIATION - BOARD_TITLE define('BOARD_ABBREVIATION', '/%s/', true); - + // Automatically convert things like "..." to Unicode characters ("…") define('AUTO_UNICODE', true, true); // Use some Wiki-like syntax (''em'', '''strong''', ==Heading==, etc) diff --git a/inc/mod.php b/inc/mod.php index 00f94544..83e4cfdf 100644 --- a/inc/mod.php +++ b/inc/mod.php @@ -1,8 +1,96 @@ - $user['id'], + 'type' => $user['type'], + 'username' => $username, + 'password' => $password, + 'hash' => isset($_SESSION['mod']['hash']) ? $_SESSION['mod']['hash'] : mkhash() + ); + } else return false; + } + + function setCookies() { + global $mod; + if(!$mod) error('setCookies() was called for a non-moderator!'); + + // MOD_COOKIE contains username:hash + setcookie(MOD_COOKIE, $mod['username'] . ':' . $mod['hash'], time()+COOKIE_EXPIRE, JAIL_COOKIES?ROOT:'/', null, false, true); + + // Put $mod in the session + $_SESSION['mod'] = $mod; + + // Lock sessions to IP addresses + if(MOD_LOCK_IP) + $_SESSION['mod']['ip'] = $_SERVER['REMOTE_ADDR']; + } + + function destroyCookies() { + // Delete the cookies + setcookie(MOD_COOKIE, 'deleted', time()-COOKIE_EXPIRE, JAIL_COOKIES?ROOT:'/', null, false, true); + + // Unset the session + unset($_SESSION['mod']); + } + + if(isset($_COOKIE['mod']) && isset($_SESSION['mod']) && is_array($_SESSION['mod'])) { + // Should be username:session hash + $cookie = explode(':', $_COOKIE['mod']); + if(count($cookie) != 2) { + destroyCookies(); + error(ERROR_MALFORMED); + } + + // Validate session + if( $cookie[0] != $_SESSION['mod']['username'] || + $cookie[1] != $_SESSION['mod']['hash']) { + // Malformed cookies + destroyCookies(); + error(ERROR_MALFORMED); + } + + // Open connection + sql_open(); + + // Check username/password + if(!login($_SESSION['mod']['username'], $_SESSION['mod']['password'], false)) { + destroyCookies(); + error(ERROR_INVALIDAFTER); + } + + } + // Generates a