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