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