mirror of
https://github.com/hotspotbilling/phpnuxbill.git
synced 2025-02-23 15:07:19 +08:00
154 lines
No EOL
5.4 KiB
PHP
154 lines
No EOL
5.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
|
* by https://t.me/ibnux
|
|
**/
|
|
|
|
if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])) {
|
|
header('HTTP/1.0 403 Forbidden', TRUE, 403);
|
|
header('location: ../');
|
|
die();
|
|
}
|
|
$root_path = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
|
|
$isApi = false;
|
|
// on some server, it getting error because of slash is backwards
|
|
function _autoloader($class)
|
|
{
|
|
global $root_path;
|
|
if (strpos($class, '_') !== false) {
|
|
$class = str_replace('_', DIRECTORY_SEPARATOR, $class);
|
|
if (file_exists($root_path . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
|
|
include $root_path . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
|
|
} else {
|
|
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
|
|
if (file_exists($root_path . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
|
|
include $root_path . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
|
|
}
|
|
} else {
|
|
if (file_exists($root_path . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php')) {
|
|
include $root_path . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
|
|
} else {
|
|
$class = str_replace("\\", DIRECTORY_SEPARATOR, $class);
|
|
if (file_exists($root_path . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php'))
|
|
include $root_path . DIRECTORY_SEPARATOR . 'system' . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . $class . '.php';
|
|
}
|
|
}
|
|
}
|
|
spl_autoload_register('_autoloader');
|
|
|
|
|
|
if (!file_exists($root_path . 'config.php')) {
|
|
$root_path .= '..' . DIRECTORY_SEPARATOR;
|
|
if (!file_exists($root_path . 'config.php')) {
|
|
die("config.php file not found");
|
|
}
|
|
}
|
|
|
|
|
|
if (!file_exists($root_path . File::pathFixer('system/orm.php'))) {
|
|
die($root_path . "orm.php file not found");
|
|
}
|
|
|
|
if (!file_exists($root_path . File::pathFixer('system/uploads/notifications.default.json'))) {
|
|
die($root_path . File::pathFixer("system/uploads/notifications.default.json file not found"));
|
|
}
|
|
|
|
require_once $root_path . 'config.php';
|
|
require_once $root_path . File::pathFixer('system/orm.php');
|
|
require_once $root_path . File::pathFixer('system/autoload/PEAR2/Autoload.php');
|
|
include $root_path . File::pathFixer('system/autoload/Hookers.php');
|
|
|
|
ORM::configure("mysql:host=$db_host;dbname=$db_name");
|
|
ORM::configure('username', $db_user);
|
|
ORM::configure('password', $db_password);
|
|
ORM::configure('return_result_sets', true);
|
|
if ($_app_stage != 'Live') {
|
|
ORM::configure('logging', true);
|
|
}
|
|
|
|
|
|
// notification message
|
|
if (file_exists($root_path . File::pathFixer("system/uploads/notifications.json"))) {
|
|
$_notifmsg = json_decode(file_get_contents($root_path . File::pathFixer('system/uploads/notifications.json')), true);
|
|
}
|
|
$_notifmsg_default = json_decode(file_get_contents($root_path . File::pathFixer('system/uploads/notifications.default.json')), true);
|
|
|
|
//register all plugin
|
|
foreach (glob(File::pathFixer($root_path . File::pathFixer("system/plugin/*.php"))) as $filename) {
|
|
try {
|
|
include $filename;
|
|
} catch (Throwable $e) {
|
|
//ignore plugin error
|
|
} catch (Exception $e) {
|
|
//ignore plugin error
|
|
}
|
|
}
|
|
|
|
$result = ORM::for_table('tbl_appconfig')->find_many();
|
|
foreach ($result as $value) {
|
|
$config[$value['setting']] = $value['value'];
|
|
}
|
|
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'];
|
|
}
|
|
}
|
|
date_default_timezone_set($config['timezone']);
|
|
|
|
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');
|
|
}
|
|
|
|
|
|
if (empty($config['language'])) {
|
|
$config['language'] = 'english';
|
|
}
|
|
$lan_file = $root_path .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));
|
|
}
|
|
|
|
|
|
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]);
|
|
}
|
|
} |