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