diff --git a/system/.htaccess b/system/.htaccess new file mode 100644 index 0000000..44c2236 --- /dev/null +++ b/system/.htaccess @@ -0,0 +1,24 @@ + + Order Deny,Allow + Deny from all + + + + Order Allow,Deny + Allow from all + + + + Order Allow,Deny + Allow from all + + + + Order Allow,Deny + Allow from all + + + + Order Allow,Deny + Allow from all + diff --git a/system/api.php b/system/api.php new file mode 100644 index 0000000..751c9d1 --- /dev/null +++ b/system/api.php @@ -0,0 +1,127 @@ +getAll()); + } + function assign($key, $value) + { + $this->assign[$key] = $value; + } + function get($key) + { + if (isset($this->assign[$key])) { + return $this->assign[$key]; + } + return ''; + } + function getTemplateVars($key) + { + if (isset($this->assign[$key])) { + return $this->assign[$key]; + } + return ''; + } + function getAll() + { + return $this->assign; + } +}; + +$req = _get('r'); +# a/c.id.time.md5 +# md5(a/c.id.time.$api_secret) +$token = _req('token'); +$routes = explode('/', $req); +$handler = $routes[0]; + +if (!empty($token)) { + if ($token == $config['api_key']) { + $admin = ORM::for_table('tbl_users')->where('user_type', 'SuperAdmin')->find_one($id); + if (empty($admin)) { + $admin = ORM::for_table('tbl_users')->where('user_type', 'Admin')->find_one($id); + if (empty($admin)) { + showResult(false, Lang::T("Token is invalid")); + } + } + } else { + # validate token + list($tipe, $uid, $time, $sha1) = explode('.', $token); + if (trim($sha1) != sha1($uid . '.' . $time . '.' . $api_secret)) { + showResult(false, Lang::T("Token is invalid")); + } + + #cek token expiration + // 3 bulan + if ($time != 0 && time() - $time > 7776000) { + die("$time != " . (time() - $time)); + showResult(false, Lang::T("Token Expired"), [], ['login' => true]); + } + + if ($tipe == 'a') { + $_SESSION['aid'] = $uid; + $admin = Admin::_info(); + } else if ($tipe == 'c') { + $_SESSION['uid'] = $uid; + } else { + showResult(false, Lang::T("Unknown Token"), [], ['login' => true]); + } + } + + if (!isset($handler) || empty($handler)) { + showResult(true, Lang::T("Token is valid")); + } + + + if ($handler == 'isValid') { + showResult(true, Lang::T("Token is valid")); + } + + if ($handler == 'me') { + $admin = Admin::_info(); + if (!empty($admin['id'])) { + showResult(true, "", $admin); + } else { + showResult(false, Lang::T("Token is invalid")); + } + } +}else{ + unset($_COOKIE); + unset($_SESSION); +} + +try { + $sys_render = File::pathFixer($root_path . 'system/controllers/' . $handler . '.php'); + if (file_exists($sys_render)) { + include($sys_render); + showResult(true, $req, $ui->getAll()); + } else { + showResult(false, Lang::T('Command not found')); + } +} catch (Exception $e) { + showResult(false, $e->getMessage()); +} diff --git a/system/boot.php b/system/boot.php new file mode 100644 index 0000000..c766baf --- /dev/null +++ b/system/boot.php @@ -0,0 +1,168 @@ +setTemplateDir([ + 'custom' => File::pathFixer($UI_PATH . '/ui_custom/'), + 'default' => File::pathFixer($UI_PATH . '/ui/') + ]); + $ui->assign('_url', APP_URL . '/index.php?_route='); + $ui->setCompileDir(File::pathFixer($UI_PATH . '/compiled/')); + $ui->setConfigDir(File::pathFixer($UI_PATH . '/conf/')); + $ui->setCacheDir(File::pathFixer($UI_PATH . '/cache/')); + $ui->assign("error_title", "PHPNuxBill Crash"); + if (_auth()) { + $ui->assign("error_message", $e->getMessage() . '
'); + } else { + $ui->assign("error_message", $e->getMessage() . '
' . $e->getTraceAsString() . '
'); + } + $ui->display('router-error.tpl'); + die(); +} catch (Exception $e) { + $ui = new Smarty(); + $ui->setTemplateDir([ + 'custom' => File::pathFixer($UI_PATH . '/ui_custom/'), + 'default' => File::pathFixer($UI_PATH . '/ui/') + ]); + $ui->assign('_url', APP_URL . '/index.php?_route='); + $ui->setCompileDir(File::pathFixer($UI_PATH . '/compiled/')); + $ui->setConfigDir(File::pathFixer($UI_PATH . '/conf/')); + $ui->setCacheDir(File::pathFixer($UI_PATH . '/cache/')); + $ui->assign("error_title", "PHPNuxBill Crash"); + if (_auth()) { + $ui->assign("error_message", $e->getMessage() . '
'); + } else { + $ui->assign("error_message", $e->getMessage() . '
' . $e->getTraceAsString() . '
'); + } + $ui->display('router-error.tpl'); + die(); +} + +function _notify($msg, $type = 'e') +{ + $_SESSION['ntype'] = $type; + $_SESSION['notify'] = $msg; +} + +$ui = new Smarty(); +$ui->assign('_kolaps', $_COOKIE['kolaps']); +if (!empty($config['theme']) && $config['theme'] != 'default') { + $_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/') + ]); +} else { + $_theme = APP_URL . '/' . $UI_PATH . '/ui'; + $ui->setTemplateDir([ + 'custom' => File::pathFixer($UI_PATH . '/ui_custom/'), + 'default' => File::pathFixer($UI_PATH . '/ui/') + ]); +} +$ui->assign('_theme', $_theme); +$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/')); +$ui->assign('app_url', APP_URL); +$ui->assign('_domain', str_replace('www.', '', parse_url(APP_URL, PHP_URL_HOST))); +$ui->assign('_url', APP_URL . '/index.php?_route='); +$ui->assign('_path', __DIR__); +$ui->assign('_c', $config); +$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)); +$ui->assign('_system_menu', 'dashboard'); + +function _msglog($type, $msg) +{ + $_SESSION['ntype'] = $type; + $_SESSION['notify'] = $msg; +} + +if (isset($_SESSION['notify'])) { + $notify = $_SESSION['notify']; + $ntype = $_SESSION['ntype']; + $ui->assign('notify', $notify); + $ui->assign('notify_t', $ntype); + unset($_SESSION['notify']); + unset($_SESSION['ntype']); +} + +// Routing Engine +$req = _get('_route'); +$routes = explode('/', $req); +$ui->assign('_routes', $routes); +$handler = $routes[0]; +if ($handler == '') { + $handler = 'default'; +} +$admin = Admin::_info(); +try { + $sys_render = $root_path . File::pathFixer('system/controllers/' . $handler . '.php'); + 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) { + if ($menu['admin'] && _admin(false)) { + if (count($menu['auth']) == 0 || in_array($admin['user_type'], $menu['auth'])) { + $menus[$menu['position']] .= ''; + if (!empty($menu['icon'])) { + $menus[$menu['position']] .= ''; + } + if (!empty($menu['label'])) { + $menus[$menu['position']] .= ''; + $menus[$menu['position']] .= '' . $menu['label'] . ''; + } + $menus[$menu['position']] .= '' . $menu['name'] . ''; + } + } else if (!$menu['admin'] && _auth(false)) { + $menus[$menu['position']] .= ''; + if (!empty($menu['icon'])) { + $menus[$menu['position']] .= ''; + } + if (!empty($menu['label'])) { + $menus[$menu['position']] .= ''; + $menus[$menu['position']] .= '' . $menu['label'] . ''; + } + $menus[$menu['position']] .= '' . $menu['name'] . ''; + } + } + foreach ($menus as $k => $v) { + $ui->assign('_MENU_' . $k, $v); + } + unset($menus, $menu_registered); + include($sys_render); + } else { + r2(U . 'dashboard', 'e', 'not found'); + } +} catch (Throwable $e) { + if (!Admin::getID()) { + r2(U . 'home', 'e', $e->getMessage()); + } + $ui->assign("error_message", $e->getMessage() . '
' . $e->getTraceAsString() . '
'); + $ui->assign("error_title", "PHPNuxBill Crash"); + $ui->display('router-error.tpl'); + die(); +} catch (Exception $e) { + if (!Admin::getID()) { + r2(U . 'home', 'e', $e->getMessage()); + } + $ui->assign("error_message", $e->getMessage() . '
' . $e->getTraceAsString() . '
'); + $ui->assign("error_title", "PHPNuxBill Crash"); + $ui->display('router-error.tpl'); + die(); +} diff --git a/system/composer.json b/system/composer.json new file mode 100644 index 0000000..9bded24 --- /dev/null +++ b/system/composer.json @@ -0,0 +1,6 @@ +{ + "require": { + "mpdf/mpdf": "^8.1", + "smarty/smarty": "^4.3" + } +} diff --git a/system/composer.lock b/system/composer.lock new file mode 100644 index 0000000..40d0cae --- /dev/null +++ b/system/composer.lock @@ -0,0 +1,490 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "81c1d3c4b2673fdd2922ac32768d59f1", + "packages": [ + { + "name": "mpdf/mpdf", + "version": "v8.1.6", + "source": { + "type": "git", + "url": "https://github.com/mpdf/mpdf.git", + "reference": "146c7c1dfd21c826b9d5bbfe3c15e52fd933c90f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mpdf/mpdf/zipball/146c7c1dfd21c826b9d5bbfe3c15e52fd933c90f", + "reference": "146c7c1dfd21c826b9d5bbfe3c15e52fd933c90f", + "shasum": "" + }, + "require": { + "ext-gd": "*", + "ext-mbstring": "*", + "mpdf/psr-log-aware-trait": "^2.0 || ^3.0", + "myclabs/deep-copy": "^1.7", + "paragonie/random_compat": "^1.4|^2.0|^9.99.99", + "php": "^5.6 || ^7.0 || ~8.0.0 || ~8.1.0 || ~8.2.0", + "psr/http-message": "^1.0", + "psr/log": "^1.0 || ^2.0 || ^3.0", + "setasign/fpdi": "^2.1" + }, + "require-dev": { + "mockery/mockery": "^1.3.0", + "mpdf/qrcode": "^1.1.0", + "squizlabs/php_codesniffer": "^3.5.0", + "tracy/tracy": "~2.5", + "yoast/phpunit-polyfills": "^1.0" + }, + "suggest": { + "ext-bcmath": "Needed for generation of some types of barcodes", + "ext-xml": "Needed mainly for SVG manipulation", + "ext-zlib": "Needed for compression of embedded resources, such as fonts" + }, + "type": "library", + "autoload": { + "psr-4": { + "Mpdf\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-only" + ], + "authors": [ + { + "name": "Matěj Humpál", + "role": "Developer, maintainer" + }, + { + "name": "Ian Back", + "role": "Developer (retired)" + } + ], + "description": "PHP library generating PDF files from UTF-8 encoded HTML", + "homepage": "https://mpdf.github.io", + "keywords": [ + "pdf", + "php", + "utf-8" + ], + "support": { + "docs": "http://mpdf.github.io", + "issues": "https://github.com/mpdf/mpdf/issues", + "source": "https://github.com/mpdf/mpdf" + }, + "funding": [ + { + "url": "https://www.paypal.me/mpdf", + "type": "custom" + } + ], + "time": "2023-05-03T19:36:43+00:00" + }, + { + "name": "mpdf/psr-log-aware-trait", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/mpdf/psr-log-aware-trait.git", + "reference": "7a077416e8f39eb626dee4246e0af99dd9ace275" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/mpdf/psr-log-aware-trait/zipball/7a077416e8f39eb626dee4246e0af99dd9ace275", + "reference": "7a077416e8f39eb626dee4246e0af99dd9ace275", + "shasum": "" + }, + "require": { + "psr/log": "^1.0 || ^2.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Mpdf\\PsrLogAwareTrait\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Dorison", + "email": "mark@chromatichq.com" + }, + { + "name": "Kristofer Widholm", + "email": "kristofer@chromatichq.com" + } + ], + "description": "Trait to allow support of different psr/log versions.", + "support": { + "issues": "https://github.com/mpdf/psr-log-aware-trait/issues", + "source": "https://github.com/mpdf/psr-log-aware-trait/tree/v2.0.0" + }, + "time": "2023-05-03T06:18:28+00:00" + }, + { + "name": "myclabs/deep-copy", + "version": "1.11.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3,<3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2023-03-08T13:26:56+00:00" + }, + { + "name": "paragonie/random_compat", + "version": "v9.99.100", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/996434e5492cb4c3edcb9168db6fbb1359ef965a", + "reference": "996434e5492cb4c3edcb9168db6fbb1359ef965a", + "shasum": "" + }, + "require": { + "php": ">= 7" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*", + "vimeo/psalm": "^1" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "polyfill", + "pseudorandom", + "random" + ], + "support": { + "email": "info@paragonie.com", + "issues": "https://github.com/paragonie/random_compat/issues", + "source": "https://github.com/paragonie/random_compat" + }, + "time": "2020-10-15T08:29:30+00:00" + }, + { + "name": "psr/http-message", + "version": "1.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/cb6ce4845ce34a8ad9e68117c10ee90a29919eba", + "reference": "cb6ce4845ce34a8ad9e68117c10ee90a29919eba", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/1.1" + }, + "time": "2023-04-04T09:50:52+00:00" + }, + { + "name": "psr/log", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.4" + }, + "time": "2021-05-03T11:20:27+00:00" + }, + { + "name": "setasign/fpdi", + "version": "v2.3.7", + "source": { + "type": "git", + "url": "https://github.com/Setasign/FPDI.git", + "reference": "bccc892d5fa1f48c43f8ba7db5ed4ba6f30c8c05" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Setasign/FPDI/zipball/bccc892d5fa1f48c43f8ba7db5ed4ba6f30c8c05", + "reference": "bccc892d5fa1f48c43f8ba7db5ed4ba6f30c8c05", + "shasum": "" + }, + "require": { + "ext-zlib": "*", + "php": "^5.6 || ^7.0 || ^8.0" + }, + "conflict": { + "setasign/tfpdf": "<1.31" + }, + "require-dev": { + "phpunit/phpunit": "~5.7", + "setasign/fpdf": "~1.8", + "setasign/tfpdf": "1.31", + "squizlabs/php_codesniffer": "^3.5", + "tecnickcom/tcpdf": "~6.2" + }, + "suggest": { + "setasign/fpdf": "FPDI will extend this class but as it is also possible to use TCPDF or tFPDF as an alternative. There's no fixed dependency configured." + }, + "type": "library", + "autoload": { + "psr-4": { + "setasign\\Fpdi\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Slabon", + "email": "jan.slabon@setasign.com", + "homepage": "https://www.setasign.com" + }, + { + "name": "Maximilian Kresse", + "email": "maximilian.kresse@setasign.com", + "homepage": "https://www.setasign.com" + } + ], + "description": "FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF. Because it is also possible to use FPDI with TCPDF, there are no fixed dependencies defined. Please see suggestions for packages which evaluates the dependencies automatically.", + "homepage": "https://www.setasign.com/fpdi", + "keywords": [ + "fpdf", + "fpdi", + "pdf" + ], + "support": { + "issues": "https://github.com/Setasign/FPDI/issues", + "source": "https://github.com/Setasign/FPDI/tree/v2.3.7" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/setasign/fpdi", + "type": "tidelift" + } + ], + "time": "2023-02-09T10:38:43+00:00" + }, + { + "name": "smarty/smarty", + "version": "v4.3.1", + "source": { + "type": "git", + "url": "https://github.com/smarty-php/smarty.git", + "reference": "e28cb0915b4e3749bf57d4ebae2984e25395cfe5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/smarty-php/smarty/zipball/e28cb0915b4e3749bf57d4ebae2984e25395cfe5", + "reference": "e28cb0915b4e3749bf57d4ebae2984e25395cfe5", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.5 || ^7.5", + "smarty/smarty-lexer": "^3.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "libs/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Monte Ohrt", + "email": "monte@ohrt.com" + }, + { + "name": "Uwe Tews", + "email": "uwe.tews@googlemail.com" + }, + { + "name": "Rodney Rehm", + "email": "rodney.rehm@medialize.de" + }, + { + "name": "Simon Wisselink", + "homepage": "https://www.iwink.nl/" + } + ], + "description": "Smarty - the compiling PHP template engine", + "homepage": "https://smarty-php.github.io/smarty/", + "keywords": [ + "templating" + ], + "support": { + "forum": "https://github.com/smarty-php/smarty/discussions", + "issues": "https://github.com/smarty-php/smarty/issues", + "source": "https://github.com/smarty-php/smarty/tree/v4.3.1" + }, + "time": "2023-03-28T19:47:03+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.3.0" +}