upd: lib.cyclic-hash{decr,source/decr.php} > added optional arg 'revert' to `incr` instead of `decr`
This commit is contained in:
parent
2eeb4ed6ff
commit
d564612512
|
@ -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;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
|
||||
|
||||
require_once __DIR__.'/../../include/php/const';
|
||||
|
||||
|
||||
|
@ -24,14 +24,14 @@
|
|||
|
||||
|
||||
|
||||
function cyclichash_decr(){
|
||||
function cyclichash_decr($decr_factor=-1){
|
||||
|
||||
/* [2] Fetch necessary data
|
||||
=========================================================*/
|
||||
|
||||
/* (1) Fetch secret file */
|
||||
$secret = @file_get_contents(SECRET_CONF);
|
||||
|
||||
|
||||
/* (2) Check secret file format */
|
||||
if( !is_string($secret) || !preg_match("/^(.{".SECRET_SIZE."}):(\d+):(.{".SECRET_SIZE."})$/", $secret, $match) ){
|
||||
|
||||
|
@ -59,7 +59,7 @@
|
|||
if( $depth > 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);
|
||||
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue