[fix]
This commit is contained in:
parent
9f7da3f040
commit
7e70ee4ec8
|
@ -5,11 +5,10 @@
|
|||
require_once __DIR__.'/../../include/php/const';
|
||||
|
||||
$f_auth;
|
||||
$f_gstate;
|
||||
$f_accesslog;
|
||||
$f_actions;
|
||||
|
||||
$state = null;
|
||||
|
||||
$actions = [];
|
||||
|
||||
$last_user = null;
|
||||
|
@ -20,6 +19,32 @@
|
|||
|
||||
|
||||
|
||||
/* RETURN CURRENT GLOBAL STATE
|
||||
*
|
||||
* @return gstate<string> Current global state as string
|
||||
*
|
||||
*/
|
||||
function get_gstate(){
|
||||
|
||||
/* (1) Export global file descriptor */
|
||||
global $g_gstate;
|
||||
|
||||
/* (2) Read first line */
|
||||
$f_gstate->seek(0);
|
||||
$state = $f_gstate->fgets();
|
||||
|
||||
$state = preg_replace('@^\s+@', '', $state);
|
||||
$state = preg_replace('@\s+$@', '', $state);
|
||||
|
||||
/* (3) Check data */
|
||||
if( strlen($state) < 1 )
|
||||
return false;
|
||||
|
||||
/* (4) Return global state */
|
||||
return $state;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* RETURNS THE PERMISSIONS FOR A SPECIFIC CODE AND AN ACTION
|
||||
*
|
||||
|
@ -80,11 +105,14 @@
|
|||
global $timeout;
|
||||
|
||||
/* (2) Caches */
|
||||
global $actions, $state;
|
||||
global $actions;
|
||||
|
||||
/* (3) Log history file descriptor */
|
||||
global $f_accesslog;
|
||||
|
||||
/* (5) Update global state */
|
||||
$state = get_gstate();
|
||||
|
||||
|
||||
/* [2] Manage timeout
|
||||
=========================================================*/
|
||||
|
@ -129,7 +157,7 @@
|
|||
$action = $actionlist[$id_action];
|
||||
|
||||
/* (4) Check if the state allows the action to be performed */
|
||||
for( $c = 0 ; $c < count($state) || $c < strlen($action['prev']) ; $c++ ){
|
||||
for( $c = 0 ; $c < strlen($state) || $c < strlen($action['prev']) ; $c++ ){
|
||||
// {1} 'X' = any state -> so ignore //
|
||||
if( $action['prev'][$c] == 'X' )
|
||||
continue;
|
||||
|
@ -160,7 +188,7 @@
|
|||
/* [5] Process the action on the STATE
|
||||
=========================================================*/
|
||||
/* (1) Update the state with the found action */
|
||||
for( $c = 0 ; $c < count($state) || $c < strlen($action['next']) ; $c++ ){
|
||||
for( $c = 0 ; $c < strlen($state) || $c < strlen($action['next']) ; $c++ ){
|
||||
|
||||
// {1} If 'x' -> let the current state //
|
||||
if( $action['next'][$c] == 'X' )
|
||||
|
@ -174,7 +202,7 @@
|
|||
|
||||
|
||||
/* (2) Update the state file */
|
||||
$written = @file_put_contents(STATE_CONF, implode('', $state));
|
||||
$written = @file_put_contents(STATE_CONF, $state);
|
||||
|
||||
/* (3) Manage error */
|
||||
if( $written === false )
|
||||
|
@ -213,10 +241,10 @@
|
|||
/* [0] Initialize global variables
|
||||
=========================================================*/
|
||||
/* (1) File descriptiors */
|
||||
global $f_auth, $f_accesslog;
|
||||
global $f_auth, $f_accesslog, $f_gstate;
|
||||
|
||||
/* (2) Caches */
|
||||
global $actions, $state;
|
||||
global $actions;
|
||||
|
||||
|
||||
|
||||
|
@ -225,7 +253,7 @@
|
|||
/* (1) Read accesses */
|
||||
$f_auth = new SplFileObject(AUTH_CONF, 'r');
|
||||
$f_actions = new SplFileObject(ACTIONS_CONF, 'r');
|
||||
$f_gstate = @file_get_contents(STATE_CONF);
|
||||
$f_gstate = new SplFileObject(STATE_CONF, 'r');
|
||||
|
||||
/* (2) Append accesses (logs) */
|
||||
$f_accesslog = new SplFileObject(DEFAULT_DATA, 'a');
|
||||
|
@ -261,9 +289,11 @@
|
|||
|
||||
|
||||
|
||||
/* [3] Cache global state
|
||||
/* [3] Check global state
|
||||
=========================================================*/
|
||||
/* (1) Check file */
|
||||
$gstate = $f_gstate->current();
|
||||
|
||||
if( $f_gstate === false )
|
||||
return 127;
|
||||
|
||||
|
@ -271,11 +301,8 @@
|
|||
$f_gstate = preg_replace('@^\s+@', '', $f_gstate);
|
||||
$f_gstate = preg_replace('@\s+$@', '', $f_gstate);
|
||||
|
||||
/* (3) For each character create an entry */
|
||||
$state = str_split($f_gstate);
|
||||
|
||||
/* (4) Manage error */
|
||||
if( is_null($state) )
|
||||
/* (3) Manage error */
|
||||
if( strlen($state) < 1 )
|
||||
return 127;
|
||||
|
||||
return 0;
|
||||
|
@ -294,7 +321,7 @@
|
|||
global $timeout;
|
||||
|
||||
/* (2) Caches */
|
||||
global $actions, $state;
|
||||
global $actions;
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue