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