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