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