View Admin and Init script

This commit is contained in:
Ibnu Maksum
2024-02-19 14:24:34 +07:00
parent ce649220f5
commit ade714e2ae
15 changed files with 377 additions and 378 deletions

View File

@ -1,35 +1,10 @@
<?php
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
**/
// on some server, it getting error because of slash is backwards
function _autoloader($class)
{
if (strpos($class, '_') !== false) {
$class = str_replace('_', DIRECTORY_SEPARATOR, $class);
if (file_exists('autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
include __DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
}
} else {
if (file_exists('autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
include 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
} else {
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
if (file_exists(__DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
include __DIR__ . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
}
}
}
spl_autoload_register('_autoloader');
function r2($to, $ntype = 'e', $msg = '')
{
if ($msg == '') {
@ -48,75 +23,8 @@ if (file_exists('config.php')) {
r2('install');
}
function safedata($value)
{
$value = trim($value);
return $value;
}
function _post($param, $defvalue = '')
{
if (!isset($_POST[$param])) {
return $defvalue;
} else {
return safedata($_POST[$param]);
}
}
function _get($param, $defvalue = '')
{
if (!isset($_GET[$param])) {
return $defvalue;
} else {
return safedata($_GET[$param]);
}
}
function _req($param, $defvalue = '')
{
if (!isset($_REQUEST[$param])) {
return $defvalue;
} else {
return safedata($_REQUEST[$param]);
}
}
try {
require_once File::pathFixer('system/orm.php');
ORM::configure("mysql:host=$db_host;dbname=$db_name");
ORM::configure('username', $db_user);
ORM::configure('password', $db_password);
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
ORM::configure('return_result_sets', true);
if ($_app_stage != 'Live') {
ORM::configure('logging', true);
}
$result = ORM::for_table('tbl_appconfig')->find_many();
foreach ($result as $value) {
$config[$value['setting']] = $value['value'];
}
date_default_timezone_set($config['timezone']);
$_c = $config;
// check if proxy setup in database
if (empty($http_proxy) && !empty($config['http_proxy'])) {
$http_proxy = $config['http_proxy'];
if (empty($http_proxyauth) && !empty($config['http_proxyauth'])) {
$http_proxyauth = $config['http_proxyauth'];
}
}
if ((!empty($radius_user) && $config['radius_enable']) || _post('radius_enable')) {
ORM::configure("mysql:host=$radius_host;dbname=$radius_name", null, 'radius');
ORM::configure('username', $radius_user, 'radius');
ORM::configure('password', $radius_pass, 'radius');
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'), 'radius');
ORM::configure('return_result_sets', true, 'radius');
}
require_once 'init.php';
} catch (Throwable $e) {
$ui = new Smarty();
$ui->setTemplateDir(['custom' => File::pathFixer('ui/ui_custom/'), 'default' => File::pathFixer('ui/ui/')]);
@ -154,18 +62,6 @@ function _notify($msg, $type = 'e')
$_SESSION['ntype'] = $type;
$_SESSION['notify'] = $msg;
}
if (empty($config['language'])) {
$config['language'] = 'english';
}
$lan_file = File::pathFixer('system/lan/' . $config['language'] . '.json');
if (file_exists($lan_file)) {
$_L = json_decode(file_get_contents($lan_file), true);
$_SESSION['Lang'] = $_L;
} else {
$_L['author'] = 'Auto Generated by iBNuX Script';
$_SESSION['Lang'] = $_L;
file_put_contents($lan_file, json_encode($_L));
}
$ui = new Smarty();
$ui->assign('_kolaps', $_COOKIE['kolaps']);
@ -190,7 +86,6 @@ $ui->assign('_path', __DIR__);
$ui->assign('_c', $config);
$ui->assign('_L', $_L);
$ui->assign('_system_menu', 'dashboard');
$ui->assign('_title', $config['CompanyName']);
function _msglog($type, $msg)
{
@ -207,24 +102,6 @@ if (isset($_SESSION['notify'])) {
unset($_SESSION['ntype']);
}
include "autoload/Hookers.php";
// notification message
if (file_exists(File::pathFixer("system/uploads/notifications.json"))) {
$_notifmsg = json_decode(file_get_contents(File::pathFixer('system/uploads/notifications.json')), true);
}
$_notifmsg_default = json_decode(file_get_contents(File::pathFixer('system/uploads/notifications.default.json')), true);
//register all plugin
foreach (glob(File::pathFixer("system/plugin/*.php")) as $filename) {
try {
include $filename;
} catch (Throwable $e) {
} catch (Exception $e) {
}
}
function _auth($login = true)
{
if (User::getID()) {
@ -290,37 +167,6 @@ function sendWhatsapp($phone, $txt)
}
function time_elapsed_string($datetime, $full = false)
{
$now = new DateTime;
$ago = new DateTime($datetime);
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7);
$diff->d -= $diff->w * 7;
$string = array(
'y' => 'year',
'm' => 'month',
'w' => 'week',
'd' => 'day',
'h' => 'hour',
'i' => 'minute',
's' => 'second',
);
foreach ($string as $k => &$v) {
if ($diff->$k) {
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
} else {
unset($string[$k]);
}
}
if (!$full)
$string = array_slice($string, 0, 1);
return $string ? implode(', ', $string) . ' ago' : 'just now';
}
// Routing Engine
$req = _get('_route');
$routes = explode('/', $req);