phpnuxbill/system/autoload/Admin.php

58 lines
1.4 KiB
PHP
Raw Normal View History

2017-03-11 03:51:06 +08:00
<?php
2024-02-26 15:38:04 +08:00
2017-03-11 03:51:06 +08:00
/**
2023-10-12 16:55:42 +08:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
**/
2017-03-11 03:51:06 +08:00
2024-02-26 15:38:04 +08:00
class Admin
{
2024-02-12 10:45:44 +08:00
2024-02-26 15:38:04 +08:00
public static function getID()
{
2024-02-12 10:45:44 +08:00
global $db_password;
2024-02-26 15:38:04 +08:00
if (isset($_SESSION['aid'])) {
2024-02-12 10:45:44 +08:00
return $_SESSION['aid'];
2024-02-26 15:38:04 +08:00
} else if (isset($_COOKIE['aid'])) {
2024-02-12 10:45:44 +08:00
// id.time.sha1
2024-02-26 15:38:04 +08:00
$tmp = explode('.', $_COOKIE['aid']);
if (sha1($tmp[0] . '.' . $tmp[1] . '.' . $db_password) == $tmp[2]) {
if (time() - $tmp[1] < 86400 * 7) {
2024-02-12 10:45:44 +08:00
$_SESSION['aid'] = $tmp[0];
return $tmp[0];
}
}
}
return 0;
}
2024-02-26 15:38:04 +08:00
public static function setCookie($aid)
{
2024-02-12 10:45:44 +08:00
global $db_password;
2024-02-26 15:38:04 +08:00
if (isset($aid)) {
2024-02-12 10:45:44 +08:00
$time = time();
2024-02-26 15:38:04 +08:00
setcookie('aid', $aid . '.' . $time . '.' . sha1($aid . '.' . $time . '.' . $db_password), time() + 86400 * 7);
2024-02-12 10:45:44 +08:00
}
}
2024-02-26 15:38:04 +08:00
public static function removeCookie()
{
if (isset($_COOKIE['aid'])) {
setcookie('aid', '', time() - 86400);
2024-02-12 10:45:44 +08:00
}
}
2024-02-26 15:38:04 +08:00
public static function _info($id = 0)
{
if (empty($id) && $id == 0) {
2024-02-23 15:40:47 +08:00
$id = Admin::getID();
}
2024-02-26 15:38:04 +08:00
if ($id) {
2024-02-26 12:25:15 +08:00
return ORM::for_table('tbl_users')->find_one($id);
2024-02-26 15:38:04 +08:00
} else {
2024-02-27 08:12:02 +08:00
return null;
2024-02-26 12:25:15 +08:00
}
2017-03-11 03:51:06 +08:00
}
2024-02-26 15:38:04 +08:00
}