forked from StepanNakonechnyi/vivabill_agent_freebsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fn_ovsp.php
133 lines (99 loc) · 3.83 KB
/
fn_ovsp.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
function cmanager_ovsp_action ($id, $ch, $connect_url, $connect_api, $action, $comment) {
include ("config.php");
$func_role = basename(__FILE__)." ".__FUNCTION__ ;
$result="";
curl_setopt($ch, CURLOPT_URL, $connect_url."set_cmanager_ovsp_action");
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id\":\"".$id."\",\"action\":\"".$action."\",\"api\":\"".$connect_api."\"}");
$return=curl_exec($ch);
if(curl_errno($ch)) {
echo system_addlog($func_role,"1","Curl error: ". curl_error($ch) );
} else {
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpcode == "200") {
$result_json = json_decode($return, true);
$result = $result_json["result"];
} else {
$last_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
echo system_addlog ($func_role,"1","Error [".$httpcode."] ".$last_url);
}
}
return $result;
}
function cmanager_ovsp_task_result ($id_comx_manager, $ch, $connect_url, $connect_api) {
include ("config.php");
$task_result="0";
foreach (glob($ovsp_dir."*.task") as $filename) {
$task_result="1";
}
if ( $task_result == "1") {
cmanager_ovsp_check($id_comx_manager, $ch, $connect_url, $connect_api);
}
}
function cmanager_ovsp_check ($id_comx_manager, $ch, $connect_url, $connect_api) {
include ("config.php");
$func_role = basename(__FILE__)." ".__FUNCTION__ ;
foreach (glob($ovsp_dir."*.task") as $filename) {
$data = file_get_contents ($filename);
$config_json = json_decode($data, true);
$id=$config_json["process"]["id"];
$status=$config_json["process"]["status"];
$comment=$config_json["process"]["comment"];
$file_task=$ovsp_dir.$id.".task";
$file_data=$ovsp_dir.$id.".data";
if ( $status == "success") {
if ( cmanager_ovsp_action($id, $ch, $connect_url, $connect_api, "success", $comment) == "success") {
if (file_exists($file_task)) { unlink($file_task); }
if (file_exists($file_data)) { unlink($file_data); }
echo system_addlog($func_role, "0", "Task ID-".$id.". ".$comment);
}
}
if ( $status == "error") {
if ( cmanager_ovsp_action($id, $ch, $connect_url, $connect_api, "error", $comment) == "success") {
if (file_exists($file_task)) { unlink($file_task); }
if (file_exists($file_data)) { unlink($file_data); }
echo system_addlog($func_role, "1", "Task ID-".$id.". ".$comment);
}
}
}
}
function cmanager_ovsp_task ($id_comx_manager, $ch, $connect_url, $connect_api) {
include ("config.php");
$func_role = basename(__FILE__)." ".__FUNCTION__ ;
curl_setopt($ch, CURLOPT_URL, $connect_url."get_cmanager_ovsp_list");
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"id_comx_manager\":\"".$id_comx_manager."\",\"api\":\"".$connect_api."\"}");
$return=curl_exec($ch);
if(curl_errno($ch)) {
echo system_addlog($func_role,"1","Curl error: ". curl_error($ch) );
} else {
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpcode == "200") {
$r_ovsp = json_decode($return,true);
foreach ($r_ovsp as $ovsp) {
$id=$ovsp["id"];
$data_file=$ovsp_dir.$id.".data";
$task_file=$ovsp_dir.$id.".task";
if (!file_exists($task_file)) {
$fp = fopen($data_file, "w");
fwrite($fp, json_encode($ovsp));
fclose($fp);
$execute_name=$driver_dir.$ovsp["execute"]["name"];
if ( cmanager_ovsp_action($id, $ch, $connect_url, $connect_api, "process","") == "success" ) {
$execute_command=$execute_name." ".$id." < /dev/null >> ".$log_dir."vivabill.log &";
$return=system_exec($execute_command);
echo system_addlog($func_role, $return, $execute_command );
}
} else {
echo message_addlog($func_role,"Task ".$id." is exists");
}
}
} else {
$last_url=curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
echo system_addlog($func_role,"1","Error [".$httpcode."] ".$last_url);
}
}
}
function cmanager_comx ($id_comx_manager, $ch, $connect_url, $connect_api) {
include("config.php");
}
?>