diff --git a/daemon b/daemon index f90e1fb..ba3b892 100755 --- a/daemon +++ b/daemon @@ -2,9 +2,16 @@ ABSPATH=$( dirname $(realpath $0) ); +source $ABSPATH/include/bash/const; +source $ABSPATH/include/bash/func; + # (1) Check synchronization done # if [ ! -e /target/sync ]; then slog "[!] not synced yet, aborting" - "daemon" && exit 127; 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; diff --git a/lib/mfrc522/loop b/feature/rfid-read/main similarity index 100% rename from lib/mfrc522/loop rename to feature/rfid-read/main diff --git a/lib/mfrc522/read b/feature/rfid-read/read similarity index 100% rename from lib/mfrc522/read rename to feature/rfid-read/read diff --git a/lib/mfrc522/source/MFRC522.py b/feature/rfid-read/source/MFRC522.py similarity index 100% rename from lib/mfrc522/source/MFRC522.py rename to feature/rfid-read/source/MFRC522.py diff --git a/lib/mfrc522/source/loop.php b/feature/rfid-read/source/loop.php similarity index 98% rename from lib/mfrc522/source/loop.php rename to feature/rfid-read/source/loop.php index d6868f5..bd7b3df 100755 --- a/lib/mfrc522/source/loop.php +++ b/feature/rfid-read/source/loop.php @@ -2,7 +2,7 @@ fwrite( $etree.PHP_EOL ); + + $f = null; + + /* [6] Remove history entries =========================================================*/ @@ -178,33 +198,33 @@ return 0; } - /* (1) Check history entries count */ - if( !isset($arr_r['saved']) || !is_array($arr_r['saved']) ){ - slog('No \'saved\' found in api.response file', 'api:deploy', 'update'); - return 127; - } + if( isset($arr_r['saved']) && is_array($arr_r['saved']) ){ - /* (2) Check history count */ - if( !isset($arr_r['saved']['history']) || !is_numeric($arr_r['saved']['history']) ){ - slog('No \'actions\'.\'history\' found in api.response file', 'api:deploy', 'update'); - return 127; - } + foreach($arr_r['saved'] as $feat_name=>$count){ - /* (3) Fetch number of entries */ - $saved = intval($arr_r['saved']['history']); - $saved = $saved < 0 ? 0 : $saved; // prevent negative + /* (2) Check history count */ + if( !is_numeric($count) ){ + slog("No \'history\' found for '$feat_name' in api.response file", 'api:deploy', 'update'); + return 127; + } - /* (4) Truncate the log file */ - $truncated = syscall(SOURCE_DIR."/lib/file/truncate mfrc522 {$saved}"); + /* (3) Fetch number of entries */ + $saved = intval($count); + $saved = $saved < 0 ? 0 : $saved; // prevent negative - /* (5) Manage error */ - if( $truncated === false ){ - slog('History cannot be truncated', 'api:deploy', 'update'); - return 127; - } + /* (4) Truncate the log file */ + $truncated = syscall(SOURCE_DIR."/lib/file/truncate $feat_name {$saved}"); + + /* (5) Manage error */ + if( $truncated === false ){ + slog('History cannot be truncated', 'api:deploy', 'update'); + return 127; + } - slog('History succesfully truncated', 'api:deploy', 'update'); + slog("History '$feat_name' succesfully truncated", 'api:deploy', 'update'); + + } return 0; } diff --git a/lib/api/source/fetch.php b/lib/api/source/fetch.php index cc4b0c2..065750e 100755 --- a/lib/api/source/fetch.php +++ b/lib/api/source/fetch.php @@ -4,57 +4,41 @@ function api_fetch(){ - /* [1] Fetch & generate useful data from features + $data = []; + + /* [1] Get the list of daemons (features) =========================================================*/ - /* (1) Initialize dataset - ---------------------------------------------------------*/ - $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'); + $f = new SplFileObject(ETREE_CONF, 'r'); while( !$f->eof() ){ /* (1) Try to parse each line */ - $parsed = json_decode($f->fgets(), true); + $etree = $f->fgets(); /* (2) Manage error */ - if( is_null($parsed) ) + if( is_null($etree) ) continue; /* (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 */ - $abs_path = SOURCE_DIR."/feature/$feat_name"; - - /* (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] = []; + /* (2) Fetch for each feature which generates data + ---------------------------------------------------------*/ + foreach($data['feature'] as $feat_name=>$feat_data){ /* (5) Check for feature access log */ if( !file_exists(DATA_DIR."/$feat_name") ) diff --git a/lib/include/bash/const b/lib/include/bash/const index 9248767..3e59df2 100755 --- a/lib/include/bash/const +++ b/lib/include/bash/const @@ -26,6 +26,7 @@ export AUTH_CONF="$CONF_DIR/auth.list"; export STATES_CONF="$CONF_DIR/states.list"; export CHIPS_CONF="$CONF_DIR/chips.list"; export ACTIONS_CONF="$CONF_DIR/actions.list"; +export ETREE_CONF="$CONF_DIR/etree.list"; # LOG FILES @@ -35,10 +36,6 @@ export INSTALL_LOG="$LOG_DIR/install-source.log"; export UPDATE_LOG="$LOG_DIR/update.log"; -# DATA FILES -export DEFAULT_DATA="$DATA_DIR/mfrc522"; - - # SETTINGS export SECRET_SIZE=250; diff --git a/lib/include/php/const b/lib/include/php/const index b637722..93ca8de 100755 --- a/lib/include/php/const +++ b/lib/include/php/const @@ -25,6 +25,7 @@ define('STATES_CONF', CONF_DIR.'/states.list'); define('CHIPS_CONF', CONF_DIR.'/chips.list'); define('ACTIONS_CONF', CONF_DIR.'/actions.list'); + define('ETREE_CONF', CONF_DIR.'/etree.list'); # LOG FILES define('BOOT_LOG', LOG_DIR.'/boot.log'); @@ -32,9 +33,6 @@ define('INSTALL_LOG', LOG_DIR.'/install-source.log'); define('UPDATE_LOG', LOG_DIR.'/update.log'); - # DATA FILES - define('DEFAULT_DATA', DATA_DIR.'/mfrc522'); - # SETTINGS define('SECRET_SIZE', 250);