15 @date_default_timezone_set(@date_default_timezone_get());
17 require_once
'hce_cli_api.inc.php';
18 require_once
'hce_drce_api.inc.php';
21 defined(
'LOG_MODE_JSON') or define('LOG_MODE_JSON', 3);
22 defined('RESPONSE_TIMEOUT_DEFAULT') or define('RESPONSE_TIMEOUT_DEFAULT', 5000);
24 if(php_sapi_name()!=='cli' || !
defined('STDIN')){
25 echo
'Only cli execution mode supported'.PHP_EOL;
34 ' [--host=<router_host>] [--port=<router_port>] [--request=<request_type{SET, CHECK, TERMINATE, GET, DELETE}>] [--id=<task_id>] [--json=<json_protocol_file>]'.
35 ' [--n=<max_queries_number>] [--d=<request_delay_ms>] [--ttl=<request_msg_ttl_ms>] [--l=<log_mode{0-no,1-result,(2-params),3-json,4-result+object}>]'.
36 ' [--t=<response_timeout_ms, '.RESPONSE_TIMEOUT_DEFAULT.
' default>] [--cid=<client_id>] [--subtasks=<json_subtasks_file>]'.
37 ' [--route=<route string include of node names list comma separated>]'.
38 ' [--cover=<0-strip cover from response|1-response with cover> used only with --l=3]'.PHP_EOL;
52 $requests_names=array(
'SET'=>HCE_DRCE_REQUEST_TYPE_SET,
'CHECK'=>HCE_DRCE_REQUEST_TYPE_CHECK,
'TERMINATE'=>HCE_DRCE_REQUEST_TYPE_TERMINATE,
'GET'=>HCE_DRCE_REQUEST_TYPE_GET,
'DELETE'=>HCE_DRCE_REQUEST_TYPE_DELETE);
54 echo
'Error: --request not supported "'.$REQUEST_TYPE.
'"'.PHP_EOL;
59 $REQUEST_ID=isset(
$args[
'id']) ?
$args[
'id'] : 0;
61 echo
'Error: this --request required --id value greater than zero'.PHP_EOL;
71 if(!isset(
$args[
'json']) || !file_exists(
$args[
'json'])){
72 echo
'Error: --json required option or file not set or not found'.PHP_EOL;
75 $input_json=trim(file_get_contents(
$args[
'json']));
79 if(isset(
$args[
'subtasks'])){
80 if(!file_exists(
$args[
'subtasks'])){
81 echo
'Error: --subtasks file not set or not found: "'.$args[
'subtasks'].
'"'.PHP_EOL;
85 $subtasks=file_get_contents(
$args[
'subtasks']);
96 $strip_cover=isset(
$args[
'cover']) ?
$args[
'cover']+0 : 1;
102 echo
'Request json: '.PHP_EOL.$Request_body.PHP_EOL;
105 if(isset($r[HCE_DRCE_EXEC_FIELD_DATA])){
106 $r[HCE_DRCE_EXEC_FIELD_DATA]=json_decode($r[HCE_DRCE_EXEC_FIELD_DATA],
true);
107 if(isset($r[HCE_DRCE_EXEC_FIELD_DATA][HCE_DRCE_EXEC_FIELD_DATA])){
108 $r[HCE_DRCE_EXEC_FIELD_DATA][HCE_DRCE_EXEC_FIELD_DATA]=json_decode(base64_decode($r[HCE_DRCE_EXEC_FIELD_DATA][HCE_DRCE_EXEC_FIELD_DATA]),
true);
109 if(is_array($r[HCE_DRCE_EXEC_FIELD_DATA][
'subtasks'])){
110 foreach($r[HCE_DRCE_EXEC_FIELD_DATA][
'subtasks'] as $key=>$st){
111 if(is_array($st) && isset($st[
'data'])){
112 $r[HCE_DRCE_EXEC_FIELD_DATA][
'subtasks'][$key][
'data']=json_decode(base64_decode($st[
'data']),
true);
116 echo PHP_EOL.cli_prettyPrintJson(json_encode($r),
' ').PHP_EOL;
123 echo
'Error: create request json fault'.PHP_EOL;