diff --git a/.gitignore b/.gitignore index 382cbe4..7664bcb 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ modules/* !modules/welcome !modules/admin !modules/phatemplates +!modules/phangoapp settings/config.php setting/config_test.php diff --git a/index.php b/index.php index 70de78e..a6ba863 100644 --- a/index.php +++ b/index.php @@ -4,8 +4,8 @@ use PhangoApp\PhaUtils\Utils; ob_start(); -include('libraries/Utils.php'); -include('libraries/Routes.php'); +//include('libraries/Utils.php'); +//include('libraries/Routes.php'); if(is_file(__DIR__.'/vendor/autoload.php')) { @@ -15,8 +15,6 @@ if(is_file(__DIR__.'/vendor/autoload.php')) { //ob_start(); -Utils::load_config('config'); - spl_autoload_register(function($class_name) { //Simple autoload for modules, first element is module, second element is the file to load. @@ -26,23 +24,34 @@ spl_autoload_register(function($class_name) { if(count($arr_library)>1) { $module=strtolower($arr_library[0]); - $library=strtolower($arr_library[1]); - + + $last_path=implode('/', array_slice($arr_library, 1, count($arr_library))); + + $library=strtolower($last_path); + if(is_file('modules/'.$module.'/libraries/'.$library.'.php')) { include('modules/'.$module.'/libraries/'.$library.'.php'); } + else if(is_file('modules/'.$module.'/libraries/'.strtolower($arr_library[1]).'.php')) { + + include('modules/'.$module.'/libraries/'.strtolower($arr_library[1]).'.php'); + + } } }); +Utils::load_config('config'); + if(!PhangoApp\PhaRouter\Config::$on_other) { - + if(!PhangoApp\PhaRouter\Config::$get_path_info) { - + $path_info=isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : ''; + } else { diff --git a/libraries/Routes.php b/libraries/Routes.php index 8d8bffa..ba4cbb5 100644 --- a/libraries/Routes.php +++ b/libraries/Routes.php @@ -32,7 +32,7 @@ class Config { * Url: http://domain.com/index.php/{module}/index/{arg1}/{arg2} -> modules/module/controller_index.php AppController->App($args); */ -function get_controller($controller, $args=[]) { +function get_controller($path_info, $controller, $args=[]) { $controller=__DIR__.'/../'.$controller; @@ -44,6 +44,8 @@ function get_controller($controller, $args=[]) { $controller=new \AppController(); + $controller->path_info=$path_info; + //return $controller->App($args); return call_user_func_array(array($controller, 'App'), $args); @@ -75,7 +77,7 @@ function get_controller($controller, $args=[]) { //Route is: /module/file/switch/parameter1/parameter2 function get_route($path_info) { - + if($path_info!='') { $arr_path=filter_path($path_info); @@ -86,7 +88,7 @@ function get_route($path_info) { $controller=\PhangoApp\PhaRouter\Config::$modules_allowed[\PhangoApp\PhaRouter\Config::$home_module].'/controllers/app.php'; - return \PhangoApp\PhaRouter\get_controller($controller, []); + return \PhangoApp\PhaRouter\get_controller($path_info, $controller, []); break; @@ -98,7 +100,7 @@ function get_route($path_info) { $controller=$module_path.'/controllers/app.php'; - return \PhangoApp\PhaRouter\get_controller($controller, []); + return \PhangoApp\PhaRouter\get_controller($path_info, $controller, []); } @@ -112,7 +114,7 @@ function get_route($path_info) { $controller=$module_path.'/controllers/'.$arr_path[2].'.php'; - return \PhangoApp\PhaRouter\get_controller($controller, []); + return \PhangoApp\PhaRouter\get_controller($path_info, $controller, []); } @@ -128,7 +130,7 @@ function get_route($path_info) { $args=array_slice($arr_path, 2, count($arr_path)); - return \PhangoApp\PhaRouter\get_controller($controller, $args); + return \PhangoApp\PhaRouter\get_controller($path_info, $controller, $args); } @@ -141,7 +143,7 @@ function get_route($path_info) { $controller=\PhangoApp\PhaRouter\Config::$modules_allowed[\PhangoApp\PhaRouter\Config::$home_module].'/controllers/app.php'; - return \PhangoApp\PhaRouter\get_controller($controller, []); + return \PhangoApp\PhaRouter\get_controller($path_info, $controller, []); } @@ -225,6 +227,8 @@ class Url { class Controller { + public $path_info=''; + public function json($arr_return) { $final_return=json_encode($arr_return); diff --git a/modules/admin/controllers/app.php b/modules/admin/controllers/app.php index 7218511..33b1e67 100644 --- a/modules/admin/controllers/app.php +++ b/modules/admin/controllers/app.php @@ -86,8 +86,8 @@ class AppController extends TplController{ if($num_tries<5) { - $username=trim($_POST['username']); - $password=trim($_POST['password']); + $username=trim($_POST['username'] ?? ''); + $password=trim($_POST['password'] ?? ''); if($username=='') { @@ -104,6 +104,7 @@ class AppController extends TplController{ $error=0; $_SESSION['admin_login']=1; + $_SESSION['date_login']=date("Y-m-d H:i:s"); if($arr_user['double_auth']) { @@ -253,15 +254,32 @@ class AppController extends TplController{ break; - case 'double_auth': + case 'check_auth': + + //Session expired. + + if($this->check_login()) { - echo $this->tpl->load_template('check_auth', ['title' => 'Double auth']); + if($_SERVER['REQUEST_METHOD']=='POST') { + + + + } + else { + + echo $this->tpl->load_template('check_auth', ['title' => 'Double auth']); + + } + + } break; case 'logout': unset($_SESSION['admin_login']); + unset($_SESSION['double_auth']); + unset($_SESSION['date_login']); header('Location: '.PhangoApp\PhaRouter\Url::make_url('admin')); diff --git a/modules/admin/libraries/tplcontroller.php b/modules/admin/libraries/tplcontroller.php index a86a9e1..a0c4ff7 100644 --- a/modules/admin/libraries/tplcontroller.php +++ b/modules/admin/libraries/tplcontroller.php @@ -26,11 +26,24 @@ class TplController extends PhangoApp\PhaRouter\Controller { if(isset($_SESSION['admin_login'])) { - if(isset($_SESSION['double_auth'])) { + if(isset($_SESSION['double_auth']) && $this->path_info!='/admin/app/check_auth') { - //header('Location: '.PhangoApp\PhaRouter\Url::make_url('admin', 'app', ['check_auth'])); + header('Location: '.PhangoApp\PhaRouter\Url::make_url('admin', 'app', ['check_auth'])); die; + } else { + + $now=date("Y-m-d H:i:s"); + + $timestamp_5_min=strtotime($now)-300; + $timestamp_last_login=strtotime($_SESSION['date_login']); + + if($timestamp_5_min>$timestamp_last_login) { + + header('Location: '.PhangoApp\PhaRouter\Url::make_url('admin', 'app', ['logout'])); + + } + } return true; diff --git a/modules/admin/templates/check_auth.php b/modules/admin/templates/check_auth.php index f5269a3..dd16dbd 100644 --- a/modules/admin/templates/check_auth.php +++ b/modules/admin/templates/check_auth.php @@ -1,8 +1,9 @@ =$this->layout('login_tpl', ['title' => $title])?> =$this->start('content')?>