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