Fixed log flag for api/cyclic-hash
This commit is contained in:
parent
390312ad41
commit
68d82b9218
|
@ -10,7 +10,7 @@
|
||||||
$url = @file_get_contents(URL_CONF);
|
$url = @file_get_contents(URL_CONF);
|
||||||
|
|
||||||
if( $url === false ){
|
if( $url === false ){
|
||||||
slog("Cannot find server's api url", 'api:sync');
|
slog("Cannot find server's api url", 'api:sync','update');
|
||||||
return 127;
|
return 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
$hash = syscall(SOURCE_DIR.'/lib/cyclic-hash/hash');
|
$hash = syscall(SOURCE_DIR.'/lib/cyclic-hash/hash');
|
||||||
|
|
||||||
if( strlen($hash) != 128 ){
|
if( strlen($hash) != 128 ){
|
||||||
slog("Wrong cyclic-hash:hash hash length (".strlen($hash).")", 'api:sync');
|
slog("Wrong cyclic-hash:hash hash length (".strlen($hash).")", 'api:sync','update');
|
||||||
return 127;
|
return 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
$new = syscall(SOURCE_DIR.'/lib/cyclic-hash/new');
|
$new = syscall(SOURCE_DIR.'/lib/cyclic-hash/new');
|
||||||
|
|
||||||
if( $new === false ){
|
if( $new === false ){
|
||||||
slog("cyclic-hash:new returned $new EXIT_STATUS", 'api:sync');
|
slog("cyclic-hash:new returned $new EXIT_STATUS", 'api:sync','update');
|
||||||
return 127;
|
return 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
$data = json_decode(syscall(SOURCE_DIR.'/lib/api/fetch'));
|
$data = json_decode(syscall(SOURCE_DIR.'/lib/api/fetch'));
|
||||||
|
|
||||||
if( is_null($data) ){
|
if( is_null($data) ){
|
||||||
slog("api:fetch returned unreadable content", 'api:sync');
|
slog("api:fetch returned unreadable content", 'api:sync','update');
|
||||||
$data = [];
|
$data = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@
|
||||||
|
|
||||||
/* (3) Return response as result */
|
/* (3) Return response as result */
|
||||||
if( $response === false ){
|
if( $response === false ){
|
||||||
slog("Request error", 'api:sync');
|
slog("Request error", 'api:sync','update');
|
||||||
return 127;
|
return 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@
|
||||||
$decr = syscall(SOURCE_DIR.'/lib/cyclic-hash/decr');
|
$decr = syscall(SOURCE_DIR.'/lib/cyclic-hash/decr');
|
||||||
|
|
||||||
if( $decr === false ){
|
if( $decr === false ){
|
||||||
slog("cyclic-hash:decr returned $decr EXIT_STATUS", 'api:sync');
|
slog("cyclic-hash:decr returned $decr EXIT_STATUS", 'api:sync','update');
|
||||||
return 127;
|
return 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,10 +40,10 @@
|
||||||
|
|
||||||
// Try to override the secret file
|
// Try to override the secret file
|
||||||
if( @file_put_contents(SECRET_CONF, $secret) ){
|
if( @file_put_contents(SECRET_CONF, $secret) ){
|
||||||
slog("Random secret generated successfully", 'cyclic-hash:decr');
|
slog("Random secret generated successfully", 'cyclic-hash:decr', 'update');
|
||||||
return 0;
|
return 0;
|
||||||
}else{
|
}else{
|
||||||
slog("Error while generating new random secret", 'cyclic-hash:decr');
|
slog("Error while generating new random secret", 'cyclic-hash:decr', 'update');
|
||||||
return 127;
|
return 127;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,10 +63,10 @@
|
||||||
|
|
||||||
/* (2) Try to override the secret file */
|
/* (2) Try to override the secret file */
|
||||||
if( @file_put_contents(SECRET_CONF, "$key:$depth:$next") ){
|
if( @file_put_contents(SECRET_CONF, "$key:$depth:$next") ){
|
||||||
slog("Secret depth decremented to $depth", 'cyclic-hash:decr');
|
slog("Secret depth decremented to $depth", 'cyclic-hash:decr', 'update');
|
||||||
return 0;
|
return 0;
|
||||||
}else{
|
}else{
|
||||||
slog("Error while decrementing secret depth", 'cyclic-hash:decr');
|
slog("Error while decrementing secret depth", 'cyclic-hash:decr', 'update');
|
||||||
return 127;
|
return 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,10 +80,10 @@
|
||||||
|
|
||||||
// Try to override the secret file
|
// Try to override the secret file
|
||||||
if( @file_put_contents(SECRET_CONF, $secret) ){
|
if( @file_put_contents(SECRET_CONF, $secret) ){
|
||||||
slog("Random secret generated successfully", 'cyclic-hash:decr');
|
slog("Random secret generated successfully", 'cyclic-hash:decr', 'update');
|
||||||
return 0;
|
return 0;
|
||||||
}else{
|
}else{
|
||||||
slog("Error while generating new random secret", 'cyclic-hash:decr');
|
slog("Error while generating new random secret", 'cyclic-hash:decr', 'update');
|
||||||
return 127;
|
return 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
$hash = hash('sha512', $hash);
|
$hash = hash('sha512', $hash);
|
||||||
|
|
||||||
|
|
||||||
slog("Returning hash with $depth depth", 'cyclic-hash:hash');
|
slog("Returning hash with $depth depth", 'cyclic-hash:hash', 'update');
|
||||||
return $hash;
|
return $hash;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
/* (2) Check secret file format */
|
/* (2) Check secret file format */
|
||||||
if( !is_string($secret) || !preg_match("/^(.{".SECRET_SIZE."}):(\d+):(.{".SECRET_SIZE."})$/", $secret, $match) ){
|
if( !is_string($secret) || !preg_match("/^(.{".SECRET_SIZE."}):(\d+):(.{".SECRET_SIZE."})$/", $secret, $match) ){
|
||||||
slog("Error while reading secret", 'cyclic-hash:new');
|
slog("Error while reading secret", 'cyclic-hash:new', 'update');
|
||||||
return 127;
|
return 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* (4) Die if not token not changed */
|
/* (4) Die if not token not changed */
|
||||||
if( $depth > 1 ){
|
if( $depth > 1 ){
|
||||||
slog("No new secret with $depth depth", 'cyclic-hash:new');
|
slog("No new secret with $depth depth", 'cyclic-hash:new', 'update');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
for( $d = 0 ; $d < 1000 ; $d++ )
|
for( $d = 0 ; $d < 1000 ; $d++ )
|
||||||
$newhash = hash('sha512', $newhash);
|
$newhash = hash('sha512', $newhash);
|
||||||
|
|
||||||
slog("New secret with $depth depth", 'cyclic-hash:new');
|
slog("New secret with $depth depth", 'cyclic-hash:new', 'update');
|
||||||
return $newhash;
|
return $newhash;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
/* [2] Log management
|
/* [2] Log management
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
function slog($message="unknown error...", $feature="default", $flag="daemon"){
|
function slog($message="unknown error", $feature="main", $flag="daemon"){
|
||||||
|
|
||||||
file_put_contents(LOG_DIR."/$flag.log", time()." [$feature] $message\n", FILE_APPEND);
|
file_put_contents(LOG_DIR."/$flag.log", time()." [$feature] $message\n", FILE_APPEND);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue