r4079 process.php: fix function name
[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['createTag']['OK'] = 59;
1625 $msgcode['createTag']['ERR1'] = 145;
1626 $msgcode['createTag']['ERR3'] = 147;
1627 function createTag ()
1628 {
1629 assertStringArg ('tag_name');
1630 assertUIntArg ('parent_id', TRUE);
1631 $tagname = trim ($_REQUEST['tag_name']);
1632 if (!validTagName ($tagname))
1633 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($tagname));
1634 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1635 $parent_id = NULL;
1636 if (FALSE === commitCreateTag ($tagname, $parent_id))
1637 return buildRedirectURL (__FUNCTION__, 'ERR3', array (niftyString ($tagname)));
1638 return buildRedirectURL (__FUNCTION__, 'OK', array (niftyString ($tagname)));
1639 }
1640
1641 $msgcode['updateTag']['OK'] = 60;
1642 $msgcode['updateTag']['ERR1'] = 145;
1643 $msgcode['updateTag']['ERR2'] = 109;
1644 function updateTag ()
1645 {
1646 assertUIntArg ('tag_id');
1647 assertUIntArg ('parent_id', TRUE);
1648 assertStringArg ('tag_name');
1649 $tagname = trim ($_REQUEST['tag_name']);
1650 if (!validTagName ($tagname))
1651 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($tagname));
1652 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1653 $parent_id = 'NULL';
1654 if (FALSE !== commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id))
1655 return buildRedirectURL (__FUNCTION__, 'OK', array ($tagname));
1656 // Use old name in the message, cause update failed.
1657 global $taglist;
1658 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($taglist[$_REQUEST['tag_id']]['tag']));
1659 }
1660
1661 $msgcode['rollTags']['OK'] = 67;
1662 $msgcode['rollTags']['ERR'] = 149;
1663 function rollTags ()
1664 {
1665 assertUIntArg ('row_id');
1666 assertStringArg ('sum', TRUE);
1667 assertUIntArg ('realsum');
1668 if ($_REQUEST['sum'] != $_REQUEST['realsum'])
1669 return buildRedirectURL (__FUNCTION__, 'ERR');
1670 // Even if the user requested an empty tag list, don't bail out, but process existing
1671 // tag chains with "zero" extra. This will make sure, that the stuff processed will
1672 // have its chains refined to "normal" form.
1673 $extratags = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1674 $n_ok = 0;
1675 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
1676 // filter out the same tag again and again. It will have own noise to cancel.
1677 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
1678 foreach (listCells ('rack', $_REQUEST['row_id']) as $rack)
1679 {
1680 if (rebuildTagChainForEntity ('rack', $rack['id'], $extrachain))
1681 $n_ok++;
1682 amplifyCell ($rack);
1683 foreach ($rack['mountedObjects'] as $object_id)
1684 if (rebuildTagChainForEntity ('object', $object_id, $extrachain))
1685 $n_ok++;
1686 }
1687 return buildRedirectURL (__FUNCTION__, 'OK', array ($n_ok));
1688 }
1689
1690 $msgcode['changeMyPassword']['OK'] = 61;
1691 $msgcode['changeMyPassword']['ERR1'] = 150;
1692 $msgcode['changeMyPassword']['ERR2'] = 151;
1693 $msgcode['changeMyPassword']['ERR3'] = 152;
1694 $msgcode['changeMyPassword']['ERR4'] = 153;
1695 function changeMyPassword ()
1696 {
1697 global $remote_username, $user_auth_src;
1698 if ($user_auth_src != 'database')
1699 return buildRedirectURL (__FUNCTION__, 'ERR1');
1700 assertStringArg ('oldpassword');
1701 assertStringArg ('newpassword1');
1702 assertStringArg ('newpassword2');
1703 $remote_userid = getUserIDByUsername ($remote_username);
1704 $userinfo = spotEntity ('user', $remote_userid);
1705 if ($userinfo['user_password_hash'] != sha1 ($_REQUEST['oldpassword']))
1706 return buildRedirectURL (__FUNCTION__, 'ERR2');
1707 if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2'])
1708 return buildRedirectURL (__FUNCTION__, 'ERR3');
1709 if (FALSE !== commitUpdateUserAccount ($remote_userid, $userinfo['user_name'], $userinfo['user_realname'], sha1 ($_REQUEST['newpassword1'])))
1710 return buildRedirectURL (__FUNCTION__, 'OK');
1711 else
1712 return buildRedirectURL (__FUNCTION__, 'ERR4');
1713 }
1714
1715 $msgcode['saveRackCode']['OK'] = 43;
1716 $msgcode['saveRackCode']['ERR1'] = 154;
1717 $msgcode['saveRackCode']['ERR2'] = 155;
1718 function saveRackCode ()
1719 {
1720 assertStringArg ('rackcode');
1721 // For the test to succeed, unescape LFs, strip CRs.
1722 $newcode = dos2unix ($_REQUEST['rackcode']);
1723 $parseTree = getRackCode ($newcode);
1724 if ($parseTree['result'] != 'ACK')
1725 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($parseTree['load']));
1726 if (FALSE !== saveScript ('RackCode', $newcode))
1727 {
1728 saveScript ('RackCodeCache', base64_encode (serialize ($parseTree)));
1729 return buildRedirectURL (__FUNCTION__, 'OK');
1730 }
1731 return buildRedirectURL (__FUNCTION__, 'ERR2');
1732 }
1733
1734 $msgcode['setPortVLAN']['ERR1'] = 156;
1735 // This handler's context is pre-built, but not authorized. It is assumed, that the
1736 // handler will take existing context and before each commit check authorization
1737 // on the base chain plus necessary context added.
1738 function setPortVLAN ()
1739 {
1740 assertUIntArg ('portcount');
1741 $data = getSwitchVLANs ($_REQUEST['object_id']);
1742 if ($data === NULL)
1743 return buildRedirectURL (__FUNCTION__, 'ERR1');
1744 list ($vlanlist, $portlist) = $data;
1745 // Here we just build up 1 set command for the gateway with all of the ports
1746 // included. The gateway is expected to filter unnecessary changes silently
1747 // and to provide a list of responses with either error or success message
1748 // for each of the rest.
1749 $nports = $_REQUEST['portcount'];
1750 $prefix = 'set ';
1751 $log = emptyLog();
1752 $setcmd = '';
1753 for ($i = 0; $i < $nports; $i++)
1754 if
1755 (
1756 !isset ($_REQUEST['portname_' . $i]) ||
1757 !isset ($_REQUEST['vlanid_' . $i]) ||
1758 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
1759 )
1760 $log['m'][] = array ('c' => 158, 'a' => array ($i));
1761 elseif
1762 (
1763 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
1764 $portlist[$i]['vlaind'] == 'TRUNK'
1765 )
1766 continue;
1767 else
1768 {
1769 $portname = $_REQUEST['portname_' . $i];
1770 $oldvlanid = $portlist[$i]['vlanid'];
1771 $newvlanid = $_REQUEST['vlanid_' . $i];
1772 if
1773 (
1774 !permitted (NULL, NULL, NULL, array (array ('tag' => '$fromvlan_' . $oldvlanid))) or
1775 !permitted (NULL, NULL, NULL, array (array ('tag' => '$tovlan_' . $newvlanid)))
1776 )
1777 {
1778 $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid));
1779 continue;
1780 }
1781 $setcmd .= $prefix . $portname . '=' . $newvlanid;
1782 $prefix = ';';
1783 }
1784 // Feed the gateway and interpret its (non)response.
1785 if ($setcmd != '')
1786 $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd));
1787 else
1788 $log['m'][] = array ('c' => 201);
1789 return buildWideRedirectURL ($log);
1790 }
1791
1792 $msgcode['submitSLBConfig']['OK'] = 66;
1793 $msgcode['submitSLBConfig']['ERR'] = 164;
1794 function submitSLBConfig ()
1795 {
1796 assertUIntArg ('object_id');
1797 $newconfig = buildLVSConfig ($_REQUEST['object_id']);
1798 try
1799 {
1800 gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8'));
1801 }
1802 catch (RTGatewayError $e)
1803 {
1804 return buildRedirectURL (__FUNCTION__, 'ERR', array ($e->getMessage()));
1805 }
1806 return buildRedirectURL (__FUNCTION__, 'OK', array ('slbconfig'));
1807 }
1808
1809 $msgcode['updateRow']['OK'] = 75;
1810 $msgcode['updateRow']['ERR'] = 100;
1811 function updateRow ()
1812 {
1813 assertUIntArg ('row_id');
1814 assertStringArg ('name');
1815
1816 if (FALSE !== commitUpdateRow ($_REQUEST['row_id'], $_REQUEST['name']))
1817 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name']));
1818 else
1819 return buildRedirectURL (__FUNCTION__, 'ERR', array ($_REQUEST['name']));
1820 }
1821
1822 $msgcode['deleteRow']['OK'] = 77;
1823 $msgcode['deleteRow']['ERR'] = 146;
1824 function deleteRow ()
1825 {
1826 assertUIntArg ('row_id');
1827 $rowinfo = getRackRowInfo ($_REQUEST['row_id']);
1828 return buildRedirectURL (__FUNCTION__, FALSE === commitDeleteRow ($_REQUEST['row_id']) ? 'ERR' : 'OK', array ($rowinfo['name']));
1829 }
1830
1831 $msgcode['addRack']['OK'] = 65;
1832 $msgcode['addRack']['ERR1'] = 171;
1833 $msgcode['addRack']['ERR2'] = 172;
1834 function addRack ()
1835 {
1836 assertUIntArg ('row_id');
1837 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1838 if (isset ($_REQUEST['got_data']))
1839 {
1840 assertStringArg ('rack_name');
1841 assertUIntArg ('rack_height1');
1842 assertStringArg ('rack_comment', TRUE);
1843
1844 if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
1845 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name']));
1846 else
1847 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($_REQUEST['rack_name']));
1848 }
1849 elseif (isset ($_REQUEST['got_mdata']))
1850 {
1851 assertUIntArg ('rack_height2');
1852 assertStringArg ('rack_names', TRUE);
1853 $log = emptyLog();
1854 // copy-and-paste from renderAddMultipleObjectsForm()
1855 $names1 = explode ("\n", $_REQUEST['rack_names']);
1856 $names2 = array();
1857 foreach ($names1 as $line)
1858 {
1859 $parts = explode ('\r', $line);
1860 reset ($parts);
1861 if (!strlen ($parts[0]))
1862 continue;
1863 else
1864 $names2[] = rtrim ($parts[0]);
1865 }
1866 global $msgcode;
1867 foreach ($names2 as $cname)
1868 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE)
1869 $log['m'][] = array ('c' => $msgcode[__FUNCTION__]['OK'], 'a' => array ($cname));
1870 else
1871 $log['m'][] = array ('c' => $msgcode[__FUNCTION__]['ERR1'], 'a' => array ($cname));
1872 return buildWideRedirectURL ($log);
1873 }
1874 else
1875 return buildRedirectURL (__FUNCTION__, 'ERR2');
1876 }
1877
1878 $msgcode['deleteRack']['OK'] = 79;
1879 $msgcode['deleteRack']['ERR'] = 100;
1880 $msgcode['deleteRack']['ERR1'] = 206;
1881 function deleteRack ()
1882 {
1883 assertUIntArg ('rack_id');
1884 if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id'])))
1885 return buildRedirectURL (__FUNCTION__, 'ERR', array ('Rack not found'), 'rackspace', 'default');
1886 amplifyCell ($rackData);
1887 if (count ($rackData['mountedObjects']))
1888 return buildRedirectURL (__FUNCTION__, 'ERR1');
1889 if (TRUE !== commitDeleteRack ($_REQUEST['rack_id']))
1890 return buildRedirectURL (__FUNCTION__, 'ERR', array(), 'rackspace', 'default');
1891 return buildRedirectURL (__FUNCTION__, 'OK', array ($rackData['name']), 'rackspace', 'default');
1892 }
1893
1894 $msgcode['updateRack']['OK'] = 68;
1895 $msgcode['updateRack']['ERR'] = 177;
1896 function updateRack ()
1897 {
1898 assertUIntArg ('rack_id');
1899 assertUIntArg ('rack_row_id');
1900 assertUIntArg ('rack_height');
1901 assertStringArg ('rack_name');
1902 assertStringArg ('rack_comment', TRUE);
1903
1904 resetThumbCache ($_REQUEST['rack_id']);
1905 if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
1906 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name']));
1907 else
1908 return buildRedirectURL (__FUNCTION__, 'ERR');
1909 }
1910
1911 function updateRackDesign ()
1912 {
1913 assertUIntArg ('rack_id');
1914 $rackData = spotEntity ('rack', $_REQUEST['rack_id']);
1915 amplifyCell ($rackData);
1916 applyRackDesignMask($rackData);
1917 markupObjectProblems ($rackData);
1918 $response = processGridForm ($rackData, 'A', 'F');
1919 return buildWideRedirectURL (array($response));
1920 }
1921
1922 function updateRackProblems ()
1923 {
1924 assertUIntArg ('rack_id');
1925 $rackData = spotEntity ('rack', $_REQUEST['rack_id']);
1926 amplifyCell ($rackData);
1927 applyRackProblemMask($rackData);
1928 markupObjectProblems ($rackData);
1929 $response = processGridForm ($rackData, 'F', 'U');
1930 return buildWideRedirectURL (array($response));
1931 }
1932
1933 function querySNMPData ()
1934 {
1935 assertUIntArg ('object_id');
1936 assertStringArg ('community', TRUE);
1937
1938 $snmpsetup = array ();
1939 if ( strlen($_REQUEST['community']) == 0 ) {
1940 assertStringArg ('sec_name');
1941 assertStringArg ('sec_level');
1942 assertStringArg ('auth_protocol');
1943 assertStringArg ('auth_passphrase', TRUE);
1944 assertStringArg ('priv_protocol');
1945 assertStringArg ('priv_passphrase', TRUE);
1946
1947 $snmpsetup['sec_name'] = $_REQUEST['sec_name'];
1948 $snmpsetup['sec_level'] = $_REQUEST['sec_level'];
1949 $snmpsetup['auth_protocol'] = $_REQUEST['auth_protocol'];
1950 $snmpsetup['auth_passphrase'] = $_REQUEST['auth_passphrase'];
1951 $snmpsetup['priv_protocol'] = $_REQUEST['priv_protocol'];
1952 $snmpsetup['priv_passphrase'] = $_REQUEST['priv_passphrase'];
1953 }
1954 else {
1955 $snmpsetup['community'] = $_REQUEST['community'];
1956 }
1957
1958
1959 return doSNMPmining ($_REQUEST['object_id'], $snmpsetup);
1960 }
1961
1962 $msgcode['addFileWithoutLink']['OK'] = 69;
1963 $msgcode['addFileWithoutLink']['ERR1'] = 181;
1964 $msgcode['addFileWithoutLink']['ERR2'] = 110;
1965 // File-related functions
1966 function addFileWithoutLink ()
1967 {
1968 assertStringArg ('comment', TRUE);
1969
1970 // Make sure the file can be uploaded
1971 if (get_cfg_var('file_uploads') != 1)
1972 return buildRedirectURL (__FUNCTION__, 'ERR1');
1973
1974 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1975 global $sic;
1976 if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']))
1977 return buildRedirectURL (__FUNCTION__, 'ERR2');
1978 if (isset ($_REQUEST['taglist']))
1979 produceTagsForLastRecord ('file', $_REQUEST['taglist']);
1980 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($_FILES['file']['name'])));
1981 }
1982
1983 $msgcode['addFileToEntity']['OK'] = 69;
1984 $msgcode['addFileToEntity']['ERR2'] = 181;
1985 $msgcode['addFileToEntity']['ERR3'] = 110;
1986 function addFileToEntity ()
1987 {
1988 global $page, $pageno, $etype_by_pageno;
1989 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1990 throw new RackTablesError ('dispatching failure', RackTablesError::INTERNAL);
1991 $realm = $etype_by_pageno[$pageno];
1992 $bypass = $page[$pageno]['bypass'];
1993 assertUIntArg ($bypass);
1994 $entity_id = $_REQUEST[$bypass];
1995 assertStringArg ('comment', TRUE);
1996
1997 // Make sure the file can be uploaded
1998 if (get_cfg_var('file_uploads') != 1)
1999 return buildRedirectURL (__FUNCTION__, 'ERR2');
2000
2001 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
2002 global $sic;
2003 if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']))
2004 return buildRedirectURL (__FUNCTION__, 'ERR3');
2005 if (FALSE === commitLinkFile (lastInsertID(), $realm, $entity_id))
2006 return buildRedirectURL (__FUNCTION__, 'ERR3');
2007
2008 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($_FILES['file']['name'])));
2009 }
2010
2011 $msgcode['linkFileToEntity']['OK'] = 71;
2012 $msgcode['linkFileToEntity']['ERR1'] = 178;
2013 $msgcode['linkFileToEntity']['ERR2'] = 110;
2014 function linkFileToEntity ()
2015 {
2016 assertUIntArg ('file_id');
2017 global $page, $pageno, $etype_by_pageno;
2018 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
2019 throw new RackTablesError ('dispatching failure', RackTablesError::INTERNAL);
2020 $entity_type = $etype_by_pageno[$pageno];
2021 $bypass_name = $page[$pageno]['bypass'];
2022 assertUIntArg ($bypass_name);
2023
2024 $fi = spotEntity ('file', $_REQUEST['file_id']);
2025 if (FALSE === commitLinkFile ($_REQUEST['file_id'], $entity_type, $_REQUEST[$bypass_name]))
2026 return buildRedirectURL (__FUNCTION__, 'ERR2');
2027
2028 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($fi['name'])));
2029 }
2030
2031 $msgcode['replaceFile']['OK'] = 70;
2032 $msgcode['replaceFile']['ERR1'] = 181;
2033 $msgcode['replaceFile']['ERR2'] = 207;
2034 $msgcode['replaceFile']['ERR3'] = 109;
2035 function replaceFile ()
2036 {
2037 global $sic;
2038 assertUIntArg ('file_id');
2039
2040 // Make sure the file can be uploaded
2041 if (get_cfg_var('file_uploads') != 1)
2042 return buildRedirectURL (__FUNCTION__, 'ERR1');
2043 $shortInfo = spotEntity ('file', $sic['file_id']);
2044
2045 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
2046 if ($fp === FALSE)
2047 return buildRedirectURL (__FUNCTION__, 'ERR2');
2048 if (FALSE === commitReplaceFile ($sic['file_id'], $fp))
2049 return buildRedirectURL (__FUNCTION__, 'ERR3');
2050
2051 usePreparedExecuteBlade
2052 (
2053 'UPDATE File SET thumbnail = NULL WHERE id = ?',
2054 $sic['file_id']
2055 );
2056
2057 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
2058 }
2059
2060 $msgcode['updateFile']['OK'] = 70;
2061 $msgcode['updateFile']['ERR'] = 109;
2062 function updateFile ()
2063 {
2064 assertUIntArg ('file_id');
2065 assertStringArg ('file_name');
2066 assertStringArg ('file_type');
2067 assertStringArg ('file_comment', TRUE);
2068 global $sic;
2069 if (FALSE === commitUpdateFile ($sic['file_id'], $sic['file_name'], $sic['file_type'], $sic['file_comment']))
2070 return buildRedirectURL (__FUNCTION__, 'ERR');
2071 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['file_name']));
2072 }
2073
2074 $msgcode['unlinkFile']['OK'] = 72;
2075 $msgcode['unlinkFile']['ERR'] = 182;
2076 function unlinkFile ()
2077 {
2078 assertUIntArg ('link_id');
2079 $error = commitUnlinkFile ($_REQUEST['link_id']);
2080
2081 if ($error != '')
2082 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
2083
2084 return buildRedirectURL (__FUNCTION__, 'OK');
2085 }
2086
2087 $msgcode['deleteFile']['OK'] = 73;
2088 $msgcode['deleteFile']['ERR'] = 100;
2089 function deleteFile ()
2090 {
2091 assertUIntArg ('file_id');
2092 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
2093 $error = commitDeleteFile ($_REQUEST['file_id']);
2094
2095 if ($error != '')
2096 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
2097
2098 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
2099 }
2100
2101 $msgcode['updateFileText']['OK'] = 78;
2102 $msgcode['updateFileText']['ERR1'] = 179;
2103 $msgcode['updateFileText']['ERR2'] = 180;
2104 function updateFileText ()
2105 {
2106 assertUIntArg ('file_id');
2107 assertStringArg ('mtime_copy');
2108 assertStringArg ('file_text', TRUE); // it's Ok to save empty
2109 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
2110 if ($shortInfo['mtime'] != $_REQUEST['mtime_copy'])
2111 return buildRedirectURL (__FUNCTION__, 'ERR1');
2112 global $sic;
2113 if (FALSE === commitReplaceFile ($sic['file_id'], $sic['file_text']))
2114 return buildRedirectURL (__FUNCTION__, 'ERR2');
2115 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
2116 }
2117
2118 $msgcode['addPortInterfaceCompat']['OK'] = 48;
2119 $msgcode['addPortInterfaceCompat']['ERR'] = 110;
2120 function addPortInterfaceCompat ()
2121 {
2122 assertUIntArg ('iif_id');
2123 assertUIntArg ('oif_id');
2124 if (commitSupplementPIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
2125 return buildRedirectURL (__FUNCTION__, 'OK');
2126 return buildRedirectURL (__FUNCTION__, 'ERR');
2127 }
2128
2129 $msgcode['delPortInterfaceCompat']['OK'] = 49;
2130 $msgcode['delPortInterfaceCompat']['ERR'] = 111;
2131 function delPortInterfaceCompat ()
2132 {
2133 assertUIntArg ('iif_id');
2134 assertUIntArg ('oif_id');
2135 if (commitReducePIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
2136 return buildRedirectURL (__FUNCTION__, 'OK');
2137 return buildRedirectURL (__FUNCTION__, 'ERR');
2138 }
2139
2140 $ifcompatpack = array
2141 (
2142 '1000cwdm80' => array (1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216),
2143 '1000dwdm80' => array // ITU channels 20~61
2144 (
2145 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226,
2146 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236,
2147 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246,
2148 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256,
2149 1257, 1258
2150 ),
2151 '10000dwdm80' => array // same channels for 10GE
2152 (
2153 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268,
2154 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278,
2155 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288,
2156 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298,
2157 1299, 1300
2158 ),
2159 );
2160
2161 $msgcode['addPortInterfaceCompatPack']['OK'] = 44;
2162 $msgcode['addPortInterfaceCompatPack']['ERR'] = 123;
2163 function addPortInterfaceCompatPack ()
2164 {
2165 assertStringArg ('standard');
2166 assertUIntArg ('iif_id');
2167 global $ifcompatpack;
2168 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
2169 return buildRedirectURL (__FUNCTION__, 'ERR');
2170 $ngood = $nbad = 0;
2171 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2172 if (commitSupplementPIC ($_REQUEST['iif_id'], $oif_id))
2173 $ngood++;
2174 else
2175 $nbad++;
2176 return buildRedirectURL (__FUNCTION__, 'OK', array ($nbad, $ngood));
2177 }
2178
2179 $msgcode['delPortInterfaceCompatPack']['OK'] = 44;
2180 $msgcode['delPortInterfaceCompatPack']['ERR'] = 123;
2181 function delPortInterfaceCompatPack ()
2182 {
2183 assertStringArg ('standard');
2184 assertUIntArg ('iif_id');
2185 global $ifcompatpack;
2186 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
2187 return buildRedirectURL (__FUNCTION__, 'ERR');
2188 $ngood = $nbad = 0;
2189 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2190 if (commitReducePIC ($_REQUEST['iif_id'], $oif_id))
2191 $ngood++;
2192 else
2193 $nbad++;
2194 return buildRedirectURL (__FUNCTION__, 'OK', array ($nbad, $ngood));
2195 }
2196
2197 $msgcode['addPortOIFCompat']['OK'] = 48;
2198 $msgcode['addPortOIFCompat']['ERR'] = 110;
2199 function addPortOIFCompat()
2200 {
2201 assertUIntArg('type1');
2202 assertUIntArg('type2');
2203 if (commitSupplementPOIFC($_REQUEST['type1'], $_REQUEST['type2']))
2204 return buildRedirectURL(__FUNCTION__, 'OK');
2205 return buildRedirectURL(__FUNCTION__, 'ERR');
2206 }
2207
2208 $msgcode['delPortOIFCompat']['OK'] = 49;
2209 $msgcode['delPortOIFCompat']['ERR'] = 111;
2210 function delPortOIFCompat ()
2211 {
2212 assertUIntArg('type1');
2213 assertUIntArg('type2');
2214 if (commitReducePOIFC ($_REQUEST['type1'], $_REQUEST['type2']) !== FALSE)
2215 return buildRedirectURL (__FUNCTION__, 'OK');
2216 return buildRedirectURL (__FUNCTION__, 'ERR');
2217
2218 }
2219
2220 $msgcode['add8021QOrder']['OK'] = 48;
2221 $msgcode['add8021QOrder']['ERR'] = 118;
2222 function add8021QOrder ()
2223 {
2224 assertUIntArg ('vdom_id');
2225 assertUIntArg ('object_id');
2226 assertUIntArg ('vst_id');
2227 global $sic;
2228 $result = usePreparedExecuteBlade
2229 (
2230 'INSERT INTO VLANSwitch (domain_id, object_id, template_id, last_change, out_of_sync) ' .
2231 'VALUES (?, ?, ?, NOW(), "yes")',
2232 array ($sic['vdom_id'], $sic['object_id'], $sic['vst_id'])
2233 );
2234 return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR');
2235 }
2236
2237 $msgcode['del8021QOrder']['OK'] = 49;
2238 $msgcode['del8021QOrder']['ERR'] = 119;
2239 function del8021QOrder ()
2240 {
2241 assertUIntArg ('object_id');
2242 assertUIntArg ('vdom_id');
2243 assertUIntArg ('vst_id');
2244 global $sic;
2245 $result = usePreparedDeleteBlade ('VLANSwitch', array ('object_id' => $sic['object_id']));
2246 $focus_hints = array
2247 (
2248 'prev_objid' => $_REQUEST['object_id'],
2249 'prev_vstid' => $_REQUEST['vst_id'],
2250 'prev_vdid' => $_REQUEST['vdom_id'],
2251 );
2252 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR', array(), NULL, NULL, $focus_hints);
2253 }
2254
2255 $msgcode['addVLANDescription']['OK'] = 48;
2256 $msgcode['addVLANDescription']['ERR1'] = 190;
2257 $msgcode['addVLANDescription']['ERR2'] = 110;
2258 function addVLANDescription ()
2259 {
2260 assertUIntArg ('vlan_id');
2261 assertStringArg ('vlan_type', TRUE);
2262 assertStringArg ('vlan_descr', TRUE);
2263 global $sic;
2264 if (!($sic['vlan_id'] >= VLAN_MIN_ID + 1 and $sic['vlan_id'] <= VLAN_MAX_ID))
2265 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($sic['vlan_id']));
2266 $result = usePreparedInsertBlade
2267 (
2268 'VLANDescription',
2269 array
2270 (
2271 'domain_id' => $sic['vdom_id'],
2272 'vlan_id' => $sic['vlan_id'],
2273 'vlan_type' => $sic['vlan_type'],
2274 'vlan_descr' => mb_strlen ($sic['vlan_descr']) ? $sic['vlan_descr'] : NULL
2275 )
2276 );
2277 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR2');
2278 }
2279
2280 $msgcode['delVLANDescription']['OK'] = 49;
2281 $msgcode['delVLANDescription']['ERR1'] = 105;
2282 $msgcode['delVLANDescription']['ERR2'] = 111;
2283 function delVLANDescription ()
2284 {
2285 assertUIntArg ('vlan_id');
2286 global $sic;
2287 if ($sic['vlan_id'] == VLAN_DFL_ID)
2288 return buildRedirectURL (__FUNCTION__, 'ERR1');
2289 $result = commitReduceVLANDescription ($sic['vdom_id'], $sic['vlan_id']);
2290 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR2');
2291 }
2292
2293 $msgcode['updVLANDescription']['OK'] = 51;
2294 $msgcode['updVLANDescription']['ERR1'] = 105;
2295 $msgcode['updVLANDescription']['ERR2'] = 109;
2296 function updVLANDescription ()
2297 {
2298 assertUIntArg ('vlan_id');
2299 assertStringArg ('vlan_type');
2300 assertStringArg ('vlan_descr', TRUE);
2301 global $sic;
2302 if ($sic['vlan_id'] == VLAN_DFL_ID)
2303 return buildRedirectURL (__FUNCTION__, 'ERR1');
2304 $result = commitUpdateVLANDescription
2305 (
2306 $sic['vdom_id'],
2307 $sic['vlan_id'],
2308 $sic['vlan_type'],
2309 $sic['vlan_descr']
2310 );
2311 return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR2');
2312 }
2313
2314 $msgcode['createVLANDomain']['OK'] = 48;
2315 $msgcode['createVLANDomain']['ERR'] = 110;
2316 function createVLANDomain ()
2317 {
2318 assertStringArg ('vdom_descr');
2319 global $sic;
2320 $result = usePreparedInsertBlade
2321 (
2322 'VLANDomain',
2323 array
2324 (
2325 'description' => $sic['vdom_descr'],
2326 )
2327 );
2328 $result = $result and usePreparedInsertBlade
2329 (
2330 'VLANDescription',
2331 array
2332 (
2333 'domain_id' => lastInsertID(),
2334 'vlan_id' => VLAN_DFL_ID,
2335 'vlan_type' => 'compulsory',
2336 'vlan_descr' => 'default',
2337 )
2338 );
2339 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2340 }
2341
2342 $msgcode['destroyVLANDomain']['OK'] = 49;
2343 $msgcode['destroyVLANDomain']['ERR'] = 111;
2344 function destroyVLANDomain ()
2345 {
2346 assertUIntArg ('vdom_id');
2347 global $sic;
2348 $result = FALSE !== usePreparedDeleteBlade ('VLANDomain', array ('id' => $sic['vdom_id']));
2349 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2350 }
2351
2352 $msgcode['updateVLANDomain']['OK'] = 51;
2353 $msgcode['updateVLANDomain']['ERR'] = 109;
2354 function updateVLANDomain ()
2355 {
2356 assertUIntArg ('vdom_id');
2357 assertStringArg ('vdom_descr');
2358 global $sic;
2359 $result = FALSE !== commitUpdateVLANDomain ($sic['vdom_id'], $sic['vdom_descr']);
2360 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2361 }
2362
2363 $msgcode['save8021QPorts']['OK1'] = 63;
2364 $msgcode['save8021QPorts']['OK2'] = 41;
2365 $msgcode['save8021QPorts']['ERR1'] = 160;
2366 $msgcode['save8021QPorts']['ERR2'] = 109;
2367 function save8021QPorts ()
2368 {
2369 global $sic, $dbxlink;
2370 assertUIntArg ('mutex_rev', TRUE); // counts from 0
2371 assertStringArg ('form_mode');
2372 if ($sic['form_mode'] != 'save' and $sic['form_mode'] != 'duplicate')
2373 throw new InvalidRequestArgException ('form_mode', $sic['form_mode']);
2374 $extra = array();
2375 $dbxlink->beginTransaction();
2376 try
2377 {
2378 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE'))
2379 throw new InvalidArgException ('object_id', $object_id, 'VLAN domain is not set for this object');
2380 if ($vswitch['mutex_rev'] != $sic['mutex_rev'])
2381 throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form data');
2382 $after = $before = apply8021QOrder ($vswitch['template_id'], getStored8021QConfig ($sic['object_id'], 'desired'));
2383 $changes = array();
2384 switch ($sic['form_mode'])
2385 {
2386 case 'save':
2387 assertUIntArg ('nports');
2388 if ($sic['nports'] == 1)
2389 {
2390 assertStringArg ('pn_0');
2391 $extra = array ('port_name' => $sic['pn_0']);
2392 }
2393 for ($i = 0; $i < $sic['nports']; $i++)
2394 {
2395 assertStringArg ('pn_' . $i);
2396 assertStringArg ('pm_' . $i);
2397 // An access port only generates form input for its native VLAN,
2398 // which we derive allowed VLAN list from.
2399 $native = isset ($sic['pnv_' . $i]) ? $sic['pnv_' . $i] : 0;
2400 switch ($sic["pm_${i}"])
2401 {
2402 case 'trunk':
2403 # assertArrayArg ('pav_' . $i);
2404 $allowed = isset ($sic['pav_' . $i]) ? $sic['pav_' . $i] : array();
2405 break;
2406 case 'access':
2407 if ($native == 'same')
2408 continue 2;
2409 assertUIntArg ('pnv_' . $i);
2410 $allowed = array ($native);
2411 break;
2412 default:
2413 throw new InvalidRequestArgException ("pm_${i}", $_REQUEST["pm_${i}"], 'unknown port mode');
2414 }
2415 $changes[$sic['pn_' . $i]] = array
2416 (
2417 'mode' => $sic['pm_' . $i],
2418 'allowed' => $allowed,
2419 'native' => $native,
2420 );
2421 }
2422 break;
2423 case 'duplicate':
2424 assertStringArg ('from_port');
2425 # assertArrayArg ('to_ports');
2426 if (!array_key_exists ($sic['from_port'], $before))
2427 throw new InvalidArgException ('from_port', $sic['from_port'], 'this port does not exist');
2428 foreach ($sic['to_ports'] as $tpn)
2429 if (!array_key_exists ($tpn, $before))
2430 throw new InvalidArgException ('to_ports[]', $tpn, 'this port does not exist');
2431 elseif ($tpn != $sic['from_port'])
2432 $changes[$tpn] = $before[$sic['from_port']];
2433 break;
2434 }
2435 $domain_vlanlist = getDomainVLANs ($vswitch['domain_id']);
2436 $changes = filter8021QChangeRequests
2437 (
2438 $domain_vlanlist,
2439 $before,
2440 apply8021QOrder ($vswitch['template_id'], $changes)
2441 );
2442 $changes = authorize8021QChangeRequests ($before, $changes);
2443 foreach ($changes as $port_name => $port)
2444 $after[$port_name] = $port;
2445 $new_uplinks = filter8021QChangeRequests ($domain_vlanlist, $after, produceUplinkPorts ($domain_vlanlist, $after));
2446 $npulled = replace8021QPorts ('desired', $vswitch['object_id'], $before, $changes);
2447 $nsaved_uplinks = replace8021QPorts ('desired', $vswitch['object_id'], $before, $new_uplinks);
2448 }
2449 catch (Exception $e)
2450 {
2451 $dbxlink->rollBack();
2452 return buildRedirectURL (__FUNCTION__, 'ERR2', array(), NULL, NULL, $extra);
2453 }
2454 if ($npulled + $nsaved_uplinks)
2455 $result = usePreparedExecuteBlade
2456 (
2457 'UPDATE VLANSwitch SET mutex_rev=mutex_rev+1, last_change=NOW(), out_of_sync="yes" WHERE object_id=?',
2458 array ($sic['object_id'])
2459 );
2460 $dbxlink->commit();
2461 $log = oneLiner (63, array ($npulled + $nsaved_uplinks));
2462 if ($nsaved_uplinks)
2463 {
2464 initiateUplinksReverb ($vswitch['object_id'], $new_uplinks);
2465 $log = mergeLogs ($log, oneLiner (41));
2466 }
2467 if ($npulled + $nsaved_uplinks > 0 and getConfigVar ('8021Q_INSTANT_DEPLOY') == 'yes')
2468 {
2469 try
2470 {
2471 if (FALSE === $done = exec8021QDeploy ($sic['object_id'], TRUE))
2472 $log = mergeLogs ($log, oneLiner (191));
2473 else
2474 $log = mergeLogs ($log, oneLiner (63, array ($done)));
2475 }
2476 catch (Exception $e)
2477 {
2478 $log = mergeLogs ($log, oneLiner (109));
2479 }
2480 }
2481 return buildWideRedirectURL ($log, NULL, NULL, $extra);
2482 }
2483
2484 $msgcode['bindVLANtoIPv4']['OK'] = 48;
2485 $msgcode['bindVLANtoIPv4']['ERR'] = 110;
2486 function bindVLANtoIPv4 ()
2487 {
2488 assertUIntArg ('id'); // network id
2489 global $sic;
2490 $result = commitSupplementVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2491 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2492 }
2493
2494 $msgcode['bindVLANtoIPv6']['OK'] = 48;
2495 $msgcode['bindVLANtoIPv6']['ERR'] = 110;
2496 function bindVLANtoIPv6 ()
2497 {
2498 assertUIntArg ('id'); // network id
2499 global $sic;
2500 $result = commitSupplementVLANIPv6 ($sic['vlan_ck'], $_REQUEST['id']);
2501 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2502 }
2503
2504 $msgcode['unbindVLANfromIPv4']['OK'] = 49;
2505 $msgcode['unbindVLANfromIPv4']['ERR'] = 111;
2506 function unbindVLANfromIPv4 ()
2507 {
2508 assertUIntArg ('id'); // network id
2509 global $sic;
2510 $result = commitReduceVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2511 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2512 }
2513
2514 $msgcode['unbindVLANfromIPv6']['OK'] = 49;
2515 $msgcode['unbindVLANfromIPv6']['ERR'] = 111;
2516 function unbindVLANfromIPv6 ()
2517 {
2518 assertUIntArg ('id'); // network id
2519 global $sic;
2520 $result = commitReduceVLANIPv6 ($sic['vlan_ck'], $sic['id']);
2521 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2522 }
2523
2524 $msgcode['process8021QSyncRequest']['OK'] = 63;
2525 $msgcode['process8021QSyncRequest']['ERR'] = 191;
2526 function process8021QSyncRequest ()
2527 {
2528 // behave depending on current operation: exec8021QPull or exec8021QPush
2529 global $sic, $op;
2530 if (FALSE === $done = exec8021QDeploy ($sic['object_id'], $op == 'exec8021QPush'))
2531 return buildRedirectURL (__FUNCTION__, 'ERR');
2532 return buildRedirectURL (__FUNCTION__, 'OK', array ($done));
2533 }
2534
2535 $msgcode['process8021QRecalcRequest']['CHANGED'] = 87;
2536 $msgcode['process8021QRecalcRequest']['NO_CHANGES'] = 300;
2537 $msgcode['process8021QRecalcRequest']['ERR'] = 192;
2538 function process8021QRecalcRequest ()
2539 {
2540 assertUIntArg ('object_id');
2541 global $sic;
2542 if (! permitted (NULL, NULL, NULL, array (array ('tag' => '$op_recalc8021Q'))))
2543 return buildRedirectURL (__FUNCTION__, 'ERR');
2544 $counters = recalc8021QPorts ($sic['object_id']);
2545 if ($counters['ports'])
2546 return buildRedirectURL (__FUNCTION__, 'CHANGED', array ($counters['ports'], $counters['switches']));
2547 else
2548 return buildRedirectURL (__FUNCTION__, 'NO_CHANGES', array ('No changes were made'));
2549 }
2550
2551 $msgcode['resolve8021QConflicts']['OK'] = 63;
2552 $msgcode['resolve8021QConflicts']['ERR1'] = 179;
2553 $msgcode['resolve8021QConflicts']['ERR2'] = 109;
2554 function resolve8021QConflicts ()
2555 {
2556 global $sic, $dbxlink;
2557 assertUIntArg ('mutex_rev', TRUE); // counts from 0
2558 assertUIntArg ('nrows');
2559 // Divide submitted radio buttons into 3 groups:
2560 // left (saved version wins)
2561 // asis (ignore)
2562 // right (running version wins)
2563 $F = array();
2564 for ($i = 0; $i < $sic['nrows']; $i++)
2565 {
2566 if (!array_key_exists ("i_${i}", $sic))
2567 continue;
2568 // let's hope other inputs are in place
2569 switch ($sic["i_${i}"])
2570 {
2571 case 'left':
2572 case 'right':
2573 $F[$sic["pn_${i}"]] = array
2574 (
2575 'mode' => $sic["rm_${i}"],
2576 'allowed' => $sic["ra_${i}"],
2577 'native' => $sic["rn_${i}"],
2578 'decision' => $sic["i_${i}"],
2579 );
2580 break;
2581 default:
2582 // don't care
2583 }
2584 }
2585 $dbxlink->beginTransaction();
2586 try
2587 {
2588 if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE'))
2589 throw new InvalidArgException ('object_id', $sic['object_id'], 'VLAN domain is not set for this object');
2590 if ($vswitch['mutex_rev'] != $sic['mutex_rev'])
2591 throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form (table data has changed)');
2592 $D = getStored8021QConfig ($vswitch['object_id'], 'desired');
2593 $C = getStored8021QConfig ($vswitch['object_id'], 'cached');
2594 $R = getRunning8021QConfig ($vswitch['object_id']);
2595 $plan = get8021QSyncOptions ($vswitch, $D, $C, $R['portdata']);
2596 $ndone = 0;
2597 foreach ($F as $port_name => $port)
2598 {
2599 if (!array_key_exists ($port_name, $plan))
2600 continue;
2601 elseif ($plan[$port_name]['status'] == 'merge_conflict')
2602 {
2603 // for R neither mutex nor revisions can be emulated, but revision change can be
2604 if (!same8021QConfigs ($port, $R['portdata'][$port_name]))
2605 throw new InvalidRequestArgException ("port ${port_name}", '(hidden)', 'expired form (switch data has changed)');
2606 if ($port['decision'] == 'right') // D wins, frame R by writing value of R to C
2607 $ndone += upd8021QPort ('cached', $vswitch['object_id'], $port_name, $port);
2608 elseif ($port['decision'] == 'left') // R wins, cross D up
2609 $ndone += upd8021QPort ('cached', $vswitch['object_id'], $port_name, $D[$port_name]);
2610 // otherwise there was no decision made
2611 }
2612 elseif
2613 (
2614 $plan[$port_name]['status'] == 'delete_conflict' or
2615 $plan[$port_name]['status'] == 'martian_conflict'
2616 )
2617 {
2618 if ($port['decision'] == 'left') // confirm deletion of local copy
2619 $ndone += del8021QPort ($vswitch['object_id'], $port_name);
2620 }
2621 // otherwise ignore a decision, which doesn't address a conflict
2622 }
2623 }
2624 catch (InvalidRequestArgException $e)
2625 {
2626 $dbxlink->rollBack();
2627 return buildRedirectURL (__FUNCTION__, 'ERR1');
2628 }
2629 catch (Exception $e)
2630 {
2631 $dbxlink->rollBack();
2632 return buildRedirectURL (__FUNCTION__, 'ERR2');
2633 }
2634 $dbxlink->commit();
2635 return buildRedirectURL (__FUNCTION__, 'OK', array ($ndone));
2636 }
2637
2638 $msgcode['addVLANSwitchTemplate']['OK'] = 48;
2639 $msgcode['addVLANSwitchTemplate']['ERR'] = 110;
2640 function addVLANSwitchTemplate()
2641 {
2642 assertStringArg ('vst_descr');
2643 global $sic;
2644 $max_local_vlans = NULL;
2645 if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans']))
2646 {
2647 assertUIntArg ('vst_maxvlans');
2648 $max_local_vlans = $sic['vst_maxvlans'];
2649 }
2650 $result = usePreparedInsertBlade
2651 (
2652 'VLANSwitchTemplate',
2653 array
2654 (
2655 'max_local_vlans' => $max_local_vlans,
2656 'description' => $sic['vst_descr'],
2657 )
2658 );
2659 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2660 }
2661
2662 $msgcode['delVLANSwitchTemplate']['OK'] = 49;
2663 $msgcode['delVLANSwitchTemplate']['ERR'] = 111;
2664 function delVLANSwitchTemplate()
2665 {
2666 assertUIntArg ('vst_id');
2667 global $sic;
2668 $result = FALSE !== usePreparedDeleteBlade ('VLANSwitchTemplate', array ('id' => $sic['vst_id']));
2669 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2670 }
2671
2672 $msgcode['updVLANSwitchTemplate']['OK'] = 51;
2673 $msgcode['updVLANSwitchTemplate']['ERR'] = 109;
2674 function updVLANSwitchTemplate()
2675 {
2676 assertUIntArg ('vst_id');
2677 assertStringArg ('vst_descr');
2678 global $sic;
2679 $max_local_vlans = NULL;
2680 if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans']))
2681 {
2682 assertUIntArg ('vst_maxvlans');
2683 $max_local_vlans = $sic['vst_maxvlans'];
2684 }
2685 $result = commitUpdateVST ($sic['vst_id'], $max_local_vlans, $sic['vst_descr']);
2686 return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR');
2687 }
2688
2689 $msgcode['cloneVSTRule']['OK'] = 48;
2690 $msgcode['cloneVSTRule']['ERR'] = 179;
2691 function cloneVSTRule()
2692 {
2693 global $dbxlink;
2694 $message = '';
2695 assertUIntArg ('vst_id');
2696 assertUIntArg ('mutex_rev', TRUE);
2697 $dst_vst = getVLANSwitchTemplate ($_REQUEST['vst_id']);
2698 if ($dst_vst['mutex_rev'] != $_REQUEST['mutex_rev'])
2699 $message = "User ${dst_vst['saved_by']} saved this template after you started to edit it. Please concern differencies";
2700 else
2701 {
2702 assertUIntArg ('from_id');
2703 $src_vst = getVLANSwitchTemplate ($_REQUEST['from_id']);
2704 if (! commitUpdateVSTRules ($_REQUEST['vst_id'], $src_vst['rules']))
2705 $message = 'DB error';
2706 }
2707 $result = !(BOOL) $message;
2708 if ($result)
2709 $message = 'Supplement succeeded';
2710 return buildWideRedirectURL (array (array ('code' => $result ? 'success' : 'error', 'message' => $message)));
2711 }
2712
2713 function updVSTRule()
2714 {
2715 global $port_role_options;
2716 assertUIntArg ('vst_id');
2717 assertUIntArg ('mutex_rev', TRUE);
2718 assertStringArg ('template_json');
2719 $message = '';
2720 $data = json_decode ($_POST['template_json'], TRUE);
2721 if (! isset ($data) or ! is_array ($data))
2722 $message = 'Invalid JSON code received from client';
2723 else
2724 {
2725 $rule_no = 0;
2726 foreach ($data as $rule)
2727 {
2728 $rule_no++;
2729 if (! isInteger ($rule['rule_no']))
2730 $message = 'Invalid rule number';
2731 elseif (! isPCRE ($rule['port_pcre']))
2732 $message = 'Invalid port regexp';
2733 elseif (! isset ($rule['port_role']) or ! array_key_exists ($rule['port_role'], $port_role_options))
2734 $message = 'Invalid port role';
2735 elseif (! isset ($rule['wrt_vlans']) or ! preg_match ('/^[ 0-9\-,]*$/', $rule['wrt_vlans']))
2736 $message = 'Invalid port vlan mask';
2737 elseif (! isset ($rule['description']))
2738 $message = 'Invalid description';
2739
2740 if ($message)
2741 {
2742 $message .= " in rule $rule_no";
2743 break;
2744 }
2745 }
2746 if (! $message)
2747 {
2748 $vst = getVLANSwitchTemplate ($_REQUEST['vst_id']);
2749 if ($vst['mutex_rev'] != $_REQUEST['mutex_rev'])
2750 $message = "User ${vst['saved_by']} saved this template after you started to edit it. Please concern differencies";
2751 }
2752 if (! $message)
2753 if (! commitUpdateVSTRules ($_REQUEST['vst_id'], $data))
2754 $message = 'DB update error';
2755 if ($message)
2756 $_SESSION['vst_edited'] = $data;
2757 }
2758 if ($message)
2759 {
2760 $result = FALSE;
2761 $message = "Template update failed: $message";
2762 }
2763 else
2764 {
2765 $result = TRUE;
2766 $message = "Update success";
2767 }
2768 return buildWideRedirectURL (array (array ('code' => $result ? 'success' : 'error', 'message' => $message)));
2769 }
2770
2771 $msgcode['importDPData']['OK'] = 44;
2772 function importDPData()
2773 {
2774 global $sic;
2775 assertUIntArg ('nports');
2776 $nignored = $ndone = 0;
2777 $POIFC = getPortOIFCompat();
2778 for ($i = 0; $i < $sic['nports']; $i++)
2779 if (array_key_exists ("do_${i}", $sic))
2780 {
2781 assertUIntArg ("pid1_${i}");
2782 assertUIntArg ("pid2_${i}");
2783 $porta = getPortInfo ($_REQUEST["pid1_${i}"]);
2784 $portb = getPortInfo ($_REQUEST["pid2_${i}"]);
2785 if
2786 (
2787 $porta['linked'] or
2788 $portb['linked'] or
2789 ($porta['object_id'] != $sic['object_id'] and $portb['object_id'] != $sic['object_id'])
2790 )
2791 {
2792 $nignored++;
2793 continue;
2794 }
2795 foreach ($POIFC as $item)
2796 if ($item['type1'] == $porta['oif_id'] and $item['type2'] == $portb['oif_id'])
2797 {
2798 linkPorts ($_REQUEST["pid1_${i}"], $_REQUEST["pid2_${i}"]);
2799 $ndone++;
2800 continue 2; // next port
2801 }
2802 $nignored++;
2803 }
2804 return buildRedirectURL (__FUNCTION__, 'OK', array ($nignored, $ndone));
2805 }
2806
2807 $msgcode['deleteObjectLog']['OK'] = 77;
2808 function deleteObjectLog ()
2809 {
2810 assertUIntArg ('logid');
2811 usePreparedDeleteBlade ('ObjectLog', array ('id' => $_REQUEST['logid']));
2812 return buildRedirectURL (__FUNCTION__, 'OK', array ('log entry'));
2813 }
2814
2815 $msgcode['addObjectlog']['OK'] = 0;
2816 function addObjectlog ()
2817 {
2818 assertUIntArg ('object_id');
2819 assertStringArg ('logentry');
2820 global $remote_username, $sic;
2821 $oi = spotEntity ('object', $sic['object_id']);
2822 usePreparedExecuteBlade ('INSERT INTO ObjectLog SET object_id=?, user=?, date=NOW(), content=?', array ($sic['object_id'], $remote_username, $sic['logentry']));
2823 $ob_url = makeHref (array ('page' => 'object', 'tab' => 'objectlog', 'object_id' => $sic['object_id']));
2824 return buildRedirectURL (__FUNCTION__, 'OK', array ("Log entry for <a href=" . ${ob_url} . ">${oi['dname']}</a> added by ${remote_username}"));
2825 }
2826
2827 function tableHandler ($opspec)
2828 {
2829 global $sic;
2830 if (!array_key_exists ('table', $opspec))
2831 throw new InvalidArgException ('opspec', '(malformed array structure)', '"table" not set');
2832 $columns = array();
2833 foreach ($opspec['arglist'] as $argspec)
2834 {
2835 genericAssertion ($argspec['url_argname'], $argspec['assertion']);
2836 $columns[$argspec['table_colname']] = $sic[$argspec['url_argname']];
2837 }
2838 switch ($opspec['action'])
2839 {
2840 case 'INSERT':
2841 $retcode = TRUE === usePreparedInsertBlade ($opspec['table'], $columns) ? 48 : 110;
2842 break;
2843 default:
2844 throw new InvalidArgException ('opspec/action', '(malformed array structure)');
2845 }
2846 return buildWideRedirectURL (oneLiner ($retcode));
2847 }
2848
2849 ?>