[1] Daemon uses etree list
[2] lib/mfrc522 -> feature/rfid-read [3] rfid-read logs to DATA/rfid-read [4] api/fetch checks for DATA/* according to etree [5] api/deploy deploys etrees truncates [6] more updates...
This commit is contained in:
parent
4fd7197cc6
commit
9a62d404fa
9
daemon
9
daemon
|
@ -2,9 +2,16 @@
|
||||||
|
|
||||||
ABSPATH=$( dirname $(realpath $0) );
|
ABSPATH=$( dirname $(realpath $0) );
|
||||||
|
|
||||||
|
source $ABSPATH/include/bash/const;
|
||||||
|
source $ABSPATH/include/bash/func;
|
||||||
|
|
||||||
# (1) Check synchronization done #
|
# (1) Check synchronization done #
|
||||||
if [ ! -e /target/sync ]; then
|
if [ ! -e /target/sync ]; then
|
||||||
slog "[!] not synced yet, aborting" - "daemon" && exit 127;
|
slog "[!] not synced yet, aborting" - "daemon" && exit 127;
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
$ABSPATH/lib/mfrc522/loop;
|
# (2) Get the list of etrees #
|
||||||
|
cat $ETREE_CONF | \
|
||||||
|
while read etree; do
|
||||||
|
sudo systemctl restart sats-feature@$ETREE_CONF.service;
|
||||||
|
done;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once __DIR__.'/../../include/php/const';
|
require_once __DIR__.'/../../lib/include/php/const';
|
||||||
|
|
||||||
$f_auth;
|
$f_auth;
|
||||||
$f_accesslog;
|
$f_accesslog;
|
||||||
|
@ -13,6 +13,8 @@
|
||||||
$last_user = null;
|
$last_user = null;
|
||||||
$timeout = 0;
|
$timeout = 0;
|
||||||
|
|
||||||
|
$FEATURE = basename(dirname(__DIR__));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -265,7 +267,7 @@
|
||||||
$f_actions = new SplFileObject(ACTIONS_CONF, 'r');
|
$f_actions = new SplFileObject(ACTIONS_CONF, 'r');
|
||||||
|
|
||||||
/* (2) Append accesses (logs) */
|
/* (2) Append accesses (logs) */
|
||||||
$f_accesslog = new SplFileObject(DEFAULT_DATA, 'a');
|
$f_accesslog = new SplFileObject(DATA_DIR."/$FEATURE", 'a');
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,26 @@
|
||||||
$f = null;
|
$f = null;
|
||||||
|
|
||||||
|
|
||||||
|
/* [6] Get etrees list
|
||||||
|
=========================================================*/
|
||||||
|
/* (1) Check data */
|
||||||
|
if( !isset($arr_r['etrees']) || !is_array($arr_r['etrees']) ){
|
||||||
|
slog('No \'etree\' found in api.response file', 'api:deploy', 'update');
|
||||||
|
return 127;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (2) Reset file */
|
||||||
|
file_put_contents(ETREE_CONF, '');
|
||||||
|
|
||||||
|
/* (3) Replace content */
|
||||||
|
$f = new SplFileObject(ETREE_CONF, 'w');
|
||||||
|
|
||||||
|
foreach($arr_r['etrees'] as $etree)
|
||||||
|
$f->fwrite( $etree.PHP_EOL );
|
||||||
|
|
||||||
|
$f = null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* [6] Remove history entries
|
/* [6] Remove history entries
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
|
@ -178,24 +198,22 @@
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (1) Check history entries count */
|
if( isset($arr_r['saved']) && is_array($arr_r['saved']) ){
|
||||||
if( !isset($arr_r['saved']) || !is_array($arr_r['saved']) ){
|
|
||||||
slog('No \'saved\' found in api.response file', 'api:deploy', 'update');
|
foreach($arr_r['saved'] as $feat_name=>$count){
|
||||||
return 127;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (2) Check history count */
|
/* (2) Check history count */
|
||||||
if( !isset($arr_r['saved']['history']) || !is_numeric($arr_r['saved']['history']) ){
|
if( !is_numeric($count) ){
|
||||||
slog('No \'actions\'.\'history\' found in api.response file', 'api:deploy', 'update');
|
slog("No \'history\' found for '$feat_name' in api.response file", 'api:deploy', 'update');
|
||||||
return 127;
|
return 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (3) Fetch number of entries */
|
/* (3) Fetch number of entries */
|
||||||
$saved = intval($arr_r['saved']['history']);
|
$saved = intval($count);
|
||||||
$saved = $saved < 0 ? 0 : $saved; // prevent negative
|
$saved = $saved < 0 ? 0 : $saved; // prevent negative
|
||||||
|
|
||||||
/* (4) Truncate the log file */
|
/* (4) Truncate the log file */
|
||||||
$truncated = syscall(SOURCE_DIR."/lib/file/truncate mfrc522 {$saved}");
|
$truncated = syscall(SOURCE_DIR."/lib/file/truncate $feat_name {$saved}");
|
||||||
|
|
||||||
/* (5) Manage error */
|
/* (5) Manage error */
|
||||||
if( $truncated === false ){
|
if( $truncated === false ){
|
||||||
|
@ -204,7 +222,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
slog('History succesfully truncated', 'api:deploy', 'update');
|
slog("History '$feat_name' succesfully truncated", 'api:deploy', 'update');
|
||||||
|
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,57 +4,41 @@
|
||||||
|
|
||||||
function api_fetch(){
|
function api_fetch(){
|
||||||
|
|
||||||
/* [1] Fetch & generate useful data from features
|
$data = [];
|
||||||
|
|
||||||
|
/* [1] Get the list of daemons (features)
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* (1) Initialize dataset
|
$f = new SplFileObject(ETREE_CONF, 'r');
|
||||||
---------------------------------------------------------*/
|
|
||||||
$data = [
|
|
||||||
'default' => [],
|
|
||||||
'feature' => [],
|
|
||||||
'identity' => [
|
|
||||||
'ap' => syscall(SOURCE_DIR.'/lib/netid/ap'),
|
|
||||||
'ip' => syscall(SOURCE_DIR.'/lib/netid/ip')
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/* (2) Fetch DEFAULT data log
|
|
||||||
---------------------------------------------------------*/
|
|
||||||
$f = new SplFileObject(DEFAULT_DATA, 'r');
|
|
||||||
|
|
||||||
while( !$f->eof() ){
|
while( !$f->eof() ){
|
||||||
|
|
||||||
/* (1) Try to parse each line */
|
/* (1) Try to parse each line */
|
||||||
$parsed = json_decode($f->fgets(), true);
|
$etree = $f->fgets();
|
||||||
|
|
||||||
/* (2) Manage error */
|
/* (2) Manage error */
|
||||||
if( is_null($parsed) )
|
if( is_null($etree) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* (3) Add entry to log */
|
/* (3) Add entry to log */
|
||||||
$data['default'][] = $parsed;
|
$data['feature'][$etree] = [];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* (3) Fetch for each feature which generates data
|
/* [2] Fetch & generate useful data from features
|
||||||
|
=========================================================*/
|
||||||
|
/* (1) Get identity
|
||||||
---------------------------------------------------------*/
|
---------------------------------------------------------*/
|
||||||
foreach(scandir(SOURCE_DIR.'/feature') as $feat_name){
|
$data['identity'] = [
|
||||||
|
'ap' => syscall(SOURCE_DIR.'/lib/netid/ap'),
|
||||||
|
'ip' => syscall(SOURCE_DIR.'/lib/netid/ip')
|
||||||
|
];
|
||||||
|
|
||||||
/* (1) Ignore . and .. entries */
|
|
||||||
if( in_array($feat_name, ['.', '..']) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* (2) Get absolute path */
|
/* (2) Fetch for each feature which generates data
|
||||||
$abs_path = SOURCE_DIR."/feature/$feat_name";
|
---------------------------------------------------------*/
|
||||||
|
foreach($data['feature'] as $feat_name=>$feat_data){
|
||||||
/* (3) Check if it is a directory */
|
|
||||||
if( !file_exists($abs_path) || !is_dir($abs_path) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
/* (4) Store the feature entry (empty) */
|
|
||||||
$data['feature'][$feat_name] = [];
|
|
||||||
|
|
||||||
/* (5) Check for feature access log */
|
/* (5) Check for feature access log */
|
||||||
if( !file_exists(DATA_DIR."/$feat_name") )
|
if( !file_exists(DATA_DIR."/$feat_name") )
|
||||||
|
|
|
@ -26,6 +26,7 @@ export AUTH_CONF="$CONF_DIR/auth.list";
|
||||||
export STATES_CONF="$CONF_DIR/states.list";
|
export STATES_CONF="$CONF_DIR/states.list";
|
||||||
export CHIPS_CONF="$CONF_DIR/chips.list";
|
export CHIPS_CONF="$CONF_DIR/chips.list";
|
||||||
export ACTIONS_CONF="$CONF_DIR/actions.list";
|
export ACTIONS_CONF="$CONF_DIR/actions.list";
|
||||||
|
export ETREE_CONF="$CONF_DIR/etree.list";
|
||||||
|
|
||||||
|
|
||||||
# LOG FILES
|
# LOG FILES
|
||||||
|
@ -35,10 +36,6 @@ export INSTALL_LOG="$LOG_DIR/install-source.log";
|
||||||
export UPDATE_LOG="$LOG_DIR/update.log";
|
export UPDATE_LOG="$LOG_DIR/update.log";
|
||||||
|
|
||||||
|
|
||||||
# DATA FILES
|
|
||||||
export DEFAULT_DATA="$DATA_DIR/mfrc522";
|
|
||||||
|
|
||||||
|
|
||||||
# SETTINGS
|
# SETTINGS
|
||||||
export SECRET_SIZE=250;
|
export SECRET_SIZE=250;
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
define('STATES_CONF', CONF_DIR.'/states.list');
|
define('STATES_CONF', CONF_DIR.'/states.list');
|
||||||
define('CHIPS_CONF', CONF_DIR.'/chips.list');
|
define('CHIPS_CONF', CONF_DIR.'/chips.list');
|
||||||
define('ACTIONS_CONF', CONF_DIR.'/actions.list');
|
define('ACTIONS_CONF', CONF_DIR.'/actions.list');
|
||||||
|
define('ETREE_CONF', CONF_DIR.'/etree.list');
|
||||||
|
|
||||||
# LOG FILES
|
# LOG FILES
|
||||||
define('BOOT_LOG', LOG_DIR.'/boot.log');
|
define('BOOT_LOG', LOG_DIR.'/boot.log');
|
||||||
|
@ -32,9 +33,6 @@
|
||||||
define('INSTALL_LOG', LOG_DIR.'/install-source.log');
|
define('INSTALL_LOG', LOG_DIR.'/install-source.log');
|
||||||
define('UPDATE_LOG', LOG_DIR.'/update.log');
|
define('UPDATE_LOG', LOG_DIR.'/update.log');
|
||||||
|
|
||||||
# DATA FILES
|
|
||||||
define('DEFAULT_DATA', DATA_DIR.'/mfrc522');
|
|
||||||
|
|
||||||
# SETTINGS
|
# SETTINGS
|
||||||
define('SECRET_SIZE', 250);
|
define('SECRET_SIZE', 250);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue