Files
.github
admin
install
pages_template
qrcode
scan
system
autoload
PEAR2
mail
Admin.php
App.php
Balance.php
File.php
Hookers.php
Http.php
Lang.php
Log.php
Message.php
Mikrotik.php
Package.php
Paginator.php
Password.php
Text.php
Timezone.php
User.php
Validator.php
index.html
cache
controllers
devices
lan
paymentgateway
plugin
uploads
vendor
.htaccess
api.php
boot.php
composer.json
composer.lock
cron.php
cron_reminder.php
index.html
orm.php
updates.json
ui
.gitignore
.htaccess_firewall
CHANGELOG.md
Dockerfile
LICENSE
README.md
composer.json
config.sample.php
docker-compose.example.yml
favicon.ico
index.php
init.php
update.php
version.json
mitrobill/system/autoload/Admin.php

62 lines
1.5 KiB
PHP
Raw Normal View History

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();
$token = $aid . '.' . $time . '.' . sha1($aid . '.' . $time . '.' . $db_password);
setcookie('aid', $token, time() + 86400 * 7);
return $token;
2024-02-12 09:45:44 +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
}