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