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