2017-03-11 03:51:06 +08:00
|
|
|
|
<?php
|
2021-08-19 14:38:29 +08:00
|
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
|
/**
|
2021-08-19 14:38:29 +08:00
|
|
|
|
* PHP Mikrotik Billing (https://ibnux.github.io/phpmixbill/)
|
2017-03-24 14:26:14 +08:00
|
|
|
|
|
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
* @copyright Copyright (C) 2014-2015 PHP Mikrotik Billing
|
|
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
2017-03-24 14:26:14 +08:00
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
**/
|
2017-03-11 03:51:06 +08:00
|
|
|
|
session_start();
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function r2($to, $ntype = 'e', $msg = '')
|
|
|
|
|
{
|
|
|
|
|
if ($msg == '') {
|
|
|
|
|
header("location: $to");
|
|
|
|
|
exit;
|
2017-03-11 03:51:06 +08:00
|
|
|
|
}
|
2021-08-19 14:38:29 +08:00
|
|
|
|
$_SESSION['ntype'] = $ntype;
|
|
|
|
|
$_SESSION['notify'] = $msg;
|
|
|
|
|
header("location: $to");
|
|
|
|
|
exit;
|
2017-03-11 03:51:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (file_exists('system/config.php')) {
|
|
|
|
|
require('system/config.php');
|
|
|
|
|
} else {
|
|
|
|
|
r2('system/install');
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function safedata($value)
|
|
|
|
|
{
|
2017-03-11 03:51:06 +08:00
|
|
|
|
$value = trim($value);
|
|
|
|
|
return $value;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function _post($param, $defvalue = '')
|
|
|
|
|
{
|
|
|
|
|
if (!isset($_POST[$param])) {
|
2017-03-11 03:51:06 +08:00
|
|
|
|
return $defvalue;
|
|
|
|
|
} else {
|
|
|
|
|
return safedata($_POST[$param]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function _get($param, $defvalue = '')
|
|
|
|
|
{
|
|
|
|
|
if (!isset($_GET[$param])) {
|
2017-03-11 03:51:06 +08:00
|
|
|
|
return $defvalue;
|
|
|
|
|
} else {
|
|
|
|
|
return safedata($_GET[$param]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
require('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);
|
|
|
|
|
ORM::configure('logging', true);
|
|
|
|
|
|
|
|
|
|
$result = ORM::for_table('tbl_appconfig')->find_many();
|
2021-08-19 14:38:29 +08:00
|
|
|
|
foreach ($result as $value) {
|
|
|
|
|
$config[$value['setting']] = $value['value'];
|
2017-03-11 03:51:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
date_default_timezone_set($config['timezone']);
|
|
|
|
|
$_c = $config;
|
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function _notify($msg, $type = 'e')
|
|
|
|
|
{
|
|
|
|
|
$_SESSION['ntype'] = $type;
|
|
|
|
|
$_SESSION['notify'] = $msg;
|
2017-03-11 03:51:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
require_once('system/vendors/smarty/libs/Smarty.class.php');
|
2021-08-19 14:38:29 +08:00
|
|
|
|
$_theme = APP_URL . '/ui/theme/' . $config['theme'];
|
2017-03-11 03:51:06 +08:00
|
|
|
|
$lan_file = 'system/lan/' . $config['language'] . '/common.lan.php';
|
|
|
|
|
require($lan_file);
|
|
|
|
|
$ui = new Smarty();
|
|
|
|
|
$ui->setTemplateDir('ui/theme/' . $config['theme'] . '/');
|
|
|
|
|
$ui->setCompileDir('ui/compiled/');
|
|
|
|
|
$ui->setConfigDir('ui/conf/');
|
|
|
|
|
$ui->setCacheDir('ui/cache/');
|
|
|
|
|
$ui->assign('app_url', APP_URL);
|
2021-08-19 14:38:29 +08:00
|
|
|
|
define('U', APP_URL . '/index.php?_route=');
|
|
|
|
|
$ui->assign('_url', APP_URL . '/index.php?_route=');
|
2017-03-11 03:51:06 +08:00
|
|
|
|
$ui->assign('_theme', $_theme);
|
2017-03-19 08:02:14 +08:00
|
|
|
|
$ui->assign('_path', __DIR__);
|
2017-03-11 03:51:06 +08:00
|
|
|
|
$ui->assign('_c', $config);
|
|
|
|
|
$ui->assign('_L', $_L);
|
|
|
|
|
$ui->assign('_system_menu', 'dashboard');
|
|
|
|
|
$ui->assign('_title', $config['CompanyName']);
|
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function _msglog($type, $msg)
|
|
|
|
|
{
|
2017-03-11 03:51:06 +08:00
|
|
|
|
$_SESSION['ntype'] = $type;
|
|
|
|
|
$_SESSION['notify'] = $msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($_SESSION['notify'])) {
|
|
|
|
|
$notify = $_SESSION['notify'];
|
|
|
|
|
$ntype = $_SESSION['ntype'];
|
|
|
|
|
if ($ntype == 's') {
|
2021-08-19 14:38:29 +08:00
|
|
|
|
$ui->assign('notify', '<div class="alert alert-info">
|
2017-03-11 03:51:06 +08:00
|
|
|
|
<button type="button" class="close" data-dismiss="alert">
|
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
|
</button>
|
2021-08-19 14:38:29 +08:00
|
|
|
|
<div>' . $notify . '</div></div>');
|
2017-03-11 03:51:06 +08:00
|
|
|
|
} else {
|
2021-08-19 14:38:29 +08:00
|
|
|
|
$ui->assign('notify', '<div class="alert alert-danger">
|
2017-03-11 03:51:06 +08:00
|
|
|
|
<button type="button" class="close" data-dismiss="alert">
|
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
|
</button>
|
2021-08-19 14:38:29 +08:00
|
|
|
|
<div>' . $notify . '</div></div>');
|
2017-03-11 03:51:06 +08:00
|
|
|
|
}
|
|
|
|
|
unset($_SESSION['notify']);
|
|
|
|
|
unset($_SESSION['ntype']);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 03:25:45 +08:00
|
|
|
|
// on some server, it getting error because of slash is backwards
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function _autoloader($class)
|
|
|
|
|
{
|
2017-03-11 03:51:06 +08:00
|
|
|
|
if (strpos($class, '_') !== false) {
|
2021-08-19 14:38:29 +08:00
|
|
|
|
$class = str_replace('_', '/', $class);
|
|
|
|
|
if (file_exists('autoload/' . $class . '.php')) {
|
2017-03-23 03:25:45 +08:00
|
|
|
|
include 'autoload/' . $class . '.php';
|
2021-08-19 14:38:29 +08:00
|
|
|
|
} else {
|
|
|
|
|
$class = str_replace("\\", "/", $class);
|
|
|
|
|
if (file_exists(__DIR__ . '/autoload/' . $class . '.php'))
|
|
|
|
|
include __DIR__ . '/autoload/' . $class . '.php';
|
2017-03-23 03:25:45 +08:00
|
|
|
|
}
|
2021-08-19 14:38:29 +08:00
|
|
|
|
} else {
|
|
|
|
|
if (file_exists('autoload/' . $class . '.php')) {
|
2017-03-23 03:25:45 +08:00
|
|
|
|
include 'autoload/' . $class . '.php';
|
2021-08-19 14:38:29 +08:00
|
|
|
|
} else {
|
|
|
|
|
$class = str_replace("\\", "/", $class);
|
|
|
|
|
if (file_exists(__DIR__ . '/autoload/' . $class . '.php'))
|
|
|
|
|
include __DIR__ . '/autoload/' . $class . '.php';
|
2017-03-23 03:25:45 +08:00
|
|
|
|
}
|
2017-03-11 03:51:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spl_autoload_register('_autoloader');
|
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function _auth()
|
|
|
|
|
{
|
|
|
|
|
if (isset($_SESSION['uid'])) {
|
2017-03-11 03:51:06 +08:00
|
|
|
|
return true;
|
2021-08-19 14:38:29 +08:00
|
|
|
|
} else {
|
|
|
|
|
r2(U . 'login');
|
2017-03-11 03:51:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function _admin()
|
|
|
|
|
{
|
|
|
|
|
if (isset($_SESSION['aid'])) {
|
2017-03-11 03:51:06 +08:00
|
|
|
|
return true;
|
2021-08-19 14:38:29 +08:00
|
|
|
|
} else {
|
|
|
|
|
r2(U . 'login');
|
2017-03-11 03:51:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function _raid($l)
|
|
|
|
|
{
|
|
|
|
|
$r = substr(str_shuffle(str_repeat('0123456789', $l)), 0, $l);
|
2017-03-11 03:51:06 +08:00
|
|
|
|
return $r;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function _log($description, $type = '', $userid = '0')
|
|
|
|
|
{
|
2017-03-11 03:51:06 +08:00
|
|
|
|
$d = ORM::for_table('tbl_logs')->create();
|
|
|
|
|
$d->date = date('Y-m-d H:i:s');
|
|
|
|
|
$d->type = $type;
|
|
|
|
|
$d->description = $description;
|
|
|
|
|
$d->userid = $userid;
|
|
|
|
|
$d->ip = $_SERVER["REMOTE_ADDR"];
|
|
|
|
|
$d->save();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-19 14:38:29 +08:00
|
|
|
|
function time_elapsed_string($datetime, $full = false)
|
|
|
|
|
{
|
2017-03-11 03:51:06 +08:00
|
|
|
|
$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);
|
|
|
|
|
$handler = $routes['0'];
|
|
|
|
|
if ($handler == '') {
|
|
|
|
|
$handler = 'default';
|
|
|
|
|
}
|
|
|
|
|
$sys_render = 'system/controllers/' . $handler . '.php';
|
|
|
|
|
if (file_exists($sys_render)) {
|
|
|
|
|
include($sys_render);
|
|
|
|
|
} else {
|
2021-08-19 14:38:29 +08:00
|
|
|
|
exit("$sys_render");
|
2017-03-11 03:51:06 +08:00
|
|
|
|
}
|