[Update] Factored `machineDefault/init` content to fetch basic working information (idem in `machineDefault/sync`)
This commit is contained in:
parent
aa5e2a572e
commit
cdb7818998
|
@ -452,47 +452,23 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* ENVOI DES DONNEES D'INITIALISATION DU SYSTEME DES MACHINES
|
||||
/* RETURNS ALL INFORMATION NEEDED BY MACHINES IN ORDER TO WORK
|
||||
*
|
||||
* @return id_machine<int> UID de la machine
|
||||
* @return token<string> Nouveau token d'identification (hashage cyclique)
|
||||
* @return unlock<string> Code de déblocage de la machine
|
||||
* @id_machine<int> Machine UID
|
||||
*
|
||||
* @return data<Array<Mixed>> Useful data
|
||||
*
|
||||
*/
|
||||
public function init($params){
|
||||
extract($params);
|
||||
private static function getMachineWorkingInformation($id_machine){
|
||||
|
||||
|
||||
/* [1] On essaie de débloquer la machine
|
||||
=========================================================*/
|
||||
/* (1) On rédige la requête */
|
||||
$unlockReq = new Repo('machine/unlock', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_machine,
|
||||
$unlock,
|
||||
$token
|
||||
]);
|
||||
|
||||
/* (2) On gère l'erreur */
|
||||
if( $unlockReq->error->get() != Err::Success || !$unlockReq->answer() )
|
||||
return [ 'error' => new Error(Err::TokenError) ];
|
||||
|
||||
|
||||
/* [2] On récupére la liste des actions
|
||||
/* [1] On récupére la liste des actions
|
||||
=========================================================*/
|
||||
$actionsReq = new Repo('action/getAll');
|
||||
$actions = ($actionsReq->error->get()==Err::Success) ? $actionsReq->answer() : [];
|
||||
// var_dump($actionsReq->answer());
|
||||
|
||||
|
||||
/* [3] On regroupe les actions par TIMEOUT
|
||||
/* [2] On regroupe les actions par TIMEOUT
|
||||
=========================================================*/
|
||||
$sorted_actions = [];
|
||||
|
||||
|
@ -511,13 +487,13 @@
|
|||
}
|
||||
|
||||
|
||||
/* [4] On récupère la liste des états
|
||||
/* [3] On récupère la liste des états
|
||||
=========================================================*/
|
||||
$globalStatesReq = new Repo('global_state/getAll');
|
||||
$globalStates = ($globalStatesReq->error->get()==Err::Success) ? $globalStatesReq->answer() : [];
|
||||
|
||||
|
||||
/* [5] On récupère la liste des MODULES (puces)
|
||||
/* [4] On récupère la liste des MODULES (puces)
|
||||
=========================================================*/
|
||||
$chipsReq = new Repo('chip/getAll', [$_SESSION['WAREHOUSE']['id']]);
|
||||
$chips = ($chipsReq->error->get()==Err::Success) ? $chipsReq->answer() : [];
|
||||
|
@ -552,7 +528,7 @@
|
|||
}
|
||||
|
||||
|
||||
/* [6] On récupère les utilisateurs + accès sur la machine
|
||||
/* [5] On récupère les utilisateurs + accès sur la machine
|
||||
=========================================================*/
|
||||
/* (1) On récupère les utilisateurs et leurs permissions */
|
||||
$permissionsReq = new Repo('action_merge/getAccess', [
|
||||
|
@ -602,6 +578,47 @@
|
|||
|
||||
|
||||
|
||||
/* ENVOI DES DONNEES D'INITIALISATION DU SYSTEME DES MACHINES
|
||||
*
|
||||
* @return id_machine<int> UID de la machine
|
||||
* @return token<string> Nouveau token d'identification (hashage cyclique)
|
||||
* @return unlock<string> Code de déblocage de la machine
|
||||
*
|
||||
*/
|
||||
public function init($params){
|
||||
extract($params);
|
||||
|
||||
|
||||
/* [1] On essaie de débloquer la machine
|
||||
=========================================================*/
|
||||
/* (1) On rédige la requête */
|
||||
$unlockReq = new Repo('machine/unlock', [
|
||||
$_SESSION['WAREHOUSE']['id'],
|
||||
$id_machine,
|
||||
$unlock,
|
||||
$token
|
||||
]);
|
||||
|
||||
/* (2) On gère l'erreur */
|
||||
if( $unlockReq->error->get() != Err::Success || !$unlockReq->answer() )
|
||||
return [ 'error' => new Error(Err::TokenError) ];
|
||||
|
||||
|
||||
/* [N] Retourne les données
|
||||
=========================================================*/
|
||||
return self::getMachineWorkingInformation($id_machine);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -645,21 +662,50 @@
|
|||
$data = ['a', 'b'];
|
||||
|
||||
|
||||
|
||||
/* [2] Données à reçues
|
||||
z
|
||||
/* [2] Gestion des données reçues
|
||||
=========================================================*/
|
||||
/* (1) For each history entry */
|
||||
if( isset($data['history']) && is_array($data['history']) )
|
||||
|
||||
/* (2) Create history entry in db */
|
||||
foreach($data['history'] as $entry){
|
||||
|
||||
// {1} Build request //
|
||||
$log_req = new Request('historyDefault/create', [
|
||||
'id_user' => $entry[0],
|
||||
'id_machine' => $entry[1],
|
||||
'id_action' => $entry[2],
|
||||
'timestamp' => $entry[3]
|
||||
]);
|
||||
|
||||
// {2} Manage error //
|
||||
if( $log_req->error->get() != Err::Success )
|
||||
continue;
|
||||
|
||||
// {3} Process + get response //
|
||||
$log_res = $log_req->dispatch();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* [3] Données à envoyer
|
||||
|
||||
|
||||
/* [3] Gestion des données à envoyer
|
||||
=========================================================*/
|
||||
/* (1) Basic working data update
|
||||
---------------------------------------------------------*/
|
||||
$basis_update = self::getMachineWorkingInformation($id_machine);
|
||||
|
||||
|
||||
return [
|
||||
'data' => $data
|
||||
];
|
||||
|
||||
|
||||
|
||||
/* [4] Envoi des données
|
||||
=========================================================*/
|
||||
return array_merge($basis_update, ['data' => $data]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,12 +3,18 @@ require_once __ROOT__.'/autoloader.php';
|
|||
|
||||
$_SESSION['history'] = [];
|
||||
|
||||
if( !isset($_COOKIE['mac_password']) || !isset($_COOKIE['mac_count']) ){
|
||||
if( !isset($_COOKIE['mac_password']) || !isset($_COOKIE['mac_count']) || !isset($_COOKIE['token']) ){
|
||||
$_COOKIE['mac_count'] = 10;
|
||||
$_COOKIE['mac_password'] = 'macPassword';
|
||||
|
||||
// hash password
|
||||
$_COOKIE['token'] = $_COOKIE['mac_password'];
|
||||
for( $i = 0 ; $i < $_COOKIE['mac_count'] ; $i++ )
|
||||
$_COOKIE['token'] = hash('512', $_COOKIE['token']);
|
||||
|
||||
setcookie('mac_count', $_COOKIE['mac_count'], time()+3600*24*365, '/');
|
||||
setcookie('mac_password', $_COOKIE['mac_password'], time()+3600*24*365, '/');
|
||||
setcookie('token', $_COOKIE['token'], time()+3600*24*365, '/');
|
||||
|
||||
header('Refresh: 0');
|
||||
}
|
||||
|
@ -249,7 +255,13 @@ if( !isset($_COOKIE['mac_password']) || !isset($_COOKIE['mac_count']) ){
|
|||
|
||||
var ACTIONS, STATES, CHIPS, PERMISSIONS;
|
||||
|
||||
api.send({path: 'machineDefault/init', id_machine: 1}, function(response){
|
||||
var request = {
|
||||
path: 'machineDefault/init',
|
||||
id_machine: 126,
|
||||
token:
|
||||
};
|
||||
|
||||
api.send({path: 'machineDefault/init', id_machine: 126}, function(response){
|
||||
lsi.import('ACTIONS.CNF', response.actions);
|
||||
lsi.import('STATES.CNF', response.states);
|
||||
lsi.import('CHIPS.CNF', response.chips);
|
||||
|
|
Loading…
Reference in New Issue