22 *****************************************************************************/ |
22 *****************************************************************************/ |
23 |
23 |
24 require_once('utilities.php'); |
24 require_once('utilities.php'); |
25 |
25 |
26 |
26 |
27 $sock = open_socket(); |
|
28 if ($sock == false) { |
|
29 load('index.php'); |
|
30 } |
|
31 |
|
32 socket_write($sock, "UNIT LIST", 4096); |
|
33 $answer = ""; |
|
34 while (1) { |
|
35 $line = socket_read($sock, 4096); |
|
36 if ($line === '') |
|
37 break; |
|
38 $answer .= $line; |
|
39 } |
|
40 socket_close($sock); |
|
41 |
|
42 /* |
27 /* |
43 * $arr contains the complete reply of the LIST command. |
28 * $arr contains the complete reply of the LIST command. |
44 */ |
29 */ |
|
30 $answer = send_cmd("UNIT LIST"); |
45 $arr = explode("\r\n", $answer); |
31 $arr = explode("\r\n", $answer); |
46 |
32 |
47 |
33 |
48 if (isset($_GET['action'])) { |
34 if (isset($_GET['action'])) { |
49 switch ($_GET['action']) { |
35 switch ($_GET['action']) { |
73 * @param string $_POST['Name'] The rpofile name |
59 * @param string $_POST['Name'] The rpofile name |
74 */ |
60 */ |
75 function unit_add() { |
61 function unit_add() { |
76 |
62 |
77 if ($_POST['key'] == 'Add') { |
63 if ($_POST['key'] == 'Add') { |
78 |
64 send_cmd("UNIT ADD ".$_POST['Name']); |
79 $cmd = "UNIT ADD ".$_POST['Name']; |
|
80 |
|
81 $sock = open_socket(); |
|
82 if ($sock != false) { |
|
83 /* |
|
84 * Send command and absorb the result. |
|
85 */ |
|
86 socket_write($sock, $cmd, 4096); |
|
87 while (1) { |
|
88 $line = socket_read($sock, 4096); |
|
89 if ($line === '') |
|
90 break; |
|
91 } |
|
92 socket_close($sock); |
|
93 } |
|
94 } |
65 } |
95 |
66 |
96 unset($_POST['UUID']); |
67 unset($_POST['UUID']); |
97 unset($_POST['Name']); |
68 unset($_POST['Name']); |
98 unset($_POST['key']); |
69 unset($_POST['key']); |
112 function unit_update() { |
83 function unit_update() { |
113 /* |
84 /* |
114 * Build the update command |
85 * Build the update command |
115 */ |
86 */ |
116 if ($_POST['key'] == 'Delete') { |
87 if ($_POST['key'] == 'Delete') { |
117 $sock = open_socket(); |
88 send_cmd("UNIT DEL ".$_POST['UUID']); |
118 if ($sock != false) { |
|
119 socket_write($sock, "UNIT DEL ".$_POST['UUID'], 4096); |
|
120 /* Absorb response */ |
|
121 while (1) { |
|
122 $line = socket_read($sock, 4096); |
|
123 if ($line === '') |
|
124 break; |
|
125 } |
|
126 socket_close($sock); |
|
127 } |
|
128 } |
89 } |
129 |
90 |
130 if ($_POST['key'] == 'Save') { |
91 if ($_POST['key'] == 'Save') { |
131 $sock = open_socket(); |
92 $sock = open_socket(); |
132 if ($sock != false) { |
93 if ($sock != false) { |
281 function edit_screen($UUID, $command, $heading, $error_message) { |
242 function edit_screen($UUID, $command, $heading, $error_message) { |
282 |
243 |
283 /* |
244 /* |
284 * Get list of devices, we need it later |
245 * Get list of devices, we need it later |
285 */ |
246 */ |
286 $sock = open_socket(); |
247 $answer = send_cmd("DEVICE LIST"); |
287 if ($sock == false) { |
|
288 load("units.php"); |
|
289 return; |
|
290 } |
|
291 |
|
292 socket_write($sock, "DEVICE LIST", 4096); |
|
293 $answer = ""; |
|
294 while (1) { |
|
295 $line = socket_read($sock, 4096); |
|
296 if ($line === '') |
|
297 break; |
|
298 $answer .= $line; |
|
299 } |
|
300 socket_close($sock); |
|
301 $devices = explode("\r\n", $answer); |
248 $devices = explode("\r\n", $answer); |
302 |
249 |
303 /* |
250 /* |
304 * Get current unit data |
251 * Get current unit data |
305 */ |
252 */ |
306 $sock = open_socket(); |
253 $answer = send_cmd("UNIT GET ".$UUID); |
307 if ($sock == false) { |
|
308 load("units.php"); |
|
309 return; |
|
310 } |
|
311 |
|
312 socket_write($sock, "UNIT GET ".$UUID, 4096); |
|
313 $answer = ""; |
|
314 while (1) { |
|
315 $line = socket_read($sock, 4096); |
|
316 if ($line === '') |
|
317 break; |
|
318 $answer .= $line; |
|
319 } |
|
320 socket_close($sock); |
|
321 $reply = explode("\r\n", $answer); |
254 $reply = explode("\r\n", $answer); |
322 |
255 |
323 $outstr = build_header($heading); |
256 $outstr = build_header($heading); |
324 $outstr .= ' <div id="errors">'.PHP_EOL; |
257 $outstr .= ' <div id="errors">'.PHP_EOL; |
325 $outstr .= ' '.$error_message.PHP_EOL; |
258 $outstr .= ' '.$error_message.PHP_EOL; |