Commit | Line | Data |
---|---|---|
b325120a | 1 | <?php |
e673ee24 DO |
2 | /* |
3 | * | |
4 | * This file is a library of operation handlers for RackTables. | |
5 | * | |
6 | */ | |
7 | ||
b6a7d936 | 8 | $msgcode = array(); |
17c32f4c | 9 | |
b6a7d936 | 10 | function buildWideRedirectURL ($log, $nextpage = NULL, $nexttab = NULL, $moreArgs = array()) |
17c32f4c | 11 | { |
790a60e8 | 12 | global $page, $pageno, $tabno; |
b6a7d936 DO |
13 | if ($nextpage === NULL) |
14 | $nextpage = $pageno; | |
15 | if ($nexttab === NULL) | |
16 | $nexttab = $tabno; | |
790a60e8 | 17 | $url = "index.php?page=${nextpage}&tab=${nexttab}"; |
b6a7d936 DO |
18 | if (isset ($page[$nextpage]['bypass'])) |
19 | $url .= '&' . $page[$nextpage]['bypass'] . '=' . $_REQUEST[$page[$nextpage]['bypass']]; | |
17c32f4c | 20 | |
b6a7d936 | 21 | if (count($moreArgs)>0) |
17c32f4c | 22 | { |
b6a7d936 DO |
23 | foreach($moreArgs as $arg=>$value) |
24 | { | |
25 | if (gettype($value) == 'array') | |
26 | { | |
27 | foreach ($value as $v) | |
28 | { | |
29 | $url .= '&'.urlencode($arg.'[]').'='.urlencode($v); | |
30 | } | |
31 | } | |
32 | else | |
33 | $url .= '&'.urlencode($arg).'='.urlencode($value); | |
34 | } | |
17c32f4c | 35 | } |
b6a7d936 DO |
36 | |
37 | $_SESSION['log'] = $log; | |
38 | return $url; | |
17c32f4c DO |
39 | } |
40 | ||
05d3c190 | 41 | function buildRedirectURL ($callfunc, $status, $log_args = array(), $nextpage = NULL, $nexttab = NULL, $url_args = array()) |
17c32f4c | 42 | { |
b6a7d936 DO |
43 | global $pageno, $tabno, $msgcode; |
44 | if ($nextpage === NULL) | |
45 | $nextpage = $pageno; | |
46 | if ($nexttab === NULL) | |
47 | $nexttab = $tabno; | |
05d3c190 | 48 | return buildWideRedirectURL (oneLiner ($msgcode[$callfunc][$status], $log_args), $nextpage, $nexttab, $url_args); |
17c32f4c DO |
49 | } |
50 | ||
b6a7d936 DO |
51 | $msgcode['addPortForwarding']['OK'] = 2; |
52 | $msgcode['addPortForwarding']['ERR'] = 100; | |
e673ee24 DO |
53 | function addPortForwarding () |
54 | { | |
0cc24e9a DY |
55 | assertUIntArg ('object_id'); |
56 | assertIPv4Arg ('localip'); | |
57 | assertIPv4Arg ('remoteip'); | |
58 | assertUIntArg ('localport'); | |
59 | assertStringArg ('proto'); | |
60 | assertStringArg ('description', TRUE); | |
103b1e1e | 61 | $remoteport = isset ($_REQUEST['remoteport']) ? $_REQUEST['remoteport'] : ''; |
59a83bd8 | 62 | if (!strlen ($remoteport)) |
f75eb878 | 63 | $remoteport = $_REQUEST['localport']; |
e673ee24 | 64 | |
9bea3a8b DO |
65 | $error = newPortForwarding |
66 | ( | |
103b1e1e | 67 | $_REQUEST['object_id'], |
9bea3a8b DO |
68 | $_REQUEST['localip'], |
69 | $_REQUEST['localport'], | |
70 | $_REQUEST['remoteip'], | |
71 | $remoteport, | |
72 | $_REQUEST['proto'], | |
73 | $_REQUEST['description'] | |
74 | ); | |
e673ee24 DO |
75 | |
76 | if ($error == '') | |
135080d8 | 77 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 78 | else |
135080d8 | 79 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 DO |
80 | } |
81 | ||
b6a7d936 DO |
82 | $msgcode['delPortForwarding']['OK'] = 3; |
83 | $msgcode['delPortForwarding']['ERR'] = 100; | |
e673ee24 DO |
84 | function delPortForwarding () |
85 | { | |
0cc24e9a DY |
86 | assertUIntArg ('object_id'); |
87 | assertIPv4Arg ('localip'); | |
88 | assertIPv4Arg ('remoteip'); | |
89 | assertUIntArg ('localport'); | |
90 | assertUIntArg ('remoteport'); | |
91 | assertStringArg ('proto'); | |
e673ee24 | 92 | |
103b1e1e DO |
93 | $error = deletePortForwarding |
94 | ( | |
95 | $_REQUEST['object_id'], | |
96 | $_REQUEST['localip'], | |
97 | $_REQUEST['localport'], | |
98 | $_REQUEST['remoteip'], | |
99 | $_REQUEST['remoteport'], | |
100 | $_REQUEST['proto'] | |
101 | ); | |
e673ee24 | 102 | if ($error == '') |
135080d8 | 103 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 104 | else |
135080d8 | 105 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 DO |
106 | } |
107 | ||
b6a7d936 DO |
108 | $msgcode['updPortForwarding']['OK'] = 4; |
109 | $msgcode['updPortForwarding']['ERR'] = 100; | |
e673ee24 DO |
110 | function updPortForwarding () |
111 | { | |
0cc24e9a DY |
112 | assertUIntArg ('object_id'); |
113 | assertIPv4Arg ('localip'); | |
114 | assertIPv4Arg ('remoteip'); | |
115 | assertUIntArg ('localport'); | |
116 | assertUIntArg ('remoteport'); | |
117 | assertStringArg ('proto'); | |
118 | assertStringArg ('description'); | |
e673ee24 | 119 | |
103b1e1e DO |
120 | $error = updatePortForwarding |
121 | ( | |
122 | $_REQUEST['object_id'], | |
123 | $_REQUEST['localip'], | |
124 | $_REQUEST['localport'], | |
125 | $_REQUEST['remoteip'], | |
126 | $_REQUEST['remoteport'], | |
127 | $_REQUEST['proto'], | |
128 | $_REQUEST['description'] | |
129 | ); | |
e673ee24 | 130 | if ($error == '') |
135080d8 | 131 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 132 | else |
135080d8 | 133 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 DO |
134 | } |
135 | ||
b6a7d936 DO |
136 | $msgcode['addPortForObject']['OK'] = 5; |
137 | $msgcode['addPortForObject']['ERR1'] = 101; | |
138 | $msgcode['addPortForObject']['ERR2'] = 100; | |
e673ee24 DO |
139 | function addPortForObject () |
140 | { | |
0cc24e9a DY |
141 | assertUIntArg ('object_id'); |
142 | assertStringArg ('port_name', TRUE); | |
59a83bd8 | 143 | if (!strlen ($_REQUEST['port_name'])) |
135080d8 | 144 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
103b1e1e DO |
145 | $error = commitAddPort ($_REQUEST['object_id'], $_REQUEST['port_name'], $_REQUEST['port_type_id'], $_REQUEST['port_label'], $_REQUEST['port_l2address']); |
146 | if ($error != '') | |
135080d8 | 147 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error)); |
e673ee24 | 148 | else |
135080d8 | 149 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name'])); |
e673ee24 DO |
150 | } |
151 | ||
b6a7d936 DO |
152 | $msgcode['editPortForObject']['OK'] = 6; |
153 | $msgcode['editPortForObject']['ERR1'] = 101; | |
154 | $msgcode['editPortForObject']['ERR2'] = 100; | |
e673ee24 DO |
155 | function editPortForObject () |
156 | { | |
0cc24e9a DY |
157 | assertUIntArg ('object_id'); |
158 | assertUIntArg ('port_id'); | |
159 | assertUIntArg ('port_type_id'); | |
d0a69ce8 | 160 | // tolerate empty value now to produce custom informative message later |
0cc24e9a | 161 | assertStringArg ('name', TRUE); |
59a83bd8 | 162 | if (!strlen ($_REQUEST['name'])) |
135080d8 | 163 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
103b1e1e | 164 | |
59a83bd8 | 165 | if (isset ($_REQUEST['reservation_comment']) and strlen ($_REQUEST['reservation_comment'])) |
e673ee24 DO |
166 | $port_rc = '"' . $_REQUEST['reservation_comment'] . '"'; |
167 | else | |
168 | $port_rc = 'NULL'; | |
6be06cbb | 169 | $error = commitUpdatePort ($_REQUEST['object_id'], $_REQUEST['port_id'], $_REQUEST['name'], $_REQUEST['port_type_id'], $_REQUEST['label'], $_REQUEST['l2address'], $port_rc); |
103b1e1e | 170 | if ($error != '') |
135080d8 | 171 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error)); |
e673ee24 | 172 | else |
135080d8 | 173 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name'])); |
e673ee24 DO |
174 | } |
175 | ||
b6a7d936 DO |
176 | $msgcode['delPortFromObject']['OK'] = 7; |
177 | $msgcode['delPortFromObject']['ERR'] = 100; | |
e673ee24 DO |
178 | function delPortFromObject () |
179 | { | |
0cc24e9a | 180 | assertUIntArg ('port_id'); |
103b1e1e | 181 | $error = delObjectPort ($_REQUEST['port_id']); |
e673ee24 DO |
182 | |
183 | if ($error != '') | |
135080d8 | 184 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 | 185 | else |
135080d8 | 186 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name'])); |
e673ee24 DO |
187 | } |
188 | ||
b6a7d936 DO |
189 | $msgcode['linkPortForObject']['OK'] = 8; |
190 | $msgcode['linkPortForObject']['ERR'] = 100; | |
e673ee24 DO |
191 | function linkPortForObject () |
192 | { | |
0cc24e9a DY |
193 | assertUIntArg ('port_id'); |
194 | assertUIntArg ('remote_port_id'); | |
e673ee24 | 195 | |
cd3775e9 | 196 | // FIXME: ensure, that at least one of these ports belongs to the current object |
103b1e1e | 197 | $error = linkPorts ($_REQUEST['port_id'], $_REQUEST['remote_port_id']); |
e673ee24 | 198 | if ($error != '') |
135080d8 | 199 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
d0dadd80 DO |
200 | global $sic; |
201 | $local_port_info = getPortInfo ($sic['port_id']); | |
202 | $remote_port_info = getPortInfo ($sic['remote_port_id']); | |
cd3775e9 DO |
203 | $remote_object = spotEntity ('object', $remote_port_info['object_id']); |
204 | return buildRedirectURL | |
205 | ( | |
206 | __FUNCTION__, | |
207 | 'OK', | |
208 | array | |
209 | ( | |
210 | $local_port_info['name'], | |
211 | $remote_port_info['name'], | |
212 | $remote_object['dname'], | |
213 | ) | |
214 | ); | |
e673ee24 DO |
215 | } |
216 | ||
b6a7d936 DO |
217 | $msgcode['unlinkPortForObject']['OK'] = 9; |
218 | $msgcode['unlinkPortForObject']['ERR'] = 100; | |
e673ee24 DO |
219 | function unlinkPortForObject () |
220 | { | |
0cc24e9a DY |
221 | assertUIntArg ('port_id'); |
222 | assertUIntArg ('remote_port_id'); | |
e673ee24 | 223 | |
d0dadd80 DO |
224 | global $sic; |
225 | $local_port_info = getPortInfo ($sic['port_id']); | |
226 | $remote_port_info = getPortInfo ($sic['remote_port_id']); | |
cd3775e9 | 227 | $remote_object = spotEntity ('object', $remote_port_info['object_id']); |
103b1e1e | 228 | $error = unlinkPort ($_REQUEST['port_id']); |
e673ee24 | 229 | if ($error != '') |
135080d8 | 230 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
cd3775e9 DO |
231 | return buildRedirectURL |
232 | ( | |
233 | __FUNCTION__, | |
234 | 'OK', | |
235 | array | |
236 | ( | |
237 | $local_port_info['name'], | |
238 | $remote_port_info['name'], | |
239 | $remote_object['dname'], | |
240 | ) | |
241 | ); | |
e673ee24 DO |
242 | } |
243 | ||
b6a7d936 DO |
244 | $msgcode['addMultiPorts']['OK'] = 10; |
245 | $msgcode['addMultiPorts']['ERR'] = 123; | |
e673ee24 DO |
246 | function addMultiPorts () |
247 | { | |
0cc24e9a DY |
248 | assertStringArg ('format'); |
249 | assertStringArg ('input'); | |
250 | assertUIntArg ('port_type'); | |
251 | assertUIntArg ('object_id'); | |
e673ee24 DO |
252 | $format = $_REQUEST['format']; |
253 | $port_type = $_REQUEST['port_type']; | |
254 | $object_id = $_REQUEST['object_id']; | |
255 | // Input lines are escaped, so we have to explode and to chop by 2-char | |
256 | // \n and \r respectively. | |
257 | $lines1 = explode ('\n', $_REQUEST['input']); | |
258 | foreach ($lines1 as $line) | |
259 | { | |
260 | $parts = explode ('\r', $line); | |
261 | reset ($parts); | |
59a83bd8 | 262 | if (!strlen ($parts[0])) |
e673ee24 DO |
263 | continue; |
264 | else | |
265 | $lines2[] = rtrim ($parts[0]); | |
266 | } | |
267 | $ports = array(); | |
268 | foreach ($lines2 as $line) | |
269 | { | |
270 | switch ($format) | |
271 | { | |
272 | case 'fisxii': | |
84986395 | 273 | $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', $line)); |
e673ee24 DO |
274 | list ($slot, $port) = explode ('/', $words[0]); |
275 | $ports[] = array | |
276 | ( | |
277 | 'name' => "e ${slot}/${port}", | |
278 | 'l2address' => $words[8], | |
279 | 'label' => "slot ${slot} port ${port}" | |
280 | ); | |
281 | break; | |
282 | case 'c3600asy': | |
84986395 | 283 | $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', trim (substr ($line, 3)))); |
e673ee24 DO |
284 | /* |
285 | How Async Lines are Numbered in Cisco 3600 Series Routers | |
286 | http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00801ca70b.shtml | |
287 | ||
288 | Understanding 16- and 32-Port Async Network Modules | |
289 | http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00800a93f0.shtml | |
290 | */ | |
291 | $async = $words[0]; | |
292 | $slot = floor (($async - 1) / 32); | |
293 | $octalgroup = floor (($async - 1 - $slot * 32) / 8); | |
294 | $cable = $async - $slot * 32 - $octalgroup * 8; | |
295 | $og_label[0] = 'async 0-7'; | |
296 | $og_label[1] = 'async 8-15'; | |
297 | $og_label[2] = 'async 16-23'; | |
298 | $og_label[3] = 'async 24-31'; | |
299 | $ports[] = array | |
300 | ( | |
301 | 'name' => "async ${async}", | |
302 | 'l2address' => '', | |
303 | 'label' => "slot ${slot} " . $og_label[$octalgroup] . " cable ${cable}" | |
304 | ); | |
305 | break; | |
306 | case 'fiwg': | |
84986395 | 307 | $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', $line)); |
e673ee24 DO |
308 | $ifnumber = $words[0] * 1; |
309 | $ports[] = array | |
310 | ( | |
311 | 'name' => "e ${ifnumber}", | |
312 | 'l2address' => "${words[8]}", | |
313 | 'label' => "${ifnumber}" | |
314 | ); | |
315 | break; | |
351d4dbf | 316 | case 'ssv1': |
5b585342 | 317 | $words = explode (' ', $line); |
59a83bd8 | 318 | if (!strlen ($words[0]) or !strlen ($words[1])) |
351d4dbf DO |
319 | continue; |
320 | $ports[] = array | |
321 | ( | |
322 | 'name' => $words[0], | |
323 | 'l2address' => $words[1], | |
324 | 'label' => '' | |
325 | ); | |
326 | break; | |
e673ee24 | 327 | default: |
135080d8 | 328 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
329 | break; |
330 | } | |
331 | } | |
332 | // Create ports, if they don't exist. | |
333 | $added_count = $updated_count = $error_count = 0; | |
334 | foreach ($ports as $port) | |
335 | { | |
336 | $port_id = getPortID ($object_id, $port['name']); | |
337 | if ($port_id === NULL) | |
338 | { | |
339 | $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']); | |
340 | if ($result == '') | |
341 | $added_count++; | |
342 | else | |
343 | $error_count++; | |
344 | } | |
345 | else | |
346 | { | |
6be06cbb | 347 | $result = commitUpdatePort ($object_id, $port_id, $port['name'], $port_type, $port['label'], $port['l2address']); |
e673ee24 DO |
348 | if ($result == '') |
349 | $updated_count++; | |
350 | else | |
351 | $error_count++; | |
352 | } | |
353 | } | |
135080d8 | 354 | return buildRedirectURL (__FUNCTION__, 'OK', array ($added_count, $updated_count, $error_count)); |
e673ee24 DO |
355 | } |
356 | ||
b6a7d936 DO |
357 | $msgcode['updIPv4Allocation']['OK'] = 12; |
358 | $msgcode['updIPv4Allocation']['ERR'] = 100; | |
b4c1ef87 | 359 | function updIPv4Allocation () |
e673ee24 | 360 | { |
0cc24e9a DY |
361 | assertIPv4Arg ('ip'); |
362 | assertUIntArg ('object_id'); | |
363 | assertStringArg ('bond_name', TRUE); | |
364 | assertStringArg ('bond_type'); | |
e673ee24 | 365 | |
b4c1ef87 | 366 | $error = updateBond ($_REQUEST['ip'], $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']); |
e673ee24 | 367 | if ($error != '') |
135080d8 | 368 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 | 369 | else |
135080d8 | 370 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
371 | } |
372 | ||
b6a7d936 DO |
373 | $msgcode['delIPv4Allocation']['OK'] = 14; |
374 | $msgcode['delIPv4Allocation']['ERR'] = 100; | |
b4c1ef87 | 375 | function delIPv4Allocation () |
e673ee24 | 376 | { |
0cc24e9a DY |
377 | assertIPv4Arg ('ip'); |
378 | assertUIntArg ('object_id'); | |
e673ee24 | 379 | |
b4c1ef87 | 380 | $error = unbindIpFromObject ($_REQUEST['ip'], $_REQUEST['object_id']); |
e673ee24 | 381 | if ($error != '') |
135080d8 | 382 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 | 383 | else |
135080d8 | 384 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
385 | } |
386 | ||
b6a7d936 DO |
387 | $msgcode['addIPv4Allocation']['OK'] = 13; |
388 | $msgcode['addIPv4Allocation']['ERR1'] = 170; | |
389 | $msgcode['addIPv4Allocation']['ERR2'] = 100; | |
b4c1ef87 | 390 | function addIPv4Allocation () |
e673ee24 | 391 | { |
0cc24e9a DY |
392 | assertIPv4Arg ('ip'); |
393 | assertUIntArg ('object_id'); | |
394 | assertStringArg ('bond_name', TRUE); | |
395 | assertStringArg ('bond_type'); | |
da958e52 | 396 | |
b4c1ef87 | 397 | // Strip masklen. |
84986395 | 398 | $ip = preg_replace ('@/[[:digit:]]+$@', '', $_REQUEST['ip']); |
2be3fd23 | 399 | if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv4AddressNetworkId ($ip)) |
135080d8 | 400 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($ip)); |
5222f192 | 401 | |
b4c1ef87 | 402 | $error = bindIpToObject ($ip, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']); |
5222f192 | 403 | if ($error != '') |
135080d8 | 404 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error)); |
53ef3908 | 405 | $address = getIPv4Address ($ip); |
59a83bd8 | 406 | if ($address['reserved'] == 'yes' or strlen ($address['name'])) |
b4c1ef87 DO |
407 | { |
408 | $release = getConfigVar ('IPV4_AUTO_RELEASE'); | |
409 | if ($release >= 1) | |
410 | $address['reserved'] = 'no'; | |
411 | if ($release >= 2) | |
412 | $address['name'] = ''; | |
413 | updateAddress ($ip, $address['name'], $address['reserved']); | |
414 | } | |
135080d8 | 415 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
416 | } |
417 | ||
b6a7d936 DO |
418 | $msgcode['addIPv4Prefix']['OK'] = 23; |
419 | $msgcode['addIPv4Prefix']['ERR'] = 100; | |
420 | $msgcode['addIPv4Prefix']['ERR1'] = 173; | |
421 | $msgcode['addIPv4Prefix']['ERR2'] = 174; | |
422 | $msgcode['addIPv4Prefix']['ERR3'] = 175; | |
423 | $msgcode['addIPv4Prefix']['ERR4'] = 176; | |
42023f03 | 424 | function addIPv4Prefix () |
e673ee24 | 425 | { |
0cc24e9a DY |
426 | assertStringArg ('range'); |
427 | assertStringArg ('name', TRUE); | |
e673ee24 | 428 | |
fa05e3de DO |
429 | $is_bcast = isset ($_REQUEST['is_bcast']) ? $_REQUEST['is_bcast'] : 'off'; |
430 | $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); | |
357eb2ea DO |
431 | global $sic; |
432 | $error = createIPv4Prefix ($_REQUEST['range'], $sic['name'], $is_bcast == 'on', $taglist); | |
e673ee24 | 433 | if ($error != '') |
135080d8 | 434 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 | 435 | else |
135080d8 | 436 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
437 | } |
438 | ||
b6a7d936 DO |
439 | $msgcode['delIPv4Prefix']['OK'] = 24; |
440 | $msgcode['delIPv4Prefix']['ERR'] = 100; | |
42023f03 | 441 | function delIPv4Prefix () |
e673ee24 | 442 | { |
0cc24e9a | 443 | assertUIntArg ('id'); |
42023f03 | 444 | $error = destroyIPv4Prefix ($_REQUEST['id']); |
e673ee24 | 445 | if ($error != '') |
135080d8 | 446 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 | 447 | else |
135080d8 | 448 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
449 | } |
450 | ||
b6a7d936 DO |
451 | $msgcode['updIPv4Prefix']['OK'] = 25; |
452 | $msgcode['updIPv4Prefix']['ERR'] = 100; | |
04d619d0 | 453 | function updIPv4Prefix () |
e673ee24 | 454 | { |
0cc24e9a DY |
455 | assertUIntArg ('id'); |
456 | assertStringArg ('name', TRUE); | |
457 | assertStringArg ('comment', TRUE); | |
99ab184f DO |
458 | global $sic; |
459 | if (strlen ($error = updateIPv4Network_real ($sic['id'], $sic['name'], $sic['comment']))) | |
135080d8 | 460 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 | 461 | else |
135080d8 | 462 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
463 | } |
464 | ||
b6a7d936 DO |
465 | $msgcode['editAddress']['OK'] = 27; |
466 | $msgcode['editAddress']['ERR'] = 100; | |
e673ee24 DO |
467 | function editAddress () |
468 | { | |
0cc24e9a DY |
469 | assertIPv4Arg ('ip'); |
470 | assertStringArg ('name', TRUE); | |
e673ee24 | 471 | |
e673ee24 DO |
472 | if (isset ($_REQUEST['reserved'])) |
473 | $reserved = $_REQUEST['reserved']; | |
474 | else | |
475 | $reserved = 'off'; | |
da958e52 | 476 | $error = updateAddress ($_REQUEST['ip'], $_REQUEST['name'], $reserved == 'on' ? 'yes' : 'no'); |
e673ee24 | 477 | if ($error != '') |
135080d8 | 478 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 | 479 | else |
135080d8 | 480 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
481 | } |
482 | ||
b6a7d936 DO |
483 | $msgcode['createUser']['OK'] = 40; |
484 | $msgcode['createUser']['ERR'] = 102; | |
cced6b7d | 485 | function createUser () |
e673ee24 | 486 | { |
0cc24e9a DY |
487 | assertStringArg ('username'); |
488 | assertStringArg ('realname', TRUE); | |
489 | assertStringArg ('password'); | |
e673ee24 | 490 | $username = $_REQUEST['username']; |
93bdb7ba | 491 | $password = sha1 ($_REQUEST['password']); |
e673ee24 | 492 | $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password); |
f857f71f | 493 | if ($result != TRUE) |
135080d8 | 494 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($username)); |
f857f71f DO |
495 | if (isset ($_REQUEST['taglist'])) |
496 | produceTagsForLastRecord ('user', $_REQUEST['taglist']); | |
497 | return buildRedirectURL (__FUNCTION__, 'OK', array ($username)); | |
e673ee24 DO |
498 | } |
499 | ||
b6a7d936 DO |
500 | $msgcode['updateUser']['OK'] = 39; |
501 | $msgcode['updateUser']['ERR1'] = 103; | |
502 | $msgcode['updateUser']['ERR1'] = 104; | |
cced6b7d | 503 | function updateUser () |
e673ee24 | 504 | { |
0cc24e9a DY |
505 | assertUIntArg ('user_id'); |
506 | assertStringArg ('username'); | |
507 | assertStringArg ('realname', TRUE); | |
508 | assertStringArg ('password'); | |
e673ee24 DO |
509 | $username = $_REQUEST['username']; |
510 | $new_password = $_REQUEST['password']; | |
0b2c74cb | 511 | if (NULL == ($userinfo = spotEntity ('user', $_REQUEST['user_id']))) |
135080d8 | 512 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
e673ee24 | 513 | // Update user password only if provided password is not the same as current password hash. |
b82cce3f | 514 | if ($new_password != $userinfo['user_password_hash']) |
93bdb7ba | 515 | $new_password = sha1 ($new_password); |
103b1e1e | 516 | $result = commitUpdateUserAccount ($_REQUEST['user_id'], $username, $_REQUEST['realname'], $new_password); |
e673ee24 | 517 | if ($result == TRUE) |
135080d8 | 518 | return buildRedirectURL (__FUNCTION__, 'OK', array ($username)); |
e673ee24 | 519 | else |
135080d8 | 520 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($username)); |
e673ee24 DO |
521 | } |
522 | ||
b6a7d936 DO |
523 | $msgcode['updateDictionary']['OK'] = 51; |
524 | $msgcode['updateDictionary']['ERR'] = 109; | |
e673ee24 DO |
525 | function updateDictionary () |
526 | { | |
0cc24e9a DY |
527 | assertUIntArg ('chapter_no'); |
528 | assertUIntArg ('dict_key'); | |
529 | assertStringArg ('dict_value'); | |
e673ee24 | 530 | if (commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value']) === TRUE) |
135080d8 | 531 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 532 | else |
135080d8 | 533 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
534 | } |
535 | ||
b6a7d936 DO |
536 | $msgcode['supplementDictionary']['OK'] = 52; |
537 | $msgcode['supplementDictionary']['ERR'] = 110; | |
e673ee24 DO |
538 | function supplementDictionary () |
539 | { | |
0cc24e9a DY |
540 | assertUIntArg ('chapter_no'); |
541 | assertStringArg ('dict_value'); | |
e673ee24 | 542 | if (commitSupplementDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_value']) === TRUE) |
135080d8 | 543 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 544 | else |
135080d8 | 545 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
546 | } |
547 | ||
b6a7d936 DO |
548 | $msgcode['reduceDictionary']['OK'] = 50; |
549 | $msgcode['reduceDictionary']['ERR'] = 111; | |
e673ee24 DO |
550 | function reduceDictionary () |
551 | { | |
0cc24e9a DY |
552 | assertUIntArg ('chapter_no'); |
553 | assertUIntArg ('dict_key'); | |
e673ee24 | 554 | if (commitReduceDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key']) === TRUE) |
135080d8 | 555 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 556 | else |
135080d8 | 557 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
558 | } |
559 | ||
b6a7d936 DO |
560 | $msgcode['addChapter']['OK'] = 55; |
561 | $msgcode['addChapter']['ERR'] = 112; | |
e673ee24 DO |
562 | function addChapter () |
563 | { | |
0cc24e9a | 564 | assertStringArg ('chapter_name'); |
e673ee24 | 565 | if (commitAddChapter ($_REQUEST['chapter_name']) === TRUE) |
135080d8 | 566 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 567 | else |
135080d8 | 568 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
569 | } |
570 | ||
b6a7d936 DO |
571 | $msgcode['updateChapter']['OK'] = 54; |
572 | $msgcode['updateChapter']['ERR'] = 113; | |
e673ee24 DO |
573 | function updateChapter () |
574 | { | |
0cc24e9a DY |
575 | assertUIntArg ('chapter_no'); |
576 | assertStringArg ('chapter_name'); | |
e673ee24 | 577 | if (commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name']) === TRUE) |
135080d8 | 578 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 579 | else |
135080d8 | 580 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
581 | } |
582 | ||
b6a7d936 DO |
583 | $msgcode['delChapter']['OK'] = 53; |
584 | $msgcode['delChapter']['ERR'] = 114; | |
e673ee24 DO |
585 | function delChapter () |
586 | { | |
0cc24e9a | 587 | assertUIntArg ('chapter_no'); |
e673ee24 | 588 | if (commitDeleteChapter ($_REQUEST['chapter_no'])) |
135080d8 | 589 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 590 | else |
135080d8 | 591 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
592 | } |
593 | ||
b6a7d936 DO |
594 | $msgcode['changeAttribute']['OK'] = 46; |
595 | $msgcode['changeAttribute']['ERR'] = 115; | |
e673ee24 DO |
596 | function changeAttribute () |
597 | { | |
0cc24e9a DY |
598 | assertUIntArg ('attr_id'); |
599 | assertStringArg ('attr_name'); | |
e673ee24 | 600 | if (commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name'])) |
135080d8 | 601 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 602 | else |
135080d8 | 603 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
604 | } |
605 | ||
b6a7d936 DO |
606 | $msgcode['createAttribute']['OK'] = 45; |
607 | $msgcode['createAttribute']['ERR'] = 116; | |
e673ee24 DO |
608 | function createAttribute () |
609 | { | |
0cc24e9a DY |
610 | assertStringArg ('attr_name'); |
611 | assertStringArg ('attr_type'); | |
e673ee24 | 612 | if (commitAddAttribute ($_REQUEST['attr_name'], $_REQUEST['attr_type'])) |
135080d8 | 613 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['attr_name'])); |
e673ee24 | 614 | else |
135080d8 | 615 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
616 | } |
617 | ||
b6a7d936 DO |
618 | $msgcode['deleteAttribute']['OK'] = 47; |
619 | $msgcode['deleteAttribute']['ERR'] = 117; | |
e673ee24 DO |
620 | function deleteAttribute () |
621 | { | |
0cc24e9a | 622 | assertUIntArg ('attr_id'); |
e673ee24 | 623 | if (commitDeleteAttribute ($_REQUEST['attr_id'])) |
135080d8 | 624 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 625 | else |
135080d8 | 626 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
627 | } |
628 | ||
b6a7d936 | 629 | $msgcode['supplementAttrMap']['OK'] = 48; |
7028a42c DO |
630 | $msgcode['supplementAttrMap']['ERR1'] = 154; |
631 | $msgcode['supplementAttrMap']['ERR2'] = 118; | |
e673ee24 DO |
632 | function supplementAttrMap () |
633 | { | |
0cc24e9a DY |
634 | assertUIntArg ('attr_id'); |
635 | assertUIntArg ('objtype_id'); | |
7028a42c DO |
636 | $attrMap = getAttrMap(); |
637 | if ($attrMap[$_REQUEST['attr_id']]['type'] != 'dict') | |
638 | $chapter_id = 'NULL'; | |
639 | else | |
640 | { | |
0cc24e9a | 641 | assertUIntArg ('chapter_no'); // FIXME: this doesn't fail on 0 (ticket:272) |
7028a42c DO |
642 | if (0 == ($chapter_id = $_REQUEST['chapter_no'])) |
643 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ('chapter not selected')); | |
644 | } | |
645 | if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $chapter_id) === TRUE) | |
135080d8 | 646 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 647 | else |
7028a42c | 648 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
e673ee24 DO |
649 | } |
650 | ||
b6a7d936 DO |
651 | $msgcode['reduceAttrMap']['OK'] = 49; |
652 | $msgcode['reduceAttrMap']['ERR'] = 119; | |
e673ee24 DO |
653 | function reduceAttrMap () |
654 | { | |
0cc24e9a DY |
655 | assertUIntArg ('attr_id'); |
656 | assertUIntArg ('objtype_id'); | |
e673ee24 | 657 | if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) === TRUE) |
135080d8 | 658 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 659 | else |
135080d8 | 660 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
661 | } |
662 | ||
b6a7d936 DO |
663 | $msgcode['clearSticker']['OK'] = 15; |
664 | $msgcode['clearSticker']['ERR'] = 120; | |
22bb04da | 665 | function clearSticker () |
e673ee24 | 666 | { |
0cc24e9a DY |
667 | assertUIntArg ('attr_id'); |
668 | assertUIntArg ('object_id'); | |
22bb04da | 669 | if (commitResetAttrValue ($_REQUEST['object_id'], $_REQUEST['attr_id']) === TRUE) |
135080d8 | 670 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 671 | else |
135080d8 | 672 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
673 | } |
674 | ||
e97e8866 | 675 | $msgcode['updateObjectAllocation']['OK'] = 63; |
4fbb5a00 DY |
676 | function updateObjectAllocation () |
677 | { | |
0cc24e9a | 678 | assertUIntArg ('object_id'); |
4fbb5a00 | 679 | |
e97e8866 DO |
680 | if (!isset ($_REQUEST['got_atoms'])) |
681 | { | |
682 | unset($_GET['page']); | |
683 | unset($_GET['tab']); | |
684 | unset($_GET['op']); | |
685 | unset($_POST['page']); | |
686 | unset($_POST['tab']); | |
687 | unset($_POST['op']); | |
688 | return buildWideRedirectURL (array(), NULL, NULL, array_merge ($_GET, $_POST)); | |
689 | } | |
690 | $object_id = $_REQUEST['object_id']; | |
691 | $workingRacksData = array(); | |
692 | foreach ($_REQUEST['rackmulti'] as $cand_id) | |
4fbb5a00 | 693 | { |
e97e8866 | 694 | if (!isset ($workingRacksData[$cand_id])) |
4fbb5a00 | 695 | { |
e97e8866 | 696 | $rackData = spotEntity ('rack', $cand_id); |
e97e8866 DO |
697 | amplifyCell ($rackData); |
698 | $workingRacksData[$cand_id] = $rackData; | |
4fbb5a00 | 699 | } |
e97e8866 | 700 | } |
2135fd83 | 701 | |
e97e8866 DO |
702 | foreach ($workingRacksData as &$rd) |
703 | applyObjectMountMask ($rd, $object_id); | |
4fbb5a00 | 704 | |
e97e8866 DO |
705 | $oldMolecule = getMoleculeForObject ($object_id); |
706 | $changecnt = 0; | |
707 | $log = array(); | |
708 | foreach ($workingRacksData as $rack_id => $rackData) | |
4fbb5a00 | 709 | { |
e97e8866 DO |
710 | $logrecord = processGridForm ($rackData, 'F', 'T', $object_id); |
711 | $log[] = $logrecord; | |
712 | if ($logrecord['code'] == 300) | |
713 | continue; | |
714 | $changecnt++; | |
715 | // Reload our working copy after form processing. | |
716 | $rackData = spotEntity ('rack', $cand_id); | |
717 | amplifyCell ($rackData); | |
718 | applyObjectMountMask ($rackData, $object_id); | |
719 | $workingRacksData[$rack_id] = $rackData; | |
4fbb5a00 | 720 | } |
e97e8866 DO |
721 | if (!$changecnt) |
722 | return buildRedirectURL (__FUNCTION__, 'OK', $changecnt); | |
723 | // Log a record. | |
724 | $newMolecule = getMoleculeForObject ($object_id); | |
725 | $oc = count ($oldMolecule); | |
726 | $nc = count ($newMolecule); | |
727 | $omid = $oc ? createMolecule ($oldMolecule) : 'NULL'; | |
728 | $nmid = $nc ? createMolecule ($newMolecule) : 'NULL'; | |
729 | global $remote_username; | |
730 | $comment = empty ($_REQUEST['comment']) ? 'NULL' : "'${_REQUEST['comment']}'"; | |
731 | $query = | |
732 | "insert into MountOperation(object_id, old_molecule_id, new_molecule_id, user_name, comment) " . | |
733 | "values (${object_id}, ${omid}, ${nmid}, '${remote_username}', ${comment})"; | |
734 | global $dbxlink; | |
735 | $result = $dbxlink->query ($query); | |
736 | if ($result == NULL) | |
737 | $log[] = array ('code' => 500, 'message' => 'SQL query failed during history logging.'); | |
738 | else | |
739 | $log[] = array ('code' => 200, 'message' => 'History logged.'); | |
740 | return buildWideRedirectURL ($log); | |
4fbb5a00 DY |
741 | } |
742 | ||
b6a7d936 DO |
743 | $msgcode['updateObject']['OK'] = 16; |
744 | $msgcode['updateObject']['ERR'] = 121; | |
22bb04da DO |
745 | function updateObject () |
746 | { | |
0cc24e9a DY |
747 | assertUIntArg ('num_attrs', TRUE); |
748 | assertUIntArg ('object_id'); | |
749 | assertUIntArg ('object_type_id'); | |
750 | assertStringArg ('object_name', TRUE); | |
751 | assertStringArg ('object_label', TRUE); | |
752 | assertStringArg ('object_barcode', TRUE); | |
753 | assertStringArg ('object_asset_no', TRUE); | |
22bb04da DO |
754 | if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on') |
755 | $has_problems = 'yes'; | |
756 | else | |
757 | $has_problems = 'no'; | |
758 | ||
759 | if (commitUpdateObject ( | |
760 | $_REQUEST['object_id'], | |
761 | $_REQUEST['object_name'], | |
762 | $_REQUEST['object_label'], | |
763 | $_REQUEST['object_barcode'], | |
764 | $_REQUEST['object_type_id'], | |
765 | $has_problems, | |
766 | $_REQUEST['object_asset_no'], | |
767 | $_REQUEST['object_comment'] | |
768 | ) !== TRUE) | |
135080d8 | 769 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
22bb04da | 770 | |
cdd3efe9 | 771 | // Update optional attributes |
f59e8cf5 | 772 | $oldvalues = getAttrValues ($_REQUEST['object_id']); |
0dfb8a2a | 773 | $result = array(); |
0f63538a DO |
774 | $num_attrs = isset ($_REQUEST['num_attrs']) ? $_REQUEST['num_attrs'] : 0; |
775 | for ($i = 0; $i < $num_attrs; $i++) | |
0dfb8a2a | 776 | { |
0cc24e9a | 777 | assertUIntArg ("${i}_attr_id"); |
0dfb8a2a DO |
778 | $attr_id = $_REQUEST["${i}_attr_id"]; |
779 | ||
780 | // Field is empty, delete attribute and move on. | |
59a83bd8 | 781 | if (!strlen ($_REQUEST["${i}_value"])) |
0dfb8a2a | 782 | { |
103b1e1e | 783 | commitResetAttrValue ($_REQUEST['object_id'], $attr_id); |
0dfb8a2a DO |
784 | continue; |
785 | } | |
786 | ||
787 | // The value could be uint/float, but we don't know ATM. Let SQL | |
788 | // server check this and complain. | |
0cc24e9a | 789 | assertStringArg ("${i}_value"); |
0dfb8a2a DO |
790 | $value = $_REQUEST["${i}_value"]; |
791 | switch ($oldvalues[$attr_id]['type']) | |
792 | { | |
793 | case 'uint': | |
794 | case 'float': | |
795 | case 'string': | |
796 | $oldvalue = $oldvalues[$attr_id]['value']; | |
797 | break; | |
798 | case 'dict': | |
799 | $oldvalue = $oldvalues[$attr_id]['key']; | |
800 | break; | |
801 | default: | |
0cc24e9a | 802 | throw new RuntimeException('Internal structure error'); |
0dfb8a2a | 803 | } |
59a83bd8 | 804 | if ($value === $oldvalue) // ('' == 0), but ('' !== 0) |
0dfb8a2a DO |
805 | continue; |
806 | ||
807 | // Note if the queries succeed or not, it determines which page they see. | |
103b1e1e | 808 | $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value); |
0dfb8a2a | 809 | } |
103b1e1e | 810 | if (in_array (FALSE, $result)) |
135080d8 | 811 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
0dfb8a2a | 812 | |
cdd3efe9 AD |
813 | // Invalidate thumb cache of all racks objects could occupy. |
814 | foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id) | |
815 | resetThumbCache ($rack_id); | |
816 | ||
135080d8 | 817 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
818 | } |
819 | ||
42d73cbf DY |
820 | |
821 | function addMultipleObjects() | |
822 | { | |
7abce0b7 | 823 | $log = emptyLog(); |
42d73cbf | 824 | $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); |
42d73cbf DY |
825 | $max = getConfigVar ('MASSCOUNT'); |
826 | for ($i = 0; $i < $max; $i++) | |
827 | { | |
828 | if (!isset ($_REQUEST["${i}_object_type_id"])) | |
829 | { | |
57777e4a | 830 | $log = mergeLogs ($log, oneLiner (184, array ($i + 1))); |
42d73cbf DY |
831 | break; |
832 | } | |
0cc24e9a DY |
833 | assertUIntArg ("${i}_object_type_id", TRUE); |
834 | assertStringArg ("${i}_object_name", TRUE); | |
835 | assertStringArg ("${i}_object_label", TRUE); | |
836 | assertStringArg ("${i}_object_asset_no", TRUE); | |
837 | assertStringArg ("${i}_object_barcode", TRUE); | |
7abce0b7 | 838 | $name = $_REQUEST["${i}_object_name"]; |
42d73cbf DY |
839 | |
840 | // It's better to skip silently, than to print a notice. | |
7abce0b7 | 841 | if ($_REQUEST["${i}_object_type_id"] == 0) |
42d73cbf | 842 | continue; |
fee7977b | 843 | if (($object_id = commitAddObject |
7abce0b7 DO |
844 | ( |
845 | $name, | |
846 | $_REQUEST["${i}_object_label"], | |
847 | $_REQUEST["${i}_object_barcode"], | |
848 | $_REQUEST["${i}_object_type_id"], | |
849 | $_REQUEST["${i}_object_asset_no"], | |
850 | $taglist | |
fee7977b DO |
851 | )) !== FALSE){ |
852 | $info = spotEntity ('object', $object_id); | |
853 | // FIXME: employ amplifyCell() instead of calling loader functions directly | |
854 | amplifyCell ($info); | |
855 | $log = mergeLogs ($log, oneLiner (80, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>'))); | |
856 | }else{ | |
57777e4a | 857 | $log = mergeLogs ($log, oneLiner (185, array ($name))); |
fee7977b | 858 | } |
42d73cbf | 859 | } |
7abce0b7 | 860 | return buildWideRedirectURL ($log); |
42d73cbf DY |
861 | } |
862 | ||
863 | function addLotOfObjects() | |
864 | { | |
7abce0b7 | 865 | $log = emptyLog(); |
42d73cbf | 866 | $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); |
0cc24e9a DY |
867 | assertUIntArg ('global_type_id', TRUE); |
868 | assertStringArg ('namelist', TRUE); | |
42d73cbf | 869 | $global_type_id = $_REQUEST['global_type_id']; |
59a83bd8 | 870 | if ($global_type_id == 0 or !strlen ($_REQUEST['namelist'])) |
57777e4a | 871 | $log = mergeLogs ($log, oneLiner (186)); |
42d73cbf DY |
872 | else |
873 | { | |
874 | // The name extractor below was stolen from ophandlers.php:addMultiPorts() | |
875 | $names1 = explode ('\n', $_REQUEST['namelist']); | |
876 | $names2 = array(); | |
877 | foreach ($names1 as $line) | |
878 | { | |
879 | $parts = explode ('\r', $line); | |
880 | reset ($parts); | |
59a83bd8 | 881 | if (!strlen ($parts[0])) |
42d73cbf DY |
882 | continue; |
883 | else | |
884 | $names2[] = rtrim ($parts[0]); | |
885 | } | |
57777e4a | 886 | foreach ($names2 as $name) |
9d535a0c DO |
887 | if (($object_id = commitAddObject ($name, '', '', $global_type_id, '', $taglist)) !== FALSE) |
888 | { | |
889 | $info = spotEntity ('object', $object_id); | |
890 | amplifyCell ($info); | |
891 | $log = mergeLogs ($log, oneLiner (80, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>'))); | |
892 | } | |
42d73cbf | 893 | else |
57777e4a | 894 | $log = mergeLogs ($log, oneLiner (185, array ($name))); |
42d73cbf | 895 | } |
7abce0b7 | 896 | return buildWideRedirectURL ($log); |
42d73cbf DY |
897 | } |
898 | ||
b6a7d936 DO |
899 | $msgcode['deleteObject']['OK'] = 76; |
900 | $msgcode['deleteObject']['ERR'] = 100; | |
52b34485 AD |
901 | function deleteObject () |
902 | { | |
0cc24e9a | 903 | assertUIntArg ('object_id'); |
6297d584 | 904 | if (NULL === ($oinfo = spotEntity ('object', $_REQUEST['object_id']))) |
c78a40ec DO |
905 | return buildRedirectURL (__FUNCTION__, 'ERR', array ('object not found')); |
906 | ||
f0e2c99f | 907 | $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE); |
52b34485 | 908 | $error = commitDeleteObject ($_REQUEST['object_id']); |
f0e2c99f DO |
909 | foreach ($racklist as $rack_id) |
910 | resetThumbCache ($rack_id); | |
52b34485 AD |
911 | |
912 | if ($error != '') | |
135080d8 | 913 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
52b34485 | 914 | |
c78a40ec | 915 | return buildRedirectURL (__FUNCTION__, 'OK', array ($oinfo['dname'])); |
52b34485 AD |
916 | } |
917 | ||
b6a7d936 DO |
918 | $msgcode['useupPort']['OK'] = 11; |
919 | $msgcode['useupPort']['ERR'] = 124; | |
e673ee24 DO |
920 | function useupPort () |
921 | { | |
0cc24e9a | 922 | assertUIntArg ('port_id'); |
e673ee24 | 923 | if (commitUseupPort ($_REQUEST['port_id']) === TRUE) |
135080d8 | 924 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 925 | else |
135080d8 | 926 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
927 | } |
928 | ||
b6a7d936 DO |
929 | $msgcode['updateUI']['OK'] = 56; |
930 | $msgcode['updateUI']['ERR'] = 125; | |
4fe32e78 DY |
931 | function updateUI () |
932 | { | |
0cc24e9a | 933 | assertUIntArg ('num_vars'); |
4fe32e78 | 934 | |
103b1e1e | 935 | for ($i = 0; $i < $_REQUEST['num_vars']; $i++) |
4fe32e78 | 936 | { |
0cc24e9a DY |
937 | assertStringArg ("${i}_varname"); |
938 | assertStringArg ("${i}_varvalue", TRUE); | |
4fe32e78 | 939 | $varname = $_REQUEST["${i}_varname"]; |
4fe32e78 | 940 | $varvalue = $_REQUEST["${i}_varvalue"]; |
4fe32e78 | 941 | |
c461c579 | 942 | // If form value = value in DB, don't bother updating DB |
ed941e67 | 943 | if (!isConfigVarChanged($varname, $varvalue)) |
4fe32e78 DY |
944 | continue; |
945 | ||
946 | // Note if the queries succeed or not, it determines which page they see. | |
3540d15c DY |
947 | try { |
948 | setConfigVar ($varname, $varvalue, TRUE); | |
949 | } catch (InvalidArgException $e) { | |
950 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($e->getMessage())); | |
951 | } | |
952 | } | |
953 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
954 | } | |
955 | ||
956 | $msgcode['saveMyPreferences']['OK'] = 56; | |
957 | $msgcode['saveMyPreferences']['ERR'] = 125; | |
958 | function saveMyPreferences () | |
959 | { | |
960 | assertUIntArg ('num_vars'); | |
961 | ||
962 | for ($i = 0; $i < $_REQUEST['num_vars']; $i++) | |
963 | { | |
964 | assertStringArg ("${i}_varname"); | |
965 | assertStringArg ("${i}_varvalue", TRUE); | |
966 | $varname = $_REQUEST["${i}_varname"]; | |
967 | $varvalue = $_REQUEST["${i}_varvalue"]; | |
968 | ||
969 | // If form value = value in DB, don't bother updating DB | |
ed941e67 | 970 | if (!isConfigVarChanged($varname, $varvalue)) |
3540d15c | 971 | continue; |
3540d15c DY |
972 | // Note if the queries succeed or not, it determines which page they see. |
973 | try { | |
974 | setUserConfigVar ($varname, $varvalue); | |
975 | } catch (InvalidArgException $e) { | |
976 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($e->getMessage())); | |
977 | } | |
978 | } | |
979 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
980 | } | |
981 | ||
982 | $msgcode['resetMyPreference']['OK'] = 56; | |
983 | $msgcode['resetMyPreference']['ERR'] = 125; | |
984 | function resetMyPreference () | |
985 | { | |
986 | assertStringArg ("varname"); | |
987 | $varname = $_REQUEST["varname"]; | |
988 | ||
989 | try { | |
990 | resetUserConfigVar ($varname); | |
991 | } catch (InvalidArgException $e) { | |
992 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($e->getMessage())); | |
4fe32e78 | 993 | } |
135080d8 | 994 | return buildRedirectURL (__FUNCTION__, 'OK'); |
4fe32e78 DY |
995 | } |
996 | ||
3540d15c DY |
997 | |
998 | ||
999 | ||
b6a7d936 | 1000 | $msgcode['resetUIConfig']['OK'] = 57; |
b07f617c DO |
1001 | function resetUIConfig() |
1002 | { | |
b07f617c DO |
1003 | setConfigVar ('MASSCOUNT','15'); |
1004 | setConfigVar ('MAXSELSIZE','30'); | |
b07f617c DO |
1005 | setConfigVar ('ROW_SCALE','2'); |
1006 | setConfigVar ('PORTS_PER_ROW','12'); | |
1007 | setConfigVar ('IPV4_ADDRS_PER_PAGE','256'); | |
1008 | setConfigVar ('DEFAULT_RACK_HEIGHT','42'); | |
b5ce46aa DO |
1009 | setConfigVar ('DEFAULT_SLB_VS_PORT',''); |
1010 | setConfigVar ('DEFAULT_SLB_RS_PORT',''); | |
72281138 | 1011 | setConfigVar ('DETECT_URLS','no'); |
4b8d413e | 1012 | setConfigVar ('RACK_PRESELECT_THRESHOLD','1'); |
b108de49 | 1013 | setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no'); |
8dfb997c | 1014 | setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm'); |
194e3748 DO |
1015 | setConfigVar ('SHOW_EXPLICIT_TAGS','yes'); |
1016 | setConfigVar ('SHOW_IMPLICIT_TAGS','yes'); | |
1017 | setConfigVar ('SHOW_AUTOMATIC_TAGS','no'); | |
a477e405 | 1018 | setConfigVar ('DEFAULT_OBJECT_TYPE','4'); |
2754cefc | 1019 | setConfigVar ('IPV4_AUTO_RELEASE','1'); |
a53dc9df | 1020 | setConfigVar ('SHOW_LAST_TAB', 'no'); |
f0ed1181 | 1021 | setConfigVar ('EXT_IPV4_VIEW', 'yes'); |
efee2692 | 1022 | setConfigVar ('TREE_THRESHOLD', '25'); |
2be3fd23 | 1023 | setConfigVar ('IPV4_JAYWALK', 'no'); |
9318d2ef | 1024 | setConfigVar ('ADDNEW_AT_TOP', 'yes'); |
64347dcf | 1025 | setConfigVar ('IPV4_TREE_SHOW_USAGE', 'yes'); |
37e59768 DO |
1026 | setConfigVar ('PREVIEW_TEXT_MAXCHARS', '10240'); |
1027 | setConfigVar ('PREVIEW_TEXT_ROWS', '25'); | |
1028 | setConfigVar ('PREVIEW_TEXT_COLS', '80'); | |
1029 | setConfigVar ('PREVIEW_IMAGE_MAXPXS', '320'); | |
f3d274bf | 1030 | setConfigVar ('VENDOR_SIEVE', ''); |
35bf153d | 1031 | setConfigVar ('IPV4LB_LISTSRC', '{$typeid_4}'); |
8fee82b4 DO |
1032 | setConfigVar ('IPV4OBJ_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_12} or {$typeid_445} or {$typeid_447} or {$typeid_798}'); |
1033 | setConfigVar ('IPV4NAT_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_798}'); | |
35bf153d DO |
1034 | setConfigVar ('ASSETWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}'); |
1035 | setConfigVar ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}'); | |
f5883ec1 | 1036 | setConfigVar ('RACKS_PER_ROW','12'); |
590e1281 | 1037 | setConfigVar ('FILTER_PREDICATE_SIEVE',''); |
23cdc7e9 DO |
1038 | setConfigVar ('FILTER_DEFAULT_ANDOR','or'); |
1039 | setConfigVar ('FILTER_SUGGEST_ANDOR','yes'); | |
1040 | setConfigVar ('FILTER_SUGGEST_TAGS','yes'); | |
1041 | setConfigVar ('FILTER_SUGGEST_PREDICATES','yes'); | |
1042 | setConfigVar ('FILTER_SUGGEST_EXTRA','no'); | |
8fee82b4 | 1043 | setConfigVar ('DEFAULT_SNMP_COMMUNITY','public'); |
f06fe423 | 1044 | setConfigVar ('IPV4_ENABLE_KNIGHT','yes'); |
9e51318b DO |
1045 | setConfigVar ('TAGS_TOPLIST_SIZE','50'); |
1046 | setConfigVar ('TAGS_QUICKLIST_SIZE','20'); | |
1047 | setConfigVar ('TAGS_QUICKLIST_THRESHOLD','50'); | |
f44fdef9 | 1048 | setConfigVar ('ENABLE_MULTIPORT_FORM', 'no'); |
2400d7ec DO |
1049 | setConfigVar ('DEFAULT_PORT_IIF_ID', '1'); |
1050 | setConfigVar ('DEFAULT_PORT_OIF_IDS', '1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084'); | |
4a47d34b | 1051 | setConfigVar ('IPV4_TREE_RTR_AS_CELL', 'yes'); |
cd3775e9 | 1052 | setConfigVar ('PROXIMITY_RANGE', 0); |
ca4eb604 | 1053 | setConfigVar ('IPV4_TREE_SHOW_VLAN', 'yes'); |
2fb1f79b DO |
1054 | setConfigVar ('DEFAULT_VDOM_ID', ''); |
1055 | setConfigVar ('DEFAULT_VST_ID', ''); | |
135080d8 | 1056 | return buildRedirectURL (__FUNCTION__, 'OK'); |
b07f617c DO |
1057 | } |
1058 | ||
b6a7d936 DO |
1059 | $msgcode['addRealServer']['OK'] = 34; |
1060 | $msgcode['addRealServer']['ERR'] = 126; | |
732e4578 | 1061 | // Add single record. |
ca461127 DO |
1062 | function addRealServer () |
1063 | { | |
0cc24e9a DY |
1064 | assertUIntArg ('pool_id'); |
1065 | assertIPv4Arg ('remoteip'); | |
1066 | assertStringArg ('rsport', TRUE); | |
1067 | assertStringArg ('rsconfig', TRUE); | |
103b1e1e DO |
1068 | if (!addRStoRSPool ( |
1069 | $_REQUEST['pool_id'], | |
1070 | $_REQUEST['remoteip'], | |
1071 | $_REQUEST['rsport'], | |
1072 | getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), | |
1073 | $_REQUEST['rsconfig'] | |
1074 | )) | |
135080d8 | 1075 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
d6517a21 | 1076 | else |
135080d8 | 1077 | return buildRedirectURL (__FUNCTION__, 'OK'); |
d6517a21 DO |
1078 | } |
1079 | ||
b6a7d936 DO |
1080 | $msgcode['addRealServers']['OK'] = 37; |
1081 | $msgcode['addRealServers']['ERR1'] = 131; | |
1082 | $msgcode['addRealServers']['ERR2'] = 127; | |
732e4578 DO |
1083 | // Parse textarea submitted and try adding a real server for each line. |
1084 | function addRealServers () | |
1085 | { | |
0cc24e9a DY |
1086 | assertUIntArg ('pool_id'); |
1087 | assertStringArg ('format'); | |
1088 | assertStringArg ('rawtext'); | |
732e4578 DO |
1089 | $rawtext = str_replace ('\r', '', $_REQUEST['rawtext']); |
1090 | $ngood = $nbad = 0; | |
1091 | $rsconfig = ''; | |
1092 | // Keep in mind, that the text will have HTML entities (namely '>') escaped. | |
1093 | foreach (explode ('\n', $rawtext) as $line) | |
1094 | { | |
59a83bd8 | 1095 | if (!strlen ($line)) |
732e4578 DO |
1096 | continue; |
1097 | $match = array (); | |
1098 | switch ($_REQUEST['format']) | |
1099 | { | |
1100 | case 'ipvs_2': // address and port only | |
1101 | if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) /', $line, $match)) | |
1102 | continue; | |
103b1e1e | 1103 | if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), '')) |
732e4578 DO |
1104 | $ngood++; |
1105 | else | |
1106 | $nbad++; | |
1107 | break; | |
1108 | case 'ipvs_3': // address, port and weight | |
1109 | if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match)) | |
1110 | continue; | |
103b1e1e | 1111 | if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3])) |
732e4578 DO |
1112 | $ngood++; |
1113 | else | |
1114 | $nbad++; | |
1115 | break; | |
e69c2aa3 DO |
1116 | case 'ssv_2': // IP address and port |
1117 | if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match)) | |
1118 | continue; | |
103b1e1e | 1119 | if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), '')) |
e69c2aa3 DO |
1120 | $ngood++; |
1121 | else | |
1122 | $nbad++; | |
1123 | break; | |
948c37e3 DO |
1124 | case 'ssv_1': // IP address |
1125 | if (!preg_match ('/^([0-9\.]+)$/', $line, $match)) | |
1126 | continue; | |
1127 | if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), '')) | |
1128 | $ngood++; | |
1129 | else | |
1130 | $nbad++; | |
1131 | break; | |
732e4578 | 1132 | default: |
135080d8 | 1133 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
732e4578 DO |
1134 | break; |
1135 | } | |
1136 | } | |
1137 | if ($nbad == 0 and $ngood > 0) | |
135080d8 | 1138 | return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood)); |
732e4578 | 1139 | else |
135080d8 | 1140 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($ngood, $nbad)); |
732e4578 DO |
1141 | } |
1142 | ||
b6a7d936 DO |
1143 | $msgcode['addVService']['OK'] = 28; |
1144 | $msgcode['addVService']['ERR1'] = 132; | |
1145 | $msgcode['addVService']['ERR2'] = 100; | |
d6517a21 DO |
1146 | function addVService () |
1147 | { | |
0cc24e9a DY |
1148 | assertIPv4Arg ('vip'); |
1149 | assertUIntArg ('vport'); | |
1150 | assertStringArg ('proto'); | |
103b1e1e | 1151 | if ($_REQUEST['proto'] != 'TCP' and $_REQUEST['proto'] != 'UDP') |
135080d8 | 1152 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
0cc24e9a DY |
1153 | assertStringArg ('name', TRUE); |
1154 | assertStringArg ('vsconfig', TRUE); | |
1155 | assertStringArg ('rsconfig', TRUE); | |
c63a8d6e DO |
1156 | $error = commitCreateVS |
1157 | ( | |
103b1e1e DO |
1158 | $_REQUEST['vip'], |
1159 | $_REQUEST['vport'], | |
7320b661 | 1160 | $_REQUEST['proto'], |
103b1e1e DO |
1161 | $_REQUEST['name'], |
1162 | $_REQUEST['vsconfig'], | |
c63a8d6e DO |
1163 | $_REQUEST['rsconfig'], |
1164 | isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array() | |
1165 | ); | |
1166 | if ($error != '') | |
135080d8 | 1167 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error)); |
ca461127 | 1168 | else |
135080d8 | 1169 | return buildRedirectURL (__FUNCTION__, 'OK'); |
fb1c4a54 DO |
1170 | } |
1171 | ||
b6a7d936 DO |
1172 | $msgcode['deleteRealServer']['OK'] = 35; |
1173 | $msgcode['deleteRealServer']['ERR'] = 128; | |
fb1c4a54 DO |
1174 | function deleteRealServer () |
1175 | { | |
0cc24e9a | 1176 | assertUIntArg ('id'); |
d6517a21 | 1177 | if (!commitDeleteRS ($_REQUEST['id'])) |
135080d8 | 1178 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
fb1c4a54 | 1179 | else |
135080d8 | 1180 | return buildRedirectURL (__FUNCTION__, 'OK'); |
fb1c4a54 DO |
1181 | } |
1182 | ||
b6a7d936 DO |
1183 | $msgcode['deleteLoadBalancer']['OK'] = 19; |
1184 | $msgcode['deleteLoadBalancer']['ERR'] = 129; | |
3241551e DO |
1185 | function deleteLoadBalancer () |
1186 | { | |
0cc24e9a DY |
1187 | assertUIntArg ('object_id'); |
1188 | assertUIntArg ('pool_id'); | |
1189 | assertUIntArg ('vs_id'); | |
103b1e1e DO |
1190 | if (!commitDeleteLB ( |
1191 | $_REQUEST['object_id'], | |
1192 | $_REQUEST['pool_id'], | |
1193 | $_REQUEST['vs_id'] | |
1194 | )) | |
135080d8 | 1195 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
d6517a21 | 1196 | else |
135080d8 | 1197 | return buildRedirectURL (__FUNCTION__, 'OK'); |
d6517a21 DO |
1198 | } |
1199 | ||
b6a7d936 DO |
1200 | $msgcode['deleteVService']['OK'] = 29; |
1201 | $msgcode['deleteVService']['ERR'] = 130; | |
d6517a21 DO |
1202 | function deleteVService () |
1203 | { | |
0cc24e9a | 1204 | assertUIntArg ('vs_id'); |
e02e1941 | 1205 | if (!commitDeleteVS ($_REQUEST['vs_id'])) |
135080d8 | 1206 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
3241551e | 1207 | else |
135080d8 | 1208 | return buildRedirectURL (__FUNCTION__, 'OK'); |
3241551e DO |
1209 | } |
1210 | ||
b6a7d936 DO |
1211 | $msgcode['updateRealServer']['OK'] = 36; |
1212 | $msgcode['updateRealServer']['ERR'] = 133; | |
fb1c4a54 DO |
1213 | function updateRealServer () |
1214 | { | |
0cc24e9a DY |
1215 | assertUIntArg ('rs_id'); |
1216 | assertIPv4Arg ('rsip'); | |
1217 | assertStringArg ('rsport', TRUE); | |
1218 | assertStringArg ('rsconfig', TRUE); | |
103b1e1e DO |
1219 | if (!commitUpdateRS ( |
1220 | $_REQUEST['rs_id'], | |
1221 | $_REQUEST['rsip'], | |
1222 | $_REQUEST['rsport'], | |
1223 | $_REQUEST['rsconfig'] | |
1224 | )) | |
135080d8 | 1225 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
fb1c4a54 | 1226 | else |
135080d8 | 1227 | return buildRedirectURL (__FUNCTION__, 'OK'); |
ca461127 DO |
1228 | } |
1229 | ||
b6a7d936 DO |
1230 | $msgcode['updateLoadBalancer']['OK'] = 20; |
1231 | $msgcode['updateLoadBalancer']['ERR'] = 134; | |
c1ca768c | 1232 | function updateLoadBalancer () |
3241551e | 1233 | { |
0cc24e9a DY |
1234 | assertUIntArg ('object_id'); |
1235 | assertUIntArg ('pool_id'); | |
1236 | assertUIntArg ('vs_id'); | |
1237 | assertStringArg ('vsconfig', TRUE); | |
1238 | assertStringArg ('rsconfig', TRUE); | |
103b1e1e DO |
1239 | if (!commitUpdateLB ( |
1240 | $_REQUEST['object_id'], | |
1241 | $_REQUEST['pool_id'], | |
1242 | $_REQUEST['vs_id'], | |
1243 | $_REQUEST['vsconfig'], | |
1244 | $_REQUEST['rsconfig'] | |
1245 | )) | |
135080d8 | 1246 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
d6517a21 | 1247 | else |
135080d8 | 1248 | return buildRedirectURL (__FUNCTION__, 'OK'); |
d6517a21 DO |
1249 | } |
1250 | ||
b6a7d936 DO |
1251 | $msgcode['updateVService']['OK'] = 30; |
1252 | $msgcode['updateVService']['ERR'] = 135; | |
d6517a21 DO |
1253 | function updateVService () |
1254 | { | |
0cc24e9a DY |
1255 | assertUIntArg ('vs_id'); |
1256 | assertIPv4Arg ('vip'); | |
1257 | assertUIntArg ('vport'); | |
1258 | assertStringArg ('proto'); | |
1259 | assertStringArg ('name', TRUE); | |
1260 | assertStringArg ('vsconfig', TRUE); | |
1261 | assertStringArg ('rsconfig', TRUE); | |
103b1e1e DO |
1262 | if (!commitUpdateVS ( |
1263 | $_REQUEST['vs_id'], | |
1264 | $_REQUEST['vip'], | |
1265 | $_REQUEST['vport'], | |
1266 | $_REQUEST['proto'], | |
1267 | $_REQUEST['name'], | |
1268 | $_REQUEST['vsconfig'], | |
1269 | $_REQUEST['rsconfig'] | |
1270 | )) | |
135080d8 | 1271 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
3241551e | 1272 | else |
135080d8 | 1273 | return buildRedirectURL (__FUNCTION__, 'OK'); |
3241551e DO |
1274 | } |
1275 | ||
b6a7d936 DO |
1276 | $msgcode['addLoadBalancer']['OK'] = 18; |
1277 | $msgcode['addLoadBalancer']['ERR'] = 137; | |
3241551e DO |
1278 | function addLoadBalancer () |
1279 | { | |
0cc24e9a DY |
1280 | assertUIntArg ('pool_id'); |
1281 | assertUIntArg ('object_id'); | |
1282 | assertUIntArg ('vs_id'); | |
1283 | assertStringArg ('vsconfig', TRUE); | |
1284 | assertStringArg ('rsconfig', TRUE); | |
103b1e1e DO |
1285 | if (!addLBtoRSPool ( |
1286 | $_REQUEST['pool_id'], | |
1287 | $_REQUEST['object_id'], | |
1288 | $_REQUEST['vs_id'], | |
1289 | $_REQUEST['vsconfig'], | |
1290 | $_REQUEST['rsconfig'] | |
1291 | )) | |
135080d8 | 1292 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
3241551e | 1293 | else |
135080d8 | 1294 | return buildRedirectURL (__FUNCTION__, 'OK'); |
3241551e DO |
1295 | } |
1296 | ||
b6a7d936 DO |
1297 | $msgcode['addRSPool']['OK'] = 31; |
1298 | $msgcode['addRSPool']['ERR'] = 100; | |
5ad76f01 DO |
1299 | function addRSPool () |
1300 | { | |
0cc24e9a DY |
1301 | assertStringArg ('name', TRUE); |
1302 | assertStringArg ('vsconfig', TRUE); | |
1303 | assertStringArg ('rsconfig', TRUE); | |
c63a8d6e DO |
1304 | $error = commitCreateRSPool |
1305 | ( | |
103b1e1e DO |
1306 | $_REQUEST['name'], |
1307 | $_REQUEST['vsconfig'], | |
c63a8d6e DO |
1308 | $_REQUEST['rsconfig'], |
1309 | isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array() | |
1310 | ); | |
1311 | if ($error != '') | |
135080d8 | 1312 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
5ad76f01 | 1313 | else |
135080d8 | 1314 | return buildRedirectURL (__FUNCTION__, 'OK'); |
5ad76f01 DO |
1315 | } |
1316 | ||
b6a7d936 DO |
1317 | $msgcode['deleteRSPool']['OK'] = 32; |
1318 | $msgcode['deleteRSPool']['ERR'] = 138; | |
5ad76f01 DO |
1319 | function deleteRSPool () |
1320 | { | |
0cc24e9a | 1321 | assertUIntArg ('pool_id'); |
841a7a7a | 1322 | if (!commitDeleteRSPool ($_REQUEST['pool_id'])) |
135080d8 | 1323 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
5ad76f01 | 1324 | else |
135080d8 | 1325 | return buildRedirectURL (__FUNCTION__, 'OK'); |
5ad76f01 DO |
1326 | } |
1327 | ||
b6a7d936 DO |
1328 | $msgcode['updateRSPool']['OK'] = 33; |
1329 | $msgcode['updateRSPool']['ERR'] = 139; | |
5ad76f01 DO |
1330 | function updateRSPool () |
1331 | { | |
0cc24e9a DY |
1332 | assertUIntArg ('pool_id'); |
1333 | assertStringArg ('name', TRUE); | |
1334 | assertStringArg ('vsconfig', TRUE); | |
1335 | assertStringArg ('rsconfig', TRUE); | |
841a7a7a | 1336 | if (!commitUpdateRSPool ($_REQUEST['pool_id'], $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig'])) |
135080d8 | 1337 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
5ad76f01 | 1338 | else |
135080d8 | 1339 | return buildRedirectURL (__FUNCTION__, 'OK'); |
5ad76f01 DO |
1340 | } |
1341 | ||
b6a7d936 DO |
1342 | $msgcode['updateRSInService']['OK'] = 38; |
1343 | $msgcode['updateRSInService']['ERR'] = 140; | |
1f7d18fa DO |
1344 | function updateRSInService () |
1345 | { | |
0cc24e9a | 1346 | assertUIntArg ('rscount'); |
841a7a7a | 1347 | $pool_id = $_REQUEST['pool_id']; |
a6e91ac2 DO |
1348 | $orig = spotEntity ('ipv4rspool', $pool_id); |
1349 | amplifyCell ($orig); | |
1f7d18fa DO |
1350 | $nbad = $ngood = 0; |
1351 | for ($i = 1; $i <= $_REQUEST['rscount']; $i++) | |
1352 | { | |
1353 | $rs_id = $_REQUEST["rsid_${i}"]; | |
1354 | if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on') | |
1355 | $newval = 'yes'; | |
1356 | else | |
1357 | $newval = 'no'; | |
1358 | if ($newval != $orig['rslist'][$rs_id]['inservice']) | |
1359 | { | |
1360 | if (commitSetInService ($rs_id, $newval)) | |
1361 | $ngood++; | |
1362 | else | |
1363 | $nbad++; | |
1364 | } | |
1365 | } | |
1366 | if (!$nbad) | |
135080d8 | 1367 | return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood)); |
1f7d18fa | 1368 | else |
135080d8 | 1369 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($nbad, $ngood)); |
1f7d18fa DO |
1370 | } |
1371 | ||
b6a7d936 DO |
1372 | $msgcode['importPTRData']['OK'] = 26; |
1373 | $msgcode['importPTRData']['ERR'] = 141; | |
8d9c16e7 DO |
1374 | // FIXME: check, that each submitted address belongs to the prefix we |
1375 | // are operating on. | |
03eb5209 DO |
1376 | function importPTRData () |
1377 | { | |
0cc24e9a | 1378 | assertUIntArg ('addrcount'); |
03eb5209 | 1379 | $nbad = $ngood = 0; |
03eb5209 DO |
1380 | for ($i = 0; $i < $_REQUEST['addrcount']; $i++) |
1381 | { | |
3f3bd41e | 1382 | $inputname = "import_${i}"; |
03eb5209 DO |
1383 | if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on') |
1384 | continue; | |
0cc24e9a DY |
1385 | assertIPv4Arg ("addr_${i}"); |
1386 | assertStringArg ("descr_${i}", TRUE); | |
1387 | assertStringArg ("rsvd_${i}"); | |
3f3bd41e DO |
1388 | // Non-existent addresses will not have this argument set in request. |
1389 | $rsvd = 'no'; | |
03eb5209 DO |
1390 | if ($_REQUEST["rsvd_${i}"] == 'yes') |
1391 | $rsvd = 'yes'; | |
3f3bd41e | 1392 | if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '') |
03eb5209 DO |
1393 | $ngood++; |
1394 | else | |
1395 | $nbad++; | |
1396 | } | |
1397 | if (!$nbad) | |
135080d8 | 1398 | return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood)); |
03eb5209 | 1399 | else |
135080d8 | 1400 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($nbad, $ngood)); |
03eb5209 DO |
1401 | } |
1402 | ||
b6a7d936 DO |
1403 | $msgcode['generateAutoPorts']['OK'] = 21; |
1404 | $msgcode['generateAutoPorts']['ERR'] = 142; | |
f3f0161f DO |
1405 | function generateAutoPorts () |
1406 | { | |
103b1e1e | 1407 | global $pageno; |
0cc24e9a | 1408 | assertUIntArg ('object_id'); |
6297d584 | 1409 | $info = spotEntity ('object', $_REQUEST['object_id']); |
f3f0161f | 1410 | // Navigate away in case of success, stay at the place otherwise. |
103b1e1e | 1411 | if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id'])) |
135080d8 | 1412 | return buildRedirectURL (__FUNCTION__, 'OK', array(), $pageno, 'ports'); |
f3f0161f | 1413 | else |
135080d8 | 1414 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
f3f0161f DO |
1415 | } |
1416 | ||
b6a7d936 DO |
1417 | $msgcode['saveEntityTags']['OK'] = 22; |
1418 | $msgcode['saveEntityTags']['ERR1'] = 143; | |
1419 | $msgcode['saveEntityTags']['ERR2'] = 187; | |
24cbe8af | 1420 | // Filter out implicit tags before storing the new tag set. |
3355ca56 | 1421 | function saveEntityTags () |
24cbe8af | 1422 | { |
eb27afad | 1423 | global $page, $pageno, $etype_by_pageno; |
be2ae2a2 | 1424 | if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass'])) |
9a61c175 | 1425 | return buildRedirectURL (__FUNCTION__, 'ERR2', array (__FUNCTION__)); |
be2ae2a2 | 1426 | $realm = $etype_by_pageno[$pageno]; |
3355ca56 | 1427 | $bypass = $page[$pageno]['bypass']; |
0cc24e9a | 1428 | assertUIntArg ($bypass); |
2034d968 | 1429 | $entity_id = $_REQUEST[$bypass]; |
e04931c8 | 1430 | $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); |
6e49bd1f | 1431 | // Build a chain from the submitted data, minimize it, |
ab379543 | 1432 | // then wipe existing records and store the new set instead. |
01b6b4d6 | 1433 | destroyTagsForEntity ($realm, $entity_id); |
eb27afad DO |
1434 | // TODO: these actions are very close to what rebuildTagChainForEntity() does, |
1435 | // so why not use it? | |
6e49bd1f | 1436 | $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist)); |
ab379543 | 1437 | $n_succeeds = $n_errors = 0; |
6e49bd1f | 1438 | foreach ($newchain as $taginfo) |
eb6ea26f | 1439 | if (addTagForEntity ($realm, $entity_id, $taginfo['id'])) |
ab379543 DO |
1440 | $n_succeeds++; |
1441 | else | |
1442 | $n_errors++; | |
ab379543 | 1443 | if ($n_errors) |
9a61c175 | 1444 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($n_succeeds, $n_errors)); |
ab379543 | 1445 | else |
135080d8 | 1446 | return buildRedirectURL (__FUNCTION__, 'OK', array ($n_succeeds)); |
2034d968 DO |
1447 | } |
1448 | ||
b6a7d936 DO |
1449 | $msgcode['destroyTag']['OK'] = 58; |
1450 | $msgcode['destroyTag']['ERR1'] = 183; | |
1451 | $msgcode['destroyTag']['ERR2'] = 144; | |
fe7044ad DO |
1452 | function destroyTag () |
1453 | { | |
0cc24e9a | 1454 | assertUIntArg ('tag_id'); |
c615a655 DO |
1455 | global $taglist; |
1456 | if (!isset ($taglist[$_REQUEST['tag_id']])) | |
1457 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($_REQUEST['tag_id'])); | |
49fb1027 | 1458 | if (($ret = commitDestroyTag ($_REQUEST['tag_id'])) == '') |
c615a655 | 1459 | return buildRedirectURL (__FUNCTION__, 'OK', array ($taglist[$_REQUEST['tag_id']]['tag'])); |
fe7044ad | 1460 | else |
c615a655 | 1461 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
fe7044ad DO |
1462 | } |
1463 | ||
b6a7d936 DO |
1464 | $msgcode['createTag']['OK'] = 59; |
1465 | $msgcode['createTag']['ERR1'] = 145; | |
1466 | $msgcode['createTag']['ERR3'] = 147; | |
fe7044ad DO |
1467 | function createTag () |
1468 | { | |
0cc24e9a DY |
1469 | assertStringArg ('tag_name'); |
1470 | assertUIntArg ('parent_id', TRUE); | |
49fb1027 | 1471 | $tagname = trim ($_REQUEST['tag_name']); |
2eeeca80 | 1472 | if (!validTagName ($tagname)) |
135080d8 | 1473 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($tagname)); |
fe7044ad DO |
1474 | if (($parent_id = $_REQUEST['parent_id']) <= 0) |
1475 | $parent_id = 'NULL'; | |
1476 | if (($ret = commitCreateTag ($tagname, $parent_id)) == '') | |
135080d8 | 1477 | return buildRedirectURL (__FUNCTION__, 'OK', array ($tagname)); |
fe7044ad | 1478 | else |
135080d8 | 1479 | return buildRedirectURL (__FUNCTION__, 'ERR3', array ($tagname, $ret)); |
fe7044ad DO |
1480 | } |
1481 | ||
b6a7d936 DO |
1482 | $msgcode['updateTag']['OK'] = 60; |
1483 | $msgcode['updateTag']['ERR1'] = 145; | |
1484 | $msgcode['updateTag']['ERR2'] = 148; | |
49fb1027 DO |
1485 | function updateTag () |
1486 | { | |
0cc24e9a DY |
1487 | assertUIntArg ('tag_id'); |
1488 | assertUIntArg ('parent_id', TRUE); | |
1489 | assertStringArg ('tag_name'); | |
49fb1027 | 1490 | $tagname = trim ($_REQUEST['tag_name']); |
2eeeca80 | 1491 | if (!validTagName ($tagname)) |
135080d8 | 1492 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($tagname)); |
49fb1027 DO |
1493 | if (($parent_id = $_REQUEST['parent_id']) <= 0) |
1494 | $parent_id = 'NULL'; | |
1495 | if (($ret = commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id)) == '') | |
135080d8 | 1496 | return buildRedirectURL (__FUNCTION__, 'OK', array ($tagname)); |
590e1281 DO |
1497 | // Use old name in the message, cause update failed. |
1498 | global $taglist; | |
1499 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($taglist[$_REQUEST['tag_id']]['tag'], $ret)); | |
49fb1027 DO |
1500 | } |
1501 | ||
b6a7d936 DO |
1502 | $msgcode['rollTags']['OK'] = 67; |
1503 | $msgcode['rollTags']['ERR'] = 149; | |
eb6ea26f DO |
1504 | function rollTags () |
1505 | { | |
0cc24e9a DY |
1506 | assertUIntArg ('row_id'); |
1507 | assertStringArg ('sum', TRUE); | |
1508 | assertUIntArg ('realsum'); | |
eb6ea26f | 1509 | if ($_REQUEST['sum'] != $_REQUEST['realsum']) |
135080d8 | 1510 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
abef7149 DO |
1511 | // Even if the user requested an empty tag list, don't bail out, but process existing |
1512 | // tag chains with "zero" extra. This will make sure, that the stuff processed will | |
1513 | // have its chains refined to "normal" form. | |
1514 | $extratags = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); | |
1515 | $n_ok = 0; | |
1516 | // Minimizing the extra chain early, so that tag rebuilder doesn't have to | |
1517 | // filter out the same tag again and again. It will have own noise to cancel. | |
1518 | $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags)); | |
61a1d996 | 1519 | foreach (listCells ('rack', $_REQUEST['row_id']) as $rack) |
abef7149 | 1520 | { |
61a1d996 | 1521 | if (rebuildTagChainForEntity ('rack', $rack['id'], $extrachain)) |
abef7149 | 1522 | $n_ok++; |
61a1d996 DO |
1523 | amplifyCell ($rack); |
1524 | foreach ($rack['mountedObjects'] as $object_id) | |
abef7149 DO |
1525 | if (rebuildTagChainForEntity ('object', $object_id, $extrachain)) |
1526 | $n_ok++; | |
1527 | } | |
135080d8 | 1528 | return buildRedirectURL (__FUNCTION__, 'OK', array ($n_ok)); |
eb6ea26f DO |
1529 | } |
1530 | ||
b6a7d936 DO |
1531 | $msgcode['changeMyPassword']['OK'] = 61; |
1532 | $msgcode['changeMyPassword']['ERR1'] = 150; | |
1533 | $msgcode['changeMyPassword']['ERR2'] = 151; | |
1534 | $msgcode['changeMyPassword']['ERR3'] = 152; | |
1535 | $msgcode['changeMyPassword']['ERR4'] = 153; | |
9457ca59 | 1536 | function changeMyPassword () |
cced6b7d | 1537 | { |
b82cce3f | 1538 | global $remote_username, $user_auth_src; |
204284ba | 1539 | if ($user_auth_src != 'database') |
135080d8 | 1540 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
0cc24e9a DY |
1541 | assertStringArg ('oldpassword'); |
1542 | assertStringArg ('newpassword1'); | |
1543 | assertStringArg ('newpassword2'); | |
b82cce3f | 1544 | $remote_userid = getUserIDByUsername ($remote_username); |
0b2c74cb | 1545 | $userinfo = spotEntity ('user', $remote_userid); |
b82cce3f | 1546 | if ($userinfo['user_password_hash'] != sha1 ($_REQUEST['oldpassword'])) |
135080d8 | 1547 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
cced6b7d | 1548 | if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2']) |
135080d8 | 1549 | return buildRedirectURL (__FUNCTION__, 'ERR3'); |
b82cce3f | 1550 | if (commitUpdateUserAccount ($remote_userid, $userinfo['user_name'], $userinfo['user_realname'], sha1 ($_REQUEST['newpassword1']))) |
135080d8 | 1551 | return buildRedirectURL (__FUNCTION__, 'OK'); |
cced6b7d | 1552 | else |
135080d8 | 1553 | return buildRedirectURL (__FUNCTION__, 'ERR4'); |
cced6b7d DO |
1554 | } |
1555 | ||
b6a7d936 DO |
1556 | $msgcode['saveRackCode']['OK'] = 43; |
1557 | $msgcode['saveRackCode']['ERR1'] = 154; | |
1558 | $msgcode['saveRackCode']['ERR2'] = 155; | |
cced6b7d DO |
1559 | function saveRackCode () |
1560 | { | |
cced6b7d | 1561 | assertStringArg ('rackcode'); |
e6a4adb9 DO |
1562 | // For the test to succeed, unescape LFs, strip CRs. |
1563 | $newcode = str_replace ('\r', '', str_replace ('\n', "\n", $_REQUEST['rackcode'])); | |
cf25e649 DO |
1564 | $parseTree = getRackCode ($newcode); |
1565 | if ($parseTree['result'] != 'ACK') | |
135080d8 | 1566 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($parseTree['load'])); |
4a6a28f1 | 1567 | saveScript ('RackCodeCache', ''); |
cf25e649 | 1568 | if (saveScript ('RackCode', $newcode)) |
135080d8 | 1569 | return buildRedirectURL (__FUNCTION__, 'OK'); |
cced6b7d | 1570 | else |
135080d8 | 1571 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
cced6b7d DO |
1572 | } |
1573 | ||
b6a7d936 | 1574 | $msgcode['setPortVLAN']['ERR1'] = 156; |
46f92ff7 DO |
1575 | // This handler's context is pre-built, but not authorized. It is assumed, that the |
1576 | // handler will take existing context and before each commit check authorization | |
1577 | // on the base chain plus necessary context added. | |
1578 | function setPortVLAN () | |
1579 | { | |
0cc24e9a | 1580 | assertUIntArg ('portcount'); |
46f92ff7 DO |
1581 | $data = getSwitchVLANs ($_REQUEST['object_id']); |
1582 | if ($data === NULL) | |
135080d8 | 1583 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
46f92ff7 DO |
1584 | list ($vlanlist, $portlist) = $data; |
1585 | // Here we just build up 1 set command for the gateway with all of the ports | |
1586 | // included. The gateway is expected to filter unnecessary changes silently | |
1587 | // and to provide a list of responses with either error or success message | |
1588 | // for each of the rest. | |
1589 | $nports = $_REQUEST['portcount']; | |
1590 | $prefix = 'set '; | |
db55cf54 | 1591 | $log = emptyLog(); |
46f92ff7 DO |
1592 | $setcmd = ''; |
1593 | for ($i = 0; $i < $nports; $i++) | |
1594 | if | |
1595 | ( | |
1596 | !isset ($_REQUEST['portname_' . $i]) || | |
1597 | !isset ($_REQUEST['vlanid_' . $i]) || | |
1598 | $_REQUEST['portname_' . $i] != $portlist[$i]['portname'] | |
1599 | ) | |
24dcb9d8 | 1600 | $log['m'][] = array ('c' => 158, 'a' => array ($i)); |
46f92ff7 DO |
1601 | elseif |
1602 | ( | |
1603 | $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] || | |
1604 | $portlist[$i]['vlaind'] == 'TRUNK' | |
1605 | ) | |
1606 | continue; | |
1607 | else | |
1608 | { | |
1609 | $portname = $_REQUEST['portname_' . $i]; | |
1610 | $oldvlanid = $portlist[$i]['vlanid']; | |
1611 | $newvlanid = $_REQUEST['vlanid_' . $i]; | |
1612 | // Finish the security context and evaluate it. | |
1613 | $annex = array(); | |
1614 | $annex[] = array ('tag' => '$fromvlan_' . $oldvlanid); | |
1615 | $annex[] = array ('tag' => '$tovlan_' . $newvlanid); | |
1616 | if (!permitted (NULL, NULL, NULL, $annex)) | |
1617 | { | |
24dcb9d8 | 1618 | $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid)); |
46f92ff7 DO |
1619 | continue; |
1620 | } | |
1621 | $setcmd .= $prefix . $portname . '=' . $newvlanid; | |
1622 | $prefix = ';'; | |
1623 | } | |
1624 | // Feed the gateway and interpret its (non)response. | |
1625 | if ($setcmd != '') | |
f0ff4930 | 1626 | $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd)); |
46f92ff7 | 1627 | else |
24dcb9d8 | 1628 | $log['m'][] = array ('c' => 201); |
46f92ff7 DO |
1629 | return buildWideRedirectURL ($log); |
1630 | } | |
1631 | ||
2987fc1f DO |
1632 | function submitSLBConfig () |
1633 | { | |
0cc24e9a | 1634 | assertUIntArg ('object_id'); |
2987fc1f | 1635 | $newconfig = buildLVSConfig ($_REQUEST['object_id']); |
ff0df5c3 | 1636 | $msglog = gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8')); |
2987fc1f DO |
1637 | return buildWideRedirectURL ($msglog); |
1638 | } | |
1639 | ||
b6a7d936 DO |
1640 | $msgcode['addRow']['OK'] = 74; |
1641 | $msgcode['addRow']['ERR'] = 100; | |
345fd640 AD |
1642 | function addRow () |
1643 | { | |
0cc24e9a | 1644 | assertStringArg ('name'); |
345fd640 | 1645 | |
10bac82a | 1646 | if (commitAddRow ($_REQUEST['name']) === TRUE) |
135080d8 | 1647 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name'])); |
345fd640 | 1648 | else |
135080d8 | 1649 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($_REQUEST['name'])); |
345fd640 AD |
1650 | } |
1651 | ||
b6a7d936 DO |
1652 | $msgcode['updateRow']['OK'] = 75; |
1653 | $msgcode['updateRow']['ERR'] = 100; | |
345fd640 AD |
1654 | function updateRow () |
1655 | { | |
0cc24e9a DY |
1656 | assertUIntArg ('row_id'); |
1657 | assertStringArg ('name'); | |
345fd640 | 1658 | |
10bac82a | 1659 | if (TRUE === commitUpdateRow ($_REQUEST['row_id'], $_REQUEST['name'])) |
135080d8 | 1660 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name'])); |
345fd640 | 1661 | else |
135080d8 | 1662 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($_REQUEST['name'])); |
345fd640 AD |
1663 | } |
1664 | ||
b6a7d936 DO |
1665 | $msgcode['deleteRow']['OK'] = 77; |
1666 | $msgcode['deleteRow']['ERR'] = 100; | |
9f14a7ef DY |
1667 | function deleteRow () |
1668 | { | |
0cc24e9a | 1669 | assertUIntArg ('row_id'); |
7be51fea | 1670 | $rowinfo = getRackRowInfo ($_REQUEST['row_id']); |
9f14a7ef DY |
1671 | |
1672 | if (TRUE === commitDeleteRow ($_REQUEST['row_id'])) | |
7be51fea | 1673 | return buildRedirectURL (__FUNCTION__, 'OK', array ($rowinfo['name'])); |
9f14a7ef | 1674 | else |
7be51fea | 1675 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($rowinfo['name'])); |
9f14a7ef DY |
1676 | } |
1677 | ||
b6a7d936 DO |
1678 | $msgcode['addRack']['OK'] = 65; |
1679 | $msgcode['addRack']['ERR1'] = 171; | |
1680 | $msgcode['addRack']['ERR2'] = 172; | |
f19c75d6 DO |
1681 | function addRack () |
1682 | { | |
0cc24e9a | 1683 | assertUIntArg ('row_id'); |
f19c75d6 DO |
1684 | $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); |
1685 | if (isset ($_REQUEST['got_data'])) | |
1686 | { | |
0cc24e9a DY |
1687 | assertStringArg ('rack_name'); |
1688 | assertUIntArg ('rack_height1'); | |
1689 | assertStringArg ('rack_comment', TRUE); | |
f19c75d6 DO |
1690 | |
1691 | if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE) | |
135080d8 | 1692 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name'])); |
f19c75d6 | 1693 | else |
135080d8 | 1694 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($_REQUEST['rack_name'])); |
f19c75d6 DO |
1695 | } |
1696 | elseif (isset ($_REQUEST['got_mdata'])) | |
1697 | { | |
0cc24e9a DY |
1698 | assertUIntArg ('rack_height2'); |
1699 | assertStringArg ('rack_names', TRUE); | |
db55cf54 | 1700 | $log = emptyLog(); |
f19c75d6 DO |
1701 | // copy-and-paste from renderAddMultipleObjectsForm() |
1702 | $names1 = explode ('\n', $_REQUEST['rack_names']); | |
1703 | $names2 = array(); | |
1704 | foreach ($names1 as $line) | |
1705 | { | |
1706 | $parts = explode ('\r', $line); | |
1707 | reset ($parts); | |
59a83bd8 | 1708 | if (!strlen ($parts[0])) |
f19c75d6 DO |
1709 | continue; |
1710 | else | |
1711 | $names2[] = rtrim ($parts[0]); | |
1712 | } | |
b3029d5c | 1713 | global $msgcode; |
f19c75d6 DO |
1714 | foreach ($names2 as $cname) |
1715 | if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE) | |
b3029d5c | 1716 | $log['m'][] = array ('c' => $msgcode[__FUNCTION__]['OK'], 'a' => array ($cname)); |
f19c75d6 | 1717 | else |
b3029d5c | 1718 | $log['m'][] = array ('c' => $msgcode[__FUNCTION__]['ERR1'], 'a' => array ($cname)); |
f19c75d6 DO |
1719 | return buildWideRedirectURL ($log); |
1720 | } | |
1721 | else | |
135080d8 | 1722 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
f19c75d6 DO |
1723 | } |
1724 | ||
b6a7d936 DO |
1725 | $msgcode['deleteRack']['OK'] = 79; |
1726 | $msgcode['deleteRack']['ERR'] = 100; | |
1727 | $msgcode['deleteRack']['ERR1'] = 206; | |
c8187437 DY |
1728 | function deleteRack () |
1729 | { | |
0cc24e9a | 1730 | assertUIntArg ('rack_id'); |
61a1d996 DO |
1731 | if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id']))) |
1732 | return buildRedirectURL (__FUNCTION__, 'ERR', array ('Rack not found'), 'rackspace', 'default'); | |
1733 | amplifyCell ($rackData); | |
1734 | if (count ($rackData['mountedObjects'])) | |
c8187437 | 1735 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
61a1d996 DO |
1736 | if (TRUE !== commitDeleteRack ($_REQUEST['rack_id'])) |
1737 | return buildRedirectURL (__FUNCTION__, 'ERR', array(), 'rackspace', 'default'); | |
1738 | return buildRedirectURL (__FUNCTION__, 'OK', array ($rackData['name']), 'rackspace', 'default'); | |
c8187437 DY |
1739 | } |
1740 | ||
b6a7d936 DO |
1741 | $msgcode['updateRack']['OK'] = 68; |
1742 | $msgcode['updateRack']['ERR'] = 177; | |
7056988c DO |
1743 | function updateRack () |
1744 | { | |
0cc24e9a DY |
1745 | assertUIntArg ('rack_id'); |
1746 | assertUIntArg ('rack_row_id'); | |
1747 | assertUIntArg ('rack_height'); | |
1748 | assertStringArg ('rack_name'); | |
1749 | assertStringArg ('rack_comment', TRUE); | |
7056988c | 1750 | |
7056988c | 1751 | resetThumbCache ($_REQUEST['rack_id']); |
0c2b7c4a | 1752 | if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment'])) |
135080d8 | 1753 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name'])); |
0c2b7c4a | 1754 | else |
135080d8 | 1755 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
7056988c DO |
1756 | } |
1757 | ||
61a1d996 | 1758 | $msgcode['updateRackDesign']['ERR'] = 100; |
4fbb5a00 DY |
1759 | function updateRackDesign () |
1760 | { | |
0cc24e9a | 1761 | assertUIntArg ('rack_id'); |
61a1d996 DO |
1762 | if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id']))) |
1763 | return buildRedirectURL (__FUNCTION__, 'ERR', array ('Rack not found'), 'rackspace', 'default'); | |
1764 | amplifyCell ($rackData); | |
4fbb5a00 DY |
1765 | applyRackDesignMask($rackData); |
1766 | markupObjectProblems ($rackData); | |
1767 | $response = processGridForm ($rackData, 'A', 'F'); | |
51690ad4 | 1768 | return buildWideRedirectURL (array($response)); |
4fbb5a00 DY |
1769 | } |
1770 | ||
61a1d996 | 1771 | $msgcode['updateRackProblems']['ERR'] = 100; |
4fbb5a00 DY |
1772 | function updateRackProblems () |
1773 | { | |
0cc24e9a | 1774 | assertUIntArg ('rack_id'); |
61a1d996 DO |
1775 | if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id']))) |
1776 | return buildRedirectURL (__FUNCTION__, 'ERR', array ('Rack not found'), 'rackspace', 'default'); | |
1777 | amplifyCell ($rackData); | |
4fbb5a00 DY |
1778 | applyRackProblemMask($rackData); |
1779 | markupObjectProblems ($rackData); | |
1780 | $response = processGridForm ($rackData, 'F', 'U'); | |
51690ad4 | 1781 | return buildWideRedirectURL (array($response)); |
4fbb5a00 DY |
1782 | } |
1783 | ||
7056988c DO |
1784 | function querySNMPData () |
1785 | { | |
0cc24e9a DY |
1786 | assertUIntArg ('object_id'); |
1787 | assertStringArg ('community'); | |
8536e20a | 1788 | return doSNMPmining ($_REQUEST['object_id'], $_REQUEST['community']); |
7056988c DO |
1789 | } |
1790 | ||
b6a7d936 DO |
1791 | $msgcode['addFileWithoutLink']['OK'] = 69; |
1792 | $msgcode['addFileWithoutLink']['ERR'] = 100; | |
e1ae3fb4 AD |
1793 | // File-related functions |
1794 | function addFileWithoutLink () | |
1795 | { | |
0cc24e9a | 1796 | assertStringArg ('comment', TRUE); |
e1ae3fb4 AD |
1797 | |
1798 | // Make sure the file can be uploaded | |
1799 | if (get_cfg_var('file_uploads') != 1) | |
135080d8 | 1800 | return buildRedirectURL (__FUNCTION__, 'ERR', array ("file uploads not allowed, change 'file_uploads' parameter in php.ini")); |
e1ae3fb4 AD |
1801 | |
1802 | $fp = fopen($_FILES['file']['tmp_name'], 'rb'); | |
4bb95650 DO |
1803 | global $sic; |
1804 | // commitAddFile() uses prepared statements | |
1805 | $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']); | |
f857f71f DO |
1806 | if (isset ($_REQUEST['taglist'])) |
1807 | produceTagsForLastRecord ('file', $_REQUEST['taglist']); | |
e1ae3fb4 AD |
1808 | |
1809 | if ($error != '') | |
135080d8 | 1810 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e1ae3fb4 | 1811 | |
135080d8 | 1812 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_FILES['file']['name'])); |
e1ae3fb4 AD |
1813 | } |
1814 | ||
b6a7d936 DO |
1815 | $msgcode['addFileToEntity']['OK'] = 69; |
1816 | $msgcode['addFileToEntity']['ERR1'] = 187; | |
1817 | $msgcode['addFileToEntity']['ERR2'] = 181; | |
1818 | $msgcode['addFileToEntity']['ERR3'] = 182; | |
e1ae3fb4 AD |
1819 | function addFileToEntity () |
1820 | { | |
9a61c175 DO |
1821 | global $page, $pageno, $etype_by_pageno; |
1822 | if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass'])) | |
1823 | return buildRedirectURL (__FUNCTION__, 'ERR1', array (__FUNCTION__)); | |
1824 | $realm = $etype_by_pageno[$pageno]; | |
1825 | $bypass = $page[$pageno]['bypass']; | |
0cc24e9a | 1826 | assertUIntArg ($bypass); |
9a61c175 | 1827 | $entity_id = $_REQUEST[$bypass]; |
0cc24e9a | 1828 | assertStringArg ('comment', TRUE); |
e1ae3fb4 AD |
1829 | |
1830 | // Make sure the file can be uploaded | |
1831 | if (get_cfg_var('file_uploads') != 1) | |
9a61c175 | 1832 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
e1ae3fb4 AD |
1833 | |
1834 | $fp = fopen($_FILES['file']['tmp_name'], 'rb'); | |
4bb95650 DO |
1835 | global $sic; |
1836 | // commitAddFile() uses prepared statements | |
1837 | $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']); | |
e1ae3fb4 | 1838 | if ($error != '') |
9a61c175 | 1839 | return buildRedirectURL (__FUNCTION__, 'ERR3', array ($error)); |
e1ae3fb4 | 1840 | |
9a61c175 | 1841 | $error = commitLinkFile (lastInsertID(), $realm, $entity_id); |
e1ae3fb4 | 1842 | if ($error != '') |
9a61c175 | 1843 | return buildRedirectURL (__FUNCTION__, 'ERR3', array ($error)); |
e1ae3fb4 | 1844 | |
135080d8 | 1845 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_FILES['file']['name'])); |
e1ae3fb4 AD |
1846 | } |
1847 | ||
b6a7d936 DO |
1848 | $msgcode['linkFileToEntity']['OK'] = 71; |
1849 | $msgcode['linkFileToEntity']['ERR1'] = 178; | |
1850 | $msgcode['linkFileToEntity']['ERR2'] = 100; | |
e1ae3fb4 AD |
1851 | function linkFileToEntity () |
1852 | { | |
0cc24e9a | 1853 | assertUIntArg ('file_id'); |
482c7f35 | 1854 | global $page, $pageno, $etype_by_pageno; |
121496b6 DO |
1855 | $entity_type = $etype_by_pageno[$pageno]; |
1856 | $bypass_name = $page[$pageno]['bypass']; | |
0cc24e9a | 1857 | assertUIntArg ($bypass_name); |
121496b6 | 1858 | |
d3b5008b | 1859 | $fi = spotEntity ('file', $_REQUEST['file_id']); |
121496b6 | 1860 | if ($fi === NULL) |
135080d8 | 1861 | return buildRedirectURL (__FUNCTION__, 'ERR1'); // file not found |
121496b6 | 1862 | $error = commitLinkFile ($_REQUEST['file_id'], $entity_type, $_REQUEST[$bypass_name]); |
e1ae3fb4 | 1863 | if ($error != '') |
135080d8 | 1864 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error)); // linking failed |
e1ae3fb4 | 1865 | |
135080d8 | 1866 | return buildRedirectURL (__FUNCTION__, 'OK', array ($fi['name'])); |
e1ae3fb4 AD |
1867 | } |
1868 | ||
b6a7d936 DO |
1869 | $msgcode['replaceFile']['OK'] = 70; |
1870 | $msgcode['replaceFile']['ERR1'] = 181; | |
1871 | $msgcode['replaceFile']['ERR2'] = 207; | |
1872 | $msgcode['replaceFile']['ERR3'] = 182; | |
fd1fb420 AD |
1873 | function replaceFile () |
1874 | { | |
db55cf54 | 1875 | global $sic; |
0cc24e9a | 1876 | assertUIntArg ('file_id'); |
fd1fb420 AD |
1877 | |
1878 | // Make sure the file can be uploaded | |
1879 | if (get_cfg_var('file_uploads') != 1) | |
db55cf54 | 1880 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
d3b5008b | 1881 | $shortInfo = spotEntity ('file', $sic['file_id']); |
fd1fb420 AD |
1882 | |
1883 | $fp = fopen($_FILES['file']['tmp_name'], 'rb'); | |
db55cf54 DO |
1884 | if ($fp === FALSE) |
1885 | return buildRedirectURL (__FUNCTION__, 'ERR2'); | |
f8874cdb | 1886 | $error = commitReplaceFile ($sic['file_id'], $fp); |
fd1fb420 | 1887 | if ($error != '') |
db55cf54 | 1888 | return buildRedirectURL (__FUNCTION__, 'ERR3', array ($error)); |
fd1fb420 | 1889 | |
db55cf54 | 1890 | return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name']))); |
fd1fb420 AD |
1891 | } |
1892 | ||
b6a7d936 DO |
1893 | $msgcode['updateFile']['OK'] = 70; |
1894 | $msgcode['updateFile']['ERR'] = 100; | |
e1ae3fb4 AD |
1895 | function updateFile () |
1896 | { | |
0cc24e9a DY |
1897 | assertUIntArg ('file_id'); |
1898 | assertStringArg ('file_name'); | |
1899 | assertStringArg ('file_type'); | |
1900 | assertStringArg ('file_comment', TRUE); | |
f3d274bf DO |
1901 | // prepared statement params below |
1902 | global $sic; | |
1903 | $error = commitUpdateFile ($sic['file_id'], $sic['file_name'], $sic['file_type'], $sic['file_comment']); | |
e1ae3fb4 | 1904 | if ($error != '') |
135080d8 | 1905 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e1ae3fb4 | 1906 | |
135080d8 | 1907 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name'])); |
e1ae3fb4 AD |
1908 | } |
1909 | ||
b6a7d936 DO |
1910 | $msgcode['unlinkFile']['OK'] = 72; |
1911 | $msgcode['unlinkFile']['ERR'] = 182; | |
e1ae3fb4 AD |
1912 | function unlinkFile () |
1913 | { | |
0cc24e9a | 1914 | assertUIntArg ('link_id'); |
e1ae3fb4 AD |
1915 | $error = commitUnlinkFile ($_REQUEST['link_id']); |
1916 | ||
1917 | if ($error != '') | |
135080d8 | 1918 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e1ae3fb4 | 1919 | |
8bc5d1e4 | 1920 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e1ae3fb4 AD |
1921 | } |
1922 | ||
b6a7d936 DO |
1923 | $msgcode['deleteFile']['OK'] = 73; |
1924 | $msgcode['deleteFile']['ERR'] = 100; | |
e1ae3fb4 AD |
1925 | function deleteFile () |
1926 | { | |
0cc24e9a | 1927 | assertUIntArg ('file_id'); |
d3b5008b | 1928 | $shortInfo = spotEntity ('file', $_REQUEST['file_id']); |
e1ae3fb4 AD |
1929 | $error = commitDeleteFile ($_REQUEST['file_id']); |
1930 | ||
1931 | if ($error != '') | |
135080d8 | 1932 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e1ae3fb4 | 1933 | |
f8874cdb | 1934 | return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name']))); |
e1ae3fb4 AD |
1935 | } |
1936 | ||
b6a7d936 DO |
1937 | $msgcode['updateFileText']['OK'] = 78; |
1938 | $msgcode['updateFileText']['ERR1'] = 179; | |
1939 | $msgcode['updateFileText']['ERR2'] = 180; | |
8628ae44 DO |
1940 | function updateFileText () |
1941 | { | |
0cc24e9a DY |
1942 | assertUIntArg ('file_id'); |
1943 | assertStringArg ('mtime_copy'); | |
1944 | assertStringArg ('file_text', TRUE); // it's Ok to save empty | |
d3b5008b | 1945 | $shortInfo = spotEntity ('file', $_REQUEST['file_id']); |
70cb9b56 DO |
1946 | if ($shortInfo['mtime'] != $_REQUEST['mtime_copy']) |
1947 | return buildRedirectURL (__FUNCTION__, 'ERR1'); | |
f8874cdb DO |
1948 | global $sic; |
1949 | $error = commitReplaceFile ($sic['file_id'], $sic['file_text']); | |
8628ae44 | 1950 | if ($error == '') |
f8874cdb | 1951 | return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name']))); |
70cb9b56 | 1952 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
8628ae44 DO |
1953 | } |
1954 | ||
2dfa1b73 DO |
1955 | $msgcode['addPortInterfaceCompat']['OK'] = 48; |
1956 | $msgcode['addPortInterfaceCompat']['ERR'] = 110; | |
1957 | function addPortInterfaceCompat () | |
1958 | { | |
0cc24e9a DY |
1959 | assertUIntArg ('iif_id'); |
1960 | assertUIntArg ('oif_id'); | |
2dfa1b73 DO |
1961 | if (commitSupplementPIC ($_REQUEST['iif_id'], $_REQUEST['oif_id'])) |
1962 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
1963 | return buildRedirectURL (__FUNCTION__, 'ERR'); | |
1964 | } | |
1965 | ||
1966 | $msgcode['delPortInterfaceCompat']['OK'] = 49; | |
1967 | $msgcode['delPortInterfaceCompat']['ERR'] = 111; | |
1968 | function delPortInterfaceCompat () | |
1969 | { | |
0cc24e9a DY |
1970 | assertUIntArg ('iif_id'); |
1971 | assertUIntArg ('oif_id'); | |
2dfa1b73 DO |
1972 | if (commitReducePIC ($_REQUEST['iif_id'], $_REQUEST['oif_id'])) |
1973 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
1974 | return buildRedirectURL (__FUNCTION__, 'ERR'); | |
1975 | } | |
1976 | ||
2400d7ec DO |
1977 | $ifcompatpack = array |
1978 | ( | |
1979 | '1000cwdm80' => array (1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216), | |
1980 | '1000dwdm80' => array // ITU channels 20~61 | |
1981 | ( | |
1982 | 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226, | |
1983 | 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236, | |
1984 | 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, | |
1985 | 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256, | |
1986 | 1257, 1258 | |
1987 | ), | |
1988 | '10000dwdm80' => array // same channels for 10GE | |
1989 | ( | |
1990 | 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268, | |
1991 | 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, | |
1992 | 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, | |
1993 | 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298, | |
1994 | 1299, 1300 | |
1995 | ), | |
1996 | ); | |
1997 | ||
3d9ac3d4 DO |
1998 | $msgcode['addPortInterfaceCompatPack']['OK'] = 44; |
1999 | $msgcode['addPortInterfaceCompatPack']['ERR'] = 123; | |
2400d7ec DO |
2000 | function addPortInterfaceCompatPack () |
2001 | { | |
0cc24e9a DY |
2002 | assertStringArg ('standard'); |
2003 | assertUIntArg ('iif_id'); | |
3d9ac3d4 DO |
2004 | global $ifcompatpack; |
2005 | if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions())) | |
2006 | return buildRedirectURL (__FUNCTION__, 'ERR'); | |
2007 | $ngood = $nbad = 0; | |
2008 | foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id) | |
2009 | if (commitSupplementPIC ($_REQUEST['iif_id'], $oif_id)) | |
2010 | $ngood++; | |
2011 | else | |
2012 | $nbad++; | |
2013 | return buildRedirectURL (__FUNCTION__, 'OK', array ($nbad, $ngood)); | |
2400d7ec DO |
2014 | } |
2015 | ||
3d9ac3d4 DO |
2016 | $msgcode['delPortInterfaceCompatPack']['OK'] = 44; |
2017 | $msgcode['delPortInterfaceCompatPack']['ERR'] = 123; | |
2400d7ec DO |
2018 | function delPortInterfaceCompatPack () |
2019 | { | |
0cc24e9a DY |
2020 | assertStringArg ('standard'); |
2021 | assertUIntArg ('iif_id'); | |
3d9ac3d4 DO |
2022 | global $ifcompatpack; |
2023 | if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions())) | |
2024 | return buildRedirectURL (__FUNCTION__, 'ERR'); | |
2025 | $ngood = $nbad = 0; | |
2026 | foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id) | |
2027 | if (commitReducePIC ($_REQUEST['iif_id'], $oif_id)) | |
2028 | $ngood++; | |
2029 | else | |
2030 | $nbad++; | |
2031 | return buildRedirectURL (__FUNCTION__, 'OK', array ($nbad, $ngood)); | |
2400d7ec DO |
2032 | } |
2033 | ||
a310dd80 DO |
2034 | $msgcode['addPortOIFCompat']['OK'] = 48; |
2035 | $msgcode['addPortOIFCompat']['ERR'] = 110; | |
2036 | function addPortOIFCompat() | |
2037 | { | |
80ec1f4f DO |
2038 | assertUIntArg('type1'); |
2039 | assertUIntArg('type2'); | |
a310dd80 DO |
2040 | if (commitSupplementPOIFC($_REQUEST['type1'], $_REQUEST['type2'])) |
2041 | return buildRedirectURL(__FUNCTION__, 'OK'); | |
2042 | return buildRedirectURL(__FUNCTION__, 'ERR'); | |
2043 | } | |
2044 | ||
2045 | $msgcode['delPortOIFCompat']['OK'] = 49; | |
2046 | $msgcode['delPortOIFCompat']['ERR'] = 111; | |
2047 | function delPortOIFCompat () | |
2048 | { | |
80ec1f4f DO |
2049 | assertUIntArg('type1'); |
2050 | assertUIntArg('type2'); | |
a310dd80 DO |
2051 | if (commitReducePOIFC ($_REQUEST['type1'], $_REQUEST['type2'])) |
2052 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
2053 | return buildRedirectURL (__FUNCTION__, 'ERR'); | |
2054 | ||
2055 | } | |
2056 | ||
38cd7704 DO |
2057 | $msgcode['add8021QOrder']['OK'] = 48; |
2058 | $msgcode['add8021QOrder']['ERR'] = 118; | |
2059 | function add8021QOrder () | |
8198f2c6 | 2060 | { |
80ec1f4f DO |
2061 | assertUIntArg ('vdom_id'); |
2062 | assertUIntArg ('object_id'); | |
38cd7704 | 2063 | assertUIntArg ('vst_id'); |
8198f2c6 DO |
2064 | global $sic; |
2065 | $result = usePreparedInsertBlade | |
2066 | ( | |
2067 | 'VLANSwitch', | |
2068 | array | |
2069 | ( | |
2070 | 'domain_id' => $sic['vdom_id'], | |
2071 | 'object_id' => $sic['object_id'], | |
38cd7704 | 2072 | 'template_id' => $sic['vst_id'], |
8198f2c6 DO |
2073 | ) |
2074 | ); | |
2075 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2076 | } | |
2077 | ||
38cd7704 DO |
2078 | $msgcode['del8021QOrder']['OK'] = 49; |
2079 | $msgcode['del8021QOrder']['ERR'] = 119; | |
2080 | function del8021QOrder () | |
8198f2c6 | 2081 | { |
80ec1f4f | 2082 | assertUIntArg ('object_id'); |
8198f2c6 | 2083 | global $sic; |
38cd7704 | 2084 | $result = usePreparedDeleteBlade ('VLANSwitch', array ('object_id' => $sic['object_id'])); |
8198f2c6 DO |
2085 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); |
2086 | } | |
2087 | ||
2088 | $msgcode['addVLANDescription']['OK'] = 48; | |
2089 | $msgcode['addVLANDescription']['ERR1'] = 190; | |
2090 | $msgcode['addVLANDescription']['ERR2'] = 110; | |
2091 | function addVLANDescription () | |
2092 | { | |
80ec1f4f | 2093 | assertUIntArg ('vlan_id'); |
5b989e4d | 2094 | assertStringArg ('vlan_type', TRUE); |
80ec1f4f | 2095 | assertStringArg ('vlan_descr', TRUE); |
8198f2c6 DO |
2096 | global $sic; |
2097 | if (!($sic['vlan_id'] >= VLAN_MIN_ID and $sic['vlan_id'] <= VLAN_MAX_ID)) | |
2098 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($sic['vlan_id'])); | |
2099 | $result = usePreparedInsertBlade | |
2100 | ( | |
2101 | 'VLANDescription', | |
2102 | array | |
2103 | ( | |
2104 | 'domain_id' => $sic['vdom_id'], | |
2105 | 'vlan_id' => $sic['vlan_id'], | |
5b989e4d | 2106 | 'vlan_type' => $sic['vlan_type'], |
5286b29f | 2107 | 'vlan_descr' => mb_strlen ($sic['vlan_descr']) ? $sic['vlan_descr'] : NULL |
8198f2c6 DO |
2108 | ) |
2109 | ); | |
2110 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR2'); | |
2111 | } | |
2112 | ||
2113 | $msgcode['delVLANDescription']['OK'] = 49; | |
2114 | $msgcode['delVLANDescription']['ERR'] = 111; | |
2115 | function delVLANDescription () | |
2116 | { | |
80ec1f4f | 2117 | assertUIntArg ('vlan_id'); |
8198f2c6 DO |
2118 | global $sic; |
2119 | $result = commitReduceVLANDescription ($sic['vdom_id'], $sic['vlan_id']); | |
2120 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2121 | } | |
2122 | ||
2123 | $msgcode['updVLANDescription']['OK'] = 51; | |
2124 | $msgcode['updVLANDescription']['ERR'] = 109; | |
2125 | function updVLANDescription () | |
2126 | { | |
80ec1f4f DO |
2127 | assertUIntArg ('vlan_id'); |
2128 | assertStringArg ('vlan_type'); | |
2129 | assertStringArg ('vlan_descr', TRUE); | |
8198f2c6 DO |
2130 | global $sic; |
2131 | $result = commitUpdateVLANDescription | |
2132 | ( | |
2133 | $sic['vdom_id'], | |
2134 | $sic['vlan_id'], | |
0dabdc53 | 2135 | $sic['vlan_type'], |
8198f2c6 DO |
2136 | $sic['vlan_descr'] |
2137 | ); | |
2138 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2139 | } | |
2140 | ||
2141 | $msgcode['createVLANDomain']['OK'] = 48; | |
2142 | $msgcode['createVLANDomain']['ERR'] = 110; | |
2143 | function createVLANDomain () | |
2144 | { | |
80ec1f4f | 2145 | assertStringArg ('vdom_descr'); |
8198f2c6 DO |
2146 | global $sic; |
2147 | $result = usePreparedInsertBlade | |
2148 | ( | |
2149 | 'VLANDomain', | |
2150 | array | |
2151 | ( | |
2152 | 'description' => $sic['vdom_descr'], | |
2153 | ) | |
2154 | ); | |
2155 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2156 | } | |
2157 | ||
2158 | $msgcode['destroyVLANDomain']['OK'] = 49; | |
2159 | $msgcode['destroyVLANDomain']['ERR'] = 111; | |
2160 | function destroyVLANDomain () | |
2161 | { | |
80ec1f4f | 2162 | assertUIntArg ('vdom_id'); |
8198f2c6 | 2163 | global $sic; |
bbae3611 | 2164 | $result = FALSE !== usePreparedDeleteBlade ('VLANDomain', array ('id' => $sic['vdom_id'])); |
8198f2c6 DO |
2165 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); |
2166 | } | |
2167 | ||
2168 | $msgcode['updateVLANDomain']['OK'] = 51; | |
2169 | $msgcode['updateVLANDomain']['ERR'] = 109; | |
2170 | function updateVLANDomain () | |
2171 | { | |
80ec1f4f DO |
2172 | assertUIntArg ('vdom_id'); |
2173 | assertStringArg ('vdom_descr'); | |
8198f2c6 DO |
2174 | global $sic; |
2175 | $result = commitUpdateVLANDomain ($sic['vdom_id'], $sic['vdom_descr']); | |
2176 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2177 | } | |
2178 | ||
706d9175 DO |
2179 | $msgcode['save8021QPorts']['OK'] = 43; |
2180 | $msgcode['save8021QPorts']['ERR1'] = 160; | |
2181 | $msgcode['save8021QPorts']['ERR2'] = 109; | |
2182 | function save8021QPorts () | |
8198f2c6 | 2183 | { |
a7492e95 | 2184 | global $sic, $dbxlink; |
706d9175 DO |
2185 | assertUIntArg ('nports'); |
2186 | assertUIntArg ('mutex_rev'); | |
2187 | if ($sic['nports'] == 1) | |
2188 | { | |
2189 | assertStringArg ('pn_0'); | |
2190 | $extra = array ('port_name' => $sic['pn_0']); | |
2191 | } | |
2192 | else | |
2193 | $extra = array(); | |
a7492e95 | 2194 | $dbxlink->beginTransaction(); |
2996cbbb DO |
2195 | try |
2196 | { | |
a7492e95 DO |
2197 | if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE')) |
2198 | throw new InvalidArgException ('object_id', $object_id, 'VLAN domain is not set for this object'); | |
a7492e95 | 2199 | $stored_config = getDesired8021QConfig ($sic['object_id']); |
706d9175 DO |
2200 | $work = array(); |
2201 | for ($i = 0; $i < $sic['nports']; $i++) | |
2202 | { | |
2203 | assertStringArg ('pn_' . $i); | |
2204 | assertStringArg ('pm_' . $i); | |
2205 | # assertArrayArg ('pav_' . $i); | |
2206 | // An access port only generates form input for its native VLAN, | |
2207 | // which we derive allowed VLAN list from. | |
2208 | $native = isset ($sic['pnv_' . $i]) ? $sic['pnv_' . $i] : 0; | |
2209 | if ($sic["pm_${i}"] == 'trunk') | |
2210 | $allowed = isset ($sic['pav_' . $i]) ? $sic['pav_' . $i] : array(); | |
2211 | elseif ($native) | |
2212 | { | |
2213 | assertUIntArg ('pnv_' . $i); | |
2214 | $allowed = array ($native); | |
2215 | } | |
2216 | else | |
2217 | $allowed = array(); | |
2218 | ||
2219 | $work[$sic['pn_' . $i]] = array | |
2220 | ( | |
2221 | 'mode' => $sic['pm_' . $i], | |
2222 | 'allowed' => $allowed, | |
2223 | 'native' => $native, | |
2224 | ); | |
2225 | } | |
ec4d604c | 2226 | $npulled = importSwitch8021QConfig |
a7492e95 | 2227 | ( |
4741e9c3 | 2228 | $vswitch, |
a7492e95 | 2229 | $sic['mutex_rev'], |
a7492e95 DO |
2230 | $stored_config, |
2231 | $work, | |
2232 | $work | |
2233 | ); | |
2996cbbb DO |
2234 | } |
2235 | catch (Exception $e) | |
861292ee | 2236 | { |
a7492e95 | 2237 | $dbxlink->rollBack(); |
706d9175 | 2238 | return buildRedirectURL (__FUNCTION__, 'ERR2', array(), NULL, NULL, $extra); |
861292ee | 2239 | } |
ec4d604c DO |
2240 | if ($npulled) |
2241 | { | |
2242 | $query = $dbxlink->prepare ('UPDATE VLANSwitch SET mutex_rev = mutex_rev + 1, last_pull = NOW() WHERE object_id = ?'); | |
2243 | $query->execute (array ($sic['object_id'])); | |
2244 | } | |
a7492e95 | 2245 | $dbxlink->commit(); |
706d9175 | 2246 | return buildRedirectURL (__FUNCTION__, 'OK', array(), NULL, NULL, $extra); |
8198f2c6 DO |
2247 | } |
2248 | ||
8846b060 DO |
2249 | $msgcode['bindVLANtoIPv4']['OK'] = 48; |
2250 | $msgcode['bindVLANtoIPv4']['ERR'] = 110; | |
2251 | function bindVLANtoIPv4 () | |
2252 | { | |
2253 | assertUIntArg ('id'); // network id | |
2254 | global $sic; | |
2255 | $result = commitSupplementVLANIPv4 ($sic['vlan_ck'], $sic['id']); | |
2256 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2257 | } | |
2258 | ||
2259 | $msgcode['unbindVLANfromIPv4']['OK'] = 49; | |
2260 | $msgcode['unbindVLANfromIPv4']['ERR'] = 111; | |
2261 | function unbindVLANfromIPv4 () | |
2262 | { | |
2263 | assertUIntArg ('id'); // network id | |
2264 | global $sic; | |
2265 | $result = commitReduceVLANIPv4 ($sic['vlan_ck'], $sic['id']); | |
2266 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2267 | } | |
2268 | ||
07de6bb3 DO |
2269 | $msgcode['processVLANSyncRequest']['OK'] = 63; |
2270 | $msgcode['processVLANSyncRequest']['ERR'] = 179; | |
2271 | function processVLANSyncRequest () | |
2272 | { | |
a7492e95 | 2273 | global $sic, $dbxlink; |
07de6bb3 | 2274 | assertUIntArg ('mutex_rev'); |
de47b574 DO |
2275 | assertUIntArg ('nrows'); |
2276 | // Divide submitted radio buttons into 3 groups: | |
07de6bb3 DO |
2277 | // left (produce and send commands to switch) |
2278 | // asis (ignore) | |
2279 | // right (fetch config from switch and save into database) | |
a7492e95 | 2280 | $old_running_config = array(); |
de47b574 | 2281 | for ($i = 1; $i <= $sic['nrows']; $i++) |
07de6bb3 | 2282 | { |
de47b574 | 2283 | if (!array_key_exists ("i_${i}", $sic)) |
07de6bb3 | 2284 | continue; |
de47b574 DO |
2285 | // let's hope other inputs are in place |
2286 | switch ($sic["i_${i}"]) | |
07de6bb3 DO |
2287 | { |
2288 | case 'left': | |
07de6bb3 | 2289 | case 'right': |
a7492e95 | 2290 | $old_running_config[$sic["i_${i}"]][$sic["pn_${i}"]] = array |
07de6bb3 | 2291 | ( |
ca9e1c9d | 2292 | 'mode' => $sic["rm_${i}"], |
de47b574 DO |
2293 | 'allowed' => $sic["ra_${i}"], |
2294 | 'native' => $sic["rn_${i}"], | |
07de6bb3 DO |
2295 | ); |
2296 | break; | |
2297 | default: | |
2298 | // don't care | |
2299 | } | |
2300 | } | |
a7492e95 | 2301 | $dbxlink->beginTransaction(); |
07de6bb3 DO |
2302 | try |
2303 | { | |
a7492e95 | 2304 | if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE')) |
ec4d604c | 2305 | throw new InvalidArgException ('object_id', $sic['object_id'], 'VLAN domain is not set for this object'); |
a7492e95 DO |
2306 | $stored_config = getDesired8021QConfig ($sic['object_id']); |
2307 | $new_running_config = getRunning8021QConfig ($sic['object_id']); | |
ec4d604c | 2308 | $npulled = importSwitch8021QConfig |
a7492e95 | 2309 | ( |
4741e9c3 | 2310 | $vswitch, |
a7492e95 | 2311 | $sic['mutex_rev'], |
a7492e95 DO |
2312 | $stored_config, |
2313 | $old_running_config['right'], | |
2314 | $new_running_config['portdata'] | |
2315 | ); | |
ec4d604c DO |
2316 | // To keep device's VLAN table and uplink ports in sync regardless |
2317 | // of user's choice, "export" procedure must be run: | |
2318 | // 1. even if the user didn't select any ports for "export" | |
2319 | // 2. after call to "import" function | |
2320 | $npushed = exportSwitch8021QConfig | |
2321 | ( | |
4741e9c3 | 2322 | $vswitch, |
ec4d604c | 2323 | $sic['mutex_rev'], |
ec4d604c DO |
2324 | $new_running_config['vlanlist'], |
2325 | $old_running_config['left'], | |
2326 | $new_running_config['portdata'], | |
2327 | $stored_config | |
2328 | ); | |
07de6bb3 DO |
2329 | } |
2330 | catch (Exception $e) | |
2331 | { | |
a7492e95 DO |
2332 | $dbxlink->rollBack(); |
2333 | return buildRedirectURL (__FUNCTION__, 'ERR'); | |
07de6bb3 | 2334 | } |
ec4d604c DO |
2335 | if ($npushed) |
2336 | { | |
2337 | $query = $dbxlink->prepare ('UPDATE VLANSwitch SET last_push = NOW() WHERE object_id = ?'); | |
2338 | $query->execute (array ($sic['object_id'])); | |
2339 | } | |
2340 | if ($npulled) | |
2341 | { | |
2342 | $query = $dbxlink->prepare ('UPDATE VLANSwitch SET mutex_rev = mutex_rev + 1, last_pull = NOW() WHERE object_id = ?'); | |
2343 | $query->execute (array ($sic['object_id'])); | |
2344 | } | |
a7492e95 | 2345 | $dbxlink->commit(); |
ec4d604c | 2346 | return buildRedirectURL (__FUNCTION__, 'OK', array ($npulled + $npushed)); |
07de6bb3 DO |
2347 | } |
2348 | ||
e0d188ef DO |
2349 | $msgcode['addVLANSwitchTemplate']['OK'] = 48; |
2350 | $msgcode['addVLANSwitchTemplate']['ERR'] = 110; | |
2351 | function addVLANSwitchTemplate() | |
2352 | { | |
2353 | assertStringArg ('vst_descr'); | |
2354 | global $sic; | |
2355 | $max_local_vlans = NULL; | |
2356 | if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans'])) | |
2357 | { | |
2358 | assertUIntArg ('vst_maxvlans'); | |
2359 | $max_local_vlans = $sic['vst_maxvlans']; | |
2360 | } | |
2361 | $result = usePreparedInsertBlade | |
2362 | ( | |
2363 | 'VLANSwitchTemplate', | |
2364 | array | |
2365 | ( | |
2366 | 'max_local_vlans' => $max_local_vlans, | |
2367 | 'description' => $sic['vst_descr'], | |
2368 | ) | |
2369 | ); | |
2370 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2371 | } | |
2372 | ||
2373 | $msgcode['delVLANSwitchTemplate']['OK'] = 49; | |
2374 | $msgcode['delVLANSwitchTemplate']['ERR'] = 111; | |
2375 | function delVLANSwitchTemplate() | |
2376 | { | |
2377 | assertUIntArg ('vst_id'); | |
2378 | global $sic; | |
2379 | $result = FALSE !== usePreparedDeleteBlade ('VLANSwitchTemplate', array ('id' => $sic['vst_id'])); | |
2380 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2381 | } | |
2382 | ||
2383 | $msgcode['updVLANSwitchTemplate']['OK'] = 51; | |
2384 | $msgcode['updVLANSwitchTemplate']['ERR'] = 109; | |
2385 | function updVLANSwitchTemplate() | |
2386 | { | |
2387 | assertUIntArg ('vst_id'); | |
2388 | assertStringArg ('vst_descr'); | |
2389 | global $sic; | |
2390 | $max_local_vlans = NULL; | |
2391 | if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans'])) | |
2392 | { | |
2393 | assertUIntArg ('vst_maxvlans'); | |
2394 | $max_local_vlans = $sic['vst_maxvlans']; | |
2395 | } | |
2396 | $result = commitUpdateVST ($sic['vst_id'], $max_local_vlans, $sic['vst_descr']); | |
2397 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2398 | } | |
2399 | ||
2400 | $msgcode['addVSTRule']['OK'] = 48; | |
2401 | $msgcode['addVSTRule']['ERR'] = 110; | |
2402 | function addVSTRule() | |
2403 | { | |
2404 | assertUIntArg ('vst_id'); | |
2405 | assertUIntArg ('rule_no'); | |
2406 | assertPCREArg ('port_pcre'); | |
2407 | assertStringArg ('port_role'); | |
2408 | assertStringArg ('wrt_vlans', TRUE); | |
2409 | global $sic; | |
2410 | $result = usePreparedInsertBlade | |
2411 | ( | |
2412 | 'VLANSTRule', | |
2413 | array | |
2414 | ( | |
2415 | 'vst_id' => $sic['vst_id'], | |
2416 | 'rule_no' => $sic['rule_no'], | |
2417 | 'port_pcre' => $sic['port_pcre'], | |
2418 | 'port_role' => $sic['port_role'], | |
2419 | 'wrt_vlans' => $sic['wrt_vlans'], | |
2420 | ) | |
2421 | ); | |
2422 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2423 | } | |
2424 | ||
2425 | $msgcode['delVSTRule']['OK'] = 49; | |
2426 | $msgcode['delVSTRule']['ERR'] = 111; | |
2427 | function delVSTRule() | |
2428 | { | |
2429 | assertUIntArg ('vst_id'); | |
2430 | assertUIntArg ('rule_no'); | |
2431 | global $sic; | |
2432 | $result = FALSE !== usePreparedDeleteBlade | |
2433 | ( | |
2434 | 'VLANSTRule', | |
2435 | array | |
2436 | ( | |
2437 | 'vst_id' => $sic['vst_id'], | |
2438 | 'rule_no' => $sic['rule_no'] | |
2439 | ) | |
2440 | ); | |
2441 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2442 | } | |
2443 | ||
2444 | $msgcode['updVSTRule']['OK'] = 51; | |
2445 | $msgcode['updVSTRule']['ERR'] = 109; | |
2446 | function updVSTRule() | |
2447 | { | |
2448 | assertUIntArg ('vst_id'); | |
2449 | assertUIntArg ('rule_no'); | |
2450 | assertUIntArg ('new_rule_no'); | |
2451 | assertPCREArg ('port_pcre'); | |
2452 | assertStringArg ('port_role'); | |
2453 | assertStringArg ('wrt_vlans', TRUE); | |
2454 | global $sic; | |
2455 | $result = commitUpdateVSTRule | |
2456 | ( | |
2457 | $sic['vst_id'], | |
2458 | $sic['rule_no'], | |
2459 | $sic['new_rule_no'], | |
2460 | $sic['port_pcre'], | |
2461 | $sic['port_role'], | |
2462 | $sic['wrt_vlans'] | |
2463 | ); | |
2464 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2465 | } | |
2466 | ||
e673ee24 | 2467 | ?> |