r3309 getObjectVLANDomainID(): dismissed
[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
DO
82$msgcode['delPortForwarding']['OK'] = 3;
83$msgcode['delPortForwarding']['ERR'] = 100;
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
103b1e1e
DO
93 $error = deletePortForwarding
94 (
95 $_REQUEST['object_id'],
96 $_REQUEST['localip'],
97 $_REQUEST['localport'],
98 $_REQUEST['remoteip'],
99 $_REQUEST['remoteport'],
100 $_REQUEST['proto']
101 );
e673ee24 102 if ($error == '')
135080d8 103 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 104 else
135080d8 105 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e673ee24
DO
106}
107
b6a7d936
DO
108$msgcode['updPortForwarding']['OK'] = 4;
109$msgcode['updPortForwarding']['ERR'] = 100;
e673ee24
DO
110function updPortForwarding ()
111{
0cc24e9a
DY
112 assertUIntArg ('object_id');
113 assertIPv4Arg ('localip');
114 assertIPv4Arg ('remoteip');
115 assertUIntArg ('localport');
116 assertUIntArg ('remoteport');
117 assertStringArg ('proto');
118 assertStringArg ('description');
e673ee24 119
103b1e1e
DO
120 $error = updatePortForwarding
121 (
122 $_REQUEST['object_id'],
123 $_REQUEST['localip'],
124 $_REQUEST['localport'],
125 $_REQUEST['remoteip'],
126 $_REQUEST['remoteport'],
127 $_REQUEST['proto'],
128 $_REQUEST['description']
129 );
e673ee24 130 if ($error == '')
135080d8 131 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 132 else
135080d8 133 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e673ee24
DO
134}
135
b6a7d936
DO
136$msgcode['addPortForObject']['OK'] = 5;
137$msgcode['addPortForObject']['ERR1'] = 101;
138$msgcode['addPortForObject']['ERR2'] = 100;
e673ee24
DO
139function addPortForObject ()
140{
0cc24e9a
DY
141 assertUIntArg ('object_id');
142 assertStringArg ('port_name', TRUE);
59a83bd8 143 if (!strlen ($_REQUEST['port_name']))
135080d8 144 return buildRedirectURL (__FUNCTION__, 'ERR1');
103b1e1e
DO
145 $error = commitAddPort ($_REQUEST['object_id'], $_REQUEST['port_name'], $_REQUEST['port_type_id'], $_REQUEST['port_label'], $_REQUEST['port_l2address']);
146 if ($error != '')
135080d8 147 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
e673ee24 148 else
135080d8 149 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name']));
e673ee24
DO
150}
151
b6a7d936
DO
152$msgcode['editPortForObject']['OK'] = 6;
153$msgcode['editPortForObject']['ERR1'] = 101;
154$msgcode['editPortForObject']['ERR2'] = 100;
e673ee24
DO
155function editPortForObject ()
156{
0cc24e9a
DY
157 assertUIntArg ('object_id');
158 assertUIntArg ('port_id');
159 assertUIntArg ('port_type_id');
d0a69ce8 160 // tolerate empty value now to produce custom informative message later
0cc24e9a 161 assertStringArg ('name', TRUE);
59a83bd8 162 if (!strlen ($_REQUEST['name']))
135080d8 163 return buildRedirectURL (__FUNCTION__, 'ERR1');
103b1e1e 164
59a83bd8 165 if (isset ($_REQUEST['reservation_comment']) and strlen ($_REQUEST['reservation_comment']))
e673ee24
DO
166 $port_rc = '"' . $_REQUEST['reservation_comment'] . '"';
167 else
168 $port_rc = 'NULL';
6be06cbb 169 $error = commitUpdatePort ($_REQUEST['object_id'], $_REQUEST['port_id'], $_REQUEST['name'], $_REQUEST['port_type_id'], $_REQUEST['label'], $_REQUEST['l2address'], $port_rc);
103b1e1e 170 if ($error != '')
135080d8 171 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
e673ee24 172 else
135080d8 173 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name']));
e673ee24
DO
174}
175
b6a7d936
DO
176$msgcode['delPortFromObject']['OK'] = 7;
177$msgcode['delPortFromObject']['ERR'] = 100;
e673ee24
DO
178function delPortFromObject ()
179{
0cc24e9a 180 assertUIntArg ('port_id');
103b1e1e 181 $error = delObjectPort ($_REQUEST['port_id']);
e673ee24
DO
182
183 if ($error != '')
135080d8 184 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e673ee24 185 else
135080d8 186 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name']));
e673ee24
DO
187}
188
b6a7d936
DO
189$msgcode['linkPortForObject']['OK'] = 8;
190$msgcode['linkPortForObject']['ERR'] = 100;
e673ee24
DO
191function linkPortForObject ()
192{
0cc24e9a
DY
193 assertUIntArg ('port_id');
194 assertUIntArg ('remote_port_id');
e673ee24 195
cd3775e9 196 // FIXME: ensure, that at least one of these ports belongs to the current object
103b1e1e 197 $error = linkPorts ($_REQUEST['port_id'], $_REQUEST['remote_port_id']);
e673ee24 198 if ($error != '')
135080d8 199 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
d0dadd80
DO
200 global $sic;
201 $local_port_info = getPortInfo ($sic['port_id']);
202 $remote_port_info = getPortInfo ($sic['remote_port_id']);
cd3775e9
DO
203 $remote_object = spotEntity ('object', $remote_port_info['object_id']);
204 return buildRedirectURL
205 (
206 __FUNCTION__,
207 'OK',
208 array
209 (
210 $local_port_info['name'],
211 $remote_port_info['name'],
212 $remote_object['dname'],
213 )
214 );
e673ee24
DO
215}
216
b6a7d936
DO
217$msgcode['unlinkPortForObject']['OK'] = 9;
218$msgcode['unlinkPortForObject']['ERR'] = 100;
e673ee24
DO
219function unlinkPortForObject ()
220{
0cc24e9a
DY
221 assertUIntArg ('port_id');
222 assertUIntArg ('remote_port_id');
e673ee24 223
d0dadd80
DO
224 global $sic;
225 $local_port_info = getPortInfo ($sic['port_id']);
226 $remote_port_info = getPortInfo ($sic['remote_port_id']);
cd3775e9 227 $remote_object = spotEntity ('object', $remote_port_info['object_id']);
103b1e1e 228 $error = unlinkPort ($_REQUEST['port_id']);
e673ee24 229 if ($error != '')
135080d8 230 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
cd3775e9
DO
231 return buildRedirectURL
232 (
233 __FUNCTION__,
234 'OK',
235 array
236 (
237 $local_port_info['name'],
238 $remote_port_info['name'],
239 $remote_object['dname'],
240 )
241 );
e673ee24
DO
242}
243
b6a7d936
DO
244$msgcode['addMultiPorts']['OK'] = 10;
245$msgcode['addMultiPorts']['ERR'] = 123;
e673ee24
DO
246function addMultiPorts ()
247{
0cc24e9a
DY
248 assertStringArg ('format');
249 assertStringArg ('input');
250 assertUIntArg ('port_type');
251 assertUIntArg ('object_id');
e673ee24
DO
252 $format = $_REQUEST['format'];
253 $port_type = $_REQUEST['port_type'];
254 $object_id = $_REQUEST['object_id'];
255 // Input lines are escaped, so we have to explode and to chop by 2-char
256 // \n and \r respectively.
257 $lines1 = explode ('\n', $_REQUEST['input']);
258 foreach ($lines1 as $line)
259 {
260 $parts = explode ('\r', $line);
261 reset ($parts);
59a83bd8 262 if (!strlen ($parts[0]))
e673ee24
DO
263 continue;
264 else
265 $lines2[] = rtrim ($parts[0]);
266 }
267 $ports = array();
268 foreach ($lines2 as $line)
269 {
270 switch ($format)
271 {
272 case 'fisxii':
273 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
274 list ($slot, $port) = explode ('/', $words[0]);
275 $ports[] = array
276 (
277 'name' => "e ${slot}/${port}",
278 'l2address' => $words[8],
279 'label' => "slot ${slot} port ${port}"
280 );
281 break;
282 case 'c3600asy':
283 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', trim (substr ($line, 3))));
284/*
285How Async Lines are Numbered in Cisco 3600 Series Routers
286http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00801ca70b.shtml
287
288Understanding 16- and 32-Port Async Network Modules
289http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00800a93f0.shtml
290*/
291 $async = $words[0];
292 $slot = floor (($async - 1) / 32);
293 $octalgroup = floor (($async - 1 - $slot * 32) / 8);
294 $cable = $async - $slot * 32 - $octalgroup * 8;
295 $og_label[0] = 'async 0-7';
296 $og_label[1] = 'async 8-15';
297 $og_label[2] = 'async 16-23';
298 $og_label[3] = 'async 24-31';
299 $ports[] = array
300 (
301 'name' => "async ${async}",
302 'l2address' => '',
303 'label' => "slot ${slot} " . $og_label[$octalgroup] . " cable ${cable}"
304 );
305 break;
306 case 'fiwg':
307 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
308 $ifnumber = $words[0] * 1;
309 $ports[] = array
310 (
311 'name' => "e ${ifnumber}",
312 'l2address' => "${words[8]}",
313 'label' => "${ifnumber}"
314 );
315 break;
351d4dbf 316 case 'ssv1':
5b585342 317 $words = explode (' ', $line);
59a83bd8 318 if (!strlen ($words[0]) or !strlen ($words[1]))
351d4dbf
DO
319 continue;
320 $ports[] = array
321 (
322 'name' => $words[0],
323 'l2address' => $words[1],
324 'label' => ''
325 );
326 break;
e673ee24 327 default:
135080d8 328 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
329 break;
330 }
331 }
332 // Create ports, if they don't exist.
333 $added_count = $updated_count = $error_count = 0;
334 foreach ($ports as $port)
335 {
336 $port_id = getPortID ($object_id, $port['name']);
337 if ($port_id === NULL)
338 {
339 $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
340 if ($result == '')
341 $added_count++;
342 else
343 $error_count++;
344 }
345 else
346 {
6be06cbb 347 $result = commitUpdatePort ($object_id, $port_id, $port['name'], $port_type, $port['label'], $port['l2address']);
e673ee24
DO
348 if ($result == '')
349 $updated_count++;
350 else
351 $error_count++;
352 }
353 }
135080d8 354 return buildRedirectURL (__FUNCTION__, 'OK', array ($added_count, $updated_count, $error_count));
e673ee24
DO
355}
356
b6a7d936
DO
357$msgcode['updIPv4Allocation']['OK'] = 12;
358$msgcode['updIPv4Allocation']['ERR'] = 100;
b4c1ef87 359function updIPv4Allocation ()
e673ee24 360{
0cc24e9a
DY
361 assertIPv4Arg ('ip');
362 assertUIntArg ('object_id');
363 assertStringArg ('bond_name', TRUE);
364 assertStringArg ('bond_type');
e673ee24 365
b4c1ef87 366 $error = updateBond ($_REQUEST['ip'], $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
e673ee24 367 if ($error != '')
135080d8 368 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e673ee24 369 else
135080d8 370 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24
DO
371}
372
b6a7d936
DO
373$msgcode['delIPv4Allocation']['OK'] = 14;
374$msgcode['delIPv4Allocation']['ERR'] = 100;
b4c1ef87 375function delIPv4Allocation ()
e673ee24 376{
0cc24e9a
DY
377 assertIPv4Arg ('ip');
378 assertUIntArg ('object_id');
e673ee24 379
b4c1ef87 380 $error = unbindIpFromObject ($_REQUEST['ip'], $_REQUEST['object_id']);
e673ee24 381 if ($error != '')
135080d8 382 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e673ee24 383 else
135080d8 384 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24
DO
385}
386
b6a7d936
DO
387$msgcode['addIPv4Allocation']['OK'] = 13;
388$msgcode['addIPv4Allocation']['ERR1'] = 170;
389$msgcode['addIPv4Allocation']['ERR2'] = 100;
b4c1ef87 390function addIPv4Allocation ()
e673ee24 391{
0cc24e9a
DY
392 assertIPv4Arg ('ip');
393 assertUIntArg ('object_id');
394 assertStringArg ('bond_name', TRUE);
395 assertStringArg ('bond_type');
da958e52 396
b4c1ef87
DO
397 // Strip masklen.
398 $ip = ereg_replace ('/[[:digit:]]+$', '', $_REQUEST['ip']);
2be3fd23 399 if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv4AddressNetworkId ($ip))
135080d8 400 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($ip));
5222f192 401
b4c1ef87 402 $error = bindIpToObject ($ip, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
5222f192 403 if ($error != '')
135080d8 404 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
53ef3908 405 $address = getIPv4Address ($ip);
59a83bd8 406 if ($address['reserved'] == 'yes' or strlen ($address['name']))
b4c1ef87
DO
407 {
408 $release = getConfigVar ('IPV4_AUTO_RELEASE');
409 if ($release >= 1)
410 $address['reserved'] = 'no';
411 if ($release >= 2)
412 $address['name'] = '';
413 updateAddress ($ip, $address['name'], $address['reserved']);
414 }
135080d8 415 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24
DO
416}
417
b6a7d936
DO
418$msgcode['addIPv4Prefix']['OK'] = 23;
419$msgcode['addIPv4Prefix']['ERR'] = 100;
420$msgcode['addIPv4Prefix']['ERR1'] = 173;
421$msgcode['addIPv4Prefix']['ERR2'] = 174;
422$msgcode['addIPv4Prefix']['ERR3'] = 175;
423$msgcode['addIPv4Prefix']['ERR4'] = 176;
42023f03 424function addIPv4Prefix ()
e673ee24 425{
0cc24e9a
DY
426 assertStringArg ('range');
427 assertStringArg ('name', TRUE);
e673ee24 428
fa05e3de
DO
429 $is_bcast = isset ($_REQUEST['is_bcast']) ? $_REQUEST['is_bcast'] : 'off';
430 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
357eb2ea
DO
431 global $sic;
432 $error = createIPv4Prefix ($_REQUEST['range'], $sic['name'], $is_bcast == 'on', $taglist);
e673ee24 433 if ($error != '')
135080d8 434 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e673ee24 435 else
135080d8 436 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24
DO
437}
438
b6a7d936
DO
439$msgcode['delIPv4Prefix']['OK'] = 24;
440$msgcode['delIPv4Prefix']['ERR'] = 100;
42023f03 441function delIPv4Prefix ()
e673ee24 442{
0cc24e9a 443 assertUIntArg ('id');
42023f03 444 $error = destroyIPv4Prefix ($_REQUEST['id']);
e673ee24 445 if ($error != '')
135080d8 446 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e673ee24 447 else
135080d8 448 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24
DO
449}
450
b6a7d936
DO
451$msgcode['updIPv4Prefix']['OK'] = 25;
452$msgcode['updIPv4Prefix']['ERR'] = 100;
04d619d0 453function updIPv4Prefix ()
e673ee24 454{
0cc24e9a
DY
455 assertUIntArg ('id');
456 assertStringArg ('name', TRUE);
457 assertStringArg ('comment', TRUE);
99ab184f
DO
458 global $sic;
459 if (strlen ($error = updateIPv4Network_real ($sic['id'], $sic['name'], $sic['comment'])))
135080d8 460 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e673ee24 461 else
135080d8 462 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24
DO
463}
464
b6a7d936
DO
465$msgcode['editAddress']['OK'] = 27;
466$msgcode['editAddress']['ERR'] = 100;
e673ee24
DO
467function editAddress ()
468{
0cc24e9a
DY
469 assertIPv4Arg ('ip');
470 assertStringArg ('name', TRUE);
e673ee24 471
e673ee24
DO
472 if (isset ($_REQUEST['reserved']))
473 $reserved = $_REQUEST['reserved'];
474 else
475 $reserved = 'off';
da958e52 476 $error = updateAddress ($_REQUEST['ip'], $_REQUEST['name'], $reserved == 'on' ? 'yes' : 'no');
e673ee24 477 if ($error != '')
135080d8 478 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e673ee24 479 else
135080d8 480 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24
DO
481}
482
b6a7d936
DO
483$msgcode['createUser']['OK'] = 40;
484$msgcode['createUser']['ERR'] = 102;
cced6b7d 485function createUser ()
e673ee24 486{
0cc24e9a
DY
487 assertStringArg ('username');
488 assertStringArg ('realname', TRUE);
489 assertStringArg ('password');
e673ee24 490 $username = $_REQUEST['username'];
93bdb7ba 491 $password = sha1 ($_REQUEST['password']);
e673ee24 492 $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password);
f857f71f 493 if ($result != TRUE)
135080d8 494 return buildRedirectURL (__FUNCTION__, 'ERR', array ($username));
f857f71f
DO
495 if (isset ($_REQUEST['taglist']))
496 produceTagsForLastRecord ('user', $_REQUEST['taglist']);
497 return buildRedirectURL (__FUNCTION__, 'OK', array ($username));
e673ee24
DO
498}
499
b6a7d936
DO
500$msgcode['updateUser']['OK'] = 39;
501$msgcode['updateUser']['ERR1'] = 103;
502$msgcode['updateUser']['ERR1'] = 104;
cced6b7d 503function updateUser ()
e673ee24 504{
0cc24e9a
DY
505 assertUIntArg ('user_id');
506 assertStringArg ('username');
507 assertStringArg ('realname', TRUE);
508 assertStringArg ('password');
e673ee24
DO
509 $username = $_REQUEST['username'];
510 $new_password = $_REQUEST['password'];
0b2c74cb 511 if (NULL == ($userinfo = spotEntity ('user', $_REQUEST['user_id'])))
135080d8 512 return buildRedirectURL (__FUNCTION__, 'ERR1');
e673ee24 513 // Update user password only if provided password is not the same as current password hash.
b82cce3f 514 if ($new_password != $userinfo['user_password_hash'])
93bdb7ba 515 $new_password = sha1 ($new_password);
103b1e1e 516 $result = commitUpdateUserAccount ($_REQUEST['user_id'], $username, $_REQUEST['realname'], $new_password);
e673ee24 517 if ($result == TRUE)
135080d8 518 return buildRedirectURL (__FUNCTION__, 'OK', array ($username));
e673ee24 519 else
135080d8 520 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($username));
e673ee24
DO
521}
522
b6a7d936
DO
523$msgcode['updateDictionary']['OK'] = 51;
524$msgcode['updateDictionary']['ERR'] = 109;
e673ee24
DO
525function updateDictionary ()
526{
0cc24e9a
DY
527 assertUIntArg ('chapter_no');
528 assertUIntArg ('dict_key');
529 assertStringArg ('dict_value');
e673ee24 530 if (commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value']) === TRUE)
135080d8 531 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 532 else
135080d8 533 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
534}
535
b6a7d936
DO
536$msgcode['supplementDictionary']['OK'] = 52;
537$msgcode['supplementDictionary']['ERR'] = 110;
e673ee24
DO
538function supplementDictionary ()
539{
0cc24e9a
DY
540 assertUIntArg ('chapter_no');
541 assertStringArg ('dict_value');
e673ee24 542 if (commitSupplementDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_value']) === TRUE)
135080d8 543 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 544 else
135080d8 545 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
546}
547
b6a7d936
DO
548$msgcode['reduceDictionary']['OK'] = 50;
549$msgcode['reduceDictionary']['ERR'] = 111;
e673ee24
DO
550function reduceDictionary ()
551{
0cc24e9a
DY
552 assertUIntArg ('chapter_no');
553 assertUIntArg ('dict_key');
e673ee24 554 if (commitReduceDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key']) === TRUE)
135080d8 555 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 556 else
135080d8 557 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
558}
559
b6a7d936
DO
560$msgcode['addChapter']['OK'] = 55;
561$msgcode['addChapter']['ERR'] = 112;
e673ee24
DO
562function addChapter ()
563{
0cc24e9a 564 assertStringArg ('chapter_name');
e673ee24 565 if (commitAddChapter ($_REQUEST['chapter_name']) === TRUE)
135080d8 566 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 567 else
135080d8 568 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
569}
570
b6a7d936
DO
571$msgcode['updateChapter']['OK'] = 54;
572$msgcode['updateChapter']['ERR'] = 113;
e673ee24
DO
573function updateChapter ()
574{
0cc24e9a
DY
575 assertUIntArg ('chapter_no');
576 assertStringArg ('chapter_name');
e673ee24 577 if (commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name']) === TRUE)
135080d8 578 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 579 else
135080d8 580 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
581}
582
b6a7d936
DO
583$msgcode['delChapter']['OK'] = 53;
584$msgcode['delChapter']['ERR'] = 114;
e673ee24
DO
585function delChapter ()
586{
0cc24e9a 587 assertUIntArg ('chapter_no');
e673ee24 588 if (commitDeleteChapter ($_REQUEST['chapter_no']))
135080d8 589 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 590 else
135080d8 591 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
592}
593
b6a7d936
DO
594$msgcode['changeAttribute']['OK'] = 46;
595$msgcode['changeAttribute']['ERR'] = 115;
e673ee24
DO
596function changeAttribute ()
597{
0cc24e9a
DY
598 assertUIntArg ('attr_id');
599 assertStringArg ('attr_name');
e673ee24 600 if (commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name']))
135080d8 601 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 602 else
135080d8 603 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
604}
605
b6a7d936
DO
606$msgcode['createAttribute']['OK'] = 45;
607$msgcode['createAttribute']['ERR'] = 116;
e673ee24
DO
608function createAttribute ()
609{
0cc24e9a
DY
610 assertStringArg ('attr_name');
611 assertStringArg ('attr_type');
e673ee24 612 if (commitAddAttribute ($_REQUEST['attr_name'], $_REQUEST['attr_type']))
135080d8 613 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['attr_name']));
e673ee24 614 else
135080d8 615 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
616}
617
b6a7d936
DO
618$msgcode['deleteAttribute']['OK'] = 47;
619$msgcode['deleteAttribute']['ERR'] = 117;
e673ee24
DO
620function deleteAttribute ()
621{
0cc24e9a 622 assertUIntArg ('attr_id');
e673ee24 623 if (commitDeleteAttribute ($_REQUEST['attr_id']))
135080d8 624 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 625 else
135080d8 626 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
627}
628
b6a7d936 629$msgcode['supplementAttrMap']['OK'] = 48;
7028a42c
DO
630$msgcode['supplementAttrMap']['ERR1'] = 154;
631$msgcode['supplementAttrMap']['ERR2'] = 118;
e673ee24
DO
632function supplementAttrMap ()
633{
0cc24e9a
DY
634 assertUIntArg ('attr_id');
635 assertUIntArg ('objtype_id');
7028a42c
DO
636 $attrMap = getAttrMap();
637 if ($attrMap[$_REQUEST['attr_id']]['type'] != 'dict')
638 $chapter_id = 'NULL';
639 else
640 {
0cc24e9a 641 assertUIntArg ('chapter_no'); // FIXME: this doesn't fail on 0 (ticket:272)
7028a42c
DO
642 if (0 == ($chapter_id = $_REQUEST['chapter_no']))
643 return buildRedirectURL (__FUNCTION__, 'ERR1', array ('chapter not selected'));
644 }
645 if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $chapter_id) === TRUE)
135080d8 646 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 647 else
7028a42c 648 return buildRedirectURL (__FUNCTION__, 'ERR2');
e673ee24
DO
649}
650
b6a7d936
DO
651$msgcode['reduceAttrMap']['OK'] = 49;
652$msgcode['reduceAttrMap']['ERR'] = 119;
e673ee24
DO
653function reduceAttrMap ()
654{
0cc24e9a
DY
655 assertUIntArg ('attr_id');
656 assertUIntArg ('objtype_id');
e673ee24 657 if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) === TRUE)
135080d8 658 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 659 else
135080d8 660 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
661}
662
b6a7d936
DO
663$msgcode['clearSticker']['OK'] = 15;
664$msgcode['clearSticker']['ERR'] = 120;
22bb04da 665function clearSticker ()
e673ee24 666{
0cc24e9a
DY
667 assertUIntArg ('attr_id');
668 assertUIntArg ('object_id');
22bb04da 669 if (commitResetAttrValue ($_REQUEST['object_id'], $_REQUEST['attr_id']) === TRUE)
135080d8 670 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 671 else
135080d8 672 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
673}
674
e97e8866 675$msgcode['updateObjectAllocation']['OK'] = 63;
4fbb5a00
DY
676function updateObjectAllocation ()
677{
0cc24e9a 678 assertUIntArg ('object_id');
4fbb5a00 679
e97e8866
DO
680 if (!isset ($_REQUEST['got_atoms']))
681 {
682 unset($_GET['page']);
683 unset($_GET['tab']);
684 unset($_GET['op']);
685 unset($_POST['page']);
686 unset($_POST['tab']);
687 unset($_POST['op']);
688 return buildWideRedirectURL (array(), NULL, NULL, array_merge ($_GET, $_POST));
689 }
690 $object_id = $_REQUEST['object_id'];
691 $workingRacksData = array();
692 foreach ($_REQUEST['rackmulti'] as $cand_id)
4fbb5a00 693 {
e97e8866 694 if (!isset ($workingRacksData[$cand_id]))
4fbb5a00 695 {
e97e8866 696 $rackData = spotEntity ('rack', $cand_id);
e97e8866
DO
697 amplifyCell ($rackData);
698 $workingRacksData[$cand_id] = $rackData;
4fbb5a00 699 }
e97e8866 700 }
2135fd83 701
e97e8866
DO
702 foreach ($workingRacksData as &$rd)
703 applyObjectMountMask ($rd, $object_id);
4fbb5a00 704
e97e8866
DO
705 $oldMolecule = getMoleculeForObject ($object_id);
706 $changecnt = 0;
707 $log = array();
708 foreach ($workingRacksData as $rack_id => $rackData)
4fbb5a00 709 {
e97e8866
DO
710 $logrecord = processGridForm ($rackData, 'F', 'T', $object_id);
711 $log[] = $logrecord;
712 if ($logrecord['code'] == 300)
713 continue;
714 $changecnt++;
715 // Reload our working copy after form processing.
716 $rackData = spotEntity ('rack', $cand_id);
717 amplifyCell ($rackData);
718 applyObjectMountMask ($rackData, $object_id);
719 $workingRacksData[$rack_id] = $rackData;
4fbb5a00 720 }
e97e8866
DO
721 if (!$changecnt)
722 return buildRedirectURL (__FUNCTION__, 'OK', $changecnt);
723 // Log a record.
724 $newMolecule = getMoleculeForObject ($object_id);
725 $oc = count ($oldMolecule);
726 $nc = count ($newMolecule);
727 $omid = $oc ? createMolecule ($oldMolecule) : 'NULL';
728 $nmid = $nc ? createMolecule ($newMolecule) : 'NULL';
729 global $remote_username;
730 $comment = empty ($_REQUEST['comment']) ? 'NULL' : "'${_REQUEST['comment']}'";
731 $query =
732 "insert into MountOperation(object_id, old_molecule_id, new_molecule_id, user_name, comment) " .
733 "values (${object_id}, ${omid}, ${nmid}, '${remote_username}', ${comment})";
734 global $dbxlink;
735 $result = $dbxlink->query ($query);
736 if ($result == NULL)
737 $log[] = array ('code' => 500, 'message' => 'SQL query failed during history logging.');
738 else
739 $log[] = array ('code' => 200, 'message' => 'History logged.');
740 return buildWideRedirectURL ($log);
4fbb5a00
DY
741}
742
b6a7d936
DO
743$msgcode['updateObject']['OK'] = 16;
744$msgcode['updateObject']['ERR'] = 121;
22bb04da
DO
745function updateObject ()
746{
0cc24e9a
DY
747 assertUIntArg ('num_attrs', TRUE);
748 assertUIntArg ('object_id');
749 assertUIntArg ('object_type_id');
750 assertStringArg ('object_name', TRUE);
751 assertStringArg ('object_label', TRUE);
752 assertStringArg ('object_barcode', TRUE);
753 assertStringArg ('object_asset_no', TRUE);
22bb04da
DO
754 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
755 $has_problems = 'yes';
756 else
757 $has_problems = 'no';
758
759 if (commitUpdateObject (
760 $_REQUEST['object_id'],
761 $_REQUEST['object_name'],
762 $_REQUEST['object_label'],
763 $_REQUEST['object_barcode'],
764 $_REQUEST['object_type_id'],
765 $has_problems,
766 $_REQUEST['object_asset_no'],
767 $_REQUEST['object_comment']
768 ) !== TRUE)
135080d8 769 return buildRedirectURL (__FUNCTION__, 'ERR');
22bb04da 770
cdd3efe9 771 // Update optional attributes
f59e8cf5 772 $oldvalues = getAttrValues ($_REQUEST['object_id']);
0dfb8a2a 773 $result = array();
0f63538a
DO
774 $num_attrs = isset ($_REQUEST['num_attrs']) ? $_REQUEST['num_attrs'] : 0;
775 for ($i = 0; $i < $num_attrs; $i++)
0dfb8a2a 776 {
0cc24e9a 777 assertUIntArg ("${i}_attr_id");
0dfb8a2a
DO
778 $attr_id = $_REQUEST["${i}_attr_id"];
779
780 // Field is empty, delete attribute and move on.
59a83bd8 781 if (!strlen ($_REQUEST["${i}_value"]))
0dfb8a2a 782 {
103b1e1e 783 commitResetAttrValue ($_REQUEST['object_id'], $attr_id);
0dfb8a2a
DO
784 continue;
785 }
786
787 // The value could be uint/float, but we don't know ATM. Let SQL
788 // server check this and complain.
0cc24e9a 789 assertStringArg ("${i}_value");
0dfb8a2a
DO
790 $value = $_REQUEST["${i}_value"];
791 switch ($oldvalues[$attr_id]['type'])
792 {
793 case 'uint':
794 case 'float':
795 case 'string':
796 $oldvalue = $oldvalues[$attr_id]['value'];
797 break;
798 case 'dict':
799 $oldvalue = $oldvalues[$attr_id]['key'];
800 break;
801 default:
0cc24e9a 802 throw new RuntimeException('Internal structure error');
0dfb8a2a 803 }
59a83bd8 804 if ($value === $oldvalue) // ('' == 0), but ('' !== 0)
0dfb8a2a
DO
805 continue;
806
807 // Note if the queries succeed or not, it determines which page they see.
103b1e1e 808 $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value);
0dfb8a2a 809 }
103b1e1e 810 if (in_array (FALSE, $result))
135080d8 811 return buildRedirectURL (__FUNCTION__, 'ERR');
0dfb8a2a 812
cdd3efe9
AD
813 // Invalidate thumb cache of all racks objects could occupy.
814 foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id)
815 resetThumbCache ($rack_id);
816
135080d8 817 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24
DO
818}
819
42d73cbf
DY
820
821function addMultipleObjects()
822{
7abce0b7 823 $log = emptyLog();
42d73cbf 824 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
42d73cbf
DY
825 $max = getConfigVar ('MASSCOUNT');
826 for ($i = 0; $i < $max; $i++)
827 {
828 if (!isset ($_REQUEST["${i}_object_type_id"]))
829 {
57777e4a 830 $log = mergeLogs ($log, oneLiner (184, array ($i + 1)));
42d73cbf
DY
831 break;
832 }
0cc24e9a
DY
833 assertUIntArg ("${i}_object_type_id", TRUE);
834 assertStringArg ("${i}_object_name", TRUE);
835 assertStringArg ("${i}_object_label", TRUE);
836 assertStringArg ("${i}_object_asset_no", TRUE);
837 assertStringArg ("${i}_object_barcode", TRUE);
7abce0b7 838 $name = $_REQUEST["${i}_object_name"];
42d73cbf
DY
839
840 // It's better to skip silently, than to print a notice.
7abce0b7 841 if ($_REQUEST["${i}_object_type_id"] == 0)
42d73cbf 842 continue;
fee7977b 843 if (($object_id = commitAddObject
7abce0b7
DO
844 (
845 $name,
846 $_REQUEST["${i}_object_label"],
847 $_REQUEST["${i}_object_barcode"],
848 $_REQUEST["${i}_object_type_id"],
849 $_REQUEST["${i}_object_asset_no"],
850 $taglist
fee7977b
DO
851 )) !== FALSE){
852 $info = spotEntity ('object', $object_id);
853 // FIXME: employ amplifyCell() instead of calling loader functions directly
854 amplifyCell ($info);
855 $log = mergeLogs ($log, oneLiner (80, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>')));
856 }else{
57777e4a 857 $log = mergeLogs ($log, oneLiner (185, array ($name)));
fee7977b 858 }
42d73cbf 859 }
7abce0b7 860 return buildWideRedirectURL ($log);
42d73cbf
DY
861}
862
863function addLotOfObjects()
864{
7abce0b7 865 $log = emptyLog();
42d73cbf 866 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
0cc24e9a
DY
867 assertUIntArg ('global_type_id', TRUE);
868 assertStringArg ('namelist', TRUE);
42d73cbf 869 $global_type_id = $_REQUEST['global_type_id'];
59a83bd8 870 if ($global_type_id == 0 or !strlen ($_REQUEST['namelist']))
57777e4a 871 $log = mergeLogs ($log, oneLiner (186));
42d73cbf
DY
872 else
873 {
874 // The name extractor below was stolen from ophandlers.php:addMultiPorts()
875 $names1 = explode ('\n', $_REQUEST['namelist']);
876 $names2 = array();
877 foreach ($names1 as $line)
878 {
879 $parts = explode ('\r', $line);
880 reset ($parts);
59a83bd8 881 if (!strlen ($parts[0]))
42d73cbf
DY
882 continue;
883 else
884 $names2[] = rtrim ($parts[0]);
885 }
57777e4a 886 foreach ($names2 as $name)
fee7977b 887 if (commitAddObject ($name, '', '', $global_type_id, '', $taglist) !== FALSE)
57777e4a 888 $log = mergeLogs ($log, oneLiner (80, array ($name)));
42d73cbf 889 else
57777e4a 890 $log = mergeLogs ($log, oneLiner (185, array ($name)));
42d73cbf 891 }
7abce0b7 892 return buildWideRedirectURL ($log);
42d73cbf
DY
893}
894
b6a7d936
DO
895$msgcode['deleteObject']['OK'] = 76;
896$msgcode['deleteObject']['ERR'] = 100;
52b34485
AD
897function deleteObject ()
898{
0cc24e9a 899 assertUIntArg ('object_id');
6297d584 900 if (NULL === ($oinfo = spotEntity ('object', $_REQUEST['object_id'])))
c78a40ec
DO
901 return buildRedirectURL (__FUNCTION__, 'ERR', array ('object not found'));
902
f0e2c99f 903 $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE);
52b34485 904 $error = commitDeleteObject ($_REQUEST['object_id']);
f0e2c99f
DO
905 foreach ($racklist as $rack_id)
906 resetThumbCache ($rack_id);
52b34485
AD
907
908 if ($error != '')
135080d8 909 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
52b34485 910
c78a40ec 911 return buildRedirectURL (__FUNCTION__, 'OK', array ($oinfo['dname']));
52b34485
AD
912}
913
b6a7d936
DO
914$msgcode['useupPort']['OK'] = 11;
915$msgcode['useupPort']['ERR'] = 124;
e673ee24
DO
916function useupPort ()
917{
0cc24e9a 918 assertUIntArg ('port_id');
e673ee24 919 if (commitUseupPort ($_REQUEST['port_id']) === TRUE)
135080d8 920 return buildRedirectURL (__FUNCTION__, 'OK');
e673ee24 921 else
135080d8 922 return buildRedirectURL (__FUNCTION__, 'ERR');
e673ee24
DO
923}
924
b6a7d936
DO
925$msgcode['updateUI']['OK'] = 56;
926$msgcode['updateUI']['ERR'] = 125;
4fe32e78
DY
927function updateUI ()
928{
0cc24e9a 929 assertUIntArg ('num_vars');
4fe32e78 930
103b1e1e 931 for ($i = 0; $i < $_REQUEST['num_vars']; $i++)
4fe32e78 932 {
0cc24e9a
DY
933 assertStringArg ("${i}_varname");
934 assertStringArg ("${i}_varvalue", TRUE);
4fe32e78 935 $varname = $_REQUEST["${i}_varname"];
4fe32e78 936 $varvalue = $_REQUEST["${i}_varvalue"];
4fe32e78 937
c461c579 938 // If form value = value in DB, don't bother updating DB
ed941e67 939 if (!isConfigVarChanged($varname, $varvalue))
4fe32e78
DY
940 continue;
941
942 // Note if the queries succeed or not, it determines which page they see.
3540d15c
DY
943 try {
944 setConfigVar ($varname, $varvalue, TRUE);
945 } catch (InvalidArgException $e) {
946 return buildRedirectURL (__FUNCTION__, 'ERR', array ($e->getMessage()));
947 }
948 }
949 return buildRedirectURL (__FUNCTION__, 'OK');
950}
951
952$msgcode['saveMyPreferences']['OK'] = 56;
953$msgcode['saveMyPreferences']['ERR'] = 125;
954function saveMyPreferences ()
955{
956 assertUIntArg ('num_vars');
957
958 for ($i = 0; $i < $_REQUEST['num_vars']; $i++)
959 {
960 assertStringArg ("${i}_varname");
961 assertStringArg ("${i}_varvalue", TRUE);
962 $varname = $_REQUEST["${i}_varname"];
963 $varvalue = $_REQUEST["${i}_varvalue"];
964
965 // If form value = value in DB, don't bother updating DB
ed941e67 966 if (!isConfigVarChanged($varname, $varvalue))
3540d15c 967 continue;
3540d15c
DY
968 // Note if the queries succeed or not, it determines which page they see.
969 try {
970 setUserConfigVar ($varname, $varvalue);
971 } catch (InvalidArgException $e) {
972 return buildRedirectURL (__FUNCTION__, 'ERR', array ($e->getMessage()));
973 }
974 }
975 return buildRedirectURL (__FUNCTION__, 'OK');
976}
977
978$msgcode['resetMyPreference']['OK'] = 56;
979$msgcode['resetMyPreference']['ERR'] = 125;
980function resetMyPreference ()
981{
982 assertStringArg ("varname");
983 $varname = $_REQUEST["varname"];
984
985 try {
986 resetUserConfigVar ($varname);
987 } catch (InvalidArgException $e) {
988 return buildRedirectURL (__FUNCTION__, 'ERR', array ($e->getMessage()));
4fe32e78 989 }
135080d8 990 return buildRedirectURL (__FUNCTION__, 'OK');
4fe32e78
DY
991}
992
3540d15c
DY
993
994
995
b6a7d936 996$msgcode['resetUIConfig']['OK'] = 57;
b07f617c
DO
997function resetUIConfig()
998{
b07f617c
DO
999 setConfigVar ('MASSCOUNT','15');
1000 setConfigVar ('MAXSELSIZE','30');
b07f617c
DO
1001 setConfigVar ('ROW_SCALE','2');
1002 setConfigVar ('PORTS_PER_ROW','12');
1003 setConfigVar ('IPV4_ADDRS_PER_PAGE','256');
1004 setConfigVar ('DEFAULT_RACK_HEIGHT','42');
b5ce46aa
DO
1005 setConfigVar ('DEFAULT_SLB_VS_PORT','');
1006 setConfigVar ('DEFAULT_SLB_RS_PORT','');
72281138 1007 setConfigVar ('DETECT_URLS','no');
4b8d413e 1008 setConfigVar ('RACK_PRESELECT_THRESHOLD','1');
b108de49 1009 setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no');
8dfb997c 1010 setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm');
194e3748
DO
1011 setConfigVar ('SHOW_EXPLICIT_TAGS','yes');
1012 setConfigVar ('SHOW_IMPLICIT_TAGS','yes');
1013 setConfigVar ('SHOW_AUTOMATIC_TAGS','no');
a477e405 1014 setConfigVar ('DEFAULT_OBJECT_TYPE','4');
2754cefc 1015 setConfigVar ('IPV4_AUTO_RELEASE','1');
a53dc9df 1016 setConfigVar ('SHOW_LAST_TAB', 'no');
f0ed1181 1017 setConfigVar ('EXT_IPV4_VIEW', 'yes');
efee2692 1018 setConfigVar ('TREE_THRESHOLD', '25');
2be3fd23 1019 setConfigVar ('IPV4_JAYWALK', 'no');
9318d2ef 1020 setConfigVar ('ADDNEW_AT_TOP', 'yes');
64347dcf 1021 setConfigVar ('IPV4_TREE_SHOW_USAGE', 'yes');
37e59768
DO
1022 setConfigVar ('PREVIEW_TEXT_MAXCHARS', '10240');
1023 setConfigVar ('PREVIEW_TEXT_ROWS', '25');
1024 setConfigVar ('PREVIEW_TEXT_COLS', '80');
1025 setConfigVar ('PREVIEW_IMAGE_MAXPXS', '320');
f3d274bf 1026 setConfigVar ('VENDOR_SIEVE', '');
35bf153d 1027 setConfigVar ('IPV4LB_LISTSRC', '{$typeid_4}');
8fee82b4
DO
1028 setConfigVar ('IPV4OBJ_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_12} or {$typeid_445} or {$typeid_447} or {$typeid_798}');
1029 setConfigVar ('IPV4NAT_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_798}');
35bf153d
DO
1030 setConfigVar ('ASSETWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
1031 setConfigVar ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}');
f5883ec1 1032 setConfigVar ('RACKS_PER_ROW','12');
590e1281 1033 setConfigVar ('FILTER_PREDICATE_SIEVE','');
23cdc7e9
DO
1034 setConfigVar ('FILTER_DEFAULT_ANDOR','or');
1035 setConfigVar ('FILTER_SUGGEST_ANDOR','yes');
1036 setConfigVar ('FILTER_SUGGEST_TAGS','yes');
1037 setConfigVar ('FILTER_SUGGEST_PREDICATES','yes');
1038 setConfigVar ('FILTER_SUGGEST_EXTRA','no');
8fee82b4 1039 setConfigVar ('DEFAULT_SNMP_COMMUNITY','public');
f06fe423 1040 setConfigVar ('IPV4_ENABLE_KNIGHT','yes');
9e51318b
DO
1041 setConfigVar ('TAGS_TOPLIST_SIZE','50');
1042 setConfigVar ('TAGS_QUICKLIST_SIZE','20');
1043 setConfigVar ('TAGS_QUICKLIST_THRESHOLD','50');
f44fdef9 1044 setConfigVar ('ENABLE_MULTIPORT_FORM', 'no');
2400d7ec
DO
1045 setConfigVar ('DEFAULT_PORT_IIF_ID', '1');
1046 setConfigVar ('DEFAULT_PORT_OIF_IDS', '1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084');
4a47d34b 1047 setConfigVar ('IPV4_TREE_RTR_AS_CELL', 'yes');
cd3775e9 1048 setConfigVar ('PROXIMITY_RANGE', 0);
135080d8 1049 return buildRedirectURL (__FUNCTION__, 'OK');
b07f617c
DO
1050}
1051
b6a7d936
DO
1052$msgcode['addRealServer']['OK'] = 34;
1053$msgcode['addRealServer']['ERR'] = 126;
732e4578 1054// Add single record.
ca461127
DO
1055function addRealServer ()
1056{
0cc24e9a
DY
1057 assertUIntArg ('pool_id');
1058 assertIPv4Arg ('remoteip');
1059 assertStringArg ('rsport', TRUE);
1060 assertStringArg ('rsconfig', TRUE);
103b1e1e
DO
1061 if (!addRStoRSPool (
1062 $_REQUEST['pool_id'],
1063 $_REQUEST['remoteip'],
1064 $_REQUEST['rsport'],
1065 getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'),
1066 $_REQUEST['rsconfig']
1067 ))
135080d8 1068 return buildRedirectURL (__FUNCTION__, 'ERR');
d6517a21 1069 else
135080d8 1070 return buildRedirectURL (__FUNCTION__, 'OK');
d6517a21
DO
1071}
1072
b6a7d936
DO
1073$msgcode['addRealServers']['OK'] = 37;
1074$msgcode['addRealServers']['ERR1'] = 131;
1075$msgcode['addRealServers']['ERR2'] = 127;
732e4578
DO
1076// Parse textarea submitted and try adding a real server for each line.
1077function addRealServers ()
1078{
0cc24e9a
DY
1079 assertUIntArg ('pool_id');
1080 assertStringArg ('format');
1081 assertStringArg ('rawtext');
732e4578
DO
1082 $rawtext = str_replace ('\r', '', $_REQUEST['rawtext']);
1083 $ngood = $nbad = 0;
1084 $rsconfig = '';
1085 // Keep in mind, that the text will have HTML entities (namely '>') escaped.
1086 foreach (explode ('\n', $rawtext) as $line)
1087 {
59a83bd8 1088 if (!strlen ($line))
732e4578
DO
1089 continue;
1090 $match = array ();
1091 switch ($_REQUEST['format'])
1092 {
1093 case 'ipvs_2': // address and port only
1094 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) /', $line, $match))
1095 continue;
103b1e1e 1096 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
732e4578
DO
1097 $ngood++;
1098 else
1099 $nbad++;
1100 break;
1101 case 'ipvs_3': // address, port and weight
1102 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match))
1103 continue;
103b1e1e 1104 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3]))
732e4578
DO
1105 $ngood++;
1106 else
1107 $nbad++;
1108 break;
e69c2aa3
DO
1109 case 'ssv_2': // IP address and port
1110 if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match))
1111 continue;
103b1e1e 1112 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
e69c2aa3
DO
1113 $ngood++;
1114 else
1115 $nbad++;
1116 break;
948c37e3
DO
1117 case 'ssv_1': // IP address
1118 if (!preg_match ('/^([0-9\.]+)$/', $line, $match))
1119 continue;
1120 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
1121 $ngood++;
1122 else
1123 $nbad++;
1124 break;
732e4578 1125 default:
135080d8 1126 return buildRedirectURL (__FUNCTION__, 'ERR1');
732e4578
DO
1127 break;
1128 }
1129 }
1130 if ($nbad == 0 and $ngood > 0)
135080d8 1131 return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood));
732e4578 1132 else
135080d8 1133 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($ngood, $nbad));
732e4578
DO
1134}
1135
b6a7d936
DO
1136$msgcode['addVService']['OK'] = 28;
1137$msgcode['addVService']['ERR1'] = 132;
1138$msgcode['addVService']['ERR2'] = 100;
d6517a21
DO
1139function addVService ()
1140{
0cc24e9a
DY
1141 assertIPv4Arg ('vip');
1142 assertUIntArg ('vport');
1143 assertStringArg ('proto');
103b1e1e 1144 if ($_REQUEST['proto'] != 'TCP' and $_REQUEST['proto'] != 'UDP')
135080d8 1145 return buildRedirectURL (__FUNCTION__, 'ERR1');
0cc24e9a
DY
1146 assertStringArg ('name', TRUE);
1147 assertStringArg ('vsconfig', TRUE);
1148 assertStringArg ('rsconfig', TRUE);
c63a8d6e
DO
1149 $error = commitCreateVS
1150 (
103b1e1e
DO
1151 $_REQUEST['vip'],
1152 $_REQUEST['vport'],
7320b661 1153 $_REQUEST['proto'],
103b1e1e
DO
1154 $_REQUEST['name'],
1155 $_REQUEST['vsconfig'],
c63a8d6e
DO
1156 $_REQUEST['rsconfig'],
1157 isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array()
1158 );
1159 if ($error != '')
135080d8 1160 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error));
ca461127 1161 else
135080d8 1162 return buildRedirectURL (__FUNCTION__, 'OK');
fb1c4a54
DO
1163}
1164
b6a7d936
DO
1165$msgcode['deleteRealServer']['OK'] = 35;
1166$msgcode['deleteRealServer']['ERR'] = 128;
fb1c4a54
DO
1167function deleteRealServer ()
1168{
0cc24e9a 1169 assertUIntArg ('id');
d6517a21 1170 if (!commitDeleteRS ($_REQUEST['id']))
135080d8 1171 return buildRedirectURL (__FUNCTION__, 'ERR');
fb1c4a54 1172 else
135080d8 1173 return buildRedirectURL (__FUNCTION__, 'OK');
fb1c4a54
DO
1174}
1175
b6a7d936
DO
1176$msgcode['deleteLoadBalancer']['OK'] = 19;
1177$msgcode['deleteLoadBalancer']['ERR'] = 129;
3241551e
DO
1178function deleteLoadBalancer ()
1179{
0cc24e9a
DY
1180 assertUIntArg ('object_id');
1181 assertUIntArg ('pool_id');
1182 assertUIntArg ('vs_id');
103b1e1e
DO
1183 if (!commitDeleteLB (
1184 $_REQUEST['object_id'],
1185 $_REQUEST['pool_id'],
1186 $_REQUEST['vs_id']
1187 ))
135080d8 1188 return buildRedirectURL (__FUNCTION__, 'ERR');
d6517a21 1189 else
135080d8 1190 return buildRedirectURL (__FUNCTION__, 'OK');
d6517a21
DO
1191}
1192
b6a7d936
DO
1193$msgcode['deleteVService']['OK'] = 29;
1194$msgcode['deleteVService']['ERR'] = 130;
d6517a21
DO
1195function deleteVService ()
1196{
0cc24e9a 1197 assertUIntArg ('vs_id');
e02e1941 1198 if (!commitDeleteVS ($_REQUEST['vs_id']))
135080d8 1199 return buildRedirectURL (__FUNCTION__, 'ERR');
3241551e 1200 else
135080d8 1201 return buildRedirectURL (__FUNCTION__, 'OK');
3241551e
DO
1202}
1203
b6a7d936
DO
1204$msgcode['updateRealServer']['OK'] = 36;
1205$msgcode['updateRealServer']['ERR'] = 133;
fb1c4a54
DO
1206function updateRealServer ()
1207{
0cc24e9a
DY
1208 assertUIntArg ('rs_id');
1209 assertIPv4Arg ('rsip');
1210 assertStringArg ('rsport', TRUE);
1211 assertStringArg ('rsconfig', TRUE);
103b1e1e
DO
1212 if (!commitUpdateRS (
1213 $_REQUEST['rs_id'],
1214 $_REQUEST['rsip'],
1215 $_REQUEST['rsport'],
1216 $_REQUEST['rsconfig']
1217 ))
135080d8 1218 return buildRedirectURL (__FUNCTION__, 'ERR');
fb1c4a54 1219 else
135080d8 1220 return buildRedirectURL (__FUNCTION__, 'OK');
ca461127
DO
1221}
1222
b6a7d936
DO
1223$msgcode['updateLoadBalancer']['OK'] = 20;
1224$msgcode['updateLoadBalancer']['ERR'] = 134;
c1ca768c 1225function updateLoadBalancer ()
3241551e 1226{
0cc24e9a
DY
1227 assertUIntArg ('object_id');
1228 assertUIntArg ('pool_id');
1229 assertUIntArg ('vs_id');
1230 assertStringArg ('vsconfig', TRUE);
1231 assertStringArg ('rsconfig', TRUE);
103b1e1e
DO
1232 if (!commitUpdateLB (
1233 $_REQUEST['object_id'],
1234 $_REQUEST['pool_id'],
1235 $_REQUEST['vs_id'],
1236 $_REQUEST['vsconfig'],
1237 $_REQUEST['rsconfig']
1238 ))
135080d8 1239 return buildRedirectURL (__FUNCTION__, 'ERR');
d6517a21 1240 else
135080d8 1241 return buildRedirectURL (__FUNCTION__, 'OK');
d6517a21
DO
1242}
1243
b6a7d936
DO
1244$msgcode['updateVService']['OK'] = 30;
1245$msgcode['updateVService']['ERR'] = 135;
d6517a21
DO
1246function updateVService ()
1247{
0cc24e9a
DY
1248 assertUIntArg ('vs_id');
1249 assertIPv4Arg ('vip');
1250 assertUIntArg ('vport');
1251 assertStringArg ('proto');
1252 assertStringArg ('name', TRUE);
1253 assertStringArg ('vsconfig', TRUE);
1254 assertStringArg ('rsconfig', TRUE);
103b1e1e
DO
1255 if (!commitUpdateVS (
1256 $_REQUEST['vs_id'],
1257 $_REQUEST['vip'],
1258 $_REQUEST['vport'],
1259 $_REQUEST['proto'],
1260 $_REQUEST['name'],
1261 $_REQUEST['vsconfig'],
1262 $_REQUEST['rsconfig']
1263 ))
135080d8 1264 return buildRedirectURL (__FUNCTION__, 'ERR');
3241551e 1265 else
135080d8 1266 return buildRedirectURL (__FUNCTION__, 'OK');
3241551e
DO
1267}
1268
b6a7d936
DO
1269$msgcode['addLoadBalancer']['OK'] = 18;
1270$msgcode['addLoadBalancer']['ERR'] = 137;
3241551e
DO
1271function addLoadBalancer ()
1272{
0cc24e9a
DY
1273 assertUIntArg ('pool_id');
1274 assertUIntArg ('object_id');
1275 assertUIntArg ('vs_id');
1276 assertStringArg ('vsconfig', TRUE);
1277 assertStringArg ('rsconfig', TRUE);
103b1e1e
DO
1278 if (!addLBtoRSPool (
1279 $_REQUEST['pool_id'],
1280 $_REQUEST['object_id'],
1281 $_REQUEST['vs_id'],
1282 $_REQUEST['vsconfig'],
1283 $_REQUEST['rsconfig']
1284 ))
135080d8 1285 return buildRedirectURL (__FUNCTION__, 'ERR');
3241551e 1286 else
135080d8 1287 return buildRedirectURL (__FUNCTION__, 'OK');
3241551e
DO
1288}
1289
b6a7d936
DO
1290$msgcode['addRSPool']['OK'] = 31;
1291$msgcode['addRSPool']['ERR'] = 100;
5ad76f01
DO
1292function addRSPool ()
1293{
0cc24e9a
DY
1294 assertStringArg ('name', TRUE);
1295 assertStringArg ('vsconfig', TRUE);
1296 assertStringArg ('rsconfig', TRUE);
c63a8d6e
DO
1297 $error = commitCreateRSPool
1298 (
103b1e1e
DO
1299 $_REQUEST['name'],
1300 $_REQUEST['vsconfig'],
c63a8d6e
DO
1301 $_REQUEST['rsconfig'],
1302 isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array()
1303 );
1304 if ($error != '')
135080d8 1305 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
5ad76f01 1306 else
135080d8 1307 return buildRedirectURL (__FUNCTION__, 'OK');
5ad76f01
DO
1308}
1309
b6a7d936
DO
1310$msgcode['deleteRSPool']['OK'] = 32;
1311$msgcode['deleteRSPool']['ERR'] = 138;
5ad76f01
DO
1312function deleteRSPool ()
1313{
0cc24e9a 1314 assertUIntArg ('pool_id');
841a7a7a 1315 if (!commitDeleteRSPool ($_REQUEST['pool_id']))
135080d8 1316 return buildRedirectURL (__FUNCTION__, 'ERR');
5ad76f01 1317 else
135080d8 1318 return buildRedirectURL (__FUNCTION__, 'OK');
5ad76f01
DO
1319}
1320
b6a7d936
DO
1321$msgcode['updateRSPool']['OK'] = 33;
1322$msgcode['updateRSPool']['ERR'] = 139;
5ad76f01
DO
1323function updateRSPool ()
1324{
0cc24e9a
DY
1325 assertUIntArg ('pool_id');
1326 assertStringArg ('name', TRUE);
1327 assertStringArg ('vsconfig', TRUE);
1328 assertStringArg ('rsconfig', TRUE);
841a7a7a 1329 if (!commitUpdateRSPool ($_REQUEST['pool_id'], $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
135080d8 1330 return buildRedirectURL (__FUNCTION__, 'ERR');
5ad76f01 1331 else
135080d8 1332 return buildRedirectURL (__FUNCTION__, 'OK');
5ad76f01
DO
1333}
1334
b6a7d936
DO
1335$msgcode['updateRSInService']['OK'] = 38;
1336$msgcode['updateRSInService']['ERR'] = 140;
1f7d18fa
DO
1337function updateRSInService ()
1338{
0cc24e9a 1339 assertUIntArg ('rscount');
841a7a7a 1340 $pool_id = $_REQUEST['pool_id'];
a6e91ac2
DO
1341 $orig = spotEntity ('ipv4rspool', $pool_id);
1342 amplifyCell ($orig);
1f7d18fa
DO
1343 $nbad = $ngood = 0;
1344 for ($i = 1; $i <= $_REQUEST['rscount']; $i++)
1345 {
1346 $rs_id = $_REQUEST["rsid_${i}"];
1347 if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on')
1348 $newval = 'yes';
1349 else
1350 $newval = 'no';
1351 if ($newval != $orig['rslist'][$rs_id]['inservice'])
1352 {
1353 if (commitSetInService ($rs_id, $newval))
1354 $ngood++;
1355 else
1356 $nbad++;
1357 }
1358 }
1359 if (!$nbad)
135080d8 1360 return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood));
1f7d18fa 1361 else
135080d8 1362 return buildRedirectURL (__FUNCTION__, 'ERR', array ($nbad, $ngood));
1f7d18fa
DO
1363}
1364
b6a7d936
DO
1365$msgcode['importPTRData']['OK'] = 26;
1366$msgcode['importPTRData']['ERR'] = 141;
8d9c16e7
DO
1367// FIXME: check, that each submitted address belongs to the prefix we
1368// are operating on.
03eb5209
DO
1369function importPTRData ()
1370{
0cc24e9a 1371 assertUIntArg ('addrcount');
03eb5209 1372 $nbad = $ngood = 0;
03eb5209
DO
1373 for ($i = 0; $i < $_REQUEST['addrcount']; $i++)
1374 {
3f3bd41e 1375 $inputname = "import_${i}";
03eb5209
DO
1376 if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on')
1377 continue;
0cc24e9a
DY
1378 assertIPv4Arg ("addr_${i}");
1379 assertStringArg ("descr_${i}", TRUE);
1380 assertStringArg ("rsvd_${i}");
3f3bd41e
DO
1381 // Non-existent addresses will not have this argument set in request.
1382 $rsvd = 'no';
03eb5209
DO
1383 if ($_REQUEST["rsvd_${i}"] == 'yes')
1384 $rsvd = 'yes';
3f3bd41e 1385 if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '')
03eb5209
DO
1386 $ngood++;
1387 else
1388 $nbad++;
1389 }
1390 if (!$nbad)
135080d8 1391 return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood));
03eb5209 1392 else
135080d8 1393 return buildRedirectURL (__FUNCTION__, 'ERR', array ($nbad, $ngood));
03eb5209
DO
1394}
1395
b6a7d936
DO
1396$msgcode['generateAutoPorts']['OK'] = 21;
1397$msgcode['generateAutoPorts']['ERR'] = 142;
f3f0161f
DO
1398function generateAutoPorts ()
1399{
103b1e1e 1400 global $pageno;
0cc24e9a 1401 assertUIntArg ('object_id');
6297d584 1402 $info = spotEntity ('object', $_REQUEST['object_id']);
f3f0161f 1403 // Navigate away in case of success, stay at the place otherwise.
103b1e1e 1404 if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id']))
135080d8 1405 return buildRedirectURL (__FUNCTION__, 'OK', array(), $pageno, 'ports');
f3f0161f 1406 else
135080d8 1407 return buildRedirectURL (__FUNCTION__, 'ERR');
f3f0161f
DO
1408}
1409
b6a7d936
DO
1410$msgcode['saveEntityTags']['OK'] = 22;
1411$msgcode['saveEntityTags']['ERR1'] = 143;
1412$msgcode['saveEntityTags']['ERR2'] = 187;
24cbe8af 1413// Filter out implicit tags before storing the new tag set.
3355ca56 1414function saveEntityTags ()
24cbe8af 1415{
eb27afad 1416 global $page, $pageno, $etype_by_pageno;
be2ae2a2 1417 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
9a61c175 1418 return buildRedirectURL (__FUNCTION__, 'ERR2', array (__FUNCTION__));
be2ae2a2 1419 $realm = $etype_by_pageno[$pageno];
3355ca56 1420 $bypass = $page[$pageno]['bypass'];
0cc24e9a 1421 assertUIntArg ($bypass);
2034d968 1422 $entity_id = $_REQUEST[$bypass];
e04931c8 1423 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
6e49bd1f 1424 // Build a chain from the submitted data, minimize it,
ab379543 1425 // then wipe existing records and store the new set instead.
01b6b4d6 1426 destroyTagsForEntity ($realm, $entity_id);
eb27afad
DO
1427 // TODO: these actions are very close to what rebuildTagChainForEntity() does,
1428 // so why not use it?
6e49bd1f 1429 $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist));
ab379543 1430 $n_succeeds = $n_errors = 0;
6e49bd1f 1431 foreach ($newchain as $taginfo)
eb6ea26f 1432 if (addTagForEntity ($realm, $entity_id, $taginfo['id']))
ab379543
DO
1433 $n_succeeds++;
1434 else
1435 $n_errors++;
ab379543 1436 if ($n_errors)
9a61c175 1437 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($n_succeeds, $n_errors));
ab379543 1438 else
135080d8 1439 return buildRedirectURL (__FUNCTION__, 'OK', array ($n_succeeds));
2034d968
DO
1440}
1441
b6a7d936
DO
1442$msgcode['destroyTag']['OK'] = 58;
1443$msgcode['destroyTag']['ERR1'] = 183;
1444$msgcode['destroyTag']['ERR2'] = 144;
fe7044ad
DO
1445function destroyTag ()
1446{
0cc24e9a 1447 assertUIntArg ('tag_id');
c615a655
DO
1448 global $taglist;
1449 if (!isset ($taglist[$_REQUEST['tag_id']]))
1450 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($_REQUEST['tag_id']));
49fb1027 1451 if (($ret = commitDestroyTag ($_REQUEST['tag_id'])) == '')
c615a655 1452 return buildRedirectURL (__FUNCTION__, 'OK', array ($taglist[$_REQUEST['tag_id']]['tag']));
fe7044ad 1453 else
c615a655 1454 return buildRedirectURL (__FUNCTION__, 'ERR2');
fe7044ad
DO
1455}
1456
b6a7d936
DO
1457$msgcode['createTag']['OK'] = 59;
1458$msgcode['createTag']['ERR1'] = 145;
1459$msgcode['createTag']['ERR3'] = 147;
fe7044ad
DO
1460function createTag ()
1461{
0cc24e9a
DY
1462 assertStringArg ('tag_name');
1463 assertUIntArg ('parent_id', TRUE);
49fb1027 1464 $tagname = trim ($_REQUEST['tag_name']);
2eeeca80 1465 if (!validTagName ($tagname))
135080d8 1466 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($tagname));
fe7044ad
DO
1467 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1468 $parent_id = 'NULL';
1469 if (($ret = commitCreateTag ($tagname, $parent_id)) == '')
135080d8 1470 return buildRedirectURL (__FUNCTION__, 'OK', array ($tagname));
fe7044ad 1471 else
135080d8 1472 return buildRedirectURL (__FUNCTION__, 'ERR3', array ($tagname, $ret));
fe7044ad
DO
1473}
1474
b6a7d936
DO
1475$msgcode['updateTag']['OK'] = 60;
1476$msgcode['updateTag']['ERR1'] = 145;
1477$msgcode['updateTag']['ERR2'] = 148;
49fb1027
DO
1478function updateTag ()
1479{
0cc24e9a
DY
1480 assertUIntArg ('tag_id');
1481 assertUIntArg ('parent_id', TRUE);
1482 assertStringArg ('tag_name');
49fb1027 1483 $tagname = trim ($_REQUEST['tag_name']);
2eeeca80 1484 if (!validTagName ($tagname))
135080d8 1485 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($tagname));
49fb1027
DO
1486 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1487 $parent_id = 'NULL';
1488 if (($ret = commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id)) == '')
135080d8 1489 return buildRedirectURL (__FUNCTION__, 'OK', array ($tagname));
590e1281
DO
1490 // Use old name in the message, cause update failed.
1491 global $taglist;
1492 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($taglist[$_REQUEST['tag_id']]['tag'], $ret));
49fb1027
DO
1493}
1494
b6a7d936
DO
1495$msgcode['rollTags']['OK'] = 67;
1496$msgcode['rollTags']['ERR'] = 149;
eb6ea26f
DO
1497function rollTags ()
1498{
0cc24e9a
DY
1499 assertUIntArg ('row_id');
1500 assertStringArg ('sum', TRUE);
1501 assertUIntArg ('realsum');
eb6ea26f 1502 if ($_REQUEST['sum'] != $_REQUEST['realsum'])
135080d8 1503 return buildRedirectURL (__FUNCTION__, 'ERR');
abef7149
DO
1504 // Even if the user requested an empty tag list, don't bail out, but process existing
1505 // tag chains with "zero" extra. This will make sure, that the stuff processed will
1506 // have its chains refined to "normal" form.
1507 $extratags = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1508 $n_ok = 0;
1509 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
1510 // filter out the same tag again and again. It will have own noise to cancel.
1511 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
61a1d996 1512 foreach (listCells ('rack', $_REQUEST['row_id']) as $rack)
abef7149 1513 {
61a1d996 1514 if (rebuildTagChainForEntity ('rack', $rack['id'], $extrachain))
abef7149 1515 $n_ok++;
61a1d996
DO
1516 amplifyCell ($rack);
1517 foreach ($rack['mountedObjects'] as $object_id)
abef7149
DO
1518 if (rebuildTagChainForEntity ('object', $object_id, $extrachain))
1519 $n_ok++;
1520 }
135080d8 1521 return buildRedirectURL (__FUNCTION__, 'OK', array ($n_ok));
eb6ea26f
DO
1522}
1523
b6a7d936
DO
1524$msgcode['changeMyPassword']['OK'] = 61;
1525$msgcode['changeMyPassword']['ERR1'] = 150;
1526$msgcode['changeMyPassword']['ERR2'] = 151;
1527$msgcode['changeMyPassword']['ERR3'] = 152;
1528$msgcode['changeMyPassword']['ERR4'] = 153;
9457ca59 1529function changeMyPassword ()
cced6b7d 1530{
b82cce3f 1531 global $remote_username, $user_auth_src;
204284ba 1532 if ($user_auth_src != 'database')
135080d8 1533 return buildRedirectURL (__FUNCTION__, 'ERR1');
0cc24e9a
DY
1534 assertStringArg ('oldpassword');
1535 assertStringArg ('newpassword1');
1536 assertStringArg ('newpassword2');
b82cce3f 1537 $remote_userid = getUserIDByUsername ($remote_username);
0b2c74cb 1538 $userinfo = spotEntity ('user', $remote_userid);
b82cce3f 1539 if ($userinfo['user_password_hash'] != sha1 ($_REQUEST['oldpassword']))
135080d8 1540 return buildRedirectURL (__FUNCTION__, 'ERR2');
cced6b7d 1541 if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2'])
135080d8 1542 return buildRedirectURL (__FUNCTION__, 'ERR3');
b82cce3f 1543 if (commitUpdateUserAccount ($remote_userid, $userinfo['user_name'], $userinfo['user_realname'], sha1 ($_REQUEST['newpassword1'])))
135080d8 1544 return buildRedirectURL (__FUNCTION__, 'OK');
cced6b7d 1545 else
135080d8 1546 return buildRedirectURL (__FUNCTION__, 'ERR4');
cced6b7d
DO
1547}
1548
b6a7d936
DO
1549$msgcode['saveRackCode']['OK'] = 43;
1550$msgcode['saveRackCode']['ERR1'] = 154;
1551$msgcode['saveRackCode']['ERR2'] = 155;
cced6b7d
DO
1552function saveRackCode ()
1553{
cced6b7d 1554 assertStringArg ('rackcode');
e6a4adb9
DO
1555 // For the test to succeed, unescape LFs, strip CRs.
1556 $newcode = str_replace ('\r', '', str_replace ('\n', "\n", $_REQUEST['rackcode']));
cf25e649
DO
1557 $parseTree = getRackCode ($newcode);
1558 if ($parseTree['result'] != 'ACK')
135080d8 1559 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($parseTree['load']));
4a6a28f1 1560 saveScript ('RackCodeCache', '');
cf25e649 1561 if (saveScript ('RackCode', $newcode))
135080d8 1562 return buildRedirectURL (__FUNCTION__, 'OK');
cced6b7d 1563 else
135080d8 1564 return buildRedirectURL (__FUNCTION__, 'ERR2');
cced6b7d
DO
1565}
1566
b6a7d936 1567$msgcode['setPortVLAN']['ERR1'] = 156;
46f92ff7
DO
1568// This handler's context is pre-built, but not authorized. It is assumed, that the
1569// handler will take existing context and before each commit check authorization
1570// on the base chain plus necessary context added.
1571function setPortVLAN ()
1572{
0cc24e9a 1573 assertUIntArg ('portcount');
46f92ff7
DO
1574 $data = getSwitchVLANs ($_REQUEST['object_id']);
1575 if ($data === NULL)
135080d8 1576 return buildRedirectURL (__FUNCTION__, 'ERR1');
46f92ff7
DO
1577 list ($vlanlist, $portlist) = $data;
1578 // Here we just build up 1 set command for the gateway with all of the ports
1579 // included. The gateway is expected to filter unnecessary changes silently
1580 // and to provide a list of responses with either error or success message
1581 // for each of the rest.
1582 $nports = $_REQUEST['portcount'];
1583 $prefix = 'set ';
db55cf54 1584 $log = emptyLog();
46f92ff7
DO
1585 $setcmd = '';
1586 for ($i = 0; $i < $nports; $i++)
1587 if
1588 (
1589 !isset ($_REQUEST['portname_' . $i]) ||
1590 !isset ($_REQUEST['vlanid_' . $i]) ||
1591 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
1592 )
24dcb9d8 1593 $log['m'][] = array ('c' => 158, 'a' => array ($i));
46f92ff7
DO
1594 elseif
1595 (
1596 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
1597 $portlist[$i]['vlaind'] == 'TRUNK'
1598 )
1599 continue;
1600 else
1601 {
1602 $portname = $_REQUEST['portname_' . $i];
1603 $oldvlanid = $portlist[$i]['vlanid'];
1604 $newvlanid = $_REQUEST['vlanid_' . $i];
1605 // Finish the security context and evaluate it.
1606 $annex = array();
1607 $annex[] = array ('tag' => '$fromvlan_' . $oldvlanid);
1608 $annex[] = array ('tag' => '$tovlan_' . $newvlanid);
1609 if (!permitted (NULL, NULL, NULL, $annex))
1610 {
24dcb9d8 1611 $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid));
46f92ff7
DO
1612 continue;
1613 }
1614 $setcmd .= $prefix . $portname . '=' . $newvlanid;
1615 $prefix = ';';
1616 }
1617 // Feed the gateway and interpret its (non)response.
1618 if ($setcmd != '')
f0ff4930 1619 $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd));
46f92ff7 1620 else
24dcb9d8 1621 $log['m'][] = array ('c' => 201);
46f92ff7
DO
1622 return buildWideRedirectURL ($log);
1623}
1624
2987fc1f
DO
1625function submitSLBConfig ()
1626{
0cc24e9a 1627 assertUIntArg ('object_id');
2987fc1f 1628 $newconfig = buildLVSConfig ($_REQUEST['object_id']);
ff0df5c3 1629 $msglog = gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8'));
2987fc1f
DO
1630 return buildWideRedirectURL ($msglog);
1631}
1632
b6a7d936
DO
1633$msgcode['addRow']['OK'] = 74;
1634$msgcode['addRow']['ERR'] = 100;
345fd640
AD
1635function addRow ()
1636{
0cc24e9a 1637 assertStringArg ('name');
345fd640 1638
10bac82a 1639 if (commitAddRow ($_REQUEST['name']) === TRUE)
135080d8 1640 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name']));
345fd640 1641 else
135080d8 1642 return buildRedirectURL (__FUNCTION__, 'ERR', array ($_REQUEST['name']));
345fd640
AD
1643}
1644
b6a7d936
DO
1645$msgcode['updateRow']['OK'] = 75;
1646$msgcode['updateRow']['ERR'] = 100;
345fd640
AD
1647function updateRow ()
1648{
0cc24e9a
DY
1649 assertUIntArg ('row_id');
1650 assertStringArg ('name');
345fd640 1651
10bac82a 1652 if (TRUE === commitUpdateRow ($_REQUEST['row_id'], $_REQUEST['name']))
135080d8 1653 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name']));
345fd640 1654 else
135080d8 1655 return buildRedirectURL (__FUNCTION__, 'ERR', array ($_REQUEST['name']));
345fd640
AD
1656}
1657
b6a7d936
DO
1658$msgcode['deleteRow']['OK'] = 77;
1659$msgcode['deleteRow']['ERR'] = 100;
9f14a7ef
DY
1660function deleteRow ()
1661{
0cc24e9a 1662 assertUIntArg ('row_id');
7be51fea 1663 $rowinfo = getRackRowInfo ($_REQUEST['row_id']);
9f14a7ef
DY
1664
1665 if (TRUE === commitDeleteRow ($_REQUEST['row_id']))
7be51fea 1666 return buildRedirectURL (__FUNCTION__, 'OK', array ($rowinfo['name']));
9f14a7ef 1667 else
7be51fea 1668 return buildRedirectURL (__FUNCTION__, 'ERR', array ($rowinfo['name']));
9f14a7ef
DY
1669}
1670
b6a7d936
DO
1671$msgcode['addRack']['OK'] = 65;
1672$msgcode['addRack']['ERR1'] = 171;
1673$msgcode['addRack']['ERR2'] = 172;
f19c75d6
DO
1674function addRack ()
1675{
0cc24e9a 1676 assertUIntArg ('row_id');
f19c75d6
DO
1677 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1678 if (isset ($_REQUEST['got_data']))
1679 {
0cc24e9a
DY
1680 assertStringArg ('rack_name');
1681 assertUIntArg ('rack_height1');
1682 assertStringArg ('rack_comment', TRUE);
f19c75d6
DO
1683
1684 if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
135080d8 1685 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name']));
f19c75d6 1686 else
135080d8 1687 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($_REQUEST['rack_name']));
f19c75d6
DO
1688 }
1689 elseif (isset ($_REQUEST['got_mdata']))
1690 {
0cc24e9a
DY
1691 assertUIntArg ('rack_height2');
1692 assertStringArg ('rack_names', TRUE);
db55cf54 1693 $log = emptyLog();
f19c75d6
DO
1694 // copy-and-paste from renderAddMultipleObjectsForm()
1695 $names1 = explode ('\n', $_REQUEST['rack_names']);
1696 $names2 = array();
1697 foreach ($names1 as $line)
1698 {
1699 $parts = explode ('\r', $line);
1700 reset ($parts);
59a83bd8 1701 if (!strlen ($parts[0]))
f19c75d6
DO
1702 continue;
1703 else
1704 $names2[] = rtrim ($parts[0]);
1705 }
b3029d5c 1706 global $msgcode;
f19c75d6
DO
1707 foreach ($names2 as $cname)
1708 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE)
b3029d5c 1709 $log['m'][] = array ('c' => $msgcode[__FUNCTION__]['OK'], 'a' => array ($cname));
f19c75d6 1710 else
b3029d5c 1711 $log['m'][] = array ('c' => $msgcode[__FUNCTION__]['ERR1'], 'a' => array ($cname));
f19c75d6
DO
1712 return buildWideRedirectURL ($log);
1713 }
1714 else
135080d8 1715 return buildRedirectURL (__FUNCTION__, 'ERR2');
f19c75d6
DO
1716}
1717
b6a7d936
DO
1718$msgcode['deleteRack']['OK'] = 79;
1719$msgcode['deleteRack']['ERR'] = 100;
1720$msgcode['deleteRack']['ERR1'] = 206;
c8187437
DY
1721function deleteRack ()
1722{
0cc24e9a 1723 assertUIntArg ('rack_id');
61a1d996
DO
1724 if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id'])))
1725 return buildRedirectURL (__FUNCTION__, 'ERR', array ('Rack not found'), 'rackspace', 'default');
1726 amplifyCell ($rackData);
1727 if (count ($rackData['mountedObjects']))
c8187437 1728 return buildRedirectURL (__FUNCTION__, 'ERR1');
61a1d996
DO
1729 if (TRUE !== commitDeleteRack ($_REQUEST['rack_id']))
1730 return buildRedirectURL (__FUNCTION__, 'ERR', array(), 'rackspace', 'default');
1731 return buildRedirectURL (__FUNCTION__, 'OK', array ($rackData['name']), 'rackspace', 'default');
c8187437
DY
1732}
1733
b6a7d936
DO
1734$msgcode['updateRack']['OK'] = 68;
1735$msgcode['updateRack']['ERR'] = 177;
7056988c
DO
1736function updateRack ()
1737{
0cc24e9a
DY
1738 assertUIntArg ('rack_id');
1739 assertUIntArg ('rack_row_id');
1740 assertUIntArg ('rack_height');
1741 assertStringArg ('rack_name');
1742 assertStringArg ('rack_comment', TRUE);
7056988c 1743
7056988c 1744 resetThumbCache ($_REQUEST['rack_id']);
0c2b7c4a 1745 if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
135080d8 1746 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name']));
0c2b7c4a 1747 else
135080d8 1748 return buildRedirectURL (__FUNCTION__, 'ERR');
7056988c
DO
1749}
1750
61a1d996 1751$msgcode['updateRackDesign']['ERR'] = 100;
4fbb5a00
DY
1752function updateRackDesign ()
1753{
0cc24e9a 1754 assertUIntArg ('rack_id');
61a1d996
DO
1755 if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id'])))
1756 return buildRedirectURL (__FUNCTION__, 'ERR', array ('Rack not found'), 'rackspace', 'default');
1757 amplifyCell ($rackData);
4fbb5a00
DY
1758 applyRackDesignMask($rackData);
1759 markupObjectProblems ($rackData);
1760 $response = processGridForm ($rackData, 'A', 'F');
51690ad4 1761 return buildWideRedirectURL (array($response));
4fbb5a00
DY
1762}
1763
61a1d996 1764$msgcode['updateRackProblems']['ERR'] = 100;
4fbb5a00
DY
1765function updateRackProblems ()
1766{
0cc24e9a 1767 assertUIntArg ('rack_id');
61a1d996
DO
1768 if (NULL == ($rackData = spotEntity ('rack', $_REQUEST['rack_id'])))
1769 return buildRedirectURL (__FUNCTION__, 'ERR', array ('Rack not found'), 'rackspace', 'default');
1770 amplifyCell ($rackData);
4fbb5a00
DY
1771 applyRackProblemMask($rackData);
1772 markupObjectProblems ($rackData);
1773 $response = processGridForm ($rackData, 'F', 'U');
51690ad4 1774 return buildWideRedirectURL (array($response));
4fbb5a00
DY
1775}
1776
7056988c
DO
1777function querySNMPData ()
1778{
0cc24e9a
DY
1779 assertUIntArg ('object_id');
1780 assertStringArg ('community');
8536e20a 1781 return doSNMPmining ($_REQUEST['object_id'], $_REQUEST['community']);
7056988c
DO
1782}
1783
b6a7d936
DO
1784$msgcode['addFileWithoutLink']['OK'] = 69;
1785$msgcode['addFileWithoutLink']['ERR'] = 100;
e1ae3fb4
AD
1786// File-related functions
1787function addFileWithoutLink ()
1788{
0cc24e9a 1789 assertStringArg ('comment', TRUE);
e1ae3fb4
AD
1790
1791 // Make sure the file can be uploaded
1792 if (get_cfg_var('file_uploads') != 1)
135080d8 1793 return buildRedirectURL (__FUNCTION__, 'ERR', array ("file uploads not allowed, change 'file_uploads' parameter in php.ini"));
e1ae3fb4
AD
1794
1795 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
4bb95650
DO
1796 global $sic;
1797 // commitAddFile() uses prepared statements
1798 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']);
f857f71f
DO
1799 if (isset ($_REQUEST['taglist']))
1800 produceTagsForLastRecord ('file', $_REQUEST['taglist']);
e1ae3fb4
AD
1801
1802 if ($error != '')
135080d8 1803 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e1ae3fb4 1804
135080d8 1805 return buildRedirectURL (__FUNCTION__, 'OK', array ($_FILES['file']['name']));
e1ae3fb4
AD
1806}
1807
b6a7d936
DO
1808$msgcode['addFileToEntity']['OK'] = 69;
1809$msgcode['addFileToEntity']['ERR1'] = 187;
1810$msgcode['addFileToEntity']['ERR2'] = 181;
1811$msgcode['addFileToEntity']['ERR3'] = 182;
e1ae3fb4
AD
1812function addFileToEntity ()
1813{
9a61c175
DO
1814 global $page, $pageno, $etype_by_pageno;
1815 if (!isset ($etype_by_pageno[$pageno]) or !isset ($page[$pageno]['bypass']))
1816 return buildRedirectURL (__FUNCTION__, 'ERR1', array (__FUNCTION__));
1817 $realm = $etype_by_pageno[$pageno];
1818 $bypass = $page[$pageno]['bypass'];
0cc24e9a 1819 assertUIntArg ($bypass);
9a61c175 1820 $entity_id = $_REQUEST[$bypass];
0cc24e9a 1821 assertStringArg ('comment', TRUE);
e1ae3fb4
AD
1822
1823 // Make sure the file can be uploaded
1824 if (get_cfg_var('file_uploads') != 1)
9a61c175 1825 return buildRedirectURL (__FUNCTION__, 'ERR2');
e1ae3fb4
AD
1826
1827 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
4bb95650
DO
1828 global $sic;
1829 // commitAddFile() uses prepared statements
1830 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment']);
e1ae3fb4 1831 if ($error != '')
9a61c175 1832 return buildRedirectURL (__FUNCTION__, 'ERR3', array ($error));
e1ae3fb4 1833
9a61c175 1834 $error = commitLinkFile (lastInsertID(), $realm, $entity_id);
e1ae3fb4 1835 if ($error != '')
9a61c175 1836 return buildRedirectURL (__FUNCTION__, 'ERR3', array ($error));
e1ae3fb4 1837
135080d8 1838 return buildRedirectURL (__FUNCTION__, 'OK', array ($_FILES['file']['name']));
e1ae3fb4
AD
1839}
1840
b6a7d936
DO
1841$msgcode['linkFileToEntity']['OK'] = 71;
1842$msgcode['linkFileToEntity']['ERR1'] = 178;
1843$msgcode['linkFileToEntity']['ERR2'] = 100;
e1ae3fb4
AD
1844function linkFileToEntity ()
1845{
0cc24e9a 1846 assertUIntArg ('file_id');
482c7f35 1847 global $page, $pageno, $etype_by_pageno;
121496b6
DO
1848 $entity_type = $etype_by_pageno[$pageno];
1849 $bypass_name = $page[$pageno]['bypass'];
0cc24e9a 1850 assertUIntArg ($bypass_name);
121496b6 1851
d3b5008b 1852 $fi = spotEntity ('file', $_REQUEST['file_id']);
121496b6 1853 if ($fi === NULL)
135080d8 1854 return buildRedirectURL (__FUNCTION__, 'ERR1'); // file not found
121496b6 1855 $error = commitLinkFile ($_REQUEST['file_id'], $entity_type, $_REQUEST[$bypass_name]);
e1ae3fb4 1856 if ($error != '')
135080d8 1857 return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error)); // linking failed
e1ae3fb4 1858
135080d8 1859 return buildRedirectURL (__FUNCTION__, 'OK', array ($fi['name']));
e1ae3fb4
AD
1860}
1861
b6a7d936
DO
1862$msgcode['replaceFile']['OK'] = 70;
1863$msgcode['replaceFile']['ERR1'] = 181;
1864$msgcode['replaceFile']['ERR2'] = 207;
1865$msgcode['replaceFile']['ERR3'] = 182;
fd1fb420
AD
1866function replaceFile ()
1867{
db55cf54 1868 global $sic;
0cc24e9a 1869 assertUIntArg ('file_id');
fd1fb420
AD
1870
1871 // Make sure the file can be uploaded
1872 if (get_cfg_var('file_uploads') != 1)
db55cf54 1873 return buildRedirectURL (__FUNCTION__, 'ERR1');
d3b5008b 1874 $shortInfo = spotEntity ('file', $sic['file_id']);
fd1fb420
AD
1875
1876 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
db55cf54
DO
1877 if ($fp === FALSE)
1878 return buildRedirectURL (__FUNCTION__, 'ERR2');
f8874cdb 1879 $error = commitReplaceFile ($sic['file_id'], $fp);
fd1fb420 1880 if ($error != '')
db55cf54 1881 return buildRedirectURL (__FUNCTION__, 'ERR3', array ($error));
fd1fb420 1882
db55cf54 1883 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
fd1fb420
AD
1884}
1885
b6a7d936
DO
1886$msgcode['updateFile']['OK'] = 70;
1887$msgcode['updateFile']['ERR'] = 100;
e1ae3fb4
AD
1888function updateFile ()
1889{
0cc24e9a
DY
1890 assertUIntArg ('file_id');
1891 assertStringArg ('file_name');
1892 assertStringArg ('file_type');
1893 assertStringArg ('file_comment', TRUE);
f3d274bf
DO
1894 // prepared statement params below
1895 global $sic;
1896 $error = commitUpdateFile ($sic['file_id'], $sic['file_name'], $sic['file_type'], $sic['file_comment']);
e1ae3fb4 1897 if ($error != '')
135080d8 1898 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e1ae3fb4 1899
135080d8 1900 return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name']));
e1ae3fb4
AD
1901}
1902
b6a7d936
DO
1903$msgcode['unlinkFile']['OK'] = 72;
1904$msgcode['unlinkFile']['ERR'] = 182;
e1ae3fb4
AD
1905function unlinkFile ()
1906{
0cc24e9a 1907 assertUIntArg ('link_id');
e1ae3fb4
AD
1908 $error = commitUnlinkFile ($_REQUEST['link_id']);
1909
1910 if ($error != '')
135080d8 1911 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e1ae3fb4 1912
8bc5d1e4 1913 return buildRedirectURL (__FUNCTION__, 'OK');
e1ae3fb4
AD
1914}
1915
b6a7d936
DO
1916$msgcode['deleteFile']['OK'] = 73;
1917$msgcode['deleteFile']['ERR'] = 100;
e1ae3fb4
AD
1918function deleteFile ()
1919{
0cc24e9a 1920 assertUIntArg ('file_id');
d3b5008b 1921 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
e1ae3fb4
AD
1922 $error = commitDeleteFile ($_REQUEST['file_id']);
1923
1924 if ($error != '')
135080d8 1925 return buildRedirectURL (__FUNCTION__, 'ERR', array ($error));
e1ae3fb4 1926
f8874cdb 1927 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
e1ae3fb4
AD
1928}
1929
b6a7d936
DO
1930$msgcode['updateFileText']['OK'] = 78;
1931$msgcode['updateFileText']['ERR1'] = 179;
1932$msgcode['updateFileText']['ERR2'] = 180;
8628ae44
DO
1933function updateFileText ()
1934{
0cc24e9a
DY
1935 assertUIntArg ('file_id');
1936 assertStringArg ('mtime_copy');
1937 assertStringArg ('file_text', TRUE); // it's Ok to save empty
d3b5008b 1938 $shortInfo = spotEntity ('file', $_REQUEST['file_id']);
70cb9b56
DO
1939 if ($shortInfo['mtime'] != $_REQUEST['mtime_copy'])
1940 return buildRedirectURL (__FUNCTION__, 'ERR1');
f8874cdb
DO
1941 global $sic;
1942 $error = commitReplaceFile ($sic['file_id'], $sic['file_text']);
8628ae44 1943 if ($error == '')
f8874cdb 1944 return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name'])));
70cb9b56 1945 return buildRedirectURL (__FUNCTION__, 'ERR2');
8628ae44
DO
1946}
1947
2dfa1b73
DO
1948$msgcode['addPortInterfaceCompat']['OK'] = 48;
1949$msgcode['addPortInterfaceCompat']['ERR'] = 110;
1950function addPortInterfaceCompat ()
1951{
0cc24e9a
DY
1952 assertUIntArg ('iif_id');
1953 assertUIntArg ('oif_id');
2dfa1b73
DO
1954 if (commitSupplementPIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
1955 return buildRedirectURL (__FUNCTION__, 'OK');
1956 return buildRedirectURL (__FUNCTION__, 'ERR');
1957}
1958
1959$msgcode['delPortInterfaceCompat']['OK'] = 49;
1960$msgcode['delPortInterfaceCompat']['ERR'] = 111;
1961function delPortInterfaceCompat ()
1962{
0cc24e9a
DY
1963 assertUIntArg ('iif_id');
1964 assertUIntArg ('oif_id');
2dfa1b73
DO
1965 if (commitReducePIC ($_REQUEST['iif_id'], $_REQUEST['oif_id']))
1966 return buildRedirectURL (__FUNCTION__, 'OK');
1967 return buildRedirectURL (__FUNCTION__, 'ERR');
1968}
1969
2400d7ec
DO
1970$ifcompatpack = array
1971(
1972 '1000cwdm80' => array (1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216),
1973 '1000dwdm80' => array // ITU channels 20~61
1974 (
1975 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226,
1976 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236,
1977 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246,
1978 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256,
1979 1257, 1258
1980 ),
1981 '10000dwdm80' => array // same channels for 10GE
1982 (
1983 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268,
1984 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278,
1985 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288,
1986 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298,
1987 1299, 1300
1988 ),
1989);
1990
3d9ac3d4
DO
1991$msgcode['addPortInterfaceCompatPack']['OK'] = 44;
1992$msgcode['addPortInterfaceCompatPack']['ERR'] = 123;
2400d7ec
DO
1993function addPortInterfaceCompatPack ()
1994{
0cc24e9a
DY
1995 assertStringArg ('standard');
1996 assertUIntArg ('iif_id');
3d9ac3d4
DO
1997 global $ifcompatpack;
1998 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
1999 return buildRedirectURL (__FUNCTION__, 'ERR');
2000 $ngood = $nbad = 0;
2001 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2002 if (commitSupplementPIC ($_REQUEST['iif_id'], $oif_id))
2003 $ngood++;
2004 else
2005 $nbad++;
2006 return buildRedirectURL (__FUNCTION__, 'OK', array ($nbad, $ngood));
2400d7ec
DO
2007}
2008
3d9ac3d4
DO
2009$msgcode['delPortInterfaceCompatPack']['OK'] = 44;
2010$msgcode['delPortInterfaceCompatPack']['ERR'] = 123;
2400d7ec
DO
2011function delPortInterfaceCompatPack ()
2012{
0cc24e9a
DY
2013 assertStringArg ('standard');
2014 assertUIntArg ('iif_id');
3d9ac3d4
DO
2015 global $ifcompatpack;
2016 if (!array_key_exists ($_REQUEST['standard'], $ifcompatpack) or !array_key_exists ($_REQUEST['iif_id'], getPortIIFOptions()))
2017 return buildRedirectURL (__FUNCTION__, 'ERR');
2018 $ngood = $nbad = 0;
2019 foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id)
2020 if (commitReducePIC ($_REQUEST['iif_id'], $oif_id))
2021 $ngood++;
2022 else
2023 $nbad++;
2024 return buildRedirectURL (__FUNCTION__, 'OK', array ($nbad, $ngood));
2400d7ec
DO
2025}
2026
a310dd80
DO
2027$msgcode['addPortOIFCompat']['OK'] = 48;
2028$msgcode['addPortOIFCompat']['ERR'] = 110;
2029function addPortOIFCompat()
2030{
80ec1f4f
DO
2031 assertUIntArg('type1');
2032 assertUIntArg('type2');
a310dd80
DO
2033 if (commitSupplementPOIFC($_REQUEST['type1'], $_REQUEST['type2']))
2034 return buildRedirectURL(__FUNCTION__, 'OK');
2035 return buildRedirectURL(__FUNCTION__, 'ERR');
2036}
2037
2038$msgcode['delPortOIFCompat']['OK'] = 49;
2039$msgcode['delPortOIFCompat']['ERR'] = 111;
2040function delPortOIFCompat ()
2041{
80ec1f4f
DO
2042 assertUIntArg('type1');
2043 assertUIntArg('type2');
a310dd80
DO
2044 if (commitReducePOIFC ($_REQUEST['type1'], $_REQUEST['type2']))
2045 return buildRedirectURL (__FUNCTION__, 'OK');
2046 return buildRedirectURL (__FUNCTION__, 'ERR');
2047
2048}
2049
8198f2c6
DO
2050$msgcode['addVLANSwitchBinding']['OK'] = 48;
2051$msgcode['addVLANSwitchBinding']['ERR'] = 118;
2052function addVLANSwitchBinding ()
2053{
80ec1f4f
DO
2054 assertUIntArg ('vdom_id');
2055 assertUIntArg ('object_id');
8198f2c6
DO
2056 global $sic;
2057 $result = usePreparedInsertBlade
2058 (
2059 'VLANSwitch',
2060 array
2061 (
2062 'domain_id' => $sic['vdom_id'],
2063 'object_id' => $sic['object_id'],
2064 )
2065 );
2066 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2067}
2068
2069$msgcode['delVLANSwitchBinding']['OK'] = 49;
2070$msgcode['delVLANSwitchBinding']['ERR'] = 119;
2071function delVLANSwitchBinding ()
2072{
80ec1f4f
DO
2073 assertUIntArg ('vdom_id');
2074 assertUIntArg ('object_id');
8198f2c6
DO
2075 global $sic;
2076 $result = commitReduceVLANSwitch ($sic['vdom_id'], $sic['object_id']);
2077 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2078}
2079
2080$msgcode['addVLANDescription']['OK'] = 48;
2081$msgcode['addVLANDescription']['ERR1'] = 190;
2082$msgcode['addVLANDescription']['ERR2'] = 110;
2083function addVLANDescription ()
2084{
80ec1f4f
DO
2085 assertUIntArg ('vlan_id');
2086 assertStringArg ('vlan_descr', TRUE);
8198f2c6
DO
2087 global $sic;
2088 if (!($sic['vlan_id'] >= VLAN_MIN_ID and $sic['vlan_id'] <= VLAN_MAX_ID))
2089 return buildRedirectURL (__FUNCTION__, 'ERR1', array ($sic['vlan_id']));
2090 $result = usePreparedInsertBlade
2091 (
2092 'VLANDescription',
2093 array
2094 (
2095 'domain_id' => $sic['vdom_id'],
2096 'vlan_id' => $sic['vlan_id'],
2097 'vlan_descr' => strlen ($sic['vlan_descr']) ? $sic['vlan_descr'] : sprintf ('VLAN%04u', $sic['vlan_id'])
2098 )
2099 );
2100 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR2');
2101}
2102
2103$msgcode['delVLANDescription']['OK'] = 49;
2104$msgcode['delVLANDescription']['ERR'] = 111;
2105function delVLANDescription ()
2106{
80ec1f4f 2107 assertUIntArg ('vlan_id');
8198f2c6
DO
2108 global $sic;
2109 $result = commitReduceVLANDescription ($sic['vdom_id'], $sic['vlan_id']);
2110 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2111}
2112
2113$msgcode['updVLANDescription']['OK'] = 51;
2114$msgcode['updVLANDescription']['ERR'] = 109;
2115function updVLANDescription ()
2116{
80ec1f4f
DO
2117 assertUIntArg ('vlan_id');
2118 assertStringArg ('vlan_type');
2119 assertStringArg ('vlan_descr', TRUE);
8198f2c6
DO
2120 global $sic;
2121 $result = commitUpdateVLANDescription
2122 (
2123 $sic['vdom_id'],
2124 $sic['vlan_id'],
0dabdc53 2125 $sic['vlan_type'],
8198f2c6
DO
2126 $sic['vlan_descr']
2127 );
2128 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2129}
2130
2131$msgcode['createVLANDomain']['OK'] = 48;
2132$msgcode['createVLANDomain']['ERR'] = 110;
2133function createVLANDomain ()
2134{
80ec1f4f 2135 assertStringArg ('vdom_descr');
8198f2c6
DO
2136 global $sic;
2137 $result = usePreparedInsertBlade
2138 (
2139 'VLANDomain',
2140 array
2141 (
2142 'description' => $sic['vdom_descr'],
2143 )
2144 );
2145 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2146}
2147
2148$msgcode['destroyVLANDomain']['OK'] = 49;
2149$msgcode['destroyVLANDomain']['ERR'] = 111;
2150function destroyVLANDomain ()
2151{
80ec1f4f 2152 assertUIntArg ('vdom_id');
8198f2c6 2153 global $sic;
05d3c190 2154 $result = FALSE !== usePreparedDeleteBlade ('VLANDomain', 'id', $sic['vdom_id']);
8198f2c6
DO
2155 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2156}
2157
2158$msgcode['updateVLANDomain']['OK'] = 51;
2159$msgcode['updateVLANDomain']['ERR'] = 109;
2160function updateVLANDomain ()
2161{
80ec1f4f
DO
2162 assertUIntArg ('vdom_id');
2163 assertStringArg ('vdom_descr');
8198f2c6
DO
2164 global $sic;
2165 $result = commitUpdateVLANDomain ($sic['vdom_id'], $sic['vdom_descr']);
2166 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2167}
2168
861292ee
DO
2169$msgcode['savePortVLANConfig']['OK'] = 43;
2170$msgcode['savePortVLANConfig']['ERR1'] = 160;
2171$msgcode['savePortVLANConfig']['ERR2'] = 109;
2172function savePortVLANConfig ()
8198f2c6 2173{
80ec1f4f 2174 assertUIntArg ('port_id');
2996cbbb
DO
2175 assertUIntArg ('mutex_rev');
2176 global $sic;
05d3c190
DO
2177 $portinfo = getPortInfo ($sic['port_id']);
2178 if ($portinfo['object_id'] != $sic['object_id'])
861292ee
DO
2179 // should we throw instead?
2180 return buildRedirectURL (__FUNCTION__, 'ERR1', array(), NULL, NULL, array ('port_id' => $sic['port_id']));
2996cbbb
DO
2181 try
2182 {
2183 $allowed = isset ($sic['allowed_id']) ? $sic['allowed_id'] : array();
2184 $native = isset ($sic['native_id']) ? $sic['native_id'] : 0; // 0 means "reset"
2185 $work = array (array ('port_id' => $sic['port_id'], 'allowed' => $allowed, 'native' => $native));
2186 setSwitchVLANConfig ($sic['object_id'], $sic['mutex_rev'], $work);
2187 }
2188 catch (Exception $e)
861292ee 2189 {
2996cbbb 2190 return buildRedirectURL (__FUNCTION__, 'ERR2', array(), NULL, NULL, array ('port_id' => $sic['port_id']));
861292ee 2191 }
2996cbbb 2192 return buildRedirectURL (__FUNCTION__, 'OK', array(), NULL, NULL, array ('port_id' => $sic['port_id']));
8198f2c6
DO
2193}
2194
8846b060
DO
2195$msgcode['bindVLANtoIPv4']['OK'] = 48;
2196$msgcode['bindVLANtoIPv4']['ERR'] = 110;
2197function bindVLANtoIPv4 ()
2198{
2199 assertUIntArg ('id'); // network id
2200 global $sic;
2201 $result = commitSupplementVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2202 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2203}
2204
2205$msgcode['unbindVLANfromIPv4']['OK'] = 49;
2206$msgcode['unbindVLANfromIPv4']['ERR'] = 111;
2207function unbindVLANfromIPv4 ()
2208{
2209 assertUIntArg ('id'); // network id
2210 global $sic;
2211 $result = commitReduceVLANIPv4 ($sic['vlan_ck'], $sic['id']);
2212 return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR');
2213}
2214
e673ee24 2215?>