Merge branch '1.0-local' into 1.0

This commit is contained in:
xdrm-brackets 2017-02-23 16:12:10 +01:00
commit 658c7080ed
1 changed files with 41 additions and 16 deletions

View File

@ -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,7 +289,7 @@
/* [3] Cache global state
/* [3] Check global state
=========================================================*/
/* (1) Check file */
if( $f_gstate === false )
@ -271,11 +299,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 +319,7 @@
global $timeout;
/* (2) Caches */
global $actions, $state;
global $actions;