From 415bd4e549131046df1b45ad881fcc161f9884da Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Wed, 20 Jul 2016 10:55:04 +0200 Subject: [PATCH] Client Virtuel : Enregistrement des actions dans l'historique --- js/lib/sha256-min.js | 6 ++++++ manager/module/machineDefault.php | 5 ++++- manager/repo/action_merge.php | 4 ++-- test/automate.php | 12 ------------ test/client/interface.php | 18 ++++++++++++++---- 5 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 js/lib/sha256-min.js diff --git a/js/lib/sha256-min.js b/js/lib/sha256-min.js new file mode 100644 index 0000000..9bd92d3 --- /dev/null +++ b/js/lib/sha256-min.js @@ -0,0 +1,6 @@ +var sha256={hash:function(a){a=a.utf8Encode();var d=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411, +3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],b=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];a+=String.fromCharCode(128);for(var g=Math.ceil((a.length/4+2)/16),h=Array(g),f=0;fe;e++)h[f][e]=a.charCodeAt(64*f+4*e)<<24|a.charCodeAt(64* +f+4*e+1)<<16|a.charCodeAt(64*f+4*e+2)<<8|a.charCodeAt(64*f+4*e+3)}h[g-1][14]=8*(a.length-1)/Math.pow(2,32);h[g-1][14]=Math.floor(h[g-1][14]);h[g-1][15]=8*(a.length-1)&4294967295;a=Array(64);for(var l,m,q,k,n,p,r,f=0;fc;c++)a[c]=h[f][c];for(c=16;64>c;c++)a[c]=sha256.\u03c31(a[c-2])+a[c-7]+sha256.\u03c30(a[c-15])+a[c-16]&4294967295;e=b[0];l=b[1];m=b[2];q=b[3];k=b[4];n=b[5];p=b[6];r=b[7];for(c=0;64>c;c++){var t=r+sha256.\u03a31(k)+sha256.Ch(k,n,p)+d[c]+a[c],u=sha256.\u03a30(e)+ +sha256.Maj(e,l,m);r=p;p=n;n=k;k=q+t&4294967295;q=m;m=l;l=e;e=t+u&4294967295}b[0]=b[0]+e&4294967295;b[1]=b[1]+l&4294967295;b[2]=b[2]+m&4294967295;b[3]=b[3]+q&4294967295;b[4]=b[4]+k&4294967295;b[5]=b[5]+n&4294967295;b[6]=b[6]+p&4294967295;b[7]=b[7]+r&4294967295}return sha256.toHexStr(b[0])+sha256.toHexStr(b[1])+sha256.toHexStr(b[2])+sha256.toHexStr(b[3])+sha256.toHexStr(b[4])+sha256.toHexStr(b[5])+sha256.toHexStr(b[6])+sha256.toHexStr(b[7])},ROTR:function(a,d){return d>>>a|d<<32-a},"\u03a30":function(a){return sha256.ROTR(2, +a)^sha256.ROTR(13,a)^sha256.ROTR(22,a)},"\u03a31":function(a){return sha256.ROTR(6,a)^sha256.ROTR(11,a)^sha256.ROTR(25,a)},"\u03c30":function(a){return sha256.ROTR(7,a)^sha256.ROTR(18,a)^a>>>3},"\u03c31":function(a){return sha256.ROTR(17,a)^sha256.ROTR(19,a)^a>>>10},Ch:function(a,d,b){return a&d^~a&b},Maj:function(a,d,b){return a&d^a&b^d&b},toHexStr:function(a){for(var d="",b,g=7;0<=g;g--)b=a>>>4*g&15,d+=b.toString(16);return d}}; +"undefined"==typeof String.prototype.utf8Encode&&(String.prototype.utf8Encode=function(){return unescape(encodeURIComponent(this))});"undefined"==typeof String.prototype.utf8Decode&&(String.prototype.utf8Decode=function(){try{return decodeURIComponent(escape(this))}catch(a){return this}});"undefined"!=typeof module&&module.exports&&(module.exports=sha256);"function"==typeof define&&define.amd&&define([],function(){return sha256}); diff --git a/manager/module/machineDefault.php b/manager/module/machineDefault.php index 52bb351..b21003d 100755 --- a/manager/module/machineDefault.php +++ b/manager/module/machineDefault.php @@ -445,7 +445,10 @@ $indexed_permissions = []; foreach($permissions as $p=>$permission) - $indexed_permissions[$permission['code']] = explode(',', $permission['actions']); + $indexed_permissions[$permission['code']] = [ + 'id_user' => $permission['id_user'], + 'actions' => explode(',', $permission['actions']) + ]; diff --git a/manager/repo/action_merge.php b/manager/repo/action_merge.php index fca35ce..28aec95 100644 --- a/manager/repo/action_merge.php +++ b/manager/repo/action_merge.php @@ -177,7 +177,7 @@ */ public static function getPermissions($id_warehouse, $id_machine){ - $getPermissions = Database::getPDO()->prepare("SELECT u.code, GROUP_CONCAT(DISTINCT a.id_action ORDER BY a.id_action ASC) as actions + $getPermissions = Database::getPDO()->prepare("SELECT u.id_user, u.code, GROUP_CONCAT(DISTINCT a.id_action ORDER BY a.id_action ASC) as actions FROM user as u, user_cluster as uc, @@ -199,7 +199,7 @@ AND am.id_target = mc.id_machine_cluster AND a.id_action = am.id_action - GROUP BY u.code"); + GROUP BY u.id_user, u.code"); $getPermissions->execute([ ':id_warehouse' => $id_warehouse, diff --git a/test/automate.php b/test/automate.php index 7b5633b..2266754 100755 --- a/test/automate.php +++ b/test/automate.php @@ -337,18 +337,6 @@ debug(); - $int = '1'; - $flo1 = '1.2'; - $flo2 = '1,2'; - $str = '1,s2'; - $arr = [$int, $flo1, $flo2, $str]; - - - var_dump( Database::autotype($int) ); - var_dump( Database::autotype($flo1) ); - var_dump( Database::autotype($flo2) ); - var_dump( Database::autotype($str) ); - var_dump( Database::autotype($arr) ); ?> diff --git a/test/client/interface.php b/test/client/interface.php index 39f3d27..65ca54f 100644 --- a/test/client/interface.php +++ b/test/client/interface.php @@ -239,7 +239,7 @@ lsi.createDataset('STATES.CNF' ); lsi.createDataset('ACTIONS.CNF'); lsi.createDataset('CHIPS.CNF'); - lsi.createDataset('PERMISSIONS.CNF' ); + lsi.createDataset('PERMISSIONS.CNF'); lsi.createDataset('SERVER.CNF' ); lsi.createDataset('HISTORY.LOG'); lsi.createDataset('STATES.LOG' ); @@ -248,6 +248,7 @@ var api = new APIClass('/api/'); var ACTIONS, STATES, CHIPS, PERMISSIONS; + api.send({path: 'machineDefault/init', id_machine: 1}, function(response){ lsi.import('ACTIONS.CNF', response.actions); lsi.import('STATES.CNF', response.states); @@ -363,18 +364,27 @@ for( var a in Object.keys(ACTIONS[COUNT]) ){ /* (3) On vérifie que l'utilisateur a la permissions d'effectuer l'action */ - var hasPermission = PERMISSIONS.hasOwnProperty(CARD) && PERMISSIONS[CARD].indexOf( ACTIONS[COUNT][a].id_action.toString() ) > -1; + var hasPermission = PERMISSIONS.hasOwnProperty(CARD) && PERMISSIONS[CARD].actions.indexOf( ACTIONS[COUNT][a].id_action.toString() ) > -1; // Si on a pas la permission, on quitte if( !hasPermission ) continue; - // Si pas la permission, on fait rien - if( !hasPermission ) break; + /* (4) Si la condition est correcte, On applique la modification de l'état */ if( previous(ACTIONS[COUNT][a].previous, STATE) ){ action(ACTIONS[COUNT][a].action, STATE); + + /* (5) On enregistre l'action dans l'historique */ + var historyKeys = lsi.keys('HISTORY.LOG').length; + + lsi.set('HISTORY.LOG', historyKeys+1, { + id_user: parseInt(PERMISSIONS[CARD].id_user), + id_machine: 1, + id_action: parseInt(ACTIONS[COUNT][a].id_action) + }); + break; }