4 * This file is a library of operation handlers for RackTables.
8 // This function assures that specified argument was passed
9 // and is a number greater than zero.
10 function assertUIntArg ($argname, $caller = 'N/A', $allow_zero = FALSE)
12 if (!isset ($_REQUEST[$argname]))
14 showError ("Parameter '${argname}' is missing (calling function is [${caller}]).", __FUNCTION__
);
17 if (!is_numeric ($_REQUEST[$argname]))
19 showError ("Parameter '${argname}' is not a number (calling function is [${caller}]).", __FUNCTION__
);
22 if ($_REQUEST[$argname] < 0)
24 showError ("Parameter '${argname}' is less than zero (calling function is [${caller}]).", __FUNCTION__
);
27 if (!$allow_zero and $_REQUEST[$argname] == 0)
29 showError ("Parameter '${argname}' is equal to zero (calling function is [${caller}]).", __FUNCTION__
);
34 // This function assures that specified argument was passed
35 // and is a non-empty string.
36 function assertStringArg ($argname, $caller = 'N/A', $ok_if_empty = FALSE)
38 if (!isset ($_REQUEST[$argname]))
40 showError ("Parameter '${argname}' is missing (calling function is [${caller}]).", __FUNCTION__
);
43 if (!is_string ($_REQUEST[$argname]))
45 showError ("Parameter '${argname}' is not a string (calling function is [${caller}]).", __FUNCTION__
);
48 if (!$ok_if_empty and empty ($_REQUEST[$argname]))
50 showError ("Parameter '${argname}' is an empty string (calling function is [${caller}]).", __FUNCTION__
);
55 function assertBoolArg ($argname, $caller = 'N/A', $ok_if_empty = FALSE)
57 if (!isset ($_REQUEST[$argname]))
59 showError ("Parameter '${argname}' is missing (calling function is [${caller}]).", __FUNCTION__
);
62 if (!is_string ($_REQUEST[$argname]) or $_REQUEST[$argname] != 'on')
64 showError ("Parameter '${argname}' is not a string (calling function is [${caller}]).", __FUNCTION__
);
67 if (!$ok_if_empty and empty ($_REQUEST[$argname]))
69 showError ("Parameter '${argname}' is an empty string (calling function is [${caller}]).", __FUNCTION__
);
74 function assertIPv4Arg ($argname, $caller = 'N/A', $ok_if_empty = FALSE)
76 assertStringArg ($argname, $caller, $ok_if_empty);
77 if (!empty ($_REQUEST[$argname]) and long2ip (ip2long ($_REQUEST[$argname])) !== $_REQUEST[$argname])
79 showError ("IPv4 address validation failed for value '" . $_REQUEST[$argname] . "' (calling function is [${caller}]).", __FUNCTION__
);
84 function addPortForwarding ()
86 assertUIntArg ('object_id', __FUNCTION__
);
87 assertIPv4Arg ('localip', __FUNCTION__
);
88 assertIPv4Arg ('remoteip', __FUNCTION__
);
89 assertUIntArg ('localport', __FUNCTION__
);
90 assertStringArg ('proto', __FUNCTION__
);
91 assertStringArg ('description', __FUNCTION__
, TRUE);
92 $remoteport = isset ($_REQUEST['remoteport']) ?
$_REQUEST['remoteport'] : '';
93 if (empty ($remoteport))
94 $remoteport = $_REQUEST['localport'];
96 $error = newPortForwarding
98 $_REQUEST['object_id'],
100 $_REQUEST['localport'],
101 $_REQUEST['remoteip'],
104 $_REQUEST['description']
108 return buildRedirectURL (__FUNCTION__
, 'OK');
110 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
113 function delPortForwarding ()
115 assertUIntArg ('object_id', __FUNCTION__
);
116 assertIPv4Arg ('localip', __FUNCTION__
);
117 assertIPv4Arg ('remoteip', __FUNCTION__
);
118 assertUIntArg ('localport', __FUNCTION__
);
119 assertUIntArg ('remoteport', __FUNCTION__
);
120 assertStringArg ('proto', __FUNCTION__
);
122 $error = deletePortForwarding
124 $_REQUEST['object_id'],
125 $_REQUEST['localip'],
126 $_REQUEST['localport'],
127 $_REQUEST['remoteip'],
128 $_REQUEST['remoteport'],
132 return buildRedirectURL (__FUNCTION__
, 'OK');
134 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
137 function updPortForwarding ()
139 assertUIntArg ('object_id', __FUNCTION__
);
140 assertIPv4Arg ('localip', __FUNCTION__
);
141 assertIPv4Arg ('remoteip', __FUNCTION__
);
142 assertUIntArg ('localport', __FUNCTION__
);
143 assertUIntArg ('remoteport', __FUNCTION__
);
144 assertStringArg ('proto', __FUNCTION__
);
145 assertStringArg ('description', __FUNCTION__
);
147 $error = updatePortForwarding
149 $_REQUEST['object_id'],
150 $_REQUEST['localip'],
151 $_REQUEST['localport'],
152 $_REQUEST['remoteip'],
153 $_REQUEST['remoteport'],
155 $_REQUEST['description']
158 return buildRedirectURL (__FUNCTION__
, 'OK');
160 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
163 function addPortForObject ()
165 assertUIntArg ('object_id', __FUNCTION__
);
166 assertStringArg ('port_name', __FUNCTION__
, TRUE);
167 if (empty ($_REQUEST['port_name']))
168 return buildRedirectURL (__FUNCTION__
, 'ERR1');
169 $error = commitAddPort ($_REQUEST['object_id'], $_REQUEST['port_name'], $_REQUEST['port_type_id'], $_REQUEST['port_label'], $_REQUEST['port_l2address']);
171 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
173 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['port_name']));
176 function editPortForObject ()
178 assertUIntArg ('port_id', __FUNCTION__
);
179 assertUIntArg ('port_type_id', __FUNCTION__
);
180 // tolerate empty value now to produce custom informative message later
181 assertStringArg ('name', __FUNCTION__
, TRUE);
182 if (empty ($_REQUEST['name']))
183 return buildRedirectURL (__FUNCTION__
, 'ERR1');
185 if (isset ($_REQUEST['reservation_comment']) and !empty ($_REQUEST['reservation_comment']))
186 $port_rc = '"' . $_REQUEST['reservation_comment'] . '"';
189 $error = commitUpdatePort ($_REQUEST['port_id'], $_REQUEST['name'], $_REQUEST['port_type_id'], $_REQUEST['label'], $_REQUEST['l2address'], $port_rc);
191 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
193 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
196 function delPortFromObject ()
198 assertUIntArg ('port_id', __FUNCTION__
);
199 $error = delObjectPort ($_REQUEST['port_id']);
202 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
204 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['port_name']));
207 function linkPortForObject ()
209 assertUIntArg ('port_id', __FUNCTION__
);
210 assertUIntArg ('remote_port_id', __FUNCTION__
);
211 assertStringArg ('port_name', __FUNCTION__
, TRUE);
212 assertStringArg ('remote_port_name', __FUNCTION__
, TRUE);
213 assertStringArg ('remote_object_name', __FUNCTION__
, TRUE);
215 $error = linkPorts ($_REQUEST['port_id'], $_REQUEST['remote_port_id']);
217 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
219 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['port_name'], $_REQUEST['remote_port_name'], $_REQUEST['remote_object_name']));
222 function unlinkPortForObject ()
224 assertUIntArg ('port_id', __FUNCTION__
);
225 assertStringArg ('port_name', __FUNCTION__
, TRUE);
226 assertStringArg ('remote_port_name', __FUNCTION__
, TRUE);
227 assertStringArg ('remote_object_name', __FUNCTION__
, TRUE);
229 $error = unlinkPort ($_REQUEST['port_id']);
231 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
233 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['port_name'], $_REQUEST['remote_port_name'], $_REQUEST['remote_object_name']));
236 function addMultiPorts ()
238 assertStringArg ('format', __FUNCTION__
);
239 assertStringArg ('input', __FUNCTION__
);
240 assertUIntArg ('port_type', __FUNCTION__
);
241 assertUIntArg ('object_id', __FUNCTION__
);
242 $format = $_REQUEST['format'];
243 $port_type = $_REQUEST['port_type'];
244 $object_id = $_REQUEST['object_id'];
245 // Input lines are escaped, so we have to explode and to chop by 2-char
246 // \n and \r respectively.
247 $lines1 = explode ('\n', $_REQUEST['input']);
248 foreach ($lines1 as $line)
250 $parts = explode ('\r', $line);
252 if (empty ($parts[0]))
255 $lines2[] = rtrim ($parts[0]);
258 foreach ($lines2 as $line)
263 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
264 list ($slot, $port) = explode ('/', $words[0]);
267 'name' => "e ${slot}/${port}",
268 'l2address' => $words[8],
269 'label' => "slot ${slot} port ${port}"
273 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', trim (substr ($line, 3))));
275 How Async Lines are Numbered in Cisco 3600 Series Routers
276 http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00801ca70b.shtml
278 Understanding 16- and 32-Port Async Network Modules
279 http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00800a93f0.shtml
282 $slot = floor (($async - 1) / 32);
283 $octalgroup = floor (($async - 1 - $slot * 32) / 8);
284 $cable = $async - $slot * 32 - $octalgroup * 8;
285 $og_label[0] = 'async 0-7';
286 $og_label[1] = 'async 8-15';
287 $og_label[2] = 'async 16-23';
288 $og_label[3] = 'async 24-31';
291 'name' => "async ${async}",
293 'label' => "slot ${slot} " . $og_label[$octalgroup] . " cable ${cable}"
297 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
298 $ifnumber = $words[0] * 1;
301 'name' => "e ${ifnumber}",
302 'l2address' => "${words[8]}",
303 'label' => "${ifnumber}"
307 $words = explode (' ', $line);
308 if (empty ($words[0]) or empty ($words[1]))
313 'l2address' => $words[1],
318 return buildRedirectURL (__FUNCTION__
, 'ERR');
322 // Create ports, if they don't exist.
323 $added_count = $updated_count = $error_count = 0;
324 foreach ($ports as $port)
326 $port_id = getPortID ($object_id, $port['name']);
327 if ($port_id === NULL)
329 $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
337 $result = commitUpdatePort ($port_id, $port['name'], $port_type, $port['label'], $port['l2address']);
344 return buildRedirectURL (__FUNCTION__
, 'OK', array ($added_count, $updated_count, $error_count));
347 function updIPv4Allocation ()
349 assertIPv4Arg ('ip', __FUNCTION__
);
350 assertUIntArg ('object_id', __FUNCTION__
);
351 assertStringArg ('bond_name', __FUNCTION__
, TRUE);
352 assertStringArg ('bond_type', __FUNCTION__
);
354 $error = updateBond ($_REQUEST['ip'], $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
356 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
358 return buildRedirectURL (__FUNCTION__
, 'OK');
361 function delIPv4Allocation ()
363 assertIPv4Arg ('ip', __FUNCTION__
);
364 assertUIntArg ('object_id', __FUNCTION__
);
366 $error = unbindIpFromObject ($_REQUEST['ip'], $_REQUEST['object_id']);
368 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
370 return buildRedirectURL (__FUNCTION__
, 'OK');
373 function addIPv4Allocation ()
375 assertIPv4Arg ('ip', __FUNCTION__
);
376 assertUIntArg ('object_id', __FUNCTION__
);
377 assertStringArg ('bond_name', __FUNCTION__
, TRUE);
378 assertStringArg ('bond_type', __FUNCTION__
);
381 $ip = ereg_replace ('/[[:digit:]]+$', '', $_REQUEST['ip']);
382 if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv4AddressNetworkId ($ip))
383 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($ip));
385 $error = bindIpToObject ($ip, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
387 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
388 $address = getIPv4Address ($ip);
389 if ($address['reserved'] == 'yes' or !empty ($address['name']))
391 $release = getConfigVar ('IPV4_AUTO_RELEASE');
393 $address['reserved'] = 'no';
395 $address['name'] = '';
396 updateAddress ($ip, $address['name'], $address['reserved']);
398 return buildRedirectURL (__FUNCTION__
, 'OK');
401 function addIPv4Prefix ()
403 assertStringArg ('range', __FUNCTION__
);
404 assertStringArg ('name', __FUNCTION__
, TRUE);
406 $is_bcast = isset ($_REQUEST['is_bcast']) ?
$_REQUEST['is_bcast'] : 'off';
407 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
408 $error = createIPv4Prefix ($_REQUEST['range'], $_REQUEST['name'], $is_bcast == 'on', $taglist);
410 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
412 return buildRedirectURL (__FUNCTION__
, 'OK');
415 function delIPv4Prefix ()
417 assertUIntArg ('id', __FUNCTION__
);
418 $error = destroyIPv4Prefix ($_REQUEST['id']);
420 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
422 return buildRedirectURL (__FUNCTION__
, 'OK');
425 function updIPv4Prefix ()
427 assertUIntArg ('id', __FUNCTION__
);
428 assertStringArg ('name', __FUNCTION__
, TRUE);
430 $error = updateRange ($_REQUEST['id'], $_REQUEST['name']);
432 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
434 return buildRedirectURL (__FUNCTION__
, 'OK');
437 function editAddress ()
439 assertIPv4Arg ('ip', __FUNCTION__
);
440 assertStringArg ('name', __FUNCTION__
, TRUE);
442 if (isset ($_REQUEST['reserved']))
443 $reserved = $_REQUEST['reserved'];
446 $error = updateAddress ($_REQUEST['ip'], $_REQUEST['name'], $reserved == 'on' ?
'yes' : 'no');
448 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
450 return buildRedirectURL (__FUNCTION__
, 'OK');
453 function createUser ()
455 assertStringArg ('username', __FUNCTION__
);
456 assertStringArg ('realname', __FUNCTION__
, TRUE);
457 assertStringArg ('password', __FUNCTION__
);
458 $username = $_REQUEST['username'];
459 $password = hash (PASSWORD_HASH
, $_REQUEST['password']);
460 $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password);
462 return buildRedirectURL (__FUNCTION__
, 'OK', array ($username));
464 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($username));
467 function updateUser ()
469 assertUIntArg ('user_id', __FUNCTION__
);
470 assertStringArg ('username', __FUNCTION__
);
471 assertStringArg ('realname', __FUNCTION__
, TRUE);
472 assertStringArg ('password', __FUNCTION__
);
473 $username = $_REQUEST['username'];
474 $new_password = $_REQUEST['password'];
475 $old_hash = getHashByID ($_REQUEST['user_id']);
476 if ($old_hash == NULL)
477 return buildRedirectURL (__FUNCTION__
, 'ERR1');
478 // Update user password only if provided password is not the same as current password hash.
479 if ($new_password != $old_hash)
480 $new_password = hash (PASSWORD_HASH
, $new_password);
481 $result = commitUpdateUserAccount ($_REQUEST['user_id'], $username, $_REQUEST['realname'], $new_password);
483 return buildRedirectURL (__FUNCTION__
, 'OK', array ($username));
485 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($username));
488 // This function find differences in users's submit and PortCompat table
489 // and modifies database accordingly.
490 function savePortMap ()
492 $ptlist = getPortTypes();
493 $oldCompat = getPortCompat();
494 $newCompat = array();
495 foreach (array_keys ($ptlist) as $leftKey)
496 foreach (array_keys ($ptlist) as $rightKey)
497 if (isset ($_REQUEST["atom_${leftKey}_${rightKey}"]))
498 $newCompat[] = array ('type1' => $leftKey, 'type2' => $rightKey);
499 // Build the new matrix from user's submit and compare it to
500 // the old matrix. Those pairs which appear on
501 // new matrix only, have to be stored in PortCompat table. Those who appear
502 // on the old matrix only, should be removed from PortCompat table.
503 // Those present in both matrices should be skipped.
504 $oldCompatTable = buildPortCompatMatrixFromList ($ptlist, $oldCompat);
505 $newCompatTable = buildPortCompatMatrixFromList ($ptlist, $newCompat);
506 $error_count = $success_count = 0;
507 foreach (array_keys ($ptlist) as $type1)
508 foreach (array_keys ($ptlist) as $type2)
509 if ($oldCompatTable[$type1][$type2] != $newCompatTable[$type1][$type2])
510 switch ($oldCompatTable[$type1][$type2])
512 case TRUE: // new value is FALSE
513 if (removePortCompat ($type1, $type2) === TRUE)
518 case FALSE: // new value is TRUE
519 if (addPortCompat ($type1, $type2) === TRUE)
525 showError ('Internal error: oldCompatTable is invalid', __FUNCTION__
);
528 if ($error_count == 0)
529 return buildRedirectURL (__FUNCTION__
, 'OK', array ($error_count, $success_count));
531 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error_count, $success_count));
534 function updateDictionary ()
536 assertUIntArg ('chapter_no', __FUNCTION__
);
537 assertUIntArg ('dict_key', __FUNCTION__
);
538 assertStringArg ('dict_value', __FUNCTION__
);
539 if (commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value']) === TRUE)
540 return buildRedirectURL (__FUNCTION__
, 'OK');
542 return buildRedirectURL (__FUNCTION__
, 'ERR');
545 function supplementDictionary ()
547 assertUIntArg ('chapter_no', __FUNCTION__
);
548 assertStringArg ('dict_value', __FUNCTION__
);
549 if (commitSupplementDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_value']) === TRUE)
550 return buildRedirectURL (__FUNCTION__
, 'OK');
552 return buildRedirectURL (__FUNCTION__
, 'ERR');
555 function reduceDictionary ()
557 assertUIntArg ('chapter_no', __FUNCTION__
);
558 assertUIntArg ('dict_key', __FUNCTION__
);
559 if (commitReduceDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key']) === TRUE)
560 return buildRedirectURL (__FUNCTION__
, 'OK');
562 return buildRedirectURL (__FUNCTION__
, 'ERR');
565 function addChapter ()
567 assertStringArg ('chapter_name', __FUNCTION__
);
568 if (commitAddChapter ($_REQUEST['chapter_name']) === TRUE)
569 return buildRedirectURL (__FUNCTION__
, 'OK');
571 return buildRedirectURL (__FUNCTION__
, 'ERR');
574 function updateChapter ()
576 assertUIntArg ('chapter_no', __FUNCTION__
);
577 assertStringArg ('chapter_name', __FUNCTION__
);
578 if (commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name']) === TRUE)
579 return buildRedirectURL (__FUNCTION__
, 'OK');
581 return buildRedirectURL (__FUNCTION__
, 'ERR');
584 function delChapter ()
586 assertUIntArg ('chapter_no', __FUNCTION__
);
587 if (commitDeleteChapter ($_REQUEST['chapter_no']))
588 return buildRedirectURL (__FUNCTION__
, 'OK');
590 return buildRedirectURL (__FUNCTION__
, 'ERR');
593 function changeAttribute ()
595 assertUIntArg ('attr_id', __FUNCTION__
);
596 assertStringArg ('attr_name', __FUNCTION__
);
597 if (commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name']))
598 return buildRedirectURL (__FUNCTION__
, 'OK');
600 return buildRedirectURL (__FUNCTION__
, 'ERR');
603 function createAttribute ()
605 assertStringArg ('attr_name', __FUNCTION__
);
606 assertStringArg ('attr_type', __FUNCTION__
);
607 if (commitAddAttribute ($_REQUEST['attr_name'], $_REQUEST['attr_type']))
608 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['attr_name']));
610 return buildRedirectURL (__FUNCTION__
, 'ERR');
613 function deleteAttribute ()
615 assertUIntArg ('attr_id', __FUNCTION__
);
616 if (commitDeleteAttribute ($_REQUEST['attr_id']))
617 return buildRedirectURL (__FUNCTION__
, 'OK');
619 return buildRedirectURL (__FUNCTION__
, 'ERR');
622 function supplementAttrMap ()
624 assertUIntArg ('attr_id', __FUNCTION__
);
625 assertUIntArg ('objtype_id', __FUNCTION__
);
626 assertUIntArg ('chapter_no', __FUNCTION__
);
627 if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $_REQUEST['chapter_no']) === TRUE)
628 return buildRedirectURL (__FUNCTION__
, 'OK');
630 return buildRedirectURL (__FUNCTION__
, 'ERR');
633 function reduceAttrMap ()
635 assertUIntArg ('attr_id', __FUNCTION__
);
636 assertUIntArg ('objtype_id', __FUNCTION__
);
637 if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) === TRUE)
638 return buildRedirectURL (__FUNCTION__
, 'OK');
640 return buildRedirectURL (__FUNCTION__
, 'ERR');
643 function clearSticker ()
645 assertUIntArg ('attr_id', __FUNCTION__
);
646 assertUIntArg ('object_id', __FUNCTION__
);
647 if (commitResetAttrValue ($_REQUEST['object_id'], $_REQUEST['attr_id']) === TRUE)
648 return buildRedirectURL (__FUNCTION__
, 'OK');
650 return buildRedirectURL (__FUNCTION__
, 'ERR');
653 function updateObjectAllocation ()
655 assertUIntArg ('object_id', __FUNCTION__
);
657 $is_submit = isset ($_REQUEST['got_atoms']);
658 $is_update = isset ($_REQUEST['rackmulti'][0]);
660 error_log(print_r($_REQUEST,1));
661 error_log(print_r($_REQUEST,1));
665 $object_id = $_REQUEST['object_id'];
666 $workingRacksData = getResidentRacksData ($object_id);
667 if ($workingRacksData === NULL)
669 print_r ($workingRacksData);
670 showError ('getResidentRacksData() failed', __FUNCTION__
);
673 foreach ($_REQUEST['rackmulti'] as $cand_id)
675 if (!isset ($workingRacksData[$cand_id]))
677 $rackData = getRackData ($cand_id);
678 if ($rackData == NULL)
680 showError ('getRackData() failed', __FUNCTION__
);
683 $workingRacksData[$cand_id] = $rackData;
686 foreach ($workingRacksData as &$rackData)
687 applyObjectMountMask ($rackData, $object_id);
689 $oldMolecule = getMoleculeForObject ($object_id);
690 $worldchanged = FALSE;
692 foreach ($workingRacksData as $rack_id => $rackData)
694 $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
697 return buildWideRedirectURL($log);
702 unset($_REQUEST['page']);
703 unset($_REQUEST['tab']);
704 unset($_REQUEST['op']);
705 return buildWideRedirectURL('', NULL, NULL, $_REQUEST);
711 function updateObject ()
713 assertUIntArg ('num_attrs', __FUNCTION__
);
714 assertUIntArg ('object_id', __FUNCTION__
);
715 assertUIntArg ('object_type_id', __FUNCTION__
);
716 assertStringArg ('object_name', __FUNCTION__
, TRUE);
717 assertStringArg ('object_label', __FUNCTION__
, TRUE);
718 assertStringArg ('object_barcode', __FUNCTION__
, TRUE);
719 assertStringArg ('object_asset_no', __FUNCTION__
, TRUE);
720 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
721 $has_problems = 'yes';
723 $has_problems = 'no';
725 if (commitUpdateObject (
726 $_REQUEST['object_id'],
727 $_REQUEST['object_name'],
728 $_REQUEST['object_label'],
729 $_REQUEST['object_barcode'],
730 $_REQUEST['object_type_id'],
732 $_REQUEST['object_asset_no'],
733 $_REQUEST['object_comment']
735 return buildRedirectURL (__FUNCTION__
, 'ERR');
737 // Update optional attributes
738 $oldvalues = getAttrValues ($_REQUEST['object_id']);
740 for ($i = 0; $i < $_REQUEST['num_attrs']; $i++
)
742 assertUIntArg ("${i}_attr_id", __FUNCTION__
);
743 $attr_id = $_REQUEST["${i}_attr_id"];
745 // Field is empty, delete attribute and move on.
746 if (empty($_REQUEST["${i}_value"]))
748 commitResetAttrValue ($_REQUEST['object_id'], $attr_id);
752 // The value could be uint/float, but we don't know ATM. Let SQL
753 // server check this and complain.
754 assertStringArg ("${i}_value", __FUNCTION__
);
755 $value = $_REQUEST["${i}_value"];
756 switch ($oldvalues[$attr_id]['type'])
761 $oldvalue = $oldvalues[$attr_id]['value'];
764 $oldvalue = $oldvalues[$attr_id]['key'];
767 showError ('Internal structure error', __FUNCTION__
);
770 if ($value == $oldvalue)
773 // Note if the queries succeed or not, it determines which page they see.
774 $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value);
776 if (in_array (FALSE, $result))
777 return buildRedirectURL (__FUNCTION__
, 'ERR');
779 // Invalidate thumb cache of all racks objects could occupy.
780 foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id)
781 resetThumbCache ($rack_id);
783 return buildRedirectURL (__FUNCTION__
, 'OK');
786 function deleteObject ()
788 assertUIntArg ('object_id', __FUNCTION__
);
789 $error = commitDeleteObject ($_REQUEST['object_id']);
792 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
794 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
797 function useupPort ()
799 assertUIntArg ('port_id', __FUNCTION__
);
800 if (commitUseupPort ($_REQUEST['port_id']) === TRUE)
801 return buildRedirectURL (__FUNCTION__
, 'OK');
803 return buildRedirectURL (__FUNCTION__
, 'ERR');
808 assertUIntArg ('num_vars', __FUNCTION__
);
811 for ($i = 0; $i < $_REQUEST['num_vars']; $i++
)
813 assertStringArg ("${i}_varname", __FUNCTION__
);
814 assertStringArg ("${i}_varvalue", __FUNCTION__
, TRUE);
815 $varname = $_REQUEST["${i}_varname"];
816 $varvalue = $_REQUEST["${i}_varvalue"];
818 // If form value = value in DB, don't bother updating DB
819 if ($varvalue == getConfigVar ($varname))
822 // Note if the queries succeed or not, it determines which page they see.
823 $error = setConfigVar ($varname, $varvalue, TRUE);
829 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
831 return buildRedirectURL (__FUNCTION__
, 'OK');
834 function resetUIConfig()
836 setConfigVar ('default_port_type','24');
837 setConfigVar ('MASSCOUNT','15');
838 setConfigVar ('MAXSELSIZE','30');
839 setConfigVar ('NAMEFUL_OBJTYPES','4,7,8');
840 setConfigVar ('ROW_SCALE','2');
841 setConfigVar ('PORTS_PER_ROW','12');
842 setConfigVar ('IPV4_ADDRS_PER_PAGE','256');
843 setConfigVar ('DEFAULT_RACK_HEIGHT','42');
844 setConfigVar ('REQUIRE_ASSET_TAG_FOR','4,7,8');
845 setConfigVar ('DEFAULT_SLB_VS_PORT','');
846 setConfigVar ('DEFAULT_SLB_RS_PORT','');
847 setConfigVar ('IPV4_PERFORMERS','1,4,7,8,12,14,445,447');
848 setConfigVar ('NATV4_PERFORMERS','4,7,8');
849 setConfigVar ('DETECT_URLS','no');
850 setConfigVar ('RACK_PRESELECT_THRESHOLD','1');
851 setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no');
852 setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm');
853 setConfigVar ('SHOW_EXPLICIT_TAGS','yes');
854 setConfigVar ('SHOW_IMPLICIT_TAGS','yes');
855 setConfigVar ('SHOW_AUTOMATIC_TAGS','no');
856 setConfigVar ('DEFAULT_OBJECT_TYPE','4');
857 setConfigVar ('IPV4_AUTO_RELEASE','1');
858 setConfigVar ('SHOW_LAST_TAB', 'no');
859 setConfigVar ('COOKIE_TTL', '1209600');
860 setConfigVar ('EXT_IPV4_VIEW', 'yes');
861 setConfigVar ('TREE_THRESHOLD', '25');
862 setConfigVar ('IPV4_JAYWALK', 'no');
863 setConfigVar ('ADDNEW_AT_TOP', 'yes');
864 setConfigVar ('IPV4_TREE_SHOW_USAGE', 'yes');
865 setConfigVar ('PREVIEW_TEXT_MAXCHARS', '10240');
866 setConfigVar ('PREVIEW_TEXT_ROWS', '25');
867 setConfigVar ('PREVIEW_TEXT_COLS', '80');
868 setConfigVar ('PREVIEW_IMAGE_MAXPXS', '320');
869 return buildRedirectURL (__FUNCTION__
, 'OK');
872 // Add single record.
873 function addRealServer ()
875 assertUIntArg ('pool_id', __FUNCTION__
);
876 assertIPv4Arg ('remoteip', __FUNCTION__
);
877 assertStringArg ('rsport', __FUNCTION__
, TRUE);
878 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
880 $_REQUEST['pool_id'],
881 $_REQUEST['remoteip'],
883 getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'),
884 $_REQUEST['rsconfig']
886 return buildRedirectURL (__FUNCTION__
, 'ERR');
888 return buildRedirectURL (__FUNCTION__
, 'OK');
891 // Parse textarea submitted and try adding a real server for each line.
892 function addRealServers ()
894 assertUIntArg ('pool_id', __FUNCTION__
);
895 assertStringArg ('format', __FUNCTION__
);
896 assertStringArg ('rawtext', __FUNCTION__
);
897 $rawtext = str_replace ('\r', '', $_REQUEST['rawtext']);
900 // Keep in mind, that the text will have HTML entities (namely '>') escaped.
901 foreach (explode ('\n', $rawtext) as $line)
906 switch ($_REQUEST['format'])
908 case 'ipvs_2': // address and port only
909 if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) /', $line, $match))
911 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
916 case 'ipvs_3': // address, port and weight
917 if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match))
919 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3]))
924 case 'ssv_2': // IP address and port
925 if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match))
927 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
932 case 'ssv_1': // IP address
933 if (!preg_match ('/^([0-9\.]+)$/', $line, $match))
935 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
941 return buildRedirectURL (__FUNCTION__
, 'ERR1');
945 if ($nbad == 0 and $ngood > 0)
946 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
948 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($ngood, $nbad));
951 function addVService ()
953 assertIPv4Arg ('vip', __FUNCTION__
);
954 assertUIntArg ('vport', __FUNCTION__
);
955 assertStringArg ('proto', __FUNCTION__
);
956 if ($_REQUEST['proto'] != 'TCP' and $_REQUEST['proto'] != 'UDP')
957 return buildRedirectURL (__FUNCTION__
, 'ERR1');
958 assertStringArg ('name', __FUNCTION__
, TRUE);
959 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
960 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
961 $error = commitCreateVS
967 $_REQUEST['vsconfig'],
968 $_REQUEST['rsconfig'],
969 isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array()
972 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
974 return buildRedirectURL (__FUNCTION__
, 'OK');
977 function deleteRealServer ()
979 assertUIntArg ('id', __FUNCTION__
);
980 if (!commitDeleteRS ($_REQUEST['id']))
981 return buildRedirectURL (__FUNCTION__
, 'ERR');
983 return buildRedirectURL (__FUNCTION__
, 'OK');
986 function deleteLoadBalancer ()
988 assertUIntArg ('object_id', __FUNCTION__
);
989 assertUIntArg ('pool_id', __FUNCTION__
);
990 assertUIntArg ('vs_id', __FUNCTION__
);
991 if (!commitDeleteLB (
992 $_REQUEST['object_id'],
993 $_REQUEST['pool_id'],
996 return buildRedirectURL (__FUNCTION__
, 'ERR');
998 return buildRedirectURL (__FUNCTION__
, 'OK');
1001 function deleteVService ()
1003 assertUIntArg ('vs_id', __FUNCTION__
);
1004 if (!commitDeleteVS ($_REQUEST['vs_id']))
1005 return buildRedirectURL (__FUNCTION__
, 'ERR');
1007 return buildRedirectURL (__FUNCTION__
, 'OK');
1010 function updateRealServer ()
1012 assertUIntArg ('rs_id', __FUNCTION__
);
1013 assertIPv4Arg ('rsip', __FUNCTION__
);
1014 assertStringArg ('rsport', __FUNCTION__
, TRUE);
1015 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1016 if (!commitUpdateRS (
1019 $_REQUEST['rsport'],
1020 $_REQUEST['rsconfig']
1022 return buildRedirectURL (__FUNCTION__
, 'ERR');
1024 return buildRedirectURL (__FUNCTION__
, 'OK');
1027 function updateLoadBalancer ()
1029 assertUIntArg ('object_id', __FUNCTION__
);
1030 assertUIntArg ('pool_id', __FUNCTION__
);
1031 assertUIntArg ('vs_id', __FUNCTION__
);
1032 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
1033 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1034 if (!commitUpdateLB (
1035 $_REQUEST['object_id'],
1036 $_REQUEST['pool_id'],
1038 $_REQUEST['vsconfig'],
1039 $_REQUEST['rsconfig']
1041 return buildRedirectURL (__FUNCTION__
, 'ERR');
1043 return buildRedirectURL (__FUNCTION__
, 'OK');
1046 function updateVService ()
1048 assertUIntArg ('vs_id', __FUNCTION__
);
1049 assertIPv4Arg ('vip', __FUNCTION__
);
1050 assertUIntArg ('vport', __FUNCTION__
);
1051 assertStringArg ('proto', __FUNCTION__
);
1052 assertStringArg ('name', __FUNCTION__
, TRUE);
1053 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
1054 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1055 if (!commitUpdateVS (
1061 $_REQUEST['vsconfig'],
1062 $_REQUEST['rsconfig']
1064 return buildRedirectURL (__FUNCTION__
, 'ERR');
1066 return buildRedirectURL (__FUNCTION__
, 'OK');
1069 function addLoadBalancer ()
1071 assertUIntArg ('pool_id', __FUNCTION__
);
1072 assertUIntArg ('object_id', __FUNCTION__
);
1073 assertUIntArg ('vs_id', __FUNCTION__
);
1074 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
1075 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1076 if (!addLBtoRSPool (
1077 $_REQUEST['pool_id'],
1078 $_REQUEST['object_id'],
1080 $_REQUEST['vsconfig'],
1081 $_REQUEST['rsconfig']
1083 return buildRedirectURL (__FUNCTION__
, 'ERR');
1085 return buildRedirectURL (__FUNCTION__
, 'OK');
1088 function addRSPool ()
1090 assertStringArg ('name', __FUNCTION__
, TRUE);
1091 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
1092 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1093 $error = commitCreateRSPool
1096 $_REQUEST['vsconfig'],
1097 $_REQUEST['rsconfig'],
1098 isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array()
1101 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1103 return buildRedirectURL (__FUNCTION__
, 'OK');
1106 function deleteRSPool ()
1108 assertUIntArg ('pool_id', __FUNCTION__
);
1109 if (!commitDeleteRSPool ($_REQUEST['pool_id']))
1110 return buildRedirectURL (__FUNCTION__
, 'ERR');
1112 return buildRedirectURL (__FUNCTION__
, 'OK');
1115 function updateRSPool ()
1117 assertUIntArg ('pool_id', __FUNCTION__
);
1118 assertStringArg ('name', __FUNCTION__
, TRUE);
1119 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
1120 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1121 if (!commitUpdateRSPool ($_REQUEST['pool_id'], $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
1122 return buildRedirectURL (__FUNCTION__
, 'ERR');
1124 return buildRedirectURL (__FUNCTION__
, 'OK');
1127 function updateRSInService ()
1129 assertUIntArg ('rscount', __FUNCTION__
);
1130 $pool_id = $_REQUEST['pool_id'];
1131 $orig = getRSPoolInfo ($pool_id);
1133 for ($i = 1; $i <= $_REQUEST['rscount']; $i++
)
1135 $rs_id = $_REQUEST["rsid_${i}"];
1136 if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on')
1140 if ($newval != $orig['rslist'][$rs_id]['inservice'])
1142 if (commitSetInService ($rs_id, $newval))
1149 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1151 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($nbad, $ngood));
1154 // FIXME: check, that each submitted address belongs to the prefix we
1155 // are operating on.
1156 function importPTRData ()
1158 assertUIntArg ('addrcount', __FUNCTION__
);
1160 for ($i = 0; $i < $_REQUEST['addrcount']; $i++
)
1162 $inputname = "import_${i}";
1163 if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on')
1165 assertIPv4Arg ("addr_${i}", __FUNCTION__
);
1166 assertStringArg ("descr_${i}", __FUNCTION__
, TRUE);
1167 assertStringArg ("rsvd_${i}", __FUNCTION__
);
1168 // Non-existent addresses will not have this argument set in request.
1170 if ($_REQUEST["rsvd_${i}"] == 'yes')
1172 if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '')
1178 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1180 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($nbad, $ngood));
1183 function generateAutoPorts ()
1186 assertUIntArg ('object_id', __FUNCTION__
);
1187 $info = getObjectInfo ($_REQUEST['object_id']);
1188 // Navigate away in case of success, stay at the place otherwise.
1189 if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id']))
1190 return buildRedirectURL (__FUNCTION__
, 'OK', array(), $pageno, 'ports');
1192 return buildRedirectURL (__FUNCTION__
, 'ERR');
1195 // Filter out implicit tags before storing the new tag set.
1196 function saveEntityTags ()
1198 global $explicit_tags, $implicit_tags, $page, $pageno, $etype_by_pageno;
1199 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1201 showError ('Internal error', __FUNCTION__
);
1204 $realm = $etype_by_pageno[$pageno];
1205 $bypass = $page[$pageno]['bypass'];
1206 assertUIntArg ($bypass, __FUNCTION__
);
1207 $entity_id = $_REQUEST[$bypass];
1208 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1209 // Build a chain from the submitted data, minimize it,
1210 // then wipe existing records and store the new set instead.
1211 destroyTagsForEntity ($realm, $entity_id);
1212 $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist));
1213 $n_succeeds = $n_errors = 0;
1214 foreach ($newchain as $taginfo)
1215 if (addTagForEntity ($realm, $entity_id, $taginfo['id']))
1220 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($n_succeeds, $n_errors));
1222 return buildRedirectURL (__FUNCTION__
, 'OK', array ($n_succeeds));
1225 function destroyTag ()
1227 assertUIntArg ('tag_id', __FUNCTION__
);
1228 if (($ret = commitDestroyTag ($_REQUEST['tag_id'])) == '')
1229 return buildRedirectURL (__FUNCTION__
, 'OK');
1231 return buildRedirectURL (__FUNCTION__
, 'ERR');
1234 function createTag ()
1236 assertStringArg ('tag_name', __FUNCTION__
);
1237 assertUIntArg ('parent_id', __FUNCTION__
, TRUE);
1238 $tagname = trim ($_REQUEST['tag_name']);
1239 if (!validTagName ($tagname))
1240 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($tagname));
1241 if (tagExistsInDatabase ($tagname))
1242 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($tagname));
1243 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1244 $parent_id = 'NULL';
1245 if (($ret = commitCreateTag ($tagname, $parent_id)) == '')
1246 return buildRedirectURL (__FUNCTION__
, 'OK', array ($tagname));
1248 return buildRedirectURL (__FUNCTION__
, 'ERR3', array ($tagname, $ret));
1251 function updateTag ()
1253 assertUIntArg ('tag_id', __FUNCTION__
);
1254 assertUIntArg ('parent_id', __FUNCTION__
, TRUE);
1255 assertStringArg ('tag_name', __FUNCTION__
);
1256 $tagname = trim ($_REQUEST['tag_name']);
1257 if (!validTagName ($tagname))
1258 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($tagname));
1259 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1260 $parent_id = 'NULL';
1261 if (($ret = commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id)) == '')
1262 return buildRedirectURL (__FUNCTION__
, 'OK', array ($tagname));
1264 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($tagname, $ret));
1267 function rollTags ()
1269 assertUIntArg ('row_id', __FUNCTION__
);
1270 assertStringArg ('sum', __FUNCTION__
, TRUE);
1271 assertUIntArg ('realsum', __FUNCTION__
);
1272 if ($_REQUEST['sum'] != $_REQUEST['realsum'])
1273 return buildRedirectURL (__FUNCTION__
, 'ERR');
1274 // Even if the user requested an empty tag list, don't bail out, but process existing
1275 // tag chains with "zero" extra. This will make sure, that the stuff processed will
1276 // have its chains refined to "normal" form.
1277 $extratags = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1279 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
1280 // filter out the same tag again and again. It will have own noise to cancel.
1281 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
1282 foreach (getRacksForRow ($_REQUEST['row_id']) as $rackInfo)
1284 if (rebuildTagChainForEntity ('rack', $rackInfo['id'], $extrachain))
1286 foreach (stuffInRackspace (getRackData ($rackInfo['id'])) as $object_id)
1287 if (rebuildTagChainForEntity ('object', $object_id, $extrachain))
1290 return buildRedirectURL (__FUNCTION__
, 'OK', array ($n_ok));
1293 function changeMyPassword ()
1295 global $accounts, $remote_username, $user_auth_src;
1296 if ($user_auth_src != 'database')
1297 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1298 assertStringArg ('oldpassword', __FUNCTION__
);
1299 assertStringArg ('newpassword1', __FUNCTION__
);
1300 assertStringArg ('newpassword2', __FUNCTION__
);
1301 if ($accounts[$remote_username]['user_password_hash'] != hash (PASSWORD_HASH
, $_REQUEST['oldpassword']))
1302 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1303 if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2'])
1304 return buildRedirectURL (__FUNCTION__
, 'ERR3');
1305 if (commitUpdateUserAccount ($accounts[$remote_username]['user_id'], $accounts[$remote_username]['user_name'], $accounts[$remote_username]['user_realname'], hash (PASSWORD_HASH
, $_REQUEST['newpassword1'])))
1306 return buildRedirectURL (__FUNCTION__
, 'OK');
1308 return buildRedirectURL (__FUNCTION__
, 'ERR4');
1311 function saveRackCode ()
1313 assertStringArg ('rackcode');
1314 // For the test to succeed, unescape LFs, strip CRs.
1315 $newcode = str_replace ('\r', '', str_replace ('\n', "\n", $_REQUEST['rackcode']));
1316 $parseTree = getRackCode ($newcode);
1317 if ($parseTree['result'] != 'ACK')
1318 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($parseTree['load']));
1319 saveScript ('RackCodeCache', '');
1320 if (saveScript ('RackCode', $newcode))
1321 return buildRedirectURL (__FUNCTION__
, 'OK');
1323 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1326 // This handler's context is pre-built, but not authorized. It is assumed, that the
1327 // handler will take existing context and before each commit check authorization
1328 // on the base chain plus necessary context added.
1329 function setPortVLAN ()
1331 assertUIntArg ('portcount', __FUNCTION__
);
1332 $data = getSwitchVLANs ($_REQUEST['object_id']);
1334 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1335 list ($vlanlist, $portlist) = $data;
1336 // Here we just build up 1 set command for the gateway with all of the ports
1337 // included. The gateway is expected to filter unnecessary changes silently
1338 // and to provide a list of responses with either error or success message
1339 // for each of the rest.
1340 $nports = $_REQUEST['portcount'];
1342 $log = array ('v' => 2, 'm' => array());
1344 for ($i = 0; $i < $nports; $i++
)
1347 !isset ($_REQUEST['portname_' . $i]) ||
1348 !isset ($_REQUEST['vlanid_' . $i]) ||
1349 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
1351 $log['m'][] = array ('c' => 158, 'a' => array ($i));
1354 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
1355 $portlist[$i]['vlaind'] == 'TRUNK'
1360 $portname = $_REQUEST['portname_' . $i];
1361 $oldvlanid = $portlist[$i]['vlanid'];
1362 $newvlanid = $_REQUEST['vlanid_' . $i];
1363 // Finish the security context and evaluate it.
1365 $annex[] = array ('tag' => '$fromvlan_' . $oldvlanid);
1366 $annex[] = array ('tag' => '$tovlan_' . $newvlanid);
1367 if (!permitted (NULL, NULL, NULL, $annex))
1369 $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid));
1372 $setcmd .= $prefix . $portname . '=' . $newvlanid;
1375 // Feed the gateway and interpret its (non)response.
1377 $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd));
1379 $log['m'][] = array ('c' => 201);
1380 return buildWideRedirectURL ($log);
1383 function submitSLBConfig ()
1385 assertUIntArg ('object_id', __FUNCTION__
);
1386 $newconfig = buildLVSConfig ($_REQUEST['object_id']);
1387 $msglog = gwSendFile ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES
, 'UTF-8'));
1388 return buildWideRedirectURL ($msglog);
1393 assertStringArg ('name', __FUNCTION__
);
1395 if (commitAddRow ($_REQUEST['name']) === TRUE)
1396 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1398 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($_REQUEST['name']));
1401 function updateRow ()
1403 assertUIntArg ('row_id', __FUNCTION__
);
1404 assertStringArg ('name', __FUNCTION__
);
1406 if (TRUE === commitUpdateRow ($_REQUEST['row_id'], $_REQUEST['name']))
1407 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1409 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($_REQUEST['name']));
1412 function deleteRow ()
1414 assertUIntArg ('row_id', __FUNCTION__
);
1416 if (TRUE === commitDeleteRow ($_REQUEST['row_id']))
1417 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1419 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($_REQUEST['name']));
1426 assertUIntArg ('row_id', __FUNCTION__
);
1427 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1428 if (isset ($_REQUEST['got_data']))
1430 assertStringArg ('rack_name', __FUNCTION__
);
1431 assertUIntArg ('rack_height1', __FUNCTION__
);
1432 assertStringArg ('rack_comment', __FUNCTION__
, TRUE);
1434 if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
1435 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['rack_name']));
1437 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($_REQUEST['rack_name']));
1439 elseif (isset ($_REQUEST['got_mdata']))
1441 assertUIntArg ('rack_height2', __FUNCTION__
);
1442 assertStringArg ('rack_names', __FUNCTION__
, TRUE);
1443 $log = array ('v' => 2);
1444 // copy-and-paste from renderAddMultipleObjectsForm()
1445 $names1 = explode ('\n', $_REQUEST['rack_names']);
1447 foreach ($names1 as $line)
1449 $parts = explode ('\r', $line);
1451 if (empty ($parts[0]))
1454 $names2[] = rtrim ($parts[0]);
1456 foreach ($names2 as $cname)
1457 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE)
1458 $log['m'][] = array ('c' => getMessageCode (__FUNCTION__
, 'OK'), 'a' => array ($cname));
1460 $log['m'][] = array ('c' => getMessageCode (__FUNCTION__
, 'ERR1'), 'a' => array ($cname));
1461 return buildWideRedirectURL ($log);
1464 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1467 function updateRack ()
1469 assertUIntArg ('rack_id', __FUNCTION__
);
1470 assertUIntArg ('rack_row_id', __FUNCTION__
);
1471 assertUIntArg ('rack_height', __FUNCTION__
);
1472 assertStringArg ('rack_name', __FUNCTION__
);
1473 assertStringArg ('rack_comment', __FUNCTION__
, TRUE);
1475 resetThumbCache ($_REQUEST['rack_id']);
1476 if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
1477 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['rack_name']));
1479 return buildRedirectURL (__FUNCTION__
, 'ERR');
1482 function updateRackDesign ()
1484 assertUIntArg ('rack_id', __FUNCTION__
);
1485 if (($rackData = getRackData ($_REQUEST['rack_id'])) == NULL)
1487 showError ('getRackData() failed', __FUNCTION__
);
1490 applyRackDesignMask($rackData);
1491 markupObjectProblems ($rackData);
1492 $response = processGridForm ($rackData, 'A', 'F');
1493 return buildWideRedirectURL ($response);
1496 function updateRackProblems ()
1498 assertUIntArg ('rack_id', __FUNCTION__
);
1499 if (($rackData = getRackData ($_REQUEST['rack_id'])) == NULL)
1501 showError ('getRackData() failed', __FUNCTION__
);
1504 applyRackProblemMask($rackData);
1505 markupObjectProblems ($rackData);
1506 $response = processGridForm ($rackData, 'F', 'U');
1507 return buildWideRedirectURL ($response);
1512 function querySNMPData ()
1514 assertUIntArg ('object_id', __FUNCTION__
);
1515 assertStringArg ('community', __FUNCTION__
);
1516 return buildWideRedirectURL (doSNMPmining ($_REQUEST['object_id'], $_REQUEST['community']));
1519 // File-related functions
1520 function addFileWithoutLink ()
1522 assertStringArg ('comment', __FUNCTION__
, TRUE);
1524 // Make sure the file can be uploaded
1525 if (get_cfg_var('file_uploads') != 1)
1526 return buildRedirectURL (__FUNCTION__
, 'ERR', array ("file uploads not allowed, change 'file_uploads' parameter in php.ini"));
1528 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1529 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $_REQUEST['comment']);
1532 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1534 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_FILES['file']['name']));
1537 function addFileToEntity ()
1539 assertStringArg ('entity_type', __FUNCTION__
);
1540 assertUIntArg ('entity_id', __FUNCTION__
);
1541 assertStringArg ('comment', __FUNCTION__
, TRUE);
1542 if (empty ($_REQUEST['entity_type']) ||
empty ($_REQUEST['entity_id']))
1543 return buildRedirectURL (__FUNCTION__
, 'ERR');
1545 // Make sure the file can be uploaded
1546 if (get_cfg_var('file_uploads') != 1)
1547 return buildRedirectURL (__FUNCTION__
, 'ERR', array ("file uploads not allowed, change 'file_uploads' parameter in php.ini"));
1549 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1550 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $_REQUEST['comment']);
1552 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1554 $file_id = lastInsertID();
1555 $error = commitLinkFile ($file_id, $_REQUEST['entity_type'], $_REQUEST['entity_id']);
1557 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1559 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_FILES['file']['name']));
1562 function linkFileToEntity ()
1564 assertUIntArg ('file_id', __FUNCTION__
);
1565 global $page, $pageno, $etype_by_pageno;
1566 $entity_type = $etype_by_pageno[$pageno];
1567 $bypass_name = $page[$pageno]['bypass'];
1568 assertUIntArg ($bypass_name, __FUNCTION__
);
1570 $fi = getFileInfo ($_REQUEST['file_id']);
1572 return buildRedirectURL (__FUNCTION__
, 'ERR1'); // file not found
1573 $error = commitLinkFile ($_REQUEST['file_id'], $entity_type, $_REQUEST[$bypass_name]);
1575 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error)); // linking failed
1577 return buildRedirectURL (__FUNCTION__
, 'OK', array ($fi['name']));
1580 function replaceFile ()
1582 assertUIntArg ('file_id', __FUNCTION__
);
1584 // Make sure the file can be uploaded
1585 if (get_cfg_var('file_uploads') != 1)
1586 return buildRedirectURL (__FUNCTION__
, 'ERR', array ("file uploads not allowed, change 'file_uploads' parameter in php.ini"));
1588 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1589 $error = commitReplaceFile ($_REQUEST['file_id'], $_FILES['file']['size'], $fp);
1591 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1593 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1596 function updateFile ()
1598 assertUIntArg ('file_id', __FUNCTION__
);
1599 assertStringArg ('name', __FUNCTION__
);
1600 assertStringArg ('comment', __FUNCTION__
, TRUE);
1601 $error = commitUpdateFile ($_REQUEST['file_id'], $_REQUEST['name'], $_REQUEST['comment']);
1603 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1605 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1608 function unlinkFile ()
1610 assertUIntArg ('link_id', __FUNCTION__
);
1611 $error = commitUnlinkFile ($_REQUEST['link_id']);
1614 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1616 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1619 function deleteFile ()
1621 assertUIntArg ('file_id', __FUNCTION__
);
1622 $error = commitDeleteFile ($_REQUEST['file_id']);
1625 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1627 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));