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