mitrobill/system/boot.php

170 lines
6.5 KiB
PHP
Raw Permalink Normal View History

2017-03-11 02:51:06 +07:00
<?php
2024-02-19 14:24:34 +07:00
2017-03-11 02:51:06 +07:00
/**
2022-10-16 14:50:24 +07:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
2021-08-19 13:38:29 +07:00
**/
2023-09-06 10:48:52 +07:00
2023-09-14 13:53:28 +07:00
try {
2024-02-19 14:24:34 +07:00
require_once 'init.php';
2024-01-17 10:54:31 +07:00
} catch (Throwable $e) {
2024-06-16 16:19:55 +07:00
die($e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre>');
2023-09-14 13:53:28 +07:00
} catch (Exception $e) {
2024-06-16 16:19:55 +07:00
die($e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre>');
2022-10-03 11:03:56 +07:00
}
2021-08-19 13:38:29 +07:00
function _notify($msg, $type = 'e')
{
$_SESSION['ntype'] = $type;
$_SESSION['notify'] = $msg;
2017-03-11 02:51:06 +07:00
}
2023-10-12 16:15:50 +07:00
2017-03-11 02:51:06 +07:00
$ui = new Smarty();
2024-02-13 16:22:00 +07:00
$ui->assign('_kolaps', $_COOKIE['kolaps']);
2023-10-12 16:15:50 +07:00
if (!empty($config['theme']) && $config['theme'] != 'default') {
2024-02-26 14:38:04 +07:00
$_theme = APP_URL . '/' . $UI_PATH . '/themes/' . $config['theme'];
$ui->setTemplateDir([
'custom' => File::pathFixer($UI_PATH . '/ui_custom/'),
'theme' => File::pathFixer($UI_PATH . '/themes/' . $config['theme']),
'default' => File::pathFixer($UI_PATH . '/ui/')
]);
2023-10-12 16:15:50 +07:00
} else {
2024-02-26 14:38:04 +07:00
$_theme = APP_URL . '/' . $UI_PATH . '/ui';
$ui->setTemplateDir([
'custom' => File::pathFixer($UI_PATH . '/ui_custom/'),
'default' => File::pathFixer($UI_PATH . '/ui/')
]);
2023-10-12 16:15:50 +07:00
}
$ui->assign('_theme', $_theme);
2024-02-26 14:38:04 +07:00
$ui->addTemplateDir($PAYMENTGATEWAY_PATH . File::pathFixer('/ui/'), 'pg');
$ui->addTemplateDir($PLUGIN_PATH . File::pathFixer('/ui/'), 'plugin');
$ui->setCompileDir(File::pathFixer($UI_PATH . '/compiled/'));
$ui->setConfigDir(File::pathFixer($UI_PATH . '/conf/'));
$ui->setCacheDir(File::pathFixer($UI_PATH . '/cache/'));
2017-03-11 02:51:06 +07:00
$ui->assign('app_url', APP_URL);
2022-09-17 21:03:47 +07:00
$ui->assign('_domain', str_replace('www.', '', parse_url(APP_URL, PHP_URL_HOST)));
2024-08-14 16:54:14 +07:00
$ui->assign('_url', APP_URL . '/?_route=');
$ui->assign('_path', __DIR__);
2017-03-11 02:51:06 +07:00
$ui->assign('_c', $config);
$ui->assign('user_language', $_SESSION['user_language']);
2024-03-01 13:44:46 +07:00
$ui->assign('UPLOAD_PATH', str_replace($root_path, '', $UPLOAD_PATH));
$ui->assign('CACHE_PATH', str_replace($root_path, '', $CACHE_PATH));
$ui->assign('PAGES_PATH', str_replace($root_path, '', $PAGES_PATH));
2017-03-11 02:51:06 +07:00
$ui->assign('_system_menu', 'dashboard');
2021-08-19 13:38:29 +07:00
function _msglog($type, $msg)
{
2017-03-11 02:51:06 +07:00
$_SESSION['ntype'] = $type;
$_SESSION['notify'] = $msg;
}
if (isset($_SESSION['notify'])) {
$notify = $_SESSION['notify'];
$ntype = $_SESSION['ntype'];
2023-10-20 14:07:49 +07:00
$ui->assign('notify', $notify);
$ui->assign('notify_t', $ntype);
2017-03-11 02:51:06 +07:00
unset($_SESSION['notify']);
unset($_SESSION['ntype']);
}
2025-02-07 15:18:41 +07:00
if (!isset($_GET['_route'])) {
$req = ltrim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
$len = strlen(ltrim(parse_url(APP_URL, PHP_URL_PATH), '/'));
if ($len > 0) {
$req = ltrim(substr($req, $len), '/');
}
} else {
2024-08-14 16:54:14 +07:00
// Routing Engine
$req = _get('_route');
}
2025-02-07 15:18:41 +07:00
2017-03-11 02:51:06 +07:00
$routes = explode('/', $req);
2022-09-17 22:34:55 +07:00
$ui->assign('_routes', $routes);
$handler = $routes[0];
2017-03-11 02:51:06 +07:00
if ($handler == '') {
$handler = 'default';
}
2023-09-14 13:45:35 +07:00
try {
2025-02-07 15:18:41 +07:00
if (!empty($_GET['uid'])) {
$_COOKIE['uid'] = $_GET['uid'];
2024-11-04 13:57:28 +07:00
}
2024-10-11 11:07:47 +07:00
$admin = Admin::_info();
2024-02-26 14:38:04 +07:00
$sys_render = $root_path . File::pathFixer('system/controllers/' . $handler . '.php');
2023-09-14 13:45:35 +07:00
if (file_exists($sys_render)) {
$menus = array();
// "name" => $name,
// "admin" => $admin,
// "position" => $position,
// "function" => $function
$ui->assign('_system_menu', $routes[0]);
foreach ($menu_registered as $menu) {
2024-01-17 10:54:31 +07:00
if ($menu['admin'] && _admin(false)) {
2024-02-26 14:38:04 +07:00
if (count($menu['auth']) == 0 || in_array($admin['user_type'], $menu['auth'])) {
2025-01-31 16:22:58 +07:00
$menus[$menu['position']] .= '<li' . (($routes[1] == $menu['function']) ? ' class="active"' : '') . '><a href="' . getUrl('plugin/' . $menu['function']) . '">';
2024-02-26 11:25:15 +07:00
if (!empty($menu['icon'])) {
$menus[$menu['position']] .= '<i class="' . $menu['icon'] . '"></i>';
}
if (!empty($menu['label'])) {
$menus[$menu['position']] .= '<span class="pull-right-container">';
$menus[$menu['position']] .= '<small class="label pull-right bg-' . $menu['color'] . '">' . $menu['label'] . '</small></span>';
}
$menus[$menu['position']] .= '<span class="text">' . $menu['name'] . '</span></a></li>';
2024-01-17 10:54:31 +07:00
}
} else if (!$menu['admin'] && _auth(false)) {
2025-01-31 16:22:58 +07:00
$menus[$menu['position']] .= '<li' . (($routes[1] == $menu['function']) ? ' class="active"' : '') . '><a href="' . getUrl('plugin/' . $menu['function']) . '">';
2024-01-17 10:54:31 +07:00
if (!empty($menu['icon'])) {
$menus[$menu['position']] .= '<i class="' . $menu['icon'] . '"></i>';
}
if (!empty($menu['label'])) {
$menus[$menu['position']] .= '<span class="pull-right-container">';
$menus[$menu['position']] .= '<small class="label pull-right bg-' . $menu['color'] . '">' . $menu['label'] . '</small></span>';
}
$menus[$menu['position']] .= '<span class="text">' . $menu['name'] . '</span></a></li>';
}
}
2023-09-14 13:45:35 +07:00
foreach ($menus as $k => $v) {
$ui->assign('_MENU_' . $k, $v);
}
unset($menus, $menu_registered);
include($sys_render);
} else {
2025-02-12 11:50:04 +07:00
if( empty($_SERVER["HTTP_SEC_FETCH_DEST"]) || $_SERVER["HTTP_SEC_FETCH_DEST"] != 'document' ){
// header 404
header("HTTP/1.0 404 Not Found");
header("Content-Type: text/html; charset=utf-8");
echo "404 Not Found";
die();
}else{
r2(getUrl('login'));
}
2022-09-17 22:34:55 +07:00
}
2024-01-17 10:54:31 +07:00
} catch (Throwable $e) {
2024-06-26 17:38:33 +07:00
Message::sendTelegram(
"Sistem Error.\n" .
$e->getMessage() . "\n" .
$e->getTraceAsString()
);
2024-10-11 11:07:47 +07:00
if (empty($_SESSION['aid'])) {
2025-02-07 15:18:41 +07:00
$ui->display('customer/error.tpl');
die();
2024-01-17 10:54:31 +07:00
}
$ui->assign("error_message", $e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre>');
$ui->assign("error_title", "PHPNuxBill Crash");
2025-02-04 10:56:02 +07:00
$ui->display('admin/error.tpl');
2024-06-26 17:38:33 +07:00
die();
} catch (Exception $e) {
2024-06-03 15:47:49 +07:00
Message::sendTelegram(
"Sistem Error.\n" .
$e->getMessage() . "\n" .
$e->getTraceAsString()
);
2024-10-11 11:07:47 +07:00
if (empty($_SESSION['aid'])) {
2025-02-07 15:18:41 +07:00
$ui->display('customer/error.tpl');
die();
2023-11-17 14:38:20 +07:00
}
2023-10-12 16:15:50 +07:00
$ui->assign("error_message", $e->getMessage() . '<br><pre>' . $e->getTraceAsString() . '</pre>');
2023-11-17 14:38:20 +07:00
$ui->assign("error_title", "PHPNuxBill Crash");
2025-02-04 10:56:02 +07:00
$ui->display('admin/error.tpl');
2023-09-14 13:45:35 +07:00
die();
2023-09-14 13:53:28 +07:00
}