4 * This file is a library of operation handlers for RackTables.
10 function buildWideRedirectURL ($log, $nextpage = NULL, $nexttab = NULL, $moreArgs = array())
12 global $page, $pageno, $tabno;
13 if ($nextpage === NULL)
15 if ($nexttab === NULL)
17 $url = "index.php?page=${nextpage}&tab=${nexttab}";
18 if (isset ($page[$nextpage]['bypass']))
19 $url .= '&' . $page[$nextpage]['bypass'] . '=' . $_REQUEST[$page[$nextpage]['bypass']];
21 if (count($moreArgs)>0)
23 foreach($moreArgs as $arg=>$value)
25 if (gettype($value) == 'array')
27 foreach ($value as $v)
29 $url .= '&'.urlencode($arg.'[]').'='.urlencode($v);
33 $url .= '&'.urlencode($arg).'='.urlencode($value);
37 $_SESSION['log'] = $log;
41 function buildRedirectURL ($callfunc, $status, $log_args = array(), $nextpage = NULL, $nexttab = NULL, $url_args = array())
43 global $pageno, $tabno, $msgcode;
44 if ($nextpage === NULL)
46 if ($nexttab === NULL)
48 return buildWideRedirectURL (oneLiner ($msgcode[$callfunc][$status], $log_args), $nextpage, $nexttab, $url_args);
51 $msgcode['addPortForwarding']['OK'] = 2;
52 $msgcode['addPortForwarding']['ERR'] = 100;
53 function addPortForwarding ()
55 assertUIntArg ('object_id');
56 assertIPv4Arg ('localip');
57 assertIPv4Arg ('remoteip');
58 assertUIntArg ('localport');
59 assertStringArg ('proto');
60 assertStringArg ('description', TRUE);
61 $remoteport = isset ($_REQUEST['remoteport']) ?
$_REQUEST['remoteport'] : '';
62 if (!strlen ($remoteport))
63 $remoteport = $_REQUEST['localport'];
65 $error = newPortForwarding
67 $_REQUEST['object_id'],
69 $_REQUEST['localport'],
70 $_REQUEST['remoteip'],
73 $_REQUEST['description']
77 return buildRedirectURL (__FUNCTION__
, 'OK');
79 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
82 $msgcode['delPortForwarding']['OK'] = 3;
83 $msgcode['delPortForwarding']['ERR'] = 111;
84 function delPortForwarding ()
86 assertUIntArg ('object_id');
87 assertIPv4Arg ('localip');
88 assertIPv4Arg ('remoteip');
89 assertUIntArg ('localport');
90 assertUIntArg ('remoteport');
91 assertStringArg ('proto');
93 $result = deletePortForwarding
95 $_REQUEST['object_id'],
97 $_REQUEST['localport'],
98 $_REQUEST['remoteip'],
99 $_REQUEST['remoteport'],
102 buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
105 $msgcode['updPortForwarding']['OK'] = 4;
106 $msgcode['updPortForwarding']['ERR'] = 109;
107 function updPortForwarding ()
109 assertUIntArg ('object_id');
110 assertIPv4Arg ('localip');
111 assertIPv4Arg ('remoteip');
112 assertUIntArg ('localport');
113 assertUIntArg ('remoteport');
114 assertStringArg ('proto');
115 assertStringArg ('description');
117 $result = updatePortForwarding
119 $_REQUEST['object_id'],
120 $_REQUEST['localip'],
121 $_REQUEST['localport'],
122 $_REQUEST['remoteip'],
123 $_REQUEST['remoteport'],
125 $_REQUEST['description']
127 buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
130 $msgcode['addPortForObject']['OK'] = 5;
131 $msgcode['addPortForObject']['ERR1'] = 101;
132 $msgcode['addPortForObject']['ERR2'] = 100;
133 function addPortForObject ()
135 assertUIntArg ('object_id');
136 assertStringArg ('port_name', TRUE);
137 if (!strlen ($_REQUEST['port_name']))
138 return buildRedirectURL (__FUNCTION__
, 'ERR1');
139 $error = commitAddPort
141 $_REQUEST['object_id'],
142 trim ($_REQUEST['port_name']),
143 $_REQUEST['port_type_id'],
144 trim ($_REQUEST['port_label']),
145 trim ($_REQUEST['port_l2address'])
148 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
150 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['port_name']));
153 $msgcode['editPortForObject']['OK'] = 6;
154 $msgcode['editPortForObject']['ERR1'] = 101;
155 $msgcode['editPortForObject']['ERR2'] = 100;
156 function editPortForObject ()
158 assertUIntArg ('object_id');
159 assertUIntArg ('port_id');
160 assertUIntArg ('port_type_id');
161 assertStringArg ('reservation_comment', TRUE);
162 // tolerate empty value now to produce custom informative message later
163 assertStringArg ('name', TRUE);
164 if (!strlen ($_REQUEST['name']))
165 return buildRedirectURL (__FUNCTION__
, 'ERR1');
167 $error = commitUpdatePort ($_REQUEST['object_id'], $_REQUEST['port_id'], $_REQUEST['name'], $_REQUEST['port_type_id'], $_REQUEST['label'], $_REQUEST['l2address'], $_REQUEST['reservation_comment']);
169 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
171 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
174 $msgcode['delPortFromObject']['OK'] = 7;
175 $msgcode['delPortFromObject']['ERR'] = 100;
176 function delPortFromObject ()
178 assertUIntArg ('port_id');
179 $error = delObjectPort ($_REQUEST['port_id']);
182 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
184 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['port_name']));
187 $msgcode['linkPortForObject']['OK'] = 8;
188 $msgcode['linkPortForObject']['ERR'] = 100;
189 function linkPortForObject ()
191 assertUIntArg ('port_id');
192 assertUIntArg ('remote_port_id');
194 // FIXME: ensure, that at least one of these ports belongs to the current object
195 $error = linkPorts ($_REQUEST['port_id'], $_REQUEST['remote_port_id']);
197 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
199 $local_port_info = getPortInfo ($sic['port_id']);
200 $remote_port_info = getPortInfo ($sic['remote_port_id']);
201 $remote_object = spotEntity ('object', $remote_port_info['object_id']);
202 return buildRedirectURL
208 $local_port_info['name'],
209 $remote_port_info['name'],
210 $remote_object['dname'],
215 $msgcode['unlinkPortForObject']['OK'] = 9;
216 $msgcode['unlinkPortForObject']['ERR'] = 100;
217 function unlinkPortForObject ()
219 assertUIntArg ('port_id');
220 assertUIntArg ('remote_port_id');
223 $local_port_info = getPortInfo ($sic['port_id']);
224 $remote_port_info = getPortInfo ($sic['remote_port_id']);
225 $remote_object = spotEntity ('object', $remote_port_info['object_id']);
226 $error = unlinkPort ($_REQUEST['port_id']);
228 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
229 return buildRedirectURL
235 $local_port_info['name'],
236 $remote_port_info['name'],
237 $remote_object['dname'],
242 $msgcode['addMultiPorts']['OK'] = 10;
243 $msgcode['addMultiPorts']['ERR'] = 123;
244 function addMultiPorts ()
246 assertStringArg ('format');
247 assertStringArg ('input');
248 assertStringArg ('port_type');
249 assertUIntArg ('object_id');
250 $format = $_REQUEST['format'];
251 $port_type = $_REQUEST['port_type'];
252 $object_id = $_REQUEST['object_id'];
253 // Input lines are escaped, so we have to explode and to chop by 2-char
254 // \n and \r respectively.
255 $lines1 = explode ("\n", $_REQUEST['input']);
256 foreach ($lines1 as $line)
258 $parts = explode ('\r', $line);
260 if (!strlen ($parts[0]))
263 $lines2[] = rtrim ($parts[0]);
266 foreach ($lines2 as $line)
271 $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', $line));
272 list ($slot, $port) = explode ('/', $words[0]);
275 'name' => "e ${slot}/${port}",
276 'l2address' => $words[8],
277 'label' => "slot ${slot} port ${port}"
281 $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', trim (substr ($line, 3))));
283 How Async Lines are Numbered in Cisco 3600 Series Routers
284 http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00801ca70b.shtml
286 Understanding 16- and 32-Port Async Network Modules
287 http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00800a93f0.shtml
290 $slot = floor (($async - 1) / 32);
291 $octalgroup = floor (($async - 1 - $slot * 32) / 8);
292 $cable = $async - $slot * 32 - $octalgroup * 8;
293 $og_label[0] = 'async 0-7';
294 $og_label[1] = 'async 8-15';
295 $og_label[2] = 'async 16-23';
296 $og_label[3] = 'async 24-31';
299 'name' => "async ${async}",
301 'label' => "slot ${slot} " . $og_label[$octalgroup] . " cable ${cable}"
305 $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', $line));
306 $ifnumber = $words[0] * 1;
309 'name' => "e ${ifnumber}",
310 'l2address' => "${words[8]}",
311 'label' => "${ifnumber}"
315 $words = explode (' ', $line);
316 if (!strlen ($words[0]) or !strlen ($words[1]))
321 'l2address' => $words[1],
326 return buildRedirectURL (__FUNCTION__
, 'ERR');
330 // Create ports, if they don't exist.
331 $added_count = $updated_count = $error_count = 0;
332 foreach ($ports as $port)
334 $port_ids = getPortIDs ($object_id, $port['name']);
335 if (!count ($port_ids))
337 $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
343 elseif (count ($port_ids) == 1) // update only single-socket ports
345 $result = commitUpdatePort ($object_id, $port_ids[0], $port['name'], $port_type, $port['label'], $port['l2address']);
352 return buildRedirectURL (__FUNCTION__
, 'OK', array ($added_count, $updated_count, $error_count));
355 $msgcode['addBulkPorts']['OK'] = 82;
356 function addBulkPorts ()
358 assertUIntArg ('object_id');
359 assertStringArg ('port_type_id');
360 assertStringArg ('port_name');
361 assertStringArg ('port_label', TRUE);
362 assertUIntArg ('port_numbering_start');
363 assertUIntArg ('port_numbering_count');
365 $object_id = $_REQUEST['object_id'];
366 $port_name = $_REQUEST['port_name'];
367 $port_type_id = $_REQUEST['port_type_id'];
368 $port_label = $_REQUEST['port_label'];
369 $port_numbering_start = $_REQUEST['port_numbering_start'];
370 $port_numbering_count = $_REQUEST['port_numbering_count'];
372 $added_count = $error_count = 0;
373 if(strrpos($port_name, "%u") === false )
375 for ($i=0,$c=$port_numbering_start; $i<$port_numbering_count; $i++
,$c++
)
377 $result = commitAddPort ($object_id, @sprintf
($port_name,$c), $port_type_id, @sprintf
($port_label,$c), '');
383 return buildRedirectURL (__FUNCTION__
, 'OK', array ($added_count, $error_count));
386 $msgcode['updIPv4Allocation']['OK'] = 12;
387 $msgcode['updIPv4Allocation']['ERR'] = 109;
388 function updIPv4Allocation ()
390 assertIPv4Arg ('ip');
391 assertUIntArg ('object_id');
392 assertStringArg ('bond_name', TRUE);
393 assertStringArg ('bond_type');
395 $result = updateBond ($_REQUEST['ip'], $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
396 return buildRedirectURL (__FUNCTION__
, $result === FALSE ?
'ERR' : 'OK');
399 $msgcode['updIPv6Allocation']['OK'] = 12;
400 $msgcode['updIv6PAllocation']['ERR'] = 109;
401 function updIPv6Allocation ()
403 $ipv6 = assertIPv6Arg ('ip');
404 assertUIntArg ('object_id');
405 assertStringArg ('bond_name', TRUE);
406 assertStringArg ('bond_type');
408 $result = updateIPv6Bond ($ipv6, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
409 return buildRedirectURL (__FUNCTION__
, $result === FALSE ?
'ERR' : 'OK');
412 $msgcode['delIPv4Allocation']['OK'] = 14;
413 $msgcode['delIPv4Allocation']['ERR'] = 111;
414 function delIPv4Allocation ()
416 assertIPv4Arg ('ip');
417 assertUIntArg ('object_id');
419 $result = unbindIpFromObject ($_REQUEST['ip'], $_REQUEST['object_id']);
420 return buildRedirectURL (__FUNCTION__
, $result === FALSE ?
'ERR' : 'OK');
423 $msgcode['delIPv6Allocation']['OK'] = 14;
424 $msgcode['delIPv6Allocation']['ERR'] = 111;
425 function delIPv6Allocation ()
427 assertUIntArg ('object_id');
428 $ipv6 = assertIPv6Arg ('ip');
429 $result = unbindIPv6FromObject ($ipv6, $_REQUEST['object_id']);
430 return buildRedirectURL (__FUNCTION__
, $result === FALSE ?
'ERR' : 'OK');
433 $msgcode['addIPv4Allocation']['OK'] = 13;
434 $msgcode['addIPv4Allocation']['ERR1'] = 170;
435 $msgcode['addIPv4Allocation']['ERR2'] = 100;
436 function addIPv4Allocation ()
438 assertIPv4Arg ('ip');
439 assertUIntArg ('object_id');
440 assertStringArg ('bond_name', TRUE);
441 assertStringArg ('bond_type');
444 $ip = preg_replace ('@/[[:digit:]]+$@', '', $_REQUEST['ip']);
445 if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv4AddressNetworkId ($ip))
446 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($ip));
448 if (FALSE === bindIpToObject ($ip, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']))
449 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
450 $address = getIPv4Address ($ip);
451 if ($address['reserved'] == 'yes' or strlen ($address['name']))
453 $release = getConfigVar ('IPV4_AUTO_RELEASE');
455 $address['reserved'] = 'no';
457 $address['name'] = '';
458 updateAddress ($ip, $address['name'], $address['reserved']);
460 return buildRedirectURL (__FUNCTION__
, 'OK');
463 $msgcode['addIPv6Allocation']['OK'] = 13;
464 $msgcode['addIPv6Allocation']['ERR1'] = 170;
465 $msgcode['addIPv6Allocation']['ERR2'] = 100;
466 function addIPv6Allocation ()
468 assertUIntArg ('object_id');
469 assertStringArg ('bond_name', TRUE);
470 assertStringArg ('bond_type');
473 $ipv6 = new IPv6Address
;
474 if (! $ipv6->parse (preg_replace ('@/\d+$@', '', $_REQUEST['ip'])))
475 throw new InvalidRequestArgException('ip', $_REQUEST['ip'], 'parameter is not a valid ipv6 address');
477 if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv6AddressNetworkId ($ipv6))
478 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($ip));
480 if (FALSE === bindIPv6ToObject ($ipv6, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']))
481 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
482 $address = getIPv6Address ($ipv6);
483 if ($address['reserved'] == 'yes' or strlen ($address['name']))
485 $release = getConfigVar ('IPV4_AUTO_RELEASE');
487 $address['reserved'] = 'no';
489 $address['name'] = '';
490 updateAddress ($ipv6, $address['name'], $address['reserved']);
492 return buildRedirectURL (__FUNCTION__
, 'OK');
495 $msgcode['addIPv4Prefix']['OK'] = 23;
496 $msgcode['addIPv4Prefix']['ERR'] = 100;
497 $msgcode['addIPv4Prefix']['ERR1'] = 173;
498 $msgcode['addIPv4Prefix']['ERR2'] = 174;
499 $msgcode['addIPv4Prefix']['ERR3'] = 175;
500 $msgcode['addIPv4Prefix']['ERR4'] = 176;
501 function addIPv4Prefix ()
503 assertStringArg ('range');
504 assertStringArg ('name', TRUE);
506 $is_bcast = isset ($_REQUEST['is_bcast']) ?
$_REQUEST['is_bcast'] : 'off';
507 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
509 $error = createIPv4Prefix ($_REQUEST['range'], $sic['name'], $is_bcast == 'on', $taglist);
511 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
513 return buildRedirectURL (__FUNCTION__
, 'OK');
516 $msgcode['addIPv6Prefix']['OK'] = 86;
517 $msgcode['addIPv6Prefix']['ERR'] = 100;
518 $msgcode['addIPv6Prefix']['ERR1'] = 173;
519 $msgcode['addIPv6Prefix']['ERR2'] = 174;
520 $msgcode['addIPv6Prefix']['ERR3'] = 175;
521 $msgcode['addIPv6Prefix']['ERR4'] = 176;
522 function addIPv6Prefix ()
524 assertStringArg ('range');
525 assertStringArg ('name', TRUE);
527 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
529 $error = createIPv6Prefix ($_REQUEST['range'], $sic['name'], $taglist);
531 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
533 return buildRedirectURL (__FUNCTION__
, 'OK');
536 $msgcode['delIPv4Prefix']['OK'] = 24;
537 $msgcode['delIPv4Prefix']['ERR'] = 100;
538 function delIPv4Prefix ()
540 assertUIntArg ('id');
541 $error = destroyIPv4Prefix ($_REQUEST['id']);
543 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
545 return buildRedirectURL (__FUNCTION__
, 'OK');
548 $msgcode['delIPv6Prefix']['OK'] = 85;
549 $msgcode['delIPv6Prefix']['ERR'] = 100;
550 function delIPv6Prefix ()
552 assertUIntArg ('id');
553 $error = destroyIPv6Prefix ($_REQUEST['id']);
555 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
557 return buildRedirectURL (__FUNCTION__
, 'OK');
560 $msgcode['updIPv4Prefix']['OK'] = 25;
561 $msgcode['updIPv4Prefix']['ERR'] = 109;
562 function updIPv4Prefix ()
564 assertUIntArg ('id');
565 assertStringArg ('name', TRUE);
566 assertStringArg ('comment', TRUE);
568 $result = updateIPv4Network_real ($sic['id'], $sic['name'], $sic['comment']);
569 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
572 $msgcode['updIPv6Prefix']['OK'] = 86;
573 $msgcode['updIPv6Prefix']['ERR'] = 109;
574 function updIPv6Prefix ()
576 assertUIntArg ('id');
577 assertStringArg ('name', TRUE);
578 assertStringArg ('comment', TRUE);
580 $result = updateIPv6Network_real ($sic['id'], $sic['name'], $sic['comment']);
581 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
584 $msgcode['editAddress']['OK'] = 27;
585 $msgcode['editAddress']['ERR'] = 100;
586 function editAddress ()
588 assertIPv4Arg ('ip');
589 assertStringArg ('name', TRUE);
591 if (isset ($_REQUEST['reserved']))
592 $reserved = $_REQUEST['reserved'];
595 $error = updateAddress ($_REQUEST['ip'], $_REQUEST['name'], $reserved == 'on' ?
'yes' : 'no');
597 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
599 return buildRedirectURL (__FUNCTION__
, 'OK');
602 $msgcode['editv6Address']['OK'] = 27;
603 $msgcode['editv6Address']['ERR'] = 100;
604 function editv6Address ()
606 $ipv6 = assertIPArg ('ip');
607 assertStringArg ('name', TRUE);
609 if (isset ($_REQUEST['reserved']))
610 $reserved = $_REQUEST['reserved'];
613 $error = updateAddress ($ipv6, $_REQUEST['name'], $reserved == 'on' ?
'yes' : 'no');
615 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
617 return buildRedirectURL (__FUNCTION__
, 'OK');
620 $msgcode['createUser']['OK'] = 40;
621 $msgcode['createUser']['ERR'] = 102;
622 function createUser ()
624 assertStringArg ('username');
625 assertStringArg ('realname', TRUE);
626 assertStringArg ('password');
627 $username = $_REQUEST['username'];
628 $password = sha1 ($_REQUEST['password']);
629 $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password);
631 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($username));
632 if (isset ($_REQUEST['taglist']))
633 produceTagsForLastRecord ('user', $_REQUEST['taglist']);
634 return buildRedirectURL (__FUNCTION__
, 'OK', array ($username));
637 $msgcode['updateUser']['OK'] = 39;
638 $msgcode['updateUser']['ERR1'] = 103;
639 $msgcode['updateUser']['ERR1'] = 104;
640 function updateUser ()
642 assertUIntArg ('user_id');
643 assertStringArg ('username');
644 assertStringArg ('realname', TRUE);
645 assertStringArg ('password');
646 $username = $_REQUEST['username'];
647 $new_password = $_REQUEST['password'];
648 if (NULL == ($userinfo = spotEntity ('user', $_REQUEST['user_id'])))
649 return buildRedirectURL (__FUNCTION__
, 'ERR1');
650 // Update user password only if provided password is not the same as current password hash.
651 if ($new_password != $userinfo['user_password_hash'])
652 $new_password = sha1 ($new_password);
653 $result = commitUpdateUserAccount ($_REQUEST['user_id'], $username, $_REQUEST['realname'], $new_password);
654 if ($result !== FALSE)
655 return buildRedirectURL (__FUNCTION__
, 'OK', array ($username));
657 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($username));
660 $msgcode['updateDictionary']['OK'] = 51;
661 $msgcode['updateDictionary']['ERR'] = 109;
662 function updateDictionary ()
664 assertUIntArg ('chapter_no');
665 assertUIntArg ('dict_key');
666 assertStringArg ('dict_value');
667 if (FALSE !== commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value']))
668 return buildRedirectURL (__FUNCTION__
, 'OK');
670 return buildRedirectURL (__FUNCTION__
, 'ERR');
673 $msgcode['supplementDictionary']['OK'] = 52;
674 $msgcode['supplementDictionary']['ERR'] = 110;
675 function supplementDictionary ()
677 assertUIntArg ('chapter_no');
678 assertStringArg ('dict_value');
679 if (commitSupplementDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_value']) === TRUE)
680 return buildRedirectURL (__FUNCTION__
, 'OK');
682 return buildRedirectURL (__FUNCTION__
, 'ERR');
685 $msgcode['reduceDictionary']['OK'] = 50;
686 $msgcode['reduceDictionary']['ERR'] = 111;
687 function reduceDictionary ()
689 assertUIntArg ('chapter_no');
690 assertUIntArg ('dict_key');
691 if (commitReduceDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key']) === TRUE)
692 return buildRedirectURL (__FUNCTION__
, 'OK');
694 return buildRedirectURL (__FUNCTION__
, 'ERR');
697 $msgcode['addChapter']['OK'] = 55;
698 $msgcode['addChapter']['ERR'] = 112;
699 function addChapter ()
701 assertStringArg ('chapter_name');
702 if (commitAddChapter ($_REQUEST['chapter_name']) === TRUE)
703 return buildRedirectURL (__FUNCTION__
, 'OK');
705 return buildRedirectURL (__FUNCTION__
, 'ERR');
708 $msgcode['updateChapter']['OK'] = 54;
709 $msgcode['updateChapter']['ERR'] = 113;
710 function updateChapter ()
712 assertUIntArg ('chapter_no');
713 assertStringArg ('chapter_name');
714 if (FALSE !== commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name']))
715 return buildRedirectURL (__FUNCTION__
, 'OK');
717 return buildRedirectURL (__FUNCTION__
, 'ERR');
720 $msgcode['delChapter']['OK'] = 53;
721 $msgcode['delChapter']['ERR'] = 114;
722 function delChapter ()
724 assertUIntArg ('chapter_no');
725 if (commitDeleteChapter ($_REQUEST['chapter_no']))
726 return buildRedirectURL (__FUNCTION__
, 'OK');
728 return buildRedirectURL (__FUNCTION__
, 'ERR');
731 $msgcode['changeAttribute']['OK'] = 46;
732 $msgcode['changeAttribute']['ERR'] = 115;
733 function changeAttribute ()
735 assertUIntArg ('attr_id');
736 assertStringArg ('attr_name');
737 if (FALSE !== commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name']))
738 return buildRedirectURL (__FUNCTION__
, 'OK');
740 return buildRedirectURL (__FUNCTION__
, 'ERR');
743 $msgcode['createAttribute']['OK'] = 45;
744 $msgcode['createAttribute']['ERR'] = 116;
745 function createAttribute ()
747 assertStringArg ('attr_name');
748 assertStringArg ('attr_type');
749 if (commitAddAttribute ($_REQUEST['attr_name'], $_REQUEST['attr_type']))
750 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['attr_name']));
752 return buildRedirectURL (__FUNCTION__
, 'ERR');
755 $msgcode['deleteAttribute']['OK'] = 47;
756 $msgcode['deleteAttribute']['ERR'] = 117;
757 function deleteAttribute ()
759 assertUIntArg ('attr_id');
760 if (commitDeleteAttribute ($_REQUEST['attr_id']))
761 return buildRedirectURL (__FUNCTION__
, 'OK');
763 return buildRedirectURL (__FUNCTION__
, 'ERR');
766 $msgcode['supplementAttrMap']['OK'] = 48;
767 $msgcode['supplementAttrMap']['ERR1'] = 154;
768 $msgcode['supplementAttrMap']['ERR2'] = 118;
769 function supplementAttrMap ()
771 assertUIntArg ('attr_id');
772 assertUIntArg ('objtype_id');
773 $attrMap = getAttrMap();
774 if ($attrMap[$_REQUEST['attr_id']]['type'] != 'dict')
780 assertUIntArg ('chapter_no');
782 catch (InvalidRequestArgException
$e)
784 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ('chapter not selected'));
786 $chapter_id = $_REQUEST['chapter_no'];
788 if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $chapter_id) !== FALSE)
789 return buildRedirectURL (__FUNCTION__
, 'OK');
791 return buildRedirectURL (__FUNCTION__
, 'ERR2');
794 $msgcode['reduceAttrMap']['OK'] = 49;
795 $msgcode['reduceAttrMap']['ERR'] = 119;
796 function reduceAttrMap ()
798 assertUIntArg ('attr_id');
799 assertUIntArg ('objtype_id');
800 if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) !== FALSE)
801 return buildRedirectURL (__FUNCTION__
, 'OK');
803 return buildRedirectURL (__FUNCTION__
, 'ERR');
806 $msgcode['clearSticker']['OK'] = 15;
807 $msgcode['clearSticker']['ERR'] = 120;
808 function clearSticker ()
810 assertUIntArg ('attr_id');
811 assertUIntArg ('object_id');
812 if (commitResetAttrValue ($_REQUEST['object_id'], $_REQUEST['attr_id']) !== FALSE)
813 return buildRedirectURL (__FUNCTION__
, 'OK');
815 return buildRedirectURL (__FUNCTION__
, 'ERR');
818 $msgcode['updateObjectAllocation']['OK'] = 63;
819 function updateObjectAllocation ()
821 assertUIntArg ('object_id');
823 if (!isset ($_REQUEST['got_atoms']))
825 unset($_GET['page']);
828 unset($_POST['page']);
829 unset($_POST['tab']);
831 return buildWideRedirectURL (array(), NULL, NULL, array_merge ($_GET, $_POST));
833 $object_id = $_REQUEST['object_id'];
834 $workingRacksData = array();
835 foreach ($_REQUEST['rackmulti'] as $cand_id)
837 if (!isset ($workingRacksData[$cand_id]))
839 $rackData = spotEntity ('rack', $cand_id);
840 amplifyCell ($rackData);
841 $workingRacksData[$cand_id] = $rackData;
845 foreach ($workingRacksData as &$rd)
846 applyObjectMountMask ($rd, $object_id);
848 $oldMolecule = getMoleculeForObject ($object_id);
851 foreach ($workingRacksData as $rack_id => $rackData)
853 $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
855 if ($logrecord['code'] == 300)
858 // Reload our working copy after form processing.
859 $rackData = spotEntity ('rack', $cand_id);
860 amplifyCell ($rackData);
861 applyObjectMountMask ($rackData, $object_id);
862 $workingRacksData[$rack_id] = $rackData;
865 return buildRedirectURL (__FUNCTION__
, 'OK', $changecnt);
867 $newMolecule = getMoleculeForObject ($object_id);
868 $oc = count ($oldMolecule);
869 $nc = count ($newMolecule);
870 $omid = $oc ?
createMolecule ($oldMolecule) : 'NULL';
871 $nmid = $nc ?
createMolecule ($newMolecule) : 'NULL';
872 global $remote_username;
873 $comment = empty ($_REQUEST['comment']) ?
'NULL' : "'${_REQUEST['comment']}'";
875 "insert into MountOperation(object_id, old_molecule_id, new_molecule_id, user_name, comment) " .
876 "values (${object_id}, ${omid}, ${nmid}, '${remote_username}', ${comment})";
878 $result = $dbxlink->query ($query);
880 $log[] = array ('code' => 500, 'message' => 'SQL query failed during history logging.');
882 $log[] = array ('code' => 200, 'message' => 'History logged.');
883 return buildWideRedirectURL ($log);
886 $msgcode['updateObject']['OK'] = 16;
887 $msgcode['updateObject']['ERR'] = 121;
888 function updateObject ()
890 assertUIntArg ('num_attrs', TRUE);
891 assertUIntArg ('object_id');
892 assertUIntArg ('object_type_id');
893 assertStringArg ('object_name', TRUE);
894 assertStringArg ('object_label', TRUE);
895 assertStringArg ('object_barcode', TRUE);
896 assertStringArg ('object_asset_no', TRUE);
897 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
898 $has_problems = 'yes';
900 $has_problems = 'no';
902 if (commitUpdateObject (
903 $_REQUEST['object_id'],
904 $_REQUEST['object_name'],
905 $_REQUEST['object_label'],
906 $_REQUEST['object_barcode'],
907 $_REQUEST['object_type_id'],
909 $_REQUEST['object_asset_no'],
910 $_REQUEST['object_comment']
912 return buildRedirectURL (__FUNCTION__
, 'ERR');
914 // Update optional attributes
915 $oldvalues = getAttrValues ($_REQUEST['object_id']);
917 $num_attrs = isset ($_REQUEST['num_attrs']) ?
$_REQUEST['num_attrs'] : 0;
918 for ($i = 0; $i < $num_attrs; $i++
)
920 assertUIntArg ("${i}_attr_id");
921 $attr_id = $_REQUEST["${i}_attr_id"];
923 // 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
924 if (!strlen ($_REQUEST["${i}_value"]) ||
($oldvalues[$attr_id]['type']=='dict' && $_REQUEST["${i}_value"] == 0))
926 commitResetAttrValue ($_REQUEST['object_id'], $attr_id);
930 // The value could be uint/float, but we don't know ATM. Let SQL
931 // server check this and complain.
932 assertStringArg ("${i}_value");
933 $value = $_REQUEST["${i}_value"];
934 switch ($oldvalues[$attr_id]['type'])
939 $oldvalue = $oldvalues[$attr_id]['value'];
942 $oldvalue = $oldvalues[$attr_id]['key'];
946 if ($value === $oldvalue) // ('' == 0), but ('' !== 0)
949 // Note if the queries succeed or not, it determines which page they see.
950 $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value);
952 if (in_array (FALSE, $result))
953 return buildRedirectURL (__FUNCTION__
, 'ERR');
955 // Invalidate thumb cache of all racks objects could occupy.
956 foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id)
957 resetThumbCache ($rack_id);
959 return buildRedirectURL (__FUNCTION__
, 'OK');
963 function addMultipleObjects()
966 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
967 $max = getConfigVar ('MASSCOUNT');
968 for ($i = 0; $i < $max; $i++
)
970 if (!isset ($_REQUEST["${i}_object_type_id"]))
972 $log = mergeLogs ($log, oneLiner (184, array ($i +
1)));
975 assertUIntArg ("${i}_object_type_id", TRUE);
976 assertStringArg ("${i}_object_name", TRUE);
977 assertStringArg ("${i}_object_label", TRUE);
978 assertStringArg ("${i}_object_asset_no", TRUE);
979 assertStringArg ("${i}_object_barcode", TRUE);
980 $name = $_REQUEST["${i}_object_name"];
982 // It's better to skip silently, than to print a notice.
983 if ($_REQUEST["${i}_object_type_id"] == 0)
985 if (($object_id = commitAddObject
988 $_REQUEST["${i}_object_label"],
989 $_REQUEST["${i}_object_barcode"],
990 $_REQUEST["${i}_object_type_id"],
991 $_REQUEST["${i}_object_asset_no"],
994 $info = spotEntity ('object', $object_id);
995 // FIXME: employ amplifyCell() instead of calling loader functions directly
997 $log = mergeLogs ($log, oneLiner (80, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>')));
999 $log = mergeLogs ($log, oneLiner (185, array ($name)));
1002 return buildWideRedirectURL ($log);
1005 function addLotOfObjects()
1008 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1009 assertUIntArg ('global_type_id', TRUE);
1010 assertStringArg ('namelist', TRUE);
1011 $global_type_id = $_REQUEST['global_type_id'];
1012 if ($global_type_id == 0 or !strlen ($_REQUEST['namelist']))
1013 $log = mergeLogs ($log, oneLiner (186));
1016 // The name extractor below was stolen from ophandlers.php:addMultiPorts()
1017 $names1 = explode ("\n", $_REQUEST['namelist']);
1019 foreach ($names1 as $line)
1021 $parts = explode ('\r', $line);
1023 if (!strlen ($parts[0]))
1026 $names2[] = rtrim ($parts[0]);
1028 foreach ($names2 as $name)
1029 if (($object_id = commitAddObject ($name, '', '', $global_type_id, '', $taglist)) !== FALSE)
1031 $info = spotEntity ('object', $object_id);
1032 amplifyCell ($info);
1033 $log = mergeLogs ($log, oneLiner (80, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>')));
1036 $log = mergeLogs ($log, oneLiner (185, array ($name)));
1038 return buildWideRedirectURL ($log);
1041 $msgcode['deleteObject']['OK'] = 76;
1042 function deleteObject ()
1044 assertUIntArg ('object_id');
1045 $oinfo = spotEntity ('object', $_REQUEST['object_id']);
1047 $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE);
1048 commitDeleteObject ($_REQUEST['object_id']);
1049 foreach ($racklist as $rack_id)
1050 resetThumbCache ($rack_id);
1051 return buildRedirectURL (__FUNCTION__
, 'OK', array ($oinfo['dname']));
1054 $msgcode['resetObject']['OK'] = 83;
1055 $msgcode['resetObject']['ERR'] = 100;
1056 function resetObject ()
1058 assertUIntArg ('object_id');
1059 $oinfo = spotEntity ('object', $_REQUEST['object_id']);
1061 $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE);
1062 commitResetObject ($_REQUEST['object_id']);
1063 foreach ($racklist as $rack_id)
1064 resetThumbCache ($rack_id);
1065 return buildRedirectURL (__FUNCTION__
, 'OK', array ($oinfo['dname']));
1068 $msgcode['useupPort']['OK'] = 11;
1069 $msgcode['useupPort']['ERR'] = 124;
1070 function useupPort ()
1072 assertUIntArg ('port_id');
1073 if (FALSE !== commitUseupPort ($_REQUEST['port_id']))
1074 return buildRedirectURL (__FUNCTION__
, 'OK');
1076 return buildRedirectURL (__FUNCTION__
, 'ERR');
1079 $msgcode['updateUI']['OK'] = 56;
1080 function updateUI ()
1082 assertUIntArg ('num_vars');
1084 for ($i = 0; $i < $_REQUEST['num_vars']; $i++
)
1086 assertStringArg ("${i}_varname");
1087 assertStringArg ("${i}_varvalue", TRUE);
1088 $varname = $_REQUEST["${i}_varname"];
1089 $varvalue = $_REQUEST["${i}_varvalue"];
1091 // If form value = value in DB, don't bother updating DB
1092 if (!isConfigVarChanged($varname, $varvalue))
1094 // any exceptions will be handled by process.php
1095 setConfigVar ($varname, $varvalue, TRUE);
1097 return buildRedirectURL (__FUNCTION__
, 'OK');
1100 $msgcode['saveMyPreferences']['OK'] = 56;
1101 function saveMyPreferences ()
1103 assertUIntArg ('num_vars');
1105 for ($i = 0; $i < $_REQUEST['num_vars']; $i++
)
1107 assertStringArg ("${i}_varname");
1108 assertStringArg ("${i}_varvalue", TRUE);
1109 $varname = $_REQUEST["${i}_varname"];
1110 $varvalue = $_REQUEST["${i}_varvalue"];
1112 // If form value = value in DB, don't bother updating DB
1113 if (!isConfigVarChanged($varname, $varvalue))
1115 setUserConfigVar ($varname, $varvalue);
1117 return buildRedirectURL (__FUNCTION__
, 'OK');
1120 $msgcode['resetMyPreference']['OK'] = 56;
1121 function resetMyPreference ()
1123 assertStringArg ("varname");
1124 resetUserConfigVar ($_REQUEST["varname"]);
1125 return buildRedirectURL (__FUNCTION__
, 'OK');
1128 $msgcode['resetUIConfig']['OK'] = 57;
1129 function resetUIConfig()
1131 setConfigVar ('MASSCOUNT','15');
1132 setConfigVar ('MAXSELSIZE','30');
1133 setConfigVar ('ROW_SCALE','2');
1134 setConfigVar ('PORTS_PER_ROW','12');
1135 setConfigVar ('IPV4_ADDRS_PER_PAGE','256');
1136 setConfigVar ('DEFAULT_RACK_HEIGHT','42');
1137 setConfigVar ('DEFAULT_SLB_VS_PORT','');
1138 setConfigVar ('DEFAULT_SLB_RS_PORT','');
1139 setConfigVar ('DETECT_URLS','no');
1140 setConfigVar ('RACK_PRESELECT_THRESHOLD','1');
1141 setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no');
1142 setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm');
1143 setConfigVar ('SHOW_EXPLICIT_TAGS','yes');
1144 setConfigVar ('SHOW_IMPLICIT_TAGS','yes');
1145 setConfigVar ('SHOW_AUTOMATIC_TAGS','no');
1146 setConfigVar ('DEFAULT_OBJECT_TYPE','4');
1147 setConfigVar ('IPV4_AUTO_RELEASE','1');
1148 setConfigVar ('SHOW_LAST_TAB', 'no');
1149 setConfigVar ('EXT_IPV4_VIEW', 'yes');
1150 setConfigVar ('TREE_THRESHOLD', '25');
1151 setConfigVar ('IPV4_JAYWALK', 'no');
1152 setConfigVar ('ADDNEW_AT_TOP', 'yes');
1153 setConfigVar ('IPV4_TREE_SHOW_USAGE', 'yes');
1154 setConfigVar ('PREVIEW_TEXT_MAXCHARS', '10240');
1155 setConfigVar ('PREVIEW_TEXT_ROWS', '25');
1156 setConfigVar ('PREVIEW_TEXT_COLS', '80');
1157 setConfigVar ('PREVIEW_IMAGE_MAXPXS', '320');
1158 setConfigVar ('VENDOR_SIEVE', '');
1159 setConfigVar ('IPV4LB_LISTSRC', '{$typeid_4}');
1160 setConfigVar ('IPV4OBJ_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_12} or {$typeid_445} or {$typeid_447} or {$typeid_798}');
1161 setConfigVar ('IPV4NAT_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_798}');
1162 setConfigVar ('ASSETWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1163 setConfigVar ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1164 setConfigVar ('RACKS_PER_ROW','12');
1165 setConfigVar ('FILTER_PREDICATE_SIEVE','');
1166 setConfigVar ('FILTER_DEFAULT_ANDOR','or');
1167 setConfigVar ('FILTER_SUGGEST_ANDOR','yes');
1168 setConfigVar ('FILTER_SUGGEST_TAGS','yes');
1169 setConfigVar ('FILTER_SUGGEST_PREDICATES','yes');
1170 setConfigVar ('FILTER_SUGGEST_EXTRA','no');
1171 setConfigVar ('DEFAULT_SNMP_COMMUNITY','public');
1172 setConfigVar ('IPV4_ENABLE_KNIGHT','yes');
1173 setConfigVar ('TAGS_TOPLIST_SIZE','50');
1174 setConfigVar ('TAGS_QUICKLIST_SIZE','20');
1175 setConfigVar ('TAGS_QUICKLIST_THRESHOLD','50');
1176 setConfigVar ('ENABLE_MULTIPORT_FORM', 'no');
1177 setConfigVar ('DEFAULT_PORT_IIF_ID', '1');
1178 setConfigVar ('DEFAULT_PORT_OIF_IDS', '1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084');
1179 setConfigVar ('IPV4_TREE_RTR_AS_CELL', 'yes');
1180 setConfigVar ('PROXIMITY_RANGE', 0);
1181 setConfigVar ('IPV4_TREE_SHOW_VLAN', 'yes');
1182 setConfigVar ('VLANSWITCH_LISTSRC', '');
1183 setConfigVar ('VLANIPV4NET_LISTSRC', '');
1184 setConfigVar ('DEFAULT_VDOM_ID', '');
1185 setConfigVar ('DEFAULT_VST_ID', '');
1186 setConfigVar ('STATIC_FILTER', 'yes');
1187 setConfigVar ('8021Q_DEPLOY_MINAGE', '300');
1188 setConfigVar ('8021Q_DEPLOY_MAXAGE', '3600');
1189 setConfigVar ('8021Q_DEPLOY_RETRY', '10800');
1190 setConfigVar ('8021Q_WRI_AFTER_CONFT_LISTSRC', 'false');
1191 setConfigVar ('8021Q_INSTANT_DEPLOY', 'no');
1192 setConfigVar ('CDP_RUNNERS_LISTSRC', '');
1193 setConfigVar ('LLDP_RUNNERS_LISTSRC', '');
1194 setConfigVar ('HNDP_RUNNERS_LISTSRC', '');
1195 setConfigVar ('SHRINK_TAG_TREE_ON_CLICK', 'yes');
1196 setConfigVar ('MAX_UNFILTERED_ENTITIES', '0');
1197 return buildRedirectURL (__FUNCTION__
, 'OK');
1200 $msgcode['addRealServer']['OK'] = 34;
1201 $msgcode['addRealServer']['ERR'] = 126;
1202 // Add single record.
1203 function addRealServer ()
1205 assertUIntArg ('pool_id');
1206 assertIPv4Arg ('remoteip');
1207 assertStringArg ('rsport', TRUE);
1208 assertStringArg ('rsconfig', TRUE);
1209 if (!addRStoRSPool (
1210 $_REQUEST['pool_id'],
1211 $_REQUEST['remoteip'],
1212 $_REQUEST['rsport'],
1213 getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'),
1214 $_REQUEST['rsconfig']
1216 return buildRedirectURL (__FUNCTION__
, 'ERR');
1218 return buildRedirectURL (__FUNCTION__
, 'OK');
1221 $msgcode['addRealServers']['OK'] = 37;
1222 $msgcode['addRealServers']['ERR1'] = 131;
1223 $msgcode['addRealServers']['ERR2'] = 127;
1224 // Parse textarea submitted and try adding a real server for each line.
1225 function addRealServers ()
1227 assertUIntArg ('pool_id');
1228 assertStringArg ('format');
1229 assertStringArg ('rawtext');
1232 // Keep in mind, that the text will have HTML entities (namely '>') escaped.
1233 foreach (explode ("\n", dos2unix ($_REQUEST['rawtext'])) as $line)
1235 if (!strlen ($line))
1238 switch ($_REQUEST['format'])
1240 case 'ipvs_2': // address and port only
1241 if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) /', $line, $match))
1243 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1248 case 'ipvs_3': // address, port and weight
1249 if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match))
1251 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3]))
1256 case 'ssv_2': // IP address and port
1257 if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match))
1259 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1264 case 'ssv_1': // IP address
1265 if (!preg_match ('/^([0-9\.]+)$/', $line, $match))
1267 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1273 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1277 if ($nbad == 0 and $ngood > 0)
1278 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1280 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($ngood, $nbad));
1283 $msgcode['addVService']['OK'] = 28;
1284 $msgcode['addVService']['ERR1'] = 132;
1285 $msgcode['addVService']['ERR2'] = 100;
1286 function addVService ()
1288 assertIPv4Arg ('vip');
1289 assertUIntArg ('vport');
1290 assertStringArg ('proto');
1291 if ($_REQUEST['proto'] != 'TCP' and $_REQUEST['proto'] != 'UDP')
1292 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1293 assertStringArg ('name', TRUE);
1294 assertStringArg ('vsconfig', TRUE);
1295 assertStringArg ('rsconfig', TRUE);
1296 $error = commitCreateVS
1302 $_REQUEST['vsconfig'],
1303 $_REQUEST['rsconfig'],
1304 isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array()
1307 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
1309 return buildRedirectURL (__FUNCTION__
, 'OK');
1312 $msgcode['deleteRealServer']['OK'] = 35;
1313 $msgcode['deleteRealServer']['ERR'] = 128;
1314 function deleteRealServer ()
1316 assertUIntArg ('id');
1317 if (!commitDeleteRS ($_REQUEST['id']))
1318 return buildRedirectURL (__FUNCTION__
, 'ERR');
1320 return buildRedirectURL (__FUNCTION__
, 'OK');
1323 $msgcode['deleteLoadBalancer']['OK'] = 19;
1324 $msgcode['deleteLoadBalancer']['ERR'] = 129;
1325 function deleteLoadBalancer ()
1327 assertUIntArg ('object_id');
1328 assertUIntArg ('pool_id');
1329 assertUIntArg ('vs_id');
1330 if (!commitDeleteLB (
1331 $_REQUEST['object_id'],
1332 $_REQUEST['pool_id'],
1335 return buildRedirectURL (__FUNCTION__
, 'ERR');
1337 return buildRedirectURL (__FUNCTION__
, 'OK');
1340 $msgcode['deleteVService']['OK'] = 29;
1341 $msgcode['deleteVService']['ERR'] = 130;
1342 function deleteVService ()
1344 assertUIntArg ('vs_id');
1345 if (!commitDeleteVS ($_REQUEST['vs_id']))
1346 return buildRedirectURL (__FUNCTION__
, 'ERR');
1348 return buildRedirectURL (__FUNCTION__
, 'OK');
1351 $msgcode['updateSLBDefConfig']['OK'] = 43;
1352 $msgcode['updateSLBDefConfig']['ERR'] = 109;
1353 function updateSLBDefConfig ()
1356 'vs' => $_REQUEST['vsconfig'],
1357 'rs' => $_REQUEST['rsconfig']
1359 if (!commitUpdateSLBDefConf ($data))
1360 return buildRedirectURL (__FUNCTION__
, 'ERR');
1362 return buildRedirectURL (__FUNCTION__
, 'OK');
1365 $msgcode['updateRealServer']['OK'] = 36;
1366 $msgcode['updateRealServer']['ERR'] = 133;
1367 function updateRealServer ()
1369 assertUIntArg ('rs_id');
1370 assertIPv4Arg ('rsip');
1371 assertStringArg ('rsport', TRUE);
1372 assertStringArg ('rsconfig', TRUE);
1373 if (FALSE === commitUpdateRS (
1376 $_REQUEST['rsport'],
1377 $_REQUEST['rsconfig']
1379 return buildRedirectURL (__FUNCTION__
, 'ERR');
1381 return buildRedirectURL (__FUNCTION__
, 'OK');
1384 $msgcode['updateLoadBalancer']['OK'] = 20;
1385 $msgcode['updateLoadBalancer']['ERR'] = 134;
1386 function updateLoadBalancer ()
1388 assertUIntArg ('object_id');
1389 assertUIntArg ('pool_id');
1390 assertUIntArg ('vs_id');
1391 assertStringArg ('vsconfig', TRUE);
1392 assertStringArg ('rsconfig', TRUE);
1393 if (! empty($_REQUEST['prio']))
1394 assertUIntArg('prio', TRUE);
1396 if (FALSE === commitUpdateLB (
1397 $_REQUEST['object_id'],
1398 $_REQUEST['pool_id'],
1400 $_REQUEST['vsconfig'],
1401 $_REQUEST['rsconfig'],
1404 return buildRedirectURL (__FUNCTION__
, 'ERR');
1406 return buildRedirectURL (__FUNCTION__
, 'OK');
1409 $msgcode['updateVService']['OK'] = 30;
1410 $msgcode['updateVService']['ERR'] = 135;
1411 function updateVService ()
1413 assertUIntArg ('vs_id');
1414 assertIPv4Arg ('vip');
1415 assertUIntArg ('vport');
1416 assertStringArg ('proto');
1417 assertStringArg ('name', TRUE);
1418 assertStringArg ('vsconfig', TRUE);
1419 assertStringArg ('rsconfig', TRUE);
1420 if (FALSE === commitUpdateVS (
1426 $_REQUEST['vsconfig'],
1427 $_REQUEST['rsconfig']
1429 return buildRedirectURL (__FUNCTION__
, 'ERR');
1431 return buildRedirectURL (__FUNCTION__
, 'OK');
1434 $msgcode['addLoadBalancer']['OK'] = 18;
1435 $msgcode['addLoadBalancer']['ERR'] = 137;
1436 function addLoadBalancer ()
1438 assertUIntArg ('pool_id');
1439 assertUIntArg ('object_id');
1440 assertUIntArg ('vs_id');
1441 assertStringArg ('vsconfig', TRUE);
1442 assertStringArg ('rsconfig', TRUE);
1443 if (! empty($_REQUEST['prio']))
1444 assertUIntArg('prio', TRUE);
1446 if (!addLBtoRSPool (
1447 $_REQUEST['pool_id'],
1448 $_REQUEST['object_id'],
1450 $_REQUEST['vsconfig'],
1451 $_REQUEST['rsconfig'],
1454 return buildRedirectURL (__FUNCTION__
, 'ERR');
1456 return buildRedirectURL (__FUNCTION__
, 'OK');
1459 $msgcode['addRSPool']['OK'] = 31;
1460 $msgcode['addRSPool']['ERR'] = 100;
1461 function addRSPool ()
1463 assertStringArg ('name', TRUE);
1464 assertStringArg ('vsconfig', TRUE);
1465 assertStringArg ('rsconfig', TRUE);
1466 $error = commitCreateRSPool
1469 $_REQUEST['vsconfig'],
1470 $_REQUEST['rsconfig'],
1471 isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array()
1474 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1476 return buildRedirectURL (__FUNCTION__
, 'OK');
1479 $msgcode['deleteRSPool']['OK'] = 32;
1480 $msgcode['deleteRSPool']['ERR'] = 138;
1481 function deleteRSPool ()
1483 assertUIntArg ('pool_id');
1484 if (commitDeleteRSPool ($_REQUEST['pool_id']) === FALSE)
1485 return buildRedirectURL (__FUNCTION__
, 'ERR');
1487 return buildRedirectURL (__FUNCTION__
, 'OK');
1490 $msgcode['updateRSPool']['OK'] = 33;
1491 $msgcode['updateRSPool']['ERR'] = 139;
1492 function updateRSPool ()
1494 assertUIntArg ('pool_id');
1495 assertStringArg ('name', TRUE);
1496 assertStringArg ('vsconfig', TRUE);
1497 assertStringArg ('rsconfig', TRUE);
1498 if (FALSE === commitUpdateRSPool
1500 $_REQUEST['pool_id'],
1502 $_REQUEST['vsconfig'],
1503 $_REQUEST['rsconfig']
1506 return buildRedirectURL (__FUNCTION__
, 'ERR');
1508 return buildRedirectURL (__FUNCTION__
, 'OK');
1511 $msgcode['updateRSInService']['OK'] = 38;
1512 $msgcode['updateRSInService']['ERR'] = 140;
1513 function updateRSInService ()
1515 assertUIntArg ('rscount');
1516 $pool_id = $_REQUEST['pool_id'];
1517 $orig = spotEntity ('ipv4rspool', $pool_id);
1518 amplifyCell ($orig);
1520 for ($i = 1; $i <= $_REQUEST['rscount']; $i++
)
1522 $rs_id = $_REQUEST["rsid_${i}"];
1523 if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on')
1527 if ($newval != $orig['rslist'][$rs_id]['inservice'])
1529 if (FALSE !== commitSetInService ($rs_id, $newval))
1536 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1538 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($nbad, $ngood));
1541 $msgcode['importPTRData']['OK'] = 26;
1542 $msgcode['importPTRData']['ERR'] = 141;
1543 // FIXME: check, that each submitted address belongs to the prefix we
1544 // are operating on.
1545 function importPTRData ()
1547 assertUIntArg ('addrcount');
1549 for ($i = 0; $i < $_REQUEST['addrcount']; $i++
)
1551 $inputname = "import_${i}";
1552 if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on')
1554 assertIPv4Arg ("addr_${i}");
1555 assertStringArg ("descr_${i}", TRUE);
1556 assertStringArg ("rsvd_${i}");
1557 // Non-existent addresses will not have this argument set in request.
1559 if ($_REQUEST["rsvd_${i}"] == 'yes')
1561 if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '')
1567 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1569 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($nbad, $ngood));
1572 $msgcode['generateAutoPorts']['OK'] = 21;
1573 $msgcode['generateAutoPorts']['ERR'] = 142;
1574 function generateAutoPorts ()
1577 assertUIntArg ('object_id');
1578 $info = spotEntity ('object', $_REQUEST['object_id']);
1579 // Navigate away in case of success, stay at the place otherwise.
1580 if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id']))
1581 return buildRedirectURL (__FUNCTION__
, 'OK', array(), $pageno, 'ports');
1583 return buildRedirectURL (__FUNCTION__
, 'ERR');
1586 $msgcode['saveEntityTags']['OK'] = 22;
1587 $msgcode['saveEntityTags']['ERR1'] = 143;
1588 $msgcode['saveEntityTags']['ERR2'] = 187;
1589 // Filter out implicit tags before storing the new tag set.
1590 function saveEntityTags ()
1592 global $page, $pageno, $etype_by_pageno;
1593 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1594 return buildRedirectURL (__FUNCTION__
, 'ERR2', array (__FUNCTION__
));
1595 $realm = $etype_by_pageno[$pageno];
1596 $bypass = $page[$pageno]['bypass'];
1597 assertUIntArg ($bypass);
1598 $entity_id = $_REQUEST[$bypass];
1599 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1600 // Build a chain from the submitted data, minimize it,
1601 // then wipe existing records and store the new set instead.
1602 destroyTagsForEntity ($realm, $entity_id);
1603 // TODO: these actions are very close to what rebuildTagChainForEntity() does,
1604 // so why not use it?
1605 $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist));
1606 $n_succeeds = $n_errors = 0;
1607 foreach ($newchain as $taginfo)
1608 if (addTagForEntity ($realm, $entity_id, $taginfo['id']))
1613 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($n_succeeds, $n_errors));
1615 return buildRedirectURL (__FUNCTION__
, 'OK', array ($n_succeeds));
1618 $msgcode['destroyTag']['OK'] = 58;
1619 $msgcode['destroyTag']['ERR1'] = 183;
1620 $msgcode['destroyTag']['ERR2'] = 144;
1621 function destroyTag ()
1623 assertUIntArg ('tag_id');
1625 if (!isset ($taglist[$_REQUEST['tag_id']]))
1626 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($_REQUEST['tag_id']));
1627 if (($ret = commitDestroyTag ($_REQUEST['tag_id'])) == '')
1628 return buildRedirectURL (__FUNCTION__
, 'OK', array ($taglist[$_REQUEST['tag_id']]['tag']));
1630 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1633 $msgcode['createTag']['OK'] = 59;
1634 $msgcode['createTag']['ERR1'] = 145;
1635 $msgcode['createTag']['ERR3'] = 147;
1636 function createTag ()
1638 assertStringArg ('tag_name');
1639 assertUIntArg ('parent_id', TRUE);
1640 $tagname = trim ($_REQUEST['tag_name']);
1641 if (!validTagName ($tagname))
1642 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($tagname));
1643 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1645 if (FALSE === commitCreateTag ($tagname, $parent_id))
1646 return buildRedirectURL (__FUNCTION__
, 'ERR3', array (niftyString ($tagname)));
1647 return buildRedirectURL (__FUNCTION__
, 'OK', array (niftyString ($tagname)));
1650 $msgcode['updateTag']['OK'] = 60;
1651 $msgcode['updateTag']['ERR1'] = 145;
1652 $msgcode['updateTag']['ERR2'] = 109;
1653 function updateTag ()
1655 assertUIntArg ('tag_id');
1656 assertUIntArg ('parent_id', TRUE);
1657 assertStringArg ('tag_name');
1658 $tagname = trim ($_REQUEST['tag_name']);
1659 if (!validTagName ($tagname))
1660 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($tagname));
1661 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1662 $parent_id = 'NULL';
1663 if (FALSE !== commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id))
1664 return buildRedirectURL (__FUNCTION__
, 'OK', array ($tagname));
1665 // Use old name in the message, cause update failed.
1667 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($taglist[$_REQUEST['tag_id']]['tag']));
1670 $msgcode['rollTags']['OK'] = 67;
1671 $msgcode['rollTags']['ERR'] = 149;
1672 function rollTags ()
1674 assertUIntArg ('row_id');
1675 assertStringArg ('sum', TRUE);
1676 assertUIntArg ('realsum');
1677 if ($_REQUEST['sum'] != $_REQUEST['realsum'])
1678 return buildRedirectURL (__FUNCTION__
, 'ERR');
1679 // Even if the user requested an empty tag list, don't bail out, but process existing
1680 // tag chains with "zero" extra. This will make sure, that the stuff processed will
1681 // have its chains refined to "normal" form.
1682 $extratags = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1684 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
1685 // filter out the same tag again and again. It will have own noise to cancel.
1686 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
1687 foreach (listCells ('rack', $_REQUEST['row_id']) as $rack)
1689 if (rebuildTagChainForEntity ('rack', $rack['id'], $extrachain))
1691 amplifyCell ($rack);
1692 foreach ($rack['mountedObjects'] as $object_id)
1693 if (rebuildTagChainForEntity ('object', $object_id, $extrachain))
1696 return buildRedirectURL (__FUNCTION__
, 'OK', array ($n_ok));
1699 $msgcode['changeMyPassword']['OK'] = 61;
1700 $msgcode['changeMyPassword']['ERR1'] = 150;
1701 $msgcode['changeMyPassword']['ERR2'] = 151;
1702 $msgcode['changeMyPassword']['ERR3'] = 152;
1703 $msgcode['changeMyPassword']['ERR4'] = 153;
1704 function changeMyPassword ()
1706 global $remote_username, $user_auth_src;
1707 if ($user_auth_src != 'database')
1708 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1709 assertStringArg ('oldpassword');
1710 assertStringArg ('newpassword1');
1711 assertStringArg ('newpassword2');
1712 $remote_userid = getUserIDByUsername ($remote_username);
1713 $userinfo = spotEntity ('user', $remote_userid);
1714 if ($userinfo['user_password_hash'] != sha1 ($_REQUEST['oldpassword']))
1715 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1716 if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2'])
1717 return buildRedirectURL (__FUNCTION__
, 'ERR3');
1718 if (FALSE !== commitUpdateUserAccount ($remote_userid, $userinfo['user_name'], $userinfo['user_realname'], sha1 ($_REQUEST['newpassword1'])))
1719 return buildRedirectURL (__FUNCTION__
, 'OK');
1721 return buildRedirectURL (__FUNCTION__
, 'ERR4');
1724 $msgcode['saveRackCode']['OK'] = 43;
1725 $msgcode['saveRackCode']['ERR1'] = 154;
1726 $msgcode['saveRackCode']['ERR2'] = 155;
1727 function saveRackCode ()
1729 assertStringArg ('rackcode');
1730 // For the test to succeed, unescape LFs, strip CRs.
1731 $newcode = dos2unix ($_REQUEST['rackcode']);
1732 $parseTree = getRackCode ($newcode);
1733 if ($parseTree['result'] != 'ACK')
1734 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($parseTree['load']));
1735 if (FALSE !== saveScript ('RackCode', $newcode))
1737 saveScript ('RackCodeCache', base64_encode (serialize ($parseTree)));
1738 return buildRedirectURL (__FUNCTION__
, 'OK');
1740 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1743 $msgcode['setPortVLAN']['ERR1'] = 156;
1744 // This handler's context is pre-built, but not authorized. It is assumed, that the
1745 // handler will take existing context and before each commit check authorization
1746 // on the base chain plus necessary context added.
1747 function setPortVLAN ()
1749 assertUIntArg ('portcount');
1750 $data = getSwitchVLANs ($_REQUEST['object_id']);
1752 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1753 list ($vlanlist, $portlist) = $data;
1754 // Here we just build up 1 set command for the gateway with all of the ports
1755 // included. The gateway is expected to filter unnecessary changes silently
1756 // and to provide a list of responses with either error or success message
1757 // for each of the rest.
1758 $nports = $_REQUEST['portcount'];
1762 for ($i = 0; $i < $nports; $i++
)
1765 !isset ($_REQUEST['portname_' . $i]) ||
1766 !isset ($_REQUEST['vlanid_' . $i]) ||
1767 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
1769 $log['m'][] = array ('c' => 158, 'a' => array ($i));
1772 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
1773 $portlist[$i]['vlaind'] == 'TRUNK'
1778 $portname = $_REQUEST['portname_' . $i];
1779 $oldvlanid = $portlist[$i]['vlanid'];
1780 $newvlanid = $_REQUEST['vlanid_' . $i];
1783 !permitted (NULL, NULL, NULL, array (array ('tag' => '$fromvlan_' . $oldvlanid))) or
1784 !permitted (NULL, NULL, NULL, array (array ('tag' => '$tovlan_' . $newvlanid)))
1787 $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid));
1790 $setcmd .= $prefix . $portname . '=' . $newvlanid;
1793 // Feed the gateway and interpret its (non)response.
1795 $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd));
1797 $log['m'][] = array ('c' => 201);
1798 return buildWideRedirectURL ($log);
1801 $msgcode['submitSLBConfig']['OK'] = 66;
1802 $msgcode['submitSLBConfig']['ERR'] = 164;
1803 function submitSLBConfig ()
1805 assertUIntArg ('object_id');
1806 $newconfig = buildLVSConfig ($_REQUEST['object_id']);
1809 gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES
, 'UTF-8'));
1811 catch (RTGatewayError
$e)
1813 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($e->getMessage()));
1815 return buildRedirectURL (__FUNCTION__
, 'OK', array ('slbconfig'));
1818 $msgcode['addRow']['OK'] = 74;
1819 $msgcode['addRow']['ERR'] = 100;
1822 assertStringArg ('name');
1824 if (commitAddRow ($_REQUEST['name']) === TRUE)
1825 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1827 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($_REQUEST['name']));
1830 $msgcode['updateRow']['OK'] = 75;
1831 $msgcode['updateRow']['ERR'] = 100;
1832 function updateRow ()
1834 assertUIntArg ('row_id');
1835 assertStringArg ('name');
1837 if (FALSE !== commitUpdateRow ($_REQUEST['row_id'], $_REQUEST['name']))
1838 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1840 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($_REQUEST['name']));
1843 $msgcode['deleteRow']['OK'] = 77;
1844 $msgcode['deleteRow']['ERR'] = 146;
1845 function deleteRow ()
1847 assertUIntArg ('row_id');
1848 $rowinfo = getRackRowInfo ($_REQUEST['row_id']);
1849 return buildRedirectURL (__FUNCTION__
, FALSE === commitDeleteRow ($_REQUEST['row_id']) ?
'ERR' : 'OK', array ($rowinfo['name']));
1852 $msgcode['addRack']['OK'] = 65;
1853 $msgcode['addRack']['ERR1'] = 171;
1854 $msgcode['addRack']['ERR2'] = 172;
1857 assertUIntArg ('row_id');
1858 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1859 if (isset ($_REQUEST['got_data']))
1861 assertStringArg ('rack_name');
1862 assertUIntArg ('rack_height1');
1863 assertStringArg ('rack_comment', TRUE);
1865 if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
1866 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['rack_name']));
1868 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($_REQUEST['rack_name']));
1870 elseif (isset ($_REQUEST['got_mdata']))
1872 assertUIntArg ('rack_height2');
1873 assertStringArg ('rack_names', TRUE);
1875 // copy-and-paste from renderAddMultipleObjectsForm()
1876 $names1 = explode ("\n", $_REQUEST['rack_names']);
1878 foreach ($names1 as $line)
1880 $parts = explode ('\r', $line);
1882 if (!strlen ($parts[0]))
1885 $names2[] = rtrim ($parts[0]);
1888 foreach ($names2 as $cname)
1889 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE)
1890 $log['m'][] = array ('c' => $msgcode[__FUNCTION__
]['OK'], 'a' => array ($cname));
1892 $log['m'][] = array ('c' => $msgcode[__FUNCTION__
]['ERR1'], 'a' => array ($cname));
1893 return buildWideRedirectURL ($log);
1896 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1899 $msgcode['deleteRack']['OK'] = 79;
1900 $msgcode['deleteRack']['ERR'] = 100;
1901 $msgcode['deleteRack']['ERR1'] = 206;
1902 function deleteRack ()
1904 assertUIntArg ('rack_id');
1905 if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id'])))
1906 return buildRedirectURL (__FUNCTION__
, 'ERR', array ('Rack not found'), 'rackspace', 'default');
1907 amplifyCell ($rackData);
1908 if (count ($rackData['mountedObjects']))
1909 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1910 if (TRUE !== commitDeleteRack ($_REQUEST['rack_id']))
1911 return buildRedirectURL (__FUNCTION__
, 'ERR', array(), 'rackspace', 'default');
1912 return buildRedirectURL (__FUNCTION__
, 'OK', array ($rackData['name']), 'rackspace', 'default');
1915 $msgcode['updateRack']['OK'] = 68;
1916 $msgcode['updateRack']['ERR'] = 177;
1917 function updateRack ()
1919 assertUIntArg ('rack_id');
1920 assertUIntArg ('rack_row_id');
1921 assertUIntArg ('rack_height');
1922 assertStringArg ('rack_name');
1923 assertStringArg ('rack_comment', TRUE);
1925 resetThumbCache ($_REQUEST['rack_id']);
1926 if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
1927 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['rack_name']));
1929 return buildRedirectURL (__FUNCTION__
, 'ERR');
1932 function updateRackDesign ()
1934 assertUIntArg ('rack_id');
1935 $rackData = spotEntity ('rack', $_REQUEST['rack_id']);
1936 amplifyCell ($rackData);
1937 applyRackDesignMask($rackData);
1938 markupObjectProblems ($rackData);
1939 $response = processGridForm ($rackData, 'A', 'F');
1940 return buildWideRedirectURL (array($response));
1943 function updateRackProblems ()
1945 assertUIntArg ('rack_id');
1946 $rackData = spotEntity ('rack', $_REQUEST['rack_id']);
1947 amplifyCell ($rackData);
1948 applyRackProblemMask($rackData);
1949 markupObjectProblems ($rackData);
1950 $response = processGridForm ($rackData, 'F', 'U');
1951 return buildWideRedirectURL (array($response));
1954 function querySNMPData ()
1956 assertUIntArg ('object_id');
1957 assertStringArg ('community');
1958 return doSNMPmining ($_REQUEST['object_id'], $_REQUEST['community']);
1961 $msgcode['addFileWithoutLink']['OK'] = 69;
1962 $msgcode['addFileWithoutLink']['ERR1'] = 181;
1963 $msgcode['addFileWithoutLink']['ERR2'] = 110;
1964 // File-related functions
1965 function addFileWithoutLink ()
1967 assertStringArg ('comment', TRUE);
1969 // Make sure the file can be uploaded
1970 if (get_cfg_var('file_uploads') != 1)
1971 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1973 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1975 if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']))
1976 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1977 if (isset ($_REQUEST['taglist']))
1978 produceTagsForLastRecord ('file', $_REQUEST['taglist']);
1979 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($_FILES['file']['name'])));
1982 $msgcode['addFileToEntity']['OK'] = 69;
1983 $msgcode['addFileToEntity']['ERR2'] = 181;
1984 $msgcode['addFileToEntity']['ERR3'] = 110;
1985 function addFileToEntity ()
1987 global $page, $pageno, $etype_by_pageno;
1988 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1989 throw new RackTablesError ('dispatching failure', RackTablesError
::INTERNAL
);
1990 $realm = $etype_by_pageno[$pageno];
1991 $bypass = $page[$pageno]['bypass'];
1992 assertUIntArg ($bypass);
1993 $entity_id = $_REQUEST[$bypass];
1994 assertStringArg ('comment', TRUE);
1996 // Make sure the file can be uploaded
1997 if (get_cfg_var('file_uploads') != 1)
1998 return buildRedirectURL (__FUNCTION__
, 'ERR2');
2000 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
2002 if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']))
2003 return buildRedirectURL (__FUNCTION__
, 'ERR3');
2004 if (FALSE === commitLinkFile (lastInsertID(), $realm, $entity_id))
2005 return buildRedirectURL (__FUNCTION__
, 'ERR3');
2007 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($_FILES['file']['name'])));
2010 $msgcode['linkFileToEntity']['OK'] = 71;
2011 $msgcode['linkFileToEntity']['ERR1'] = 178;
2012 $msgcode['linkFileToEntity']['ERR2'] = 110;
2013 function linkFileToEntity ()
2015 assertUIntArg ('file_id');
2016 global $page, $pageno, $etype_by_pageno;
2017 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
2018 throw new RackTablesError ('dispatching failure', RackTablesError
::INTERNAL
);
2019 $entity_type = $etype_by_pageno[$pageno];
2020 $bypass_name = $page[$pageno]['bypass'];
2021 assertUIntArg ($bypass_name);
2023 $fi = spotEntity ('file', $_REQUEST['file_id']);
2024 if (FALSE === commitLinkFile ($_REQUEST['file_id'], $entity_type, $_REQUEST[$bypass_name]))
2025 return buildRedirectURL (__FUNCTION__
, 'ERR2');
2027 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($fi['name'])));
2030 $msgcode['replaceFile']['OK'] = 70;
2031 $msgcode['replaceFile']['ERR1'] = 181;
2032 $msgcode['replaceFile']['ERR2'] = 207;
2033 $msgcode['replaceFile']['ERR3'] = 109;
2034 function replaceFile ()
2037 assertUIntArg ('file_id');
2039 // Make sure the file can be uploaded
2040 if (get_cfg_var('file_uploads') != 1)
2041 return buildRedirectURL (__FUNCTION__
, 'ERR1');
2042 $shortInfo = spotEntity ('file', $sic['file_id']);
2044 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
2046 return buildRedirectURL (__FUNCTION__
, 'ERR2');
2047 if (FALSE === commitReplaceFile ($sic['file_id'], $fp))
2048 return buildRedirectURL (__FUNCTION__
, 'ERR3');
2050 usePreparedExecuteBlade
2052 'UPDATE File SET thumbnail = NULL WHERE id = ?',
2056 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
2059 $msgcode['updateFile']['OK'] = 70;
2060 $msgcode['updateFile']['ERR'] = 109;
2061 function updateFile ()
2063 assertUIntArg ('file_id');
2064 assertStringArg ('file_name');
2065 assertStringArg ('file_type');
2066 assertStringArg ('file_comment', TRUE);
2068 if (FALSE === commitUpdateFile ($sic['file_id'], $sic['file_name'], $sic['file_type'], $sic['file_comment']))
2069 return buildRedirectURL (__FUNCTION__
, 'ERR');
2070 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['file_name']));
2073 $msgcode['unlinkFile']['OK'] = 72;
2074 $msgcode['unlinkFile']['ERR'] = 182;
2075 function unlinkFile ()
2077 assertUIntArg ('link_id');
2078 $error = commitUnlinkFile ($_REQUEST['link_id']);
2081 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
2083 return buildRedirectURL (__FUNCTION__
, 'OK');
2086 $msgcode['deleteFile']['OK'] = 73;
2087 $msgcode['deleteFile']['ERR'] = 100;
2088 function deleteFile ()
2090 assertUIntArg ('file_id');
2091 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
2092 $error = commitDeleteFile ($_REQUEST['file_id']);
2095 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
2097 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
2100 $msgcode['updateFileText']['OK'] = 78;
2101 $msgcode['updateFileText']['ERR1'] = 179;
2102 $msgcode['updateFileText']['ERR2'] = 180;
2103 function updateFileText ()
2105 assertUIntArg ('file_id');
2106 assertStringArg ('mtime_copy');
2107 assertStringArg ('file_text', TRUE); // it's Ok to save empty
2108 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
2109 if ($shortInfo['mtime'] != $_REQUEST['mtime_copy'])
2110 return buildRedirectURL (__FUNCTION__
, 'ERR1');
2112 if (FALSE === commitReplaceFile ($sic['file_id'], $sic['file_text']))
2113 return buildRedirectURL (__FUNCTION__
, 'ERR2');
2114 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
2117 $msgcode['addPortInterfaceCompat']['OK'] = 48;
2118 $msgcode['addPortInterfaceCompat']['ERR'] = 110;
2119 function addPortInterfaceCompat ()
2121 assertUIntArg ('iif_id');
2122 assertUIntArg ('oif_id');
2123 if (commitSupplementPIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
2124 return buildRedirectURL (__FUNCTION__
, 'OK');
2125 return buildRedirectURL (__FUNCTION__
, 'ERR');
2128 $msgcode['delPortInterfaceCompat']['OK'] = 49;
2129 $msgcode['delPortInterfaceCompat']['ERR'] = 111;
2130 function delPortInterfaceCompat ()
2132 assertUIntArg ('iif_id');
2133 assertUIntArg ('oif_id');
2134 if (commitReducePIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
2135 return buildRedirectURL (__FUNCTION__
, 'OK');
2136 return buildRedirectURL (__FUNCTION__
, 'ERR');
2139 $ifcompatpack = array
2141 '1000cwdm80' => array (1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216),
2142 '1000dwdm80' => array // ITU channels 20~61
2144 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226,
2145 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236,
2146 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246,
2147 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256,
2150 '10000dwdm80' => array // same channels for 10GE
2152 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268,
2153 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278,
2154 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288,
2155 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298,
2160 $msgcode['addPortInterfaceCompatPack']['OK'] = 44;
2161 $msgcode['addPortInterfaceCompatPack']['ERR'] = 123;
2162 function addPortInterfaceCompatPack ()
2164 assertStringArg ('standard');
2165 assertUIntArg ('iif_id');
2166 global $ifcompatpack;
2167 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
2168 return buildRedirectURL (__FUNCTION__
, 'ERR');
2170 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2171 if (commitSupplementPIC ($_REQUEST['iif_id'], $oif_id))
2175 return buildRedirectURL (__FUNCTION__
, 'OK', array ($nbad, $ngood));
2178 $msgcode['delPortInterfaceCompatPack']['OK'] = 44;
2179 $msgcode['delPortInterfaceCompatPack']['ERR'] = 123;
2180 function delPortInterfaceCompatPack ()
2182 assertStringArg ('standard');
2183 assertUIntArg ('iif_id');
2184 global $ifcompatpack;
2185 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
2186 return buildRedirectURL (__FUNCTION__
, 'ERR');
2188 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2189 if (commitReducePIC ($_REQUEST['iif_id'], $oif_id))
2193 return buildRedirectURL (__FUNCTION__
, 'OK', array ($nbad, $ngood));
2196 $msgcode['addPortOIFCompat']['OK'] = 48;
2197 $msgcode['addPortOIFCompat']['ERR'] = 110;
2198 function addPortOIFCompat()
2200 assertUIntArg('type1');
2201 assertUIntArg('type2');
2202 if (commitSupplementPOIFC($_REQUEST['type1'], $_REQUEST['type2']))
2203 return buildRedirectURL(__FUNCTION__
, 'OK');
2204 return buildRedirectURL(__FUNCTION__
, 'ERR');
2207 $msgcode['delPortOIFCompat']['OK'] = 49;
2208 $msgcode['delPortOIFCompat']['ERR'] = 111;
2209 function delPortOIFCompat ()
2211 assertUIntArg('type1');
2212 assertUIntArg('type2');
2213 if (commitReducePOIFC ($_REQUEST['type1'], $_REQUEST['type2']) !== FALSE)
2214 return buildRedirectURL (__FUNCTION__
, 'OK');
2215 return buildRedirectURL (__FUNCTION__
, 'ERR');
2219 $msgcode['add8021QOrder']['OK'] = 48;
2220 $msgcode['add8021QOrder']['ERR'] = 118;
2221 function add8021QOrder ()
2223 assertUIntArg ('vdom_id');
2224 assertUIntArg ('object_id');
2225 assertUIntArg ('vst_id');
2227 $result = usePreparedExecuteBlade
2229 'INSERT INTO VLANSwitch (domain_id, object_id, template_id, last_change, out_of_sync) ' .
2230 'VALUES (?, ?, ?, NOW(), "yes")',
2231 array ($sic['vdom_id'], $sic['object_id'], $sic['vst_id'])
2233 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
2236 $msgcode['del8021QOrder']['OK'] = 49;
2237 $msgcode['del8021QOrder']['ERR'] = 119;
2238 function del8021QOrder ()
2240 assertUIntArg ('object_id');
2241 assertUIntArg ('vdom_id');
2242 assertUIntArg ('vst_id');
2244 $result = usePreparedDeleteBlade ('VLANSwitch', array ('object_id' => $sic['object_id']));
2245 $focus_hints = array
2247 'prev_objid' => $_REQUEST['object_id'],
2248 'prev_vstid' => $_REQUEST['vst_id'],
2249 'prev_vdid' => $_REQUEST['vdom_id'],
2251 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR', array(), NULL, NULL, $focus_hints);
2254 $msgcode['addVLANDescription']['OK'] = 48;
2255 $msgcode['addVLANDescription']['ERR1'] = 190;
2256 $msgcode['addVLANDescription']['ERR2'] = 110;
2257 function addVLANDescription ()
2259 assertUIntArg ('vlan_id');
2260 assertStringArg ('vlan_type', TRUE);
2261 assertStringArg ('vlan_descr', TRUE);
2263 if (!($sic['vlan_id'] >= VLAN_MIN_ID +
1 and $sic['vlan_id'] <= VLAN_MAX_ID
))
2264 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($sic['vlan_id']));
2265 $result = usePreparedInsertBlade
2270 'domain_id' => $sic['vdom_id'],
2271 'vlan_id' => $sic['vlan_id'],
2272 'vlan_type' => $sic['vlan_type'],
2273 'vlan_descr' => mb_strlen ($sic['vlan_descr']) ?
$sic['vlan_descr'] : NULL
2276 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR2');
2279 $msgcode['delVLANDescription']['OK'] = 49;
2280 $msgcode['delVLANDescription']['ERR1'] = 105;
2281 $msgcode['delVLANDescription']['ERR2'] = 111;
2282 function delVLANDescription ()
2284 assertUIntArg ('vlan_id');
2286 if ($sic['vlan_id'] == VLAN_DFL_ID
)
2287 return buildRedirectURL (__FUNCTION__
, 'ERR1');
2288 $result = commitReduceVLANDescription ($sic['vdom_id'], $sic['vlan_id']);
2289 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR2');
2292 $msgcode['updVLANDescription']['OK'] = 51;
2293 $msgcode['updVLANDescription']['ERR1'] = 105;
2294 $msgcode['updVLANDescription']['ERR2'] = 109;
2295 function updVLANDescription ()
2297 assertUIntArg ('vlan_id');
2298 assertStringArg ('vlan_type');
2299 assertStringArg ('vlan_descr', TRUE);
2301 if ($sic['vlan_id'] == VLAN_DFL_ID
)
2302 return buildRedirectURL (__FUNCTION__
, 'ERR1');
2303 $result = commitUpdateVLANDescription
2310 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR2');
2313 $msgcode['createVLANDomain']['OK'] = 48;
2314 $msgcode['createVLANDomain']['ERR'] = 110;
2315 function createVLANDomain ()
2317 assertStringArg ('vdom_descr');
2319 $result = usePreparedInsertBlade
2324 'description' => $sic['vdom_descr'],
2327 $result = $result and usePreparedInsertBlade
2332 'domain_id' => lastInsertID(),
2333 'vlan_id' => VLAN_DFL_ID
,
2334 'vlan_type' => 'compulsory',
2335 'vlan_descr' => 'default',
2338 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2341 $msgcode['destroyVLANDomain']['OK'] = 49;
2342 $msgcode['destroyVLANDomain']['ERR'] = 111;
2343 function destroyVLANDomain ()
2345 assertUIntArg ('vdom_id');
2347 $result = FALSE !== usePreparedDeleteBlade ('VLANDomain', array ('id' => $sic['vdom_id']));
2348 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2351 $msgcode['updateVLANDomain']['OK'] = 51;
2352 $msgcode['updateVLANDomain']['ERR'] = 109;
2353 function updateVLANDomain ()
2355 assertUIntArg ('vdom_id');
2356 assertStringArg ('vdom_descr');
2358 $result = FALSE !== commitUpdateVLANDomain ($sic['vdom_id'], $sic['vdom_descr']);
2359 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2362 $msgcode['save8021QPorts']['OK1'] = 63;
2363 $msgcode['save8021QPorts']['OK2'] = 41;
2364 $msgcode['save8021QPorts']['ERR1'] = 160;
2365 $msgcode['save8021QPorts']['ERR2'] = 109;
2366 function save8021QPorts ()
2368 global $sic, $dbxlink;
2369 assertUIntArg ('mutex_rev', TRUE); // counts from 0
2370 assertStringArg ('form_mode');
2371 if ($sic['form_mode'] != 'save' and $sic['form_mode'] != 'duplicate')
2372 throw new InvalidRequestArgException ('form_mode', $sic['form_mode']);
2374 $dbxlink->beginTransaction();
2377 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE'))
2378 throw new InvalidArgException ('object_id', $object_id, 'VLAN domain is not set for this object');
2379 if ($vswitch['mutex_rev'] != $sic['mutex_rev'])
2380 throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form data');
2381 $after = $before = apply8021QOrder ($vswitch['template_id'], getStored8021QConfig ($sic['object_id'], 'desired'));
2383 switch ($sic['form_mode'])
2386 assertUIntArg ('nports');
2387 if ($sic['nports'] == 1)
2389 assertStringArg ('pn_0');
2390 $extra = array ('port_name' => $sic['pn_0']);
2392 for ($i = 0; $i < $sic['nports']; $i++
)
2394 assertStringArg ('pn_' . $i);
2395 assertStringArg ('pm_' . $i);
2396 // An access port only generates form input for its native VLAN,
2397 // which we derive allowed VLAN list from.
2398 $native = isset ($sic['pnv_' . $i]) ?
$sic['pnv_' . $i] : 0;
2399 switch ($sic["pm_${i}"])
2402 # assertArrayArg ('pav_' . $i);
2403 $allowed = isset ($sic['pav_' . $i]) ?
$sic['pav_' . $i] : array();
2406 if ($native == 'same')
2408 assertUIntArg ('pnv_' . $i);
2409 $allowed = array ($native);
2412 throw new InvalidRequestArgException ("pm_${i}", $_REQUEST["pm_${i}"], 'unknown port mode');
2414 $changes[$sic['pn_' . $i]] = array
2416 'mode' => $sic['pm_' . $i],
2417 'allowed' => $allowed,
2418 'native' => $native,
2423 assertStringArg ('from_port');
2424 # assertArrayArg ('to_ports');
2425 if (!array_key_exists ($sic['from_port'], $before))
2426 throw new InvalidArgException ('from_port', $sic['from_port'], 'this port does not exist');
2427 foreach ($sic['to_ports'] as $tpn)
2428 if (!array_key_exists ($tpn, $before))
2429 throw new InvalidArgException ('to_ports[]', $tpn, 'this port does not exist');
2430 elseif ($tpn != $sic['from_port'])
2431 $changes[$tpn] = $before[$sic['from_port']];
2434 $domain_vlanlist = getDomainVLANs ($vswitch['domain_id']);
2435 $changes = filter8021QChangeRequests
2439 apply8021QOrder ($vswitch['template_id'], $changes)
2441 $changes = authorize8021QChangeRequests ($before, $changes);
2442 foreach ($changes as $port_name => $port)
2443 $after[$port_name] = $port;
2444 $new_uplinks = filter8021QChangeRequests ($domain_vlanlist, $after, produceUplinkPorts ($domain_vlanlist, $after));
2445 $npulled = replace8021QPorts ('desired', $vswitch['object_id'], $before, $changes);
2446 $nsaved_uplinks = replace8021QPorts ('desired', $vswitch['object_id'], $before, $new_uplinks);
2448 catch (Exception
$e)
2450 $dbxlink->rollBack();
2451 return buildRedirectURL (__FUNCTION__
, 'ERR2', array(), NULL, NULL, $extra);
2453 if ($npulled +
$nsaved_uplinks)
2454 $result = usePreparedExecuteBlade
2456 'UPDATE VLANSwitch SET mutex_rev=mutex_rev+1, last_change=NOW(), out_of_sync="yes" WHERE object_id=?',
2457 array ($sic['object_id'])
2460 $log = oneLiner (63, array ($npulled +
$nsaved_uplinks));
2461 if ($nsaved_uplinks)
2463 initiateUplinksReverb ($vswitch['object_id'], $new_uplinks);
2464 $log = mergeLogs ($log, oneLiner (41));
2466 if ($npulled +
$nsaved_uplinks > 0 and getConfigVar ('8021Q_INSTANT_DEPLOY') == 'yes')
2470 if (FALSE === $done = exec8021QDeploy ($sic['object_id'], TRUE))
2471 $log = mergeLogs ($log, oneLiner (191));
2473 $log = mergeLogs ($log, oneLiner (63, array ($done)));
2475 catch (Exception
$e)
2477 $log = mergeLogs ($log, oneLiner (109));
2480 return buildWideRedirectURL ($log, NULL, NULL, $extra);
2483 $msgcode['bindVLANtoIPv4']['OK'] = 48;
2484 $msgcode['bindVLANtoIPv4']['ERR'] = 110;
2485 function bindVLANtoIPv4 ()
2487 assertUIntArg ('id'); // network id
2489 $result = commitSupplementVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2490 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2493 $msgcode['bindVLANtoIPv6']['OK'] = 48;
2494 $msgcode['bindVLANtoIPv6']['ERR'] = 110;
2495 function bindVLANtoIPv6 ()
2497 assertUIntArg ('id'); // network id
2499 $result = commitSupplementVLANIPv6 ($sic['vlan_ck'], $_REQUEST['id']);
2500 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2503 $msgcode['unbindVLANfromIPv4']['OK'] = 49;
2504 $msgcode['unbindVLANfromIPv4']['ERR'] = 111;
2505 function unbindVLANfromIPv4 ()
2507 assertUIntArg ('id'); // network id
2509 $result = commitReduceVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2510 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2513 $msgcode['unbindVLANfromIPv6']['OK'] = 49;
2514 $msgcode['unbindVLANfromIPv6']['ERR'] = 111;
2515 function unbindVLANfromIPv6 ()
2517 assertUIntArg ('id'); // network id
2519 $result = commitReduceVLANIPv6 ($sic['vlan_ck'], $sic['id']);
2520 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2523 $msgcode['process8021QSyncRequest']['OK'] = 63;
2524 $msgcode['process8021QSyncRequest']['ERR'] = 191;
2525 function process8021QSyncRequest ()
2527 // behave depending on current operation: exec8021QPull or exec8021QPush
2529 if (FALSE === $done = exec8021QDeploy ($sic['object_id'], $op == 'exec8021QPush'))
2530 return buildRedirectURL (__FUNCTION__
, 'ERR');
2531 return buildRedirectURL (__FUNCTION__
, 'OK', array ($done));
2534 $msgcode['process8021QRecalcRequest']['CHANGED'] = 87;
2535 $msgcode['process8021QRecalcRequest']['NO_CHANGES'] = 300;
2536 function process8021QRecalcRequest ()
2538 assertUIntArg ('object_id');
2540 $counters = recalc8021QPorts ($sic['object_id']);
2541 if ($counters['ports'])
2542 return buildRedirectURL (__FUNCTION__
, 'CHANGED', array ($counters['ports'], $counters['switches']));
2544 return buildRedirectURL (__FUNCTION__
, 'NO_CHANGES', array ('No changes were made'));
2547 $msgcode['resolve8021QConflicts']['OK'] = 63;
2548 $msgcode['resolve8021QConflicts']['ERR1'] = 179;
2549 $msgcode['resolve8021QConflicts']['ERR2'] = 109;
2550 function resolve8021QConflicts ()
2552 global $sic, $dbxlink;
2553 assertUIntArg ('mutex_rev', TRUE); // counts from 0
2554 assertUIntArg ('nrows');
2555 // Divide submitted radio buttons into 3 groups:
2556 // left (saved version wins)
2558 // right (running version wins)
2560 for ($i = 0; $i < $sic['nrows']; $i++
)
2562 if (!array_key_exists ("i_${i}", $sic))
2564 // let's hope other inputs are in place
2565 switch ($sic["i_${i}"])
2569 $F[$sic["pn_${i}"]] = array
2571 'mode' => $sic["rm_${i}"],
2572 'allowed' => $sic["ra_${i}"],
2573 'native' => $sic["rn_${i}"],
2574 'decision' => $sic["i_${i}"],
2581 $dbxlink->beginTransaction();
2584 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE'))
2585 throw new InvalidArgException ('object_id', $sic['object_id'], 'VLAN domain is not set for this object');
2586 if ($vswitch['mutex_rev'] != $sic['mutex_rev'])
2587 throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form (table data has changed)');
2588 $D = getStored8021QConfig ($vswitch['object_id'], 'desired');
2589 $C = getStored8021QConfig ($vswitch['object_id'], 'cached');
2590 $R = getRunning8021QConfig ($vswitch['object_id']);
2591 $plan = get8021QSyncOptions ($vswitch, $D, $C, $R['portdata']);
2593 foreach ($F as $port_name => $port)
2595 if (!array_key_exists ($port_name, $plan))
2597 elseif ($plan[$port_name]['status'] == 'merge_conflict')
2599 // for R neither mutex nor revisions can be emulated, but revision change can be
2600 if (!same8021QConfigs ($port, $R['portdata'][$port_name]))
2601 throw new InvalidRequestArgException ("port ${port_name}", '(hidden)', 'expired form (switch data has changed)');
2602 if ($port['decision'] == 'right') // D wins, frame R by writing value of R to C
2603 $ndone +
= upd8021QPort ('cached', $vswitch['object_id'], $port_name, $port);
2604 elseif ($port['decision'] == 'left') // R wins, cross D up
2605 $ndone +
= upd8021QPort ('cached', $vswitch['object_id'], $port_name, $D[$port_name]);
2606 // otherwise there was no decision made
2610 $plan[$port_name]['status'] == 'delete_conflict' or
2611 $plan[$port_name]['status'] == 'martian_conflict'
2614 if ($port['decision'] == 'left') // confirm deletion of local copy
2615 $ndone +
= del8021QPort ($vswitch['object_id'], $port_name);
2617 // otherwise ignore a decision, which doesn't address a conflict
2620 catch (InvalidRequestArgException
$e)
2622 $dbxlink->rollBack();
2623 return buildRedirectURL (__FUNCTION__
, 'ERR1');
2625 catch (Exception
$e)
2627 $dbxlink->rollBack();
2628 return buildRedirectURL (__FUNCTION__
, 'ERR2');
2631 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ndone));
2634 $msgcode['addVLANSwitchTemplate']['OK'] = 48;
2635 $msgcode['addVLANSwitchTemplate']['ERR'] = 110;
2636 function addVLANSwitchTemplate()
2638 assertStringArg ('vst_descr');
2640 $max_local_vlans = NULL;
2641 if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans']))
2643 assertUIntArg ('vst_maxvlans');
2644 $max_local_vlans = $sic['vst_maxvlans'];
2646 $result = usePreparedInsertBlade
2648 'VLANSwitchTemplate',
2651 'max_local_vlans' => $max_local_vlans,
2652 'description' => $sic['vst_descr'],
2655 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2658 $msgcode['delVLANSwitchTemplate']['OK'] = 49;
2659 $msgcode['delVLANSwitchTemplate']['ERR'] = 111;
2660 function delVLANSwitchTemplate()
2662 assertUIntArg ('vst_id');
2664 $result = FALSE !== usePreparedDeleteBlade ('VLANSwitchTemplate', array ('id' => $sic['vst_id']));
2665 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2668 $msgcode['updVLANSwitchTemplate']['OK'] = 51;
2669 $msgcode['updVLANSwitchTemplate']['ERR'] = 109;
2670 function updVLANSwitchTemplate()
2672 assertUIntArg ('vst_id');
2673 assertStringArg ('vst_descr');
2675 $max_local_vlans = NULL;
2676 if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans']))
2678 assertUIntArg ('vst_maxvlans');
2679 $max_local_vlans = $sic['vst_maxvlans'];
2681 $result = commitUpdateVST ($sic['vst_id'], $max_local_vlans, $sic['vst_descr']);
2682 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
2685 $msgcode['addVSTRule']['OK'] = 48;
2686 $msgcode['addVSTRule']['ERR'] = 110;
2687 function addVSTRule()
2689 assertUIntArg ('vst_id');
2690 assertUIntArg ('rule_no');
2691 assertPCREArg ('port_pcre');
2692 assertStringArg ('port_role');
2693 assertStringArg ('wrt_vlans', TRUE);
2694 assertStringArg ('description', TRUE);
2696 $result = usePreparedInsertBlade
2701 'vst_id' => $sic['vst_id'],
2702 'rule_no' => $sic['rule_no'],
2703 'port_pcre' => $sic['port_pcre'],
2704 'port_role' => $sic['port_role'],
2705 'wrt_vlans' => $sic['wrt_vlans'],
2706 'description' => $sic['description'],
2709 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2712 $msgcode['delVSTRule']['OK'] = 49;
2713 $msgcode['delVSTRule']['ERR'] = 111;
2714 function delVSTRule()
2716 assertUIntArg ('vst_id');
2717 assertUIntArg ('rule_no');
2719 $result = FALSE !== usePreparedDeleteBlade
2724 'vst_id' => $sic['vst_id'],
2725 'rule_no' => $sic['rule_no']
2728 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2731 $msgcode['updVSTRule']['OK'] = 51;
2732 $msgcode['updVSTRule']['ERR'] = 109;
2733 function updVSTRule()
2735 assertUIntArg ('vst_id');
2736 assertUIntArg ('rule_no');
2737 assertUIntArg ('new_rule_no');
2738 assertPCREArg ('port_pcre');
2739 assertStringArg ('port_role');
2740 assertStringArg ('wrt_vlans', TRUE);
2741 assertStringArg ('description', TRUE);
2743 $result = commitUpdateVSTRule
2747 $sic['new_rule_no'],
2753 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
2756 $msgcode['importDPData']['OK'] = 44;
2757 function importDPData()
2760 assertUIntArg ('nports');
2761 $nignored = $ndone = 0;
2762 $POIFC = getPortOIFCompat();
2763 for ($i = 0; $i < $sic['nports']; $i++
)
2764 if (array_key_exists ("do_${i}", $sic))
2766 assertUIntArg ("pid1_${i}");
2767 assertUIntArg ("pid2_${i}");
2768 $porta = getPortInfo ($_REQUEST["pid1_${i}"]);
2769 $portb = getPortInfo ($_REQUEST["pid2_${i}"]);
2774 ($porta['object_id'] != $sic['object_id'] and $portb['object_id'] != $sic['object_id'])
2780 foreach ($POIFC as $item)
2781 if ($item['type1'] == $porta['oif_id'] and $item['type2'] == $portb['oif_id'])
2783 linkPorts ($_REQUEST["pid1_${i}"], $_REQUEST["pid2_${i}"]);
2785 continue 2; // next port
2789 return buildRedirectURL (__FUNCTION__
, 'OK', array ($nignored, $ndone));