From ed3f8eb835cca49679249ad3d4e84982d6195e68 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 21 Feb 2017 15:59:04 +0100 Subject: [PATCH] [Upgrade] Updated new Permission management (SMMP all in header)History sync works --- lib/api/source/sync.php | 25 +++++++++++-------------- lib/gpio/in | 2 +- lib/gpio/out | 2 +- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/api/source/sync.php b/lib/api/source/sync.php index ba7ab32..c1da740 100755 --- a/lib/api/source/sync.php +++ b/lib/api/source/sync.php @@ -27,15 +27,15 @@ } /* (3) Try new hash if available */ - $new = syscall(SOURCE_DIR.'/lib/cyclic-hash/new'); + $new_hash = syscall(SOURCE_DIR.'/lib/cyclic-hash/new'); - if( $new === false ){ + if( $new_hash === false ){ slog("cyclic-hash:new returned $new EXIT_STATUS", 'api:sync','update'); return 127; } /* (4) Fetch data */ - $data = json_decode(syscall(SOURCE_DIR.'/lib/api/fetch')); + $data = json_decode(syscall(SOURCE_DIR.'/lib/api/fetch'), true); if( is_null($data) ){ slog("api:fetch returned unreadable content", 'api:sync','update'); @@ -62,16 +62,9 @@ /* [3] Manage post data =========================================================*/ /* (1) Set post data */ - $postarray = [ - 'token' => $hash, - 'data' => json_encode($data) - ]; + $postarray = [ 'data' => json_encode($data) ]; - /* (2) Add renew if renew */ - if( strlen($new) == 128 ) - $postarray['renew'] = $new; - - /* (3) Set postdata raw to curl */ + /* (2) Set postdata raw to curl */ curl_setopt($curl, CURLOPT_POSTFIELDS, $postarray); @@ -87,9 +80,13 @@ $wh_tok = preg_replace('/\s/', '', $wh_tok); - /* (2) Set Auth header digest */ + /* (2) Calculate @new_hash (default value) */ + if( strlen($new_hash) != 128 ) + $new_hash = $hash; + + /* (3) Set Auth header digest */ curl_setopt($curl, CURLOPT_HTTPHEADER, [ - "Authorization: Digest $wh_tok" + "Authorization: Digest {$wh_tok}{$hash}{$new_hash}" ]); diff --git a/lib/gpio/in b/lib/gpio/in index cd930fb..ae446e7 100755 --- a/lib/gpio/in +++ b/lib/gpio/in @@ -32,7 +32,7 @@ test -d /sys/class/gpio/gpio$1 || echo $1 > /sys/class/gpio/export; # [4] Set mode to OUT #========================================================# -icat /sys/class/gpio/gpio$1/direction | grep -v "in" && echo "in" > /sys/class/gpio/gpio$1/direction; +cat /sys/class/gpio/gpio$1/direction | grep -v "in" && echo "in" > /sys/class/gpio/gpio$1/direction; diff --git a/lib/gpio/out b/lib/gpio/out index 27e47ce..a2446ac 100755 --- a/lib/gpio/out +++ b/lib/gpio/out @@ -32,7 +32,7 @@ test -d /sys/class/gpio/gpio$1 || echo $1 > /sys/class/gpio/export; # [4] Set mode to OUT #========================================================# -icat /sys/class/gpio/gpio$1/direction | grep -v "out" && echo "out" > /sys/class/gpio/gpio$1/direction; +cat /sys/class/gpio/gpio$1/direction | grep -v "out" && echo "out" > /sys/class/gpio/gpio$1/direction;