diff --git a/lib/api/auth b/lib/api/auth deleted file mode 100755 index 5098831..0000000 --- a/lib/api/auth +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/php - - diff --git a/lib/api/request b/lib/api/request new file mode 100755 index 0000000..1fc33c7 --- /dev/null +++ b/lib/api/request @@ -0,0 +1,3 @@ +#!/bin/sh + +php $(realpath $(dirname $0))/source/request.php; diff --git a/lib/api/send b/lib/api/send deleted file mode 100755 index e24449c..0000000 --- a/lib/api/send +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/php - - POST */ - curl_setopt($curl, CURLOPT_POST, true); - - /* (3) Set headers */ - curl_setopt($curl, CURLOPT_HTTPHEADER, [ - 'Content-Type: multipart/form-data; boundary=' - ]); - - } - - echo api_send(); - - - -?> diff --git a/lib/api/source/request.php b/lib/api/source/request.php new file mode 100755 index 0000000..c006473 --- /dev/null +++ b/lib/api/source/request.php @@ -0,0 +1,109 @@ + POST */ + curl_setopt($curl, CURLOPT_POST, true); + + + + /* [3] Manage post data + =========================================================*/ + /* (1) Set post data */ + $postarray = [ + 'token' => $hash, + 'data' => $data + ]; + + /* (2) Add renew if renew */ + if( strlen($new) == 128 ) + $postarray['renew'] = $new; + + /* (3) Parse postfiels to multipart format */ + $postraw = "--$boundary"; + + foreach($postarray as $postkey=>$postvalue) + $postraw .= "\r\ncontent-disposition: form-data; name=\"$postkey\"\r\n\r\n$postvalue\r\n--$boundary"; + + $postraw .= "--"; + + + /* (4) Set postdata raw to curl */ + curl_setopt($curl, CURLOPT_POSTFIELDS, $postraw); + + + + /* [4] Manage headers + =========================================================*/ + curl_setopt($curl, CURLOPT_HTTPHEADER, [ + "Content-Type: multipart/form-data; boundary=$boundary", + "Content-Length: ".strlen($postraw) + ]); + + + /* [5] Send and catch request response + =========================================================*/ + /* (1) Send and catch response */ + $response = curl_exec($curl); + + /* (2) Close request */ + curl_close($curl); + + /* (3) Return response as result */ + if( $response === false ) + return 127; + + return $response; + + } + + echo api_request(); + + + +?> diff --git a/lib/api/source/sync.php b/lib/api/source/sync.php new file mode 100755 index 0000000..8ac3bda --- /dev/null +++ b/lib/api/source/sync.php @@ -0,0 +1,106 @@ + POST */ + curl_setopt($curl, CURLOPT_POST, true); + + + + /* [3] Manage post data + =========================================================*/ + /* (1) Set post data */ + $postarray = [ + 'token' => $hash, + 'data' => $data + ]; + + /* (2) Add renew if renew */ + if( strlen($new) == 128 ) + $postarray['renew'] = $new; + + /* (3) Parse postfiels to multipart format */ + $postraw = "--$boundary"; + + foreach($postarray as $postkey=>$postvalue) + $postraw .= "\r\ncontent-disposition: form-data; name=\"$postkey\"\r\n\r\n$postvalue\r\n--$boundary"; + + $postraw .= "--"; + + + /* (4) Set postdata raw to curl */ + curl_setopt($curl, CURLOPT_POSTFIELDS, $postraw); + + + + /* [4] Manage headers + =========================================================*/ + curl_setopt($curl, CURLOPT_HTTPHEADER, [ + "Content-Type: multipart/form-data; boundary=$boundary", + "Content-Length: ".strlen($postraw) + ]); + + + /* [5] Send and catch request response + =========================================================*/ + /* (1) Send and catch response */ + $response = curl_exec($curl); + + /* (2) Close request */ + curl_close($curl); + + /* (3) Return response as result */ + return $response; + + } + + echo api_sync(); + + + +?> diff --git a/lib/api/sync b/lib/api/sync new file mode 100755 index 0000000..080f13e --- /dev/null +++ b/lib/api/sync @@ -0,0 +1,3 @@ +#!/bin/sh + +php $(realpath $(dirname $0))/source/sync.php; diff --git a/lib/cyclic-hash/decr b/lib/cyclic-hash/decr index bbf384f..2a78700 100755 --- a/lib/cyclic-hash/decr +++ b/lib/cyclic-hash/decr @@ -1,92 +1,3 @@ -#!/usr/bin/php +#!/bin/sh - 1 ){ - - /* (1) Decrement the depth */ - $depth--; - - /* (2) Try to override the secret file */ - if( @file_put_contents(SECRET_CONF, "$key:$depth") ) - return 0; - else - return 127; - - - /* [4] If cannot decrement, generate new password - =========================================================*/ - }else{ - - // Generate new secret - $secret = generate_secret().':999'; - - // Try to override the secret file - if( @file_put_contents(SECRET_CONF, $secret) ) - return 0; - else - return 127; - - } - - return 0; - - - } - - echo cyclichash_decr(); - - -?> +php $(realpath $(dirname $0))/source/decr.php; diff --git a/lib/cyclic-hash/hash b/lib/cyclic-hash/hash index a719f70..ffe1d47 100755 --- a/lib/cyclic-hash/hash +++ b/lib/cyclic-hash/hash @@ -1,40 +1,3 @@ -#!/usr/bin/php - - +#!/bin/sh +php $(realpath $(dirname $0))/source/hash.php; diff --git a/lib/cyclic-hash/new b/lib/cyclic-hash/new index 8c136ad..4e2befe 100755 --- a/lib/cyclic-hash/new +++ b/lib/cyclic-hash/new @@ -1,43 +1,3 @@ -#!/usr/bin/php +#!/bin/sh - +php $(realpath $(dirname $0))/source/new.php; diff --git a/lib/cyclic-hash/source/decr.php b/lib/cyclic-hash/source/decr.php new file mode 100755 index 0000000..1d7f1e8 --- /dev/null +++ b/lib/cyclic-hash/source/decr.php @@ -0,0 +1,99 @@ + 1 ){ + + /* (1) Decrement the depth */ + $depth--; + + /* (2) Try to override the secret file */ + if( @file_put_contents(SECRET_CONF, "$key:$depth") ){ + slog("Secret depth decremented to $depth", 'cyclic-hash:decr'); + return 0; + }else{ + slog("Error while decrementing secret depth", 'cyclic-hash:decr'); + return 127; + } + + + /* [4] If cannot decrement, generate new password + =========================================================*/ + }else{ + + // Generate new secret + $secret = generate_secret().':999'; + + // Try to override the secret file + if( @file_put_contents(SECRET_CONF, $secret) ){ + slog("Random secret generated successfully", 'cyclic-hash:decr'); + return 0; + }else{ + slog("Error while generating new random secret", 'cyclic-hash:decr'); + return 127; + } + + } + + return 0; + + + } + + echo cyclichash_decr(); + + +?> diff --git a/lib/cyclic-hash/source/hash.php b/lib/cyclic-hash/source/hash.php new file mode 100755 index 0000000..ffcb88d --- /dev/null +++ b/lib/cyclic-hash/source/hash.php @@ -0,0 +1,42 @@ +#!/usr/bin/php + + + diff --git a/lib/cyclic-hash/source/new.php b/lib/cyclic-hash/source/new.php new file mode 100755 index 0000000..fdf2ba4 --- /dev/null +++ b/lib/cyclic-hash/source/new.php @@ -0,0 +1,48 @@ +#!/usr/bin/php + + diff --git a/lib/include/const b/lib/include/const index 3e5c777..b7e12a5 100755 --- a/lib/include/const +++ b/lib/include/const @@ -1,4 +1,3 @@ -#!/usr/bin/php