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['delIPv4Allocation']['OK'] = 14;
400 $msgcode['delIPv4Allocation']['ERR'] = 111;
401 function delIPv4Allocation ()
403 assertIPv4Arg ('ip');
404 assertUIntArg ('object_id');
406 $result = unbindIpFromObject ($_REQUEST['ip'], $_REQUEST['object_id']);
407 return buildRedirectURL (__FUNCTION__
, $result === FALSE ?
'ERR' : 'OK');
410 $msgcode['addIPv4Allocation']['OK'] = 13;
411 $msgcode['addIPv4Allocation']['ERR1'] = 170;
412 $msgcode['addIPv4Allocation']['ERR2'] = 100;
413 function addIPv4Allocation ()
415 assertIPv4Arg ('ip');
416 assertUIntArg ('object_id');
417 assertStringArg ('bond_name', TRUE);
418 assertStringArg ('bond_type');
421 $ip = preg_replace ('@/[[:digit:]]+$@', '', $_REQUEST['ip']);
422 if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv4AddressNetworkId ($ip))
423 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($ip));
425 if (FALSE === bindIpToObject ($ip, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']))
426 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
427 $address = getIPv4Address ($ip);
428 if ($address['reserved'] == 'yes' or strlen ($address['name']))
430 $release = getConfigVar ('IPV4_AUTO_RELEASE');
432 $address['reserved'] = 'no';
434 $address['name'] = '';
435 updateAddress ($ip, $address['name'], $address['reserved']);
437 return buildRedirectURL (__FUNCTION__
, 'OK');
440 $msgcode['addIPv4Prefix']['OK'] = 23;
441 $msgcode['addIPv4Prefix']['ERR'] = 100;
442 $msgcode['addIPv4Prefix']['ERR1'] = 173;
443 $msgcode['addIPv4Prefix']['ERR2'] = 174;
444 $msgcode['addIPv4Prefix']['ERR3'] = 175;
445 $msgcode['addIPv4Prefix']['ERR4'] = 176;
446 function addIPv4Prefix ()
448 assertStringArg ('range');
449 assertStringArg ('name', TRUE);
451 $is_bcast = isset ($_REQUEST['is_bcast']) ?
$_REQUEST['is_bcast'] : 'off';
452 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
454 $error = createIPv4Prefix ($_REQUEST['range'], $sic['name'], $is_bcast == 'on', $taglist);
456 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
458 return buildRedirectURL (__FUNCTION__
, 'OK');
461 $msgcode['delIPv4Prefix']['OK'] = 24;
462 $msgcode['delIPv4Prefix']['ERR'] = 100;
463 function delIPv4Prefix ()
465 assertUIntArg ('id');
466 $error = destroyIPv4Prefix ($_REQUEST['id']);
468 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
470 return buildRedirectURL (__FUNCTION__
, 'OK');
473 $msgcode['updIPv4Prefix']['OK'] = 25;
474 $msgcode['updIPv4Prefix']['ERR'] = 109;
475 function updIPv4Prefix ()
477 assertUIntArg ('id');
478 assertStringArg ('name', TRUE);
479 assertStringArg ('comment', TRUE);
481 $result = updateIPv4Network_real ($sic['id'], $sic['name'], $sic['comment']);
482 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
485 $msgcode['editAddress']['OK'] = 27;
486 $msgcode['editAddress']['ERR'] = 100;
487 function editAddress ()
489 assertIPv4Arg ('ip');
490 assertStringArg ('name', TRUE);
492 if (isset ($_REQUEST['reserved']))
493 $reserved = $_REQUEST['reserved'];
496 $error = updateAddress ($_REQUEST['ip'], $_REQUEST['name'], $reserved == 'on' ?
'yes' : 'no');
498 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
500 return buildRedirectURL (__FUNCTION__
, 'OK');
503 $msgcode['createUser']['OK'] = 40;
504 $msgcode['createUser']['ERR'] = 102;
505 function createUser ()
507 assertStringArg ('username');
508 assertStringArg ('realname', TRUE);
509 assertStringArg ('password');
510 $username = $_REQUEST['username'];
511 $password = sha1 ($_REQUEST['password']);
512 $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password);
514 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($username));
515 if (isset ($_REQUEST['taglist']))
516 produceTagsForLastRecord ('user', $_REQUEST['taglist']);
517 return buildRedirectURL (__FUNCTION__
, 'OK', array ($username));
520 $msgcode['updateUser']['OK'] = 39;
521 $msgcode['updateUser']['ERR1'] = 103;
522 $msgcode['updateUser']['ERR1'] = 104;
523 function updateUser ()
525 assertUIntArg ('user_id');
526 assertStringArg ('username');
527 assertStringArg ('realname', TRUE);
528 assertStringArg ('password');
529 $username = $_REQUEST['username'];
530 $new_password = $_REQUEST['password'];
531 if (NULL == ($userinfo = spotEntity ('user', $_REQUEST['user_id'])))
532 return buildRedirectURL (__FUNCTION__
, 'ERR1');
533 // Update user password only if provided password is not the same as current password hash.
534 if ($new_password != $userinfo['user_password_hash'])
535 $new_password = sha1 ($new_password);
536 $result = commitUpdateUserAccount ($_REQUEST['user_id'], $username, $_REQUEST['realname'], $new_password);
537 if ($result !== FALSE)
538 return buildRedirectURL (__FUNCTION__
, 'OK', array ($username));
540 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($username));
543 $msgcode['updateDictionary']['OK'] = 51;
544 $msgcode['updateDictionary']['ERR'] = 109;
545 function updateDictionary ()
547 assertUIntArg ('chapter_no');
548 assertUIntArg ('dict_key');
549 assertStringArg ('dict_value');
550 if (FALSE !== commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value']))
551 return buildRedirectURL (__FUNCTION__
, 'OK');
553 return buildRedirectURL (__FUNCTION__
, 'ERR');
556 $msgcode['supplementDictionary']['OK'] = 52;
557 $msgcode['supplementDictionary']['ERR'] = 110;
558 function supplementDictionary ()
560 assertUIntArg ('chapter_no');
561 assertStringArg ('dict_value');
562 if (commitSupplementDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_value']) === TRUE)
563 return buildRedirectURL (__FUNCTION__
, 'OK');
565 return buildRedirectURL (__FUNCTION__
, 'ERR');
568 $msgcode['reduceDictionary']['OK'] = 50;
569 $msgcode['reduceDictionary']['ERR'] = 111;
570 function reduceDictionary ()
572 assertUIntArg ('chapter_no');
573 assertUIntArg ('dict_key');
574 if (commitReduceDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key']) === TRUE)
575 return buildRedirectURL (__FUNCTION__
, 'OK');
577 return buildRedirectURL (__FUNCTION__
, 'ERR');
580 $msgcode['addChapter']['OK'] = 55;
581 $msgcode['addChapter']['ERR'] = 112;
582 function addChapter ()
584 assertStringArg ('chapter_name');
585 if (commitAddChapter ($_REQUEST['chapter_name']) === TRUE)
586 return buildRedirectURL (__FUNCTION__
, 'OK');
588 return buildRedirectURL (__FUNCTION__
, 'ERR');
591 $msgcode['updateChapter']['OK'] = 54;
592 $msgcode['updateChapter']['ERR'] = 113;
593 function updateChapter ()
595 assertUIntArg ('chapter_no');
596 assertStringArg ('chapter_name');
597 if (FALSE !== commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name']))
598 return buildRedirectURL (__FUNCTION__
, 'OK');
600 return buildRedirectURL (__FUNCTION__
, 'ERR');
603 $msgcode['delChapter']['OK'] = 53;
604 $msgcode['delChapter']['ERR'] = 114;
605 function delChapter ()
607 assertUIntArg ('chapter_no');
608 if (commitDeleteChapter ($_REQUEST['chapter_no']))
609 return buildRedirectURL (__FUNCTION__
, 'OK');
611 return buildRedirectURL (__FUNCTION__
, 'ERR');
614 $msgcode['changeAttribute']['OK'] = 46;
615 $msgcode['changeAttribute']['ERR'] = 115;
616 function changeAttribute ()
618 assertUIntArg ('attr_id');
619 assertStringArg ('attr_name');
620 if (FALSE !== commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name']))
621 return buildRedirectURL (__FUNCTION__
, 'OK');
623 return buildRedirectURL (__FUNCTION__
, 'ERR');
626 $msgcode['createAttribute']['OK'] = 45;
627 $msgcode['createAttribute']['ERR'] = 116;
628 function createAttribute ()
630 assertStringArg ('attr_name');
631 assertStringArg ('attr_type');
632 if (commitAddAttribute ($_REQUEST['attr_name'], $_REQUEST['attr_type']))
633 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['attr_name']));
635 return buildRedirectURL (__FUNCTION__
, 'ERR');
638 $msgcode['deleteAttribute']['OK'] = 47;
639 $msgcode['deleteAttribute']['ERR'] = 117;
640 function deleteAttribute ()
642 assertUIntArg ('attr_id');
643 if (commitDeleteAttribute ($_REQUEST['attr_id']))
644 return buildRedirectURL (__FUNCTION__
, 'OK');
646 return buildRedirectURL (__FUNCTION__
, 'ERR');
649 $msgcode['supplementAttrMap']['OK'] = 48;
650 $msgcode['supplementAttrMap']['ERR1'] = 154;
651 $msgcode['supplementAttrMap']['ERR2'] = 118;
652 function supplementAttrMap ()
654 assertUIntArg ('attr_id');
655 assertUIntArg ('objtype_id');
656 $attrMap = getAttrMap();
657 if ($attrMap[$_REQUEST['attr_id']]['type'] != 'dict')
663 assertUIntArg ('chapter_no');
665 catch (InvalidRequestArgException
$e)
667 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ('chapter not selected'));
669 $chapter_id = $_REQUEST['chapter_no'];
671 if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $chapter_id) !== FALSE)
672 return buildRedirectURL (__FUNCTION__
, 'OK');
674 return buildRedirectURL (__FUNCTION__
, 'ERR2');
677 $msgcode['reduceAttrMap']['OK'] = 49;
678 $msgcode['reduceAttrMap']['ERR'] = 119;
679 function reduceAttrMap ()
681 assertUIntArg ('attr_id');
682 assertUIntArg ('objtype_id');
683 if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) !== FALSE)
684 return buildRedirectURL (__FUNCTION__
, 'OK');
686 return buildRedirectURL (__FUNCTION__
, 'ERR');
689 $msgcode['clearSticker']['OK'] = 15;
690 $msgcode['clearSticker']['ERR'] = 120;
691 function clearSticker ()
693 assertUIntArg ('attr_id');
694 assertUIntArg ('object_id');
695 if (commitResetAttrValue ($_REQUEST['object_id'], $_REQUEST['attr_id']) !== FALSE)
696 return buildRedirectURL (__FUNCTION__
, 'OK');
698 return buildRedirectURL (__FUNCTION__
, 'ERR');
701 $msgcode['updateObjectAllocation']['OK'] = 63;
702 function updateObjectAllocation ()
704 assertUIntArg ('object_id');
706 if (!isset ($_REQUEST['got_atoms']))
708 unset($_GET['page']);
711 unset($_POST['page']);
712 unset($_POST['tab']);
714 return buildWideRedirectURL (array(), NULL, NULL, array_merge ($_GET, $_POST));
716 $object_id = $_REQUEST['object_id'];
717 $workingRacksData = array();
718 foreach ($_REQUEST['rackmulti'] as $cand_id)
720 if (!isset ($workingRacksData[$cand_id]))
722 $rackData = spotEntity ('rack', $cand_id);
723 amplifyCell ($rackData);
724 $workingRacksData[$cand_id] = $rackData;
728 foreach ($workingRacksData as &$rd)
729 applyObjectMountMask ($rd, $object_id);
731 $oldMolecule = getMoleculeForObject ($object_id);
734 foreach ($workingRacksData as $rack_id => $rackData)
736 $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
738 if ($logrecord['code'] == 300)
741 // Reload our working copy after form processing.
742 $rackData = spotEntity ('rack', $cand_id);
743 amplifyCell ($rackData);
744 applyObjectMountMask ($rackData, $object_id);
745 $workingRacksData[$rack_id] = $rackData;
748 return buildRedirectURL (__FUNCTION__
, 'OK', $changecnt);
750 $newMolecule = getMoleculeForObject ($object_id);
751 $oc = count ($oldMolecule);
752 $nc = count ($newMolecule);
753 $omid = $oc ?
createMolecule ($oldMolecule) : 'NULL';
754 $nmid = $nc ?
createMolecule ($newMolecule) : 'NULL';
755 global $remote_username;
756 $comment = empty ($_REQUEST['comment']) ?
'NULL' : "'${_REQUEST['comment']}'";
758 "insert into MountOperation(object_id, old_molecule_id, new_molecule_id, user_name, comment) " .
759 "values (${object_id}, ${omid}, ${nmid}, '${remote_username}', ${comment})";
761 $result = $dbxlink->query ($query);
763 $log[] = array ('code' => 500, 'message' => 'SQL query failed during history logging.');
765 $log[] = array ('code' => 200, 'message' => 'History logged.');
766 return buildWideRedirectURL ($log);
769 $msgcode['updateObject']['OK'] = 16;
770 $msgcode['updateObject']['ERR'] = 121;
771 function updateObject ()
773 assertUIntArg ('num_attrs', TRUE);
774 assertUIntArg ('object_id');
775 assertUIntArg ('object_type_id');
776 assertStringArg ('object_name', TRUE);
777 assertStringArg ('object_label', TRUE);
778 assertStringArg ('object_barcode', TRUE);
779 assertStringArg ('object_asset_no', TRUE);
780 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
781 $has_problems = 'yes';
783 $has_problems = 'no';
785 if (commitUpdateObject (
786 $_REQUEST['object_id'],
787 $_REQUEST['object_name'],
788 $_REQUEST['object_label'],
789 $_REQUEST['object_barcode'],
790 $_REQUEST['object_type_id'],
792 $_REQUEST['object_asset_no'],
793 $_REQUEST['object_comment']
795 return buildRedirectURL (__FUNCTION__
, 'ERR');
797 // Update optional attributes
798 $oldvalues = getAttrValues ($_REQUEST['object_id']);
800 $num_attrs = isset ($_REQUEST['num_attrs']) ?
$_REQUEST['num_attrs'] : 0;
801 for ($i = 0; $i < $num_attrs; $i++
)
803 assertUIntArg ("${i}_attr_id");
804 $attr_id = $_REQUEST["${i}_attr_id"];
806 // 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
807 if (!strlen ($_REQUEST["${i}_value"]) ||
($oldvalues[$attr_id]['type']=='dict' && $_REQUEST["${i}_value"] == 0))
809 commitResetAttrValue ($_REQUEST['object_id'], $attr_id);
813 // The value could be uint/float, but we don't know ATM. Let SQL
814 // server check this and complain.
815 assertStringArg ("${i}_value");
816 $value = $_REQUEST["${i}_value"];
817 switch ($oldvalues[$attr_id]['type'])
822 $oldvalue = $oldvalues[$attr_id]['value'];
825 $oldvalue = $oldvalues[$attr_id]['key'];
829 if ($value === $oldvalue) // ('' == 0), but ('' !== 0)
832 // Note if the queries succeed or not, it determines which page they see.
833 $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value);
835 if (in_array (FALSE, $result))
836 return buildRedirectURL (__FUNCTION__
, 'ERR');
838 // Invalidate thumb cache of all racks objects could occupy.
839 foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id)
840 resetThumbCache ($rack_id);
842 return buildRedirectURL (__FUNCTION__
, 'OK');
846 function addMultipleObjects()
849 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
850 $max = getConfigVar ('MASSCOUNT');
851 for ($i = 0; $i < $max; $i++
)
853 if (!isset ($_REQUEST["${i}_object_type_id"]))
855 $log = mergeLogs ($log, oneLiner (184, array ($i +
1)));
858 assertUIntArg ("${i}_object_type_id", TRUE);
859 assertStringArg ("${i}_object_name", TRUE);
860 assertStringArg ("${i}_object_label", TRUE);
861 assertStringArg ("${i}_object_asset_no", TRUE);
862 assertStringArg ("${i}_object_barcode", TRUE);
863 $name = $_REQUEST["${i}_object_name"];
865 // It's better to skip silently, than to print a notice.
866 if ($_REQUEST["${i}_object_type_id"] == 0)
868 if (($object_id = commitAddObject
871 $_REQUEST["${i}_object_label"],
872 $_REQUEST["${i}_object_barcode"],
873 $_REQUEST["${i}_object_type_id"],
874 $_REQUEST["${i}_object_asset_no"],
877 $info = spotEntity ('object', $object_id);
878 // FIXME: employ amplifyCell() instead of calling loader functions directly
880 $log = mergeLogs ($log, oneLiner (80, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>')));
882 $log = mergeLogs ($log, oneLiner (185, array ($name)));
885 return buildWideRedirectURL ($log);
888 function addLotOfObjects()
891 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
892 assertUIntArg ('global_type_id', TRUE);
893 assertStringArg ('namelist', TRUE);
894 $global_type_id = $_REQUEST['global_type_id'];
895 if ($global_type_id == 0 or !strlen ($_REQUEST['namelist']))
896 $log = mergeLogs ($log, oneLiner (186));
899 // The name extractor below was stolen from ophandlers.php:addMultiPorts()
900 $names1 = explode ("\n", $_REQUEST['namelist']);
902 foreach ($names1 as $line)
904 $parts = explode ('\r', $line);
906 if (!strlen ($parts[0]))
909 $names2[] = rtrim ($parts[0]);
911 foreach ($names2 as $name)
912 if (($object_id = commitAddObject ($name, '', '', $global_type_id, '', $taglist)) !== FALSE)
914 $info = spotEntity ('object', $object_id);
916 $log = mergeLogs ($log, oneLiner (80, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>')));
919 $log = mergeLogs ($log, oneLiner (185, array ($name)));
921 return buildWideRedirectURL ($log);
924 $msgcode['deleteObject']['OK'] = 76;
925 $msgcode['deleteObject']['ERR'] = 100;
926 function deleteObject ()
928 assertUIntArg ('object_id');
929 if (NULL === ($oinfo = spotEntity ('object', $_REQUEST['object_id'])))
930 return buildRedirectURL (__FUNCTION__
, 'ERR', array ('object not found'));
932 $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE);
933 $error = commitDeleteObject ($_REQUEST['object_id']);
934 foreach ($racklist as $rack_id)
935 resetThumbCache ($rack_id);
938 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
940 return buildRedirectURL (__FUNCTION__
, 'OK', array ($oinfo['dname']));
943 $msgcode['useupPort']['OK'] = 11;
944 $msgcode['useupPort']['ERR'] = 124;
945 function useupPort ()
947 assertUIntArg ('port_id');
948 if (FALSE !== commitUseupPort ($_REQUEST['port_id']))
949 return buildRedirectURL (__FUNCTION__
, 'OK');
951 return buildRedirectURL (__FUNCTION__
, 'ERR');
954 $msgcode['updateUI']['OK'] = 56;
957 assertUIntArg ('num_vars');
959 for ($i = 0; $i < $_REQUEST['num_vars']; $i++
)
961 assertStringArg ("${i}_varname");
962 assertStringArg ("${i}_varvalue", TRUE);
963 $varname = $_REQUEST["${i}_varname"];
964 $varvalue = $_REQUEST["${i}_varvalue"];
966 // If form value = value in DB, don't bother updating DB
967 if (!isConfigVarChanged($varname, $varvalue))
969 // any exceptions will be handled by process.php
970 setConfigVar ($varname, $varvalue, TRUE);
972 return buildRedirectURL (__FUNCTION__
, 'OK');
975 $msgcode['saveMyPreferences']['OK'] = 56;
976 function saveMyPreferences ()
978 assertUIntArg ('num_vars');
980 for ($i = 0; $i < $_REQUEST['num_vars']; $i++
)
982 assertStringArg ("${i}_varname");
983 assertStringArg ("${i}_varvalue", TRUE);
984 $varname = $_REQUEST["${i}_varname"];
985 $varvalue = $_REQUEST["${i}_varvalue"];
987 // If form value = value in DB, don't bother updating DB
988 if (!isConfigVarChanged($varname, $varvalue))
990 setUserConfigVar ($varname, $varvalue);
992 return buildRedirectURL (__FUNCTION__
, 'OK');
995 $msgcode['resetMyPreference']['OK'] = 56;
996 function resetMyPreference ()
998 assertStringArg ("varname");
999 resetUserConfigVar ($_REQUEST["varname"]);
1000 return buildRedirectURL (__FUNCTION__
, 'OK');
1003 $msgcode['resetUIConfig']['OK'] = 57;
1004 function resetUIConfig()
1006 setConfigVar ('MASSCOUNT','15');
1007 setConfigVar ('MAXSELSIZE','30');
1008 setConfigVar ('ROW_SCALE','2');
1009 setConfigVar ('PORTS_PER_ROW','12');
1010 setConfigVar ('IPV4_ADDRS_PER_PAGE','256');
1011 setConfigVar ('DEFAULT_RACK_HEIGHT','42');
1012 setConfigVar ('DEFAULT_SLB_VS_PORT','');
1013 setConfigVar ('DEFAULT_SLB_RS_PORT','');
1014 setConfigVar ('DETECT_URLS','no');
1015 setConfigVar ('RACK_PRESELECT_THRESHOLD','1');
1016 setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no');
1017 setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm');
1018 setConfigVar ('SHOW_EXPLICIT_TAGS','yes');
1019 setConfigVar ('SHOW_IMPLICIT_TAGS','yes');
1020 setConfigVar ('SHOW_AUTOMATIC_TAGS','no');
1021 setConfigVar ('DEFAULT_OBJECT_TYPE','4');
1022 setConfigVar ('IPV4_AUTO_RELEASE','1');
1023 setConfigVar ('SHOW_LAST_TAB', 'no');
1024 setConfigVar ('EXT_IPV4_VIEW', 'yes');
1025 setConfigVar ('TREE_THRESHOLD', '25');
1026 setConfigVar ('IPV4_JAYWALK', 'no');
1027 setConfigVar ('ADDNEW_AT_TOP', 'yes');
1028 setConfigVar ('IPV4_TREE_SHOW_USAGE', 'yes');
1029 setConfigVar ('PREVIEW_TEXT_MAXCHARS', '10240');
1030 setConfigVar ('PREVIEW_TEXT_ROWS', '25');
1031 setConfigVar ('PREVIEW_TEXT_COLS', '80');
1032 setConfigVar ('PREVIEW_IMAGE_MAXPXS', '320');
1033 setConfigVar ('VENDOR_SIEVE', '');
1034 setConfigVar ('IPV4LB_LISTSRC', '{$typeid_4}');
1035 setConfigVar ('IPV4OBJ_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_12} or {$typeid_445} or {$typeid_447} or {$typeid_798}');
1036 setConfigVar ('IPV4NAT_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_798}');
1037 setConfigVar ('ASSETWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1038 setConfigVar ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1039 setConfigVar ('RACKS_PER_ROW','12');
1040 setConfigVar ('FILTER_PREDICATE_SIEVE','');
1041 setConfigVar ('FILTER_DEFAULT_ANDOR','or');
1042 setConfigVar ('FILTER_SUGGEST_ANDOR','yes');
1043 setConfigVar ('FILTER_SUGGEST_TAGS','yes');
1044 setConfigVar ('FILTER_SUGGEST_PREDICATES','yes');
1045 setConfigVar ('FILTER_SUGGEST_EXTRA','no');
1046 setConfigVar ('DEFAULT_SNMP_COMMUNITY','public');
1047 setConfigVar ('IPV4_ENABLE_KNIGHT','yes');
1048 setConfigVar ('TAGS_TOPLIST_SIZE','50');
1049 setConfigVar ('TAGS_QUICKLIST_SIZE','20');
1050 setConfigVar ('TAGS_QUICKLIST_THRESHOLD','50');
1051 setConfigVar ('ENABLE_MULTIPORT_FORM', 'no');
1052 setConfigVar ('DEFAULT_PORT_IIF_ID', '1');
1053 setConfigVar ('DEFAULT_PORT_OIF_IDS', '1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084');
1054 setConfigVar ('IPV4_TREE_RTR_AS_CELL', 'yes');
1055 setConfigVar ('PROXIMITY_RANGE', 0);
1056 setConfigVar ('IPV4_TREE_SHOW_VLAN', 'yes');
1057 setConfigVar ('VLANSWITCH_LISTSRC', '');
1058 setConfigVar ('VLANIPV4NET_LISTSRC', '');
1059 setConfigVar ('DEFAULT_VDOM_ID', '');
1060 setConfigVar ('DEFAULT_VST_ID', '');
1061 setConfigVar ('STATIC_FILTER', 'yes');
1062 setConfigVar ('8021Q_DEPLOY_MINAGE', '300');
1063 setConfigVar ('8021Q_DEPLOY_MAXAGE', '3600');
1064 setConfigVar ('8021Q_DEPLOY_RETRY', '10800');
1065 setConfigVar ('8021Q_WRI_AFTER_CONFT_LISTSRC', 'false');
1066 setConfigVar ('8021Q_INSTANT_DEPLOY', 'no');
1067 setConfigVar ('CDP_RUNNERS_LISTSRC', '');
1068 setConfigVar ('LLDP_RUNNERS_LISTSRC', '');
1069 setConfigVar ('HNDP_RUNNERS_LISTSRC', '');
1070 return buildRedirectURL (__FUNCTION__
, 'OK');
1073 $msgcode['addRealServer']['OK'] = 34;
1074 $msgcode['addRealServer']['ERR'] = 126;
1075 // Add single record.
1076 function addRealServer ()
1078 assertUIntArg ('pool_id');
1079 assertIPv4Arg ('remoteip');
1080 assertStringArg ('rsport', TRUE);
1081 assertStringArg ('rsconfig', TRUE);
1082 if (!addRStoRSPool (
1083 $_REQUEST['pool_id'],
1084 $_REQUEST['remoteip'],
1085 $_REQUEST['rsport'],
1086 getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'),
1087 $_REQUEST['rsconfig']
1089 return buildRedirectURL (__FUNCTION__
, 'ERR');
1091 return buildRedirectURL (__FUNCTION__
, 'OK');
1094 $msgcode['addRealServers']['OK'] = 37;
1095 $msgcode['addRealServers']['ERR1'] = 131;
1096 $msgcode['addRealServers']['ERR2'] = 127;
1097 // Parse textarea submitted and try adding a real server for each line.
1098 function addRealServers ()
1100 assertUIntArg ('pool_id');
1101 assertStringArg ('format');
1102 assertStringArg ('rawtext');
1105 // Keep in mind, that the text will have HTML entities (namely '>') escaped.
1106 foreach (explode ("\n", dos2unix ($_REQUEST['rawtext'])) as $line)
1108 if (!strlen ($line))
1111 switch ($_REQUEST['format'])
1113 case 'ipvs_2': // address and port only
1114 if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) /', $line, $match))
1116 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1121 case 'ipvs_3': // address, port and weight
1122 if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match))
1124 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3]))
1129 case 'ssv_2': // IP address and port
1130 if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match))
1132 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1137 case 'ssv_1': // IP address
1138 if (!preg_match ('/^([0-9\.]+)$/', $line, $match))
1140 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1146 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1150 if ($nbad == 0 and $ngood > 0)
1151 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1153 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($ngood, $nbad));
1156 $msgcode['addVService']['OK'] = 28;
1157 $msgcode['addVService']['ERR1'] = 132;
1158 $msgcode['addVService']['ERR2'] = 100;
1159 function addVService ()
1161 assertIPv4Arg ('vip');
1162 assertUIntArg ('vport');
1163 assertStringArg ('proto');
1164 if ($_REQUEST['proto'] != 'TCP' and $_REQUEST['proto'] != 'UDP')
1165 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1166 assertStringArg ('name', TRUE);
1167 assertStringArg ('vsconfig', TRUE);
1168 assertStringArg ('rsconfig', TRUE);
1169 $error = commitCreateVS
1175 $_REQUEST['vsconfig'],
1176 $_REQUEST['rsconfig'],
1177 isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array()
1180 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
1182 return buildRedirectURL (__FUNCTION__
, 'OK');
1185 $msgcode['deleteRealServer']['OK'] = 35;
1186 $msgcode['deleteRealServer']['ERR'] = 128;
1187 function deleteRealServer ()
1189 assertUIntArg ('id');
1190 if (!commitDeleteRS ($_REQUEST['id']))
1191 return buildRedirectURL (__FUNCTION__
, 'ERR');
1193 return buildRedirectURL (__FUNCTION__
, 'OK');
1196 $msgcode['deleteLoadBalancer']['OK'] = 19;
1197 $msgcode['deleteLoadBalancer']['ERR'] = 129;
1198 function deleteLoadBalancer ()
1200 assertUIntArg ('object_id');
1201 assertUIntArg ('pool_id');
1202 assertUIntArg ('vs_id');
1203 if (!commitDeleteLB (
1204 $_REQUEST['object_id'],
1205 $_REQUEST['pool_id'],
1208 return buildRedirectURL (__FUNCTION__
, 'ERR');
1210 return buildRedirectURL (__FUNCTION__
, 'OK');
1213 $msgcode['deleteVService']['OK'] = 29;
1214 $msgcode['deleteVService']['ERR'] = 130;
1215 function deleteVService ()
1217 assertUIntArg ('vs_id');
1218 if (!commitDeleteVS ($_REQUEST['vs_id']))
1219 return buildRedirectURL (__FUNCTION__
, 'ERR');
1221 return buildRedirectURL (__FUNCTION__
, 'OK');
1224 $msgcode['updateRealServer']['OK'] = 36;
1225 $msgcode['updateRealServer']['ERR'] = 133;
1226 function updateRealServer ()
1228 assertUIntArg ('rs_id');
1229 assertIPv4Arg ('rsip');
1230 assertStringArg ('rsport', TRUE);
1231 assertStringArg ('rsconfig', TRUE);
1232 if (FALSE === commitUpdateRS (
1235 $_REQUEST['rsport'],
1236 $_REQUEST['rsconfig']
1238 return buildRedirectURL (__FUNCTION__
, 'ERR');
1240 return buildRedirectURL (__FUNCTION__
, 'OK');
1243 $msgcode['updateLoadBalancer']['OK'] = 20;
1244 $msgcode['updateLoadBalancer']['ERR'] = 134;
1245 function updateLoadBalancer ()
1247 assertUIntArg ('object_id');
1248 assertUIntArg ('pool_id');
1249 assertUIntArg ('vs_id');
1250 assertStringArg ('vsconfig', TRUE);
1251 assertStringArg ('rsconfig', TRUE);
1252 if (FALSE === commitUpdateLB (
1253 $_REQUEST['object_id'],
1254 $_REQUEST['pool_id'],
1256 $_REQUEST['vsconfig'],
1257 $_REQUEST['rsconfig']
1259 return buildRedirectURL (__FUNCTION__
, 'ERR');
1261 return buildRedirectURL (__FUNCTION__
, 'OK');
1264 $msgcode['updateVService']['OK'] = 30;
1265 $msgcode['updateVService']['ERR'] = 135;
1266 function updateVService ()
1268 assertUIntArg ('vs_id');
1269 assertIPv4Arg ('vip');
1270 assertUIntArg ('vport');
1271 assertStringArg ('proto');
1272 assertStringArg ('name', TRUE);
1273 assertStringArg ('vsconfig', TRUE);
1274 assertStringArg ('rsconfig', TRUE);
1275 if (FALSE === commitUpdateVS (
1281 $_REQUEST['vsconfig'],
1282 $_REQUEST['rsconfig']
1284 return buildRedirectURL (__FUNCTION__
, 'ERR');
1286 return buildRedirectURL (__FUNCTION__
, 'OK');
1289 $msgcode['addLoadBalancer']['OK'] = 18;
1290 $msgcode['addLoadBalancer']['ERR'] = 137;
1291 function addLoadBalancer ()
1293 assertUIntArg ('pool_id');
1294 assertUIntArg ('object_id');
1295 assertUIntArg ('vs_id');
1296 assertStringArg ('vsconfig', TRUE);
1297 assertStringArg ('rsconfig', TRUE);
1298 if (!addLBtoRSPool (
1299 $_REQUEST['pool_id'],
1300 $_REQUEST['object_id'],
1302 $_REQUEST['vsconfig'],
1303 $_REQUEST['rsconfig']
1305 return buildRedirectURL (__FUNCTION__
, 'ERR');
1307 return buildRedirectURL (__FUNCTION__
, 'OK');
1310 $msgcode['addRSPool']['OK'] = 31;
1311 $msgcode['addRSPool']['ERR'] = 100;
1312 function addRSPool ()
1314 assertStringArg ('name', TRUE);
1315 assertStringArg ('vsconfig', TRUE);
1316 assertStringArg ('rsconfig', TRUE);
1317 $error = commitCreateRSPool
1320 $_REQUEST['vsconfig'],
1321 $_REQUEST['rsconfig'],
1322 isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array()
1325 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1327 return buildRedirectURL (__FUNCTION__
, 'OK');
1330 $msgcode['deleteRSPool']['OK'] = 32;
1331 $msgcode['deleteRSPool']['ERR'] = 138;
1332 function deleteRSPool ()
1334 assertUIntArg ('pool_id');
1335 if (commitDeleteRSPool ($_REQUEST['pool_id']) === FALSE)
1336 return buildRedirectURL (__FUNCTION__
, 'ERR');
1338 return buildRedirectURL (__FUNCTION__
, 'OK');
1341 $msgcode['updateRSPool']['OK'] = 33;
1342 $msgcode['updateRSPool']['ERR'] = 139;
1343 function updateRSPool ()
1345 assertUIntArg ('pool_id');
1346 assertStringArg ('name', TRUE);
1347 assertStringArg ('vsconfig', TRUE);
1348 assertStringArg ('rsconfig', TRUE);
1349 if (FALSE === commitUpdateRSPool ($_REQUEST['pool_id'], $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
1350 return buildRedirectURL (__FUNCTION__
, 'ERR');
1352 return buildRedirectURL (__FUNCTION__
, 'OK');
1355 $msgcode['updateRSInService']['OK'] = 38;
1356 $msgcode['updateRSInService']['ERR'] = 140;
1357 function updateRSInService ()
1359 assertUIntArg ('rscount');
1360 $pool_id = $_REQUEST['pool_id'];
1361 $orig = spotEntity ('ipv4rspool', $pool_id);
1362 amplifyCell ($orig);
1364 for ($i = 1; $i <= $_REQUEST['rscount']; $i++
)
1366 $rs_id = $_REQUEST["rsid_${i}"];
1367 if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on')
1371 if ($newval != $orig['rslist'][$rs_id]['inservice'])
1373 if (FALSE !== commitSetInService ($rs_id, $newval))
1380 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1382 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($nbad, $ngood));
1385 $msgcode['importPTRData']['OK'] = 26;
1386 $msgcode['importPTRData']['ERR'] = 141;
1387 // FIXME: check, that each submitted address belongs to the prefix we
1388 // are operating on.
1389 function importPTRData ()
1391 assertUIntArg ('addrcount');
1393 for ($i = 0; $i < $_REQUEST['addrcount']; $i++
)
1395 $inputname = "import_${i}";
1396 if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on')
1398 assertIPv4Arg ("addr_${i}");
1399 assertStringArg ("descr_${i}", TRUE);
1400 assertStringArg ("rsvd_${i}");
1401 // Non-existent addresses will not have this argument set in request.
1403 if ($_REQUEST["rsvd_${i}"] == 'yes')
1405 if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '')
1411 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1413 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($nbad, $ngood));
1416 $msgcode['generateAutoPorts']['OK'] = 21;
1417 $msgcode['generateAutoPorts']['ERR'] = 142;
1418 function generateAutoPorts ()
1421 assertUIntArg ('object_id');
1422 $info = spotEntity ('object', $_REQUEST['object_id']);
1423 // Navigate away in case of success, stay at the place otherwise.
1424 if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id']))
1425 return buildRedirectURL (__FUNCTION__
, 'OK', array(), $pageno, 'ports');
1427 return buildRedirectURL (__FUNCTION__
, 'ERR');
1430 $msgcode['saveEntityTags']['OK'] = 22;
1431 $msgcode['saveEntityTags']['ERR1'] = 143;
1432 $msgcode['saveEntityTags']['ERR2'] = 187;
1433 // Filter out implicit tags before storing the new tag set.
1434 function saveEntityTags ()
1436 global $page, $pageno, $etype_by_pageno;
1437 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1438 return buildRedirectURL (__FUNCTION__
, 'ERR2', array (__FUNCTION__
));
1439 $realm = $etype_by_pageno[$pageno];
1440 $bypass = $page[$pageno]['bypass'];
1441 assertUIntArg ($bypass);
1442 $entity_id = $_REQUEST[$bypass];
1443 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1444 // Build a chain from the submitted data, minimize it,
1445 // then wipe existing records and store the new set instead.
1446 destroyTagsForEntity ($realm, $entity_id);
1447 // TODO: these actions are very close to what rebuildTagChainForEntity() does,
1448 // so why not use it?
1449 $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist));
1450 $n_succeeds = $n_errors = 0;
1451 foreach ($newchain as $taginfo)
1452 if (addTagForEntity ($realm, $entity_id, $taginfo['id']))
1457 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($n_succeeds, $n_errors));
1459 return buildRedirectURL (__FUNCTION__
, 'OK', array ($n_succeeds));
1462 $msgcode['destroyTag']['OK'] = 58;
1463 $msgcode['destroyTag']['ERR1'] = 183;
1464 $msgcode['destroyTag']['ERR2'] = 144;
1465 function destroyTag ()
1467 assertUIntArg ('tag_id');
1469 if (!isset ($taglist[$_REQUEST['tag_id']]))
1470 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($_REQUEST['tag_id']));
1471 if (($ret = commitDestroyTag ($_REQUEST['tag_id'])) == '')
1472 return buildRedirectURL (__FUNCTION__
, 'OK', array ($taglist[$_REQUEST['tag_id']]['tag']));
1474 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1477 $msgcode['createTag']['OK'] = 59;
1478 $msgcode['createTag']['ERR1'] = 145;
1479 $msgcode['createTag']['ERR3'] = 147;
1480 function createTag ()
1482 assertStringArg ('tag_name');
1483 assertUIntArg ('parent_id', TRUE);
1484 $tagname = trim ($_REQUEST['tag_name']);
1485 if (!validTagName ($tagname))
1486 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($tagname));
1487 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1489 if (FALSE === commitCreateTag ($tagname, $parent_id))
1490 return buildRedirectURL (__FUNCTION__
, 'ERR3', array (niftyString ($tagname)));
1491 return buildRedirectURL (__FUNCTION__
, 'OK', array (niftyString ($tagname)));
1494 $msgcode['updateTag']['OK'] = 60;
1495 $msgcode['updateTag']['ERR1'] = 145;
1496 $msgcode['updateTag']['ERR2'] = 109;
1497 function updateTag ()
1499 assertUIntArg ('tag_id');
1500 assertUIntArg ('parent_id', TRUE);
1501 assertStringArg ('tag_name');
1502 $tagname = trim ($_REQUEST['tag_name']);
1503 if (!validTagName ($tagname))
1504 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($tagname));
1505 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1506 $parent_id = 'NULL';
1507 if (FALSE !== commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id))
1508 return buildRedirectURL (__FUNCTION__
, 'OK', array ($tagname));
1509 // Use old name in the message, cause update failed.
1511 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($taglist[$_REQUEST['tag_id']]['tag']));
1514 $msgcode['rollTags']['OK'] = 67;
1515 $msgcode['rollTags']['ERR'] = 149;
1516 function rollTags ()
1518 assertUIntArg ('row_id');
1519 assertStringArg ('sum', TRUE);
1520 assertUIntArg ('realsum');
1521 if ($_REQUEST['sum'] != $_REQUEST['realsum'])
1522 return buildRedirectURL (__FUNCTION__
, 'ERR');
1523 // Even if the user requested an empty tag list, don't bail out, but process existing
1524 // tag chains with "zero" extra. This will make sure, that the stuff processed will
1525 // have its chains refined to "normal" form.
1526 $extratags = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1528 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
1529 // filter out the same tag again and again. It will have own noise to cancel.
1530 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
1531 foreach (listCells ('rack', $_REQUEST['row_id']) as $rack)
1533 if (rebuildTagChainForEntity ('rack', $rack['id'], $extrachain))
1535 amplifyCell ($rack);
1536 foreach ($rack['mountedObjects'] as $object_id)
1537 if (rebuildTagChainForEntity ('object', $object_id, $extrachain))
1540 return buildRedirectURL (__FUNCTION__
, 'OK', array ($n_ok));
1543 $msgcode['changeMyPassword']['OK'] = 61;
1544 $msgcode['changeMyPassword']['ERR1'] = 150;
1545 $msgcode['changeMyPassword']['ERR2'] = 151;
1546 $msgcode['changeMyPassword']['ERR3'] = 152;
1547 $msgcode['changeMyPassword']['ERR4'] = 153;
1548 function changeMyPassword ()
1550 global $remote_username, $user_auth_src;
1551 if ($user_auth_src != 'database')
1552 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1553 assertStringArg ('oldpassword');
1554 assertStringArg ('newpassword1');
1555 assertStringArg ('newpassword2');
1556 $remote_userid = getUserIDByUsername ($remote_username);
1557 $userinfo = spotEntity ('user', $remote_userid);
1558 if ($userinfo['user_password_hash'] != sha1 ($_REQUEST['oldpassword']))
1559 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1560 if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2'])
1561 return buildRedirectURL (__FUNCTION__
, 'ERR3');
1562 if (FALSE !== commitUpdateUserAccount ($remote_userid, $userinfo['user_name'], $userinfo['user_realname'], sha1 ($_REQUEST['newpassword1'])))
1563 return buildRedirectURL (__FUNCTION__
, 'OK');
1565 return buildRedirectURL (__FUNCTION__
, 'ERR4');
1568 $msgcode['saveRackCode']['OK'] = 43;
1569 $msgcode['saveRackCode']['ERR1'] = 154;
1570 $msgcode['saveRackCode']['ERR2'] = 155;
1571 function saveRackCode ()
1573 assertStringArg ('rackcode');
1574 // For the test to succeed, unescape LFs, strip CRs.
1575 $newcode = dos2unix ($_REQUEST['rackcode']);
1576 $parseTree = getRackCode ($newcode);
1577 if ($parseTree['result'] != 'ACK')
1578 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($parseTree['load']));
1579 if (FALSE !== saveScript ('RackCode', $newcode))
1581 saveScript ('RackCodeCache', base64_encode (serialize ($parseTree)));
1582 return buildRedirectURL (__FUNCTION__
, 'OK');
1584 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1587 $msgcode['setPortVLAN']['ERR1'] = 156;
1588 // This handler's context is pre-built, but not authorized. It is assumed, that the
1589 // handler will take existing context and before each commit check authorization
1590 // on the base chain plus necessary context added.
1591 function setPortVLAN ()
1593 assertUIntArg ('portcount');
1594 $data = getSwitchVLANs ($_REQUEST['object_id']);
1596 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1597 list ($vlanlist, $portlist) = $data;
1598 // Here we just build up 1 set command for the gateway with all of the ports
1599 // included. The gateway is expected to filter unnecessary changes silently
1600 // and to provide a list of responses with either error or success message
1601 // for each of the rest.
1602 $nports = $_REQUEST['portcount'];
1606 for ($i = 0; $i < $nports; $i++
)
1609 !isset ($_REQUEST['portname_' . $i]) ||
1610 !isset ($_REQUEST['vlanid_' . $i]) ||
1611 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
1613 $log['m'][] = array ('c' => 158, 'a' => array ($i));
1616 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
1617 $portlist[$i]['vlaind'] == 'TRUNK'
1622 $portname = $_REQUEST['portname_' . $i];
1623 $oldvlanid = $portlist[$i]['vlanid'];
1624 $newvlanid = $_REQUEST['vlanid_' . $i];
1627 !permitted (NULL, NULL, NULL, array (array ('tag' => '$fromvlan_' . $oldvlanid))) or
1628 !permitted (NULL, NULL, NULL, array (array ('tag' => '$tovlan_' . $newvlanid)))
1631 $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid));
1634 $setcmd .= $prefix . $portname . '=' . $newvlanid;
1637 // Feed the gateway and interpret its (non)response.
1639 $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd));
1641 $log['m'][] = array ('c' => 201);
1642 return buildWideRedirectURL ($log);
1645 $msgcode['submitSLBConfig']['OK'] = 66;
1646 $msgcode['submitSLBConfig']['ERR'] = 164;
1647 function submitSLBConfig ()
1649 assertUIntArg ('object_id');
1650 $newconfig = buildLVSConfig ($_REQUEST['object_id']);
1653 gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES
, 'UTF-8'));
1655 catch (RTGatewayError
$e)
1657 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($e->getMessage()));
1659 return buildRedirectURL (__FUNCTION__
, 'OK', array ('slbconfig'));
1662 $msgcode['addRow']['OK'] = 74;
1663 $msgcode['addRow']['ERR'] = 100;
1666 assertStringArg ('name');
1668 if (commitAddRow ($_REQUEST['name']) === TRUE)
1669 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1671 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($_REQUEST['name']));
1674 $msgcode['updateRow']['OK'] = 75;
1675 $msgcode['updateRow']['ERR'] = 100;
1676 function updateRow ()
1678 assertUIntArg ('row_id');
1679 assertStringArg ('name');
1681 if (FALSE !== commitUpdateRow ($_REQUEST['row_id'], $_REQUEST['name']))
1682 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1684 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($_REQUEST['name']));
1687 $msgcode['deleteRow']['OK'] = 77;
1688 $msgcode['deleteRow']['ERR'] = 146;
1689 function deleteRow ()
1691 assertUIntArg ('row_id');
1692 $rowinfo = getRackRowInfo ($_REQUEST['row_id']);
1693 return buildRedirectURL (__FUNCTION__
, FALSE === commitDeleteRow ($_REQUEST['row_id']) ?
'ERR' : 'OK', array ($rowinfo['name']));
1696 $msgcode['addRack']['OK'] = 65;
1697 $msgcode['addRack']['ERR1'] = 171;
1698 $msgcode['addRack']['ERR2'] = 172;
1701 assertUIntArg ('row_id');
1702 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1703 if (isset ($_REQUEST['got_data']))
1705 assertStringArg ('rack_name');
1706 assertUIntArg ('rack_height1');
1707 assertStringArg ('rack_comment', TRUE);
1709 if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
1710 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['rack_name']));
1712 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($_REQUEST['rack_name']));
1714 elseif (isset ($_REQUEST['got_mdata']))
1716 assertUIntArg ('rack_height2');
1717 assertStringArg ('rack_names', TRUE);
1719 // copy-and-paste from renderAddMultipleObjectsForm()
1720 $names1 = explode ("\n", $_REQUEST['rack_names']);
1722 foreach ($names1 as $line)
1724 $parts = explode ('\r', $line);
1726 if (!strlen ($parts[0]))
1729 $names2[] = rtrim ($parts[0]);
1732 foreach ($names2 as $cname)
1733 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE)
1734 $log['m'][] = array ('c' => $msgcode[__FUNCTION__
]['OK'], 'a' => array ($cname));
1736 $log['m'][] = array ('c' => $msgcode[__FUNCTION__
]['ERR1'], 'a' => array ($cname));
1737 return buildWideRedirectURL ($log);
1740 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1743 $msgcode['deleteRack']['OK'] = 79;
1744 $msgcode['deleteRack']['ERR'] = 100;
1745 $msgcode['deleteRack']['ERR1'] = 206;
1746 function deleteRack ()
1748 assertUIntArg ('rack_id');
1749 if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id'])))
1750 return buildRedirectURL (__FUNCTION__
, 'ERR', array ('Rack not found'), 'rackspace', 'default');
1751 amplifyCell ($rackData);
1752 if (count ($rackData['mountedObjects']))
1753 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1754 if (TRUE !== commitDeleteRack ($_REQUEST['rack_id']))
1755 return buildRedirectURL (__FUNCTION__
, 'ERR', array(), 'rackspace', 'default');
1756 return buildRedirectURL (__FUNCTION__
, 'OK', array ($rackData['name']), 'rackspace', 'default');
1759 $msgcode['updateRack']['OK'] = 68;
1760 $msgcode['updateRack']['ERR'] = 177;
1761 function updateRack ()
1763 assertUIntArg ('rack_id');
1764 assertUIntArg ('rack_row_id');
1765 assertUIntArg ('rack_height');
1766 assertStringArg ('rack_name');
1767 assertStringArg ('rack_comment', TRUE);
1769 resetThumbCache ($_REQUEST['rack_id']);
1770 if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
1771 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['rack_name']));
1773 return buildRedirectURL (__FUNCTION__
, 'ERR');
1776 function updateRackDesign ()
1778 assertUIntArg ('rack_id');
1779 $rackData = spotEntity ('rack', $_REQUEST['rack_id']);
1780 amplifyCell ($rackData);
1781 applyRackDesignMask($rackData);
1782 markupObjectProblems ($rackData);
1783 $response = processGridForm ($rackData, 'A', 'F');
1784 return buildWideRedirectURL (array($response));
1787 function updateRackProblems ()
1789 assertUIntArg ('rack_id');
1790 $rackData = spotEntity ('rack', $_REQUEST['rack_id']);
1791 amplifyCell ($rackData);
1792 applyRackProblemMask($rackData);
1793 markupObjectProblems ($rackData);
1794 $response = processGridForm ($rackData, 'F', 'U');
1795 return buildWideRedirectURL (array($response));
1798 function querySNMPData ()
1800 assertUIntArg ('object_id');
1801 assertStringArg ('community');
1802 return doSNMPmining ($_REQUEST['object_id'], $_REQUEST['community']);
1805 $msgcode['addFileWithoutLink']['OK'] = 69;
1806 $msgcode['addFileWithoutLink']['ERR1'] = 181;
1807 $msgcode['addFileWithoutLink']['ERR2'] = 110;
1808 // File-related functions
1809 function addFileWithoutLink ()
1811 assertStringArg ('comment', TRUE);
1813 // Make sure the file can be uploaded
1814 if (get_cfg_var('file_uploads') != 1)
1815 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1817 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1819 if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']))
1820 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1821 if (isset ($_REQUEST['taglist']))
1822 produceTagsForLastRecord ('file', $_REQUEST['taglist']);
1823 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($_FILES['file']['name'])));
1826 $msgcode['addFileToEntity']['OK'] = 69;
1827 $msgcode['addFileToEntity']['ERR2'] = 181;
1828 $msgcode['addFileToEntity']['ERR3'] = 110;
1829 function addFileToEntity ()
1831 global $page, $pageno, $etype_by_pageno;
1832 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1833 throw new RackTablesError ('dispatching failure', RackTablesError
::INTERNAL
);
1834 $realm = $etype_by_pageno[$pageno];
1835 $bypass = $page[$pageno]['bypass'];
1836 assertUIntArg ($bypass);
1837 $entity_id = $_REQUEST[$bypass];
1838 assertStringArg ('comment', TRUE);
1840 // Make sure the file can be uploaded
1841 if (get_cfg_var('file_uploads') != 1)
1842 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1844 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1846 if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']))
1847 return buildRedirectURL (__FUNCTION__
, 'ERR3');
1848 if (FALSE === commitLinkFile (lastInsertID(), $realm, $entity_id))
1849 return buildRedirectURL (__FUNCTION__
, 'ERR3');
1851 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($_FILES['file']['name'])));
1854 $msgcode['linkFileToEntity']['OK'] = 71;
1855 $msgcode['linkFileToEntity']['ERR1'] = 178;
1856 $msgcode['linkFileToEntity']['ERR2'] = 110;
1857 function linkFileToEntity ()
1859 assertUIntArg ('file_id');
1860 global $page, $pageno, $etype_by_pageno;
1861 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1862 throw new RackTablesError ('dispatching failure', RackTablesError
::INTERNAL
);
1863 $entity_type = $etype_by_pageno[$pageno];
1864 $bypass_name = $page[$pageno]['bypass'];
1865 assertUIntArg ($bypass_name);
1867 $fi = spotEntity ('file', $_REQUEST['file_id']);
1868 if (FALSE === commitLinkFile ($_REQUEST['file_id'], $entity_type, $_REQUEST[$bypass_name]))
1869 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1871 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($fi['name'])));
1874 $msgcode['replaceFile']['OK'] = 70;
1875 $msgcode['replaceFile']['ERR1'] = 181;
1876 $msgcode['replaceFile']['ERR2'] = 207;
1877 $msgcode['replaceFile']['ERR3'] = 109;
1878 function replaceFile ()
1881 assertUIntArg ('file_id');
1883 // Make sure the file can be uploaded
1884 if (get_cfg_var('file_uploads') != 1)
1885 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1886 $shortInfo = spotEntity ('file', $sic['file_id']);
1888 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1890 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1891 if (FALSE === commitReplaceFile ($sic['file_id'], $fp))
1892 return buildRedirectURL (__FUNCTION__
, 'ERR3');
1894 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1897 $msgcode['updateFile']['OK'] = 70;
1898 $msgcode['updateFile']['ERR'] = 109;
1899 function updateFile ()
1901 assertUIntArg ('file_id');
1902 assertStringArg ('file_name');
1903 assertStringArg ('file_type');
1904 assertStringArg ('file_comment', TRUE);
1906 if (FALSE === commitUpdateFile ($sic['file_id'], $sic['file_name'], $sic['file_type'], $sic['file_comment']))
1907 return buildRedirectURL (__FUNCTION__
, 'ERR');
1908 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['file_name']));
1911 $msgcode['unlinkFile']['OK'] = 72;
1912 $msgcode['unlinkFile']['ERR'] = 182;
1913 function unlinkFile ()
1915 assertUIntArg ('link_id');
1916 $error = commitUnlinkFile ($_REQUEST['link_id']);
1919 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1921 return buildRedirectURL (__FUNCTION__
, 'OK');
1924 $msgcode['deleteFile']['OK'] = 73;
1925 $msgcode['deleteFile']['ERR'] = 100;
1926 function deleteFile ()
1928 assertUIntArg ('file_id');
1929 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
1930 $error = commitDeleteFile ($_REQUEST['file_id']);
1933 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1935 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1938 $msgcode['updateFileText']['OK'] = 78;
1939 $msgcode['updateFileText']['ERR1'] = 179;
1940 $msgcode['updateFileText']['ERR2'] = 180;
1941 function updateFileText ()
1943 assertUIntArg ('file_id');
1944 assertStringArg ('mtime_copy');
1945 assertStringArg ('file_text', TRUE); // it's Ok to save empty
1946 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
1947 if ($shortInfo['mtime'] != $_REQUEST['mtime_copy'])
1948 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1950 if (FALSE === commitReplaceFile ($sic['file_id'], $sic['file_text']))
1951 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1952 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1955 $msgcode['addPortInterfaceCompat']['OK'] = 48;
1956 $msgcode['addPortInterfaceCompat']['ERR'] = 110;
1957 function addPortInterfaceCompat ()
1959 assertUIntArg ('iif_id');
1960 assertUIntArg ('oif_id');
1961 if (commitSupplementPIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
1962 return buildRedirectURL (__FUNCTION__
, 'OK');
1963 return buildRedirectURL (__FUNCTION__
, 'ERR');
1966 $msgcode['delPortInterfaceCompat']['OK'] = 49;
1967 $msgcode['delPortInterfaceCompat']['ERR'] = 111;
1968 function delPortInterfaceCompat ()
1970 assertUIntArg ('iif_id');
1971 assertUIntArg ('oif_id');
1972 if (commitReducePIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
1973 return buildRedirectURL (__FUNCTION__
, 'OK');
1974 return buildRedirectURL (__FUNCTION__
, 'ERR');
1977 $ifcompatpack = array
1979 '1000cwdm80' => array (1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216),
1980 '1000dwdm80' => array // ITU channels 20~61
1982 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226,
1983 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236,
1984 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246,
1985 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256,
1988 '10000dwdm80' => array // same channels for 10GE
1990 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268,
1991 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278,
1992 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288,
1993 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298,
1998 $msgcode['addPortInterfaceCompatPack']['OK'] = 44;
1999 $msgcode['addPortInterfaceCompatPack']['ERR'] = 123;
2000 function addPortInterfaceCompatPack ()
2002 assertStringArg ('standard');
2003 assertUIntArg ('iif_id');
2004 global $ifcompatpack;
2005 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
2006 return buildRedirectURL (__FUNCTION__
, 'ERR');
2008 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2009 if (commitSupplementPIC ($_REQUEST['iif_id'], $oif_id))
2013 return buildRedirectURL (__FUNCTION__
, 'OK', array ($nbad, $ngood));
2016 $msgcode['delPortInterfaceCompatPack']['OK'] = 44;
2017 $msgcode['delPortInterfaceCompatPack']['ERR'] = 123;
2018 function delPortInterfaceCompatPack ()
2020 assertStringArg ('standard');
2021 assertUIntArg ('iif_id');
2022 global $ifcompatpack;
2023 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
2024 return buildRedirectURL (__FUNCTION__
, 'ERR');
2026 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2027 if (commitReducePIC ($_REQUEST['iif_id'], $oif_id))
2031 return buildRedirectURL (__FUNCTION__
, 'OK', array ($nbad, $ngood));
2034 $msgcode['addPortOIFCompat']['OK'] = 48;
2035 $msgcode['addPortOIFCompat']['ERR'] = 110;
2036 function addPortOIFCompat()
2038 assertUIntArg('type1');
2039 assertUIntArg('type2');
2040 if (commitSupplementPOIFC($_REQUEST['type1'], $_REQUEST['type2']))
2041 return buildRedirectURL(__FUNCTION__
, 'OK');
2042 return buildRedirectURL(__FUNCTION__
, 'ERR');
2045 $msgcode['delPortOIFCompat']['OK'] = 49;
2046 $msgcode['delPortOIFCompat']['ERR'] = 111;
2047 function delPortOIFCompat ()
2049 assertUIntArg('type1');
2050 assertUIntArg('type2');
2051 if (commitReducePOIFC ($_REQUEST['type1'], $_REQUEST['type2']) !== FALSE)
2052 return buildRedirectURL (__FUNCTION__
, 'OK');
2053 return buildRedirectURL (__FUNCTION__
, 'ERR');
2057 $msgcode['add8021QOrder']['OK'] = 48;
2058 $msgcode['add8021QOrder']['ERR'] = 118;
2059 function add8021QOrder ()
2061 assertUIntArg ('vdom_id');
2062 assertUIntArg ('object_id');
2063 assertUIntArg ('vst_id');
2065 $result = usePreparedExecuteBlade
2067 'INSERT INTO VLANSwitch (domain_id, object_id, template_id, last_change, out_of_sync) ' .
2068 'VALUES (?, ?, ?, NOW(), "yes")',
2069 array ($sic['vdom_id'], $sic['object_id'], $sic['vst_id'])
2071 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
2074 $msgcode['del8021QOrder']['OK'] = 49;
2075 $msgcode['del8021QOrder']['ERR'] = 119;
2076 function del8021QOrder ()
2078 assertUIntArg ('object_id');
2080 $result = usePreparedDeleteBlade ('VLANSwitch', array ('object_id' => $sic['object_id']));
2081 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2084 $msgcode['addVLANDescription']['OK'] = 48;
2085 $msgcode['addVLANDescription']['ERR1'] = 190;
2086 $msgcode['addVLANDescription']['ERR2'] = 110;
2087 function addVLANDescription ()
2089 assertUIntArg ('vlan_id');
2090 assertStringArg ('vlan_type', TRUE);
2091 assertStringArg ('vlan_descr', TRUE);
2093 if (!($sic['vlan_id'] >= VLAN_MIN_ID +
1 and $sic['vlan_id'] <= VLAN_MAX_ID
))
2094 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($sic['vlan_id']));
2095 $result = usePreparedInsertBlade
2100 'domain_id' => $sic['vdom_id'],
2101 'vlan_id' => $sic['vlan_id'],
2102 'vlan_type' => $sic['vlan_type'],
2103 'vlan_descr' => mb_strlen ($sic['vlan_descr']) ?
$sic['vlan_descr'] : NULL
2106 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR2');
2109 $msgcode['delVLANDescription']['OK'] = 49;
2110 $msgcode['delVLANDescription']['ERR1'] = 105;
2111 $msgcode['delVLANDescription']['ERR2'] = 111;
2112 function delVLANDescription ()
2114 assertUIntArg ('vlan_id');
2116 if ($sic['vlan_id'] == VLAN_DFL_ID
)
2117 return buildRedirectURL (__FUNCTION__
, 'ERR1');
2118 $result = commitReduceVLANDescription ($sic['vdom_id'], $sic['vlan_id']);
2119 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR2');
2122 $msgcode['updVLANDescription']['OK'] = 51;
2123 $msgcode['updVLANDescription']['ERR1'] = 105;
2124 $msgcode['updVLANDescription']['ERR2'] = 109;
2125 function updVLANDescription ()
2127 assertUIntArg ('vlan_id');
2128 assertStringArg ('vlan_type');
2129 assertStringArg ('vlan_descr', TRUE);
2131 if ($sic['vlan_id'] == VLAN_DFL_ID
)
2132 return buildRedirectURL (__FUNCTION__
, 'ERR1');
2133 $result = commitUpdateVLANDescription
2140 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR2');
2143 $msgcode['createVLANDomain']['OK'] = 48;
2144 $msgcode['createVLANDomain']['ERR'] = 110;
2145 function createVLANDomain ()
2147 assertStringArg ('vdom_descr');
2149 $result = usePreparedInsertBlade
2154 'description' => $sic['vdom_descr'],
2157 $result = $result and usePreparedInsertBlade
2162 'domain_id' => lastInsertID(),
2163 'vlan_id' => VLAN_DFL_ID
,
2164 'vlan_type' => 'compulsory',
2165 'vlan_descr' => 'default',
2168 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2171 $msgcode['destroyVLANDomain']['OK'] = 49;
2172 $msgcode['destroyVLANDomain']['ERR'] = 111;
2173 function destroyVLANDomain ()
2175 assertUIntArg ('vdom_id');
2177 $result = FALSE !== usePreparedDeleteBlade ('VLANDomain', array ('id' => $sic['vdom_id']));
2178 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2181 $msgcode['updateVLANDomain']['OK'] = 51;
2182 $msgcode['updateVLANDomain']['ERR'] = 109;
2183 function updateVLANDomain ()
2185 assertUIntArg ('vdom_id');
2186 assertStringArg ('vdom_descr');
2188 $result = FALSE !== commitUpdateVLANDomain ($sic['vdom_id'], $sic['vdom_descr']);
2189 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2192 $msgcode['save8021QPorts']['OK1'] = 63;
2193 $msgcode['save8021QPorts']['OK2'] = 41;
2194 $msgcode['save8021QPorts']['ERR1'] = 160;
2195 $msgcode['save8021QPorts']['ERR2'] = 109;
2196 function save8021QPorts ()
2198 global $sic, $dbxlink;
2199 assertUIntArg ('mutex_rev', TRUE); // counts from 0
2200 assertStringArg ('form_mode');
2201 if ($sic['form_mode'] != 'save' and $sic['form_mode'] != 'duplicate')
2202 throw new InvalidRequestArgException ('form_mode', $sic['form_mode']);
2204 $dbxlink->beginTransaction();
2207 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE'))
2208 throw new InvalidArgException ('object_id', $object_id, 'VLAN domain is not set for this object');
2209 if ($vswitch['mutex_rev'] != $sic['mutex_rev'])
2210 throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form data');
2211 $after = $before = apply8021QOrder ($vswitch['template_id'], getStored8021QConfig ($sic['object_id'], 'desired'));
2213 switch ($sic['form_mode'])
2216 assertUIntArg ('nports');
2217 if ($sic['nports'] == 1)
2219 assertStringArg ('pn_0');
2220 $extra = array ('port_name' => $sic['pn_0']);
2222 for ($i = 0; $i < $sic['nports']; $i++
)
2224 assertStringArg ('pn_' . $i);
2225 assertStringArg ('pm_' . $i);
2226 // An access port only generates form input for its native VLAN,
2227 // which we derive allowed VLAN list from.
2228 $native = isset ($sic['pnv_' . $i]) ?
$sic['pnv_' . $i] : 0;
2229 switch ($sic["pm_${i}"])
2232 # assertArrayArg ('pav_' . $i);
2233 $allowed = isset ($sic['pav_' . $i]) ?
$sic['pav_' . $i] : array();
2236 if ($native == 'same')
2238 assertUIntArg ('pnv_' . $i);
2239 $allowed = array ($native);
2242 throw new InvalidRequestArgException ("pm_${i}", $_REQUEST["pm_${i}"], 'unknown port mode');
2244 $changes[$sic['pn_' . $i]] = array
2246 'mode' => $sic['pm_' . $i],
2247 'allowed' => $allowed,
2248 'native' => $native,
2253 assertStringArg ('from_port');
2254 # assertArrayArg ('to_ports');
2255 if (!array_key_exists ($sic['from_port'], $before))
2256 throw new InvalidArgException ('from_port', $sic['from_port'], 'this port does not exist');
2257 foreach ($sic['to_ports'] as $tpn)
2258 if (!array_key_exists ($tpn, $before))
2259 throw new InvalidArgException ('to_ports[]', $tpn, 'this port does not exist');
2260 elseif ($tpn != $sic['from_port'])
2261 $changes[$tpn] = $before[$sic['from_port']];
2264 $domain_vlanlist = getDomainVLANs ($vswitch['domain_id']);
2265 $changes = filter8021QChangeRequests
2269 apply8021QOrder ($vswitch['template_id'], $changes)
2271 $changes = authorize8021QChangeRequests ($before, $changes);
2272 foreach ($changes as $port_name => $port)
2273 $after[$port_name] = $port;
2274 $new_uplinks = filter8021QChangeRequests ($domain_vlanlist, $after, produceUplinkPorts ($domain_vlanlist, $after));
2275 $npulled = replace8021QPorts ('desired', $vswitch['object_id'], $before, $changes);
2276 $nsaved_uplinks = replace8021QPorts ('desired', $vswitch['object_id'], $before, $new_uplinks);
2278 catch (Exception
$e)
2280 $dbxlink->rollBack();
2281 return buildRedirectURL (__FUNCTION__
, 'ERR2', array(), NULL, NULL, $extra);
2283 if ($npulled +
$nsaved_uplinks)
2284 $result = usePreparedExecuteBlade
2286 'UPDATE VLANSwitch SET mutex_rev=mutex_rev+1, last_change=NOW(), out_of_sync="yes" WHERE object_id=?',
2287 array ($sic['object_id'])
2290 $log = oneLiner (63, array ($npulled +
$nsaved_uplinks));
2291 if ($nsaved_uplinks)
2293 initiateUplinksReverb ($vswitch['object_id'], $new_uplinks);
2294 $log = mergeLogs ($log, oneLiner (41));
2296 if ($npulled +
$nsaved_uplinks > 0 and getConfigVar ('8021Q_INSTANT_DEPLOY') == 'yes')
2300 if (FALSE === $done = exec8021QDeploy ($sic['object_id'], TRUE))
2301 $log = mergeLogs ($log, oneLiner (191));
2303 $log = mergeLogs ($log, oneLiner (63, array ($done)));
2305 catch (Exception
$e)
2307 $log = mergeLogs ($log, oneLiner (109));
2310 return buildWideRedirectURL ($log, NULL, NULL, $extra);
2313 $msgcode['bindVLANtoIPv4']['OK'] = 48;
2314 $msgcode['bindVLANtoIPv4']['ERR'] = 110;
2315 function bindVLANtoIPv4 ()
2317 assertUIntArg ('id'); // network id
2319 $result = commitSupplementVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2320 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2323 $msgcode['unbindVLANfromIPv4']['OK'] = 49;
2324 $msgcode['unbindVLANfromIPv4']['ERR'] = 111;
2325 function unbindVLANfromIPv4 ()
2327 assertUIntArg ('id'); // network id
2329 $result = commitReduceVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2330 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2333 $msgcode['process8021QSyncRequest']['OK'] = 63;
2334 $msgcode['process8021QSyncRequest']['ERR'] = 191;
2335 function process8021QSyncRequest ()
2337 // behave depending on current operation: exec8021QPull or exec8021QPush
2339 if (FALSE === $done = exec8021QDeploy ($sic['object_id'], $op == 'exec8021QPush'))
2340 return buildRedirectURL (__FUNCTION__
, 'ERR');
2341 return buildRedirectURL (__FUNCTION__
, 'OK', array ($done));
2344 $msgcode['resolve8021QConflicts']['OK'] = 63;
2345 $msgcode['resolve8021QConflicts']['ERR1'] = 179;
2346 $msgcode['resolve8021QConflicts']['ERR2'] = 109;
2347 function resolve8021QConflicts ()
2349 global $sic, $dbxlink;
2350 assertUIntArg ('mutex_rev', TRUE); // counts from 0
2351 assertUIntArg ('nrows');
2352 // Divide submitted radio buttons into 3 groups:
2353 // left (saved version wins)
2355 // right (running version wins)
2357 for ($i = 0; $i < $sic['nrows']; $i++
)
2359 if (!array_key_exists ("i_${i}", $sic))
2361 // let's hope other inputs are in place
2362 switch ($sic["i_${i}"])
2366 $F[$sic["pn_${i}"]] = array
2368 'mode' => $sic["rm_${i}"],
2369 'allowed' => $sic["ra_${i}"],
2370 'native' => $sic["rn_${i}"],
2371 'decision' => $sic["i_${i}"],
2378 $dbxlink->beginTransaction();
2381 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE'))
2382 throw new InvalidArgException ('object_id', $sic['object_id'], 'VLAN domain is not set for this object');
2383 if ($vswitch['mutex_rev'] != $sic['mutex_rev'])
2384 throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form (table data has changed)');
2385 $D = getStored8021QConfig ($vswitch['object_id'], 'desired');
2386 $C = getStored8021QConfig ($vswitch['object_id'], 'cached');
2387 $R = getRunning8021QConfig ($vswitch['object_id']);
2388 $plan = get8021QSyncOptions ($vswitch, $D, $C, $R['portdata']);
2390 foreach ($F as $port_name => $port)
2392 if (!array_key_exists ($port_name, $plan))
2394 elseif ($plan[$port_name]['status'] == 'merge_conflict')
2396 // for R neither mutex nor revisions can be emulated, but revision change can be
2397 if (!same8021QConfigs ($port, $R['portdata'][$port_name]))
2398 throw new InvalidRequestArgException ("port ${port_name}", '(hidden)', 'expired form (switch data has changed)');
2399 if ($port['decision'] == 'right') // D wins, frame R by writing value of R to C
2400 $ndone +
= upd8021QPort ('cached', $vswitch['object_id'], $port_name, $port);
2401 elseif ($port['decision'] == 'left') // R wins, cross D up
2402 $ndone +
= upd8021QPort ('cached', $vswitch['object_id'], $port_name, $D[$port_name]);
2403 // otherwise there was no decision made
2407 $plan[$port_name]['status'] == 'delete_conflict' or
2408 $plan[$port_name]['status'] == 'martian_conflict'
2411 if ($port['decision'] == 'left') // confirm deletion of local copy
2412 $ndone +
= del8021QPort ($vswitch['object_id'], $port_name);
2414 // otherwise ignore a decision, which doesn't address a conflict
2417 catch (InvalidRequestArgException
$e)
2419 $dbxlink->rollBack();
2420 return buildRedirectURL (__FUNCTION__
, 'ERR1');
2422 catch (Exception
$e)
2424 $dbxlink->rollBack();
2425 return buildRedirectURL (__FUNCTION__
, 'ERR2');
2428 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ndone));
2431 $msgcode['addVLANSwitchTemplate']['OK'] = 48;
2432 $msgcode['addVLANSwitchTemplate']['ERR'] = 110;
2433 function addVLANSwitchTemplate()
2435 assertStringArg ('vst_descr');
2437 $max_local_vlans = NULL;
2438 if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans']))
2440 assertUIntArg ('vst_maxvlans');
2441 $max_local_vlans = $sic['vst_maxvlans'];
2443 $result = usePreparedInsertBlade
2445 'VLANSwitchTemplate',
2448 'max_local_vlans' => $max_local_vlans,
2449 'description' => $sic['vst_descr'],
2452 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2455 $msgcode['delVLANSwitchTemplate']['OK'] = 49;
2456 $msgcode['delVLANSwitchTemplate']['ERR'] = 111;
2457 function delVLANSwitchTemplate()
2459 assertUIntArg ('vst_id');
2461 $result = FALSE !== usePreparedDeleteBlade ('VLANSwitchTemplate', array ('id' => $sic['vst_id']));
2462 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2465 $msgcode['updVLANSwitchTemplate']['OK'] = 51;
2466 $msgcode['updVLANSwitchTemplate']['ERR'] = 109;
2467 function updVLANSwitchTemplate()
2469 assertUIntArg ('vst_id');
2470 assertStringArg ('vst_descr');
2472 $max_local_vlans = NULL;
2473 if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans']))
2475 assertUIntArg ('vst_maxvlans');
2476 $max_local_vlans = $sic['vst_maxvlans'];
2478 $result = commitUpdateVST ($sic['vst_id'], $max_local_vlans, $sic['vst_descr']);
2479 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
2482 $msgcode['addVSTRule']['OK'] = 48;
2483 $msgcode['addVSTRule']['ERR'] = 110;
2484 function addVSTRule()
2486 assertUIntArg ('vst_id');
2487 assertUIntArg ('rule_no');
2488 assertPCREArg ('port_pcre');
2489 assertStringArg ('port_role');
2490 assertStringArg ('wrt_vlans', TRUE);
2491 assertStringArg ('description', TRUE);
2493 $result = usePreparedInsertBlade
2498 'vst_id' => $sic['vst_id'],
2499 'rule_no' => $sic['rule_no'],
2500 'port_pcre' => $sic['port_pcre'],
2501 'port_role' => $sic['port_role'],
2502 'wrt_vlans' => $sic['wrt_vlans'],
2503 'description' => $sic['description'],
2506 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2509 $msgcode['delVSTRule']['OK'] = 49;
2510 $msgcode['delVSTRule']['ERR'] = 111;
2511 function delVSTRule()
2513 assertUIntArg ('vst_id');
2514 assertUIntArg ('rule_no');
2516 $result = FALSE !== usePreparedDeleteBlade
2521 'vst_id' => $sic['vst_id'],
2522 'rule_no' => $sic['rule_no']
2525 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2528 $msgcode['updVSTRule']['OK'] = 51;
2529 $msgcode['updVSTRule']['ERR'] = 109;
2530 function updVSTRule()
2532 assertUIntArg ('vst_id');
2533 assertUIntArg ('rule_no');
2534 assertUIntArg ('new_rule_no');
2535 assertPCREArg ('port_pcre');
2536 assertStringArg ('port_role');
2537 assertStringArg ('wrt_vlans', TRUE);
2538 assertStringArg ('description', TRUE);
2540 $result = commitUpdateVSTRule
2544 $sic['new_rule_no'],
2550 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
2553 $msgcode['importDPData']['OK'] = 44;
2554 function importDPData()
2557 assertUIntArg ('nports');
2558 $nignored = $ndone = 0;
2559 $POIFC = getPortOIFCompat();
2560 for ($i = 0; $i < $sic['nports']; $i++
)
2561 if (array_key_exists ("do_${i}", $sic))
2563 assertUIntArg ("pid1_${i}");
2564 assertUIntArg ("pid2_${i}");
2565 $porta = getPortInfo ($_REQUEST["pid1_${i}"]);
2566 $portb = getPortInfo ($_REQUEST["pid2_${i}"]);
2571 ($porta['object_id'] != $sic['object_id'] and $portb['object_id'] != $sic['object_id'])
2577 foreach ($POIFC as $item)
2578 if ($item['type1'] == $porta['oif_id'] and $item['type2'] == $portb['oif_id'])
2580 linkPorts ($_REQUEST["pid1_${i}"], $_REQUEST["pid2_${i}"]);
2582 continue 2; // next port
2586 return buildRedirectURL (__FUNCTION__
, 'OK', array ($nignored, $ndone));