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-07-29 09:06:27 +07:00
|
|
|
global $db_pass, $config;
|
2024-07-31 22:04:28 +07:00
|
|
|
$enable_session_timeout = $config['enable_session_timeout'];
|
|
|
|
if ($enable_session_timeout) {
|
|
|
|
$session_timeout_duration = intval($config['session_timeout_duration']) * 60; // Convert minutes to seconds
|
|
|
|
}
|
2024-07-27 00:56:48 +01:00
|
|
|
|
|
|
|
if (isset($_SESSION['aid']) && isset($_SESSION['aid_expiration']) && $_SESSION['aid_expiration'] > time()) {
|
2024-02-12 09:45:44 +07:00
|
|
|
return $_SESSION['aid'];
|
2024-07-27 00:56:48 +01:00
|
|
|
} elseif ($enable_session_timeout && isset($_SESSION['aid']) && isset($_SESSION['aid_expiration']) && $_SESSION['aid_expiration'] <= time()) {
|
|
|
|
self::removeCookie();
|
|
|
|
session_destroy();
|
|
|
|
_alert(Lang::T('Session has expired. Please log in again.'), 'danger', "admin");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// Check if cookie is set and valid
|
|
|
|
elseif (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']);
|
2024-07-29 09:06:27 +07:00
|
|
|
if (sha1($tmp[0] . '.' . $tmp[1] . '.' . $db_pass) == $tmp[2]) {
|
2024-02-26 14:38:04 +07:00
|
|
|
if (time() - $tmp[1] < 86400 * 7) {
|
2024-02-12 09:45:44 +07:00
|
|
|
$_SESSION['aid'] = $tmp[0];
|
2024-07-27 00:56:48 +01:00
|
|
|
if ($enable_session_timeout) {
|
|
|
|
$_SESSION['aid_expiration'] = time() + $session_timeout_duration;
|
|
|
|
}
|
2024-02-12 09:45:44 +07:00
|
|
|
return $tmp[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-27 00:56:48 +01:00
|
|
|
|
2024-02-12 09:45:44 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-02-26 14:38:04 +07:00
|
|
|
public static function setCookie($aid)
|
|
|
|
{
|
2024-07-29 09:06:27 +07:00
|
|
|
global $db_pass, $config;
|
2024-07-27 00:56:48 +01:00
|
|
|
$enable_session_timeout = $config['enable_session_timeout'];
|
|
|
|
$session_timeout_duration = $config['session_timeout_duration'] * 60; // Convert minutes to seconds
|
2024-02-26 14:38:04 +07:00
|
|
|
if (isset($aid)) {
|
2024-02-12 09:45:44 +07:00
|
|
|
$time = time();
|
2024-07-29 09:06:27 +07:00
|
|
|
$token = $aid . '.' . $time . '.' . sha1($aid . '.' . $time . '.' . $db_pass);
|
2024-04-01 13:01:21 +07:00
|
|
|
setcookie('aid', $token, time() + 86400 * 7);
|
2024-07-27 00:56:48 +01:00
|
|
|
$_SESSION['aid'] = $aid;
|
|
|
|
if ($enable_session_timeout) {
|
|
|
|
$_SESSION['aid_expiration'] = $time + $session_timeout_duration;
|
|
|
|
}
|
2024-04-01 13:01:21 +07:00
|
|
|
return $token;
|
2024-02-12 09:45:44 +07:00
|
|
|
}
|
2024-04-01 13:01:21 +07:00
|
|
|
return '';
|
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-27 07:12:02 +07:00
|
|
|
return null;
|
2024-02-26 11:25:15 +07:00
|
|
|
}
|
2017-03-11 02:51:06 +07:00
|
|
|
}
|
2024-02-26 14:38:04 +07:00
|
|
|
}
|