2017-01-27 11:21:32 +00:00
|
|
|
<?php
|
|
|
|
|
2017-01-27 14:54:30 +00:00
|
|
|
/* [1] Launches external script
|
|
|
|
=========================================================*/
|
2017-01-27 19:41:02 +00:00
|
|
|
function syscall($dependency=null){
|
2017-02-20 21:26:26 +00:00
|
|
|
|
|
|
|
// cut in words
|
|
|
|
$words = explode(' ', $dependency);
|
|
|
|
|
2017-01-27 11:21:32 +00:00
|
|
|
/* (1) Check file */
|
2017-02-20 21:26:26 +00:00
|
|
|
if( is_null($dependency) || !file_exists($words[0]) )
|
2017-01-27 14:54:30 +00:00
|
|
|
return false;
|
2017-01-27 11:21:32 +00:00
|
|
|
|
|
|
|
/* (2) Call and catch output */
|
2017-02-18 10:09:49 +00:00
|
|
|
$out = shell_exec("$dependency 2> /dev/null;");
|
2017-01-27 11:21:32 +00:00
|
|
|
|
2017-01-27 19:41:02 +00:00
|
|
|
/* (3) Clean output */
|
|
|
|
$out = preg_replace('/^\s+/', '', $out);
|
|
|
|
$out = preg_replace('/\s+$/', '', $out);
|
2017-01-27 14:54:30 +00:00
|
|
|
|
|
|
|
/* (4) Manage result */
|
2017-10-12 17:19:46 +00:00
|
|
|
if( is_numeric($out) && $out === "0" )
|
|
|
|
return false;
|
|
|
|
elseif( is_numeric($out) && $out === "127" )
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return $out;
|
2017-01-27 11:21:32 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 19:41:02 +00:00
|
|
|
/* [2] Log management
|
|
|
|
=========================================================*/
|
2017-01-30 09:59:52 +00:00
|
|
|
function slog($message="unknown error", $feature="main", $flag="daemon"){
|
2017-01-27 19:41:02 +00:00
|
|
|
|
2017-01-27 20:00:06 +00:00
|
|
|
file_put_contents(LOG_DIR."/$flag.log", time()." [$feature] $message\n", FILE_APPEND);
|
2017-01-27 19:41:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-27 11:21:32 +00:00
|
|
|
?>
|