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