4 * This file is a library of operation handlers for RackTables.
10 function buildWideRedirectURL ($log, $nextpage = NULL, $nexttab = NULL, $moreArgs = array())
12 global $root, $page, $pageno, $tabno;
13 if ($nextpage === NULL)
15 if ($nexttab === NULL)
17 $url = "${root}?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, $args = array(), $nextpage = NULL, $nexttab = NULL)
43 global $pageno, $tabno, $msgcode;
44 if ($nextpage === NULL)
46 if ($nexttab === NULL)
48 return buildWideRedirectURL (oneLiner ($msgcode[$callfunc][$status], $args), $nextpage, $nexttab);
51 $msgcode['addPortForwarding']['OK'] = 2;
52 $msgcode['addPortForwarding']['ERR'] = 100;
53 function addPortForwarding ()
55 assertUIntArg ('object_id', __FUNCTION__
);
56 assertIPv4Arg ('localip', __FUNCTION__
);
57 assertIPv4Arg ('remoteip', __FUNCTION__
);
58 assertUIntArg ('localport', __FUNCTION__
);
59 assertStringArg ('proto', __FUNCTION__
);
60 assertStringArg ('description', __FUNCTION__
, TRUE);
61 $remoteport = isset ($_REQUEST['remoteport']) ?
$_REQUEST['remoteport'] : '';
62 if (empty ($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'] = 100;
84 function delPortForwarding ()
86 assertUIntArg ('object_id', __FUNCTION__
);
87 assertIPv4Arg ('localip', __FUNCTION__
);
88 assertIPv4Arg ('remoteip', __FUNCTION__
);
89 assertUIntArg ('localport', __FUNCTION__
);
90 assertUIntArg ('remoteport', __FUNCTION__
);
91 assertStringArg ('proto', __FUNCTION__
);
93 $error = deletePortForwarding
95 $_REQUEST['object_id'],
97 $_REQUEST['localport'],
98 $_REQUEST['remoteip'],
99 $_REQUEST['remoteport'],
103 return buildRedirectURL (__FUNCTION__
, 'OK');
105 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
108 $msgcode['updPortForwarding']['OK'] = 4;
109 $msgcode['updPortForwarding']['ERR'] = 100;
110 function updPortForwarding ()
112 assertUIntArg ('object_id', __FUNCTION__
);
113 assertIPv4Arg ('localip', __FUNCTION__
);
114 assertIPv4Arg ('remoteip', __FUNCTION__
);
115 assertUIntArg ('localport', __FUNCTION__
);
116 assertUIntArg ('remoteport', __FUNCTION__
);
117 assertStringArg ('proto', __FUNCTION__
);
118 assertStringArg ('description', __FUNCTION__
);
120 $error = updatePortForwarding
122 $_REQUEST['object_id'],
123 $_REQUEST['localip'],
124 $_REQUEST['localport'],
125 $_REQUEST['remoteip'],
126 $_REQUEST['remoteport'],
128 $_REQUEST['description']
131 return buildRedirectURL (__FUNCTION__
, 'OK');
133 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
136 $msgcode['addPortForObject']['OK'] = 5;
137 $msgcode['addPortForObject']['ERR1'] = 101;
138 $msgcode['addPortForObject']['ERR2'] = 100;
139 function addPortForObject ()
141 assertUIntArg ('object_id', __FUNCTION__
);
142 assertStringArg ('port_name', __FUNCTION__
, TRUE);
143 if (empty ($_REQUEST['port_name']))
144 return buildRedirectURL (__FUNCTION__
, 'ERR1');
145 $error = commitAddPort ($_REQUEST['object_id'], $_REQUEST['port_name'], $_REQUEST['port_type_id'], $_REQUEST['port_label'], $_REQUEST['port_l2address']);
147 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
149 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['port_name']));
152 $msgcode['editPortForObject']['OK'] = 6;
153 $msgcode['editPortForObject']['ERR1'] = 101;
154 $msgcode['editPortForObject']['ERR2'] = 100;
155 function editPortForObject ()
157 assertUIntArg ('port_id', __FUNCTION__
);
158 assertUIntArg ('port_type_id', __FUNCTION__
);
159 // tolerate empty value now to produce custom informative message later
160 assertStringArg ('name', __FUNCTION__
, TRUE);
161 if (empty ($_REQUEST['name']))
162 return buildRedirectURL (__FUNCTION__
, 'ERR1');
164 if (isset ($_REQUEST['reservation_comment']) and !empty ($_REQUEST['reservation_comment']))
165 $port_rc = '"' . $_REQUEST['reservation_comment'] . '"';
168 $error = commitUpdatePort ($_REQUEST['port_id'], $_REQUEST['name'], $_REQUEST['port_type_id'], $_REQUEST['label'], $_REQUEST['l2address'], $port_rc);
170 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
172 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
175 $msgcode['delPortFromObject']['OK'] = 7;
176 $msgcode['delPortFromObject']['ERR'] = 100;
177 function delPortFromObject ()
179 assertUIntArg ('port_id', __FUNCTION__
);
180 $error = delObjectPort ($_REQUEST['port_id']);
183 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
185 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['port_name']));
188 $msgcode['linkPortForObject']['OK'] = 8;
189 $msgcode['linkPortForObject']['ERR'] = 100;
190 function linkPortForObject ()
192 assertUIntArg ('port_id', __FUNCTION__
);
193 assertUIntArg ('remote_port_id', __FUNCTION__
);
194 assertStringArg ('port_name', __FUNCTION__
, TRUE);
195 assertStringArg ('remote_port_name', __FUNCTION__
, TRUE);
196 assertStringArg ('remote_object_name', __FUNCTION__
, TRUE);
198 $error = linkPorts ($_REQUEST['port_id'], $_REQUEST['remote_port_id']);
200 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
202 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['port_name'], $_REQUEST['remote_port_name'], $_REQUEST['remote_object_name']));
205 $msgcode['unlinkPortForObject']['OK'] = 9;
206 $msgcode['unlinkPortForObject']['ERR'] = 100;
207 function unlinkPortForObject ()
209 assertUIntArg ('port_id', __FUNCTION__
);
210 assertStringArg ('port_name', __FUNCTION__
, TRUE);
211 assertStringArg ('remote_port_name', __FUNCTION__
, TRUE);
212 assertStringArg ('remote_object_name', __FUNCTION__
, TRUE);
214 $error = unlinkPort ($_REQUEST['port_id']);
216 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
218 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['port_name'], $_REQUEST['remote_port_name'], $_REQUEST['remote_object_name']));
221 $msgcode['addMultiPorts']['OK'] = 10;
222 $msgcode['addMultiPorts']['ERR'] = 123;
223 function addMultiPorts ()
225 assertStringArg ('format', __FUNCTION__
);
226 assertStringArg ('input', __FUNCTION__
);
227 assertUIntArg ('port_type', __FUNCTION__
);
228 assertUIntArg ('object_id', __FUNCTION__
);
229 $format = $_REQUEST['format'];
230 $port_type = $_REQUEST['port_type'];
231 $object_id = $_REQUEST['object_id'];
232 // Input lines are escaped, so we have to explode and to chop by 2-char
233 // \n and \r respectively.
234 $lines1 = explode ('\n', $_REQUEST['input']);
235 foreach ($lines1 as $line)
237 $parts = explode ('\r', $line);
239 if (empty ($parts[0]))
242 $lines2[] = rtrim ($parts[0]);
245 foreach ($lines2 as $line)
250 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
251 list ($slot, $port) = explode ('/', $words[0]);
254 'name' => "e ${slot}/${port}",
255 'l2address' => $words[8],
256 'label' => "slot ${slot} port ${port}"
260 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', trim (substr ($line, 3))));
262 How Async Lines are Numbered in Cisco 3600 Series Routers
263 http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00801ca70b.shtml
265 Understanding 16- and 32-Port Async Network Modules
266 http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00800a93f0.shtml
269 $slot = floor (($async - 1) / 32);
270 $octalgroup = floor (($async - 1 - $slot * 32) / 8);
271 $cable = $async - $slot * 32 - $octalgroup * 8;
272 $og_label[0] = 'async 0-7';
273 $og_label[1] = 'async 8-15';
274 $og_label[2] = 'async 16-23';
275 $og_label[3] = 'async 24-31';
278 'name' => "async ${async}",
280 'label' => "slot ${slot} " . $og_label[$octalgroup] . " cable ${cable}"
284 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
285 $ifnumber = $words[0] * 1;
288 'name' => "e ${ifnumber}",
289 'l2address' => "${words[8]}",
290 'label' => "${ifnumber}"
294 $words = explode (' ', $line);
295 if (empty ($words[0]) or empty ($words[1]))
300 'l2address' => $words[1],
305 return buildRedirectURL (__FUNCTION__
, 'ERR');
309 // Create ports, if they don't exist.
310 $added_count = $updated_count = $error_count = 0;
311 foreach ($ports as $port)
313 $port_id = getPortID ($object_id, $port['name']);
314 if ($port_id === NULL)
316 $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
324 $result = commitUpdatePort ($port_id, $port['name'], $port_type, $port['label'], $port['l2address']);
331 return buildRedirectURL (__FUNCTION__
, 'OK', array ($added_count, $updated_count, $error_count));
334 $msgcode['updIPv4Allocation']['OK'] = 12;
335 $msgcode['updIPv4Allocation']['ERR'] = 100;
336 function updIPv4Allocation ()
338 assertIPv4Arg ('ip', __FUNCTION__
);
339 assertUIntArg ('object_id', __FUNCTION__
);
340 assertStringArg ('bond_name', __FUNCTION__
, TRUE);
341 assertStringArg ('bond_type', __FUNCTION__
);
343 $error = updateBond ($_REQUEST['ip'], $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
345 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
347 return buildRedirectURL (__FUNCTION__
, 'OK');
350 $msgcode['delIPv4Allocation']['OK'] = 14;
351 $msgcode['delIPv4Allocation']['ERR'] = 100;
352 function delIPv4Allocation ()
354 assertIPv4Arg ('ip', __FUNCTION__
);
355 assertUIntArg ('object_id', __FUNCTION__
);
357 $error = unbindIpFromObject ($_REQUEST['ip'], $_REQUEST['object_id']);
359 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
361 return buildRedirectURL (__FUNCTION__
, 'OK');
364 $msgcode['addIPv4Allocation']['OK'] = 13;
365 $msgcode['addIPv4Allocation']['ERR1'] = 170;
366 $msgcode['addIPv4Allocation']['ERR2'] = 100;
367 function addIPv4Allocation ()
369 assertIPv4Arg ('ip', __FUNCTION__
);
370 assertUIntArg ('object_id', __FUNCTION__
);
371 assertStringArg ('bond_name', __FUNCTION__
, TRUE);
372 assertStringArg ('bond_type', __FUNCTION__
);
375 $ip = ereg_replace ('/[[:digit:]]+$', '', $_REQUEST['ip']);
376 if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv4AddressNetworkId ($ip))
377 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($ip));
379 $error = bindIpToObject ($ip, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
381 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
382 $address = getIPv4Address ($ip);
383 if ($address['reserved'] == 'yes' or !empty ($address['name']))
385 $release = getConfigVar ('IPV4_AUTO_RELEASE');
387 $address['reserved'] = 'no';
389 $address['name'] = '';
390 updateAddress ($ip, $address['name'], $address['reserved']);
392 return buildRedirectURL (__FUNCTION__
, 'OK');
395 $msgcode['addIPv4Prefix']['OK'] = 23;
396 $msgcode['addIPv4Prefix']['ERR'] = 100;
397 $msgcode['addIPv4Prefix']['ERR1'] = 173;
398 $msgcode['addIPv4Prefix']['ERR2'] = 174;
399 $msgcode['addIPv4Prefix']['ERR3'] = 175;
400 $msgcode['addIPv4Prefix']['ERR4'] = 176;
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 $msgcode['delIPv4Prefix']['OK'] = 24;
416 $msgcode['delIPv4Prefix']['ERR'] = 100;
417 function delIPv4Prefix ()
419 assertUIntArg ('id', __FUNCTION__
);
420 $error = destroyIPv4Prefix ($_REQUEST['id']);
422 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
424 return buildRedirectURL (__FUNCTION__
, 'OK');
427 $msgcode['updIPv4Prefix']['OK'] = 25;
428 $msgcode['updIPv4Prefix']['ERR'] = 100;
429 function updIPv4Prefix ()
431 assertUIntArg ('id', __FUNCTION__
);
432 assertStringArg ('name', __FUNCTION__
, TRUE);
434 $error = updateRange ($_REQUEST['id'], $_REQUEST['name']);
436 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
438 return buildRedirectURL (__FUNCTION__
, 'OK');
441 $msgcode['editAddress']['OK'] = 27;
442 $msgcode['editAddress']['ERR'] = 100;
443 function editAddress ()
445 assertIPv4Arg ('ip', __FUNCTION__
);
446 assertStringArg ('name', __FUNCTION__
, TRUE);
448 if (isset ($_REQUEST['reserved']))
449 $reserved = $_REQUEST['reserved'];
452 $error = updateAddress ($_REQUEST['ip'], $_REQUEST['name'], $reserved == 'on' ?
'yes' : 'no');
454 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
456 return buildRedirectURL (__FUNCTION__
, 'OK');
459 $msgcode['createUser']['OK'] = 40;
460 $msgcode['createUser']['ERR'] = 102;
461 function createUser ()
463 assertStringArg ('username', __FUNCTION__
);
464 assertStringArg ('realname', __FUNCTION__
, TRUE);
465 assertStringArg ('password', __FUNCTION__
);
466 $username = $_REQUEST['username'];
467 $password = sha1 ($_REQUEST['password']);
468 $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password);
470 return buildRedirectURL (__FUNCTION__
, 'OK', array ($username));
472 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($username));
475 $msgcode['updateUser']['OK'] = 39;
476 $msgcode['updateUser']['ERR1'] = 103;
477 $msgcode['updateUser']['ERR1'] = 104;
478 function updateUser ()
480 assertUIntArg ('user_id', __FUNCTION__
);
481 assertStringArg ('username', __FUNCTION__
);
482 assertStringArg ('realname', __FUNCTION__
, TRUE);
483 assertStringArg ('password', __FUNCTION__
);
484 $username = $_REQUEST['username'];
485 $new_password = $_REQUEST['password'];
486 if (NULL == ($userinfo = getUserInfo ($_REQUEST['user_id'])))
487 return buildRedirectURL (__FUNCTION__
, 'ERR1');
488 // Update user password only if provided password is not the same as current password hash.
489 if ($new_password != $userinfo['user_password_hash'])
490 $new_password = sha1 ($new_password);
491 $result = commitUpdateUserAccount ($_REQUEST['user_id'], $username, $_REQUEST['realname'], $new_password);
493 return buildRedirectURL (__FUNCTION__
, 'OK', array ($username));
495 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($username));
498 $msgcode['savePortMap']['OK'] = 44;
499 $msgcode['savePortMap']['ERR'] = 108;
500 // This function find differences in users's submit and PortCompat table
501 // and modifies database accordingly.
502 function savePortMap ()
504 $ptlist = getPortTypes();
505 $oldCompat = getPortCompat();
506 $newCompat = array();
507 foreach (array_keys ($ptlist) as $leftKey)
508 foreach (array_keys ($ptlist) as $rightKey)
509 if (isset ($_REQUEST["atom_${leftKey}_${rightKey}"]))
510 $newCompat[] = array ('type1' => $leftKey, 'type2' => $rightKey);
511 // Build the new matrix from user's submit and compare it to
512 // the old matrix. Those pairs which appear on
513 // new matrix only, have to be stored in PortCompat table. Those who appear
514 // on the old matrix only, should be removed from PortCompat table.
515 // Those present in both matrices should be skipped.
516 $oldCompatTable = buildPortCompatMatrixFromList ($ptlist, $oldCompat);
517 $newCompatTable = buildPortCompatMatrixFromList ($ptlist, $newCompat);
518 $error_count = $success_count = 0;
519 foreach (array_keys ($ptlist) as $type1)
520 foreach (array_keys ($ptlist) as $type2)
521 if ($oldCompatTable[$type1][$type2] != $newCompatTable[$type1][$type2])
522 switch ($oldCompatTable[$type1][$type2])
524 case TRUE: // new value is FALSE
525 if (removePortCompat ($type1, $type2) === TRUE)
530 case FALSE: // new value is TRUE
531 if (addPortCompat ($type1, $type2) === TRUE)
537 showError ('Internal error: oldCompatTable is invalid', __FUNCTION__
);
540 if ($error_count == 0)
541 return buildRedirectURL (__FUNCTION__
, 'OK', array ($error_count, $success_count));
543 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error_count, $success_count));
546 $msgcode['updateDictionary']['OK'] = 51;
547 $msgcode['updateDictionary']['ERR'] = 109;
548 function updateDictionary ()
550 assertUIntArg ('chapter_no', __FUNCTION__
);
551 assertUIntArg ('dict_key', __FUNCTION__
);
552 assertStringArg ('dict_value', __FUNCTION__
);
553 if (commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value']) === TRUE)
554 return buildRedirectURL (__FUNCTION__
, 'OK');
556 return buildRedirectURL (__FUNCTION__
, 'ERR');
559 $msgcode['supplementDictionary']['OK'] = 52;
560 $msgcode['supplementDictionary']['ERR'] = 110;
561 function supplementDictionary ()
563 assertUIntArg ('chapter_no', __FUNCTION__
);
564 assertStringArg ('dict_value', __FUNCTION__
);
565 if (commitSupplementDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_value']) === TRUE)
566 return buildRedirectURL (__FUNCTION__
, 'OK');
568 return buildRedirectURL (__FUNCTION__
, 'ERR');
571 $msgcode['reduceDictionary']['OK'] = 50;
572 $msgcode['reduceDictionary']['ERR'] = 111;
573 function reduceDictionary ()
575 assertUIntArg ('chapter_no', __FUNCTION__
);
576 assertUIntArg ('dict_key', __FUNCTION__
);
577 if (commitReduceDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key']) === TRUE)
578 return buildRedirectURL (__FUNCTION__
, 'OK');
580 return buildRedirectURL (__FUNCTION__
, 'ERR');
583 $msgcode['addChapter']['OK'] = 55;
584 $msgcode['addChapter']['ERR'] = 112;
585 function addChapter ()
587 assertStringArg ('chapter_name', __FUNCTION__
);
588 if (commitAddChapter ($_REQUEST['chapter_name']) === TRUE)
589 return buildRedirectURL (__FUNCTION__
, 'OK');
591 return buildRedirectURL (__FUNCTION__
, 'ERR');
594 $msgcode['updateChapter']['OK'] = 54;
595 $msgcode['updateChapter']['ERR'] = 113;
596 function updateChapter ()
598 assertUIntArg ('chapter_no', __FUNCTION__
);
599 assertStringArg ('chapter_name', __FUNCTION__
);
600 if (commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name']) === TRUE)
601 return buildRedirectURL (__FUNCTION__
, 'OK');
603 return buildRedirectURL (__FUNCTION__
, 'ERR');
606 $msgcode['delChapter']['OK'] = 53;
607 $msgcode['delChapter']['ERR'] = 114;
608 function delChapter ()
610 assertUIntArg ('chapter_no', __FUNCTION__
);
611 if (commitDeleteChapter ($_REQUEST['chapter_no']))
612 return buildRedirectURL (__FUNCTION__
, 'OK');
614 return buildRedirectURL (__FUNCTION__
, 'ERR');
617 $msgcode['changeAttribute']['OK'] = 46;
618 $msgcode['changeAttribute']['ERR'] = 115;
619 function changeAttribute ()
621 assertUIntArg ('attr_id', __FUNCTION__
);
622 assertStringArg ('attr_name', __FUNCTION__
);
623 if (commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name']))
624 return buildRedirectURL (__FUNCTION__
, 'OK');
626 return buildRedirectURL (__FUNCTION__
, 'ERR');
629 $msgcode['createAttribute']['OK'] = 45;
630 $msgcode['createAttribute']['ERR'] = 116;
631 function createAttribute ()
633 assertStringArg ('attr_name', __FUNCTION__
);
634 assertStringArg ('attr_type', __FUNCTION__
);
635 if (commitAddAttribute ($_REQUEST['attr_name'], $_REQUEST['attr_type']))
636 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['attr_name']));
638 return buildRedirectURL (__FUNCTION__
, 'ERR');
641 $msgcode['deleteAttribute']['OK'] = 47;
642 $msgcode['deleteAttribute']['ERR'] = 117;
643 function deleteAttribute ()
645 assertUIntArg ('attr_id', __FUNCTION__
);
646 if (commitDeleteAttribute ($_REQUEST['attr_id']))
647 return buildRedirectURL (__FUNCTION__
, 'OK');
649 return buildRedirectURL (__FUNCTION__
, 'ERR');
652 $msgcode['supplementAttrMap']['OK'] = 48;
653 $msgcode['supplementAttrMap']['ERR'] = 118;
654 function supplementAttrMap ()
656 assertUIntArg ('attr_id', __FUNCTION__
);
657 assertUIntArg ('objtype_id', __FUNCTION__
);
658 assertUIntArg ('chapter_no', __FUNCTION__
);
659 if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $_REQUEST['chapter_no']) === TRUE)
660 return buildRedirectURL (__FUNCTION__
, 'OK');
662 return buildRedirectURL (__FUNCTION__
, 'ERR');
665 $msgcode['reduceAttrMap']['OK'] = 49;
666 $msgcode['reduceAttrMap']['ERR'] = 119;
667 function reduceAttrMap ()
669 assertUIntArg ('attr_id', __FUNCTION__
);
670 assertUIntArg ('objtype_id', __FUNCTION__
);
671 if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) === TRUE)
672 return buildRedirectURL (__FUNCTION__
, 'OK');
674 return buildRedirectURL (__FUNCTION__
, 'ERR');
677 $msgcode['clearSticker']['OK'] = 15;
678 $msgcode['clearSticker']['ERR'] = 120;
679 function clearSticker ()
681 assertUIntArg ('attr_id', __FUNCTION__
);
682 assertUIntArg ('object_id', __FUNCTION__
);
683 if (commitResetAttrValue ($_REQUEST['object_id'], $_REQUEST['attr_id']) === TRUE)
684 return buildRedirectURL (__FUNCTION__
, 'OK');
686 return buildRedirectURL (__FUNCTION__
, 'ERR');
689 function updateObjectAllocation ()
691 assertUIntArg ('object_id', __FUNCTION__
);
693 $is_submit = isset ($_REQUEST['got_atoms']);
697 $object_id = $_REQUEST['object_id'];
698 $workingRacksData = array();
699 foreach ($_REQUEST['rackmulti'] as $cand_id)
701 if (!isset ($workingRacksData[$cand_id]))
703 $rackData = getRackData ($cand_id);
704 if ($rackData == NULL)
706 showError ('getRackData() failed', __FUNCTION__
);
709 $workingRacksData[$cand_id] = $rackData;
713 foreach ($workingRacksData as &$rd)
714 applyObjectMountMask ($rd, $object_id);
716 $oldMolecule = getMoleculeForObject ($object_id);
717 $worldchanged = FALSE;
719 foreach ($workingRacksData as $rack_id => $rackData)
721 $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
724 return buildWideRedirectURL($log);
728 unset($_GET['page']);
731 unset($_POST['page']);
732 unset($_POST['tab']);
734 return buildWideRedirectURL(array(), NULL, NULL, array_merge($_GET, $_POST));
738 $msgcode['updateObject']['OK'] = 16;
739 $msgcode['updateObject']['ERR'] = 121;
740 function updateObject ()
742 assertUIntArg ('num_attrs', __FUNCTION__
, TRUE);
743 assertUIntArg ('object_id', __FUNCTION__
);
744 assertUIntArg ('object_type_id', __FUNCTION__
);
745 assertStringArg ('object_name', __FUNCTION__
, TRUE);
746 assertStringArg ('object_label', __FUNCTION__
, TRUE);
747 assertStringArg ('object_barcode', __FUNCTION__
, TRUE);
748 assertStringArg ('object_asset_no', __FUNCTION__
, TRUE);
749 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
750 $has_problems = 'yes';
752 $has_problems = 'no';
754 if (commitUpdateObject (
755 $_REQUEST['object_id'],
756 $_REQUEST['object_name'],
757 $_REQUEST['object_label'],
758 $_REQUEST['object_barcode'],
759 $_REQUEST['object_type_id'],
761 $_REQUEST['object_asset_no'],
762 $_REQUEST['object_comment']
764 return buildRedirectURL (__FUNCTION__
, 'ERR');
766 // Update optional attributes
767 $oldvalues = getAttrValues ($_REQUEST['object_id']);
769 $num_attrs = isset ($_REQUEST['num_attrs']) ?
$_REQUEST['num_attrs'] : 0;
770 for ($i = 0; $i < $num_attrs; $i++
)
772 assertUIntArg ("${i}_attr_id", __FUNCTION__
);
773 $attr_id = $_REQUEST["${i}_attr_id"];
775 // Field is empty, delete attribute and move on.
776 if (empty($_REQUEST["${i}_value"]))
778 commitResetAttrValue ($_REQUEST['object_id'], $attr_id);
782 // The value could be uint/float, but we don't know ATM. Let SQL
783 // server check this and complain.
784 assertStringArg ("${i}_value", __FUNCTION__
);
785 $value = $_REQUEST["${i}_value"];
786 switch ($oldvalues[$attr_id]['type'])
791 $oldvalue = $oldvalues[$attr_id]['value'];
794 $oldvalue = $oldvalues[$attr_id]['key'];
797 showError ('Internal structure error', __FUNCTION__
);
800 if ($value == $oldvalue)
803 // Note if the queries succeed or not, it determines which page they see.
804 $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value);
806 if (in_array (FALSE, $result))
807 return buildRedirectURL (__FUNCTION__
, 'ERR');
809 // Invalidate thumb cache of all racks objects could occupy.
810 foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id)
811 resetThumbCache ($rack_id);
813 return buildRedirectURL (__FUNCTION__
, 'OK');
817 function addMultipleObjects()
820 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
821 $max = getConfigVar ('MASSCOUNT');
822 for ($i = 0; $i < $max; $i++
)
824 if (!isset ($_REQUEST["${i}_object_type_id"]))
826 $log = mergeLogs ($log, oneLiner (184, array ($i +
1)));
829 assertUIntArg ("${i}_object_type_id", __FUNCTION__
, TRUE);
830 assertStringArg ("${i}_object_name", __FUNCTION__
, TRUE);
831 assertStringArg ("${i}_object_label", __FUNCTION__
, TRUE);
832 assertStringArg ("${i}_object_asset_no", __FUNCTION__
, TRUE);
833 assertStringArg ("${i}_object_barcode", __FUNCTION__
, TRUE);
834 $name = $_REQUEST["${i}_object_name"];
836 // It's better to skip silently, than to print a notice.
837 if ($_REQUEST["${i}_object_type_id"] == 0)
842 $_REQUEST["${i}_object_label"],
843 $_REQUEST["${i}_object_barcode"],
844 $_REQUEST["${i}_object_type_id"],
845 $_REQUEST["${i}_object_asset_no"],
848 $log = mergeLogs ($log, oneLiner (80, array ($name)));
850 $log = mergeLogs ($log, oneLiner (185, array ($name)));
852 return buildWideRedirectURL ($log);
855 function addLotOfObjects()
858 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
859 assertUIntArg ('global_type_id', __FUNCTION__
, TRUE);
860 assertStringArg ('namelist', __FUNCTION__
, TRUE);
861 $global_type_id = $_REQUEST['global_type_id'];
862 if ($global_type_id == 0 or empty ($_REQUEST['namelist']))
863 $log = mergeLogs ($log, oneLiner (186));
866 // The name extractor below was stolen from ophandlers.php:addMultiPorts()
867 $names1 = explode ('\n', $_REQUEST['namelist']);
869 foreach ($names1 as $line)
871 $parts = explode ('\r', $line);
873 if (empty ($parts[0]))
876 $names2[] = rtrim ($parts[0]);
878 foreach ($names2 as $name)
879 if (commitAddObject ($name, '', '', $global_type_id, '', $taglist) === TRUE)
880 $log = mergeLogs ($log, oneLiner (80, array ($name)));
882 $log = mergeLogs ($log, oneLiner (185, array ($name)));
884 return buildWideRedirectURL ($log);
887 $msgcode['deleteObject']['OK'] = 76;
888 $msgcode['deleteObject']['ERR'] = 100;
889 function deleteObject ()
891 assertUIntArg ('object_id', __FUNCTION__
);
892 if (NULL === ($oinfo = getObjectInfo ($_REQUEST['object_id'])))
893 return buildRedirectURL (__FUNCTION__
, 'ERR', array ('object not found'));
895 $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE);
896 $error = commitDeleteObject ($_REQUEST['object_id']);
897 foreach ($racklist as $rack_id)
898 resetThumbCache ($rack_id);
901 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
903 return buildRedirectURL (__FUNCTION__
, 'OK', array ($oinfo['dname']));
906 $msgcode['useupPort']['OK'] = 11;
907 $msgcode['useupPort']['ERR'] = 124;
908 function useupPort ()
910 assertUIntArg ('port_id', __FUNCTION__
);
911 if (commitUseupPort ($_REQUEST['port_id']) === TRUE)
912 return buildRedirectURL (__FUNCTION__
, 'OK');
914 return buildRedirectURL (__FUNCTION__
, 'ERR');
917 $msgcode['updateUI']['OK'] = 56;
918 $msgcode['updateUI']['ERR'] = 125;
921 assertUIntArg ('num_vars', __FUNCTION__
);
924 for ($i = 0; $i < $_REQUEST['num_vars']; $i++
)
926 assertStringArg ("${i}_varname", __FUNCTION__
);
927 assertStringArg ("${i}_varvalue", __FUNCTION__
, TRUE);
928 $varname = $_REQUEST["${i}_varname"];
929 $varvalue = $_REQUEST["${i}_varvalue"];
931 // If form value = value in DB, don't bother updating DB
932 if ($varvalue == getConfigVar ($varname))
935 // Note if the queries succeed or not, it determines which page they see.
936 $error = setConfigVar ($varname, $varvalue, TRUE);
942 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
944 return buildRedirectURL (__FUNCTION__
, 'OK');
947 $msgcode['resetUIConfig']['OK'] = 57;
948 function resetUIConfig()
950 setConfigVar ('default_port_type','24');
951 setConfigVar ('MASSCOUNT','15');
952 setConfigVar ('MAXSELSIZE','30');
953 setConfigVar ('ROW_SCALE','2');
954 setConfigVar ('PORTS_PER_ROW','12');
955 setConfigVar ('IPV4_ADDRS_PER_PAGE','256');
956 setConfigVar ('DEFAULT_RACK_HEIGHT','42');
957 setConfigVar ('DEFAULT_SLB_VS_PORT','');
958 setConfigVar ('DEFAULT_SLB_RS_PORT','');
959 setConfigVar ('DETECT_URLS','no');
960 setConfigVar ('RACK_PRESELECT_THRESHOLD','1');
961 setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no');
962 setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm');
963 setConfigVar ('SHOW_EXPLICIT_TAGS','yes');
964 setConfigVar ('SHOW_IMPLICIT_TAGS','yes');
965 setConfigVar ('SHOW_AUTOMATIC_TAGS','no');
966 setConfigVar ('DEFAULT_OBJECT_TYPE','4');
967 setConfigVar ('IPV4_AUTO_RELEASE','1');
968 setConfigVar ('SHOW_LAST_TAB', 'no');
969 setConfigVar ('EXT_IPV4_VIEW', 'yes');
970 setConfigVar ('TREE_THRESHOLD', '25');
971 setConfigVar ('IPV4_JAYWALK', 'no');
972 setConfigVar ('ADDNEW_AT_TOP', 'yes');
973 setConfigVar ('IPV4_TREE_SHOW_USAGE', 'yes');
974 setConfigVar ('PREVIEW_TEXT_MAXCHARS', '10240');
975 setConfigVar ('PREVIEW_TEXT_ROWS', '25');
976 setConfigVar ('PREVIEW_TEXT_COLS', '80');
977 setConfigVar ('PREVIEW_IMAGE_MAXPXS', '320');
978 setConfigVar ('VENDOR_SIEVE', '');
979 setConfigVar ('IPV4LB_LISTSRC', '{$typeid_4}');
980 setConfigVar ('IPV4OBJ_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_12} or {$typeid_445} or {$typeid_447}');
981 setConfigVar ('IPV4NAT_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
982 setConfigVar ('ASSETWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
983 setConfigVar ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
984 setConfigVar ('RACKS_PER_ROW','12');
985 setConfigVar ('FILTER_PREDICATE_SIEVE','');
986 setConfigVar ('FILTER_DEFAULT_ANDOR','or');
987 setConfigVar ('FILTER_SUGGEST_ANDOR','yes');
988 setConfigVar ('FILTER_SUGGEST_TAGS','yes');
989 setConfigVar ('FILTER_SUGGEST_PREDICATES','yes');
990 setConfigVar ('FILTER_SUGGEST_EXTRA','no');
991 return buildRedirectURL (__FUNCTION__
, 'OK');
994 $msgcode['addRealServer']['OK'] = 34;
995 $msgcode['addRealServer']['ERR'] = 126;
996 // Add single record.
997 function addRealServer ()
999 assertUIntArg ('pool_id', __FUNCTION__
);
1000 assertIPv4Arg ('remoteip', __FUNCTION__
);
1001 assertStringArg ('rsport', __FUNCTION__
, TRUE);
1002 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1003 if (!addRStoRSPool (
1004 $_REQUEST['pool_id'],
1005 $_REQUEST['remoteip'],
1006 $_REQUEST['rsport'],
1007 getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'),
1008 $_REQUEST['rsconfig']
1010 return buildRedirectURL (__FUNCTION__
, 'ERR');
1012 return buildRedirectURL (__FUNCTION__
, 'OK');
1015 $msgcode['addRealServers']['OK'] = 37;
1016 $msgcode['addRealServers']['ERR1'] = 131;
1017 $msgcode['addRealServers']['ERR2'] = 127;
1018 // Parse textarea submitted and try adding a real server for each line.
1019 function addRealServers ()
1021 assertUIntArg ('pool_id', __FUNCTION__
);
1022 assertStringArg ('format', __FUNCTION__
);
1023 assertStringArg ('rawtext', __FUNCTION__
);
1024 $rawtext = str_replace ('\r', '', $_REQUEST['rawtext']);
1027 // Keep in mind, that the text will have HTML entities (namely '>') escaped.
1028 foreach (explode ('\n', $rawtext) as $line)
1033 switch ($_REQUEST['format'])
1035 case 'ipvs_2': // address and port only
1036 if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) /', $line, $match))
1038 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1043 case 'ipvs_3': // address, port and weight
1044 if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match))
1046 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3]))
1051 case 'ssv_2': // IP address and port
1052 if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match))
1054 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1059 case 'ssv_1': // IP address
1060 if (!preg_match ('/^([0-9\.]+)$/', $line, $match))
1062 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1068 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1072 if ($nbad == 0 and $ngood > 0)
1073 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1075 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($ngood, $nbad));
1078 $msgcode['addVService']['OK'] = 28;
1079 $msgcode['addVService']['ERR1'] = 132;
1080 $msgcode['addVService']['ERR2'] = 100;
1081 function addVService ()
1083 assertIPv4Arg ('vip', __FUNCTION__
);
1084 assertUIntArg ('vport', __FUNCTION__
);
1085 assertStringArg ('proto', __FUNCTION__
);
1086 if ($_REQUEST['proto'] != 'TCP' and $_REQUEST['proto'] != 'UDP')
1087 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1088 assertStringArg ('name', __FUNCTION__
, TRUE);
1089 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
1090 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1091 $error = commitCreateVS
1097 $_REQUEST['vsconfig'],
1098 $_REQUEST['rsconfig'],
1099 isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array()
1102 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error));
1104 return buildRedirectURL (__FUNCTION__
, 'OK');
1107 $msgcode['deleteRealServer']['OK'] = 35;
1108 $msgcode['deleteRealServer']['ERR'] = 128;
1109 function deleteRealServer ()
1111 assertUIntArg ('id', __FUNCTION__
);
1112 if (!commitDeleteRS ($_REQUEST['id']))
1113 return buildRedirectURL (__FUNCTION__
, 'ERR');
1115 return buildRedirectURL (__FUNCTION__
, 'OK');
1118 $msgcode['deleteLoadBalancer']['OK'] = 19;
1119 $msgcode['deleteLoadBalancer']['ERR'] = 129;
1120 function deleteLoadBalancer ()
1122 assertUIntArg ('object_id', __FUNCTION__
);
1123 assertUIntArg ('pool_id', __FUNCTION__
);
1124 assertUIntArg ('vs_id', __FUNCTION__
);
1125 if (!commitDeleteLB (
1126 $_REQUEST['object_id'],
1127 $_REQUEST['pool_id'],
1130 return buildRedirectURL (__FUNCTION__
, 'ERR');
1132 return buildRedirectURL (__FUNCTION__
, 'OK');
1135 $msgcode['deleteVService']['OK'] = 29;
1136 $msgcode['deleteVService']['ERR'] = 130;
1137 function deleteVService ()
1139 assertUIntArg ('vs_id', __FUNCTION__
);
1140 if (!commitDeleteVS ($_REQUEST['vs_id']))
1141 return buildRedirectURL (__FUNCTION__
, 'ERR');
1143 return buildRedirectURL (__FUNCTION__
, 'OK');
1146 $msgcode['updateRealServer']['OK'] = 36;
1147 $msgcode['updateRealServer']['ERR'] = 133;
1148 function updateRealServer ()
1150 assertUIntArg ('rs_id', __FUNCTION__
);
1151 assertIPv4Arg ('rsip', __FUNCTION__
);
1152 assertStringArg ('rsport', __FUNCTION__
, TRUE);
1153 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1154 if (!commitUpdateRS (
1157 $_REQUEST['rsport'],
1158 $_REQUEST['rsconfig']
1160 return buildRedirectURL (__FUNCTION__
, 'ERR');
1162 return buildRedirectURL (__FUNCTION__
, 'OK');
1165 $msgcode['updateLoadBalancer']['OK'] = 20;
1166 $msgcode['updateLoadBalancer']['ERR'] = 134;
1167 function updateLoadBalancer ()
1169 assertUIntArg ('object_id', __FUNCTION__
);
1170 assertUIntArg ('pool_id', __FUNCTION__
);
1171 assertUIntArg ('vs_id', __FUNCTION__
);
1172 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
1173 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1174 if (!commitUpdateLB (
1175 $_REQUEST['object_id'],
1176 $_REQUEST['pool_id'],
1178 $_REQUEST['vsconfig'],
1179 $_REQUEST['rsconfig']
1181 return buildRedirectURL (__FUNCTION__
, 'ERR');
1183 return buildRedirectURL (__FUNCTION__
, 'OK');
1186 $msgcode['updateVService']['OK'] = 30;
1187 $msgcode['updateVService']['ERR'] = 135;
1188 function updateVService ()
1190 assertUIntArg ('vs_id', __FUNCTION__
);
1191 assertIPv4Arg ('vip', __FUNCTION__
);
1192 assertUIntArg ('vport', __FUNCTION__
);
1193 assertStringArg ('proto', __FUNCTION__
);
1194 assertStringArg ('name', __FUNCTION__
, TRUE);
1195 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
1196 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1197 if (!commitUpdateVS (
1203 $_REQUEST['vsconfig'],
1204 $_REQUEST['rsconfig']
1206 return buildRedirectURL (__FUNCTION__
, 'ERR');
1208 return buildRedirectURL (__FUNCTION__
, 'OK');
1211 $msgcode['addLoadBalancer']['OK'] = 18;
1212 $msgcode['addLoadBalancer']['ERR'] = 137;
1213 function addLoadBalancer ()
1215 assertUIntArg ('pool_id', __FUNCTION__
);
1216 assertUIntArg ('object_id', __FUNCTION__
);
1217 assertUIntArg ('vs_id', __FUNCTION__
);
1218 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
1219 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1220 if (!addLBtoRSPool (
1221 $_REQUEST['pool_id'],
1222 $_REQUEST['object_id'],
1224 $_REQUEST['vsconfig'],
1225 $_REQUEST['rsconfig']
1227 return buildRedirectURL (__FUNCTION__
, 'ERR');
1229 return buildRedirectURL (__FUNCTION__
, 'OK');
1232 $msgcode['addRSPool']['OK'] = 31;
1233 $msgcode['addRSPool']['ERR'] = 100;
1234 function addRSPool ()
1236 assertStringArg ('name', __FUNCTION__
, TRUE);
1237 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
1238 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1239 $error = commitCreateRSPool
1242 $_REQUEST['vsconfig'],
1243 $_REQUEST['rsconfig'],
1244 isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array()
1247 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1249 return buildRedirectURL (__FUNCTION__
, 'OK');
1252 $msgcode['deleteRSPool']['OK'] = 32;
1253 $msgcode['deleteRSPool']['ERR'] = 138;
1254 function deleteRSPool ()
1256 assertUIntArg ('pool_id', __FUNCTION__
);
1257 if (!commitDeleteRSPool ($_REQUEST['pool_id']))
1258 return buildRedirectURL (__FUNCTION__
, 'ERR');
1260 return buildRedirectURL (__FUNCTION__
, 'OK');
1263 $msgcode['updateRSPool']['OK'] = 33;
1264 $msgcode['updateRSPool']['ERR'] = 139;
1265 function updateRSPool ()
1267 assertUIntArg ('pool_id', __FUNCTION__
);
1268 assertStringArg ('name', __FUNCTION__
, TRUE);
1269 assertStringArg ('vsconfig', __FUNCTION__
, TRUE);
1270 assertStringArg ('rsconfig', __FUNCTION__
, TRUE);
1271 if (!commitUpdateRSPool ($_REQUEST['pool_id'], $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
1272 return buildRedirectURL (__FUNCTION__
, 'ERR');
1274 return buildRedirectURL (__FUNCTION__
, 'OK');
1277 $msgcode['updateRSInService']['OK'] = 38;
1278 $msgcode['updateRSInService']['ERR'] = 140;
1279 function updateRSInService ()
1281 assertUIntArg ('rscount', __FUNCTION__
);
1282 $pool_id = $_REQUEST['pool_id'];
1283 $orig = spotEntity ('ipv4rspool', $pool_id);
1284 amplifyCell ($orig);
1286 for ($i = 1; $i <= $_REQUEST['rscount']; $i++
)
1288 $rs_id = $_REQUEST["rsid_${i}"];
1289 if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on')
1293 if ($newval != $orig['rslist'][$rs_id]['inservice'])
1295 if (commitSetInService ($rs_id, $newval))
1302 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1304 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($nbad, $ngood));
1307 $msgcode['importPTRData']['OK'] = 26;
1308 $msgcode['importPTRData']['ERR'] = 141;
1309 // FIXME: check, that each submitted address belongs to the prefix we
1310 // are operating on.
1311 function importPTRData ()
1313 assertUIntArg ('addrcount', __FUNCTION__
);
1315 for ($i = 0; $i < $_REQUEST['addrcount']; $i++
)
1317 $inputname = "import_${i}";
1318 if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on')
1320 assertIPv4Arg ("addr_${i}", __FUNCTION__
);
1321 assertStringArg ("descr_${i}", __FUNCTION__
, TRUE);
1322 assertStringArg ("rsvd_${i}", __FUNCTION__
);
1323 // Non-existent addresses will not have this argument set in request.
1325 if ($_REQUEST["rsvd_${i}"] == 'yes')
1327 if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '')
1333 return buildRedirectURL (__FUNCTION__
, 'OK', array ($ngood));
1335 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($nbad, $ngood));
1338 $msgcode['generateAutoPorts']['OK'] = 21;
1339 $msgcode['generateAutoPorts']['ERR'] = 142;
1340 function generateAutoPorts ()
1343 assertUIntArg ('object_id', __FUNCTION__
);
1344 $info = getObjectInfo ($_REQUEST['object_id'], FALSE);
1345 // Navigate away in case of success, stay at the place otherwise.
1346 if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id']))
1347 return buildRedirectURL (__FUNCTION__
, 'OK', array(), $pageno, 'ports');
1349 return buildRedirectURL (__FUNCTION__
, 'ERR');
1352 $msgcode['saveEntityTags']['OK'] = 22;
1353 $msgcode['saveEntityTags']['ERR1'] = 143;
1354 $msgcode['saveEntityTags']['ERR2'] = 187;
1355 // Filter out implicit tags before storing the new tag set.
1356 function saveEntityTags ()
1358 global $explicit_tags, $implicit_tags, $page, $pageno, $etype_by_pageno;
1359 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1360 return buildRedirectURL (__FUNCTION__
, 'ERR2', array (__FUNCTION__
));
1361 $realm = $etype_by_pageno[$pageno];
1362 $bypass = $page[$pageno]['bypass'];
1363 assertUIntArg ($bypass, __FUNCTION__
);
1364 $entity_id = $_REQUEST[$bypass];
1365 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1366 // Build a chain from the submitted data, minimize it,
1367 // then wipe existing records and store the new set instead.
1368 destroyTagsForEntity ($realm, $entity_id);
1369 $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist));
1370 $n_succeeds = $n_errors = 0;
1371 foreach ($newchain as $taginfo)
1372 if (addTagForEntity ($realm, $entity_id, $taginfo['id']))
1377 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($n_succeeds, $n_errors));
1379 return buildRedirectURL (__FUNCTION__
, 'OK', array ($n_succeeds));
1382 $msgcode['destroyTag']['OK'] = 58;
1383 $msgcode['destroyTag']['ERR1'] = 183;
1384 $msgcode['destroyTag']['ERR2'] = 144;
1385 function destroyTag ()
1387 assertUIntArg ('tag_id', __FUNCTION__
);
1389 if (!isset ($taglist[$_REQUEST['tag_id']]))
1390 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($_REQUEST['tag_id']));
1391 if (($ret = commitDestroyTag ($_REQUEST['tag_id'])) == '')
1392 return buildRedirectURL (__FUNCTION__
, 'OK', array ($taglist[$_REQUEST['tag_id']]['tag']));
1394 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1397 $msgcode['createTag']['OK'] = 59;
1398 $msgcode['createTag']['ERR1'] = 145;
1399 $msgcode['createTag']['ERR3'] = 147;
1400 function createTag ()
1402 assertStringArg ('tag_name', __FUNCTION__
);
1403 assertUIntArg ('parent_id', __FUNCTION__
, TRUE);
1404 $tagname = trim ($_REQUEST['tag_name']);
1405 if (!validTagName ($tagname))
1406 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($tagname));
1407 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1408 $parent_id = 'NULL';
1409 if (($ret = commitCreateTag ($tagname, $parent_id)) == '')
1410 return buildRedirectURL (__FUNCTION__
, 'OK', array ($tagname));
1412 return buildRedirectURL (__FUNCTION__
, 'ERR3', array ($tagname, $ret));
1415 $msgcode['updateTag']['OK'] = 60;
1416 $msgcode['updateTag']['ERR1'] = 145;
1417 $msgcode['updateTag']['ERR2'] = 148;
1418 function updateTag ()
1420 assertUIntArg ('tag_id', __FUNCTION__
);
1421 assertUIntArg ('parent_id', __FUNCTION__
, TRUE);
1422 assertStringArg ('tag_name', __FUNCTION__
);
1423 $tagname = trim ($_REQUEST['tag_name']);
1424 if (!validTagName ($tagname))
1425 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($tagname));
1426 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1427 $parent_id = 'NULL';
1428 if (($ret = commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id)) == '')
1429 return buildRedirectURL (__FUNCTION__
, 'OK', array ($tagname));
1430 // Use old name in the message, cause update failed.
1432 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($taglist[$_REQUEST['tag_id']]['tag'], $ret));
1435 $msgcode['rollTags']['OK'] = 67;
1436 $msgcode['rollTags']['ERR'] = 149;
1437 function rollTags ()
1439 assertUIntArg ('row_id', __FUNCTION__
);
1440 assertStringArg ('sum', __FUNCTION__
, TRUE);
1441 assertUIntArg ('realsum', __FUNCTION__
);
1442 if ($_REQUEST['sum'] != $_REQUEST['realsum'])
1443 return buildRedirectURL (__FUNCTION__
, 'ERR');
1444 // Even if the user requested an empty tag list, don't bail out, but process existing
1445 // tag chains with "zero" extra. This will make sure, that the stuff processed will
1446 // have its chains refined to "normal" form.
1447 $extratags = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1449 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
1450 // filter out the same tag again and again. It will have own noise to cancel.
1451 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
1452 foreach (array_keys (listCells ('rack', $_REQUEST['row_id'])) as $rack_id)
1454 if (rebuildTagChainForEntity ('rack', $rack_id, $extrachain))
1456 foreach (stuffInRackspace (getRackData ($rack_id)) as $object_id)
1457 if (rebuildTagChainForEntity ('object', $object_id, $extrachain))
1460 return buildRedirectURL (__FUNCTION__
, 'OK', array ($n_ok));
1463 $msgcode['changeMyPassword']['OK'] = 61;
1464 $msgcode['changeMyPassword']['ERR1'] = 150;
1465 $msgcode['changeMyPassword']['ERR2'] = 151;
1466 $msgcode['changeMyPassword']['ERR3'] = 152;
1467 $msgcode['changeMyPassword']['ERR4'] = 153;
1468 function changeMyPassword ()
1470 global $remote_username, $user_auth_src;
1471 if ($user_auth_src != 'database')
1472 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1473 assertStringArg ('oldpassword', __FUNCTION__
);
1474 assertStringArg ('newpassword1', __FUNCTION__
);
1475 assertStringArg ('newpassword2', __FUNCTION__
);
1476 $remote_userid = getUserIDByUsername ($remote_username);
1477 $userinfo = getUserInfo ($remote_userid);
1478 if ($userinfo['user_password_hash'] != sha1 ($_REQUEST['oldpassword']))
1479 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1480 if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2'])
1481 return buildRedirectURL (__FUNCTION__
, 'ERR3');
1482 if (commitUpdateUserAccount ($remote_userid, $userinfo['user_name'], $userinfo['user_realname'], sha1 ($_REQUEST['newpassword1'])))
1483 return buildRedirectURL (__FUNCTION__
, 'OK');
1485 return buildRedirectURL (__FUNCTION__
, 'ERR4');
1488 $msgcode['saveRackCode']['OK'] = 43;
1489 $msgcode['saveRackCode']['ERR1'] = 154;
1490 $msgcode['saveRackCode']['ERR2'] = 155;
1491 function saveRackCode ()
1493 assertStringArg ('rackcode');
1494 // For the test to succeed, unescape LFs, strip CRs.
1495 $newcode = str_replace ('\r', '', str_replace ('\n', "\n", $_REQUEST['rackcode']));
1496 $parseTree = getRackCode ($newcode);
1497 if ($parseTree['result'] != 'ACK')
1498 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($parseTree['load']));
1499 saveScript ('RackCodeCache', '');
1500 if (saveScript ('RackCode', $newcode))
1501 return buildRedirectURL (__FUNCTION__
, 'OK');
1503 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1506 $msgcode['setPortVLAN']['ERR1'] = 156;
1507 // This handler's context is pre-built, but not authorized. It is assumed, that the
1508 // handler will take existing context and before each commit check authorization
1509 // on the base chain plus necessary context added.
1510 function setPortVLAN ()
1512 assertUIntArg ('portcount', __FUNCTION__
);
1513 $data = getSwitchVLANs ($_REQUEST['object_id']);
1515 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1516 list ($vlanlist, $portlist) = $data;
1517 // Here we just build up 1 set command for the gateway with all of the ports
1518 // included. The gateway is expected to filter unnecessary changes silently
1519 // and to provide a list of responses with either error or success message
1520 // for each of the rest.
1521 $nports = $_REQUEST['portcount'];
1525 for ($i = 0; $i < $nports; $i++
)
1528 !isset ($_REQUEST['portname_' . $i]) ||
1529 !isset ($_REQUEST['vlanid_' . $i]) ||
1530 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
1532 $log['m'][] = array ('c' => 158, 'a' => array ($i));
1535 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
1536 $portlist[$i]['vlaind'] == 'TRUNK'
1541 $portname = $_REQUEST['portname_' . $i];
1542 $oldvlanid = $portlist[$i]['vlanid'];
1543 $newvlanid = $_REQUEST['vlanid_' . $i];
1544 // Finish the security context and evaluate it.
1546 $annex[] = array ('tag' => '$fromvlan_' . $oldvlanid);
1547 $annex[] = array ('tag' => '$tovlan_' . $newvlanid);
1548 if (!permitted (NULL, NULL, NULL, $annex))
1550 $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid));
1553 $setcmd .= $prefix . $portname . '=' . $newvlanid;
1556 // Feed the gateway and interpret its (non)response.
1558 $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd));
1560 $log['m'][] = array ('c' => 201);
1561 return buildWideRedirectURL ($log);
1564 function submitSLBConfig ()
1566 assertUIntArg ('object_id', __FUNCTION__
);
1567 $newconfig = buildLVSConfig ($_REQUEST['object_id']);
1568 $msglog = gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES
, 'UTF-8'));
1569 return buildWideRedirectURL ($msglog);
1572 $msgcode['addRow']['OK'] = 74;
1573 $msgcode['addRow']['ERR'] = 100;
1576 assertStringArg ('name', __FUNCTION__
);
1578 if (commitAddRow ($_REQUEST['name']) === TRUE)
1579 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1581 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($_REQUEST['name']));
1584 $msgcode['updateRow']['OK'] = 75;
1585 $msgcode['updateRow']['ERR'] = 100;
1586 function updateRow ()
1588 assertUIntArg ('row_id', __FUNCTION__
);
1589 assertStringArg ('name', __FUNCTION__
);
1591 if (TRUE === commitUpdateRow ($_REQUEST['row_id'], $_REQUEST['name']))
1592 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1594 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($_REQUEST['name']));
1597 $msgcode['deleteRow']['OK'] = 77;
1598 $msgcode['deleteRow']['ERR'] = 100;
1599 function deleteRow ()
1601 assertUIntArg ('row_id', __FUNCTION__
);
1602 $rowinfo = getRackRowInfo ($_REQUEST['row_id']);
1604 if (TRUE === commitDeleteRow ($_REQUEST['row_id']))
1605 return buildRedirectURL (__FUNCTION__
, 'OK', array ($rowinfo['name']));
1607 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($rowinfo['name']));
1610 $msgcode['addRack']['OK'] = 65;
1611 $msgcode['addRack']['ERR1'] = 171;
1612 $msgcode['addRack']['ERR2'] = 172;
1615 assertUIntArg ('row_id', __FUNCTION__
);
1616 $taglist = isset ($_REQUEST['taglist']) ?
$_REQUEST['taglist'] : array();
1617 if (isset ($_REQUEST['got_data']))
1619 assertStringArg ('rack_name', __FUNCTION__
);
1620 assertUIntArg ('rack_height1', __FUNCTION__
);
1621 assertStringArg ('rack_comment', __FUNCTION__
, TRUE);
1623 if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
1624 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['rack_name']));
1626 return buildRedirectURL (__FUNCTION__
, 'ERR1', array ($_REQUEST['rack_name']));
1628 elseif (isset ($_REQUEST['got_mdata']))
1630 assertUIntArg ('rack_height2', __FUNCTION__
);
1631 assertStringArg ('rack_names', __FUNCTION__
, TRUE);
1633 // copy-and-paste from renderAddMultipleObjectsForm()
1634 $names1 = explode ('\n', $_REQUEST['rack_names']);
1636 foreach ($names1 as $line)
1638 $parts = explode ('\r', $line);
1640 if (empty ($parts[0]))
1643 $names2[] = rtrim ($parts[0]);
1646 foreach ($names2 as $cname)
1647 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE)
1648 $log['m'][] = array ('c' => $msgcode[__FUNCTION__
]['OK'], 'a' => array ($cname));
1650 $log['m'][] = array ('c' => $msgcode[__FUNCTION__
]['ERR1'], 'a' => array ($cname));
1651 return buildWideRedirectURL ($log);
1654 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1657 $msgcode['deleteRack']['OK'] = 79;
1658 $msgcode['deleteRack']['ERR'] = 100;
1659 $msgcode['deleteRack']['ERR1'] = 206;
1660 function deleteRack ()
1662 assertUIntArg ('rack_id', __FUNCTION__
);
1663 $rack_id = $_REQUEST['rack_id'];
1664 $rackData = getRackData ($rack_id);
1665 if ($rackData == NULL)
1667 showError ('getRackData() failed', __FUNCTION__
);
1670 if (count ($rackData['mountedObjects']) == 0)
1672 resetThumbCache ($rack_id);
1673 if (TRUE === commitDeleteRack ($rack_id))
1674 return buildRedirectURL (__FUNCTION__
, 'OK', array ($rackData['name']), 'rackspace', 'default');
1676 return buildRedirectURL (__FUNCTION__
, 'ERR', array(), 'rackspace', 'default');
1680 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1684 $msgcode['updateRack']['OK'] = 68;
1685 $msgcode['updateRack']['ERR'] = 177;
1686 function updateRack ()
1688 assertUIntArg ('rack_id', __FUNCTION__
);
1689 assertUIntArg ('rack_row_id', __FUNCTION__
);
1690 assertUIntArg ('rack_height', __FUNCTION__
);
1691 assertStringArg ('rack_name', __FUNCTION__
);
1692 assertStringArg ('rack_comment', __FUNCTION__
, TRUE);
1694 resetThumbCache ($_REQUEST['rack_id']);
1695 if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
1696 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['rack_name']));
1698 return buildRedirectURL (__FUNCTION__
, 'ERR');
1701 function updateRackDesign ()
1703 assertUIntArg ('rack_id', __FUNCTION__
);
1704 if (($rackData = getRackData ($_REQUEST['rack_id'])) == NULL)
1706 showError ('getRackData() failed', __FUNCTION__
);
1709 applyRackDesignMask($rackData);
1710 markupObjectProblems ($rackData);
1711 $response = processGridForm ($rackData, 'A', 'F');
1712 return buildWideRedirectURL (array($response));
1715 function updateRackProblems ()
1717 assertUIntArg ('rack_id', __FUNCTION__
);
1718 if (($rackData = getRackData ($_REQUEST['rack_id'])) == NULL)
1720 showError ('getRackData() failed', __FUNCTION__
);
1723 applyRackProblemMask($rackData);
1724 markupObjectProblems ($rackData);
1725 $response = processGridForm ($rackData, 'F', 'U');
1726 return buildWideRedirectURL (array($response));
1729 function querySNMPData ()
1731 assertUIntArg ('object_id', __FUNCTION__
);
1732 assertStringArg ('community', __FUNCTION__
);
1733 require 'inc/snmp.php';
1734 return buildWideRedirectURL (doSNMPmining ($_REQUEST['object_id'], $_REQUEST['community']));
1737 $msgcode['addFileWithoutLink']['OK'] = 69;
1738 $msgcode['addFileWithoutLink']['ERR'] = 100;
1739 // File-related functions
1740 function addFileWithoutLink ()
1742 assertStringArg ('comment', __FUNCTION__
, TRUE);
1744 // Make sure the file can be uploaded
1745 if (get_cfg_var('file_uploads') != 1)
1746 return buildRedirectURL (__FUNCTION__
, 'ERR', array ("file uploads not allowed, change 'file_uploads' parameter in php.ini"));
1748 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1749 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $_REQUEST['comment']);
1752 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1754 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_FILES['file']['name']));
1757 $msgcode['addFileToEntity']['OK'] = 69;
1758 $msgcode['addFileToEntity']['ERR1'] = 187;
1759 $msgcode['addFileToEntity']['ERR2'] = 181;
1760 $msgcode['addFileToEntity']['ERR3'] = 182;
1761 function addFileToEntity ()
1763 global $page, $pageno, $etype_by_pageno;
1764 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1765 return buildRedirectURL (__FUNCTION__
, 'ERR1', array (__FUNCTION__
));
1766 $realm = $etype_by_pageno[$pageno];
1767 $bypass = $page[$pageno]['bypass'];
1768 assertUIntArg ($bypass, __FUNCTION__
);
1769 $entity_id = $_REQUEST[$bypass];
1770 assertStringArg ('comment', __FUNCTION__
, TRUE);
1772 // Make sure the file can be uploaded
1773 if (get_cfg_var('file_uploads') != 1)
1774 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1776 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1777 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $_REQUEST['comment']);
1779 return buildRedirectURL (__FUNCTION__
, 'ERR3', array ($error));
1781 $error = commitLinkFile (lastInsertID(), $realm, $entity_id);
1783 return buildRedirectURL (__FUNCTION__
, 'ERR3', array ($error));
1785 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_FILES['file']['name']));
1788 $msgcode['linkFileToEntity']['OK'] = 71;
1789 $msgcode['linkFileToEntity']['ERR1'] = 178;
1790 $msgcode['linkFileToEntity']['ERR2'] = 100;
1791 function linkFileToEntity ()
1793 assertUIntArg ('file_id', __FUNCTION__
);
1794 global $page, $pageno, $etype_by_pageno;
1795 $entity_type = $etype_by_pageno[$pageno];
1796 $bypass_name = $page[$pageno]['bypass'];
1797 assertUIntArg ($bypass_name, __FUNCTION__
);
1799 $fi = getFileInfo ($_REQUEST['file_id']);
1801 return buildRedirectURL (__FUNCTION__
, 'ERR1'); // file not found
1802 $error = commitLinkFile ($_REQUEST['file_id'], $entity_type, $_REQUEST[$bypass_name]);
1804 return buildRedirectURL (__FUNCTION__
, 'ERR2', array ($error)); // linking failed
1806 return buildRedirectURL (__FUNCTION__
, 'OK', array ($fi['name']));
1809 $msgcode['replaceFile']['OK'] = 70;
1810 $msgcode['replaceFile']['ERR1'] = 181;
1811 $msgcode['replaceFile']['ERR2'] = 207;
1812 $msgcode['replaceFile']['ERR3'] = 182;
1813 function replaceFile ()
1816 assertUIntArg ('file_id', __FUNCTION__
);
1818 // Make sure the file can be uploaded
1819 if (get_cfg_var('file_uploads') != 1)
1820 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1821 $shortInfo = getFileInfo ($sic['file_id']);
1823 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1825 return buildRedirectURL (__FUNCTION__
, 'ERR2');
1826 $error = commitReplaceFile ($sic['file_id'], $fp);
1828 return buildRedirectURL (__FUNCTION__
, 'ERR3', array ($error));
1830 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1833 $msgcode['updateFile']['OK'] = 70;
1834 $msgcode['updateFile']['ERR'] = 100;
1835 function updateFile ()
1837 assertUIntArg ('file_id', __FUNCTION__
);
1838 assertStringArg ('file_name', __FUNCTION__
);
1839 assertStringArg ('file_type', __FUNCTION__
);
1840 assertStringArg ('file_comment', __FUNCTION__
, TRUE);
1841 // prepared statement params below
1843 $error = commitUpdateFile ($sic['file_id'], $sic['file_name'], $sic['file_type'], $sic['file_comment']);
1845 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1847 return buildRedirectURL (__FUNCTION__
, 'OK', array ($_REQUEST['name']));
1850 $msgcode['unlinkFile']['OK'] = 72;
1851 $msgcode['unlinkFile']['ERR'] = 182;
1852 function unlinkFile ()
1854 assertUIntArg ('link_id', __FUNCTION__
);
1855 $error = commitUnlinkFile ($_REQUEST['link_id']);
1858 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1860 return buildRedirectURL (__FUNCTION__
, 'OK');
1863 $msgcode['deleteFile']['OK'] = 73;
1864 $msgcode['deleteFile']['ERR'] = 100;
1865 function deleteFile ()
1867 assertUIntArg ('file_id', __FUNCTION__
);
1868 $shortInfo = getFileInfo ($_REQUEST['file_id']);
1869 $error = commitDeleteFile ($_REQUEST['file_id']);
1872 return buildRedirectURL (__FUNCTION__
, 'ERR', array ($error));
1874 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1877 $msgcode['updateFileText']['OK'] = 78;
1878 $msgcode['updateFileText']['ERR1'] = 179;
1879 $msgcode['updateFileText']['ERR2'] = 180;
1880 function updateFileText ()
1882 assertUIntArg ('file_id', __FUNCTION__
);
1883 assertStringArg ('mtime_copy', __FUNCTION__
);
1884 assertStringArg ('file_text', __FUNCTION__
, TRUE); // it's Ok to save empty
1885 $shortInfo = getFileInfo ($_REQUEST['file_id']);
1886 if ($shortInfo['mtime'] != $_REQUEST['mtime_copy'])
1887 return buildRedirectURL (__FUNCTION__
, 'ERR1');
1889 $error = commitReplaceFile ($sic['file_id'], $sic['file_text']);
1891 return buildRedirectURL (__FUNCTION__
, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1892 return buildRedirectURL (__FUNCTION__
, 'ERR2');