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')
658 $chapter_id = 'NULL';
661 assertUIntArg ('chapter_no'); // FIXME: this doesn't fail on 0 (ticket:272)
662 if (0 == ($chapter_id = $_REQUEST['chapter_no']))
663 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ('chapter not selected'));
665 if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $chapter_id) !== FALSE)
666 return buildRedirectURL (__FUNCTION__
, 'OK');
668 return buildRedirectURL (__FUNCTION__
, 'ERR2');
671 $msgcode['reduceAttrMap']['OK'] = 49;
672 $msgcode['reduceAttrMap']['ERR'] = 119;
673 function reduceAttrMap ()
675 assertUIntArg ('attr_id');
676 assertUIntArg ('objtype_id');
677 if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) !== FALSE)
678 return buildRedirectURL (__FUNCTION__
, 'OK');
680 return buildRedirectURL (__FUNCTION__
, 'ERR');
683 $msgcode['clearSticker']['OK'] = 15;
684 $msgcode['clearSticker']['ERR'] = 120;
685 function clearSticker ()
687 assertUIntArg ('attr_id');
688 assertUIntArg ('object_id');
689 if (commitResetAttrValue ($_REQUEST['object_id'], $_REQUEST['attr_id']) !== FALSE)
690 return buildRedirectURL (__FUNCTION__
, 'OK');
692 return buildRedirectURL (__FUNCTION__
, 'ERR');
695 $msgcode['updateObjectAllocation']['OK'] = 63;
696 function updateObjectAllocation ()
698 assertUIntArg ('object_id');
700 if (!isset ($_REQUEST['got_atoms']))
702 unset($_GET['page']);
705 unset($_POST['page']);
706 unset($_POST['tab']);
708 return buildWideRedirectURL (array(), NULL, NULL, array_merge ($_GET, $_POST));
710 $object_id = $_REQUEST['object_id'];
711 $workingRacksData = array();
712 foreach ($_REQUEST['rackmulti'] as $cand_id)
714 if (!isset ($workingRacksData[$cand_id]))
716 $rackData = spotEntity ('rack', $cand_id);
717 amplifyCell ($rackData);
718 $workingRacksData[$cand_id] = $rackData;
722 foreach ($workingRacksData as &$rd)
723 applyObjectMountMask ($rd, $object_id);
725 $oldMolecule = getMoleculeForObject ($object_id);
728 foreach ($workingRacksData as $rack_id => $rackData)
730 $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
732 if ($logrecord['code'] == 300)
735 // Reload our working copy after form processing.
736 $rackData = spotEntity ('rack', $cand_id);
737 amplifyCell ($rackData);
738 applyObjectMountMask ($rackData, $object_id);
739 $workingRacksData[$rack_id] = $rackData;
742 return buildRedirectURL (__FUNCTION__
, 'OK', $changecnt);
744 $newMolecule = getMoleculeForObject ($object_id);
745 $oc = count ($oldMolecule);
746 $nc = count ($newMolecule);
747 $omid = $oc ?
createMolecule ($oldMolecule) : 'NULL';
748 $nmid = $nc ?
createMolecule ($newMolecule) : 'NULL';
749 global $remote_username;
750 $comment = empty ($_REQUEST['comment']) ?
'NULL' : "'${_REQUEST['comment']}'";
752 "insert into MountOperation(object_id, old_molecule_id, new_molecule_id, user_name, comment) " .
753 "values (${object_id}, ${omid}, ${nmid}, '${remote_username}', ${comment})";
755 $result = $dbxlink->query ($query);
757 $log[] = array ('code' => 500, 'message' => 'SQL query failed during history logging.');
759 $log[] = array ('code' => 200, 'message' => 'History logged.');
760 return buildWideRedirectURL ($log);
763 $msgcode['updateObject']['OK'] = 16;
764 $msgcode['updateObject']['ERR'] = 121;
765 function updateObject ()
767 assertUIntArg ('num_attrs', TRUE);
768 assertUIntArg ('object_id');
769 assertUIntArg ('object_type_id');
770 assertStringArg ('object_name', TRUE);
771 assertStringArg ('object_label', TRUE);
772 assertStringArg ('object_barcode', TRUE);
773 assertStringArg ('object_asset_no', TRUE);
774 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
775 $has_problems = 'yes';
777 $has_problems = 'no';
779 if (commitUpdateObject (
780 $_REQUEST['object_id'],
781 $_REQUEST['object_name'],
782 $_REQUEST['object_label'],
783 $_REQUEST['object_barcode'],
784 $_REQUEST['object_type_id'],
786 $_REQUEST['object_asset_no'],
787 $_REQUEST['object_comment']
789 return buildRedirectURL (__FUNCTION__
, 'ERR');
791 // Update optional attributes
792 $oldvalues = getAttrValues ($_REQUEST['object_id']);
794 $num_attrs = isset ($_REQUEST['num_attrs']) ?
$_REQUEST['num_attrs'] : 0;
795 for ($i = 0; $i < $num_attrs; $i++
)
797 assertUIntArg ("${i}_attr_id");
798 $attr_id = $_REQUEST["${i}_attr_id"];
800 // 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
801 if (!strlen ($_REQUEST["${i}_value"]) ||
($oldvalues[$attr_id]['type']=='dict' && $_REQUEST["${i}_value"] == 0))
803 commitResetAttrValue ($_REQUEST['object_id'], $attr_id);
807 // The value could be uint/float, but we don't know ATM. Let SQL
808 // server check this and complain.
809 assertStringArg ("${i}_value");
810 $value = $_REQUEST["${i}_value"];
811 switch ($oldvalues[$attr_id]['type'])
816 $oldvalue = $oldvalues[$attr_id]['value'];
819 $oldvalue = $oldvalues[$attr_id]['key'];
823 if ($value === $oldvalue) // ('' == 0), but ('' !== 0)
826 // Note if the queries succeed or not, it determines which page they see.
827 $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value);
829 if (in_array (FALSE, $result))
830 return buildRedirectURL (__FUNCTION__
, 'ERR');
832 // Invalidate thumb cache of all racks objects could occupy.
833 foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id)
834 resetThumbCache ($rack_id);
836 return buildRedirectURL (__FUNCTION__
, 'OK');
840 function addMultipleObjects()
843 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
844 $max = getConfigVar ('MASSCOUNT');
845 for ($i = 0; $i < $max; $i++
)
847 if (!isset ($_REQUEST["${i}_object_type_id"]))
849 $log = mergeLogs ($log, oneLiner (184, array ($i +
1)));
852 assertUIntArg ("${i}_object_type_id", TRUE);
853 assertStringArg ("${i}_object_name", TRUE);
854 assertStringArg ("${i}_object_label", TRUE);
855 assertStringArg ("${i}_object_asset_no", TRUE);
856 assertStringArg ("${i}_object_barcode", TRUE);
857 $name = $_REQUEST["${i}_object_name"];
859 // It's better to skip silently, than to print a notice.
860 if ($_REQUEST["${i}_object_type_id"] == 0)
862 if (($object_id = commitAddObject
865 $_REQUEST["${i}_object_label"],
866 $_REQUEST["${i}_object_barcode"],
867 $_REQUEST["${i}_object_type_id"],
868 $_REQUEST["${i}_object_asset_no"],
871 $info = spotEntity ('object', $object_id);
872 // FIXME: employ amplifyCell() instead of calling loader functions directly
874 $log = mergeLogs ($log, oneLiner (80, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>')));
876 $log = mergeLogs ($log, oneLiner (185, array ($name)));
879 return buildWideRedirectURL ($log);
882 function addLotOfObjects()
885 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
886 assertUIntArg ('global_type_id', TRUE);
887 assertStringArg ('namelist', TRUE);
888 $global_type_id = $_REQUEST['global_type_id'];
889 if ($global_type_id == 0 or !strlen ($_REQUEST['namelist']))
890 $log = mergeLogs ($log, oneLiner (186));
893 // The name extractor below was stolen from ophandlers.php:addMultiPorts()
894 $names1 = explode ("\n", $_REQUEST['namelist']);
896 foreach ($names1 as $line)
898 $parts = explode ('\r', $line);
900 if (!strlen ($parts[0]))
903 $names2[] = rtrim ($parts[0]);
905 foreach ($names2 as $name)
906 if (($object_id = commitAddObject ($name, '', '', $global_type_id, '', $taglist)) !== FALSE)
908 $info = spotEntity ('object', $object_id);
910 $log = mergeLogs ($log, oneLiner (80, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>')));
913 $log = mergeLogs ($log, oneLiner (185, array ($name)));
915 return buildWideRedirectURL ($log);
918 $msgcode['deleteObject']['OK'] = 76;
919 $msgcode['deleteObject']['ERR'] = 100;
920 function deleteObject ()
922 assertUIntArg ('object_id');
923 if (NULL === ($oinfo = spotEntity ('object', $_REQUEST['object_id'])))
924 return buildRedirectURL (__FUNCTION__
, 'ERR', array ('object not found'));
926 $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE);
927 $error = commitDeleteObject ($_REQUEST['object_id']);
928 foreach ($racklist as $rack_id)
929 resetThumbCache ($rack_id);
932 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
934 return buildRedirectURL (__FUNCTION__
, 'OK', array ($oinfo['dname']));
937 $msgcode['useupPort']['OK'] = 11;
938 $msgcode['useupPort']['ERR'] = 124;
939 function useupPort ()
941 assertUIntArg ('port_id');
942 if (FALSE !== commitUseupPort ($_REQUEST['port_id']))
943 return buildRedirectURL (__FUNCTION__
, 'OK');
945 return buildRedirectURL (__FUNCTION__
, 'ERR');
948 $msgcode['updateUI']['OK'] = 56;
951 assertUIntArg ('num_vars');
953 for ($i = 0; $i < $_REQUEST['num_vars']; $i++
)
955 assertStringArg ("${i}_varname");
956 assertStringArg ("${i}_varvalue", TRUE);
957 $varname = $_REQUEST["${i}_varname"];
958 $varvalue = $_REQUEST["${i}_varvalue"];
960 // If form value = value in DB, don't bother updating DB
961 if (!isConfigVarChanged($varname, $varvalue))
963 // any exceptions will be handled by process.php
964 setConfigVar ($varname, $varvalue, TRUE);
966 return buildRedirectURL (__FUNCTION__
, 'OK');
969 $msgcode['saveMyPreferences']['OK'] = 56;
970 function saveMyPreferences ()
972 assertUIntArg ('num_vars');
974 for ($i = 0; $i < $_REQUEST['num_vars']; $i++
)
976 assertStringArg ("${i}_varname");
977 assertStringArg ("${i}_varvalue", TRUE);
978 $varname = $_REQUEST["${i}_varname"];
979 $varvalue = $_REQUEST["${i}_varvalue"];
981 // If form value = value in DB, don't bother updating DB
982 if (!isConfigVarChanged($varname, $varvalue))
984 setUserConfigVar ($varname, $varvalue);
986 return buildRedirectURL (__FUNCTION__
, 'OK');
989 $msgcode['resetMyPreference']['OK'] = 56;
990 function resetMyPreference ()
992 assertStringArg ("varname");
993 resetUserConfigVar ($_REQUEST["varname"]);
994 return buildRedirectURL (__FUNCTION__
, 'OK');
997 $msgcode['resetUIConfig']['OK'] = 57;
998 function resetUIConfig()
1000 setConfigVar ('MASSCOUNT','15');
1001 setConfigVar ('MAXSELSIZE','30');
1002 setConfigVar ('ROW_SCALE','2');
1003 setConfigVar ('PORTS_PER_ROW','12');
1004 setConfigVar ('IPV4_ADDRS_PER_PAGE','256');
1005 setConfigVar ('DEFAULT_RACK_HEIGHT','42');
1006 setConfigVar ('DEFAULT_SLB_VS_PORT','');
1007 setConfigVar ('DEFAULT_SLB_RS_PORT','');
1008 setConfigVar ('DETECT_URLS','no');
1009 setConfigVar ('RACK_PRESELECT_THRESHOLD','1');
1010 setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no');
1011 setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm');
1012 setConfigVar ('SHOW_EXPLICIT_TAGS','yes');
1013 setConfigVar ('SHOW_IMPLICIT_TAGS','yes');
1014 setConfigVar ('SHOW_AUTOMATIC_TAGS','no');
1015 setConfigVar ('DEFAULT_OBJECT_TYPE','4');
1016 setConfigVar ('IPV4_AUTO_RELEASE','1');
1017 setConfigVar ('SHOW_LAST_TAB', 'no');
1018 setConfigVar ('EXT_IPV4_VIEW', 'yes');
1019 setConfigVar ('TREE_THRESHOLD', '25');
1020 setConfigVar ('IPV4_JAYWALK', 'no');
1021 setConfigVar ('ADDNEW_AT_TOP', 'yes');
1022 setConfigVar ('IPV4_TREE_SHOW_USAGE', 'yes');
1023 setConfigVar ('PREVIEW_TEXT_MAXCHARS', '10240');
1024 setConfigVar ('PREVIEW_TEXT_ROWS', '25');
1025 setConfigVar ('PREVIEW_TEXT_COLS', '80');
1026 setConfigVar ('PREVIEW_IMAGE_MAXPXS', '320');
1027 setConfigVar ('VENDOR_SIEVE', '');
1028 setConfigVar ('IPV4LB_LISTSRC', '{$typeid_4}');
1029 setConfigVar ('IPV4OBJ_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_12} or {$typeid_445} or {$typeid_447} or {$typeid_798}');
1030 setConfigVar ('IPV4NAT_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_798}');
1031 setConfigVar ('ASSETWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1032 setConfigVar ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1033 setConfigVar ('RACKS_PER_ROW','12');
1034 setConfigVar ('FILTER_PREDICATE_SIEVE','');
1035 setConfigVar ('FILTER_DEFAULT_ANDOR','or');
1036 setConfigVar ('FILTER_SUGGEST_ANDOR','yes');
1037 setConfigVar ('FILTER_SUGGEST_TAGS','yes');
1038 setConfigVar ('FILTER_SUGGEST_PREDICATES','yes');
1039 setConfigVar ('FILTER_SUGGEST_EXTRA','no');
1040 setConfigVar ('DEFAULT_SNMP_COMMUNITY','public');
1041 setConfigVar ('IPV4_ENABLE_KNIGHT','yes');
1042 setConfigVar ('TAGS_TOPLIST_SIZE','50');
1043 setConfigVar ('TAGS_QUICKLIST_SIZE','20');
1044 setConfigVar ('TAGS_QUICKLIST_THRESHOLD','50');
1045 setConfigVar ('ENABLE_MULTIPORT_FORM', 'no');
1046 setConfigVar ('DEFAULT_PORT_IIF_ID', '1');
1047 setConfigVar ('DEFAULT_PORT_OIF_IDS', '1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084');
1048 setConfigVar ('IPV4_TREE_RTR_AS_CELL', 'yes');
1049 setConfigVar ('PROXIMITY_RANGE', 0);
1050 setConfigVar ('IPV4_TREE_SHOW_VLAN', 'yes');
1051 setConfigVar ('VLANSWITCH_LISTSRC', '');
1052 setConfigVar ('VLANIPV4NET_LISTSRC', '');
1053 setConfigVar ('DEFAULT_VDOM_ID', '');
1054 setConfigVar ('DEFAULT_VST_ID', '');
1055 setConfigVar ('STATIC_FILTER', 'yes');
1056 setConfigVar ('8021Q_DEPLOY_MINAGE', '300');
1057 setConfigVar ('8021Q_DEPLOY_MAXAGE', '3600');
1058 setConfigVar ('8021Q_DEPLOY_RETRY', '10800');
1059 setConfigVar ('8021Q_WRI_AFTER_CONFT_LISTSRC', 'false');
1060 setConfigVar ('8021Q_INSTANT_DEPLOY', 'no');
1061 setConfigVar ('CDP_RUNNERS_LISTSRC', '');
1062 setConfigVar ('LLDP_RUNNERS_LISTSRC', '');
1063 setConfigVar ('HNDP_RUNNERS_LISTSRC', '');
1064 return buildRedirectURL (__FUNCTION__
, 'OK');
1067 $msgcode['addRealServer']['OK'] = 34;
1068 $msgcode['addRealServer']['ERR'] = 126;
1069 // Add single record.
1070 function addRealServer ()
1072 assertUIntArg ('pool_id');
1073 assertIPv4Arg ('remoteip');
1074 assertStringArg ('rsport', TRUE);
1075 assertStringArg ('rsconfig', TRUE);
1076 if (!addRStoRSPool (
1077 $_REQUEST['pool_id'],
1078 $_REQUEST['remoteip'],
1079 $_REQUEST['rsport'],
1080 getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'),
1081 $_REQUEST['rsconfig']
1083 return buildRedirectURL (__FUNCTION__
, 'ERR');
1085 return buildRedirectURL (__FUNCTION__
, 'OK');
1088 $msgcode['addRealServers']['OK'] = 37;
1089 $msgcode['addRealServers']['ERR1'] = 131;
1090 $msgcode['addRealServers']['ERR2'] = 127;
1091 // Parse textarea submitted and try adding a real server for each line.
1092 function addRealServers ()
1094 assertUIntArg ('pool_id');
1095 assertStringArg ('format');
1096 assertStringArg ('rawtext');
1099 // Keep in mind, that the text will have HTML entities (namely '>') escaped.
1100 foreach (explode ("\n", dos2unix ($_REQUEST['rawtext'])) as $line)
1102 if (!strlen ($line))
1105 switch ($_REQUEST['format'])
1107 case 'ipvs_2': // address and port only
1108 if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) /', $line, $match))
1110 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1115 case 'ipvs_3': // address, port and weight
1116 if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match))
1118 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3]))
1123 case 'ssv_2': // IP address and port
1124 if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match))
1126 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1131 case 'ssv_1': // IP address
1132 if (!preg_match ('/^([0-9\.]+)$/', $line, $match))
1134 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1140 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1144 if ($nbad == 0 and $ngood > 0)
1145 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1147 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($ngood, $nbad));
1150 $msgcode['addVService']['OK'] = 28;
1151 $msgcode['addVService']['ERR1'] = 132;
1152 $msgcode['addVService']['ERR2'] = 100;
1153 function addVService ()
1155 assertIPv4Arg ('vip');
1156 assertUIntArg ('vport');
1157 assertStringArg ('proto');
1158 if ($_REQUEST['proto'] != 'TCP' and $_REQUEST['proto'] != 'UDP')
1159 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1160 assertStringArg ('name', TRUE);
1161 assertStringArg ('vsconfig', TRUE);
1162 assertStringArg ('rsconfig', TRUE);
1163 $error = commitCreateVS
1169 $_REQUEST['vsconfig'],
1170 $_REQUEST['rsconfig'],
1171 isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array()
1174 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
1176 return buildRedirectURL (__FUNCTION__
, 'OK');
1179 $msgcode['deleteRealServer']['OK'] = 35;
1180 $msgcode['deleteRealServer']['ERR'] = 128;
1181 function deleteRealServer ()
1183 assertUIntArg ('id');
1184 if (!commitDeleteRS ($_REQUEST['id']))
1185 return buildRedirectURL (__FUNCTION__
, 'ERR');
1187 return buildRedirectURL (__FUNCTION__
, 'OK');
1190 $msgcode['deleteLoadBalancer']['OK'] = 19;
1191 $msgcode['deleteLoadBalancer']['ERR'] = 129;
1192 function deleteLoadBalancer ()
1194 assertUIntArg ('object_id');
1195 assertUIntArg ('pool_id');
1196 assertUIntArg ('vs_id');
1197 if (!commitDeleteLB (
1198 $_REQUEST['object_id'],
1199 $_REQUEST['pool_id'],
1202 return buildRedirectURL (__FUNCTION__
, 'ERR');
1204 return buildRedirectURL (__FUNCTION__
, 'OK');
1207 $msgcode['deleteVService']['OK'] = 29;
1208 $msgcode['deleteVService']['ERR'] = 130;
1209 function deleteVService ()
1211 assertUIntArg ('vs_id');
1212 if (!commitDeleteVS ($_REQUEST['vs_id']))
1213 return buildRedirectURL (__FUNCTION__
, 'ERR');
1215 return buildRedirectURL (__FUNCTION__
, 'OK');
1218 $msgcode['updateRealServer']['OK'] = 36;
1219 $msgcode['updateRealServer']['ERR'] = 133;
1220 function updateRealServer ()
1222 assertUIntArg ('rs_id');
1223 assertIPv4Arg ('rsip');
1224 assertStringArg ('rsport', TRUE);
1225 assertStringArg ('rsconfig', TRUE);
1226 if (FALSE === commitUpdateRS (
1229 $_REQUEST['rsport'],
1230 $_REQUEST['rsconfig']
1232 return buildRedirectURL (__FUNCTION__
, 'ERR');
1234 return buildRedirectURL (__FUNCTION__
, 'OK');
1237 $msgcode['updateLoadBalancer']['OK'] = 20;
1238 $msgcode['updateLoadBalancer']['ERR'] = 134;
1239 function updateLoadBalancer ()
1241 assertUIntArg ('object_id');
1242 assertUIntArg ('pool_id');
1243 assertUIntArg ('vs_id');
1244 assertStringArg ('vsconfig', TRUE);
1245 assertStringArg ('rsconfig', TRUE);
1246 if (FALSE === commitUpdateLB (
1247 $_REQUEST['object_id'],
1248 $_REQUEST['pool_id'],
1250 $_REQUEST['vsconfig'],
1251 $_REQUEST['rsconfig']
1253 return buildRedirectURL (__FUNCTION__
, 'ERR');
1255 return buildRedirectURL (__FUNCTION__
, 'OK');
1258 $msgcode['updateVService']['OK'] = 30;
1259 $msgcode['updateVService']['ERR'] = 135;
1260 function updateVService ()
1262 assertUIntArg ('vs_id');
1263 assertIPv4Arg ('vip');
1264 assertUIntArg ('vport');
1265 assertStringArg ('proto');
1266 assertStringArg ('name', TRUE);
1267 assertStringArg ('vsconfig', TRUE);
1268 assertStringArg ('rsconfig', TRUE);
1269 if (FALSE === commitUpdateVS (
1275 $_REQUEST['vsconfig'],
1276 $_REQUEST['rsconfig']
1278 return buildRedirectURL (__FUNCTION__
, 'ERR');
1280 return buildRedirectURL (__FUNCTION__
, 'OK');
1283 $msgcode['addLoadBalancer']['OK'] = 18;
1284 $msgcode['addLoadBalancer']['ERR'] = 137;
1285 function addLoadBalancer ()
1287 assertUIntArg ('pool_id');
1288 assertUIntArg ('object_id');
1289 assertUIntArg ('vs_id');
1290 assertStringArg ('vsconfig', TRUE);
1291 assertStringArg ('rsconfig', TRUE);
1292 if (!addLBtoRSPool (
1293 $_REQUEST['pool_id'],
1294 $_REQUEST['object_id'],
1296 $_REQUEST['vsconfig'],
1297 $_REQUEST['rsconfig']
1299 return buildRedirectURL (__FUNCTION__
, 'ERR');
1301 return buildRedirectURL (__FUNCTION__
, 'OK');
1304 $msgcode['addRSPool']['OK'] = 31;
1305 $msgcode['addRSPool']['ERR'] = 100;
1306 function addRSPool ()
1308 assertStringArg ('name', TRUE);
1309 assertStringArg ('vsconfig', TRUE);
1310 assertStringArg ('rsconfig', TRUE);
1311 $error = commitCreateRSPool
1314 $_REQUEST['vsconfig'],
1315 $_REQUEST['rsconfig'],
1316 isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array()
1319 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1321 return buildRedirectURL (__FUNCTION__
, 'OK');
1324 $msgcode['deleteRSPool']['OK'] = 32;
1325 $msgcode['deleteRSPool']['ERR'] = 138;
1326 function deleteRSPool ()
1328 assertUIntArg ('pool_id');
1329 if (commitDeleteRSPool ($_REQUEST['pool_id']) === FALSE)
1330 return buildRedirectURL (__FUNCTION__
, 'ERR');
1332 return buildRedirectURL (__FUNCTION__
, 'OK');
1335 $msgcode['updateRSPool']['OK'] = 33;
1336 $msgcode['updateRSPool']['ERR'] = 139;
1337 function updateRSPool ()
1339 assertUIntArg ('pool_id');
1340 assertStringArg ('name', TRUE);
1341 assertStringArg ('vsconfig', TRUE);
1342 assertStringArg ('rsconfig', TRUE);
1343 if (FALSE === commitUpdateRSPool ($_REQUEST['pool_id'], $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
1344 return buildRedirectURL (__FUNCTION__
, 'ERR');
1346 return buildRedirectURL (__FUNCTION__
, 'OK');
1349 $msgcode['updateRSInService']['OK'] = 38;
1350 $msgcode['updateRSInService']['ERR'] = 140;
1351 function updateRSInService ()
1353 assertUIntArg ('rscount');
1354 $pool_id = $_REQUEST['pool_id'];
1355 $orig = spotEntity ('ipv4rspool', $pool_id);
1356 amplifyCell ($orig);
1358 for ($i = 1; $i <= $_REQUEST['rscount']; $i++
)
1360 $rs_id = $_REQUEST["rsid_${i}"];
1361 if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on')
1365 if ($newval != $orig['rslist'][$rs_id]['inservice'])
1367 if (FALSE !== commitSetInService ($rs_id, $newval))
1374 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1376 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($nbad, $ngood));
1379 $msgcode['importPTRData']['OK'] = 26;
1380 $msgcode['importPTRData']['ERR'] = 141;
1381 // FIXME: check, that each submitted address belongs to the prefix we
1382 // are operating on.
1383 function importPTRData ()
1385 assertUIntArg ('addrcount');
1387 for ($i = 0; $i < $_REQUEST['addrcount']; $i++
)
1389 $inputname = "import_${i}";
1390 if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on')
1392 assertIPv4Arg ("addr_${i}");
1393 assertStringArg ("descr_${i}", TRUE);
1394 assertStringArg ("rsvd_${i}");
1395 // Non-existent addresses will not have this argument set in request.
1397 if ($_REQUEST["rsvd_${i}"] == 'yes')
1399 if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '')
1405 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1407 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($nbad, $ngood));
1410 $msgcode['generateAutoPorts']['OK'] = 21;
1411 $msgcode['generateAutoPorts']['ERR'] = 142;
1412 function generateAutoPorts ()
1415 assertUIntArg ('object_id');
1416 $info = spotEntity ('object', $_REQUEST['object_id']);
1417 // Navigate away in case of success, stay at the place otherwise.
1418 if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id']))
1419 return buildRedirectURL (__FUNCTION__
, 'OK', array(), $pageno, 'ports');
1421 return buildRedirectURL (__FUNCTION__
, 'ERR');
1424 $msgcode['saveEntityTags']['OK'] = 22;
1425 $msgcode['saveEntityTags']['ERR1'] = 143;
1426 $msgcode['saveEntityTags']['ERR2'] = 187;
1427 // Filter out implicit tags before storing the new tag set.
1428 function saveEntityTags ()
1430 global $page, $pageno, $etype_by_pageno;
1431 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1432 return buildRedirectURL (__FUNCTION__
, 'ERR2', array (__FUNCTION__
));
1433 $realm = $etype_by_pageno[$pageno];
1434 $bypass = $page[$pageno]['bypass'];
1435 assertUIntArg ($bypass);
1436 $entity_id = $_REQUEST[$bypass];
1437 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1438 // Build a chain from the submitted data, minimize it,
1439 // then wipe existing records and store the new set instead.
1440 destroyTagsForEntity ($realm, $entity_id);
1441 // TODO: these actions are very close to what rebuildTagChainForEntity() does,
1442 // so why not use it?
1443 $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist));
1444 $n_succeeds = $n_errors = 0;
1445 foreach ($newchain as $taginfo)
1446 if (addTagForEntity ($realm, $entity_id, $taginfo['id']))
1451 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($n_succeeds, $n_errors));
1453 return buildRedirectURL (__FUNCTION__
, 'OK', array ($n_succeeds));
1456 $msgcode['destroyTag']['OK'] = 58;
1457 $msgcode['destroyTag']['ERR1'] = 183;
1458 $msgcode['destroyTag']['ERR2'] = 144;
1459 function destroyTag ()
1461 assertUIntArg ('tag_id');
1463 if (!isset ($taglist[$_REQUEST['tag_id']]))
1464 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($_REQUEST['tag_id']));
1465 if (($ret = commitDestroyTag ($_REQUEST['tag_id'])) == '')
1466 return buildRedirectURL (__FUNCTION__
, 'OK', array ($taglist[$_REQUEST['tag_id']]['tag']));
1468 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1471 $msgcode['createTag']['OK'] = 59;
1472 $msgcode['createTag']['ERR1'] = 145;
1473 $msgcode['createTag']['ERR3'] = 147;
1474 function createTag ()
1476 assertStringArg ('tag_name');
1477 assertUIntArg ('parent_id', TRUE);
1478 $tagname = trim ($_REQUEST['tag_name']);
1479 if (!validTagName ($tagname))
1480 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($tagname));
1481 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1483 if (FALSE === commitCreateTag ($tagname, $parent_id))
1484 return buildRedirectURL (__FUNCTION__
, 'ERR3', array (niftyString ($tagname)));
1485 return buildRedirectURL (__FUNCTION__
, 'OK', array (niftyString ($tagname)));
1488 $msgcode['updateTag']['OK'] = 60;
1489 $msgcode['updateTag']['ERR1'] = 145;
1490 $msgcode['updateTag']['ERR2'] = 109;
1491 function updateTag ()
1493 assertUIntArg ('tag_id');
1494 assertUIntArg ('parent_id', TRUE);
1495 assertStringArg ('tag_name');
1496 $tagname = trim ($_REQUEST['tag_name']);
1497 if (!validTagName ($tagname))
1498 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($tagname));
1499 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1500 $parent_id = 'NULL';
1501 if (FALSE !== commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id))
1502 return buildRedirectURL (__FUNCTION__
, 'OK', array ($tagname));
1503 // Use old name in the message, cause update failed.
1505 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($taglist[$_REQUEST['tag_id']]['tag']));
1508 $msgcode['rollTags']['OK'] = 67;
1509 $msgcode['rollTags']['ERR'] = 149;
1510 function rollTags ()
1512 assertUIntArg ('row_id');
1513 assertStringArg ('sum', TRUE);
1514 assertUIntArg ('realsum');
1515 if ($_REQUEST['sum'] != $_REQUEST['realsum'])
1516 return buildRedirectURL (__FUNCTION__
, 'ERR');
1517 // Even if the user requested an empty tag list, don't bail out, but process existing
1518 // tag chains with "zero" extra. This will make sure, that the stuff processed will
1519 // have its chains refined to "normal" form.
1520 $extratags = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1522 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
1523 // filter out the same tag again and again. It will have own noise to cancel.
1524 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
1525 foreach (listCells ('rack', $_REQUEST['row_id']) as $rack)
1527 if (rebuildTagChainForEntity ('rack', $rack['id'], $extrachain))
1529 amplifyCell ($rack);
1530 foreach ($rack['mountedObjects'] as $object_id)
1531 if (rebuildTagChainForEntity ('object', $object_id, $extrachain))
1534 return buildRedirectURL (__FUNCTION__
, 'OK', array ($n_ok));
1537 $msgcode['changeMyPassword']['OK'] = 61;
1538 $msgcode['changeMyPassword']['ERR1'] = 150;
1539 $msgcode['changeMyPassword']['ERR2'] = 151;
1540 $msgcode['changeMyPassword']['ERR3'] = 152;
1541 $msgcode['changeMyPassword']['ERR4'] = 153;
1542 function changeMyPassword ()
1544 global $remote_username, $user_auth_src;
1545 if ($user_auth_src != 'database')
1546 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1547 assertStringArg ('oldpassword');
1548 assertStringArg ('newpassword1');
1549 assertStringArg ('newpassword2');
1550 $remote_userid = getUserIDByUsername ($remote_username);
1551 $userinfo = spotEntity ('user', $remote_userid);
1552 if ($userinfo['user_password_hash'] != sha1 ($_REQUEST['oldpassword']))
1553 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1554 if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2'])
1555 return buildRedirectURL (__FUNCTION__
, 'ERR3');
1556 if (FALSE !== commitUpdateUserAccount ($remote_userid, $userinfo['user_name'], $userinfo['user_realname'], sha1 ($_REQUEST['newpassword1'])))
1557 return buildRedirectURL (__FUNCTION__
, 'OK');
1559 return buildRedirectURL (__FUNCTION__
, 'ERR4');
1562 $msgcode['saveRackCode']['OK'] = 43;
1563 $msgcode['saveRackCode']['ERR1'] = 154;
1564 $msgcode['saveRackCode']['ERR2'] = 155;
1565 function saveRackCode ()
1567 assertStringArg ('rackcode');
1568 // For the test to succeed, unescape LFs, strip CRs.
1569 $newcode = dos2unix ($_REQUEST['rackcode']);
1570 $parseTree = getRackCode ($newcode);
1571 if ($parseTree['result'] != 'ACK')
1572 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($parseTree['load']));
1573 if (FALSE !== saveScript ('RackCode', $newcode))
1575 saveScript ('RackCodeCache', base64_encode (serialize ($parseTree)));
1576 return buildRedirectURL (__FUNCTION__
, 'OK');
1578 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1581 $msgcode['setPortVLAN']['ERR1'] = 156;
1582 // This handler's context is pre-built, but not authorized. It is assumed, that the
1583 // handler will take existing context and before each commit check authorization
1584 // on the base chain plus necessary context added.
1585 function setPortVLAN ()
1587 assertUIntArg ('portcount');
1588 $data = getSwitchVLANs ($_REQUEST['object_id']);
1590 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1591 list ($vlanlist, $portlist) = $data;
1592 // Here we just build up 1 set command for the gateway with all of the ports
1593 // included. The gateway is expected to filter unnecessary changes silently
1594 // and to provide a list of responses with either error or success message
1595 // for each of the rest.
1596 $nports = $_REQUEST['portcount'];
1600 for ($i = 0; $i < $nports; $i++
)
1603 !isset ($_REQUEST['portname_' . $i]) ||
1604 !isset ($_REQUEST['vlanid_' . $i]) ||
1605 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
1607 $log['m'][] = array ('c' => 158, 'a' => array ($i));
1610 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
1611 $portlist[$i]['vlaind'] == 'TRUNK'
1616 $portname = $_REQUEST['portname_' . $i];
1617 $oldvlanid = $portlist[$i]['vlanid'];
1618 $newvlanid = $_REQUEST['vlanid_' . $i];
1621 !permitted (NULL, NULL, NULL, array (array ('tag' => '$fromvlan_' . $oldvlanid))) or
1622 !permitted (NULL, NULL, NULL, array (array ('tag' => '$tovlan_' . $newvlanid)))
1625 $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid));
1628 $setcmd .= $prefix . $portname . '=' . $newvlanid;
1631 // Feed the gateway and interpret its (non)response.
1633 $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd));
1635 $log['m'][] = array ('c' => 201);
1636 return buildWideRedirectURL ($log);
1639 $msgcode['submitSLBConfig']['OK'] = 66;
1640 $msgcode['submitSLBConfig']['ERR'] = 164;
1641 function submitSLBConfig ()
1643 assertUIntArg ('object_id');
1644 $newconfig = buildLVSConfig ($_REQUEST['object_id']);
1647 gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES
, 'UTF-8'));
1649 catch (RTGatewayError
$e)
1651 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($e->getMessage()));
1653 return buildRedirectURL (__FUNCTION__
, 'OK', array ('slbconfig'));
1656 $msgcode['addRow']['OK'] = 74;
1657 $msgcode['addRow']['ERR'] = 100;
1660 assertStringArg ('name');
1662 if (commitAddRow ($_REQUEST['name']) === TRUE)
1663 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1665 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($_REQUEST['name']));
1668 $msgcode['updateRow']['OK'] = 75;
1669 $msgcode['updateRow']['ERR'] = 100;
1670 function updateRow ()
1672 assertUIntArg ('row_id');
1673 assertStringArg ('name');
1675 if (FALSE !== commitUpdateRow ($_REQUEST['row_id'], $_REQUEST['name']))
1676 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1678 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($_REQUEST['name']));
1681 $msgcode['deleteRow']['OK'] = 77;
1682 $msgcode['deleteRow']['ERR'] = 146;
1683 function deleteRow ()
1685 assertUIntArg ('row_id');
1686 $rowinfo = getRackRowInfo ($_REQUEST['row_id']);
1687 return buildRedirectURL (__FUNCTION__
, FALSE === commitDeleteRow ($_REQUEST['row_id']) ?
'ERR' : 'OK', array ($rowinfo['name']));
1690 $msgcode['addRack']['OK'] = 65;
1691 $msgcode['addRack']['ERR1'] = 171;
1692 $msgcode['addRack']['ERR2'] = 172;
1695 assertUIntArg ('row_id');
1696 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1697 if (isset ($_REQUEST['got_data']))
1699 assertStringArg ('rack_name');
1700 assertUIntArg ('rack_height1');
1701 assertStringArg ('rack_comment', TRUE);
1703 if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
1704 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['rack_name']));
1706 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($_REQUEST['rack_name']));
1708 elseif (isset ($_REQUEST['got_mdata']))
1710 assertUIntArg ('rack_height2');
1711 assertStringArg ('rack_names', TRUE);
1713 // copy-and-paste from renderAddMultipleObjectsForm()
1714 $names1 = explode ("\n", $_REQUEST['rack_names']);
1716 foreach ($names1 as $line)
1718 $parts = explode ('\r', $line);
1720 if (!strlen ($parts[0]))
1723 $names2[] = rtrim ($parts[0]);
1726 foreach ($names2 as $cname)
1727 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE)
1728 $log['m'][] = array ('c' => $msgcode[__FUNCTION__
]['OK'], 'a' => array ($cname));
1730 $log['m'][] = array ('c' => $msgcode[__FUNCTION__
]['ERR1'], 'a' => array ($cname));
1731 return buildWideRedirectURL ($log);
1734 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1737 $msgcode['deleteRack']['OK'] = 79;
1738 $msgcode['deleteRack']['ERR'] = 100;
1739 $msgcode['deleteRack']['ERR1'] = 206;
1740 function deleteRack ()
1742 assertUIntArg ('rack_id');
1743 if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id'])))
1744 return buildRedirectURL (__FUNCTION__
, 'ERR', array ('Rack not found'), 'rackspace', 'default');
1745 amplifyCell ($rackData);
1746 if (count ($rackData['mountedObjects']))
1747 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1748 if (TRUE !== commitDeleteRack ($_REQUEST['rack_id']))
1749 return buildRedirectURL (__FUNCTION__
, 'ERR', array(), 'rackspace', 'default');
1750 return buildRedirectURL (__FUNCTION__
, 'OK', array ($rackData['name']), 'rackspace', 'default');
1753 $msgcode['updateRack']['OK'] = 68;
1754 $msgcode['updateRack']['ERR'] = 177;
1755 function updateRack ()
1757 assertUIntArg ('rack_id');
1758 assertUIntArg ('rack_row_id');
1759 assertUIntArg ('rack_height');
1760 assertStringArg ('rack_name');
1761 assertStringArg ('rack_comment', TRUE);
1763 resetThumbCache ($_REQUEST['rack_id']);
1764 if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
1765 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['rack_name']));
1767 return buildRedirectURL (__FUNCTION__
, 'ERR');
1770 function updateRackDesign ()
1772 assertUIntArg ('rack_id');
1773 $rackData = spotEntity ('rack', $_REQUEST['rack_id']);
1774 amplifyCell ($rackData);
1775 applyRackDesignMask($rackData);
1776 markupObjectProblems ($rackData);
1777 $response = processGridForm ($rackData, 'A', 'F');
1778 return buildWideRedirectURL (array($response));
1781 function updateRackProblems ()
1783 assertUIntArg ('rack_id');
1784 $rackData = spotEntity ('rack', $_REQUEST['rack_id']);
1785 amplifyCell ($rackData);
1786 applyRackProblemMask($rackData);
1787 markupObjectProblems ($rackData);
1788 $response = processGridForm ($rackData, 'F', 'U');
1789 return buildWideRedirectURL (array($response));
1792 function querySNMPData ()
1794 assertUIntArg ('object_id');
1795 assertStringArg ('community');
1796 return doSNMPmining ($_REQUEST['object_id'], $_REQUEST['community']);
1799 $msgcode['addFileWithoutLink']['OK'] = 69;
1800 $msgcode['addFileWithoutLink']['ERR1'] = 181;
1801 $msgcode['addFileWithoutLink']['ERR2'] = 110;
1802 // File-related functions
1803 function addFileWithoutLink ()
1805 assertStringArg ('comment', TRUE);
1807 // Make sure the file can be uploaded
1808 if (get_cfg_var('file_uploads') != 1)
1809 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1811 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1813 if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']))
1814 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1815 if (isset ($_REQUEST['taglist']))
1816 produceTagsForLastRecord ('file', $_REQUEST['taglist']);
1817 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($_FILES['file']['name'])));
1820 $msgcode['addFileToEntity']['OK'] = 69;
1821 $msgcode['addFileToEntity']['ERR2'] = 181;
1822 $msgcode['addFileToEntity']['ERR3'] = 110;
1823 function addFileToEntity ()
1825 global $page, $pageno, $etype_by_pageno;
1826 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1827 throw new RackTablesError ('dispatching failure', RackTablesError
::INTERNAL
);
1828 $realm = $etype_by_pageno[$pageno];
1829 $bypass = $page[$pageno]['bypass'];
1830 assertUIntArg ($bypass);
1831 $entity_id = $_REQUEST[$bypass];
1832 assertStringArg ('comment', TRUE);
1834 // Make sure the file can be uploaded
1835 if (get_cfg_var('file_uploads') != 1)
1836 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1838 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1840 if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']))
1841 return buildRedirectURL (__FUNCTION__
, 'ERR3');
1842 if (FALSE === commitLinkFile (lastInsertID(), $realm, $entity_id))
1843 return buildRedirectURL (__FUNCTION__
, 'ERR3');
1845 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($_FILES['file']['name'])));
1848 $msgcode['linkFileToEntity']['OK'] = 71;
1849 $msgcode['linkFileToEntity']['ERR1'] = 178;
1850 $msgcode['linkFileToEntity']['ERR2'] = 110;
1851 function linkFileToEntity ()
1853 assertUIntArg ('file_id');
1854 global $page, $pageno, $etype_by_pageno;
1855 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1856 throw new RackTablesError ('dispatching failure', RackTablesError
::INTERNAL
);
1857 $entity_type = $etype_by_pageno[$pageno];
1858 $bypass_name = $page[$pageno]['bypass'];
1859 assertUIntArg ($bypass_name);
1861 $fi = spotEntity ('file', $_REQUEST['file_id']);
1862 if (FALSE === commitLinkFile ($_REQUEST['file_id'], $entity_type, $_REQUEST[$bypass_name]))
1863 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1865 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($fi['name'])));
1868 $msgcode['replaceFile']['OK'] = 70;
1869 $msgcode['replaceFile']['ERR1'] = 181;
1870 $msgcode['replaceFile']['ERR2'] = 207;
1871 $msgcode['replaceFile']['ERR3'] = 109;
1872 function replaceFile ()
1875 assertUIntArg ('file_id');
1877 // Make sure the file can be uploaded
1878 if (get_cfg_var('file_uploads') != 1)
1879 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1880 $shortInfo = spotEntity ('file', $sic['file_id']);
1882 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1884 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1885 if (FALSE === commitReplaceFile ($sic['file_id'], $fp))
1886 return buildRedirectURL (__FUNCTION__
, 'ERR3');
1888 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1891 $msgcode['updateFile']['OK'] = 70;
1892 $msgcode['updateFile']['ERR'] = 109;
1893 function updateFile ()
1895 assertUIntArg ('file_id');
1896 assertStringArg ('file_name');
1897 assertStringArg ('file_type');
1898 assertStringArg ('file_comment', TRUE);
1900 if (FALSE === commitUpdateFile ($sic['file_id'], $sic['file_name'], $sic['file_type'], $sic['file_comment']))
1901 return buildRedirectURL (__FUNCTION__
, 'ERR');
1902 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['file_name']));
1905 $msgcode['unlinkFile']['OK'] = 72;
1906 $msgcode['unlinkFile']['ERR'] = 182;
1907 function unlinkFile ()
1909 assertUIntArg ('link_id');
1910 $error = commitUnlinkFile ($_REQUEST['link_id']);
1913 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1915 return buildRedirectURL (__FUNCTION__
, 'OK');
1918 $msgcode['deleteFile']['OK'] = 73;
1919 $msgcode['deleteFile']['ERR'] = 100;
1920 function deleteFile ()
1922 assertUIntArg ('file_id');
1923 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
1924 $error = commitDeleteFile ($_REQUEST['file_id']);
1927 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1929 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1932 $msgcode['updateFileText']['OK'] = 78;
1933 $msgcode['updateFileText']['ERR1'] = 179;
1934 $msgcode['updateFileText']['ERR2'] = 180;
1935 function updateFileText ()
1937 assertUIntArg ('file_id');
1938 assertStringArg ('mtime_copy');
1939 assertStringArg ('file_text', TRUE); // it's Ok to save empty
1940 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
1941 if ($shortInfo['mtime'] != $_REQUEST['mtime_copy'])
1942 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1944 if (FALSE === commitReplaceFile ($sic['file_id'], $sic['file_text']))
1945 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1946 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1949 $msgcode['addPortInterfaceCompat']['OK'] = 48;
1950 $msgcode['addPortInterfaceCompat']['ERR'] = 110;
1951 function addPortInterfaceCompat ()
1953 assertUIntArg ('iif_id');
1954 assertUIntArg ('oif_id');
1955 if (commitSupplementPIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
1956 return buildRedirectURL (__FUNCTION__
, 'OK');
1957 return buildRedirectURL (__FUNCTION__
, 'ERR');
1960 $msgcode['delPortInterfaceCompat']['OK'] = 49;
1961 $msgcode['delPortInterfaceCompat']['ERR'] = 111;
1962 function delPortInterfaceCompat ()
1964 assertUIntArg ('iif_id');
1965 assertUIntArg ('oif_id');
1966 if (commitReducePIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
1967 return buildRedirectURL (__FUNCTION__
, 'OK');
1968 return buildRedirectURL (__FUNCTION__
, 'ERR');
1971 $ifcompatpack = array
1973 '1000cwdm80' => array (1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216),
1974 '1000dwdm80' => array // ITU channels 20~61
1976 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226,
1977 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236,
1978 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246,
1979 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256,
1982 '10000dwdm80' => array // same channels for 10GE
1984 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268,
1985 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278,
1986 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288,
1987 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298,
1992 $msgcode['addPortInterfaceCompatPack']['OK'] = 44;
1993 $msgcode['addPortInterfaceCompatPack']['ERR'] = 123;
1994 function addPortInterfaceCompatPack ()
1996 assertStringArg ('standard');
1997 assertUIntArg ('iif_id');
1998 global $ifcompatpack;
1999 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
2000 return buildRedirectURL (__FUNCTION__
, 'ERR');
2002 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2003 if (commitSupplementPIC ($_REQUEST['iif_id'], $oif_id))
2007 return buildRedirectURL (__FUNCTION__
, 'OK', array ($nbad, $ngood));
2010 $msgcode['delPortInterfaceCompatPack']['OK'] = 44;
2011 $msgcode['delPortInterfaceCompatPack']['ERR'] = 123;
2012 function delPortInterfaceCompatPack ()
2014 assertStringArg ('standard');
2015 assertUIntArg ('iif_id');
2016 global $ifcompatpack;
2017 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
2018 return buildRedirectURL (__FUNCTION__
, 'ERR');
2020 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2021 if (commitReducePIC ($_REQUEST['iif_id'], $oif_id))
2025 return buildRedirectURL (__FUNCTION__
, 'OK', array ($nbad, $ngood));
2028 $msgcode['addPortOIFCompat']['OK'] = 48;
2029 $msgcode['addPortOIFCompat']['ERR'] = 110;
2030 function addPortOIFCompat()
2032 assertUIntArg('type1');
2033 assertUIntArg('type2');
2034 if (commitSupplementPOIFC($_REQUEST['type1'], $_REQUEST['type2']))
2035 return buildRedirectURL(__FUNCTION__
, 'OK');
2036 return buildRedirectURL(__FUNCTION__
, 'ERR');
2039 $msgcode['delPortOIFCompat']['OK'] = 49;
2040 $msgcode['delPortOIFCompat']['ERR'] = 111;
2041 function delPortOIFCompat ()
2043 assertUIntArg('type1');
2044 assertUIntArg('type2');
2045 if (commitReducePOIFC ($_REQUEST['type1'], $_REQUEST['type2']) !== FALSE)
2046 return buildRedirectURL (__FUNCTION__
, 'OK');
2047 return buildRedirectURL (__FUNCTION__
, 'ERR');
2051 $msgcode['add8021QOrder']['OK'] = 48;
2052 $msgcode['add8021QOrder']['ERR'] = 118;
2053 function add8021QOrder ()
2055 assertUIntArg ('vdom_id');
2056 assertUIntArg ('object_id');
2057 assertUIntArg ('vst_id');
2059 $result = usePreparedExecuteBlade
2061 'INSERT INTO VLANSwitch (domain_id, object_id, template_id, last_change, out_of_sync) ' .
2062 'VALUES (?, ?, ?, NOW(), "yes")',
2063 array ($sic['vdom_id'], $sic['object_id'], $sic['vst_id'])
2065 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
2068 $msgcode['del8021QOrder']['OK'] = 49;
2069 $msgcode['del8021QOrder']['ERR'] = 119;
2070 function del8021QOrder ()
2072 assertUIntArg ('object_id');
2074 $result = usePreparedDeleteBlade ('VLANSwitch', array ('object_id' => $sic['object_id']));
2075 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2078 $msgcode['addVLANDescription']['OK'] = 48;
2079 $msgcode['addVLANDescription']['ERR1'] = 190;
2080 $msgcode['addVLANDescription']['ERR2'] = 110;
2081 function addVLANDescription ()
2083 assertUIntArg ('vlan_id');
2084 assertStringArg ('vlan_type', TRUE);
2085 assertStringArg ('vlan_descr', TRUE);
2087 if (!($sic['vlan_id'] >= VLAN_MIN_ID +
1 and $sic['vlan_id'] <= VLAN_MAX_ID
))
2088 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($sic['vlan_id']));
2089 $result = usePreparedInsertBlade
2094 'domain_id' => $sic['vdom_id'],
2095 'vlan_id' => $sic['vlan_id'],
2096 'vlan_type' => $sic['vlan_type'],
2097 'vlan_descr' => mb_strlen ($sic['vlan_descr']) ?
$sic['vlan_descr'] : NULL
2100 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR2');
2103 $msgcode['delVLANDescription']['OK'] = 49;
2104 $msgcode['delVLANDescription']['ERR1'] = 105;
2105 $msgcode['delVLANDescription']['ERR2'] = 111;
2106 function delVLANDescription ()
2108 assertUIntArg ('vlan_id');
2110 if ($sic['vlan_id'] == VLAN_DFL_ID
)
2111 return buildRedirectURL (__FUNCTION__
, 'ERR1');
2112 $result = commitReduceVLANDescription ($sic['vdom_id'], $sic['vlan_id']);
2113 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR2');
2116 $msgcode['updVLANDescription']['OK'] = 51;
2117 $msgcode['updVLANDescription']['ERR1'] = 105;
2118 $msgcode['updVLANDescription']['ERR2'] = 109;
2119 function updVLANDescription ()
2121 assertUIntArg ('vlan_id');
2122 assertStringArg ('vlan_type');
2123 assertStringArg ('vlan_descr', TRUE);
2125 if ($sic['vlan_id'] == VLAN_DFL_ID
)
2126 return buildRedirectURL (__FUNCTION__
, 'ERR1');
2127 $result = commitUpdateVLANDescription
2134 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR2');
2137 $msgcode['createVLANDomain']['OK'] = 48;
2138 $msgcode['createVLANDomain']['ERR'] = 110;
2139 function createVLANDomain ()
2141 assertStringArg ('vdom_descr');
2143 $result = usePreparedInsertBlade
2148 'description' => $sic['vdom_descr'],
2151 $result = $result and usePreparedInsertBlade
2156 'domain_id' => lastInsertID(),
2157 'vlan_id' => VLAN_DFL_ID
,
2158 'vlan_type' => 'compulsory',
2159 'vlan_descr' => 'default',
2162 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2165 $msgcode['destroyVLANDomain']['OK'] = 49;
2166 $msgcode['destroyVLANDomain']['ERR'] = 111;
2167 function destroyVLANDomain ()
2169 assertUIntArg ('vdom_id');
2171 $result = FALSE !== usePreparedDeleteBlade ('VLANDomain', array ('id' => $sic['vdom_id']));
2172 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2175 $msgcode['updateVLANDomain']['OK'] = 51;
2176 $msgcode['updateVLANDomain']['ERR'] = 109;
2177 function updateVLANDomain ()
2179 assertUIntArg ('vdom_id');
2180 assertStringArg ('vdom_descr');
2182 $result = FALSE !== commitUpdateVLANDomain ($sic['vdom_id'], $sic['vdom_descr']);
2183 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2186 $msgcode['save8021QPorts']['OK1'] = 63;
2187 $msgcode['save8021QPorts']['OK2'] = 41;
2188 $msgcode['save8021QPorts']['ERR1'] = 160;
2189 $msgcode['save8021QPorts']['ERR2'] = 109;
2190 function save8021QPorts ()
2192 global $sic, $dbxlink;
2193 assertUIntArg ('mutex_rev', TRUE); // counts from 0
2194 assertStringArg ('form_mode');
2195 if ($sic['form_mode'] != 'save' and $sic['form_mode'] != 'duplicate')
2196 throw new InvalidRequestArgException ('form_mode', $sic['form_mode']);
2198 $dbxlink->beginTransaction();
2201 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE'))
2202 throw new InvalidArgException ('object_id', $object_id, 'VLAN domain is not set for this object');
2203 if ($vswitch['mutex_rev'] != $sic['mutex_rev'])
2204 throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form data');
2205 $after = $before = apply8021QOrder ($vswitch['template_id'], getStored8021QConfig ($sic['object_id'], 'desired'));
2207 switch ($sic['form_mode'])
2210 assertUIntArg ('nports');
2211 if ($sic['nports'] == 1)
2213 assertStringArg ('pn_0');
2214 $extra = array ('port_name' => $sic['pn_0']);
2216 for ($i = 0; $i < $sic['nports']; $i++
)
2218 assertStringArg ('pn_' . $i);
2219 assertStringArg ('pm_' . $i);
2220 // An access port only generates form input for its native VLAN,
2221 // which we derive allowed VLAN list from.
2222 $native = isset ($sic['pnv_' . $i]) ?
$sic['pnv_' . $i] : 0;
2223 switch ($sic["pm_${i}"])
2226 # assertArrayArg ('pav_' . $i);
2227 $allowed = isset ($sic['pav_' . $i]) ?
$sic['pav_' . $i] : array();
2230 if ($native == 'same')
2232 assertUIntArg ('pnv_' . $i);
2233 $allowed = array ($native);
2236 throw new InvalidRequestArgException ("pm_${i}", $_REQUEST["pm_${i}"], 'unknown port mode');
2238 $changes[$sic['pn_' . $i]] = array
2240 'mode' => $sic['pm_' . $i],
2241 'allowed' => $allowed,
2242 'native' => $native,
2247 assertStringArg ('from_port');
2248 # assertArrayArg ('to_ports');
2249 if (!array_key_exists ($sic['from_port'], $before))
2250 throw new InvalidArgException ('from_port', $sic['from_port'], 'this port does not exist');
2251 foreach ($sic['to_ports'] as $tpn)
2252 if (!array_key_exists ($tpn, $before))
2253 throw new InvalidArgException ('to_ports[]', $tpn, 'this port does not exist');
2254 elseif ($tpn != $sic['from_port'])
2255 $changes[$tpn] = $before[$sic['from_port']];
2258 $domain_vlanlist = getDomainVLANs ($vswitch['domain_id']);
2259 $changes = filter8021QChangeRequests
2263 apply8021QOrder ($vswitch['template_id'], $changes)
2265 $changes = authorize8021QChangeRequests ($before, $changes);
2266 foreach ($changes as $port_name => $port)
2267 $after[$port_name] = $port;
2268 $new_uplinks = filter8021QChangeRequests ($domain_vlanlist, $after, produceUplinkPorts ($domain_vlanlist, $after));
2269 $npulled = replace8021QPorts ('desired', $vswitch['object_id'], $before, $changes);
2270 $nsaved_uplinks = replace8021QPorts ('desired', $vswitch['object_id'], $before, $new_uplinks);
2272 catch (Exception
$e)
2274 $dbxlink->rollBack();
2275 return buildRedirectURL (__FUNCTION__
, 'ERR2', array(), NULL, NULL, $extra);
2277 if ($npulled +
$nsaved_uplinks)
2278 $result = usePreparedExecuteBlade
2280 'UPDATE VLANSwitch SET mutex_rev=mutex_rev+1, last_change=NOW(), out_of_sync="yes" WHERE object_id=?',
2281 array ($sic['object_id'])
2284 $log = oneLiner (63, array ($npulled +
$nsaved_uplinks));
2285 if ($nsaved_uplinks)
2287 initiateUplinksReverb ($vswitch['object_id'], $new_uplinks);
2288 $log = mergeLogs ($log, oneLiner (41));
2290 if ($npulled +
$nsaved_uplinks > 0 and getConfigVar ('8021Q_INSTANT_DEPLOY') == 'yes')
2294 if (FALSE === $done = exec8021QDeploy ($sic['object_id'], TRUE))
2295 $log = mergeLogs ($log, oneLiner (191));
2297 $log = mergeLogs ($log, oneLiner (63, array ($done)));
2299 catch (Exception
$e)
2301 $log = mergeLogs ($log, oneLiner (109));
2304 return buildWideRedirectURL ($log, NULL, NULL, $extra);
2307 $msgcode['bindVLANtoIPv4']['OK'] = 48;
2308 $msgcode['bindVLANtoIPv4']['ERR'] = 110;
2309 function bindVLANtoIPv4 ()
2311 assertUIntArg ('id'); // network id
2313 $result = commitSupplementVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2314 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2317 $msgcode['unbindVLANfromIPv4']['OK'] = 49;
2318 $msgcode['unbindVLANfromIPv4']['ERR'] = 111;
2319 function unbindVLANfromIPv4 ()
2321 assertUIntArg ('id'); // network id
2323 $result = commitReduceVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2324 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2327 $msgcode['process8021QSyncRequest']['OK'] = 63;
2328 $msgcode['process8021QSyncRequest']['ERR'] = 191;
2329 function process8021QSyncRequest ()
2331 // behave depending on current operation: exec8021QPull or exec8021QPush
2333 if (FALSE === $done = exec8021QDeploy ($sic['object_id'], $op == 'exec8021QPush'))
2334 return buildRedirectURL (__FUNCTION__
, 'ERR');
2335 return buildRedirectURL (__FUNCTION__
, 'OK', array ($done));
2338 $msgcode['resolve8021QConflicts']['OK'] = 63;
2339 $msgcode['resolve8021QConflicts']['ERR1'] = 179;
2340 $msgcode['resolve8021QConflicts']['ERR2'] = 109;
2341 function resolve8021QConflicts ()
2343 global $sic, $dbxlink;
2344 assertUIntArg ('mutex_rev', TRUE); // counts from 0
2345 assertUIntArg ('nrows');
2346 // Divide submitted radio buttons into 3 groups:
2347 // left (saved version wins)
2349 // right (running version wins)
2351 for ($i = 0; $i < $sic['nrows']; $i++
)
2353 if (!array_key_exists ("i_${i}", $sic))
2355 // let's hope other inputs are in place
2356 switch ($sic["i_${i}"])
2360 $F[$sic["pn_${i}"]] = array
2362 'mode' => $sic["rm_${i}"],
2363 'allowed' => $sic["ra_${i}"],
2364 'native' => $sic["rn_${i}"],
2365 'decision' => $sic["i_${i}"],
2372 $dbxlink->beginTransaction();
2375 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE'))
2376 throw new InvalidArgException ('object_id', $sic['object_id'], 'VLAN domain is not set for this object');
2377 if ($vswitch['mutex_rev'] != $sic['mutex_rev'])
2378 throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form (table data has changed)');
2379 $D = getStored8021QConfig ($vswitch['object_id'], 'desired');
2380 $C = getStored8021QConfig ($vswitch['object_id'], 'cached');
2381 $R = getRunning8021QConfig ($vswitch['object_id']);
2382 $plan = get8021QSyncOptions ($vswitch, $D, $C, $R['portdata']);
2384 foreach ($F as $port_name => $port)
2386 if (!array_key_exists ($port_name, $plan))
2388 elseif ($plan[$port_name]['status'] == 'merge_conflict')
2390 // for R neither mutex nor revisions can be emulated, but revision change can be
2391 if (!same8021QConfigs ($port, $R['portdata'][$port_name]))
2392 throw new InvalidRequestArgException ("port ${port_name}", '(hidden)', 'expired form (switch data has changed)');
2393 if ($port['decision'] == 'right') // D wins, frame R by writing value of R to C
2394 $ndone +
= upd8021QPort ('cached', $vswitch['object_id'], $port_name, $port);
2395 elseif ($port['decision'] == 'left') // R wins, cross D up
2396 $ndone +
= upd8021QPort ('cached', $vswitch['object_id'], $port_name, $D[$port_name]);
2397 // otherwise there was no decision made
2401 $plan[$port_name]['status'] == 'delete_conflict' or
2402 $plan[$port_name]['status'] == 'martian_conflict'
2405 if ($port['decision'] == 'left') // confirm deletion of local copy
2406 $ndone +
= del8021QPort ($vswitch['object_id'], $port_name);
2408 // otherwise ignore a decision, which doesn't address a conflict
2411 catch (InvalidRequestArgException
$e)
2413 $dbxlink->rollBack();
2414 return buildRedirectURL (__FUNCTION__
, 'ERR1');
2416 catch (Exception
$e)
2418 $dbxlink->rollBack();
2419 return buildRedirectURL (__FUNCTION__
, 'ERR2');
2422 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ndone));
2425 $msgcode['addVLANSwitchTemplate']['OK'] = 48;
2426 $msgcode['addVLANSwitchTemplate']['ERR'] = 110;
2427 function addVLANSwitchTemplate()
2429 assertStringArg ('vst_descr');
2431 $max_local_vlans = NULL;
2432 if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans']))
2434 assertUIntArg ('vst_maxvlans');
2435 $max_local_vlans = $sic['vst_maxvlans'];
2437 $result = usePreparedInsertBlade
2439 'VLANSwitchTemplate',
2442 'max_local_vlans' => $max_local_vlans,
2443 'description' => $sic['vst_descr'],
2446 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2449 $msgcode['delVLANSwitchTemplate']['OK'] = 49;
2450 $msgcode['delVLANSwitchTemplate']['ERR'] = 111;
2451 function delVLANSwitchTemplate()
2453 assertUIntArg ('vst_id');
2455 $result = FALSE !== usePreparedDeleteBlade ('VLANSwitchTemplate', array ('id' => $sic['vst_id']));
2456 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2459 $msgcode['updVLANSwitchTemplate']['OK'] = 51;
2460 $msgcode['updVLANSwitchTemplate']['ERR'] = 109;
2461 function updVLANSwitchTemplate()
2463 assertUIntArg ('vst_id');
2464 assertStringArg ('vst_descr');
2466 $max_local_vlans = NULL;
2467 if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans']))
2469 assertUIntArg ('vst_maxvlans');
2470 $max_local_vlans = $sic['vst_maxvlans'];
2472 $result = commitUpdateVST ($sic['vst_id'], $max_local_vlans, $sic['vst_descr']);
2473 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
2476 $msgcode['addVSTRule']['OK'] = 48;
2477 $msgcode['addVSTRule']['ERR'] = 110;
2478 function addVSTRule()
2480 assertUIntArg ('vst_id');
2481 assertUIntArg ('rule_no');
2482 assertPCREArg ('port_pcre');
2483 assertStringArg ('port_role');
2484 assertStringArg ('wrt_vlans', TRUE);
2485 assertStringArg ('description', TRUE);
2487 $result = usePreparedInsertBlade
2492 'vst_id' => $sic['vst_id'],
2493 'rule_no' => $sic['rule_no'],
2494 'port_pcre' => $sic['port_pcre'],
2495 'port_role' => $sic['port_role'],
2496 'wrt_vlans' => $sic['wrt_vlans'],
2497 'description' => $sic['description'],
2500 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2503 $msgcode['delVSTRule']['OK'] = 49;
2504 $msgcode['delVSTRule']['ERR'] = 111;
2505 function delVSTRule()
2507 assertUIntArg ('vst_id');
2508 assertUIntArg ('rule_no');
2510 $result = FALSE !== usePreparedDeleteBlade
2515 'vst_id' => $sic['vst_id'],
2516 'rule_no' => $sic['rule_no']
2519 return buildRedirectURL (__FUNCTION__
, $result ?
'OK' : 'ERR');
2522 $msgcode['updVSTRule']['OK'] = 51;
2523 $msgcode['updVSTRule']['ERR'] = 109;
2524 function updVSTRule()
2526 assertUIntArg ('vst_id');
2527 assertUIntArg ('rule_no');
2528 assertUIntArg ('new_rule_no');
2529 assertPCREArg ('port_pcre');
2530 assertStringArg ('port_role');
2531 assertStringArg ('wrt_vlans', TRUE);
2532 assertStringArg ('description', TRUE);
2534 $result = commitUpdateVSTRule
2538 $sic['new_rule_no'],
2544 return buildRedirectURL (__FUNCTION__
, $result !== FALSE ?
'OK' : 'ERR');
2547 $msgcode['importDPData']['OK'] = 44;
2548 function importDPData()
2551 assertUIntArg ('nports');
2552 $nignored = $ndone = 0;
2553 $POIFC = getPortOIFCompat();
2554 for ($i = 0; $i < $sic['nports']; $i++
)
2555 if (array_key_exists ("do_${i}", $sic))
2557 assertUIntArg ("pid1_${i}");
2558 assertUIntArg ("pid2_${i}");
2559 $porta = getPortInfo ($_REQUEST["pid1_${i}"]);
2560 $portb = getPortInfo ($_REQUEST["pid2_${i}"]);
2565 ($porta['object_id'] != $sic['object_id'] and $portb['object_id'] != $sic['object_id'])
2571 foreach ($POIFC as $item)
2572 if ($item['type1'] == $porta['oif_id'] and $item['type2'] == $portb['oif_id'])
2574 linkPorts ($_REQUEST["pid1_${i}"], $_REQUEST["pid2_${i}"]);
2576 continue 2; // next port
2580 return buildRedirectURL (__FUNCTION__
, 'OK', array ($nignored, $ndone));