first commit

This commit is contained in:
2026-10-29 13:34:31 +07:00
commit 45e4595c57
255 changed files with 35457 additions and 0 deletions
+151
View File
@@ -0,0 +1,151 @@
<?php
/*******************************************************************
Desc. : Loading Routing Setup
Created By : Siau Pheng ([email protected]).
Created Date : November 23rd, 2019.
Last Modified : October 21st, 2026.
(c) 3FONIA Software; WWW.3FONIA.COM.
*******************************************************************/
use flight\Engine;
use flight\Session;
use flight\net\Router;
use Webapp\App\Auth;
use Webapp\Data\Cache;
use Webapp\Web\Menu;
use App\Middleware\SecurityHeaders;
use App\Controller\IndexController;
use App\Controller\QZController;
/**
* Application routes.
*
* @var Router $router
* @var Engine $app
* @var Session $session
*/
$router = $app->router();
$router->group('', function(Router $router) use ($app, $session, $config) {
$router->get('/(@token(/@nowhere))', function(?string $token, ?string $nowhere) use ($app, $session, $config) {
$token_s = $session->get('APP_TOKEN');
if (!empty($token) && strlen($token ?? '') === 60) {
$auth = new Auth($app);
if ($token !== $token_s) {
if ($auth->token_check($token)) {
if (empty($session->get('WEB_USER'))) {
$auser = $auth->user_data($auth->getUserByToken($token));
$auth->pos_login($session->get("APP_INV")['CABANGID'] ?? 0, $auser['UserID'], $auser['UNIX'], $app->request()->ip);
$session->set('WEB_USER', $auser);
}
$auth->user_log();
$session->set('APP_TOKEN', $token);
} else {
$session->delete('APP_TOKEN');
$session->delete('WEB_USER');
$app->redirect('/', 301);
}
} else $auth->token_update();
if (!empty($nowhere)) $app->redirect($token ?? $token_s, 301);
} else {
if (!empty($token_s) && empty($nowhere) && $token !== 'monitor') $app->redirect($token_s, 301);
return true;
}
$asset = require('asset.php');
$_user = $session->get('WEB_USER') ?? [];
$_menu = new Menu($app);
$cache = new Cache($app);
$cache->set_dev($config->env() === 'development');
$cache->set_asset($asset);
$_web_app = $session->get('WEB_APP') ?? [];
$_web_app = array_merge($_web_app, $cache->Cache('index'));
$_web_app['NAVI_SIDEBAR'] = $_menu->Sidebar();
$_web_app['NAVI_HEADER'] = $_menu->Header();
$_web_app['USER_ID'] = $_user['UserID'] ?? "";
$_web_app['USER_USER'] = $_user['Username'] ?? "";
$_web_app['USER_NAME'] = $_user['Nama'] ?? "";
$_web_app['USER_POSISI'] = $_user['Posisi'] ?? "";
$_web_app['MENU_MODUL'] = $_menu->Modul();
$app->render('index', $_web_app);
});
$router->get('/login', function() use ($app, $session, $config) {
$asset = require('asset.php');
$cache = new Cache($app);
$cache->set_dev($config->env() === 'development');
$cache->set_asset($asset);
$_web_app = $session->get('WEB_APP') ?? [];
$_web_app = array_merge($_web_app, $cache->Cache('login'));
$app->render('login', $_web_app);
});
$router->get('/monitor', function() use ($app, $session, $config) {
$asset = require('asset.php');
$cache = new Cache($app);
$cache->set_dev($config->env() === 'development');
$cache->set_asset($asset);
$_web_app = $session->get('WEB_APP') ?? [];
$_web_app = array_merge($_web_app, $cache->Cache('monitor'));
$app->render('monitor', $_web_app);
});
$router->post('/(@path1(/@path2(/@path3(/@path4))))', static function ($path1, $path2, $path3, $path4) use ($app) {
$_path1 = ucfirst($path1) . '\\';
$_path2 = ucfirst($path2) . '\\';
if (empty($path3)) {
$_path1 = '';
$_path2 = '';
$controller = $path1;
$method = $path2;
} else if (empty($path4)) {
$_path2 = '';
$controller = $path2;
$method = $path3;
} else {
$controller = $path3;
$method = $path4;
}
$controller = $controller ? ucfirst(strtolower($controller)) : 'Index';
$method = $method ? $method : 'index';
$class = '\\App\\Controller\\' . $_path1 . $_path2 . $controller . 'Controller';
if (!class_exists($class) || (class_exists($class) && ! method_exists($class, $method))) return true;
$ct = $app->make($class);
$ct->$method();
});
// handle Cache css & js for application
$router->get('/cache/@filename', function($filename) use ($app) {
$rootdir = (defined('PROJECT_ROOT')) ? PROJECT_ROOT : $app->get('app.project_root');
$filePath = $rootdir . '/temp/cache/' . $filename;
if (file_exists($filePath) && !str_contains($filename, '..')) {
$mimeType = 'application/octet-stream';
if (str_ends_with($filePath, '.js')) $mimeType = 'application/javascript';
if (str_ends_with($filePath, '.css')) $mimeType = 'text/css';
$app->response()->header('Content-Type', $mimeType);
echo file_get_contents($filePath);
} else {
$app->notFound();
}
});
// handle QZ Printer
$router->group('/qz', function() use ($router) {
$router->get('/cert', [ QZController::class, 'getCert' ]);
$router->get('/sign(/@req)', [ QZController::class, 'getSign' ]);
});
$router->get('/401', [IndexController::class, 'get401']);
$router->get('/404', [IndexController::class, 'get404']);
$router->get('*', [IndexController::class, 'get404']);
$router->post('*', [IndexController::class, 'post404']);
}, [ SecurityHeaders::class ]);