Esempio n. 1
0
function check_login()
{
    global $db, $mem;
    if (defined('MEM') && MEM == True) {
        $mem = new Memcached('moyoj');
        $mem->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
        if (!count($mem->getServerList())) {
            $mem->addServer(MEM_HOST, MEM_PORT);
        }
    }
    $db = new DB();
    $db->init(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    $db->connect();
    $admin_info = mo_read_cache('mo-admin-' . $_SESSION['aid']);
    if (!$admin_info) {
        $sql = 'SELECT `id`, `username`, `password`, `nickname`, `role` FROM `mo_admin` WHERE `id` = ? AND `role` > 0';
        $db->prepare($sql);
        $db->bind('i', $_SESSION['aid']);
        $result = $db->execute();
        if (!$result || $result[0]['password'] != $_SESSION['admin_password']) {
            unset($_SESSION['aid']);
            header("Location: login.php");
            exit(0);
        }
        mo_write_cache('mo-admin-' . $_SESSION['aid'], $result[0]);
    }
    $mo_settings = array();
    mo_load_settings();
    if (!isset($active)) {
        $active = '';
    }
}
Esempio n. 2
0
function mo_set_option($option, $data)
{
    global $mo_settings, $db;
    if (is_array($data) || is_object($data)) {
        $to_write = serialize($data);
    } else {
        $to_write = $data;
    }
    if (isset($mo_settings[$option])) {
        $rt = $mo_settings[$option];
        $mo_settings[$option] = $data;
        $sql = 'UPDATE `mo_site_options` SET `value` = ? WHERE `item` = ?';
        $db->prepare($sql);
        $db->bind('ss', $to_write, $option);
    } else {
        $rt = True;
        $mo_settings[$option] = $data;
        $sql = 'INSERT INTO `mo_site_options` (`item`, `value`) VALUES (?, ?)';
        $db->prepare($sql);
        $db->bind('ss', $option, $to_write);
    }
    $db->execute();
    mo_write_cache('mo_cache_settings', $mo_settings);
    mo_write_note("Site option: '{$option}' has been update.");
    return $rt;
}
Esempio n. 3
0
        if (!count($mem->getServerList())) {
            $mem->addServer(MEM_HOST, MEM_PORT);
        }
    }
    $db = new DB();
    $db->init(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    $db->connect();
    $sql = 'SELECT `id`, `username`, `password`, `nickname`, `role` FROM `mo_admin` WHERE `username` = ? AND `role` > 0 LIMIT 1';
    $db->prepare($sql);
    $db->bind('s', $_POST['username']);
    $result = $db->execute();
    if ($result && password_verify($_POST['password'], $result[0]['password'])) {
        $result = $result[0];
        $_SESSION['aid'] = $result['id'];
        $_SESSION['admin_password'] = $result['password'];
        mo_write_cache('mo-admin-' . $_SESSION['aid'], $result);
    } else {
        $loginfail = True;
    }
}
if (isset($_GET['action']) && $_GET['action'] == 'logout') {
    unset($_SESSION['aid']);
    unset($_SESSION['admin_password']);
    $logout = True;
}
if (isset($_SESSION['aid'])) {
    header("Location: index.php");
    exit(0);
}
?>
<!DOCTYPE html>