diff --git a/lib/cyclic-hash/decr b/lib/cyclic-hash/decr index 41f572b..6f0c053 100755 --- a/lib/cyclic-hash/decr +++ b/lib/cyclic-hash/decr @@ -1,3 +1,3 @@ #!/bin/sh -/usr/bin/env php $(realpath $(dirname $0))/source/decr.php; +/usr/bin/env php $(realpath $(dirname $0))/source/decr.php $1; diff --git a/lib/cyclic-hash/source/decr.php b/lib/cyclic-hash/source/decr.php index 37ba7dc..fd8d1de 100755 --- a/lib/cyclic-hash/source/decr.php +++ b/lib/cyclic-hash/source/decr.php @@ -1,5 +1,5 @@ 1 ){ /* (1) Decrement the depth */ - $depth--; + $depth += $decr_factor; /* (2) Try to override the secret file */ if( @file_put_contents(SECRET_CONF, "$key:$depth:$next") ){ @@ -74,7 +74,7 @@ /* [4] If cannot decrement, use new secret and generate next =========================================================*/ }else{ - + // Generate new secret $secret = $next.':999:'.generate_secret(); @@ -94,7 +94,10 @@ } - echo cyclichash_decr(); + // IF received 'revert' as $1 -> increment ELSE decrement (default) + $decr_factor = ( $argc < 2 || $argv[1] != 'revert' ) ? -1 : +1; + + echo cyclichash_decr($decr_factor); ?>