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