r3078 - addPortInterfaceCompat(): new function
[racktables] / inc / ophandlers.php
1 <?php
2 /*
3 *
4 * This file is a library of operation handlers for RackTables.
5 *
6 */
7
8 $msgcode = array();
9
10 function buildWideRedirectURL ($log, $nextpage = NULL, $nexttab = NULL, $moreArgs = array())
11 {
12 global $root, $page, $pageno, $tabno;
13 if ($nextpage === NULL)
14 $nextpage = $pageno;
15 if ($nexttab === NULL)
16 $nexttab = $tabno;
17 $url = "${root}?page=${nextpage}&tab=${nexttab}";
18 if (isset ($page[$nextpage]['bypass']))
19 $url .= '&' . $page[$nextpage]['bypass'] . '=' . $_REQUEST[$page[$nextpage]['bypass']];
20
21 if (count($moreArgs)>0)
22 {
23 foreach($moreArgs as $arg=>$value)
24 {
25 if (gettype($value) == 'array')
26 {
27 foreach ($value as $v)
28 {
29 $url .= '&'.urlencode($arg.'[]').'='.urlencode($v);
30 }
31 }
32 else
33 $url .= '&'.urlencode($arg).'='.urlencode($value);
34 }
35 }
36
37 $_SESSION['log'] = $log;
38 return $url;
39 }
40
41 function buildRedirectURL ($callfunc, $status, $args = array(), $nextpage = NULL, $nexttab = NULL)
42 {
43 global $pageno, $tabno, $msgcode;
44 if ($nextpage === NULL)
45 $nextpage = $pageno;
46 if ($nexttab === NULL)
47 $nexttab = $tabno;
48 return buildWideRedirectURL (oneLiner ($msgcode[$callfunc][$status], $args), $nextpage, $nexttab);
49 }
50
51 $msgcode['addPortForwarding']['OK'] = 2;
52 $msgcode['addPortForwarding']['ERR'] = 100;
53 function addPortForwarding ()
54 {
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 (!strlen ($remoteport))
63 $remoteport = $_REQUEST['localport'];
64
65 $error = newPortForwarding
66 (
67 $_REQUEST['object_id'],
68 $_REQUEST['localip'],
69 $_REQUEST['localport'],
70 $_REQUEST['remoteip'],
71 $remoteport,
72 $_REQUEST['proto'],
73 $_REQUEST['description']
74 );
75
76 if ($error == '')
77 return buildRedirectURL (__FUNCTION__, 'OK');
78 else
79 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
80 }
81
82 $msgcode['delPortForwarding']['OK'] = 3;
83 $msgcode['delPortForwarding']['ERR'] = 100;
84 function delPortForwarding ()
85 {
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__);
92
93 $error = deletePortForwarding
94 (
95 $_REQUEST['object_id'],
96 $_REQUEST['localip'],
97 $_REQUEST['localport'],
98 $_REQUEST['remoteip'],
99 $_REQUEST['remoteport'],
100 $_REQUEST['proto']
101 );
102 if ($error == '')
103 return buildRedirectURL (__FUNCTION__, 'OK');
104 else
105 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
106 }
107
108 $msgcode['updPortForwarding']['OK'] = 4;
109 $msgcode['updPortForwarding']['ERR'] = 100;
110 function updPortForwarding ()
111 {
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__);
119
120 $error = updatePortForwarding
121 (
122 $_REQUEST['object_id'],
123 $_REQUEST['localip'],
124 $_REQUEST['localport'],
125 $_REQUEST['remoteip'],
126 $_REQUEST['remoteport'],
127 $_REQUEST['proto'],
128 $_REQUEST['description']
129 );
130 if ($error == '')
131 return buildRedirectURL (__FUNCTION__, 'OK');
132 else
133 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
134 }
135
136 $msgcode['addPortForObject']['OK'] = 5;
137 $msgcode['addPortForObject']['ERR1'] = 101;
138 $msgcode['addPortForObject']['ERR2'] = 100;
139 function addPortForObject ()
140 {
141 assertUIntArg ('object_id', __FUNCTION__);
142 assertStringArg ('port_name', __FUNCTION__, TRUE);
143 if (!strlen ($_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']);
146 if ($error != '')
147 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
148 else
149 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name']));
150 }
151
152 $msgcode['editPortForObject']['OK'] = 6;
153 $msgcode['editPortForObject']['ERR1'] = 101;
154 $msgcode['editPortForObject']['ERR2'] = 100;
155 function editPortForObject ()
156 {
157 assertUIntArg ('object_id', __FUNCTION__);
158 assertUIntArg ('port_id', __FUNCTION__);
159 assertUIntArg ('port_type_id', __FUNCTION__);
160 // tolerate empty value now to produce custom informative message later
161 assertStringArg ('name', __FUNCTION__, TRUE);
162 if (!strlen ($_REQUEST['name']))
163 return buildRedirectURL (__FUNCTION__, 'ERR1');
164
165 if (isset ($_REQUEST['reservation_comment']) and strlen ($_REQUEST['reservation_comment']))
166 $port_rc = '"' . $_REQUEST['reservation_comment'] . '"';
167 else
168 $port_rc = 'NULL';
169 $error = commitUpdatePort ($_REQUEST['object_id'], $_REQUEST['port_id'], $_REQUEST['name'], $_REQUEST['port_type_id'], $_REQUEST['label'], $_REQUEST['l2address'], $port_rc);
170 if ($error != '')
171 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
172 else
173 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name']));
174 }
175
176 $msgcode['delPortFromObject']['OK'] = 7;
177 $msgcode['delPortFromObject']['ERR'] = 100;
178 function delPortFromObject ()
179 {
180 assertUIntArg ('port_id', __FUNCTION__);
181 $error = delObjectPort ($_REQUEST['port_id']);
182
183 if ($error != '')
184 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
185 else
186 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name']));
187 }
188
189 $msgcode['linkPortForObject']['OK'] = 8;
190 $msgcode['linkPortForObject']['ERR'] = 100;
191 function linkPortForObject ()
192 {
193 assertUIntArg ('port_id', __FUNCTION__);
194 assertUIntArg ('remote_port_id', __FUNCTION__);
195 assertStringArg ('port_name', __FUNCTION__, TRUE);
196 assertStringArg ('remote_port_name', __FUNCTION__, TRUE);
197 assertStringArg ('remote_object_name', __FUNCTION__, TRUE);
198
199 $error = linkPorts ($_REQUEST['port_id'], $_REQUEST['remote_port_id']);
200 if ($error != '')
201 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
202 else
203 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name'], $_REQUEST['remote_port_name'], $_REQUEST['remote_object_name']));
204 }
205
206 $msgcode['unlinkPortForObject']['OK'] = 9;
207 $msgcode['unlinkPortForObject']['ERR'] = 100;
208 function unlinkPortForObject ()
209 {
210 assertUIntArg ('port_id', __FUNCTION__);
211 assertStringArg ('port_name', __FUNCTION__, TRUE);
212 assertStringArg ('remote_port_name', __FUNCTION__, TRUE);
213 assertStringArg ('remote_object_name', __FUNCTION__, TRUE);
214
215 $error = unlinkPort ($_REQUEST['port_id']);
216 if ($error != '')
217 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
218 else
219 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name'], $_REQUEST['remote_port_name'], $_REQUEST['remote_object_name']));
220 }
221
222 $msgcode['addMultiPorts']['OK'] = 10;
223 $msgcode['addMultiPorts']['ERR'] = 123;
224 function addMultiPorts ()
225 {
226 assertStringArg ('format', __FUNCTION__);
227 assertStringArg ('input', __FUNCTION__);
228 assertUIntArg ('port_type', __FUNCTION__);
229 assertUIntArg ('object_id', __FUNCTION__);
230 $format = $_REQUEST['format'];
231 $port_type = $_REQUEST['port_type'];
232 $object_id = $_REQUEST['object_id'];
233 // Input lines are escaped, so we have to explode and to chop by 2-char
234 // \n and \r respectively.
235 $lines1 = explode ('\n', $_REQUEST['input']);
236 foreach ($lines1 as $line)
237 {
238 $parts = explode ('\r', $line);
239 reset ($parts);
240 if (!strlen ($parts[0]))
241 continue;
242 else
243 $lines2[] = rtrim ($parts[0]);
244 }
245 $ports = array();
246 foreach ($lines2 as $line)
247 {
248 switch ($format)
249 {
250 case 'fisxii':
251 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
252 list ($slot, $port) = explode ('/', $words[0]);
253 $ports[] = array
254 (
255 'name' => "e ${slot}/${port}",
256 'l2address' => $words[8],
257 'label' => "slot ${slot} port ${port}"
258 );
259 break;
260 case 'c3600asy':
261 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', trim (substr ($line, 3))));
262 /*
263 How Async Lines are Numbered in Cisco 3600 Series Routers
264 http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00801ca70b.shtml
265
266 Understanding 16- and 32-Port Async Network Modules
267 http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00800a93f0.shtml
268 */
269 $async = $words[0];
270 $slot = floor (($async - 1) / 32);
271 $octalgroup = floor (($async - 1 - $slot * 32) / 8);
272 $cable = $async - $slot * 32 - $octalgroup * 8;
273 $og_label[0] = 'async 0-7';
274 $og_label[1] = 'async 8-15';
275 $og_label[2] = 'async 16-23';
276 $og_label[3] = 'async 24-31';
277 $ports[] = array
278 (
279 'name' => "async ${async}",
280 'l2address' => '',
281 'label' => "slot ${slot} " . $og_label[$octalgroup] . " cable ${cable}"
282 );
283 break;
284 case 'fiwg':
285 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
286 $ifnumber = $words[0] * 1;
287 $ports[] = array
288 (
289 'name' => "e ${ifnumber}",
290 'l2address' => "${words[8]}",
291 'label' => "${ifnumber}"
292 );
293 break;
294 case 'ssv1':
295 $words = explode (' ', $line);
296 if (!strlen ($words[0]) or !strlen ($words[1]))
297 continue;
298 $ports[] = array
299 (
300 'name' => $words[0],
301 'l2address' => $words[1],
302 'label' => ''
303 );
304 break;
305 default:
306 return buildRedirectURL (__FUNCTION__, 'ERR');
307 break;
308 }
309 }
310 // Create ports, if they don't exist.
311 $added_count = $updated_count = $error_count = 0;
312 foreach ($ports as $port)
313 {
314 $port_id = getPortID ($object_id, $port['name']);
315 if ($port_id === NULL)
316 {
317 $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
318 if ($result == '')
319 $added_count++;
320 else
321 $error_count++;
322 }
323 else
324 {
325 $result = commitUpdatePort ($object_id, $port_id, $port['name'], $port_type, $port['label'], $port['l2address']);
326 if ($result == '')
327 $updated_count++;
328 else
329 $error_count++;
330 }
331 }
332 return buildRedirectURL (__FUNCTION__, 'OK', array ($added_count, $updated_count, $error_count));
333 }
334
335 $msgcode['updIPv4Allocation']['OK'] = 12;
336 $msgcode['updIPv4Allocation']['ERR'] = 100;
337 function updIPv4Allocation ()
338 {
339 assertIPv4Arg ('ip', __FUNCTION__);
340 assertUIntArg ('object_id', __FUNCTION__);
341 assertStringArg ('bond_name', __FUNCTION__, TRUE);
342 assertStringArg ('bond_type', __FUNCTION__);
343
344 $error = updateBond ($_REQUEST['ip'], $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
345 if ($error != '')
346 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
347 else
348 return buildRedirectURL (__FUNCTION__, 'OK');
349 }
350
351 $msgcode['delIPv4Allocation']['OK'] = 14;
352 $msgcode['delIPv4Allocation']['ERR'] = 100;
353 function delIPv4Allocation ()
354 {
355 assertIPv4Arg ('ip', __FUNCTION__);
356 assertUIntArg ('object_id', __FUNCTION__);
357
358 $error = unbindIpFromObject ($_REQUEST['ip'], $_REQUEST['object_id']);
359 if ($error != '')
360 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
361 else
362 return buildRedirectURL (__FUNCTION__, 'OK');
363 }
364
365 $msgcode['addIPv4Allocation']['OK'] = 13;
366 $msgcode['addIPv4Allocation']['ERR1'] = 170;
367 $msgcode['addIPv4Allocation']['ERR2'] = 100;
368 function addIPv4Allocation ()
369 {
370 assertIPv4Arg ('ip', __FUNCTION__);
371 assertUIntArg ('object_id', __FUNCTION__);
372 assertStringArg ('bond_name', __FUNCTION__, TRUE);
373 assertStringArg ('bond_type', __FUNCTION__);
374
375 // Strip masklen.
376 $ip = ereg_replace ('/[[:digit:]]+$', '', $_REQUEST['ip']);
377 if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv4AddressNetworkId ($ip))
378 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($ip));
379
380 $error = bindIpToObject ($ip, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
381 if ($error != '')
382 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
383 $address = getIPv4Address ($ip);
384 if ($address['reserved'] == 'yes' or strlen ($address['name']))
385 {
386 $release = getConfigVar ('IPV4_AUTO_RELEASE');
387 if ($release >= 1)
388 $address['reserved'] = 'no';
389 if ($release >= 2)
390 $address['name'] = '';
391 updateAddress ($ip, $address['name'], $address['reserved']);
392 }
393 return buildRedirectURL (__FUNCTION__, 'OK');
394 }
395
396 $msgcode['addIPv4Prefix']['OK'] = 23;
397 $msgcode['addIPv4Prefix']['ERR'] = 100;
398 $msgcode['addIPv4Prefix']['ERR1'] = 173;
399 $msgcode['addIPv4Prefix']['ERR2'] = 174;
400 $msgcode['addIPv4Prefix']['ERR3'] = 175;
401 $msgcode['addIPv4Prefix']['ERR4'] = 176;
402 function addIPv4Prefix ()
403 {
404 assertStringArg ('range', __FUNCTION__);
405 assertStringArg ('name', __FUNCTION__, TRUE);
406
407 $is_bcast = isset ($_REQUEST['is_bcast']) ? $_REQUEST['is_bcast'] : 'off';
408 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
409 $error = createIPv4Prefix ($_REQUEST['range'], $_REQUEST['name'], $is_bcast == 'on', $taglist);
410 if ($error != '')
411 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
412 else
413 return buildRedirectURL (__FUNCTION__, 'OK');
414 }
415
416 $msgcode['delIPv4Prefix']['OK'] = 24;
417 $msgcode['delIPv4Prefix']['ERR'] = 100;
418 function delIPv4Prefix ()
419 {
420 assertUIntArg ('id', __FUNCTION__);
421 $error = destroyIPv4Prefix ($_REQUEST['id']);
422 if ($error != '')
423 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
424 else
425 return buildRedirectURL (__FUNCTION__, 'OK');
426 }
427
428 $msgcode['updIPv4Prefix']['OK'] = 25;
429 $msgcode['updIPv4Prefix']['ERR'] = 100;
430 function updIPv4Prefix ()
431 {
432 assertUIntArg ('id', __FUNCTION__);
433 assertStringArg ('name', __FUNCTION__, TRUE);
434 assertStringArg ('comment', __FUNCTION__, TRUE);
435 global $sic;
436 if (strlen ($error = updateIPv4Network_real ($sic['id'], $sic['name'], $sic['comment'])))
437 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
438 else
439 return buildRedirectURL (__FUNCTION__, 'OK');
440 }
441
442 $msgcode['editAddress']['OK'] = 27;
443 $msgcode['editAddress']['ERR'] = 100;
444 function editAddress ()
445 {
446 assertIPv4Arg ('ip', __FUNCTION__);
447 assertStringArg ('name', __FUNCTION__, TRUE);
448
449 if (isset ($_REQUEST['reserved']))
450 $reserved = $_REQUEST['reserved'];
451 else
452 $reserved = 'off';
453 $error = updateAddress ($_REQUEST['ip'], $_REQUEST['name'], $reserved == 'on' ? 'yes' : 'no');
454 if ($error != '')
455 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
456 else
457 return buildRedirectURL (__FUNCTION__, 'OK');
458 }
459
460 $msgcode['createUser']['OK'] = 40;
461 $msgcode['createUser']['ERR'] = 102;
462 function createUser ()
463 {
464 assertStringArg ('username', __FUNCTION__);
465 assertStringArg ('realname', __FUNCTION__, TRUE);
466 assertStringArg ('password', __FUNCTION__);
467 $username = $_REQUEST['username'];
468 $password = sha1 ($_REQUEST['password']);
469 $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password);
470 if ($result != TRUE)
471 return buildRedirectURL (__FUNCTION__, 'ERR', array ($username));
472 if (isset ($_REQUEST['taglist']))
473 produceTagsForLastRecord ('user', $_REQUEST['taglist']);
474 return buildRedirectURL (__FUNCTION__, 'OK', array ($username));
475 }
476
477 $msgcode['updateUser']['OK'] = 39;
478 $msgcode['updateUser']['ERR1'] = 103;
479 $msgcode['updateUser']['ERR1'] = 104;
480 function updateUser ()
481 {
482 assertUIntArg ('user_id', __FUNCTION__);
483 assertStringArg ('username', __FUNCTION__);
484 assertStringArg ('realname', __FUNCTION__, TRUE);
485 assertStringArg ('password', __FUNCTION__);
486 $username = $_REQUEST['username'];
487 $new_password = $_REQUEST['password'];
488 if (NULL == ($userinfo = spotEntity ('user', $_REQUEST['user_id'])))
489 return buildRedirectURL (__FUNCTION__, 'ERR1');
490 // Update user password only if provided password is not the same as current password hash.
491 if ($new_password != $userinfo['user_password_hash'])
492 $new_password = sha1 ($new_password);
493 $result = commitUpdateUserAccount ($_REQUEST['user_id'], $username, $_REQUEST['realname'], $new_password);
494 if ($result == TRUE)
495 return buildRedirectURL (__FUNCTION__, 'OK', array ($username));
496 else
497 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($username));
498 }
499
500 $msgcode['savePortMap']['OK'] = 44;
501 $msgcode['savePortMap']['ERR'] = 108;
502 // This function find differences in users's submit and PortCompat table
503 // and modifies database accordingly.
504 function savePortMap ()
505 {
506 // values' format doesn't matter, only keys are used
507 $ptlist = readChapter (CHAP_PORTTYPE);
508 $oldCompat = getPortCompat();
509 $newCompat = array();
510 foreach (array_keys ($ptlist) as $leftKey)
511 foreach (array_keys ($ptlist) as $rightKey)
512 if (isset ($_REQUEST["atom_${leftKey}_${rightKey}"]))
513 $newCompat[] = array ('type1' => $leftKey, 'type2' => $rightKey);
514 // Build the new matrix from user's submit and compare it to
515 // the old matrix. Those pairs which appear on
516 // new matrix only, have to be stored in PortCompat table. Those who appear
517 // on the old matrix only, should be removed from PortCompat table.
518 // Those present in both matrices should be skipped.
519 $oldCompatTable = buildPortCompatMatrixFromList ($ptlist, $oldCompat);
520 $newCompatTable = buildPortCompatMatrixFromList ($ptlist, $newCompat);
521 $error_count = $success_count = 0;
522 foreach (array_keys ($ptlist) as $type1)
523 foreach (array_keys ($ptlist) as $type2)
524 if ($oldCompatTable[$type1][$type2] != $newCompatTable[$type1][$type2])
525 switch ($oldCompatTable[$type1][$type2])
526 {
527 case TRUE: // new value is FALSE
528 if (removePortCompat ($type1, $type2) === TRUE)
529 $success_count++;
530 else
531 $error_count++;
532 break;
533 case FALSE: // new value is TRUE
534 if (addPortCompat ($type1, $type2) === TRUE)
535 $success_count++;
536 else
537 $error_count++;
538 break;
539 default:
540 showError ('Internal error: oldCompatTable is invalid', __FUNCTION__);
541 break;
542 }
543 if ($error_count == 0)
544 return buildRedirectURL (__FUNCTION__, 'OK', array ($error_count, $success_count));
545 else
546 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error_count, $success_count));
547 }
548
549 $msgcode['updateDictionary']['OK'] = 51;
550 $msgcode['updateDictionary']['ERR'] = 109;
551 function updateDictionary ()
552 {
553 assertUIntArg ('chapter_no', __FUNCTION__);
554 assertUIntArg ('dict_key', __FUNCTION__);
555 assertStringArg ('dict_value', __FUNCTION__);
556 if (commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value']) === TRUE)
557 return buildRedirectURL (__FUNCTION__, 'OK');
558 else
559 return buildRedirectURL (__FUNCTION__, 'ERR');
560 }
561
562 $msgcode['supplementDictionary']['OK'] = 52;
563 $msgcode['supplementDictionary']['ERR'] = 110;
564 function supplementDictionary ()
565 {
566 assertUIntArg ('chapter_no', __FUNCTION__);
567 assertStringArg ('dict_value', __FUNCTION__);
568 if (commitSupplementDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_value']) === TRUE)
569 return buildRedirectURL (__FUNCTION__, 'OK');
570 else
571 return buildRedirectURL (__FUNCTION__, 'ERR');
572 }
573
574 $msgcode['reduceDictionary']['OK'] = 50;
575 $msgcode['reduceDictionary']['ERR'] = 111;
576 function reduceDictionary ()
577 {
578 assertUIntArg ('chapter_no', __FUNCTION__);
579 assertUIntArg ('dict_key', __FUNCTION__);
580 if (commitReduceDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key']) === TRUE)
581 return buildRedirectURL (__FUNCTION__, 'OK');
582 else
583 return buildRedirectURL (__FUNCTION__, 'ERR');
584 }
585
586 $msgcode['addChapter']['OK'] = 55;
587 $msgcode['addChapter']['ERR'] = 112;
588 function addChapter ()
589 {
590 assertStringArg ('chapter_name', __FUNCTION__);
591 if (commitAddChapter ($_REQUEST['chapter_name']) === TRUE)
592 return buildRedirectURL (__FUNCTION__, 'OK');
593 else
594 return buildRedirectURL (__FUNCTION__, 'ERR');
595 }
596
597 $msgcode['updateChapter']['OK'] = 54;
598 $msgcode['updateChapter']['ERR'] = 113;
599 function updateChapter ()
600 {
601 assertUIntArg ('chapter_no', __FUNCTION__);
602 assertStringArg ('chapter_name', __FUNCTION__);
603 if (commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name']) === TRUE)
604 return buildRedirectURL (__FUNCTION__, 'OK');
605 else
606 return buildRedirectURL (__FUNCTION__, 'ERR');
607 }
608
609 $msgcode['delChapter']['OK'] = 53;
610 $msgcode['delChapter']['ERR'] = 114;
611 function delChapter ()
612 {
613 assertUIntArg ('chapter_no', __FUNCTION__);
614 if (commitDeleteChapter ($_REQUEST['chapter_no']))
615 return buildRedirectURL (__FUNCTION__, 'OK');
616 else
617 return buildRedirectURL (__FUNCTION__, 'ERR');
618 }
619
620 $msgcode['changeAttribute']['OK'] = 46;
621 $msgcode['changeAttribute']['ERR'] = 115;
622 function changeAttribute ()
623 {
624 assertUIntArg ('attr_id', __FUNCTION__);
625 assertStringArg ('attr_name', __FUNCTION__);
626 if (commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name']))
627 return buildRedirectURL (__FUNCTION__, 'OK');
628 else
629 return buildRedirectURL (__FUNCTION__, 'ERR');
630 }
631
632 $msgcode['createAttribute']['OK'] = 45;
633 $msgcode['createAttribute']['ERR'] = 116;
634 function createAttribute ()
635 {
636 assertStringArg ('attr_name', __FUNCTION__);
637 assertStringArg ('attr_type', __FUNCTION__);
638 if (commitAddAttribute ($_REQUEST['attr_name'], $_REQUEST['attr_type']))
639 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['attr_name']));
640 else
641 return buildRedirectURL (__FUNCTION__, 'ERR');
642 }
643
644 $msgcode['deleteAttribute']['OK'] = 47;
645 $msgcode['deleteAttribute']['ERR'] = 117;
646 function deleteAttribute ()
647 {
648 assertUIntArg ('attr_id', __FUNCTION__);
649 if (commitDeleteAttribute ($_REQUEST['attr_id']))
650 return buildRedirectURL (__FUNCTION__, 'OK');
651 else
652 return buildRedirectURL (__FUNCTION__, 'ERR');
653 }
654
655 $msgcode['supplementAttrMap']['OK'] = 48;
656 $msgcode['supplementAttrMap']['ERR1'] = 154;
657 $msgcode['supplementAttrMap']['ERR2'] = 118;
658 function supplementAttrMap ()
659 {
660 assertUIntArg ('attr_id', __FUNCTION__);
661 assertUIntArg ('objtype_id', __FUNCTION__);
662 $attrMap = getAttrMap();
663 if ($attrMap[$_REQUEST['attr_id']]['type'] != 'dict')
664 $chapter_id = 'NULL';
665 else
666 {
667 assertUIntArg ('chapter_no', __FUNCTION__); // FIXME: this doesn't fail on 0 (ticket:272)
668 if (0 == ($chapter_id = $_REQUEST['chapter_no']))
669 return buildRedirectURL (__FUNCTION__, 'ERR1', array ('chapter not selected'));
670 }
671 if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $chapter_id) === TRUE)
672 return buildRedirectURL (__FUNCTION__, 'OK');
673 else
674 return buildRedirectURL (__FUNCTION__, 'ERR2');
675 }
676
677 $msgcode['reduceAttrMap']['OK'] = 49;
678 $msgcode['reduceAttrMap']['ERR'] = 119;
679 function reduceAttrMap ()
680 {
681 assertUIntArg ('attr_id', __FUNCTION__);
682 assertUIntArg ('objtype_id', __FUNCTION__);
683 if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) === TRUE)
684 return buildRedirectURL (__FUNCTION__, 'OK');
685 else
686 return buildRedirectURL (__FUNCTION__, 'ERR');
687 }
688
689 $msgcode['clearSticker']['OK'] = 15;
690 $msgcode['clearSticker']['ERR'] = 120;
691 function clearSticker ()
692 {
693 assertUIntArg ('attr_id', __FUNCTION__);
694 assertUIntArg ('object_id', __FUNCTION__);
695 if (commitResetAttrValue ($_REQUEST['object_id'], $_REQUEST['attr_id']) === TRUE)
696 return buildRedirectURL (__FUNCTION__, 'OK');
697 else
698 return buildRedirectURL (__FUNCTION__, 'ERR');
699 }
700
701 $msgcode['updateObjectAllocation']['OK'] = 63;
702 function updateObjectAllocation ()
703 {
704 assertUIntArg ('object_id', __FUNCTION__);
705
706 if (!isset ($_REQUEST['got_atoms']))
707 {
708 unset($_GET['page']);
709 unset($_GET['tab']);
710 unset($_GET['op']);
711 unset($_POST['page']);
712 unset($_POST['tab']);
713 unset($_POST['op']);
714 return buildWideRedirectURL (array(), NULL, NULL, array_merge ($_GET, $_POST));
715 }
716 $object_id = $_REQUEST['object_id'];
717 $workingRacksData = array();
718 foreach ($_REQUEST['rackmulti'] as $cand_id)
719 {
720 if (!isset ($workingRacksData[$cand_id]))
721 {
722 $rackData = spotEntity ('rack', $cand_id);
723 if ($rackData == NULL)
724 {
725 showError ('rack not found', __FUNCTION__);
726 return;
727 }
728 amplifyCell ($rackData);
729 $workingRacksData[$cand_id] = $rackData;
730 }
731 }
732
733 foreach ($workingRacksData as &$rd)
734 applyObjectMountMask ($rd, $object_id);
735
736 $oldMolecule = getMoleculeForObject ($object_id);
737 $changecnt = 0;
738 $log = array();
739 foreach ($workingRacksData as $rack_id => $rackData)
740 {
741 $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
742 $log[] = $logrecord;
743 if ($logrecord['code'] == 300)
744 continue;
745 $changecnt++;
746 // Reload our working copy after form processing.
747 $rackData = spotEntity ('rack', $cand_id);
748 amplifyCell ($rackData);
749 applyObjectMountMask ($rackData, $object_id);
750 $workingRacksData[$rack_id] = $rackData;
751 }
752 if (!$changecnt)
753 return buildRedirectURL (__FUNCTION__, 'OK', $changecnt);
754 // Log a record.
755 $newMolecule = getMoleculeForObject ($object_id);
756 $oc = count ($oldMolecule);
757 $nc = count ($newMolecule);
758 $omid = $oc ? createMolecule ($oldMolecule) : 'NULL';
759 $nmid = $nc ? createMolecule ($newMolecule) : 'NULL';
760 global $remote_username;
761 $comment = empty ($_REQUEST['comment']) ? 'NULL' : "'${_REQUEST['comment']}'";
762 $query =
763 "insert into MountOperation(object_id, old_molecule_id, new_molecule_id, user_name, comment) " .
764 "values (${object_id}, ${omid}, ${nmid}, '${remote_username}', ${comment})";
765 global $dbxlink;
766 $result = $dbxlink->query ($query);
767 if ($result == NULL)
768 $log[] = array ('code' => 500, 'message' => 'SQL query failed during history logging.');
769 else
770 $log[] = array ('code' => 200, 'message' => 'History logged.');
771 return buildWideRedirectURL ($log);
772 }
773
774 $msgcode['updateObject']['OK'] = 16;
775 $msgcode['updateObject']['ERR'] = 121;
776 function updateObject ()
777 {
778 assertUIntArg ('num_attrs', __FUNCTION__, TRUE);
779 assertUIntArg ('object_id', __FUNCTION__);
780 assertUIntArg ('object_type_id', __FUNCTION__);
781 assertStringArg ('object_name', __FUNCTION__, TRUE);
782 assertStringArg ('object_label', __FUNCTION__, TRUE);
783 assertStringArg ('object_barcode', __FUNCTION__, TRUE);
784 assertStringArg ('object_asset_no', __FUNCTION__, TRUE);
785 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
786 $has_problems = 'yes';
787 else
788 $has_problems = 'no';
789
790 if (commitUpdateObject (
791 $_REQUEST['object_id'],
792 $_REQUEST['object_name'],
793 $_REQUEST['object_label'],
794 $_REQUEST['object_barcode'],
795 $_REQUEST['object_type_id'],
796 $has_problems,
797 $_REQUEST['object_asset_no'],
798 $_REQUEST['object_comment']
799 ) !== TRUE)
800 return buildRedirectURL (__FUNCTION__, 'ERR');
801
802 // Update optional attributes
803 $oldvalues = getAttrValues ($_REQUEST['object_id']);
804 $result = array();
805 $num_attrs = isset ($_REQUEST['num_attrs']) ? $_REQUEST['num_attrs'] : 0;
806 for ($i = 0; $i < $num_attrs; $i++)
807 {
808 assertUIntArg ("${i}_attr_id", __FUNCTION__);
809 $attr_id = $_REQUEST["${i}_attr_id"];
810
811 // Field is empty, delete attribute and move on.
812 if (!strlen ($_REQUEST["${i}_value"]))
813 {
814 commitResetAttrValue ($_REQUEST['object_id'], $attr_id);
815 continue;
816 }
817
818 // The value could be uint/float, but we don't know ATM. Let SQL
819 // server check this and complain.
820 assertStringArg ("${i}_value", __FUNCTION__);
821 $value = $_REQUEST["${i}_value"];
822 switch ($oldvalues[$attr_id]['type'])
823 {
824 case 'uint':
825 case 'float':
826 case 'string':
827 $oldvalue = $oldvalues[$attr_id]['value'];
828 break;
829 case 'dict':
830 $oldvalue = $oldvalues[$attr_id]['key'];
831 break;
832 default:
833 showError ('Internal structure error', __FUNCTION__);
834 die;
835 }
836 if ($value === $oldvalue) // ('' == 0), but ('' !== 0)
837 continue;
838
839 // Note if the queries succeed or not, it determines which page they see.
840 $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value);
841 }
842 if (in_array (FALSE, $result))
843 return buildRedirectURL (__FUNCTION__, 'ERR');
844
845 // Invalidate thumb cache of all racks objects could occupy.
846 foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id)
847 resetThumbCache ($rack_id);
848
849 return buildRedirectURL (__FUNCTION__, 'OK');
850 }
851
852
853 function addMultipleObjects()
854 {
855 $log = emptyLog();
856 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
857 $max = getConfigVar ('MASSCOUNT');
858 for ($i = 0; $i < $max; $i++)
859 {
860 if (!isset ($_REQUEST["${i}_object_type_id"]))
861 {
862 $log = mergeLogs ($log, oneLiner (184, array ($i + 1)));
863 break;
864 }
865 assertUIntArg ("${i}_object_type_id", __FUNCTION__, TRUE);
866 assertStringArg ("${i}_object_name", __FUNCTION__, TRUE);
867 assertStringArg ("${i}_object_label", __FUNCTION__, TRUE);
868 assertStringArg ("${i}_object_asset_no", __FUNCTION__, TRUE);
869 assertStringArg ("${i}_object_barcode", __FUNCTION__, TRUE);
870 $name = $_REQUEST["${i}_object_name"];
871
872 // It's better to skip silently, than to print a notice.
873 if ($_REQUEST["${i}_object_type_id"] == 0)
874 continue;
875 if (commitAddObject
876 (
877 $name,
878 $_REQUEST["${i}_object_label"],
879 $_REQUEST["${i}_object_barcode"],
880 $_REQUEST["${i}_object_type_id"],
881 $_REQUEST["${i}_object_asset_no"],
882 $taglist
883 ) === TRUE)
884 $log = mergeLogs ($log, oneLiner (80, array ($name)));
885 else
886 $log = mergeLogs ($log, oneLiner (185, array ($name)));
887 }
888 return buildWideRedirectURL ($log);
889 }
890
891 function addLotOfObjects()
892 {
893 $log = emptyLog();
894 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
895 assertUIntArg ('global_type_id', __FUNCTION__, TRUE);
896 assertStringArg ('namelist', __FUNCTION__, TRUE);
897 $global_type_id = $_REQUEST['global_type_id'];
898 if ($global_type_id == 0 or !strlen ($_REQUEST['namelist']))
899 $log = mergeLogs ($log, oneLiner (186));
900 else
901 {
902 // The name extractor below was stolen from ophandlers.php:addMultiPorts()
903 $names1 = explode ('\n', $_REQUEST['namelist']);
904 $names2 = array();
905 foreach ($names1 as $line)
906 {
907 $parts = explode ('\r', $line);
908 reset ($parts);
909 if (!strlen ($parts[0]))
910 continue;
911 else
912 $names2[] = rtrim ($parts[0]);
913 }
914 foreach ($names2 as $name)
915 if (commitAddObject ($name, '', '', $global_type_id, '', $taglist) === TRUE)
916 $log = mergeLogs ($log, oneLiner (80, array ($name)));
917 else
918 $log = mergeLogs ($log, oneLiner (185, array ($name)));
919 }
920 return buildWideRedirectURL ($log);
921 }
922
923 $msgcode['deleteObject']['OK'] = 76;
924 $msgcode['deleteObject']['ERR'] = 100;
925 function deleteObject ()
926 {
927 assertUIntArg ('object_id', __FUNCTION__);
928 if (NULL === ($oinfo = spotEntity ('object', $_REQUEST['object_id'])))
929 return buildRedirectURL (__FUNCTION__, 'ERR', array ('object not found'));
930
931 $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE);
932 $error = commitDeleteObject ($_REQUEST['object_id']);
933 foreach ($racklist as $rack_id)
934 resetThumbCache ($rack_id);
935
936 if ($error != '')
937 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
938
939 return buildRedirectURL (__FUNCTION__, 'OK', array ($oinfo['dname']));
940 }
941
942 $msgcode['useupPort']['OK'] = 11;
943 $msgcode['useupPort']['ERR'] = 124;
944 function useupPort ()
945 {
946 assertUIntArg ('port_id', __FUNCTION__);
947 if (commitUseupPort ($_REQUEST['port_id']) === TRUE)
948 return buildRedirectURL (__FUNCTION__, 'OK');
949 else
950 return buildRedirectURL (__FUNCTION__, 'ERR');
951 }
952
953 $msgcode['updateUI']['OK'] = 56;
954 $msgcode['updateUI']['ERR'] = 125;
955 function updateUI ()
956 {
957 assertUIntArg ('num_vars', __FUNCTION__);
958
959 for ($i = 0; $i < $_REQUEST['num_vars']; $i++)
960 {
961 assertStringArg ("${i}_varname", __FUNCTION__);
962 assertStringArg ("${i}_varvalue", __FUNCTION__, TRUE);
963 $varname = $_REQUEST["${i}_varname"];
964 $varvalue = $_REQUEST["${i}_varvalue"];
965
966 // If form value = value in DB, don't bother updating DB
967 if ($varvalue === getConfigVar ($varname))
968 continue;
969
970 // Note if the queries succeed or not, it determines which page they see.
971 $error = setConfigVar ($varname, $varvalue, TRUE);
972 if (strlen ($error))
973 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
974 }
975 return buildRedirectURL (__FUNCTION__, 'OK');
976 }
977
978 $msgcode['resetUIConfig']['OK'] = 57;
979 function resetUIConfig()
980 {
981 setConfigVar ('default_port_type','24');
982 setConfigVar ('MASSCOUNT','15');
983 setConfigVar ('MAXSELSIZE','30');
984 setConfigVar ('ROW_SCALE','2');
985 setConfigVar ('PORTS_PER_ROW','12');
986 setConfigVar ('IPV4_ADDRS_PER_PAGE','256');
987 setConfigVar ('DEFAULT_RACK_HEIGHT','42');
988 setConfigVar ('DEFAULT_SLB_VS_PORT','');
989 setConfigVar ('DEFAULT_SLB_RS_PORT','');
990 setConfigVar ('DETECT_URLS','no');
991 setConfigVar ('RACK_PRESELECT_THRESHOLD','1');
992 setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no');
993 setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm');
994 setConfigVar ('SHOW_EXPLICIT_TAGS','yes');
995 setConfigVar ('SHOW_IMPLICIT_TAGS','yes');
996 setConfigVar ('SHOW_AUTOMATIC_TAGS','no');
997 setConfigVar ('DEFAULT_OBJECT_TYPE','4');
998 setConfigVar ('IPV4_AUTO_RELEASE','1');
999 setConfigVar ('SHOW_LAST_TAB', 'no');
1000 setConfigVar ('EXT_IPV4_VIEW', 'yes');
1001 setConfigVar ('TREE_THRESHOLD', '25');
1002 setConfigVar ('IPV4_JAYWALK', 'no');
1003 setConfigVar ('ADDNEW_AT_TOP', 'yes');
1004 setConfigVar ('IPV4_TREE_SHOW_USAGE', 'yes');
1005 setConfigVar ('PREVIEW_TEXT_MAXCHARS', '10240');
1006 setConfigVar ('PREVIEW_TEXT_ROWS', '25');
1007 setConfigVar ('PREVIEW_TEXT_COLS', '80');
1008 setConfigVar ('PREVIEW_IMAGE_MAXPXS', '320');
1009 setConfigVar ('VENDOR_SIEVE', '');
1010 setConfigVar ('IPV4LB_LISTSRC', '{$typeid_4}');
1011 setConfigVar ('IPV4OBJ_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_12} or {$typeid_445} or {$typeid_447}');
1012 setConfigVar ('IPV4NAT_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1013 setConfigVar ('ASSETWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1014 setConfigVar ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1015 setConfigVar ('RACKS_PER_ROW','12');
1016 setConfigVar ('FILTER_PREDICATE_SIEVE','');
1017 setConfigVar ('FILTER_DEFAULT_ANDOR','or');
1018 setConfigVar ('FILTER_SUGGEST_ANDOR','yes');
1019 setConfigVar ('FILTER_SUGGEST_TAGS','yes');
1020 setConfigVar ('FILTER_SUGGEST_PREDICATES','yes');
1021 setConfigVar ('FILTER_SUGGEST_EXTRA','no');
1022 setConfigVar ('DEFAULT_SNMP_COMMUNITY','public');
1023 setConfigVar ('IPV4_ENABLE_KNIGHT','yes');
1024 setConfigVar ('TAGS_TOPLIST_SIZE','50');
1025 setConfigVar ('TAGS_QUICKLIST_SIZE','20');
1026 setConfigVar ('TAGS_QUICKLIST_THRESHOLD','50');
1027 setConfigVar ('ENABLE_MULTIPORT_FORM', 'no');
1028 return buildRedirectURL (__FUNCTION__, 'OK');
1029 }
1030
1031 $msgcode['addRealServer']['OK'] = 34;
1032 $msgcode['addRealServer']['ERR'] = 126;
1033 // Add single record.
1034 function addRealServer ()
1035 {
1036 assertUIntArg ('pool_id', __FUNCTION__);
1037 assertIPv4Arg ('remoteip', __FUNCTION__);
1038 assertStringArg ('rsport', __FUNCTION__, TRUE);
1039 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
1040 if (!addRStoRSPool (
1041 $_REQUEST['pool_id'],
1042 $_REQUEST['remoteip'],
1043 $_REQUEST['rsport'],
1044 getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'),
1045 $_REQUEST['rsconfig']
1046 ))
1047 return buildRedirectURL (__FUNCTION__, 'ERR');
1048 else
1049 return buildRedirectURL (__FUNCTION__, 'OK');
1050 }
1051
1052 $msgcode['addRealServers']['OK'] = 37;
1053 $msgcode['addRealServers']['ERR1'] = 131;
1054 $msgcode['addRealServers']['ERR2'] = 127;
1055 // Parse textarea submitted and try adding a real server for each line.
1056 function addRealServers ()
1057 {
1058 assertUIntArg ('pool_id', __FUNCTION__);
1059 assertStringArg ('format', __FUNCTION__);
1060 assertStringArg ('rawtext', __FUNCTION__);
1061 $rawtext = str_replace ('\r', '', $_REQUEST['rawtext']);
1062 $ngood = $nbad = 0;
1063 $rsconfig = '';
1064 // Keep in mind, that the text will have HTML entities (namely '>') escaped.
1065 foreach (explode ('\n', $rawtext) as $line)
1066 {
1067 if (!strlen ($line))
1068 continue;
1069 $match = array ();
1070 switch ($_REQUEST['format'])
1071 {
1072 case 'ipvs_2': // address and port only
1073 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) /', $line, $match))
1074 continue;
1075 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1076 $ngood++;
1077 else
1078 $nbad++;
1079 break;
1080 case 'ipvs_3': // address, port and weight
1081 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match))
1082 continue;
1083 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3]))
1084 $ngood++;
1085 else
1086 $nbad++;
1087 break;
1088 case 'ssv_2': // IP address and port
1089 if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match))
1090 continue;
1091 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1092 $ngood++;
1093 else
1094 $nbad++;
1095 break;
1096 case 'ssv_1': // IP address
1097 if (!preg_match ('/^([0-9\.]+)$/', $line, $match))
1098 continue;
1099 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1100 $ngood++;
1101 else
1102 $nbad++;
1103 break;
1104 default:
1105 return buildRedirectURL (__FUNCTION__, 'ERR1');
1106 break;
1107 }
1108 }
1109 if ($nbad == 0 and $ngood > 0)
1110 return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood));
1111 else
1112 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($ngood, $nbad));
1113 }
1114
1115 $msgcode['addVService']['OK'] = 28;
1116 $msgcode['addVService']['ERR1'] = 132;
1117 $msgcode['addVService']['ERR2'] = 100;
1118 function addVService ()
1119 {
1120 assertIPv4Arg ('vip', __FUNCTION__);
1121 assertUIntArg ('vport', __FUNCTION__);
1122 assertStringArg ('proto', __FUNCTION__);
1123 if ($_REQUEST['proto'] != 'TCP' and $_REQUEST['proto'] != 'UDP')
1124 return buildRedirectURL (__FUNCTION__, 'ERR1');
1125 assertStringArg ('name', __FUNCTION__, TRUE);
1126 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1127 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
1128 $error = commitCreateVS
1129 (
1130 $_REQUEST['vip'],
1131 $_REQUEST['vport'],
1132 $_REQUEST['proto'],
1133 $_REQUEST['name'],
1134 $_REQUEST['vsconfig'],
1135 $_REQUEST['rsconfig'],
1136 isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array()
1137 );
1138 if ($error != '')
1139 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
1140 else
1141 return buildRedirectURL (__FUNCTION__, 'OK');
1142 }
1143
1144 $msgcode['deleteRealServer']['OK'] = 35;
1145 $msgcode['deleteRealServer']['ERR'] = 128;
1146 function deleteRealServer ()
1147 {
1148 assertUIntArg ('id', __FUNCTION__);
1149 if (!commitDeleteRS ($_REQUEST['id']))
1150 return buildRedirectURL (__FUNCTION__, 'ERR');
1151 else
1152 return buildRedirectURL (__FUNCTION__, 'OK');
1153 }
1154
1155 $msgcode['deleteLoadBalancer']['OK'] = 19;
1156 $msgcode['deleteLoadBalancer']['ERR'] = 129;
1157 function deleteLoadBalancer ()
1158 {
1159 assertUIntArg ('object_id', __FUNCTION__);
1160 assertUIntArg ('pool_id', __FUNCTION__);
1161 assertUIntArg ('vs_id', __FUNCTION__);
1162 if (!commitDeleteLB (
1163 $_REQUEST['object_id'],
1164 $_REQUEST['pool_id'],
1165 $_REQUEST['vs_id']
1166 ))
1167 return buildRedirectURL (__FUNCTION__, 'ERR');
1168 else
1169 return buildRedirectURL (__FUNCTION__, 'OK');
1170 }
1171
1172 $msgcode['deleteVService']['OK'] = 29;
1173 $msgcode['deleteVService']['ERR'] = 130;
1174 function deleteVService ()
1175 {
1176 assertUIntArg ('vs_id', __FUNCTION__);
1177 if (!commitDeleteVS ($_REQUEST['vs_id']))
1178 return buildRedirectURL (__FUNCTION__, 'ERR');
1179 else
1180 return buildRedirectURL (__FUNCTION__, 'OK');
1181 }
1182
1183 $msgcode['updateRealServer']['OK'] = 36;
1184 $msgcode['updateRealServer']['ERR'] = 133;
1185 function updateRealServer ()
1186 {
1187 assertUIntArg ('rs_id', __FUNCTION__);
1188 assertIPv4Arg ('rsip', __FUNCTION__);
1189 assertStringArg ('rsport', __FUNCTION__, TRUE);
1190 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
1191 if (!commitUpdateRS (
1192 $_REQUEST['rs_id'],
1193 $_REQUEST['rsip'],
1194 $_REQUEST['rsport'],
1195 $_REQUEST['rsconfig']
1196 ))
1197 return buildRedirectURL (__FUNCTION__, 'ERR');
1198 else
1199 return buildRedirectURL (__FUNCTION__, 'OK');
1200 }
1201
1202 $msgcode['updateLoadBalancer']['OK'] = 20;
1203 $msgcode['updateLoadBalancer']['ERR'] = 134;
1204 function updateLoadBalancer ()
1205 {
1206 assertUIntArg ('object_id', __FUNCTION__);
1207 assertUIntArg ('pool_id', __FUNCTION__);
1208 assertUIntArg ('vs_id', __FUNCTION__);
1209 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1210 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
1211 if (!commitUpdateLB (
1212 $_REQUEST['object_id'],
1213 $_REQUEST['pool_id'],
1214 $_REQUEST['vs_id'],
1215 $_REQUEST['vsconfig'],
1216 $_REQUEST['rsconfig']
1217 ))
1218 return buildRedirectURL (__FUNCTION__, 'ERR');
1219 else
1220 return buildRedirectURL (__FUNCTION__, 'OK');
1221 }
1222
1223 $msgcode['updateVService']['OK'] = 30;
1224 $msgcode['updateVService']['ERR'] = 135;
1225 function updateVService ()
1226 {
1227 assertUIntArg ('vs_id', __FUNCTION__);
1228 assertIPv4Arg ('vip', __FUNCTION__);
1229 assertUIntArg ('vport', __FUNCTION__);
1230 assertStringArg ('proto', __FUNCTION__);
1231 assertStringArg ('name', __FUNCTION__, TRUE);
1232 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1233 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
1234 if (!commitUpdateVS (
1235 $_REQUEST['vs_id'],
1236 $_REQUEST['vip'],
1237 $_REQUEST['vport'],
1238 $_REQUEST['proto'],
1239 $_REQUEST['name'],
1240 $_REQUEST['vsconfig'],
1241 $_REQUEST['rsconfig']
1242 ))
1243 return buildRedirectURL (__FUNCTION__, 'ERR');
1244 else
1245 return buildRedirectURL (__FUNCTION__, 'OK');
1246 }
1247
1248 $msgcode['addLoadBalancer']['OK'] = 18;
1249 $msgcode['addLoadBalancer']['ERR'] = 137;
1250 function addLoadBalancer ()
1251 {
1252 assertUIntArg ('pool_id', __FUNCTION__);
1253 assertUIntArg ('object_id', __FUNCTION__);
1254 assertUIntArg ('vs_id', __FUNCTION__);
1255 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1256 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
1257 if (!addLBtoRSPool (
1258 $_REQUEST['pool_id'],
1259 $_REQUEST['object_id'],
1260 $_REQUEST['vs_id'],
1261 $_REQUEST['vsconfig'],
1262 $_REQUEST['rsconfig']
1263 ))
1264 return buildRedirectURL (__FUNCTION__, 'ERR');
1265 else
1266 return buildRedirectURL (__FUNCTION__, 'OK');
1267 }
1268
1269 $msgcode['addRSPool']['OK'] = 31;
1270 $msgcode['addRSPool']['ERR'] = 100;
1271 function addRSPool ()
1272 {
1273 assertStringArg ('name', __FUNCTION__, TRUE);
1274 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1275 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
1276 $error = commitCreateRSPool
1277 (
1278 $_REQUEST['name'],
1279 $_REQUEST['vsconfig'],
1280 $_REQUEST['rsconfig'],
1281 isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array()
1282 );
1283 if ($error != '')
1284 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
1285 else
1286 return buildRedirectURL (__FUNCTION__, 'OK');
1287 }
1288
1289 $msgcode['deleteRSPool']['OK'] = 32;
1290 $msgcode['deleteRSPool']['ERR'] = 138;
1291 function deleteRSPool ()
1292 {
1293 assertUIntArg ('pool_id', __FUNCTION__);
1294 if (!commitDeleteRSPool ($_REQUEST['pool_id']))
1295 return buildRedirectURL (__FUNCTION__, 'ERR');
1296 else
1297 return buildRedirectURL (__FUNCTION__, 'OK');
1298 }
1299
1300 $msgcode['updateRSPool']['OK'] = 33;
1301 $msgcode['updateRSPool']['ERR'] = 139;
1302 function updateRSPool ()
1303 {
1304 assertUIntArg ('pool_id', __FUNCTION__);
1305 assertStringArg ('name', __FUNCTION__, TRUE);
1306 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1307 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
1308 if (!commitUpdateRSPool ($_REQUEST['pool_id'], $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
1309 return buildRedirectURL (__FUNCTION__, 'ERR');
1310 else
1311 return buildRedirectURL (__FUNCTION__, 'OK');
1312 }
1313
1314 $msgcode['updateRSInService']['OK'] = 38;
1315 $msgcode['updateRSInService']['ERR'] = 140;
1316 function updateRSInService ()
1317 {
1318 assertUIntArg ('rscount', __FUNCTION__);
1319 $pool_id = $_REQUEST['pool_id'];
1320 $orig = spotEntity ('ipv4rspool', $pool_id);
1321 amplifyCell ($orig);
1322 $nbad = $ngood = 0;
1323 for ($i = 1; $i <= $_REQUEST['rscount']; $i++)
1324 {
1325 $rs_id = $_REQUEST["rsid_${i}"];
1326 if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on')
1327 $newval = 'yes';
1328 else
1329 $newval = 'no';
1330 if ($newval != $orig['rslist'][$rs_id]['inservice'])
1331 {
1332 if (commitSetInService ($rs_id, $newval))
1333 $ngood++;
1334 else
1335 $nbad++;
1336 }
1337 }
1338 if (!$nbad)
1339 return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood));
1340 else
1341 return buildRedirectURL (__FUNCTION__, 'ERR', array ($nbad, $ngood));
1342 }
1343
1344 $msgcode['importPTRData']['OK'] = 26;
1345 $msgcode['importPTRData']['ERR'] = 141;
1346 // FIXME: check, that each submitted address belongs to the prefix we
1347 // are operating on.
1348 function importPTRData ()
1349 {
1350 assertUIntArg ('addrcount', __FUNCTION__);
1351 $nbad = $ngood = 0;
1352 for ($i = 0; $i < $_REQUEST['addrcount']; $i++)
1353 {
1354 $inputname = "import_${i}";
1355 if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on')
1356 continue;
1357 assertIPv4Arg ("addr_${i}", __FUNCTION__);
1358 assertStringArg ("descr_${i}", __FUNCTION__, TRUE);
1359 assertStringArg ("rsvd_${i}", __FUNCTION__);
1360 // Non-existent addresses will not have this argument set in request.
1361 $rsvd = 'no';
1362 if ($_REQUEST["rsvd_${i}"] == 'yes')
1363 $rsvd = 'yes';
1364 if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '')
1365 $ngood++;
1366 else
1367 $nbad++;
1368 }
1369 if (!$nbad)
1370 return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood));
1371 else
1372 return buildRedirectURL (__FUNCTION__, 'ERR', array ($nbad, $ngood));
1373 }
1374
1375 $msgcode['generateAutoPorts']['OK'] = 21;
1376 $msgcode['generateAutoPorts']['ERR'] = 142;
1377 function generateAutoPorts ()
1378 {
1379 global $pageno;
1380 assertUIntArg ('object_id', __FUNCTION__);
1381 $info = spotEntity ('object', $_REQUEST['object_id']);
1382 // Navigate away in case of success, stay at the place otherwise.
1383 if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id']))
1384 return buildRedirectURL (__FUNCTION__, 'OK', array(), $pageno, 'ports');
1385 else
1386 return buildRedirectURL (__FUNCTION__, 'ERR');
1387 }
1388
1389 $msgcode['saveEntityTags']['OK'] = 22;
1390 $msgcode['saveEntityTags']['ERR1'] = 143;
1391 $msgcode['saveEntityTags']['ERR2'] = 187;
1392 // Filter out implicit tags before storing the new tag set.
1393 function saveEntityTags ()
1394 {
1395 global $page, $pageno, $etype_by_pageno;
1396 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1397 return buildRedirectURL (__FUNCTION__, 'ERR2', array (__FUNCTION__));
1398 $realm = $etype_by_pageno[$pageno];
1399 $bypass = $page[$pageno]['bypass'];
1400 assertUIntArg ($bypass, __FUNCTION__);
1401 $entity_id = $_REQUEST[$bypass];
1402 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1403 // Build a chain from the submitted data, minimize it,
1404 // then wipe existing records and store the new set instead.
1405 destroyTagsForEntity ($realm, $entity_id);
1406 // TODO: these actions are very close to what rebuildTagChainForEntity() does,
1407 // so why not use it?
1408 $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist));
1409 $n_succeeds = $n_errors = 0;
1410 foreach ($newchain as $taginfo)
1411 if (addTagForEntity ($realm, $entity_id, $taginfo['id']))
1412 $n_succeeds++;
1413 else
1414 $n_errors++;
1415 if ($n_errors)
1416 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($n_succeeds, $n_errors));
1417 else
1418 return buildRedirectURL (__FUNCTION__, 'OK', array ($n_succeeds));
1419 }
1420
1421 $msgcode['destroyTag']['OK'] = 58;
1422 $msgcode['destroyTag']['ERR1'] = 183;
1423 $msgcode['destroyTag']['ERR2'] = 144;
1424 function destroyTag ()
1425 {
1426 assertUIntArg ('tag_id', __FUNCTION__);
1427 global $taglist;
1428 if (!isset ($taglist[$_REQUEST['tag_id']]))
1429 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($_REQUEST['tag_id']));
1430 if (($ret = commitDestroyTag ($_REQUEST['tag_id'])) == '')
1431 return buildRedirectURL (__FUNCTION__, 'OK', array ($taglist[$_REQUEST['tag_id']]['tag']));
1432 else
1433 return buildRedirectURL (__FUNCTION__, 'ERR2');
1434 }
1435
1436 $msgcode['createTag']['OK'] = 59;
1437 $msgcode['createTag']['ERR1'] = 145;
1438 $msgcode['createTag']['ERR3'] = 147;
1439 function createTag ()
1440 {
1441 assertStringArg ('tag_name', __FUNCTION__);
1442 assertUIntArg ('parent_id', __FUNCTION__, TRUE);
1443 $tagname = trim ($_REQUEST['tag_name']);
1444 if (!validTagName ($tagname))
1445 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($tagname));
1446 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1447 $parent_id = 'NULL';
1448 if (($ret = commitCreateTag ($tagname, $parent_id)) == '')
1449 return buildRedirectURL (__FUNCTION__, 'OK', array ($tagname));
1450 else
1451 return buildRedirectURL (__FUNCTION__, 'ERR3', array ($tagname, $ret));
1452 }
1453
1454 $msgcode['updateTag']['OK'] = 60;
1455 $msgcode['updateTag']['ERR1'] = 145;
1456 $msgcode['updateTag']['ERR2'] = 148;
1457 function updateTag ()
1458 {
1459 assertUIntArg ('tag_id', __FUNCTION__);
1460 assertUIntArg ('parent_id', __FUNCTION__, TRUE);
1461 assertStringArg ('tag_name', __FUNCTION__);
1462 $tagname = trim ($_REQUEST['tag_name']);
1463 if (!validTagName ($tagname))
1464 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($tagname));
1465 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1466 $parent_id = 'NULL';
1467 if (($ret = commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id)) == '')
1468 return buildRedirectURL (__FUNCTION__, 'OK', array ($tagname));
1469 // Use old name in the message, cause update failed.
1470 global $taglist;
1471 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($taglist[$_REQUEST['tag_id']]['tag'], $ret));
1472 }
1473
1474 $msgcode['rollTags']['OK'] = 67;
1475 $msgcode['rollTags']['ERR'] = 149;
1476 function rollTags ()
1477 {
1478 assertUIntArg ('row_id', __FUNCTION__);
1479 assertStringArg ('sum', __FUNCTION__, TRUE);
1480 assertUIntArg ('realsum', __FUNCTION__);
1481 if ($_REQUEST['sum'] != $_REQUEST['realsum'])
1482 return buildRedirectURL (__FUNCTION__, 'ERR');
1483 // Even if the user requested an empty tag list, don't bail out, but process existing
1484 // tag chains with "zero" extra. This will make sure, that the stuff processed will
1485 // have its chains refined to "normal" form.
1486 $extratags = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1487 $n_ok = 0;
1488 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
1489 // filter out the same tag again and again. It will have own noise to cancel.
1490 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
1491 foreach (listCells ('rack', $_REQUEST['row_id']) as $rack)
1492 {
1493 if (rebuildTagChainForEntity ('rack', $rack['id'], $extrachain))
1494 $n_ok++;
1495 amplifyCell ($rack);
1496 foreach ($rack['mountedObjects'] as $object_id)
1497 if (rebuildTagChainForEntity ('object', $object_id, $extrachain))
1498 $n_ok++;
1499 }
1500 return buildRedirectURL (__FUNCTION__, 'OK', array ($n_ok));
1501 }
1502
1503 $msgcode['changeMyPassword']['OK'] = 61;
1504 $msgcode['changeMyPassword']['ERR1'] = 150;
1505 $msgcode['changeMyPassword']['ERR2'] = 151;
1506 $msgcode['changeMyPassword']['ERR3'] = 152;
1507 $msgcode['changeMyPassword']['ERR4'] = 153;
1508 function changeMyPassword ()
1509 {
1510 global $remote_username, $user_auth_src;
1511 if ($user_auth_src != 'database')
1512 return buildRedirectURL (__FUNCTION__, 'ERR1');
1513 assertStringArg ('oldpassword', __FUNCTION__);
1514 assertStringArg ('newpassword1', __FUNCTION__);
1515 assertStringArg ('newpassword2', __FUNCTION__);
1516 $remote_userid = getUserIDByUsername ($remote_username);
1517 $userinfo = spotEntity ('user', $remote_userid);
1518 if ($userinfo['user_password_hash'] != sha1 ($_REQUEST['oldpassword']))
1519 return buildRedirectURL (__FUNCTION__, 'ERR2');
1520 if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2'])
1521 return buildRedirectURL (__FUNCTION__, 'ERR3');
1522 if (commitUpdateUserAccount ($remote_userid, $userinfo['user_name'], $userinfo['user_realname'], sha1 ($_REQUEST['newpassword1'])))
1523 return buildRedirectURL (__FUNCTION__, 'OK');
1524 else
1525 return buildRedirectURL (__FUNCTION__, 'ERR4');
1526 }
1527
1528 $msgcode['saveRackCode']['OK'] = 43;
1529 $msgcode['saveRackCode']['ERR1'] = 154;
1530 $msgcode['saveRackCode']['ERR2'] = 155;
1531 function saveRackCode ()
1532 {
1533 assertStringArg ('rackcode');
1534 // For the test to succeed, unescape LFs, strip CRs.
1535 $newcode = str_replace ('\r', '', str_replace ('\n', "\n", $_REQUEST['rackcode']));
1536 $parseTree = getRackCode ($newcode);
1537 if ($parseTree['result'] != 'ACK')
1538 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($parseTree['load']));
1539 saveScript ('RackCodeCache', '');
1540 if (saveScript ('RackCode', $newcode))
1541 return buildRedirectURL (__FUNCTION__, 'OK');
1542 else
1543 return buildRedirectURL (__FUNCTION__, 'ERR2');
1544 }
1545
1546 $msgcode['setPortVLAN']['ERR1'] = 156;
1547 // This handler's context is pre-built, but not authorized. It is assumed, that the
1548 // handler will take existing context and before each commit check authorization
1549 // on the base chain plus necessary context added.
1550 function setPortVLAN ()
1551 {
1552 assertUIntArg ('portcount', __FUNCTION__);
1553 $data = getSwitchVLANs ($_REQUEST['object_id']);
1554 if ($data === NULL)
1555 return buildRedirectURL (__FUNCTION__, 'ERR1');
1556 list ($vlanlist, $portlist) = $data;
1557 // Here we just build up 1 set command for the gateway with all of the ports
1558 // included. The gateway is expected to filter unnecessary changes silently
1559 // and to provide a list of responses with either error or success message
1560 // for each of the rest.
1561 $nports = $_REQUEST['portcount'];
1562 $prefix = 'set ';
1563 $log = emptyLog();
1564 $setcmd = '';
1565 for ($i = 0; $i < $nports; $i++)
1566 if
1567 (
1568 !isset ($_REQUEST['portname_' . $i]) ||
1569 !isset ($_REQUEST['vlanid_' . $i]) ||
1570 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
1571 )
1572 $log['m'][] = array ('c' => 158, 'a' => array ($i));
1573 elseif
1574 (
1575 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
1576 $portlist[$i]['vlaind'] == 'TRUNK'
1577 )
1578 continue;
1579 else
1580 {
1581 $portname = $_REQUEST['portname_' . $i];
1582 $oldvlanid = $portlist[$i]['vlanid'];
1583 $newvlanid = $_REQUEST['vlanid_' . $i];
1584 // Finish the security context and evaluate it.
1585 $annex = array();
1586 $annex[] = array ('tag' => '$fromvlan_' . $oldvlanid);
1587 $annex[] = array ('tag' => '$tovlan_' . $newvlanid);
1588 if (!permitted (NULL, NULL, NULL, $annex))
1589 {
1590 $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid));
1591 continue;
1592 }
1593 $setcmd .= $prefix . $portname . '=' . $newvlanid;
1594 $prefix = ';';
1595 }
1596 // Feed the gateway and interpret its (non)response.
1597 if ($setcmd != '')
1598 $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd));
1599 else
1600 $log['m'][] = array ('c' => 201);
1601 return buildWideRedirectURL ($log);
1602 }
1603
1604 function submitSLBConfig ()
1605 {
1606 assertUIntArg ('object_id', __FUNCTION__);
1607 $newconfig = buildLVSConfig ($_REQUEST['object_id']);
1608 $msglog = gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8'));
1609 return buildWideRedirectURL ($msglog);
1610 }
1611
1612 $msgcode['addRow']['OK'] = 74;
1613 $msgcode['addRow']['ERR'] = 100;
1614 function addRow ()
1615 {
1616 assertStringArg ('name', __FUNCTION__);
1617
1618 if (commitAddRow ($_REQUEST['name']) === TRUE)
1619 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name']));
1620 else
1621 return buildRedirectURL (__FUNCTION__, 'ERR', array ($_REQUEST['name']));
1622 }
1623
1624 $msgcode['updateRow']['OK'] = 75;
1625 $msgcode['updateRow']['ERR'] = 100;
1626 function updateRow ()
1627 {
1628 assertUIntArg ('row_id', __FUNCTION__);
1629 assertStringArg ('name', __FUNCTION__);
1630
1631 if (TRUE === commitUpdateRow ($_REQUEST['row_id'], $_REQUEST['name']))
1632 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name']));
1633 else
1634 return buildRedirectURL (__FUNCTION__, 'ERR', array ($_REQUEST['name']));
1635 }
1636
1637 $msgcode['deleteRow']['OK'] = 77;
1638 $msgcode['deleteRow']['ERR'] = 100;
1639 function deleteRow ()
1640 {
1641 assertUIntArg ('row_id', __FUNCTION__);
1642 $rowinfo = getRackRowInfo ($_REQUEST['row_id']);
1643
1644 if (TRUE === commitDeleteRow ($_REQUEST['row_id']))
1645 return buildRedirectURL (__FUNCTION__, 'OK', array ($rowinfo['name']));
1646 else
1647 return buildRedirectURL (__FUNCTION__, 'ERR', array ($rowinfo['name']));
1648 }
1649
1650 $msgcode['addRack']['OK'] = 65;
1651 $msgcode['addRack']['ERR1'] = 171;
1652 $msgcode['addRack']['ERR2'] = 172;
1653 function addRack ()
1654 {
1655 assertUIntArg ('row_id', __FUNCTION__);
1656 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1657 if (isset ($_REQUEST['got_data']))
1658 {
1659 assertStringArg ('rack_name', __FUNCTION__);
1660 assertUIntArg ('rack_height1', __FUNCTION__);
1661 assertStringArg ('rack_comment', __FUNCTION__, TRUE);
1662
1663 if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
1664 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name']));
1665 else
1666 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($_REQUEST['rack_name']));
1667 }
1668 elseif (isset ($_REQUEST['got_mdata']))
1669 {
1670 assertUIntArg ('rack_height2', __FUNCTION__);
1671 assertStringArg ('rack_names', __FUNCTION__, TRUE);
1672 $log = emptyLog();
1673 // copy-and-paste from renderAddMultipleObjectsForm()
1674 $names1 = explode ('\n', $_REQUEST['rack_names']);
1675 $names2 = array();
1676 foreach ($names1 as $line)
1677 {
1678 $parts = explode ('\r', $line);
1679 reset ($parts);
1680 if (!strlen ($parts[0]))
1681 continue;
1682 else
1683 $names2[] = rtrim ($parts[0]);
1684 }
1685 global $msgcode;
1686 foreach ($names2 as $cname)
1687 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE)
1688 $log['m'][] = array ('c' => $msgcode[__FUNCTION__]['OK'], 'a' => array ($cname));
1689 else
1690 $log['m'][] = array ('c' => $msgcode[__FUNCTION__]['ERR1'], 'a' => array ($cname));
1691 return buildWideRedirectURL ($log);
1692 }
1693 else
1694 return buildRedirectURL (__FUNCTION__, 'ERR2');
1695 }
1696
1697 $msgcode['deleteRack']['OK'] = 79;
1698 $msgcode['deleteRack']['ERR'] = 100;
1699 $msgcode['deleteRack']['ERR1'] = 206;
1700 function deleteRack ()
1701 {
1702 assertUIntArg ('rack_id', __FUNCTION__);
1703 if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id'])))
1704 return buildRedirectURL (__FUNCTION__, 'ERR', array ('Rack not found'), 'rackspace', 'default');
1705 amplifyCell ($rackData);
1706 if (count ($rackData['mountedObjects']))
1707 return buildRedirectURL (__FUNCTION__, 'ERR1');
1708 if (TRUE !== commitDeleteRack ($_REQUEST['rack_id']))
1709 return buildRedirectURL (__FUNCTION__, 'ERR', array(), 'rackspace', 'default');
1710 return buildRedirectURL (__FUNCTION__, 'OK', array ($rackData['name']), 'rackspace', 'default');
1711 }
1712
1713 $msgcode['updateRack']['OK'] = 68;
1714 $msgcode['updateRack']['ERR'] = 177;
1715 function updateRack ()
1716 {
1717 assertUIntArg ('rack_id', __FUNCTION__);
1718 assertUIntArg ('rack_row_id', __FUNCTION__);
1719 assertUIntArg ('rack_height', __FUNCTION__);
1720 assertStringArg ('rack_name', __FUNCTION__);
1721 assertStringArg ('rack_comment', __FUNCTION__, TRUE);
1722
1723 resetThumbCache ($_REQUEST['rack_id']);
1724 if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
1725 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name']));
1726 else
1727 return buildRedirectURL (__FUNCTION__, 'ERR');
1728 }
1729
1730 $msgcode['updateRackDesign']['ERR'] = 100;
1731 function updateRackDesign ()
1732 {
1733 assertUIntArg ('rack_id', __FUNCTION__);
1734 if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id'])))
1735 return buildRedirectURL (__FUNCTION__, 'ERR', array ('Rack not found'), 'rackspace', 'default');
1736 amplifyCell ($rackData);
1737 applyRackDesignMask($rackData);
1738 markupObjectProblems ($rackData);
1739 $response = processGridForm ($rackData, 'A', 'F');
1740 return buildWideRedirectURL (array($response));
1741 }
1742
1743 $msgcode['updateRackProblems']['ERR'] = 100;
1744 function updateRackProblems ()
1745 {
1746 assertUIntArg ('rack_id', __FUNCTION__);
1747 if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id'])))
1748 return buildRedirectURL (__FUNCTION__, 'ERR', array ('Rack not found'), 'rackspace', 'default');
1749 amplifyCell ($rackData);
1750 applyRackProblemMask($rackData);
1751 markupObjectProblems ($rackData);
1752 $response = processGridForm ($rackData, 'F', 'U');
1753 return buildWideRedirectURL (array($response));
1754 }
1755
1756 function querySNMPData ()
1757 {
1758 assertUIntArg ('object_id', __FUNCTION__);
1759 assertStringArg ('community', __FUNCTION__);
1760 return buildWideRedirectURL (doSNMPmining ($_REQUEST['object_id'], $_REQUEST['community']));
1761 }
1762
1763 $msgcode['addFileWithoutLink']['OK'] = 69;
1764 $msgcode['addFileWithoutLink']['ERR'] = 100;
1765 // File-related functions
1766 function addFileWithoutLink ()
1767 {
1768 assertStringArg ('comment', __FUNCTION__, TRUE);
1769
1770 // Make sure the file can be uploaded
1771 if (get_cfg_var('file_uploads') != 1)
1772 return buildRedirectURL (__FUNCTION__, 'ERR', array ("file uploads not allowed, change 'file_uploads' parameter in php.ini"));
1773
1774 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1775 global $sic;
1776 // commitAddFile() uses prepared statements
1777 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']);
1778 if (isset ($_REQUEST['taglist']))
1779 produceTagsForLastRecord ('file', $_REQUEST['taglist']);
1780
1781 if ($error != '')
1782 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
1783
1784 return buildRedirectURL (__FUNCTION__, 'OK', array ($_FILES['file']['name']));
1785 }
1786
1787 $msgcode['addFileToEntity']['OK'] = 69;
1788 $msgcode['addFileToEntity']['ERR1'] = 187;
1789 $msgcode['addFileToEntity']['ERR2'] = 181;
1790 $msgcode['addFileToEntity']['ERR3'] = 182;
1791 function addFileToEntity ()
1792 {
1793 global $page, $pageno, $etype_by_pageno;
1794 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1795 return buildRedirectURL (__FUNCTION__, 'ERR1', array (__FUNCTION__));
1796 $realm = $etype_by_pageno[$pageno];
1797 $bypass = $page[$pageno]['bypass'];
1798 assertUIntArg ($bypass, __FUNCTION__);
1799 $entity_id = $_REQUEST[$bypass];
1800 assertStringArg ('comment', __FUNCTION__, TRUE);
1801
1802 // Make sure the file can be uploaded
1803 if (get_cfg_var('file_uploads') != 1)
1804 return buildRedirectURL (__FUNCTION__, 'ERR2');
1805
1806 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1807 global $sic;
1808 // commitAddFile() uses prepared statements
1809 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']);
1810 if ($error != '')
1811 return buildRedirectURL (__FUNCTION__, 'ERR3', array ($error));
1812
1813 $error = commitLinkFile (lastInsertID(), $realm, $entity_id);
1814 if ($error != '')
1815 return buildRedirectURL (__FUNCTION__, 'ERR3', array ($error));
1816
1817 return buildRedirectURL (__FUNCTION__, 'OK', array ($_FILES['file']['name']));
1818 }
1819
1820 $msgcode['linkFileToEntity']['OK'] = 71;
1821 $msgcode['linkFileToEntity']['ERR1'] = 178;
1822 $msgcode['linkFileToEntity']['ERR2'] = 100;
1823 function linkFileToEntity ()
1824 {
1825 assertUIntArg ('file_id', __FUNCTION__);
1826 global $page, $pageno, $etype_by_pageno;
1827 $entity_type = $etype_by_pageno[$pageno];
1828 $bypass_name = $page[$pageno]['bypass'];
1829 assertUIntArg ($bypass_name, __FUNCTION__);
1830
1831 $fi = spotEntity ('file', $_REQUEST['file_id']);
1832 if ($fi === NULL)
1833 return buildRedirectURL (__FUNCTION__, 'ERR1'); // file not found
1834 $error = commitLinkFile ($_REQUEST['file_id'], $entity_type, $_REQUEST[$bypass_name]);
1835 if ($error != '')
1836 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error)); // linking failed
1837
1838 return buildRedirectURL (__FUNCTION__, 'OK', array ($fi['name']));
1839 }
1840
1841 $msgcode['replaceFile']['OK'] = 70;
1842 $msgcode['replaceFile']['ERR1'] = 181;
1843 $msgcode['replaceFile']['ERR2'] = 207;
1844 $msgcode['replaceFile']['ERR3'] = 182;
1845 function replaceFile ()
1846 {
1847 global $sic;
1848 assertUIntArg ('file_id', __FUNCTION__);
1849
1850 // Make sure the file can be uploaded
1851 if (get_cfg_var('file_uploads') != 1)
1852 return buildRedirectURL (__FUNCTION__, 'ERR1');
1853 $shortInfo = spotEntity ('file', $sic['file_id']);
1854
1855 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1856 if ($fp === FALSE)
1857 return buildRedirectURL (__FUNCTION__, 'ERR2');
1858 $error = commitReplaceFile ($sic['file_id'], $fp);
1859 if ($error != '')
1860 return buildRedirectURL (__FUNCTION__, 'ERR3', array ($error));
1861
1862 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1863 }
1864
1865 $msgcode['updateFile']['OK'] = 70;
1866 $msgcode['updateFile']['ERR'] = 100;
1867 function updateFile ()
1868 {
1869 assertUIntArg ('file_id', __FUNCTION__);
1870 assertStringArg ('file_name', __FUNCTION__);
1871 assertStringArg ('file_type', __FUNCTION__);
1872 assertStringArg ('file_comment', __FUNCTION__, TRUE);
1873 // prepared statement params below
1874 global $sic;
1875 $error = commitUpdateFile ($sic['file_id'], $sic['file_name'], $sic['file_type'], $sic['file_comment']);
1876 if ($error != '')
1877 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
1878
1879 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name']));
1880 }
1881
1882 $msgcode['unlinkFile']['OK'] = 72;
1883 $msgcode['unlinkFile']['ERR'] = 182;
1884 function unlinkFile ()
1885 {
1886 assertUIntArg ('link_id', __FUNCTION__);
1887 $error = commitUnlinkFile ($_REQUEST['link_id']);
1888
1889 if ($error != '')
1890 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
1891
1892 return buildRedirectURL (__FUNCTION__, 'OK');
1893 }
1894
1895 $msgcode['deleteFile']['OK'] = 73;
1896 $msgcode['deleteFile']['ERR'] = 100;
1897 function deleteFile ()
1898 {
1899 assertUIntArg ('file_id', __FUNCTION__);
1900 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
1901 $error = commitDeleteFile ($_REQUEST['file_id']);
1902
1903 if ($error != '')
1904 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
1905
1906 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1907 }
1908
1909 $msgcode['updateFileText']['OK'] = 78;
1910 $msgcode['updateFileText']['ERR1'] = 179;
1911 $msgcode['updateFileText']['ERR2'] = 180;
1912 function updateFileText ()
1913 {
1914 assertUIntArg ('file_id', __FUNCTION__);
1915 assertStringArg ('mtime_copy', __FUNCTION__);
1916 assertStringArg ('file_text', __FUNCTION__, TRUE); // it's Ok to save empty
1917 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
1918 if ($shortInfo['mtime'] != $_REQUEST['mtime_copy'])
1919 return buildRedirectURL (__FUNCTION__, 'ERR1');
1920 global $sic;
1921 $error = commitReplaceFile ($sic['file_id'], $sic['file_text']);
1922 if ($error == '')
1923 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
1924 return buildRedirectURL (__FUNCTION__, 'ERR2');
1925 }
1926
1927 $msgcode['addPortInterfaceCompat']['OK'] = 48;
1928 $msgcode['addPortInterfaceCompat']['ERR'] = 110;
1929 function addPortInterfaceCompat ()
1930 {
1931 assertUIntArg ('iif_id', __FUNCTION__);
1932 assertUIntArg ('oif_id', __FUNCTION__);
1933 if (commitSupplementPIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
1934 return buildRedirectURL (__FUNCTION__, 'OK');
1935 return buildRedirectURL (__FUNCTION__, 'ERR');
1936 }
1937
1938 $msgcode['delPortInterfaceCompat']['OK'] = 49;
1939 $msgcode['delPortInterfaceCompat']['ERR'] = 111;
1940 function delPortInterfaceCompat ()
1941 {
1942 assertUIntArg ('iif_id', __FUNCTION__);
1943 assertUIntArg ('oif_id', __FUNCTION__);
1944 if (commitReducePIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
1945 return buildRedirectURL (__FUNCTION__, 'OK');
1946 return buildRedirectURL (__FUNCTION__, 'ERR');
1947 }
1948
1949 ?>