예제 #1
0
파일: jxbot.php 프로젝트: jhawcroft/jxbot
 public static function run_admin()
 {
     JxBotConfig::setup_environment();
     require_once dirname(__FILE__) . '/admin.php';
     session_name(JxBotConfig::SESSION_NAME);
     session_start();
     JxBotAdmin::admin_generate();
 }
예제 #2
0
파일: admin.php 프로젝트: jhawcroft/jxbot
    public static function check_and_login()
    {
        $inputs = JxBotUtil::inputs('username,password');
        /* check the user hasn't logged in too often recently */
        $stmt = JxBotDB::$db->prepare('SELECT COUNT(*) FROM login
			WHERE stamp > DATE_SUB(NOW(), INTERVAL 1 MINUTE)
				AND username=?');
        $stmt->execute(array($inputs['username']));
        $recent_logins = intval($stmt->fetchAll(PDO::FETCH_NUM)[0][0]);
        if ($recent_logins > 5) {
            return false;
        }
        /* are credentials wrong? */
        if (JxBotConfig::option('admin_user') != $inputs['username'] || JxBotConfig::option('admin_hash') != hash('sha256', $inputs['password'])) {
            $stmt = JxBotDB::$db->prepare('INSERT INTO login
				(username, note) VALUES (?, ?)');
            $stmt->execute(array($inputs['username'], 'failure'));
            return false;
        }
        /* do the login */
        $_SESSION['jxbot-admin'] = 1;
        $stmt = JxBotDB::$db->prepare('INSERT INTO login
			(username, note) VALUES (?, ?)');
        $stmt->execute(array($inputs['username'], 'success'));
        $_SESSION['jxbot-last'] = time();
        /* generate the admin page */
        JxBotAdmin::admin_generate();
        return true;
    }