94645dbeba9593b44e039644f2cbb3bbf729e6c5
[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, $log_args = array(), $nextpage = NULL, $nexttab = NULL, $url_args = array())
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], $log_args), $nextpage, $nexttab, $url_args);
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'] = 111;
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 $result = deletePortForwarding
94 (
95 $_REQUEST['object_id'],
96 $_REQUEST['localip'],
97 $_REQUEST['localport'],
98 $_REQUEST['remoteip'],
99 $_REQUEST['remoteport'],
100 $_REQUEST['proto']
101 );
102 buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR');
103 }
104
105 $msgcode['updPortForwarding']['OK'] = 4;
106 $msgcode['updPortForwarding']['ERR'] = 109;
107 function updPortForwarding ()
108 {
109 assertUIntArg ('object_id');
110 assertIPv4Arg ('localip');
111 assertIPv4Arg ('remoteip');
112 assertUIntArg ('localport');
113 assertUIntArg ('remoteport');
114 assertStringArg ('proto');
115 assertStringArg ('description');
116
117 $result = updatePortForwarding
118 (
119 $_REQUEST['object_id'],
120 $_REQUEST['localip'],
121 $_REQUEST['localport'],
122 $_REQUEST['remoteip'],
123 $_REQUEST['remoteport'],
124 $_REQUEST['proto'],
125 $_REQUEST['description']
126 );
127 buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR');
128 }
129
130 $msgcode['addPortForObject']['OK'] = 5;
131 $msgcode['addPortForObject']['ERR1'] = 101;
132 $msgcode['addPortForObject']['ERR2'] = 100;
133 function addPortForObject ()
134 {
135 assertUIntArg ('object_id');
136 assertStringArg ('port_name', TRUE);
137 if (!strlen ($_REQUEST['port_name']))
138 return buildRedirectURL (__FUNCTION__, 'ERR1');
139 $error = commitAddPort
140 (
141 $_REQUEST['object_id'],
142 trim ($_REQUEST['port_name']),
143 $_REQUEST['port_type_id'],
144 trim ($_REQUEST['port_label']),
145 trim ($_REQUEST['port_l2address'])
146 );
147 if ($error != '')
148 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
149 else
150 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name']));
151 }
152
153 $msgcode['editPortForObject']['OK'] = 6;
154 $msgcode['editPortForObject']['ERR1'] = 101;
155 $msgcode['editPortForObject']['ERR2'] = 100;
156 function editPortForObject ()
157 {
158 assertUIntArg ('object_id');
159 assertUIntArg ('port_id');
160 assertUIntArg ('port_type_id');
161 assertStringArg ('reservation_comment', TRUE);
162 // tolerate empty value now to produce custom informative message later
163 assertStringArg ('name', TRUE);
164 if (!strlen ($_REQUEST['name']))
165 return buildRedirectURL (__FUNCTION__, 'ERR1');
166
167 $error = commitUpdatePort ($_REQUEST['object_id'], $_REQUEST['port_id'], $_REQUEST['name'], $_REQUEST['port_type_id'], $_REQUEST['label'], $_REQUEST['l2address'], $_REQUEST['reservation_comment']);
168 if ($error != '')
169 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
170 else
171 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name']));
172 }
173
174 $msgcode['delPortFromObject']['OK'] = 7;
175 $msgcode['delPortFromObject']['ERR'] = 100;
176 function delPortFromObject ()
177 {
178 assertUIntArg ('port_id');
179 $error = delObjectPort ($_REQUEST['port_id']);
180
181 if ($error != '')
182 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
183 else
184 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name']));
185 }
186
187 $msgcode['linkPortForObject']['OK'] = 8;
188 $msgcode['linkPortForObject']['ERR'] = 100;
189 function linkPortForObject ()
190 {
191 assertUIntArg ('port_id');
192 assertUIntArg ('remote_port_id');
193 assertStringArg ('cable', TRUE);
194
195 // FIXME: ensure, that at least one of these ports belongs to the current object
196 $error = linkPorts ($_REQUEST['port_id'], $_REQUEST['remote_port_id'], $_REQUEST['cable']);
197 if ($error != '')
198 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
199 global $sic;
200 $local_port_info = getPortInfo ($sic['port_id']);
201 $remote_port_info = getPortInfo ($sic['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 global $sic;
224 $local_port_info = getPortInfo ($sic['port_id']);
225 $remote_port_info = getPortInfo ($sic['remote_port_id']);
226 $remote_object = spotEntity ('object', $remote_port_info['object_id']);
227 $error = unlinkPort ($_REQUEST['port_id']);
228 if ($error != '')
229 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
230 return buildRedirectURL
231 (
232 __FUNCTION__,
233 'OK',
234 array
235 (
236 $local_port_info['name'],
237 $remote_port_info['name'],
238 $remote_object['dname'],
239 )
240 );
241 }
242
243 $msgcode['addMultiPorts']['OK'] = 10;
244 $msgcode['addMultiPorts']['ERR'] = 123;
245 function addMultiPorts ()
246 {
247 assertStringArg ('format');
248 assertStringArg ('input');
249 assertStringArg ('port_type');
250 assertUIntArg ('object_id');
251 $format = $_REQUEST['format'];
252 $port_type = $_REQUEST['port_type'];
253 $object_id = $_REQUEST['object_id'];
254 // Input lines are escaped, so we have to explode and to chop by 2-char
255 // \n and \r respectively.
256 $lines1 = explode ("\n", $_REQUEST['input']);
257 foreach ($lines1 as $line)
258 {
259 $parts = explode ('\r', $line);
260 reset ($parts);
261 if (!strlen ($parts[0]))
262 continue;
263 else
264 $lines2[] = rtrim ($parts[0]);
265 }
266 $ports = array();
267 foreach ($lines2 as $line)
268 {
269 switch ($format)
270 {
271 case 'fisxii':
272 $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', $line));
273 list ($slot, $port) = explode ('/', $words[0]);
274 $ports[] = array
275 (
276 'name' => "e ${slot}/${port}",
277 'l2address' => $words[8],
278 'label' => "slot ${slot} port ${port}"
279 );
280 break;
281 case 'c3600asy':
282 $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', trim (substr ($line, 3))));
283 /*
284 How Async Lines are Numbered in Cisco 3600 Series Routers
285 http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00801ca70b.shtml
286
287 Understanding 16- and 32-Port Async Network Modules
288 http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00800a93f0.shtml
289 */
290 $async = $words[0];
291 $slot = floor (($async - 1) / 32);
292 $octalgroup = floor (($async - 1 - $slot * 32) / 8);
293 $cable = $async - $slot * 32 - $octalgroup * 8;
294 $og_label[0] = 'async 0-7';
295 $og_label[1] = 'async 8-15';
296 $og_label[2] = 'async 16-23';
297 $og_label[3] = 'async 24-31';
298 $ports[] = array
299 (
300 'name' => "async ${async}",
301 'l2address' => '',
302 'label' => "slot ${slot} " . $og_label[$octalgroup] . " cable ${cable}"
303 );
304 break;
305 case 'fiwg':
306 $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', $line));
307 $ifnumber = $words[0] * 1;
308 $ports[] = array
309 (
310 'name' => "e ${ifnumber}",
311 'l2address' => "${words[8]}",
312 'label' => "${ifnumber}"
313 );
314 break;
315 case 'ssv1':
316 $words = explode (' ', $line);
317 if (!strlen ($words[0]) or !strlen ($words[1]))
318 continue;
319 $ports[] = array
320 (
321 'name' => $words[0],
322 'l2address' => $words[1],
323 'label' => ''
324 );
325 break;
326 default:
327 return buildRedirectURL (__FUNCTION__, 'ERR');
328 break;
329 }
330 }
331 // Create ports, if they don't exist.
332 $added_count = $updated_count = $error_count = 0;
333 foreach ($ports as $port)
334 {
335 $port_ids = getPortIDs ($object_id, $port['name']);
336 if (!count ($port_ids))
337 {
338 $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
339 if ($result == '')
340 $added_count++;
341 else
342 $error_count++;
343 }
344 elseif (count ($port_ids) == 1) // update only single-socket ports
345 {
346 $result = commitUpdatePort ($object_id, $port_ids[0], $port['name'], $port_type, $port['label'], $port['l2address']);
347 if ($result == '')
348 $updated_count++;
349 else
350 $error_count++;
351 }
352 }
353 return buildRedirectURL (__FUNCTION__, 'OK', array ($added_count, $updated_count, $error_count));
354 }
355
356 $msgcode['addBulkPorts']['OK'] = 82;
357 function addBulkPorts ()
358 {
359 assertUIntArg ('object_id');
360 assertStringArg ('port_type_id');
361 assertStringArg ('port_name');
362 assertStringArg ('port_label', TRUE);
363 assertUIntArg ('port_numbering_start', TRUE);
364 assertUIntArg ('port_numbering_count');
365
366 $object_id = $_REQUEST['object_id'];
367 $port_name = $_REQUEST['port_name'];
368 $port_type_id = $_REQUEST['port_type_id'];
369 $port_label = $_REQUEST['port_label'];
370 $port_numbering_start = $_REQUEST['port_numbering_start'];
371 $port_numbering_count = $_REQUEST['port_numbering_count'];
372
373 $added_count = $error_count = 0;
374 if(strrpos($port_name, "%u") === false )
375 $port_name .= '%u';
376 for ($i=0,$c=$port_numbering_start; $i<$port_numbering_count; $i++,$c++)
377 {
378 $result = commitAddPort ($object_id, @sprintf($port_name,$c), $port_type_id, @sprintf($port_label,$c), '');
379 if ($result == '')
380 $added_count++;
381 else
382 $error_count++;
383 }
384 return buildRedirectURL (__FUNCTION__, 'OK', array ($added_count, $error_count));
385 }
386
387 $msgcode['updIPv4Allocation']['OK'] = 12;
388 $msgcode['updIPv4Allocation']['ERR'] = 109;
389 function updIPv4Allocation ()
390 {
391 assertIPv4Arg ('ip');
392 assertUIntArg ('object_id');
393 assertStringArg ('bond_name', TRUE);
394 assertStringArg ('bond_type');
395
396 $result = updateBond ($_REQUEST['ip'], $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
397 return buildRedirectURL (__FUNCTION__, $result === FALSE ? 'ERR' : 'OK');
398 }
399
400 $msgcode['updIPv6Allocation']['OK'] = 12;
401 $msgcode['updIv6PAllocation']['ERR'] = 109;
402 function updIPv6Allocation ()
403 {
404 $ipv6 = assertIPv6Arg ('ip');
405 assertUIntArg ('object_id');
406 assertStringArg ('bond_name', TRUE);
407 assertStringArg ('bond_type');
408
409 $result = updateIPv6Bond ($ipv6, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
410 return buildRedirectURL (__FUNCTION__, $result === FALSE ? 'ERR' : 'OK');
411 }
412
413 $msgcode['delIPv4Allocation']['OK'] = 14;
414 $msgcode['delIPv4Allocation']['ERR'] = 111;
415 function delIPv4Allocation ()
416 {
417 assertIPv4Arg ('ip');
418 assertUIntArg ('object_id');
419
420 $result = unbindIpFromObject ($_REQUEST['ip'], $_REQUEST['object_id']);
421 return buildRedirectURL (__FUNCTION__, $result === FALSE ? 'ERR' : 'OK');
422 }
423
424 $msgcode['delIPv6Allocation']['OK'] = 14;
425 $msgcode['delIPv6Allocation']['ERR'] = 111;
426 function delIPv6Allocation ()
427 {
428 assertUIntArg ('object_id');
429 $ipv6 = assertIPv6Arg ('ip');
430 $result = unbindIPv6FromObject ($ipv6, $_REQUEST['object_id']);
431 return buildRedirectURL (__FUNCTION__, $result === FALSE ? 'ERR' : 'OK');
432 }
433
434 $msgcode['addIPv4Allocation']['OK'] = 13;
435 $msgcode['addIPv4Allocation']['ERR1'] = 170;
436 $msgcode['addIPv4Allocation']['ERR2'] = 100;
437 function addIPv4Allocation ()
438 {
439 assertIPv4Arg ('ip');
440 assertUIntArg ('object_id');
441 assertStringArg ('bond_name', TRUE);
442 assertStringArg ('bond_type');
443
444 // Strip masklen.
445 $ip = preg_replace ('@/[[:digit:]]+$@', '', $_REQUEST['ip']);
446 if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv4AddressNetworkId ($ip))
447 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($ip));
448
449 if (FALSE === bindIpToObject ($ip, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']))
450 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
451 $address = getIPv4Address ($ip);
452 if ($address['reserved'] == 'yes' or strlen ($address['name']))
453 {
454 $release = getConfigVar ('IPV4_AUTO_RELEASE');
455 if ($release >= 1)
456 $address['reserved'] = 'no';
457 if ($release >= 2)
458 $address['name'] = '';
459 updateAddress ($ip, $address['name'], $address['reserved']);
460 }
461 return buildRedirectURL (__FUNCTION__, 'OK');
462 }
463
464 $msgcode['addIPv6Allocation']['OK'] = 13;
465 $msgcode['addIPv6Allocation']['ERR1'] = 170;
466 $msgcode['addIPv6Allocation']['ERR2'] = 100;
467 function addIPv6Allocation ()
468 {
469 assertUIntArg ('object_id');
470 assertStringArg ('bond_name', TRUE);
471 assertStringArg ('bond_type');
472
473 // Strip masklen.
474 $ipv6 = new IPv6Address;
475 if (! $ipv6->parse (preg_replace ('@/\d+$@', '', $_REQUEST['ip'])))
476 throw new InvalidRequestArgException('ip', $_REQUEST['ip'], 'parameter is not a valid ipv6 address');
477
478 if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv6AddressNetworkId ($ipv6))
479 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($ip));
480
481 if (FALSE === bindIPv6ToObject ($ipv6, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']))
482 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
483 $address = getIPv6Address ($ipv6);
484 if ($address['reserved'] == 'yes' or strlen ($address['name']))
485 {
486 $release = getConfigVar ('IPV4_AUTO_RELEASE');
487 if ($release >= 1)
488 $address['reserved'] = 'no';
489 if ($release >= 2)
490 $address['name'] = '';
491 updateAddress ($ipv6, $address['name'], $address['reserved']);
492 }
493 return buildRedirectURL (__FUNCTION__, 'OK');
494 }
495
496 $msgcode['addIPv4Prefix']['OK'] = 23;
497 $msgcode['addIPv4Prefix']['ERR'] = 100;
498 $msgcode['addIPv4Prefix']['ERR1'] = 173;
499 $msgcode['addIPv4Prefix']['ERR2'] = 174;
500 $msgcode['addIPv4Prefix']['ERR3'] = 175;
501 $msgcode['addIPv4Prefix']['ERR4'] = 176;
502 function addIPv4Prefix ()
503 {
504 assertStringArg ('range');
505 assertStringArg ('name', TRUE);
506
507 $is_bcast = isset ($_REQUEST['is_bcast']) ? $_REQUEST['is_bcast'] : 'off';
508 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
509 global $sic;
510 $error = createIPv4Prefix ($_REQUEST['range'], $sic['name'], $is_bcast == 'on', $taglist);
511 if ($error != '')
512 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
513 else
514 return buildRedirectURL (__FUNCTION__, 'OK');
515 }
516
517 $msgcode['addIPv6Prefix']['OK'] = 86;
518 $msgcode['addIPv6Prefix']['ERR'] = 100;
519 $msgcode['addIPv6Prefix']['ERR1'] = 173;
520 $msgcode['addIPv6Prefix']['ERR2'] = 174;
521 $msgcode['addIPv6Prefix']['ERR3'] = 175;
522 $msgcode['addIPv6Prefix']['ERR4'] = 176;
523 function addIPv6Prefix ()
524 {
525 assertStringArg ('range');
526 assertStringArg ('name', TRUE);
527
528 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
529 global $sic;
530 $error = createIPv6Prefix ($_REQUEST['range'], $sic['name'], $taglist);
531 if ($error != '')
532 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
533 else
534 return buildRedirectURL (__FUNCTION__, 'OK');
535 }
536
537 $msgcode['delIPv4Prefix']['OK'] = 24;
538 $msgcode['delIPv4Prefix']['ERR'] = 100;
539 function delIPv4Prefix ()
540 {
541 assertUIntArg ('id');
542 $error = destroyIPv4Prefix ($_REQUEST['id']);
543 if ($error != '')
544 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
545 else
546 return buildRedirectURL (__FUNCTION__, 'OK');
547 }
548
549 $msgcode['delIPv6Prefix']['OK'] = 85;
550 $msgcode['delIPv6Prefix']['ERR'] = 100;
551 function delIPv6Prefix ()
552 {
553 assertUIntArg ('id');
554 $error = destroyIPv6Prefix ($_REQUEST['id']);
555 if ($error != '')
556 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
557 else
558 return buildRedirectURL (__FUNCTION__, 'OK');
559 }
560
561 $msgcode['updIPv4Prefix']['OK'] = 25;
562 $msgcode['updIPv4Prefix']['ERR'] = 109;
563 function updIPv4Prefix ()
564 {
565 assertUIntArg ('id');
566 assertStringArg ('name', TRUE);
567 assertStringArg ('comment', TRUE);
568 global $sic;
569 $result = updateIPv4Network_real ($sic['id'], $sic['name'], $sic['comment']);
570 return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR');
571 }
572
573 $msgcode['updIPv6Prefix']['OK'] = 86;
574 $msgcode['updIPv6Prefix']['ERR'] = 109;
575 function updIPv6Prefix ()
576 {
577 assertUIntArg ('id');
578 assertStringArg ('name', TRUE);
579 assertStringArg ('comment', TRUE);
580 global $sic;
581 $result = updateIPv6Network_real ($sic['id'], $sic['name'], $sic['comment']);
582 return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR');
583 }
584
585 $msgcode['editAddress']['OK'] = 27;
586 $msgcode['editAddress']['ERR'] = 100;
587 function editAddress ()
588 {
589 assertIPv4Arg ('ip');
590 assertStringArg ('name', TRUE);
591
592 if (isset ($_REQUEST['reserved']))
593 $reserved = $_REQUEST['reserved'];
594 else
595 $reserved = 'off';
596 $error = updateAddress ($_REQUEST['ip'], $_REQUEST['name'], $reserved == 'on' ? 'yes' : 'no');
597 if ($error != '')
598 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
599 else
600 return buildRedirectURL (__FUNCTION__, 'OK');
601 }
602
603 $msgcode['editv6Address']['OK'] = 27;
604 $msgcode['editv6Address']['ERR'] = 100;
605 function editv6Address ()
606 {
607 $ipv6 = assertIPArg ('ip');
608 assertStringArg ('name', TRUE);
609
610 if (isset ($_REQUEST['reserved']))
611 $reserved = $_REQUEST['reserved'];
612 else
613 $reserved = 'off';
614 $error = updateAddress ($ipv6, $_REQUEST['name'], $reserved == 'on' ? 'yes' : 'no');
615 if ($error != '')
616 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
617 else
618 return buildRedirectURL (__FUNCTION__, 'OK');
619 }
620
621 $msgcode['createUser']['OK'] = 40;
622 $msgcode['createUser']['ERR'] = 102;
623 function createUser ()
624 {
625 assertStringArg ('username');
626 assertStringArg ('realname', TRUE);
627 assertStringArg ('password');
628 $username = $_REQUEST['username'];
629 $password = sha1 ($_REQUEST['password']);
630 $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password);
631 if ($result != TRUE)
632 return buildRedirectURL (__FUNCTION__, 'ERR', array ($username));
633 if (isset ($_REQUEST['taglist']))
634 produceTagsForLastRecord ('user', $_REQUEST['taglist']);
635 return buildRedirectURL (__FUNCTION__, 'OK', array ($username));
636 }
637
638 $msgcode['updateUser']['OK'] = 39;
639 $msgcode['updateUser']['ERR1'] = 103;
640 $msgcode['updateUser']['ERR1'] = 104;
641 function updateUser ()
642 {
643 assertUIntArg ('user_id');
644 assertStringArg ('username');
645 assertStringArg ('realname', TRUE);
646 assertStringArg ('password');
647 $username = $_REQUEST['username'];
648 $new_password = $_REQUEST['password'];
649 if (NULL == ($userinfo = spotEntity ('user', $_REQUEST['user_id'])))
650 return buildRedirectURL (__FUNCTION__, 'ERR1');
651 // Update user password only if provided password is not the same as current password hash.
652 if ($new_password != $userinfo['user_password_hash'])
653 $new_password = sha1 ($new_password);
654 $result = commitUpdateUserAccount ($_REQUEST['user_id'], $username, $_REQUEST['realname'], $new_password);
655 if ($result !== FALSE)
656 return buildRedirectURL (__FUNCTION__, 'OK', array ($username));
657 else
658 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($username));
659 }
660
661 $msgcode['updateDictionary']['OK'] = 51;
662 $msgcode['updateDictionary']['ERR'] = 109;
663 function updateDictionary ()
664 {
665 assertUIntArg ('chapter_no');
666 assertUIntArg ('dict_key');
667 assertStringArg ('dict_value');
668 if (FALSE !== commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value']))
669 return buildRedirectURL (__FUNCTION__, 'OK');
670 else
671 return buildRedirectURL (__FUNCTION__, 'ERR');
672 }
673
674 $msgcode['supplementDictionary']['OK'] = 52;
675 $msgcode['supplementDictionary']['ERR'] = 110;
676 function supplementDictionary ()
677 {
678 assertUIntArg ('chapter_no');
679 assertStringArg ('dict_value');
680 if (commitSupplementDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_value']) === TRUE)
681 return buildRedirectURL (__FUNCTION__, 'OK');
682 else
683 return buildRedirectURL (__FUNCTION__, 'ERR');
684 }
685
686 $msgcode['reduceDictionary']['OK'] = 50;
687 $msgcode['reduceDictionary']['ERR'] = 111;
688 function reduceDictionary ()
689 {
690 assertUIntArg ('chapter_no');
691 assertUIntArg ('dict_key');
692 if (commitReduceDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key']) === TRUE)
693 return buildRedirectURL (__FUNCTION__, 'OK');
694 else
695 return buildRedirectURL (__FUNCTION__, 'ERR');
696 }
697
698 $msgcode['updateChapter']['OK'] = 54;
699 $msgcode['updateChapter']['ERR'] = 113;
700 function updateChapter ()
701 {
702 assertUIntArg ('chapter_no');
703 assertStringArg ('chapter_name');
704 if (FALSE !== commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name']))
705 return buildRedirectURL (__FUNCTION__, 'OK');
706 else
707 return buildRedirectURL (__FUNCTION__, 'ERR');
708 }
709
710 $msgcode['delChapter']['OK'] = 53;
711 $msgcode['delChapter']['ERR'] = 114;
712 function delChapter ()
713 {
714 assertUIntArg ('chapter_no');
715 if (commitDeleteChapter ($_REQUEST['chapter_no']))
716 return buildRedirectURL (__FUNCTION__, 'OK');
717 else
718 return buildRedirectURL (__FUNCTION__, 'ERR');
719 }
720
721 $msgcode['changeAttribute']['OK'] = 46;
722 $msgcode['changeAttribute']['ERR'] = 115;
723 function changeAttribute ()
724 {
725 assertUIntArg ('attr_id');
726 assertStringArg ('attr_name');
727 if (FALSE !== commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name']))
728 return buildRedirectURL (__FUNCTION__, 'OK');
729 else
730 return buildRedirectURL (__FUNCTION__, 'ERR');
731 }
732
733 $msgcode['createAttribute']['OK'] = 45;
734 $msgcode['createAttribute']['ERR'] = 116;
735 function createAttribute ()
736 {
737 assertStringArg ('attr_name');
738 assertStringArg ('attr_type');
739 if (commitAddAttribute ($_REQUEST['attr_name'], $_REQUEST['attr_type']))
740 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['attr_name']));
741 else
742 return buildRedirectURL (__FUNCTION__, 'ERR');
743 }
744
745 $msgcode['deleteAttribute']['OK'] = 47;
746 $msgcode['deleteAttribute']['ERR'] = 117;
747 function deleteAttribute ()
748 {
749 assertUIntArg ('attr_id');
750 if (commitDeleteAttribute ($_REQUEST['attr_id']))
751 return buildRedirectURL (__FUNCTION__, 'OK');
752 else
753 return buildRedirectURL (__FUNCTION__, 'ERR');
754 }
755
756 $msgcode['supplementAttrMap']['OK'] = 48;
757 $msgcode['supplementAttrMap']['ERR1'] = 154;
758 $msgcode['supplementAttrMap']['ERR2'] = 118;
759 function supplementAttrMap ()
760 {
761 assertUIntArg ('attr_id');
762 assertUIntArg ('objtype_id');
763 $attrMap = getAttrMap();
764 if ($attrMap[$_REQUEST['attr_id']]['type'] != 'dict')
765 $chapter_id = NULL;
766 else
767 {
768 try
769 {
770 assertUIntArg ('chapter_no');
771 }
772 catch (InvalidRequestArgException $e)
773 {
774 return buildRedirectURL (__FUNCTION__, 'ERR1', array ('chapter not selected'));
775 }
776 $chapter_id = $_REQUEST['chapter_no'];
777 }
778 if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $chapter_id) !== FALSE)
779 return buildRedirectURL (__FUNCTION__, 'OK');
780 else
781 return buildRedirectURL (__FUNCTION__, 'ERR2');
782 }
783
784 $msgcode['reduceAttrMap']['OK'] = 49;
785 $msgcode['reduceAttrMap']['ERR'] = 119;
786 function reduceAttrMap ()
787 {
788 assertUIntArg ('attr_id');
789 assertUIntArg ('objtype_id');
790 if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) !== FALSE)
791 return buildRedirectURL (__FUNCTION__, 'OK');
792 else
793 return buildRedirectURL (__FUNCTION__, 'ERR');
794 }
795
796 $msgcode['clearSticker']['OK'] = 15;
797 $msgcode['clearSticker']['ERR'] = 120;
798 function clearSticker ()
799 {
800 assertUIntArg ('attr_id');
801 assertUIntArg ('object_id');
802 if (commitResetAttrValue ($_REQUEST['object_id'], $_REQUEST['attr_id']) !== FALSE)
803 return buildRedirectURL (__FUNCTION__, 'OK');
804 else
805 return buildRedirectURL (__FUNCTION__, 'ERR');
806 }
807
808 $msgcode['updateObjectAllocation']['OK'] = 63;
809 function updateObjectAllocation ()
810 {
811 assertUIntArg ('object_id');
812
813 if (!isset ($_REQUEST['got_atoms']))
814 {
815 unset($_GET['page']);
816 unset($_GET['tab']);
817 unset($_GET['op']);
818 unset($_POST['page']);
819 unset($_POST['tab']);
820 unset($_POST['op']);
821 return buildWideRedirectURL (array(), NULL, NULL, array_merge ($_GET, $_POST));
822 }
823 $object_id = $_REQUEST['object_id'];
824 $workingRacksData = array();
825 foreach ($_REQUEST['rackmulti'] as $cand_id)
826 {
827 if (!isset ($workingRacksData[$cand_id]))
828 {
829 $rackData = spotEntity ('rack', $cand_id);
830 amplifyCell ($rackData);
831 $workingRacksData[$cand_id] = $rackData;
832 }
833 }
834
835 foreach ($workingRacksData as &$rd)
836 applyObjectMountMask ($rd, $object_id);
837
838 $oldMolecule = getMoleculeForObject ($object_id);
839 $changecnt = 0;
840 $log = array();
841 foreach ($workingRacksData as $rack_id => $rackData)
842 {
843 $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
844 $log[] = $logrecord;
845 if ($logrecord['code'] == 300)
846 continue;
847 $changecnt++;
848 // Reload our working copy after form processing.
849 $rackData = spotEntity ('rack', $cand_id);
850 amplifyCell ($rackData);
851 applyObjectMountMask ($rackData, $object_id);
852 $workingRacksData[$rack_id] = $rackData;
853 }
854 if (!$changecnt)
855 return buildRedirectURL (__FUNCTION__, 'OK', $changecnt);
856 // Log a record.
857 $newMolecule = getMoleculeForObject ($object_id);
858 $oc = count ($oldMolecule);
859 $nc = count ($newMolecule);
860 $omid = $oc ? createMolecule ($oldMolecule) : 'NULL';
861 $nmid = $nc ? createMolecule ($newMolecule) : 'NULL';
862 global $remote_username;
863 $comment = empty ($_REQUEST['comment']) ? 'NULL' : "'${_REQUEST['comment']}'";
864 $query =
865 "insert into MountOperation(object_id, old_molecule_id, new_molecule_id, user_name, comment) " .
866 "values (${object_id}, ${omid}, ${nmid}, '${remote_username}', ${comment})";
867 global $dbxlink;
868 $result = $dbxlink->query ($query);
869 if ($result == NULL)
870 $log[] = array ('code' => 500, 'message' => 'SQL query failed during history logging.');
871 else
872 $log[] = array ('code' => 200, 'message' => 'History logged.');
873 return buildWideRedirectURL ($log);
874 }
875
876 $msgcode['updateObject']['OK'] = 16;
877 $msgcode['updateObject']['ERR'] = 121;
878 function updateObject ()
879 {
880 assertUIntArg ('num_attrs', TRUE);
881 assertUIntArg ('object_id');
882 assertUIntArg ('object_type_id');
883 assertStringArg ('object_name', TRUE);
884 assertStringArg ('object_label', TRUE);
885 assertStringArg ('object_barcode', TRUE);
886 assertStringArg ('object_asset_no', TRUE);
887 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
888 $has_problems = 'yes';
889 else
890 $has_problems = 'no';
891
892 if (commitUpdateObject (
893 $_REQUEST['object_id'],
894 $_REQUEST['object_name'],
895 $_REQUEST['object_label'],
896 $_REQUEST['object_barcode'],
897 $_REQUEST['object_type_id'],
898 $has_problems,
899 $_REQUEST['object_asset_no'],
900 $_REQUEST['object_comment']
901 ) !== TRUE)
902 return buildRedirectURL (__FUNCTION__, 'ERR');
903
904 // Update optional attributes
905 $oldvalues = getAttrValues ($_REQUEST['object_id']);
906 $result = array();
907 $num_attrs = isset ($_REQUEST['num_attrs']) ? $_REQUEST['num_attrs'] : 0;
908 for ($i = 0; $i < $num_attrs; $i++)
909 {
910 assertUIntArg ("${i}_attr_id");
911 $attr_id = $_REQUEST["${i}_attr_id"];
912
913 // Field is empty, delete attribute and move on. OR if the field type is a dictionary and it is the --NOT SET-- value of 0
914 if (!strlen ($_REQUEST["${i}_value"]) || ($oldvalues[$attr_id]['type']=='dict' && $_REQUEST["${i}_value"] == 0))
915 {
916 commitResetAttrValue ($_REQUEST['object_id'], $attr_id);
917 continue;
918 }
919
920 // The value could be uint/float, but we don't know ATM. Let SQL
921 // server check this and complain.
922 assertStringArg ("${i}_value");
923 $value = $_REQUEST["${i}_value"];
924 switch ($oldvalues[$attr_id]['type'])
925 {
926 case 'uint':
927 case 'float':
928 case 'string':
929 $oldvalue = $oldvalues[$attr_id]['value'];
930 break;
931 case 'dict':
932 $oldvalue = $oldvalues[$attr_id]['key'];
933 break;
934 default:
935 }
936 if ($value === $oldvalue) // ('' == 0), but ('' !== 0)
937 continue;
938
939 // Note if the queries succeed or not, it determines which page they see.
940 $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value);
941 }
942 if (in_array (FALSE, $result))
943 return buildRedirectURL (__FUNCTION__, 'ERR');
944
945 // Invalidate thumb cache of all racks objects could occupy.
946 foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id)
947 resetThumbCache ($rack_id);
948
949 return buildRedirectURL (__FUNCTION__, 'OK');
950 }
951
952
953 function addMultipleObjects()
954 {
955 $log = emptyLog();
956 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
957 $max = getConfigVar ('MASSCOUNT');
958 for ($i = 0; $i < $max; $i++)
959 {
960 if (!isset ($_REQUEST["${i}_object_type_id"]))
961 {
962 $log = mergeLogs ($log, oneLiner (184, array ($i + 1)));
963 break;
964 }
965 assertUIntArg ("${i}_object_type_id", TRUE);
966 assertStringArg ("${i}_object_name", TRUE);
967 assertStringArg ("${i}_object_label", TRUE);
968 assertStringArg ("${i}_object_asset_no", TRUE);
969 assertStringArg ("${i}_object_barcode", TRUE);
970 $name = $_REQUEST["${i}_object_name"];
971
972 // It's better to skip silently, than to print a notice.
973 if ($_REQUEST["${i}_object_type_id"] == 0)
974 continue;
975 if (($object_id = commitAddObject
976 (
977 $name,
978 $_REQUEST["${i}_object_label"],
979 $_REQUEST["${i}_object_barcode"],
980 $_REQUEST["${i}_object_type_id"],
981 $_REQUEST["${i}_object_asset_no"],
982 $taglist
983 )) !== FALSE){
984 $info = spotEntity ('object', $object_id);
985 // FIXME: employ amplifyCell() instead of calling loader functions directly
986 amplifyCell ($info);
987 $log = mergeLogs ($log, oneLiner (80, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>')));
988 }else{
989 $log = mergeLogs ($log, oneLiner (185, array ($name)));
990 }
991 }
992 return buildWideRedirectURL ($log);
993 }
994
995 function addLotOfObjects()
996 {
997 $log = emptyLog();
998 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
999 assertUIntArg ('global_type_id', TRUE);
1000 assertStringArg ('namelist', TRUE);
1001 $global_type_id = $_REQUEST['global_type_id'];
1002 if ($global_type_id == 0 or !strlen ($_REQUEST['namelist']))
1003 $log = mergeLogs ($log, oneLiner (186));
1004 else
1005 {
1006 // The name extractor below was stolen from ophandlers.php:addMultiPorts()
1007 $names1 = explode ("\n", $_REQUEST['namelist']);
1008 $names2 = array();
1009 foreach ($names1 as $line)
1010 {
1011 $parts = explode ('\r', $line);
1012 reset ($parts);
1013 if (!strlen ($parts[0]))
1014 continue;
1015 else
1016 $names2[] = rtrim ($parts[0]);
1017 }
1018 foreach ($names2 as $name)
1019 if (($object_id = commitAddObject ($name, '', '', $global_type_id, '', $taglist)) !== FALSE)
1020 {
1021 $info = spotEntity ('object', $object_id);
1022 amplifyCell ($info);
1023 $log = mergeLogs ($log, oneLiner (80, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>')));
1024 }
1025 else
1026 $log = mergeLogs ($log, oneLiner (185, array ($name)));
1027 }
1028 return buildWideRedirectURL ($log);
1029 }
1030
1031 $msgcode['deleteObject']['OK'] = 76;
1032 function deleteObject ()
1033 {
1034 assertUIntArg ('object_id');
1035 $oinfo = spotEntity ('object', $_REQUEST['object_id']);
1036
1037 $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE);
1038 commitDeleteObject ($_REQUEST['object_id']);
1039 foreach ($racklist as $rack_id)
1040 resetThumbCache ($rack_id);
1041 return buildRedirectURL (__FUNCTION__, 'OK', array ($oinfo['dname']));
1042 }
1043
1044 $msgcode['resetObject']['OK'] = 83;
1045 $msgcode['resetObject']['ERR'] = 100;
1046 function resetObject ()
1047 {
1048 assertUIntArg ('object_id');
1049 $oinfo = spotEntity ('object', $_REQUEST['object_id']);
1050
1051 $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE);
1052 commitResetObject ($_REQUEST['object_id']);
1053 foreach ($racklist as $rack_id)
1054 resetThumbCache ($rack_id);
1055 return buildRedirectURL (__FUNCTION__, 'OK', array ($oinfo['dname']));
1056 }
1057
1058 $msgcode['useupPort']['OK'] = 11;
1059 $msgcode['useupPort']['ERR'] = 124;
1060 function useupPort ()
1061 {
1062 assertUIntArg ('port_id');
1063 if (FALSE !== commitUseupPort ($_REQUEST['port_id']))
1064 return buildRedirectURL (__FUNCTION__, 'OK');
1065 else
1066 return buildRedirectURL (__FUNCTION__, 'ERR');
1067 }
1068
1069 $msgcode['updateUI']['OK'] = 56;
1070 function updateUI ()
1071 {
1072 assertUIntArg ('num_vars');
1073
1074 for ($i = 0; $i < $_REQUEST['num_vars']; $i++)
1075 {
1076 assertStringArg ("${i}_varname");
1077 assertStringArg ("${i}_varvalue", TRUE);
1078 $varname = $_REQUEST["${i}_varname"];
1079 $varvalue = $_REQUEST["${i}_varvalue"];
1080
1081 // If form value = value in DB, don't bother updating DB
1082 if (!isConfigVarChanged($varname, $varvalue))
1083 continue;
1084 // any exceptions will be handled by process.php
1085 setConfigVar ($varname, $varvalue, TRUE);
1086 }
1087 return buildRedirectURL (__FUNCTION__, 'OK');
1088 }
1089
1090 $msgcode['saveMyPreferences']['OK'] = 56;
1091 function saveMyPreferences ()
1092 {
1093 assertUIntArg ('num_vars');
1094
1095 for ($i = 0; $i < $_REQUEST['num_vars']; $i++)
1096 {
1097 assertStringArg ("${i}_varname");
1098 assertStringArg ("${i}_varvalue", TRUE);
1099 $varname = $_REQUEST["${i}_varname"];
1100 $varvalue = $_REQUEST["${i}_varvalue"];
1101
1102 // If form value = value in DB, don't bother updating DB
1103 if (!isConfigVarChanged($varname, $varvalue))
1104 continue;
1105 setUserConfigVar ($varname, $varvalue);
1106 }
1107 return buildRedirectURL (__FUNCTION__, 'OK');
1108 }
1109
1110 $msgcode['resetMyPreference']['OK'] = 56;
1111 function resetMyPreference ()
1112 {
1113 assertStringArg ("varname");
1114 resetUserConfigVar ($_REQUEST["varname"]);
1115 return buildRedirectURL (__FUNCTION__, 'OK');
1116 }
1117
1118 $msgcode['resetUIConfig']['OK'] = 57;
1119 function resetUIConfig()
1120 {
1121 setConfigVar ('MASSCOUNT','15');
1122 setConfigVar ('MAXSELSIZE','30');
1123 setConfigVar ('ROW_SCALE','2');
1124 setConfigVar ('PORTS_PER_ROW','12');
1125 setConfigVar ('IPV4_ADDRS_PER_PAGE','256');
1126 setConfigVar ('DEFAULT_RACK_HEIGHT','42');
1127 setConfigVar ('DEFAULT_SLB_VS_PORT','');
1128 setConfigVar ('DEFAULT_SLB_RS_PORT','');
1129 setConfigVar ('DETECT_URLS','no');
1130 setConfigVar ('RACK_PRESELECT_THRESHOLD','1');
1131 setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no');
1132 setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm');
1133 setConfigVar ('SHOW_EXPLICIT_TAGS','yes');
1134 setConfigVar ('SHOW_IMPLICIT_TAGS','yes');
1135 setConfigVar ('SHOW_AUTOMATIC_TAGS','no');
1136 setConfigVar ('DEFAULT_OBJECT_TYPE','4');
1137 setConfigVar ('IPV4_AUTO_RELEASE','1');
1138 setConfigVar ('SHOW_LAST_TAB', 'no');
1139 setConfigVar ('EXT_IPV4_VIEW', 'yes');
1140 setConfigVar ('TREE_THRESHOLD', '25');
1141 setConfigVar ('IPV4_JAYWALK', 'no');
1142 setConfigVar ('ADDNEW_AT_TOP', 'yes');
1143 setConfigVar ('IPV4_TREE_SHOW_USAGE', 'yes');
1144 setConfigVar ('PREVIEW_TEXT_MAXCHARS', '10240');
1145 setConfigVar ('PREVIEW_TEXT_ROWS', '25');
1146 setConfigVar ('PREVIEW_TEXT_COLS', '80');
1147 setConfigVar ('PREVIEW_IMAGE_MAXPXS', '320');
1148 setConfigVar ('VENDOR_SIEVE', '');
1149 setConfigVar ('IPV4LB_LISTSRC', '{$typeid_4}');
1150 setConfigVar ('IPV4OBJ_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_12} or {$typeid_445} or {$typeid_447} or {$typeid_798}');
1151 setConfigVar ('IPV4NAT_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_798}');
1152 setConfigVar ('ASSETWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1153 setConfigVar ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1154 setConfigVar ('RACKS_PER_ROW','12');
1155 setConfigVar ('FILTER_PREDICATE_SIEVE','');
1156 setConfigVar ('FILTER_DEFAULT_ANDOR','or');
1157 setConfigVar ('FILTER_SUGGEST_ANDOR','yes');
1158 setConfigVar ('FILTER_SUGGEST_TAGS','yes');
1159 setConfigVar ('FILTER_SUGGEST_PREDICATES','yes');
1160 setConfigVar ('FILTER_SUGGEST_EXTRA','no');
1161 setConfigVar ('DEFAULT_SNMP_COMMUNITY','public');
1162 setConfigVar ('IPV4_ENABLE_KNIGHT','yes');
1163 setConfigVar ('TAGS_TOPLIST_SIZE','50');
1164 setConfigVar ('TAGS_QUICKLIST_SIZE','20');
1165 setConfigVar ('TAGS_QUICKLIST_THRESHOLD','50');
1166 setConfigVar ('ENABLE_MULTIPORT_FORM', 'no');
1167 setConfigVar ('DEFAULT_PORT_IIF_ID', '1');
1168 setConfigVar ('DEFAULT_PORT_OIF_IDS', '1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084');
1169 setConfigVar ('IPV4_TREE_RTR_AS_CELL', 'yes');
1170 setConfigVar ('PROXIMITY_RANGE', 0);
1171 setConfigVar ('IPV4_TREE_SHOW_VLAN', 'yes');
1172 setConfigVar ('VLANSWITCH_LISTSRC', '');
1173 setConfigVar ('VLANIPV4NET_LISTSRC', '');
1174 setConfigVar ('DEFAULT_VDOM_ID', '');
1175 setConfigVar ('DEFAULT_VST_ID', '');
1176 setConfigVar ('STATIC_FILTER', 'yes');
1177 setConfigVar ('8021Q_DEPLOY_MINAGE', '300');
1178 setConfigVar ('8021Q_DEPLOY_MAXAGE', '3600');
1179 setConfigVar ('8021Q_DEPLOY_RETRY', '10800');
1180 setConfigVar ('8021Q_WRI_AFTER_CONFT_LISTSRC', 'false');
1181 setConfigVar ('8021Q_INSTANT_DEPLOY', 'no');
1182 setConfigVar ('CDP_RUNNERS_LISTSRC', '');
1183 setConfigVar ('LLDP_RUNNERS_LISTSRC', '');
1184 setConfigVar ('HNDP_RUNNERS_LISTSRC', '');
1185 setConfigVar ('SHRINK_TAG_TREE_ON_CLICK', 'yes');
1186 setConfigVar ('MAX_UNFILTERED_ENTITIES', '0');
1187 setConfigVar ('SYNCDOMAIN_MAX_PROCESSES', '0');
1188 return buildRedirectURL (__FUNCTION__, 'OK');
1189 }
1190
1191 $msgcode['addRealServer']['OK'] = 34;
1192 $msgcode['addRealServer']['ERR'] = 126;
1193 // Add single record.
1194 function addRealServer ()
1195 {
1196 assertUIntArg ('pool_id');
1197 assertIPv4Arg ('remoteip');
1198 assertStringArg ('rsport', TRUE);
1199 assertStringArg ('rsconfig', TRUE);
1200 if (!addRStoRSPool (
1201 $_REQUEST['pool_id'],
1202 $_REQUEST['remoteip'],
1203 $_REQUEST['rsport'],
1204 getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'),
1205 $_REQUEST['rsconfig']
1206 ))
1207 return buildRedirectURL (__FUNCTION__, 'ERR');
1208 else
1209 return buildRedirectURL (__FUNCTION__, 'OK');
1210 }
1211
1212 $msgcode['addRealServers']['OK'] = 37;
1213 $msgcode['addRealServers']['ERR1'] = 131;
1214 $msgcode['addRealServers']['ERR2'] = 127;
1215 // Parse textarea submitted and try adding a real server for each line.
1216 function addRealServers ()
1217 {
1218 assertUIntArg ('pool_id');
1219 assertStringArg ('format');
1220 assertStringArg ('rawtext');
1221 $ngood = $nbad = 0;
1222 $rsconfig = '';
1223 // Keep in mind, that the text will have HTML entities (namely '>') escaped.
1224 foreach (explode ("\n", dos2unix ($_REQUEST['rawtext'])) as $line)
1225 {
1226 if (!strlen ($line))
1227 continue;
1228 $match = array ();
1229 switch ($_REQUEST['format'])
1230 {
1231 case 'ipvs_2': // address and port only
1232 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) /', $line, $match))
1233 continue;
1234 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1235 $ngood++;
1236 else
1237 $nbad++;
1238 break;
1239 case 'ipvs_3': // address, port and weight
1240 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match))
1241 continue;
1242 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3]))
1243 $ngood++;
1244 else
1245 $nbad++;
1246 break;
1247 case 'ssv_2': // IP address and port
1248 if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match))
1249 continue;
1250 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1251 $ngood++;
1252 else
1253 $nbad++;
1254 break;
1255 case 'ssv_1': // IP address
1256 if (!preg_match ('/^([0-9\.]+)$/', $line, $match))
1257 continue;
1258 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1259 $ngood++;
1260 else
1261 $nbad++;
1262 break;
1263 default:
1264 return buildRedirectURL (__FUNCTION__, 'ERR1');
1265 break;
1266 }
1267 }
1268 if ($nbad == 0 and $ngood > 0)
1269 return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood));
1270 else
1271 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($ngood, $nbad));
1272 }
1273
1274 $msgcode['addVService']['OK'] = 28;
1275 $msgcode['addVService']['ERR1'] = 132;
1276 $msgcode['addVService']['ERR2'] = 100;
1277 function addVService ()
1278 {
1279 assertIPv4Arg ('vip');
1280 assertUIntArg ('vport');
1281 assertStringArg ('proto');
1282 if ($_REQUEST['proto'] != 'TCP' and $_REQUEST['proto'] != 'UDP')
1283 return buildRedirectURL (__FUNCTION__, 'ERR1');
1284 assertStringArg ('name', TRUE);
1285 assertStringArg ('vsconfig', TRUE);
1286 assertStringArg ('rsconfig', TRUE);
1287 $error = commitCreateVS
1288 (
1289 $_REQUEST['vip'],
1290 $_REQUEST['vport'],
1291 $_REQUEST['proto'],
1292 $_REQUEST['name'],
1293 $_REQUEST['vsconfig'],
1294 $_REQUEST['rsconfig'],
1295 isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array()
1296 );
1297 if ($error != '')
1298 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
1299 else
1300 return buildRedirectURL (__FUNCTION__, 'OK');
1301 }
1302
1303 $msgcode['deleteRealServer']['OK'] = 35;
1304 $msgcode['deleteRealServer']['ERR'] = 128;
1305 function deleteRealServer ()
1306 {
1307 assertUIntArg ('id');
1308 if (!commitDeleteRS ($_REQUEST['id']))
1309 return buildRedirectURL (__FUNCTION__, 'ERR');
1310 else
1311 return buildRedirectURL (__FUNCTION__, 'OK');
1312 }
1313
1314 $msgcode['deleteLoadBalancer']['OK'] = 19;
1315 $msgcode['deleteLoadBalancer']['ERR'] = 129;
1316 function deleteLoadBalancer ()
1317 {
1318 assertUIntArg ('object_id');
1319 assertUIntArg ('pool_id');
1320 assertUIntArg ('vs_id');
1321 if (!commitDeleteLB (
1322 $_REQUEST['object_id'],
1323 $_REQUEST['pool_id'],
1324 $_REQUEST['vs_id']
1325 ))
1326 return buildRedirectURL (__FUNCTION__, 'ERR');
1327 else
1328 return buildRedirectURL (__FUNCTION__, 'OK');
1329 }
1330
1331 $msgcode['deleteVService']['OK'] = 29;
1332 $msgcode['deleteVService']['ERR'] = 130;
1333 function deleteVService ()
1334 {
1335 assertUIntArg ('vs_id');
1336 if (!commitDeleteVS ($_REQUEST['vs_id']))
1337 return buildRedirectURL (__FUNCTION__, 'ERR');
1338 else
1339 return buildRedirectURL (__FUNCTION__, 'OK');
1340 }
1341
1342 $msgcode['updateSLBDefConfig']['OK'] = 43;
1343 $msgcode['updateSLBDefConfig']['ERR'] = 109;
1344 function updateSLBDefConfig ()
1345 {
1346 $data = array(
1347 'vs' => $_REQUEST['vsconfig'],
1348 'rs' => $_REQUEST['rsconfig']
1349 );
1350 if (!commitUpdateSLBDefConf ($data))
1351 return buildRedirectURL (__FUNCTION__, 'ERR');
1352 else
1353 return buildRedirectURL (__FUNCTION__, 'OK');
1354 }
1355
1356 $msgcode['updateRealServer']['OK'] = 36;
1357 $msgcode['updateRealServer']['ERR'] = 133;
1358 function updateRealServer ()
1359 {
1360 assertUIntArg ('rs_id');
1361 assertIPv4Arg ('rsip');
1362 assertStringArg ('rsport', TRUE);
1363 assertStringArg ('rsconfig', TRUE);
1364 if (FALSE === commitUpdateRS (
1365 $_REQUEST['rs_id'],
1366 $_REQUEST['rsip'],
1367 $_REQUEST['rsport'],
1368 $_REQUEST['rsconfig']
1369 ))
1370 return buildRedirectURL (__FUNCTION__, 'ERR');
1371 else
1372 return buildRedirectURL (__FUNCTION__, 'OK');
1373 }
1374
1375 $msgcode['updateLoadBalancer']['OK'] = 20;
1376 $msgcode['updateLoadBalancer']['ERR'] = 134;
1377 function updateLoadBalancer ()
1378 {
1379 assertUIntArg ('object_id');
1380 assertUIntArg ('pool_id');
1381 assertUIntArg ('vs_id');
1382 assertStringArg ('vsconfig', TRUE);
1383 assertStringArg ('rsconfig', TRUE);
1384 if (! empty($_REQUEST['prio']))
1385 assertUIntArg('prio', TRUE);
1386
1387 if (FALSE === commitUpdateLB (
1388 $_REQUEST['object_id'],
1389 $_REQUEST['pool_id'],
1390 $_REQUEST['vs_id'],
1391 $_REQUEST['vsconfig'],
1392 $_REQUEST['rsconfig'],
1393 $_REQUEST['prio']
1394 ))
1395 return buildRedirectURL (__FUNCTION__, 'ERR');
1396 else
1397 return buildRedirectURL (__FUNCTION__, 'OK');
1398 }
1399
1400 $msgcode['updateVService']['OK'] = 30;
1401 $msgcode['updateVService']['ERR'] = 135;
1402 function updateVService ()
1403 {
1404 assertUIntArg ('vs_id');
1405 assertIPv4Arg ('vip');
1406 assertUIntArg ('vport');
1407 assertStringArg ('proto');
1408 assertStringArg ('name', TRUE);
1409 assertStringArg ('vsconfig', TRUE);
1410 assertStringArg ('rsconfig', TRUE);
1411 if (FALSE === commitUpdateVS (
1412 $_REQUEST['vs_id'],
1413 $_REQUEST['vip'],
1414 $_REQUEST['vport'],
1415 $_REQUEST['proto'],
1416 $_REQUEST['name'],
1417 $_REQUEST['vsconfig'],
1418 $_REQUEST['rsconfig']
1419 ))
1420 return buildRedirectURL (__FUNCTION__, 'ERR');
1421 else
1422 return buildRedirectURL (__FUNCTION__, 'OK');
1423 }
1424
1425 $msgcode['addLoadBalancer']['OK'] = 18;
1426 $msgcode['addLoadBalancer']['ERR'] = 137;
1427 function addLoadBalancer ()
1428 {
1429 assertUIntArg ('pool_id');
1430 assertUIntArg ('object_id');
1431 assertUIntArg ('vs_id');
1432 assertStringArg ('vsconfig', TRUE);
1433 assertStringArg ('rsconfig', TRUE);
1434 if (! empty($_REQUEST['prio']))
1435 assertUIntArg('prio', TRUE);
1436
1437 if (!addLBtoRSPool (
1438 $_REQUEST['pool_id'],
1439 $_REQUEST['object_id'],
1440 $_REQUEST['vs_id'],
1441 $_REQUEST['vsconfig'],
1442 $_REQUEST['rsconfig'],
1443 $_REQUEST['prio']
1444 ))
1445 return buildRedirectURL (__FUNCTION__, 'ERR');
1446 else
1447 return buildRedirectURL (__FUNCTION__, 'OK');
1448 }
1449
1450 $msgcode['addRSPool']['OK'] = 31;
1451 $msgcode['addRSPool']['ERR'] = 100;
1452 function addRSPool ()
1453 {
1454 assertStringArg ('name', TRUE);
1455 assertStringArg ('vsconfig', TRUE);
1456 assertStringArg ('rsconfig', TRUE);
1457 $error = commitCreateRSPool
1458 (
1459 $_REQUEST['name'],
1460 $_REQUEST['vsconfig'],
1461 $_REQUEST['rsconfig'],
1462 isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array()
1463 );
1464 if ($error != '')
1465 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
1466 else
1467 return buildRedirectURL (__FUNCTION__, 'OK');
1468 }
1469
1470 $msgcode['deleteRSPool']['OK'] = 32;
1471 $msgcode['deleteRSPool']['ERR'] = 138;
1472 function deleteRSPool ()
1473 {
1474 assertUIntArg ('pool_id');
1475 if (commitDeleteRSPool ($_REQUEST['pool_id']) === FALSE)
1476 return buildRedirectURL (__FUNCTION__, 'ERR');
1477 else
1478 return buildRedirectURL (__FUNCTION__, 'OK');
1479 }
1480
1481 $msgcode['updateRSPool']['OK'] = 33;
1482 $msgcode['updateRSPool']['ERR'] = 139;
1483 function updateRSPool ()
1484 {
1485 assertUIntArg ('pool_id');
1486 assertStringArg ('name', TRUE);
1487 assertStringArg ('vsconfig', TRUE);
1488 assertStringArg ('rsconfig', TRUE);
1489 if (FALSE === commitUpdateRSPool
1490 (
1491 $_REQUEST['pool_id'],
1492 $_REQUEST['name'],
1493 $_REQUEST['vsconfig'],
1494 $_REQUEST['rsconfig']
1495 )
1496 )
1497 return buildRedirectURL (__FUNCTION__, 'ERR');
1498 else
1499 return buildRedirectURL (__FUNCTION__, 'OK');
1500 }
1501
1502 $msgcode['updateRSInService']['OK'] = 38;
1503 $msgcode['updateRSInService']['ERR'] = 140;
1504 function updateRSInService ()
1505 {
1506 assertUIntArg ('rscount');
1507 $pool_id = $_REQUEST['pool_id'];
1508 $orig = spotEntity ('ipv4rspool', $pool_id);
1509 amplifyCell ($orig);
1510 $nbad = $ngood = 0;
1511 for ($i = 1; $i <= $_REQUEST['rscount']; $i++)
1512 {
1513 $rs_id = $_REQUEST["rsid_${i}"];
1514 if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on')
1515 $newval = 'yes';
1516 else
1517 $newval = 'no';
1518 if ($newval != $orig['rslist'][$rs_id]['inservice'])
1519 {
1520 if (FALSE !== commitSetInService ($rs_id, $newval))
1521 $ngood++;
1522 else
1523 $nbad++;
1524 }
1525 }
1526 if (!$nbad)
1527 return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood));
1528 else
1529 return buildRedirectURL (__FUNCTION__, 'ERR', array ($nbad, $ngood));
1530 }
1531
1532 $msgcode['importPTRData']['OK'] = 26;
1533 $msgcode['importPTRData']['ERR'] = 141;
1534 // FIXME: check, that each submitted address belongs to the prefix we
1535 // are operating on.
1536 function importPTRData ()
1537 {
1538 assertUIntArg ('addrcount');
1539 $nbad = $ngood = 0;
1540 for ($i = 0; $i < $_REQUEST['addrcount']; $i++)
1541 {
1542 $inputname = "import_${i}";
1543 if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on')
1544 continue;
1545 assertIPv4Arg ("addr_${i}");
1546 assertStringArg ("descr_${i}", TRUE);
1547 assertStringArg ("rsvd_${i}");
1548 // Non-existent addresses will not have this argument set in request.
1549 $rsvd = 'no';
1550 if ($_REQUEST["rsvd_${i}"] == 'yes')
1551 $rsvd = 'yes';
1552 if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '')
1553 $ngood++;
1554 else
1555 $nbad++;
1556 }
1557 if (!$nbad)
1558 return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood));
1559 else
1560 return buildRedirectURL (__FUNCTION__, 'ERR', array ($nbad, $ngood));
1561 }
1562
1563 $msgcode['generateAutoPorts']['OK'] = 21;
1564 $msgcode['generateAutoPorts']['ERR'] = 142;
1565 function generateAutoPorts ()
1566 {
1567 global $pageno;
1568 assertUIntArg ('object_id');
1569 $info = spotEntity ('object', $_REQUEST['object_id']);
1570 // Navigate away in case of success, stay at the place otherwise.
1571 if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id']))
1572 return buildRedirectURL (__FUNCTION__, 'OK', array(), $pageno, 'ports');
1573 else
1574 return buildRedirectURL (__FUNCTION__, 'ERR');
1575 }
1576
1577 $msgcode['saveEntityTags']['OK'] = 22;
1578 $msgcode['saveEntityTags']['ERR1'] = 143;
1579 $msgcode['saveEntityTags']['ERR2'] = 187;
1580 // Filter out implicit tags before storing the new tag set.
1581 function saveEntityTags ()
1582 {
1583 global $page, $pageno, $etype_by_pageno;
1584 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1585 return buildRedirectURL (__FUNCTION__, 'ERR2', array (__FUNCTION__));
1586 $realm = $etype_by_pageno[$pageno];
1587 $bypass = $page[$pageno]['bypass'];
1588 assertUIntArg ($bypass);
1589 $entity_id = $_REQUEST[$bypass];
1590 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1591 // Build a chain from the submitted data, minimize it,
1592 // then wipe existing records and store the new set instead.
1593 destroyTagsForEntity ($realm, $entity_id);
1594 // TODO: these actions are very close to what rebuildTagChainForEntity() does,
1595 // so why not use it?
1596 $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist));
1597 $n_succeeds = $n_errors = 0;
1598 foreach ($newchain as $taginfo)
1599 if (addTagForEntity ($realm, $entity_id, $taginfo['id']))
1600 $n_succeeds++;
1601 else
1602 $n_errors++;
1603 if ($n_errors)
1604 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($n_succeeds, $n_errors));
1605 else
1606 return buildRedirectURL (__FUNCTION__, 'OK', array ($n_succeeds));
1607 }
1608
1609 $msgcode['destroyTag']['OK'] = 58;
1610 $msgcode['destroyTag']['ERR1'] = 183;
1611 $msgcode['destroyTag']['ERR2'] = 144;
1612 function destroyTag ()
1613 {
1614 assertUIntArg ('tag_id');
1615 global $taglist;
1616 if (!isset ($taglist[$_REQUEST['tag_id']]))
1617 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($_REQUEST['tag_id']));
1618 if (($ret = commitDestroyTag ($_REQUEST['tag_id'])) == '')
1619 return buildRedirectURL (__FUNCTION__, 'OK', array ($taglist[$_REQUEST['tag_id']]['tag']));
1620 else
1621 return buildRedirectURL (__FUNCTION__, 'ERR2');
1622 }
1623
1624 $msgcode['updateTag']['OK'] = 60;
1625 $msgcode['updateTag']['ERR1'] = 145;
1626 $msgcode['updateTag']['ERR2'] = 109;
1627 function updateTag ()
1628 {
1629 assertUIntArg ('tag_id');
1630 assertUIntArg ('parent_id', TRUE);
1631 assertStringArg ('tag_name');
1632 $tagname = trim ($_REQUEST['tag_name']);
1633 if (!validTagName ($tagname))
1634 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($tagname));
1635 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1636 $parent_id = 'NULL';
1637 if (FALSE !== commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id))
1638 return buildRedirectURL (__FUNCTION__, 'OK', array ($tagname));
1639 // Use old name in the message, cause update failed.
1640 global $taglist;
1641 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($taglist[$_REQUEST['tag_id']]['tag']));
1642 }
1643
1644 $msgcode['rollTags']['OK'] = 67;
1645 $msgcode['rollTags']['ERR'] = 149;
1646 function rollTags ()
1647 {
1648 assertUIntArg ('row_id');
1649 assertStringArg ('sum', TRUE);
1650 assertUIntArg ('realsum');
1651 if ($_REQUEST['sum'] != $_REQUEST['realsum'])
1652 return buildRedirectURL (__FUNCTION__, 'ERR');
1653 // Even if the user requested an empty tag list, don't bail out, but process existing
1654 // tag chains with "zero" extra. This will make sure, that the stuff processed will
1655 // have its chains refined to "normal" form.
1656 $extratags = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1657 $n_ok = 0;
1658 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
1659 // filter out the same tag again and again. It will have own noise to cancel.
1660 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
1661 foreach (listCells ('rack', $_REQUEST['row_id']) as $rack)
1662 {
1663 if (rebuildTagChainForEntity ('rack', $rack['id'], $extrachain))
1664 $n_ok++;
1665 amplifyCell ($rack);
1666 foreach ($rack['mountedObjects'] as $object_id)
1667 if (rebuildTagChainForEntity ('object', $object_id, $extrachain))
1668 $n_ok++;
1669 }
1670 return buildRedirectURL (__FUNCTION__, 'OK', array ($n_ok));
1671 }
1672
1673 $msgcode['changeMyPassword']['OK'] = 61;
1674 $msgcode['changeMyPassword']['ERR1'] = 150;
1675 $msgcode['changeMyPassword']['ERR2'] = 151;
1676 $msgcode['changeMyPassword']['ERR3'] = 152;
1677 $msgcode['changeMyPassword']['ERR4'] = 153;
1678 function changeMyPassword ()
1679 {
1680 global $remote_username, $user_auth_src;
1681 if ($user_auth_src != 'database')
1682 return buildRedirectURL (__FUNCTION__, 'ERR1');
1683 assertStringArg ('oldpassword');
1684 assertStringArg ('newpassword1');
1685 assertStringArg ('newpassword2');
1686 $remote_userid = getUserIDByUsername ($remote_username);
1687 $userinfo = spotEntity ('user', $remote_userid);
1688 if ($userinfo['user_password_hash'] != sha1 ($_REQUEST['oldpassword']))
1689 return buildRedirectURL (__FUNCTION__, 'ERR2');
1690 if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2'])
1691 return buildRedirectURL (__FUNCTION__, 'ERR3');
1692 if (FALSE !== commitUpdateUserAccount ($remote_userid, $userinfo['user_name'], $userinfo['user_realname'], sha1 ($_REQUEST['newpassword1'])))
1693 return buildRedirectURL (__FUNCTION__, 'OK');
1694 else
1695 return buildRedirectURL (__FUNCTION__, 'ERR4');
1696 }
1697
1698 $msgcode['saveRackCode']['OK'] = 43;
1699 $msgcode['saveRackCode']['ERR1'] = 154;
1700 $msgcode['saveRackCode']['ERR2'] = 155;
1701 function saveRackCode ()
1702 {
1703 assertStringArg ('rackcode');
1704 // For the test to succeed, unescape LFs, strip CRs.
1705 $newcode = dos2unix ($_REQUEST['rackcode']);
1706 $parseTree = getRackCode ($newcode);
1707 if ($parseTree['result'] != 'ACK')
1708 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($parseTree['load']));
1709 if (FALSE !== saveScript ('RackCode', $newcode))
1710 {
1711 saveScript ('RackCodeCache', base64_encode (serialize ($parseTree)));
1712 return buildRedirectURL (__FUNCTION__, 'OK');
1713 }
1714 return buildRedirectURL (__FUNCTION__, 'ERR2');
1715 }
1716
1717 $msgcode['setPortVLAN']['ERR1'] = 156;
1718 // This handler's context is pre-built, but not authorized. It is assumed, that the
1719 // handler will take existing context and before each commit check authorization
1720 // on the base chain plus necessary context added.
1721 function setPortVLAN ()
1722 {
1723 assertUIntArg ('portcount');
1724 $data = getSwitchVLANs ($_REQUEST['object_id']);
1725 if ($data === NULL)
1726 return buildRedirectURL (__FUNCTION__, 'ERR1');
1727 list ($vlanlist, $portlist) = $data;
1728 // Here we just build up 1 set command for the gateway with all of the ports
1729 // included. The gateway is expected to filter unnecessary changes silently
1730 // and to provide a list of responses with either error or success message
1731 // for each of the rest.
1732 $nports = $_REQUEST['portcount'];
1733 $prefix = 'set ';
1734 $log = emptyLog();
1735 $setcmd = '';
1736 for ($i = 0; $i < $nports; $i++)
1737 if
1738 (
1739 !isset ($_REQUEST['portname_' . $i]) ||
1740 !isset ($_REQUEST['vlanid_' . $i]) ||
1741 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
1742 )
1743 $log['m'][] = array ('c' => 158, 'a' => array ($i));
1744 elseif
1745 (
1746 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
1747 $portlist[$i]['vlaind'] == 'TRUNK'
1748 )
1749 continue;
1750 else
1751 {
1752 $portname = $_REQUEST['portname_' . $i];
1753 $oldvlanid = $portlist[$i]['vlanid'];
1754 $newvlanid = $_REQUEST['vlanid_' . $i];
1755 if
1756 (
1757 !permitted (NULL, NULL, NULL, array (array ('tag' => '$fromvlan_' . $oldvlanid))) or
1758 !permitted (NULL, NULL, NULL, array (array ('tag' => '$tovlan_' . $newvlanid)))
1759 )
1760 {
1761 $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid));
1762 continue;
1763 }
1764 $setcmd .= $prefix . $portname . '=' . $newvlanid;
1765 $prefix = ';';
1766 }
1767 // Feed the gateway and interpret its (non)response.
1768 if ($setcmd != '')
1769 $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd));
1770 else
1771 $log['m'][] = array ('c' => 201);
1772 return buildWideRedirectURL ($log);
1773 }
1774
1775 $msgcode['submitSLBConfig']['OK'] = 66;
1776 $msgcode['submitSLBConfig']['ERR'] = 164;
1777 function submitSLBConfig ()
1778 {
1779 assertUIntArg ('object_id');
1780 $newconfig = buildLVSConfig ($_REQUEST['object_id']);
1781 try
1782 {
1783 gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8'));
1784 }
1785 catch (RTGatewayError $e)
1786 {
1787 return buildRedirectURL (__FUNCTION__, 'ERR', array ($e->getMessage()));
1788 }
1789 return buildRedirectURL (__FUNCTION__, 'OK', array ('slbconfig'));
1790 }
1791
1792 $msgcode['updateRow']['OK'] = 75;
1793 $msgcode['updateRow']['ERR'] = 100;
1794 function updateRow ()
1795 {
1796 assertUIntArg ('row_id');
1797 assertStringArg ('name');
1798
1799 if (FALSE !== commitUpdateRow ($_REQUEST['row_id'], $_REQUEST['name']))
1800 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name']));
1801 else
1802 return buildRedirectURL (__FUNCTION__, 'ERR', array ($_REQUEST['name']));
1803 }
1804
1805 $msgcode['deleteRow']['OK'] = 77;
1806 $msgcode['deleteRow']['ERR'] = 146;
1807 function deleteRow ()
1808 {
1809 assertUIntArg ('row_id');
1810 $rowinfo = getRackRowInfo ($_REQUEST['row_id']);
1811 return buildRedirectURL (__FUNCTION__, FALSE === commitDeleteRow ($_REQUEST['row_id']) ? 'ERR' : 'OK', array ($rowinfo['name']));
1812 }
1813
1814 $msgcode['addRack']['OK'] = 65;
1815 $msgcode['addRack']['ERR1'] = 171;
1816 $msgcode['addRack']['ERR2'] = 172;
1817 function addRack ()
1818 {
1819 assertUIntArg ('row_id');
1820 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1821 if (isset ($_REQUEST['got_data']))
1822 {
1823 assertStringArg ('rack_name');
1824 assertUIntArg ('rack_height1');
1825 assertStringArg ('rack_comment', TRUE);
1826
1827 if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
1828 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name']));
1829 else
1830 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($_REQUEST['rack_name']));
1831 }
1832 elseif (isset ($_REQUEST['got_mdata']))
1833 {
1834 assertUIntArg ('rack_height2');
1835 assertStringArg ('rack_names', TRUE);
1836 $log = emptyLog();
1837 // copy-and-paste from renderAddMultipleObjectsForm()
1838 $names1 = explode ("\n", $_REQUEST['rack_names']);
1839 $names2 = array();
1840 foreach ($names1 as $line)
1841 {
1842 $parts = explode ('\r', $line);
1843 reset ($parts);
1844 if (!strlen ($parts[0]))
1845 continue;
1846 else
1847 $names2[] = rtrim ($parts[0]);
1848 }
1849 global $msgcode;
1850 foreach ($names2 as $cname)
1851 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE)
1852 $log['m'][] = array ('c' => $msgcode[__FUNCTION__]['OK'], 'a' => array ($cname));
1853 else
1854 $log['m'][] = array ('c' => $msgcode[__FUNCTION__]['ERR1'], 'a' => array ($cname));
1855 return buildWideRedirectURL ($log);
1856 }
1857 else
1858 return buildRedirectURL (__FUNCTION__, 'ERR2');
1859 }
1860
1861 $msgcode['deleteRack']['OK'] = 79;
1862 $msgcode['deleteRack']['ERR'] = 100;
1863 $msgcode['deleteRack']['ERR1'] = 206;
1864 function deleteRack ()
1865 {
1866 assertUIntArg ('rack_id');
1867 if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id'])))
1868 return buildRedirectURL (__FUNCTION__, 'ERR', array ('Rack not found'), 'rackspace', 'default');
1869 amplifyCell ($rackData);
1870 if (count ($rackData['mountedObjects']))
1871 return buildRedirectURL (__FUNCTION__, 'ERR1');
1872 if (TRUE !== commitDeleteRack ($_REQUEST['rack_id']))
1873 return buildRedirectURL (__FUNCTION__, 'ERR', array(), 'rackspace', 'default');
1874 return buildRedirectURL (__FUNCTION__, 'OK', array ($rackData['name']), 'rackspace', 'default');
1875 }
1876
1877 $msgcode['updateRack']['OK'] = 68;
1878 $msgcode['updateRack']['ERR'] = 177;
1879 function updateRack ()
1880 {
1881 assertUIntArg ('rack_id');
1882 assertUIntArg ('rack_row_id');
1883 assertUIntArg ('rack_height');
1884 assertStringArg ('rack_name');
1885 assertStringArg ('rack_comment', TRUE);
1886
1887 resetThumbCache ($_REQUEST['rack_id']);
1888 if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
1889 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name']));
1890 else
1891 return buildRedirectURL (__FUNCTION__, 'ERR');
1892 }
1893
1894 function updateRackDesign ()
1895 {
1896 assertUIntArg ('rack_id');
1897 $rackData = spotEntity ('rack', $_REQUEST['rack_id']);
1898 amplifyCell ($rackData);
1899 applyRackDesignMask($rackData);
1900 markupObjectProblems ($rackData);
1901 $response = processGridForm ($rackData, 'A', 'F');
1902 return buildWideRedirectURL (array($response));
1903 }
1904
1905 function updateRackProblems ()
1906 {
1907 assertUIntArg ('rack_id');
1908 $rackData = spotEntity ('rack', $_REQUEST['rack_id']);
1909 amplifyCell ($rackData);
1910 applyRackProblemMask($rackData);
1911 markupObjectProblems ($rackData);
1912 $response = processGridForm ($rackData, 'F', 'U');
1913 return buildWideRedirectURL (array($response));
1914 }
1915
1916 function querySNMPData ()
1917 {
1918 assertUIntArg ('object_id');
1919 assertStringArg ('community', TRUE);
1920
1921 $snmpsetup = array ();
1922 if ( strlen($_REQUEST['community']) == 0 ) {
1923 assertStringArg ('sec_name');
1924 assertStringArg ('sec_level');
1925 assertStringArg ('auth_protocol');
1926 assertStringArg ('auth_passphrase', TRUE);
1927 assertStringArg ('priv_protocol');
1928 assertStringArg ('priv_passphrase', TRUE);
1929
1930 $snmpsetup['sec_name'] = $_REQUEST['sec_name'];
1931 $snmpsetup['sec_level'] = $_REQUEST['sec_level'];
1932 $snmpsetup['auth_protocol'] = $_REQUEST['auth_protocol'];
1933 $snmpsetup['auth_passphrase'] = $_REQUEST['auth_passphrase'];
1934 $snmpsetup['priv_protocol'] = $_REQUEST['priv_protocol'];
1935 $snmpsetup['priv_passphrase'] = $_REQUEST['priv_passphrase'];
1936 }
1937 else {
1938 $snmpsetup['community'] = $_REQUEST['community'];
1939 }
1940
1941
1942 return doSNMPmining ($_REQUEST['object_id'], $snmpsetup);
1943 }
1944
1945 $msgcode['addFileWithoutLink']['OK'] = 69;
1946 $msgcode['addFileWithoutLink']['ERR1'] = 181;
1947 $msgcode['addFileWithoutLink']['ERR2'] = 110;
1948 // File-related functions
1949 function addFileWithoutLink ()
1950 {
1951 assertStringArg ('comment', TRUE);
1952
1953 // Make sure the file can be uploaded
1954 if (get_cfg_var('file_uploads') != 1)
1955 return buildRedirectURL (__FUNCTION__, 'ERR1');
1956
1957 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1958 global $sic;
1959 if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']))
1960 return buildRedirectURL (__FUNCTION__, 'ERR2');
1961 if (isset ($_REQUEST['taglist']))
1962 produceTagsForLastRecord ('file', $_REQUEST['taglist']);
1963 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($_FILES['file']['name'])));
1964 }
1965
1966 $msgcode['addFileToEntity']['OK'] = 69;
1967 $msgcode['addFileToEntity']['ERR2'] = 181;
1968 $msgcode['addFileToEntity']['ERR3'] = 110;
1969 function addFileToEntity ()
1970 {
1971 global $page, $pageno, $etype_by_pageno;
1972 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1973 throw new RackTablesError ('dispatching failure', RackTablesError::INTERNAL);
1974 $realm = $etype_by_pageno[$pageno];
1975 $bypass = $page[$pageno]['bypass'];
1976 assertUIntArg ($bypass);
1977 $entity_id = $_REQUEST[$bypass];
1978 assertStringArg ('comment', TRUE);
1979
1980 // Make sure the file can be uploaded
1981 if (get_cfg_var('file_uploads') != 1)
1982 return buildRedirectURL (__FUNCTION__, 'ERR2');
1983
1984 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1985 global $sic;
1986 if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']))
1987 return buildRedirectURL (__FUNCTION__, 'ERR3');
1988 if (FALSE === commitLinkFile (lastInsertID(), $realm, $entity_id))
1989 return buildRedirectURL (__FUNCTION__, 'ERR3');
1990
1991 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($_FILES['file']['name'])));
1992 }
1993
1994 $msgcode['linkFileToEntity']['OK'] = 71;
1995 $msgcode['linkFileToEntity']['ERR1'] = 178;
1996 $msgcode['linkFileToEntity']['ERR2'] = 110;
1997 function linkFileToEntity ()
1998 {
1999 assertUIntArg ('file_id');
2000 global $page, $pageno, $etype_by_pageno;
2001 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
2002 throw new RackTablesError ('dispatching failure', RackTablesError::INTERNAL);
2003 $entity_type = $etype_by_pageno[$pageno];
2004 $bypass_name = $page[$pageno]['bypass'];
2005 assertUIntArg ($bypass_name);
2006
2007 $fi = spotEntity ('file', $_REQUEST['file_id']);
2008 if (FALSE === commitLinkFile ($_REQUEST['file_id'], $entity_type, $_REQUEST[$bypass_name]))
2009 return buildRedirectURL (__FUNCTION__, 'ERR2');
2010
2011 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($fi['name'])));
2012 }
2013
2014 $msgcode['replaceFile']['OK'] = 70;
2015 $msgcode['replaceFile']['ERR1'] = 181;
2016 $msgcode['replaceFile']['ERR2'] = 207;
2017 $msgcode['replaceFile']['ERR3'] = 109;
2018 function replaceFile ()
2019 {
2020 global $sic;
2021 assertUIntArg ('file_id');
2022
2023 // Make sure the file can be uploaded
2024 if (get_cfg_var('file_uploads') != 1)
2025 return buildRedirectURL (__FUNCTION__, 'ERR1');
2026 $shortInfo = spotEntity ('file', $sic['file_id']);
2027
2028 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
2029 if ($fp === FALSE)
2030 return buildRedirectURL (__FUNCTION__, 'ERR2');
2031 if (FALSE === commitReplaceFile ($sic['file_id'], $fp))
2032 return buildRedirectURL (__FUNCTION__, 'ERR3');
2033
2034 usePreparedExecuteBlade
2035 (
2036 'UPDATE File SET thumbnail = NULL WHERE id = ?',
2037 $sic['file_id']
2038 );
2039
2040 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
2041 }
2042
2043 $msgcode['updateFile']['OK'] = 70;
2044 $msgcode['updateFile']['ERR'] = 109;
2045 function updateFile ()
2046 {
2047 assertUIntArg ('file_id');
2048 assertStringArg ('file_name');
2049 assertStringArg ('file_type');
2050 assertStringArg ('file_comment', TRUE);
2051 global $sic;
2052 if (FALSE === commitUpdateFile ($sic['file_id'], $sic['file_name'], $sic['file_type'], $sic['file_comment']))
2053 return buildRedirectURL (__FUNCTION__, 'ERR');
2054 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['file_name']));
2055 }
2056
2057 $msgcode['unlinkFile']['OK'] = 72;
2058 $msgcode['unlinkFile']['ERR'] = 182;
2059 function unlinkFile ()
2060 {
2061 assertUIntArg ('link_id');
2062 $error = commitUnlinkFile ($_REQUEST['link_id']);
2063
2064 if ($error != '')
2065 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
2066
2067 return buildRedirectURL (__FUNCTION__, 'OK');
2068 }
2069
2070 $msgcode['deleteFile']['OK'] = 73;
2071 $msgcode['deleteFile']['ERR'] = 100;
2072 function deleteFile ()
2073 {
2074 assertUIntArg ('file_id');
2075 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
2076 $error = commitDeleteFile ($_REQUEST['file_id']);
2077
2078 if ($error != '')
2079 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
2080
2081 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
2082 }
2083
2084 $msgcode['updateFileText']['OK'] = 78;
2085 $msgcode['updateFileText']['ERR1'] = 179;
2086 $msgcode['updateFileText']['ERR2'] = 180;
2087 function updateFileText ()
2088 {
2089 assertUIntArg ('file_id');
2090 assertStringArg ('mtime_copy');
2091 assertStringArg ('file_text', TRUE); // it's Ok to save empty
2092 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
2093 if ($shortInfo['mtime'] != $_REQUEST['mtime_copy'])
2094 return buildRedirectURL (__FUNCTION__, 'ERR1');
2095 global $sic;
2096 if (FALSE === commitReplaceFile ($sic['file_id'], $sic['file_text']))
2097 return buildRedirectURL (__FUNCTION__, 'ERR2');
2098 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
2099 }
2100
2101 $msgcode['addPortInterfaceCompat']['OK'] = 48;
2102 $msgcode['addPortInterfaceCompat']['ERR'] = 110;
2103 function addPortInterfaceCompat ()
2104 {
2105 assertUIntArg ('iif_id');
2106 assertUIntArg ('oif_id');
2107 if (commitSupplementPIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
2108 return buildRedirectURL (__FUNCTION__, 'OK');
2109 return buildRedirectURL (__FUNCTION__, 'ERR');
2110 }
2111
2112 $msgcode['delPortInterfaceCompat']['OK'] = 49;
2113 $msgcode['delPortInterfaceCompat']['ERR'] = 111;
2114 function delPortInterfaceCompat ()
2115 {
2116 assertUIntArg ('iif_id');
2117 assertUIntArg ('oif_id');
2118 if (commitReducePIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
2119 return buildRedirectURL (__FUNCTION__, 'OK');
2120 return buildRedirectURL (__FUNCTION__, 'ERR');
2121 }
2122
2123 $ifcompatpack = array
2124 (
2125 '1000cwdm80' => array (1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216),
2126 '1000dwdm80' => array // ITU channels 20~61
2127 (
2128 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226,
2129 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236,
2130 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246,
2131 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256,
2132 1257, 1258
2133 ),
2134 '10000dwdm80' => array // same channels for 10GE
2135 (
2136 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268,
2137 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278,
2138 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288,
2139 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298,
2140 1299, 1300
2141 ),
2142 );
2143
2144 $msgcode['addPortInterfaceCompatPack']['OK'] = 44;
2145 $msgcode['addPortInterfaceCompatPack']['ERR'] = 123;
2146 function addPortInterfaceCompatPack ()
2147 {
2148 assertStringArg ('standard');
2149 assertUIntArg ('iif_id');
2150 global $ifcompatpack;
2151 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
2152 return buildRedirectURL (__FUNCTION__, 'ERR');
2153 $ngood = $nbad = 0;
2154 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2155 if (commitSupplementPIC ($_REQUEST['iif_id'], $oif_id))
2156 $ngood++;
2157 else
2158 $nbad++;
2159 return buildRedirectURL (__FUNCTION__, 'OK', array ($nbad, $ngood));
2160 }
2161
2162 $msgcode['delPortInterfaceCompatPack']['OK'] = 44;
2163 $msgcode['delPortInterfaceCompatPack']['ERR'] = 123;
2164 function delPortInterfaceCompatPack ()
2165 {
2166 assertStringArg ('standard');
2167 assertUIntArg ('iif_id');
2168 global $ifcompatpack;
2169 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
2170 return buildRedirectURL (__FUNCTION__, 'ERR');
2171 $ngood = $nbad = 0;
2172 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2173 if (commitReducePIC ($_REQUEST['iif_id'], $oif_id))
2174 $ngood++;
2175 else
2176 $nbad++;
2177 return buildRedirectURL (__FUNCTION__, 'OK', array ($nbad, $ngood));
2178 }
2179
2180 $msgcode['addPortOIFCompat']['OK'] = 48;
2181 $msgcode['addPortOIFCompat']['ERR'] = 110;
2182 function addPortOIFCompat()
2183 {
2184 assertUIntArg('type1');
2185 assertUIntArg('type2');
2186 if (commitSupplementPOIFC($_REQUEST['type1'], $_REQUEST['type2']))
2187 return buildRedirectURL(__FUNCTION__, 'OK');
2188 return buildRedirectURL(__FUNCTION__, 'ERR');
2189 }
2190
2191 $msgcode['delPortOIFCompat']['OK'] = 49;
2192 $msgcode['delPortOIFCompat']['ERR'] = 111;
2193 function delPortOIFCompat ()
2194 {
2195 assertUIntArg('type1');
2196 assertUIntArg('type2');
2197 if (commitReducePOIFC ($_REQUEST['type1'], $_REQUEST['type2']) !== FALSE)
2198 return buildRedirectURL (__FUNCTION__, 'OK');
2199 return buildRedirectURL (__FUNCTION__, 'ERR');
2200
2201 }
2202
2203 $msgcode['add8021QOrder']['OK'] = 48;
2204 $msgcode['add8021QOrder']['ERR'] = 118;
2205 function add8021QOrder ()
2206 {
2207 assertUIntArg ('vdom_id');
2208 assertUIntArg ('object_id');
2209 assertUIntArg ('vst_id');
2210 global $sic;
2211 $result = usePreparedExecuteBlade
2212 (
2213 'INSERT INTO VLANSwitch (domain_id, object_id, template_id, last_change, out_of_sync) ' .
2214 'VALUES (?, ?, ?, NOW(), "yes")',
2215 array ($sic['vdom_id'], $sic['object_id'], $sic['vst_id'])
2216 );
2217 return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR');
2218 }
2219
2220 $msgcode['del8021QOrder']['OK'] = 49;
2221 $msgcode['del8021QOrder']['ERR'] = 119;
2222 function del8021QOrder ()
2223 {
2224 assertUIntArg ('object_id');
2225 assertUIntArg ('vdom_id');
2226 assertUIntArg ('vst_id');
2227 global $sic;
2228 $result = usePreparedDeleteBlade ('VLANSwitch', array ('object_id' => $sic['object_id']));
2229 $focus_hints = array
2230 (
2231 'prev_objid' => $_REQUEST['object_id'],
2232 'prev_vstid' => $_REQUEST['vst_id'],
2233 'prev_vdid' => $_REQUEST['vdom_id'],
2234 );
2235 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR', array(), NULL, NULL, $focus_hints);
2236 }
2237
2238 $msgcode['delVLANDescription']['OK'] = 49;
2239 $msgcode['delVLANDescription']['ERR1'] = 105;
2240 $msgcode['delVLANDescription']['ERR2'] = 111;
2241 function delVLANDescription ()
2242 {
2243 assertUIntArg ('vlan_id');
2244 global $sic;
2245 if ($sic['vlan_id'] == VLAN_DFL_ID)
2246 return buildRedirectURL (__FUNCTION__, 'ERR1');
2247 $result = commitReduceVLANDescription ($sic['vdom_id'], $sic['vlan_id']);
2248 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR2');
2249 }
2250
2251 $msgcode['updVLANDescription']['OK'] = 51;
2252 $msgcode['updVLANDescription']['ERR1'] = 105;
2253 $msgcode['updVLANDescription']['ERR2'] = 109;
2254 function updVLANDescription ()
2255 {
2256 assertUIntArg ('vlan_id');
2257 assertStringArg ('vlan_type');
2258 assertStringArg ('vlan_descr', TRUE);
2259 global $sic;
2260 if ($sic['vlan_id'] == VLAN_DFL_ID)
2261 return buildRedirectURL (__FUNCTION__, 'ERR1');
2262 $result = commitUpdateVLANDescription
2263 (
2264 $sic['vdom_id'],
2265 $sic['vlan_id'],
2266 $sic['vlan_type'],
2267 $sic['vlan_descr']
2268 );
2269 return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR2');
2270 }
2271
2272 $msgcode['createVLANDomain']['OK'] = 48;
2273 $msgcode['createVLANDomain']['ERR'] = 110;
2274 function createVLANDomain ()
2275 {
2276 assertStringArg ('vdom_descr');
2277 global $sic;
2278 $result = usePreparedInsertBlade
2279 (
2280 'VLANDomain',
2281 array
2282 (
2283 'description' => $sic['vdom_descr'],
2284 )
2285 );
2286 $result = $result and usePreparedInsertBlade
2287 (
2288 'VLANDescription',
2289 array
2290 (
2291 'domain_id' => lastInsertID(),
2292 'vlan_id' => VLAN_DFL_ID,
2293 'vlan_type' => 'compulsory',
2294 'vlan_descr' => 'default',
2295 )
2296 );
2297 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2298 }
2299
2300 $msgcode['destroyVLANDomain']['OK'] = 49;
2301 $msgcode['destroyVLANDomain']['ERR'] = 111;
2302 function destroyVLANDomain ()
2303 {
2304 assertUIntArg ('vdom_id');
2305 global $sic;
2306 $result = FALSE !== usePreparedDeleteBlade ('VLANDomain', array ('id' => $sic['vdom_id']));
2307 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2308 }
2309
2310 $msgcode['updateVLANDomain']['OK'] = 51;
2311 $msgcode['updateVLANDomain']['ERR'] = 109;
2312 function updateVLANDomain ()
2313 {
2314 assertUIntArg ('vdom_id');
2315 assertStringArg ('vdom_descr');
2316 global $sic;
2317 $result = FALSE !== commitUpdateVLANDomain ($sic['vdom_id'], $sic['vdom_descr']);
2318 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2319 }
2320
2321 $msgcode['save8021QPorts']['OK1'] = 63;
2322 $msgcode['save8021QPorts']['OK2'] = 41;
2323 $msgcode['save8021QPorts']['ERR1'] = 160;
2324 $msgcode['save8021QPorts']['ERR2'] = 109;
2325 function save8021QPorts ()
2326 {
2327 global $sic, $dbxlink;
2328 assertUIntArg ('mutex_rev', TRUE); // counts from 0
2329 assertStringArg ('form_mode');
2330 if ($sic['form_mode'] != 'save' and $sic['form_mode'] != 'duplicate')
2331 throw new InvalidRequestArgException ('form_mode', $sic['form_mode']);
2332 $extra = array();
2333 $dbxlink->beginTransaction();
2334 try
2335 {
2336 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE'))
2337 throw new InvalidArgException ('object_id', $object_id, 'VLAN domain is not set for this object');
2338 if ($vswitch['mutex_rev'] != $sic['mutex_rev'])
2339 throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form data');
2340 $after = $before = apply8021QOrder ($vswitch['template_id'], getStored8021QConfig ($sic['object_id'], 'desired'));
2341 $changes = array();
2342 switch ($sic['form_mode'])
2343 {
2344 case 'save':
2345 assertUIntArg ('nports');
2346 if ($sic['nports'] == 1)
2347 {
2348 assertStringArg ('pn_0');
2349 $extra = array ('port_name' => $sic['pn_0']);
2350 }
2351 for ($i = 0; $i < $sic['nports']; $i++)
2352 {
2353 assertStringArg ('pn_' . $i);
2354 assertStringArg ('pm_' . $i);
2355 // An access port only generates form input for its native VLAN,
2356 // which we derive allowed VLAN list from.
2357 $native = isset ($sic['pnv_' . $i]) ? $sic['pnv_' . $i] : 0;
2358 switch ($sic["pm_${i}"])
2359 {
2360 case 'trunk':
2361 # assertArrayArg ('pav_' . $i);
2362 $allowed = isset ($sic['pav_' . $i]) ? $sic['pav_' . $i] : array();
2363 break;
2364 case 'access':
2365 if ($native == 'same')
2366 continue 2;
2367 assertUIntArg ('pnv_' . $i);
2368 $allowed = array ($native);
2369 break;
2370 default:
2371 throw new InvalidRequestArgException ("pm_${i}", $_REQUEST["pm_${i}"], 'unknown port mode');
2372 }
2373 $changes[$sic['pn_' . $i]] = array
2374 (
2375 'mode' => $sic['pm_' . $i],
2376 'allowed' => $allowed,
2377 'native' => $native,
2378 );
2379 }
2380 break;
2381 case 'duplicate':
2382 assertStringArg ('from_port');
2383 # assertArrayArg ('to_ports');
2384 if (!array_key_exists ($sic['from_port'], $before))
2385 throw new InvalidArgException ('from_port', $sic['from_port'], 'this port does not exist');
2386 foreach ($sic['to_ports'] as $tpn)
2387 if (!array_key_exists ($tpn, $before))
2388 throw new InvalidArgException ('to_ports[]', $tpn, 'this port does not exist');
2389 elseif ($tpn != $sic['from_port'])
2390 $changes[$tpn] = $before[$sic['from_port']];
2391 break;
2392 }
2393 $domain_vlanlist = getDomainVLANs ($vswitch['domain_id']);
2394 $changes = filter8021QChangeRequests
2395 (
2396 $domain_vlanlist,
2397 $before,
2398 apply8021QOrder ($vswitch['template_id'], $changes)
2399 );
2400 $changes = authorize8021QChangeRequests ($before, $changes);
2401 foreach ($changes as $port_name => $port)
2402 $after[$port_name] = $port;
2403 $new_uplinks = filter8021QChangeRequests ($domain_vlanlist, $after, produceUplinkPorts ($domain_vlanlist, $after));
2404 $npulled = replace8021QPorts ('desired', $vswitch['object_id'], $before, $changes);
2405 $nsaved_uplinks = replace8021QPorts ('desired', $vswitch['object_id'], $before, $new_uplinks);
2406 }
2407 catch (Exception $e)
2408 {
2409 $dbxlink->rollBack();
2410 return buildRedirectURL (__FUNCTION__, 'ERR2', array(), NULL, NULL, $extra);
2411 }
2412 if ($npulled + $nsaved_uplinks)
2413 $result = usePreparedExecuteBlade
2414 (
2415 'UPDATE VLANSwitch SET mutex_rev=mutex_rev+1, last_change=NOW(), out_of_sync="yes" WHERE object_id=?',
2416 array ($sic['object_id'])
2417 );
2418 $dbxlink->commit();
2419 $log = oneLiner (63, array ($npulled + $nsaved_uplinks));
2420 if ($nsaved_uplinks)
2421 {
2422 initiateUplinksReverb ($vswitch['object_id'], $new_uplinks);
2423 $log = mergeLogs ($log, oneLiner (41));
2424 }
2425 if ($npulled + $nsaved_uplinks > 0 and getConfigVar ('8021Q_INSTANT_DEPLOY') == 'yes')
2426 {
2427 try
2428 {
2429 if (FALSE === $done = exec8021QDeploy ($sic['object_id'], TRUE))
2430 $log = mergeLogs ($log, oneLiner (191));
2431 else
2432 $log = mergeLogs ($log, oneLiner (63, array ($done)));
2433 }
2434 catch (Exception $e)
2435 {
2436 $log = mergeLogs ($log, oneLiner (109));
2437 }
2438 }
2439 return buildWideRedirectURL ($log, NULL, NULL, $extra);
2440 }
2441
2442 $msgcode['bindVLANtoIPv4']['OK'] = 48;
2443 $msgcode['bindVLANtoIPv4']['ERR'] = 110;
2444 function bindVLANtoIPv4 ()
2445 {
2446 assertUIntArg ('id'); // network id
2447 global $sic;
2448 $result = commitSupplementVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2449 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2450 }
2451
2452 $msgcode['bindVLANtoIPv6']['OK'] = 48;
2453 $msgcode['bindVLANtoIPv6']['ERR'] = 110;
2454 function bindVLANtoIPv6 ()
2455 {
2456 assertUIntArg ('id'); // network id
2457 global $sic;
2458 $result = commitSupplementVLANIPv6 ($sic['vlan_ck'], $_REQUEST['id']);
2459 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2460 }
2461
2462 $msgcode['unbindVLANfromIPv4']['OK'] = 49;
2463 $msgcode['unbindVLANfromIPv4']['ERR'] = 111;
2464 function unbindVLANfromIPv4 ()
2465 {
2466 assertUIntArg ('id'); // network id
2467 global $sic;
2468 $result = commitReduceVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2469 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2470 }
2471
2472 $msgcode['unbindVLANfromIPv6']['OK'] = 49;
2473 $msgcode['unbindVLANfromIPv6']['ERR'] = 111;
2474 function unbindVLANfromIPv6 ()
2475 {
2476 assertUIntArg ('id'); // network id
2477 global $sic;
2478 $result = commitReduceVLANIPv6 ($sic['vlan_ck'], $sic['id']);
2479 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2480 }
2481
2482 $msgcode['process8021QSyncRequest']['OK'] = 63;
2483 $msgcode['process8021QSyncRequest']['ERR'] = 191;
2484 function process8021QSyncRequest ()
2485 {
2486 // behave depending on current operation: exec8021QPull or exec8021QPush
2487 global $sic, $op;
2488 if (FALSE === $done = exec8021QDeploy ($sic['object_id'], $op == 'exec8021QPush'))
2489 return buildRedirectURL (__FUNCTION__, 'ERR');
2490 return buildRedirectURL (__FUNCTION__, 'OK', array ($done));
2491 }
2492
2493 $msgcode['process8021QRecalcRequest']['CHANGED'] = 87;
2494 $msgcode['process8021QRecalcRequest']['NO_CHANGES'] = 300;
2495 $msgcode['process8021QRecalcRequest']['ERR'] = 192;
2496 function process8021QRecalcRequest ()
2497 {
2498 assertUIntArg ('object_id');
2499 global $sic;
2500 if (! permitted (NULL, NULL, NULL, array (array ('tag' => '$op_recalc8021Q'))))
2501 return buildRedirectURL (__FUNCTION__, 'ERR');
2502 $counters = recalc8021QPorts ($sic['object_id']);
2503 if ($counters['ports'])
2504 return buildRedirectURL (__FUNCTION__, 'CHANGED', array ($counters['ports'], $counters['switches']));
2505 else
2506 return buildRedirectURL (__FUNCTION__, 'NO_CHANGES', array ('No changes were made'));
2507 }
2508
2509 $msgcode['resolve8021QConflicts']['OK'] = 63;
2510 $msgcode['resolve8021QConflicts']['ERR1'] = 179;
2511 $msgcode['resolve8021QConflicts']['ERR2'] = 109;
2512 function resolve8021QConflicts ()
2513 {
2514 global $sic, $dbxlink;
2515 assertUIntArg ('mutex_rev', TRUE); // counts from 0
2516 assertUIntArg ('nrows');
2517 // Divide submitted radio buttons into 3 groups:
2518 // left (saved version wins)
2519 // asis (ignore)
2520 // right (running version wins)
2521 $F = array();
2522 for ($i = 0; $i < $sic['nrows']; $i++)
2523 {
2524 if (!array_key_exists ("i_${i}", $sic))
2525 continue;
2526 // let's hope other inputs are in place
2527 switch ($sic["i_${i}"])
2528 {
2529 case 'left':
2530 case 'right':
2531 $F[$sic["pn_${i}"]] = array
2532 (
2533 'mode' => $sic["rm_${i}"],
2534 'allowed' => $sic["ra_${i}"],
2535 'native' => $sic["rn_${i}"],
2536 'decision' => $sic["i_${i}"],
2537 );
2538 break;
2539 default:
2540 // don't care
2541 }
2542 }
2543 $dbxlink->beginTransaction();
2544 try
2545 {
2546 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE'))
2547 throw new InvalidArgException ('object_id', $sic['object_id'], 'VLAN domain is not set for this object');
2548 if ($vswitch['mutex_rev'] != $sic['mutex_rev'])
2549 throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form (table data has changed)');
2550 $D = getStored8021QConfig ($vswitch['object_id'], 'desired');
2551 $C = getStored8021QConfig ($vswitch['object_id'], 'cached');
2552 $R = getRunning8021QConfig ($vswitch['object_id']);
2553 $plan = get8021QSyncOptions ($vswitch, $D, $C, $R['portdata']);
2554 $ndone = 0;
2555 foreach ($F as $port_name => $port)
2556 {
2557 if (!array_key_exists ($port_name, $plan))
2558 continue;
2559 elseif ($plan[$port_name]['status'] == 'merge_conflict')
2560 {
2561 // for R neither mutex nor revisions can be emulated, but revision change can be
2562 if (!same8021QConfigs ($port, $R['portdata'][$port_name]))
2563 throw new InvalidRequestArgException ("port ${port_name}", '(hidden)', 'expired form (switch data has changed)');
2564 if ($port['decision'] == 'right') // D wins, frame R by writing value of R to C
2565 $ndone += upd8021QPort ('cached', $vswitch['object_id'], $port_name, $port);
2566 elseif ($port['decision'] == 'left') // R wins, cross D up
2567 $ndone += upd8021QPort ('cached', $vswitch['object_id'], $port_name, $D[$port_name]);
2568 // otherwise there was no decision made
2569 }
2570 elseif
2571 (
2572 $plan[$port_name]['status'] == 'delete_conflict' or
2573 $plan[$port_name]['status'] == 'martian_conflict'
2574 )
2575 {
2576 if ($port['decision'] == 'left') // confirm deletion of local copy
2577 $ndone += del8021QPort ($vswitch['object_id'], $port_name);
2578 }
2579 // otherwise ignore a decision, which doesn't address a conflict
2580 }
2581 }
2582 catch (InvalidRequestArgException $e)
2583 {
2584 $dbxlink->rollBack();
2585 return buildRedirectURL (__FUNCTION__, 'ERR1');
2586 }
2587 catch (Exception $e)
2588 {
2589 $dbxlink->rollBack();
2590 return buildRedirectURL (__FUNCTION__, 'ERR2');
2591 }
2592 $dbxlink->commit();
2593 return buildRedirectURL (__FUNCTION__, 'OK', array ($ndone));
2594 }
2595
2596 $msgcode['addVLANSwitchTemplate']['OK'] = 48;
2597 $msgcode['addVLANSwitchTemplate']['ERR'] = 110;
2598 function addVLANSwitchTemplate()
2599 {
2600 assertStringArg ('vst_descr');
2601 global $sic;
2602 $max_local_vlans = NULL;
2603 if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans']))
2604 {
2605 assertUIntArg ('vst_maxvlans');
2606 $max_local_vlans = $sic['vst_maxvlans'];
2607 }
2608 $result = usePreparedInsertBlade
2609 (
2610 'VLANSwitchTemplate',
2611 array
2612 (
2613 'max_local_vlans' => $max_local_vlans,
2614 'description' => $sic['vst_descr'],
2615 )
2616 );
2617 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2618 }
2619
2620 $msgcode['delVLANSwitchTemplate']['OK'] = 49;
2621 $msgcode['delVLANSwitchTemplate']['ERR'] = 111;
2622 function delVLANSwitchTemplate()
2623 {
2624 assertUIntArg ('vst_id');
2625 global $sic;
2626 $result = FALSE !== usePreparedDeleteBlade ('VLANSwitchTemplate', array ('id' => $sic['vst_id']));
2627 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2628 }
2629
2630 $msgcode['updVLANSwitchTemplate']['OK'] = 51;
2631 $msgcode['updVLANSwitchTemplate']['ERR'] = 109;
2632 function updVLANSwitchTemplate()
2633 {
2634 assertUIntArg ('vst_id');
2635 assertStringArg ('vst_descr');
2636 global $sic;
2637 $max_local_vlans = NULL;
2638 if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans']))
2639 {
2640 assertUIntArg ('vst_maxvlans');
2641 $max_local_vlans = $sic['vst_maxvlans'];
2642 }
2643 $result = commitUpdateVST ($sic['vst_id'], $max_local_vlans, $sic['vst_descr']);
2644 return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR');
2645 }
2646
2647 $msgcode['cloneVSTRule']['OK'] = 48;
2648 $msgcode['cloneVSTRule']['ERR'] = 179;
2649 function cloneVSTRule()
2650 {
2651 global $dbxlink;
2652 $message = '';
2653 assertUIntArg ('vst_id');
2654 assertUIntArg ('mutex_rev', TRUE);
2655 $dst_vst = getVLANSwitchTemplate ($_REQUEST['vst_id']);
2656 if ($dst_vst['mutex_rev'] != $_REQUEST['mutex_rev'])
2657 $message = "User ${dst_vst['saved_by']} saved this template after you started to edit it. Please concern differencies";
2658 else
2659 {
2660 assertUIntArg ('from_id');
2661 $src_vst = getVLANSwitchTemplate ($_REQUEST['from_id']);
2662 if (! commitUpdateVSTRules ($_REQUEST['vst_id'], $src_vst['rules']))
2663 $message = 'DB error';
2664 }
2665 $result = !(BOOL) $message;
2666 if ($result)
2667 $message = 'Supplement succeeded';
2668 return buildWideRedirectURL (array (array ('code' => $result ? 'success' : 'error', 'message' => $message)));
2669 }
2670
2671 function updVSTRule()
2672 {
2673 global $port_role_options;
2674 assertUIntArg ('vst_id');
2675 assertUIntArg ('mutex_rev', TRUE);
2676 assertStringArg ('template_json');
2677 $message = '';
2678 $data = json_decode ($_POST['template_json'], TRUE);
2679 if (! isset ($data) or ! is_array ($data))
2680 $message = 'Invalid JSON code received from client';
2681 else
2682 {
2683 $rule_no = 0;
2684 foreach ($data as $rule)
2685 {
2686 $rule_no++;
2687 if (! isInteger ($rule['rule_no']))
2688 $message = 'Invalid rule number';
2689 elseif (! isPCRE ($rule['port_pcre']))
2690 $message = 'Invalid port regexp';
2691 elseif (! isset ($rule['port_role']) or ! array_key_exists ($rule['port_role'], $port_role_options))
2692 $message = 'Invalid port role';
2693 elseif (! isset ($rule['wrt_vlans']) or ! preg_match ('/^[ 0-9\-,]*$/', $rule['wrt_vlans']))
2694 $message = 'Invalid port vlan mask';
2695 elseif (! isset ($rule['description']))
2696 $message = 'Invalid description';
2697
2698 if ($message)
2699 {
2700 $message .= " in rule $rule_no";
2701 break;
2702 }
2703 }
2704 if (! $message)
2705 {
2706 $vst = getVLANSwitchTemplate ($_REQUEST['vst_id']);
2707 if ($vst['mutex_rev'] != $_REQUEST['mutex_rev'])
2708 $message = "User ${vst['saved_by']} saved this template after you started to edit it. Please concern differencies";
2709 }
2710 if (! $message)
2711 if (! commitUpdateVSTRules ($_REQUEST['vst_id'], $data))
2712 $message = 'DB update error';
2713 if ($message)
2714 $_SESSION['vst_edited'] = $data;
2715 }
2716 if ($message)
2717 {
2718 $result = FALSE;
2719 $message = "Template update failed: $message";
2720 }
2721 else
2722 {
2723 $result = TRUE;
2724 $message = "Update success";
2725 }
2726 return buildWideRedirectURL (array (array ('code' => $result ? 'success' : 'error', 'message' => $message)));
2727 }
2728
2729 $msgcode['importDPData']['OK'] = 44;
2730 function importDPData()
2731 {
2732 global $sic;
2733 assertUIntArg ('nports');
2734 $nignored = $ndone = 0;
2735 $POIFC = getPortOIFCompat();
2736 for ($i = 0; $i < $sic['nports']; $i++)
2737 if (array_key_exists ("do_${i}", $sic))
2738 {
2739 assertUIntArg ("pid1_${i}");
2740 assertUIntArg ("pid2_${i}");
2741 $porta = getPortInfo ($_REQUEST["pid1_${i}"]);
2742 $portb = getPortInfo ($_REQUEST["pid2_${i}"]);
2743 if
2744 (
2745 $porta['linked'] or
2746 $portb['linked'] or
2747 ($porta['object_id'] != $sic['object_id'] and $portb['object_id'] != $sic['object_id'])
2748 )
2749 {
2750 $nignored++;
2751 continue;
2752 }
2753 foreach ($POIFC as $item)
2754 if ($item['type1'] == $porta['oif_id'] and $item['type2'] == $portb['oif_id'])
2755 {
2756 linkPorts ($_REQUEST["pid1_${i}"], $_REQUEST["pid2_${i}"]);
2757 $ndone++;
2758 continue 2; // next port
2759 }
2760 $nignored++;
2761 }
2762 return buildRedirectURL (__FUNCTION__, 'OK', array ($nignored, $ndone));
2763 }
2764
2765 $msgcode['deleteObjectLog']['OK'] = 77;
2766 function deleteObjectLog ()
2767 {
2768 assertUIntArg ('logid');
2769 usePreparedDeleteBlade ('ObjectLog', array ('id' => $_REQUEST['logid']));
2770 return buildRedirectURL (__FUNCTION__, 'OK', array ('log entry'));
2771 }
2772
2773 $msgcode['addObjectlog']['OK'] = 0;
2774 function addObjectlog ()
2775 {
2776 assertUIntArg ('object_id');
2777 assertStringArg ('logentry');
2778 global $remote_username, $sic;
2779 $oi = spotEntity ('object', $sic['object_id']);
2780 usePreparedExecuteBlade ('INSERT INTO ObjectLog SET object_id=?, user=?, date=NOW(), content=?', array ($sic['object_id'], $remote_username, $sic['logentry']));
2781 $ob_url = makeHref (array ('page' => 'object', 'tab' => 'objectlog', 'object_id' => $sic['object_id']));
2782 return buildRedirectURL (__FUNCTION__, 'OK', array ("Log entry for <a href=" . ${ob_url} . ">${oi['dname']}</a> added by ${remote_username}"));
2783 }
2784
2785 function tableHandler ($opspec)
2786 {
2787 global $sic;
2788 if (!array_key_exists ('table', $opspec))
2789 throw new InvalidArgException ('opspec', '(malformed array structure)', '"table" not set');
2790 $columns = array();
2791 foreach ($opspec['arglist'] as $argspec)
2792 {
2793 genericAssertion ($argspec['url_argname'], $argspec['assertion']);
2794 // "table_colname" is normally used for an override, if it is not
2795 // set, use the URL argument name
2796 $table_colname = array_key_exists ('table_colname', $argspec) ?
2797 $argspec['table_colname'] :
2798 $argspec['url_argname'];
2799 $arg_value = $sic[$argspec['url_argname']];
2800 if
2801 (
2802 ($argspec['assertion'] == 'uint0' and $arg_value == 0)
2803 or ($argspec['assertion'] == 'string0' and $arg_value == '')
2804 )
2805 switch (TRUE)
2806 {
2807 case !array_key_exists ('if_empty', $argspec): // no action requested
2808 break;
2809 case $argspec['if_empty'] == 'NULL':
2810 $arg_value = NULL;
2811 break;
2812 // A trick below is likely to break non-INSERT queries.
2813 // case $argspec['if_empty'] == 'omit':
2814 // continue 2;
2815 default:
2816 throw new InvalidArgException ('opspec', '(malformed array structure)', '"if_empty" not recognized');
2817 }
2818 $columns[$table_colname] = $arg_value;
2819 }
2820 switch ($opspec['action'])
2821 {
2822 case 'INSERT':
2823 $retcode = TRUE === usePreparedInsertBlade ($opspec['table'], $columns) ? 48 : 110;
2824 break;
2825 default:
2826 throw new InvalidArgException ('opspec/action', '(malformed array structure)');
2827 }
2828 return buildWideRedirectURL (oneLiner ($retcode));
2829 }
2830
2831 ?>