Update global state when starting daemon
This commit is contained in:
parent
05eebd3930
commit
ef672e4eef
|
@ -36,7 +36,7 @@
|
||||||
/* (1) Fetch from file */
|
/* (1) Fetch from file */
|
||||||
$f_cstates = new SplFileObject(STATES_CONF, 'r');
|
$f_cstates = new SplFileObject(STATES_CONF, 'r');
|
||||||
|
|
||||||
/* (2) Section Title */
|
/* (2) If fetch error */
|
||||||
if( $f_cstates === false ){
|
if( $f_cstates === false ){
|
||||||
slog('Cannot access GLOBAL/CHIP STATES file', 'global-state:update', 'daemon');
|
slog('Cannot access GLOBAL/CHIP STATES file', 'global-state:update', 'daemon');
|
||||||
return 127;
|
return 127;
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
|
|
||||||
/* (2) Parse each line */
|
/* (2) Parse each line */
|
||||||
while( !$f_auth->eof() ){
|
while( !$f_auth->eof() ){
|
||||||
|
|
||||||
/* (3) Try to parse line */
|
/* (3) Try to parse line */
|
||||||
$parsed = json_decode($f_auth->fgets(), true);
|
$parsed = json_decode($f_auth->fgets(), true);
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@
|
||||||
/* (4) If wrong code -> go to next */
|
/* (4) If wrong code -> go to next */
|
||||||
if( $parsed[0] != $code )
|
if( $parsed[0] != $code )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* (5) return user info */
|
/* (5) return user info */
|
||||||
return [
|
return [
|
||||||
'id' => $parsed[1],
|
'id' => $parsed[1],
|
||||||
|
@ -124,7 +124,7 @@
|
||||||
/* (1) If no action for this @timeout -> reset to 0 */
|
/* (1) If no action for this @timeout -> reset to 0 */
|
||||||
if( !isset($actions[$timeout]) || !is_array($actions[$timeout]) )
|
if( !isset($actions[$timeout]) || !is_array($actions[$timeout]) )
|
||||||
$timeout = 0;
|
$timeout = 0;
|
||||||
|
|
||||||
/* (2) fetch actions for the current @timeout */
|
/* (2) fetch actions for the current @timeout */
|
||||||
$actionlist = $actions[$timeout];
|
$actionlist = $actions[$timeout];
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@
|
||||||
/* (3) Manage error */
|
/* (3) Manage error */
|
||||||
if( $written === false )
|
if( $written === false )
|
||||||
slog('cannot update STATE file', 'mfrc522:loop');
|
slog('cannot update STATE file', 'mfrc522:loop');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [6] Log action
|
/* [6] Log action
|
||||||
|
@ -273,7 +273,7 @@
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* (1) Parse each line */
|
/* (1) Parse each line */
|
||||||
while( !$f_actions->eof() ){
|
while( !$f_actions->eof() ){
|
||||||
|
|
||||||
/* (2) Try to parse line */
|
/* (2) Try to parse line */
|
||||||
$parsed = json_decode($f_actions->fgets(), true);
|
$parsed = json_decode($f_actions->fgets(), true);
|
||||||
|
|
||||||
|
@ -308,6 +308,13 @@
|
||||||
return 127;
|
return 127;
|
||||||
|
|
||||||
|
|
||||||
|
/* [4] Update global state
|
||||||
|
=========================================================*/
|
||||||
|
/* (1) Do it once to unlock gpio boot lag */
|
||||||
|
syscall(SOURCE_DIR.'/lib/global-state/update');
|
||||||
|
|
||||||
|
/* (2) Do it again to apply global state */
|
||||||
|
syscall(SOURCE_DIR.'/lib/global-state/update');
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -343,7 +350,7 @@
|
||||||
|
|
||||||
/* (2) Read card */
|
/* (2) Read card */
|
||||||
$code = syscall(SOURCE_DIR.'/lib/mfrc522/read');
|
$code = syscall(SOURCE_DIR.'/lib/mfrc522/read');
|
||||||
|
|
||||||
/* (3) If no card read -> reset @last_user / @timeout + abort */
|
/* (3) If no card read -> reset @last_user / @timeout + abort */
|
||||||
if( $code === false ){
|
if( $code === false ){
|
||||||
|
|
||||||
|
@ -370,7 +377,7 @@
|
||||||
slog("card '$code' read", 'mfrc522:read');
|
slog("card '$code' read", 'mfrc522:read');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [2] Check for user in auth list
|
/* [2] Check for user in auth list
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* (1) Check user for this code */
|
/* (1) Check user for this code */
|
||||||
|
@ -379,7 +386,7 @@
|
||||||
|
|
||||||
/* (2) If not found -> reset @last_user / @timeout + abort */
|
/* (2) If not found -> reset @last_user / @timeout + abort */
|
||||||
if( is_null($user) ){
|
if( is_null($user) ){
|
||||||
|
|
||||||
slog("Unknown user (not authenticated)", "mfrc522:loop");
|
slog("Unknown user (not authenticated)", "mfrc522:loop");
|
||||||
$last_user = null;
|
$last_user = null;
|
||||||
$timeout = 0;
|
$timeout = 0;
|
||||||
|
@ -423,7 +430,7 @@
|
||||||
|
|
||||||
/* (4) Store user for next loop */
|
/* (4) Store user for next loop */
|
||||||
$last_user = $user['id'];
|
$last_user = $user['id'];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -460,7 +467,7 @@
|
||||||
|
|
||||||
mfrc522_loop();
|
mfrc522_loop();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue