-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglobal-example.php
120 lines (104 loc) · 3.12 KB
/
global-example.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
<?php
static $api_url = "";
$object = null;
$action = null;
$attr_get = "";
$attr_post = array(
"",
);
function GetServerMemUsage(){
$free = shell_exec('free');
$free = (string)trim($free);
$free_arr = explode("\n", $free);
$mem = explode(" ", $free_arr[1]);
$mem = array_filter($mem);
$mem = array_merge($mem);
$memory_usage = $mem[2]/$mem[1]*100;
return $memory_usage;
}
function GetServerCpuUsage(){
$load = sys_getloadavg();
return $load[0];
}
function MemberReadAll(){
$object = "member";
$action = "read";
$attr_get = "operator_uid=1";
$json_return = CurlGet("member", "read", $attr_get);
return $json_return;
}
/*
function MemberReadById($uid)
function MemberMoneyEditById()
function MemberLiveOrDieById()
function MissionCreate($mission)
*/
function MissionReadAll(){
$object = "mission";
$action = "read";
$attr_get = "operator_uid=1";
$json_return = CurlGet("mission", "read", $attr_get);
return $json_return;
}
/*
function MissionReadById($mid)
function MissionEditById($mission)
function MissionDeleteById($mid)
function ReportReadAll()
function ReportReadById($rid)
function ReportCheckById($rid)
function ReportDeleteById($rid)
function ToolCreate()
function ToolReadAll()
function ToolReadById($tid)
function ToolDeleteById($tid)
function ClueCreate()
function ClueReadAll()
function ClueReadById($cid)
function ClueDeleteById($cid)
function PackCreate()
function PackReadAll()
function PackReadByUserId($uid)
function PackDeleteByRecordId($pid)
*/
function CurlGet($object, $action, $attr_get){
$ch = curl_init();
$api_url = "http://nthuee.org:8081/api/v1.1/";
curl_setopt($ch, CURLOPT_URL, $api_url. $object."/".$action."?".$attr_get);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$result = json_decode($result, true);
curl_close($ch);
return $result;
}
function CurlPost(){
curl_setopt($ch, CURLOPT_URL, $api_url+"/"+$object+"/"+$action);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($attr_post));
$result = curl_exec($ch);
$result = json_decode($result, true);
curl_close($ch);
return $result;
}
function CurlPut(){
curl_setopt($ch, CURLOPT_URL, $api_url+"/"+$object+"/"+$action);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($attr_post));
$result = curl_exec($ch);
$result = json_decode($result, true);
curl_close($ch);
return $result;
}
function CurlDelete(){
curl_setopt($ch, CURLOPT_URL, $api_url+"/"+$object+"/"+$action);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($attr_post));
$result = curl_exec($ch);
$result = json_decode($result, true);
curl_close($ch);
return $result;
}
?>