[Done] Deploy management + updated configuration files (fetched by init/sync)

This commit is contained in:
xdrm-brackets 2017-02-20 21:22:42 +01:00
parent dba451e93e
commit ee177181f8
6 changed files with 143 additions and 24 deletions

View File

@ -21,20 +21,111 @@
return 127; return 127;
/* [2] Get system states (global_state)
=========================================================*/
/* (1) Check data */
if( !isset($arr_r['states']) || !is_array($arr_r['states']) )
return 127;
/* (2) Reset file */
file_put_contents(STATES_CONF, '');
/* (3) Replace content */
$f = new SplFileObject(STATES_CONF, 'w');
foreach($arr_r['states'] as $state)
$f->fwrite( json_encode([
$state['global_state'],
$state['chips']
]).PHP_EOL );
$f = null;
/* [3] Get chip list (chips)
=========================================================*/
/* (1) Check data */
if( !isset($arr_r['chips']) || !is_array($arr_r['chips']) )
return 127;
/* (2) Reset file */
file_put_contents(CHIPS_CONF, '');
/* (3) Replace content */
$f = new SplFileObject(CHIPS_CONF, 'w');
foreach($arr_r['chips'] as $chip)
$f->fwrite( json_encode([
(int) $chip['position'],
$chip['pins'],
$chip['states']
]).PHP_EOL );
$f = null;
/* [4] Get auth list (permissions)
=========================================================*/
/* (1) Check data */
if( !isset($arr_r['permissions']) || !is_array($arr_r['permissions']) )
return 127;
/* (2) Reset file */
file_put_contents(AUTH_CONF, '');
/* (3) Replace content */
$f = new SplFileObject(AUTH_CONF, 'w');
foreach($arr_r['permissions'] as $code=>$perm)
$f->fwrite( json_encode([
$code,
(int) $perm['id_user'],
$perm['actions']
]).PHP_EOL );
$f = null;
/* [5] Get action list (with timeout)
=========================================================*/
/* (1) Check data */
if( !isset($arr_r['actions']) || !is_array($arr_r['actions']) )
return 127;
/* (2) Reset file */
file_put_contents(ACTIONS_CONF, '');
/* (3) Replace content */
$f = new SplFileObject(ACTIONS_CONF, 'w');
foreach($arr_r['actions'] as $timeout=>$actions)
foreach($actions as $action)
$f->fwrite( json_encode([
(int) $timeout,
(int) $action['id_action'],
$action['previous'],
$action['action']
]).PHP_EOL );
$f = null;
return 0; return 0;
} }
/* [1] Check $1 argument $exec = api_deploy();
=========================================================*/
if( $argc < 2 || !in_array($argv[1], 'init', 'sync' ){
echo 127;
die();
}
echo $exec;
echo api_deploy($argv[1]); die($exec);
?> ?>

View File

@ -128,12 +128,16 @@
$response_arr = json_decode($response, true); $response_arr = json_decode($response, true);
// if cannot, abort // if cannot, abort
if( is_null($response_arr) ) if( is_null($response_arr) ){
slog('Cannot parse HTTP response', 'api:init', 'update');
return 127; return 127;
}
/* (2) Check response error */ /* (2) Check response error */
if( !isset($response_arr['error']) || $response_arr['error'] != 0 ) if( !isset($response_arr['error']) || $response_arr['error'] != 0 ){
slog('API error not on \'Success\'', 'api:init', 'update');
return 127; return 127;
}
/* (3) Writes request to temporary pipe */ /* (3) Writes request to temporary pipe */
@ -150,13 +154,13 @@
return 127; return 127;
} }
return 0; slog('HTTP Response succesfully received', 'api:init', 'update');
/* [8] Deploy received data /* [8] Deploy received data
=========================================================*/ =========================================================*/
/* (1) Manage response deployement */ /* (1) Manage response deployement */
$deploy = syscall(SOURCE_DIR.'/lib/api/deploy init'); $deploy = syscall(SOURCE_DIR.'/lib/api/deploy');
/* (2) Return state */ /* (2) Return state */
return ($deploy === true) ? 0 : 127; return ($deploy === true) ? 0 : 127;
@ -164,7 +168,10 @@
} }
die(api_init());
$exec = api_init();
echo $exec;
die($exec);

View File

@ -114,12 +114,16 @@
$response_arr = json_decode($response, true); $response_arr = json_decode($response, true);
// if cannot, abort // if cannot, abort
if( is_null($response_arr) ) if( is_null($response_arr) ){
slog('Cannot parse HTTP response', 'api:sync', 'update');
return 127; return 127;
}
/* (2) Check response error */ /* (2) Check response error */
if( !isset($response_arr['error']) || $response_arr['error'] != 0 ) if( !isset($response_arr['error']) || $response_arr['error'] != 0 ){
slog('API error not on \'Success\'', 'api:sync', 'update');
return 127; return 127;
}
/* (3) Writes request to temporary pipe */ /* (3) Writes request to temporary pipe */
file_put_contents(TMP_DIR.'/api.response', $response); file_put_contents(TMP_DIR.'/api.response', $response);
@ -131,16 +135,16 @@
$decr = syscall(SOURCE_DIR.'/lib/cyclic-hash/decr'); $decr = syscall(SOURCE_DIR.'/lib/cyclic-hash/decr');
if( $decr === false ){ if( $decr === false ){
slog("cyclic-hash:decr returned $decr EXIT_STATUS", 'api:init','update'); slog("cyclic-hash:decr returned $decr EXIT_STATUS", 'api:sync','update');
return 127; return 127;
} }
return 0; slog('HTTP Response succesfully received', 'api:sync', 'update');
/* [8] Deploy received data /* [8] Deploy received data
=========================================================*/ =========================================================*/
/* (1) Manage response deployement */ /* (1) Manage response deployement */
$deploy = syscall(SOURCE_DIR.'/lib/api/deploy sync'); $deploy = syscall(SOURCE_DIR.'/lib/api/deploy');
/* (2) Return state */ /* (2) Return state */
return ($deploy === true) ? 0 : 127; return ($deploy === true) ? 0 : 127;
@ -148,7 +152,9 @@
} }
die(api_request()); $exec = api_request();
echo $exec;
die($exec);

View File

@ -12,24 +12,32 @@ export CONF_DIR="$ROOT_DIR/conf";
export SOURCE_DIR="/home/xdrm-brackets/Desktop/git.xdr/home/xdrm-brackets/Desktop/git.xdrm.io/logauth-sats"; export SOURCE_DIR="/home/xdrm-brackets/Desktop/git.xdr/home/xdrm-brackets/Desktop/git.xdrm.io/logauth-sats";
export TMP_DIR="$ROOT_DIR/tmp"; export TMP_DIR="$ROOT_DIR/tmp";
# CONFIGURATION FILES # CONFIGURATION FILES
export SECRET_CONF="$CONF_DIR/machine.secret"; export SECRET_CONF="$CONF_DIR/machine.secret";
export STATE_CONF="$CONF_DIR/machine.state"; export STATE_CONF="$CONF_DIR/machine.state";
export BRANCH_CONF="$CONF_DIR/machine.branch"; export BRANCH_CONF="$CONF_DIR/machine.branch";
export ID_CONF="$CONF_DIR/machine.id"; export ID_CONF="$CONF_DIR/machine.id";
export URL_CONF="$CONF_DIR/api.url"; export URL_CONF="$CONF_DIR/api.url";
export AUTH_CONF="$CONF_DIR/auth.list";
export WAREHOUSE_TOK="$CONF_DIR/warehouse.token"; export WAREHOUSE_TOK="$CONF_DIR/warehouse.token";
export UNLOCK_CODE="$CONF_DIR/machine.unlock"; export UNLOCK_CODE="$CONF_DIR/machine.unlock";
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";
# LOG FILES # LOG FILES
export BOOT_LOG="$LOG_DIR/boot.log"; export BOOT_LOG="$LOG_DIR/boot.log";
export DAEMON_LOG="$LOG_DIR/daemon.log"; export DAEMON_LOG="$LOG_DIR/daemon.log";
export INSTALL_LOG="$LOG_DIR/install-source.log"; export INSTALL_LOG="$LOG_DIR/install-source.log";
export UPDATE_LOG="$LOG_DIR/update.log"; export UPDATE_LOG="$LOG_DIR/update.log";
# DATA FILES # DATA FILES
export ACCESS_DATA="$DATA_DIR/access.data"; export DEFAULT_DATA="$DATA_DIR/mfrc522";
# SETTINGS # SETTINGS
export SECRET_SIZE=250; export SECRET_SIZE=250;

View File

@ -18,10 +18,14 @@
define('BRANCH_CONF', CONF_DIR.'/machine.branch'); define('BRANCH_CONF', CONF_DIR.'/machine.branch');
define('ID_CONF', CONF_DIR.'/machine.id'); define('ID_CONF', CONF_DIR.'/machine.id');
define('URL_CONF', CONF_DIR.'/api.url'); define('URL_CONF', CONF_DIR.'/api.url');
define('AUTH_CONF', CONF_DIR.'/auth.list');
define('WAREHOUSE_TOK', CONF_DIR.'/warehouse.token'); define('WAREHOUSE_TOK', CONF_DIR.'/warehouse.token');
define('UNLOCK_CODE', CONF_DIR.'/machine.unlock'); define('UNLOCK_CODE', CONF_DIR.'/machine.unlock');
define('AUTH_CONF', CONF_DIR.'/auth.list');
define('STATES_CONF', CONF_DIR.'/states.list');
define('CHIPS_CONF', CONF_DIR.'/chips.list');
define('ACTIONS_CONF', CONF_DIR.'/actions.list');
# LOG FILES # LOG FILES
define('BOOT_LOG', LOG_DIR.'/boot.log'); define('BOOT_LOG', LOG_DIR.'/boot.log');
define('DAEMON_LOG', LOG_DIR.'/daemon.log'); define('DAEMON_LOG', LOG_DIR.'/daemon.log');
@ -29,7 +33,7 @@
define('UPDATE_LOG', LOG_DIR.'/update.log'); define('UPDATE_LOG', LOG_DIR.'/update.log');
# DATA FILES # DATA FILES
define('ACCESS_DATA', DATA_DIR.'/access.data'); define('DEFAULT_DATA', DATA_DIR.'/mfrc522');
# SETTINGS # SETTINGS
define('SECRET_SIZE', 250); define('SECRET_SIZE', 250);

View File

@ -50,6 +50,9 @@
=========================================================*/ =========================================================*/
/* [3] Manage action (states)
=========================================================*/
/* [n] Wait for 0.5 s before reading again /* [n] Wait for 0.5 s before reading again
=========================================================*/ =========================================================*/