r2289 added HP and Juniper dictionary entries.
[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
17c32f4c
DO
8// This function assures that specified argument was passed
9// and is a number greater than zero.
2c6c7645 10function assertUIntArg ($argname, $caller = 'N/A', $allow_zero = FALSE)
17c32f4c
DO
11{
12 if (!isset ($_REQUEST[$argname]))
13 {
2c6c7645 14 showError ("Parameter '${argname}' is missing (calling function is [${caller}]).", __FUNCTION__);
17c32f4c
DO
15 die();
16 }
17 if (!is_numeric ($_REQUEST[$argname]))
18 {
2c6c7645 19 showError ("Parameter '${argname}' is not a number (calling function is [${caller}]).", __FUNCTION__);
17c32f4c
DO
20 die();
21 }
22 if ($_REQUEST[$argname] < 0)
23 {
2c6c7645 24 showError ("Parameter '${argname}' is less than zero (calling function is [${caller}]).", __FUNCTION__);
17c32f4c
DO
25 die();
26 }
27 if (!$allow_zero and $_REQUEST[$argname] == 0)
28 {
2c6c7645 29 showError ("Parameter '${argname}' is equal to zero (calling function is [${caller}]).", __FUNCTION__);
17c32f4c
DO
30 die();
31 }
32}
33
34// This function assures that specified argument was passed
35// and is a non-empty string.
2c6c7645 36function assertStringArg ($argname, $caller = 'N/A', $ok_if_empty = FALSE)
17c32f4c
DO
37{
38 if (!isset ($_REQUEST[$argname]))
39 {
2c6c7645 40 showError ("Parameter '${argname}' is missing (calling function is [${caller}]).", __FUNCTION__);
17c32f4c
DO
41 die();
42 }
43 if (!is_string ($_REQUEST[$argname]))
44 {
2c6c7645 45 showError ("Parameter '${argname}' is not a string (calling function is [${caller}]).", __FUNCTION__);
17c32f4c
DO
46 die();
47 }
48 if (!$ok_if_empty and empty ($_REQUEST[$argname]))
49 {
2c6c7645 50 showError ("Parameter '${argname}' is an empty string (calling function is [${caller}]).", __FUNCTION__);
17c32f4c
DO
51 die();
52 }
53}
54
2c6c7645 55function assertBoolArg ($argname, $caller = 'N/A', $ok_if_empty = FALSE)
17c32f4c
DO
56{
57 if (!isset ($_REQUEST[$argname]))
58 {
2c6c7645 59 showError ("Parameter '${argname}' is missing (calling function is [${caller}]).", __FUNCTION__);
17c32f4c
DO
60 die();
61 }
62 if (!is_string ($_REQUEST[$argname]) or $_REQUEST[$argname] != 'on')
63 {
2c6c7645 64 showError ("Parameter '${argname}' is not a string (calling function is [${caller}]).", __FUNCTION__);
17c32f4c
DO
65 die();
66 }
67 if (!$ok_if_empty and empty ($_REQUEST[$argname]))
68 {
2c6c7645 69 showError ("Parameter '${argname}' is an empty string (calling function is [${caller}]).", __FUNCTION__);
17c32f4c
DO
70 die();
71 }
72}
73
2c6c7645 74function assertIPv4Arg ($argname, $caller = 'N/A', $ok_if_empty = FALSE)
17c32f4c 75{
2c6c7645 76 assertStringArg ($argname, $caller, $ok_if_empty);
17c32f4c
DO
77 if (!empty ($_REQUEST[$argname]) and long2ip (ip2long ($_REQUEST[$argname])) !== $_REQUEST[$argname])
78 {
2c6c7645 79 showError ("IPv4 address validation failed for value '" . $_REQUEST[$argname] . "' (calling function is [${caller}]).", __FUNCTION__);
17c32f4c
DO
80 die();
81 }
82}
83
e673ee24
DO
84function addPortForwarding ()
85{
2c6c7645
DO
86 assertUIntArg ('object_id', __FUNCTION__);
87 assertIPv4Arg ('localip', __FUNCTION__);
88 assertIPv4Arg ('remoteip', __FUNCTION__);
89 assertUIntArg ('localport', __FUNCTION__);
9bea3a8b 90 assertStringArg ('proto', __FUNCTION__);
2c6c7645 91 assertStringArg ('description', __FUNCTION__, TRUE);
103b1e1e 92 $remoteport = isset ($_REQUEST['remoteport']) ? $_REQUEST['remoteport'] : '';
31fc4157 93 if (empty ($remoteport))
f75eb878 94 $remoteport = $_REQUEST['localport'];
e673ee24 95
9bea3a8b
DO
96 $error = newPortForwarding
97 (
103b1e1e 98 $_REQUEST['object_id'],
9bea3a8b
DO
99 $_REQUEST['localip'],
100 $_REQUEST['localport'],
101 $_REQUEST['remoteip'],
102 $remoteport,
103 $_REQUEST['proto'],
104 $_REQUEST['description']
105 );
e673ee24
DO
106
107 if ($error == '')
ebb5441d 108 return buildRedirectURL ('OK');
e673ee24 109 else
ebb5441d 110 return buildRedirectURL ('ERR', array ($error));
e673ee24
DO
111}
112
113function delPortForwarding ()
114{
103b1e1e
DO
115 assertUIntArg ('object_id', __FUNCTION__);
116 assertIPv4Arg ('localip', __FUNCTION__);
117 assertIPv4Arg ('remoteip', __FUNCTION__);
118 assertUIntArg ('localport', __FUNCTION__);
119 assertUIntArg ('remoteport', __FUNCTION__);
120 assertStringArg ('proto', __FUNCTION__);
e673ee24 121
103b1e1e
DO
122 $error = deletePortForwarding
123 (
124 $_REQUEST['object_id'],
125 $_REQUEST['localip'],
126 $_REQUEST['localport'],
127 $_REQUEST['remoteip'],
128 $_REQUEST['remoteport'],
129 $_REQUEST['proto']
130 );
e673ee24 131 if ($error == '')
ebb5441d 132 return buildRedirectURL ('OK');
e673ee24 133 else
ebb5441d 134 return buildRedirectURL ('ERR', array ($error));
e673ee24
DO
135}
136
137function updPortForwarding ()
138{
103b1e1e
DO
139 assertUIntArg ('object_id', __FUNCTION__);
140 assertIPv4Arg ('localip', __FUNCTION__);
141 assertIPv4Arg ('remoteip', __FUNCTION__);
142 assertUIntArg ('localport', __FUNCTION__);
143 assertUIntArg ('remoteport', __FUNCTION__);
144 assertStringArg ('proto', __FUNCTION__);
145 assertStringArg ('description', __FUNCTION__);
e673ee24 146
103b1e1e
DO
147 $error = updatePortForwarding
148 (
149 $_REQUEST['object_id'],
150 $_REQUEST['localip'],
151 $_REQUEST['localport'],
152 $_REQUEST['remoteip'],
153 $_REQUEST['remoteport'],
154 $_REQUEST['proto'],
155 $_REQUEST['description']
156 );
e673ee24 157 if ($error == '')
ebb5441d 158 return buildRedirectURL ('OK');
e673ee24 159 else
ebb5441d 160 return buildRedirectURL ('ERR', array ($error));
e673ee24
DO
161}
162
e673ee24
DO
163function addPortForObject ()
164{
103b1e1e
DO
165 assertUIntArg ('object_id', __FUNCTION__);
166 assertStringArg ('port_name', __FUNCTION__, TRUE);
167 if (empty ($_REQUEST['port_name']))
ebb5441d 168 return buildRedirectURL ('ERR1');
103b1e1e
DO
169 $error = commitAddPort ($_REQUEST['object_id'], $_REQUEST['port_name'], $_REQUEST['port_type_id'], $_REQUEST['port_label'], $_REQUEST['port_l2address']);
170 if ($error != '')
ebb5441d 171 return buildRedirectURL ('ERR2', array ($error));
e673ee24 172 else
ebb5441d 173 return buildRedirectURL ('OK', array ($_REQUEST['port_name']));
e673ee24
DO
174}
175
176function editPortForObject ()
177{
2c6c7645 178 assertUIntArg ('port_id', __FUNCTION__);
611170af 179 assertUIntArg ('port_type_id', __FUNCTION__);
d0a69ce8 180 // tolerate empty value now to produce custom informative message later
103b1e1e
DO
181 assertStringArg ('name', __FUNCTION__, TRUE);
182 if (empty ($_REQUEST['name']))
ebb5441d 183 return buildRedirectURL ('ERR1');
103b1e1e 184
e673ee24
DO
185 if (isset ($_REQUEST['reservation_comment']) and !empty ($_REQUEST['reservation_comment']))
186 $port_rc = '"' . $_REQUEST['reservation_comment'] . '"';
187 else
188 $port_rc = 'NULL';
611170af 189 $error = commitUpdatePort ($_REQUEST['port_id'], $_REQUEST['name'], $_REQUEST['port_type_id'], $_REQUEST['label'], $_REQUEST['l2address'], $port_rc);
103b1e1e 190 if ($error != '')
ebb5441d 191 return buildRedirectURL ('ERR2', array ($error));
e673ee24 192 else
ebb5441d 193 return buildRedirectURL ('OK', array ($_REQUEST['name']));
e673ee24
DO
194}
195
196function delPortFromObject ()
197{
103b1e1e 198 assertUIntArg ('port_id', __FUNCTION__);
103b1e1e 199 $error = delObjectPort ($_REQUEST['port_id']);
e673ee24
DO
200
201 if ($error != '')
ebb5441d 202 return buildRedirectURL ('ERR', array ($error));
e673ee24 203 else
ebb5441d 204 return buildRedirectURL ('OK', array ($_REQUEST['port_name']));
e673ee24
DO
205}
206
207function linkPortForObject ()
208{
103b1e1e
DO
209 assertUIntArg ('port_id', __FUNCTION__);
210 assertUIntArg ('remote_port_id', __FUNCTION__);
baf37d01
DO
211 assertStringArg ('port_name', __FUNCTION__, TRUE);
212 assertStringArg ('remote_port_name', __FUNCTION__, TRUE);
213 assertStringArg ('remote_object_name', __FUNCTION__, TRUE);
e673ee24 214
103b1e1e 215 $error = linkPorts ($_REQUEST['port_id'], $_REQUEST['remote_port_id']);
e673ee24 216 if ($error != '')
ebb5441d 217 return buildRedirectURL ('ERR', array ($error));
e673ee24 218 else
ebb5441d 219 return buildRedirectURL ('OK', array ($_REQUEST['port_name'], $_REQUEST['remote_port_name'], $_REQUEST['remote_object_name']));
e673ee24
DO
220}
221
222function unlinkPortForObject ()
223{
103b1e1e 224 assertUIntArg ('port_id', __FUNCTION__);
baf37d01
DO
225 assertStringArg ('port_name', __FUNCTION__, TRUE);
226 assertStringArg ('remote_port_name', __FUNCTION__, TRUE);
227 assertStringArg ('remote_object_name', __FUNCTION__, TRUE);
e673ee24 228
103b1e1e 229 $error = unlinkPort ($_REQUEST['port_id']);
e673ee24 230 if ($error != '')
ebb5441d 231 return buildRedirectURL ('ERR', array ($error));
e673ee24 232 else
ebb5441d 233 return buildRedirectURL ('OK', array ($_REQUEST['port_name'], $_REQUEST['remote_port_name'], $_REQUEST['remote_object_name']));
e673ee24
DO
234}
235
236function addMultiPorts ()
237{
2c6c7645
DO
238 assertStringArg ('format', __FUNCTION__);
239 assertStringArg ('input', __FUNCTION__);
240 assertUIntArg ('port_type', __FUNCTION__);
241 assertUIntArg ('object_id', __FUNCTION__);
e673ee24
DO
242 $format = $_REQUEST['format'];
243 $port_type = $_REQUEST['port_type'];
244 $object_id = $_REQUEST['object_id'];
245 // Input lines are escaped, so we have to explode and to chop by 2-char
246 // \n and \r respectively.
247 $lines1 = explode ('\n', $_REQUEST['input']);
248 foreach ($lines1 as $line)
249 {
250 $parts = explode ('\r', $line);
251 reset ($parts);
252 if (empty ($parts[0]))
253 continue;
254 else
255 $lines2[] = rtrim ($parts[0]);
256 }
257 $ports = array();
258 foreach ($lines2 as $line)
259 {
260 switch ($format)
261 {
262 case 'fisxii':
263 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
264 list ($slot, $port) = explode ('/', $words[0]);
265 $ports[] = array
266 (
267 'name' => "e ${slot}/${port}",
268 'l2address' => $words[8],
269 'label' => "slot ${slot} port ${port}"
270 );
271 break;
272 case 'c3600asy':
273 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', trim (substr ($line, 3))));
274/*
275How Async Lines are Numbered in Cisco 3600 Series Routers
276http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00801ca70b.shtml
277
278Understanding 16- and 32-Port Async Network Modules
279http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00800a93f0.shtml
280*/
281 $async = $words[0];
282 $slot = floor (($async - 1) / 32);
283 $octalgroup = floor (($async - 1 - $slot * 32) / 8);
284 $cable = $async - $slot * 32 - $octalgroup * 8;
285 $og_label[0] = 'async 0-7';
286 $og_label[1] = 'async 8-15';
287 $og_label[2] = 'async 16-23';
288 $og_label[3] = 'async 24-31';
289 $ports[] = array
290 (
291 'name' => "async ${async}",
292 'l2address' => '',
293 'label' => "slot ${slot} " . $og_label[$octalgroup] . " cable ${cable}"
294 );
295 break;
296 case 'fiwg':
297 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
298 $ifnumber = $words[0] * 1;
299 $ports[] = array
300 (
301 'name' => "e ${ifnumber}",
302 'l2address' => "${words[8]}",
303 'label' => "${ifnumber}"
304 );
305 break;
351d4dbf 306 case 'ssv1':
5b585342 307 $words = explode (' ', $line);
351d4dbf
DO
308 if (empty ($words[0]) or empty ($words[1]))
309 continue;
310 $ports[] = array
311 (
312 'name' => $words[0],
313 'l2address' => $words[1],
314 'label' => ''
315 );
316 break;
e673ee24 317 default:
ebb5441d 318 return buildRedirectURL ('ERR');
e673ee24
DO
319 break;
320 }
321 }
322 // Create ports, if they don't exist.
323 $added_count = $updated_count = $error_count = 0;
324 foreach ($ports as $port)
325 {
326 $port_id = getPortID ($object_id, $port['name']);
327 if ($port_id === NULL)
328 {
329 $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
330 if ($result == '')
331 $added_count++;
332 else
333 $error_count++;
334 }
335 else
336 {
611170af 337 $result = commitUpdatePort ($port_id, $port['name'], $port_type, $port['label'], $port['l2address']);
e673ee24
DO
338 if ($result == '')
339 $updated_count++;
340 else
341 $error_count++;
342 }
343 }
ebb5441d 344 return buildRedirectURL ('OK', array ($added_count, $updated_count, $error_count));
e673ee24
DO
345}
346
b4c1ef87 347function updIPv4Allocation ()
e673ee24 348{
b4c1ef87
DO
349 assertIPv4Arg ('ip', __FUNCTION__);
350 assertUIntArg ('object_id', __FUNCTION__);
351 assertStringArg ('bond_name', __FUNCTION__, TRUE);
352 assertStringArg ('bond_type', __FUNCTION__);
e673ee24 353
b4c1ef87 354 $error = updateBond ($_REQUEST['ip'], $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
e673ee24 355 if ($error != '')
ebb5441d 356 return buildRedirectURL ('ERR', array ($error));
e673ee24 357 else
ebb5441d 358 return buildRedirectURL ('OK');
e673ee24
DO
359}
360
b4c1ef87 361function delIPv4Allocation ()
e673ee24 362{
b4c1ef87
DO
363 assertIPv4Arg ('ip', __FUNCTION__);
364 assertUIntArg ('object_id', __FUNCTION__);
e673ee24 365
b4c1ef87 366 $error = unbindIpFromObject ($_REQUEST['ip'], $_REQUEST['object_id']);
e673ee24 367 if ($error != '')
ebb5441d 368 return buildRedirectURL ('ERR', array ($error));
e673ee24 369 else
ebb5441d 370 return buildRedirectURL ('OK');
e673ee24
DO
371}
372
b4c1ef87 373function addIPv4Allocation ()
e673ee24 374{
b4c1ef87
DO
375 assertIPv4Arg ('ip', __FUNCTION__);
376 assertUIntArg ('object_id', __FUNCTION__);
377 assertStringArg ('bond_name', __FUNCTION__, TRUE);
378 assertStringArg ('bond_type', __FUNCTION__);
da958e52 379
b4c1ef87
DO
380 // Strip masklen.
381 $ip = ereg_replace ('/[[:digit:]]+$', '', $_REQUEST['ip']);
2be3fd23 382 if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv4AddressNetworkId ($ip))
5222f192
DO
383 return buildRedirectURL ('ERR1', array ($ip));
384
b4c1ef87 385 $error = bindIpToObject ($ip, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']);
5222f192
DO
386 if ($error != '')
387 return buildRedirectURL ('ERR2', array ($error));
53ef3908
DO
388 $address = getIPv4Address ($ip);
389 if ($address['reserved'] == 'yes' or !empty ($address['name']))
b4c1ef87
DO
390 {
391 $release = getConfigVar ('IPV4_AUTO_RELEASE');
392 if ($release >= 1)
393 $address['reserved'] = 'no';
394 if ($release >= 2)
395 $address['name'] = '';
396 updateAddress ($ip, $address['name'], $address['reserved']);
397 }
5222f192 398 return buildRedirectURL ('OK');
e673ee24
DO
399}
400
42023f03 401function addIPv4Prefix ()
e673ee24 402{
2c6c7645 403 assertStringArg ('range', __FUNCTION__);
e4b9a099 404 assertStringArg ('name', __FUNCTION__, TRUE);
e673ee24 405
fa05e3de
DO
406 $is_bcast = isset ($_REQUEST['is_bcast']) ? $_REQUEST['is_bcast'] : 'off';
407 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
42023f03 408 $error = createIPv4Prefix ($_REQUEST['range'], $_REQUEST['name'], $is_bcast == 'on', $taglist);
e673ee24 409 if ($error != '')
33bcd1ce 410 return buildRedirectURL ('ERR', array ($error));
e673ee24 411 else
ebb5441d 412 return buildRedirectURL ('OK');
e673ee24
DO
413}
414
42023f03 415function delIPv4Prefix ()
e673ee24 416{
da958e52 417 assertUIntArg ('id', __FUNCTION__);
42023f03 418 $error = destroyIPv4Prefix ($_REQUEST['id']);
e673ee24 419 if ($error != '')
33bcd1ce 420 return buildRedirectURL ('ERR', array ($error));
e673ee24 421 else
ebb5441d 422 return buildRedirectURL ('OK');
e673ee24
DO
423}
424
04d619d0 425function updIPv4Prefix ()
e673ee24 426{
da958e52 427 assertUIntArg ('id', __FUNCTION__);
e4b9a099 428 assertStringArg ('name', __FUNCTION__, TRUE);
e673ee24 429
da958e52 430 $error = updateRange ($_REQUEST['id'], $_REQUEST['name']);
e673ee24 431 if ($error != '')
ebb5441d 432 return buildRedirectURL ('ERR', array ($error));
e673ee24 433 else
ebb5441d 434 return buildRedirectURL ('OK');
e673ee24
DO
435}
436
437function editAddress ()
438{
da958e52
DO
439 assertIPv4Arg ('ip', __FUNCTION__);
440 assertStringArg ('name', __FUNCTION__, TRUE);
e673ee24 441
e673ee24
DO
442 if (isset ($_REQUEST['reserved']))
443 $reserved = $_REQUEST['reserved'];
444 else
445 $reserved = 'off';
da958e52 446 $error = updateAddress ($_REQUEST['ip'], $_REQUEST['name'], $reserved == 'on' ? 'yes' : 'no');
e673ee24 447 if ($error != '')
ebb5441d 448 return buildRedirectURL ('ERR', array ($error));
e673ee24 449 else
ebb5441d 450 return buildRedirectURL ('OK');
e673ee24
DO
451}
452
cced6b7d 453function createUser ()
e673ee24 454{
2c6c7645
DO
455 assertStringArg ('username', __FUNCTION__);
456 assertStringArg ('realname', __FUNCTION__, TRUE);
457 assertStringArg ('password', __FUNCTION__);
e673ee24
DO
458 $username = $_REQUEST['username'];
459 $password = hash (PASSWORD_HASH, $_REQUEST['password']);
460 $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password);
461 if ($result == TRUE)
ebb5441d 462 return buildRedirectURL ('OK', array ($username));
e673ee24 463 else
ebb5441d 464 return buildRedirectURL ('ERR', array ($username));
e673ee24
DO
465}
466
cced6b7d 467function updateUser ()
e673ee24 468{
cced6b7d 469 assertUIntArg ('user_id', __FUNCTION__);
2c6c7645
DO
470 assertStringArg ('username', __FUNCTION__);
471 assertStringArg ('realname', __FUNCTION__, TRUE);
472 assertStringArg ('password', __FUNCTION__);
e673ee24
DO
473 $username = $_REQUEST['username'];
474 $new_password = $_REQUEST['password'];
103b1e1e 475 $old_hash = getHashByID ($_REQUEST['user_id']);
e673ee24 476 if ($old_hash == NULL)
ebb5441d 477 return buildRedirectURL ('ERR1');
e673ee24
DO
478 // Update user password only if provided password is not the same as current password hash.
479 if ($new_password != $old_hash)
480 $new_password = hash (PASSWORD_HASH, $new_password);
103b1e1e 481 $result = commitUpdateUserAccount ($_REQUEST['user_id'], $username, $_REQUEST['realname'], $new_password);
e673ee24 482 if ($result == TRUE)
ebb5441d 483 return buildRedirectURL ('OK', array ($username));
e673ee24 484 else
ebb5441d 485 return buildRedirectURL ('ERR2', array ($username));
e673ee24
DO
486}
487
cced6b7d 488function enableUser ()
e673ee24 489{
cced6b7d
DO
490 assertUIntArg ('user_id', __FUNCTION__);
491 if (commitEnableUserAccount ($_REQUEST['user_id'], 'yes') == TRUE)
ebb5441d 492 return buildRedirectURL ('OK');
e673ee24 493 else
ebb5441d 494 return buildRedirectURL ('ERR');
e673ee24
DO
495}
496
cced6b7d 497function disableUser ()
e673ee24 498{
cced6b7d 499 assertUIntArg ('user_id', __FUNCTION__);
103b1e1e 500 if ($_REQUEST['user_id'] == 1)
ebb5441d
DO
501 return buildRedirectURL ('ERR1');
502 if (commitEnableUserAccount ($_REQUEST['user_id'], 'no'))
503 return buildRedirectURL ('OK');
e673ee24 504 else
ebb5441d 505 return buildRedirectURL ('ERR2');
e673ee24
DO
506}
507
e673ee24
DO
508// This function find differences in users's submit and PortCompat table
509// and modifies database accordingly.
510function savePortMap ()
511{
e673ee24
DO
512 $ptlist = getPortTypes();
513 $oldCompat = getPortCompat();
514 $newCompat = array();
515 foreach (array_keys ($ptlist) as $leftKey)
516 foreach (array_keys ($ptlist) as $rightKey)
517 if (isset ($_REQUEST["atom_${leftKey}_${rightKey}"]))
518 $newCompat[] = array ('type1' => $leftKey, 'type2' => $rightKey);
519 // Build the new matrix from user's submit and compare it to
520 // the old matrix. Those pairs which appear on
521 // new matrix only, have to be stored in PortCompat table. Those who appear
522 // on the old matrix only, should be removed from PortCompat table.
523 // Those present in both matrices should be skipped.
524 $oldCompatTable = buildPortCompatMatrixFromList ($ptlist, $oldCompat);
525 $newCompatTable = buildPortCompatMatrixFromList ($ptlist, $newCompat);
526 $error_count = $success_count = 0;
527 foreach (array_keys ($ptlist) as $type1)
528 foreach (array_keys ($ptlist) as $type2)
529 if ($oldCompatTable[$type1][$type2] != $newCompatTable[$type1][$type2])
530 switch ($oldCompatTable[$type1][$type2])
531 {
532 case TRUE: // new value is FALSE
533 if (removePortCompat ($type1, $type2) === TRUE)
534 $success_count++;
535 else
536 $error_count++;
537 break;
538 case FALSE: // new value is TRUE
539 if (addPortCompat ($type1, $type2) === TRUE)
540 $success_count++;
541 else
542 $error_count++;
543 break;
544 default:
ebb5441d 545 showError ('Internal error: oldCompatTable is invalid', __FUNCTION__);
e673ee24
DO
546 break;
547 }
103b1e1e 548 if ($error_count == 0)
ebb5441d 549 return buildRedirectURL ('OK', array ($error_count, $success_count));
103b1e1e 550 else
ebb5441d 551 return buildRedirectURL ('ERR', array ($error_count, $success_count));
e673ee24
DO
552}
553
554function updateDictionary ()
555{
2c6c7645
DO
556 assertUIntArg ('chapter_no', __FUNCTION__);
557 assertUIntArg ('dict_key', __FUNCTION__);
558 assertStringArg ('dict_value', __FUNCTION__);
e673ee24 559 if (commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value']) === TRUE)
ebb5441d 560 return buildRedirectURL ('OK');
e673ee24 561 else
ebb5441d 562 return buildRedirectURL ('ERR');
e673ee24
DO
563}
564
565function supplementDictionary ()
566{
2c6c7645
DO
567 assertUIntArg ('chapter_no', __FUNCTION__);
568 assertStringArg ('dict_value', __FUNCTION__);
e673ee24 569 if (commitSupplementDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_value']) === TRUE)
ebb5441d 570 return buildRedirectURL ('OK');
e673ee24 571 else
ebb5441d 572 return buildRedirectURL ('ERR');
e673ee24
DO
573}
574
575function reduceDictionary ()
576{
2c6c7645
DO
577 assertUIntArg ('chapter_no', __FUNCTION__);
578 assertUIntArg ('dict_key', __FUNCTION__);
e673ee24 579 if (commitReduceDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key']) === TRUE)
ebb5441d 580 return buildRedirectURL ('OK');
e673ee24 581 else
ebb5441d 582 return buildRedirectURL ('ERR');
e673ee24
DO
583}
584
585function addChapter ()
586{
2c6c7645 587 assertStringArg ('chapter_name', __FUNCTION__);
e673ee24 588 if (commitAddChapter ($_REQUEST['chapter_name']) === TRUE)
ebb5441d 589 return buildRedirectURL ('OK');
e673ee24 590 else
ebb5441d 591 return buildRedirectURL ('ERR');
e673ee24
DO
592}
593
594function updateChapter ()
595{
2c6c7645
DO
596 assertUIntArg ('chapter_no', __FUNCTION__);
597 assertStringArg ('chapter_name', __FUNCTION__);
e673ee24 598 if (commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name']) === TRUE)
ebb5441d 599 return buildRedirectURL ('OK');
e673ee24 600 else
ebb5441d 601 return buildRedirectURL ('ERR');
e673ee24
DO
602}
603
604function delChapter ()
605{
2c6c7645 606 assertUIntArg ('chapter_no', __FUNCTION__);
e673ee24 607 if (commitDeleteChapter ($_REQUEST['chapter_no']))
ebb5441d 608 return buildRedirectURL ('OK');
e673ee24 609 else
ebb5441d 610 return buildRedirectURL ('ERR');
e673ee24
DO
611}
612
613function changeAttribute ()
614{
2c6c7645
DO
615 assertUIntArg ('attr_id', __FUNCTION__);
616 assertStringArg ('attr_name', __FUNCTION__);
e673ee24 617 if (commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name']))
ebb5441d 618 return buildRedirectURL ('OK');
e673ee24 619 else
ebb5441d 620 return buildRedirectURL ('ERR');
e673ee24
DO
621}
622
623function createAttribute ()
624{
2c6c7645
DO
625 assertStringArg ('attr_name', __FUNCTION__);
626 assertStringArg ('attr_type', __FUNCTION__);
e673ee24 627 if (commitAddAttribute ($_REQUEST['attr_name'], $_REQUEST['attr_type']))
ebb5441d 628 return buildRedirectURL ('OK', array ($_REQUEST['attr_name']));
e673ee24 629 else
ebb5441d 630 return buildRedirectURL ('ERR');
e673ee24
DO
631}
632
633function deleteAttribute ()
634{
2c6c7645 635 assertUIntArg ('attr_id', __FUNCTION__);
e673ee24 636 if (commitDeleteAttribute ($_REQUEST['attr_id']))
ebb5441d 637 return buildRedirectURL ('OK');
e673ee24 638 else
ebb5441d 639 return buildRedirectURL ('ERR');
e673ee24
DO
640}
641
642function supplementAttrMap ()
643{
2c6c7645
DO
644 assertUIntArg ('attr_id', __FUNCTION__);
645 assertUIntArg ('objtype_id', __FUNCTION__);
646 assertUIntArg ('chapter_no', __FUNCTION__);
e673ee24 647 if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $_REQUEST['chapter_no']) === TRUE)
ebb5441d 648 return buildRedirectURL ('OK');
e673ee24 649 else
ebb5441d 650 return buildRedirectURL ('ERR');
e673ee24
DO
651}
652
653function reduceAttrMap ()
654{
2c6c7645
DO
655 assertUIntArg ('attr_id', __FUNCTION__);
656 assertUIntArg ('objtype_id', __FUNCTION__);
e673ee24 657 if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) === TRUE)
ebb5441d 658 return buildRedirectURL ('OK');
e673ee24 659 else
ebb5441d 660 return buildRedirectURL ('ERR');
e673ee24
DO
661}
662
22bb04da 663function clearSticker ()
e673ee24 664{
2c6c7645
DO
665 assertUIntArg ('attr_id', __FUNCTION__);
666 assertUIntArg ('object_id', __FUNCTION__);
22bb04da 667 if (commitResetAttrValue ($_REQUEST['object_id'], $_REQUEST['attr_id']) === TRUE)
ebb5441d 668 return buildRedirectURL ('OK');
e673ee24 669 else
ebb5441d 670 return buildRedirectURL ('ERR');
e673ee24
DO
671}
672
22bb04da
DO
673function updateObject ()
674{
675 assertUIntArg ('object_id', __FUNCTION__);
676 assertUIntArg ('object_type_id', __FUNCTION__);
677 assertStringArg ('object_name', __FUNCTION__, TRUE);
678 assertStringArg ('object_label', __FUNCTION__, TRUE);
679 assertStringArg ('object_barcode', __FUNCTION__, TRUE);
680 assertStringArg ('object_asset_no', __FUNCTION__, TRUE);
681 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
682 $has_problems = 'yes';
683 else
684 $has_problems = 'no';
685
686 if (commitUpdateObject (
687 $_REQUEST['object_id'],
688 $_REQUEST['object_name'],
689 $_REQUEST['object_label'],
690 $_REQUEST['object_barcode'],
691 $_REQUEST['object_type_id'],
692 $has_problems,
693 $_REQUEST['object_asset_no'],
694 $_REQUEST['object_comment']
695 ) !== TRUE)
ebb5441d 696 return buildRedirectURL ('ERR');
22bb04da
DO
697 // Invalidate thumb cache of all racks objects could occupy.
698 foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id)
699 resetThumbCache ($rack_id);
ebb5441d 700 return buildRedirectURL ('OK');
22bb04da
DO
701}
702
703function updateStickers ()
e673ee24 704{
2c6c7645 705 assertUIntArg ('object_id', __FUNCTION__);
f59e8cf5
DO
706 assertUIntArg ('num_attrs', __FUNCTION__);
707 $oldvalues = getAttrValues ($_REQUEST['object_id']);
0dfb8a2a
DO
708 $result = array();
709
103b1e1e 710 for ($i = 0; $i < $_REQUEST['num_attrs']; $i++)
0dfb8a2a 711 {
2c6c7645 712 assertUIntArg ("${i}_attr_id", __FUNCTION__);
0dfb8a2a
DO
713 $attr_id = $_REQUEST["${i}_attr_id"];
714
715 // Field is empty, delete attribute and move on.
716 if (empty($_REQUEST["${i}_value"]))
717 {
103b1e1e 718 commitResetAttrValue ($_REQUEST['object_id'], $attr_id);
0dfb8a2a
DO
719 continue;
720 }
721
722 // The value could be uint/float, but we don't know ATM. Let SQL
723 // server check this and complain.
2c6c7645 724 assertStringArg ("${i}_value", __FUNCTION__);
0dfb8a2a
DO
725 $value = $_REQUEST["${i}_value"];
726 switch ($oldvalues[$attr_id]['type'])
727 {
728 case 'uint':
729 case 'float':
730 case 'string':
731 $oldvalue = $oldvalues[$attr_id]['value'];
732 break;
733 case 'dict':
734 $oldvalue = $oldvalues[$attr_id]['key'];
735 break;
736 default:
61e269b5 737 showError ('Internal structure error', __FUNCTION__);
0dfb8a2a
DO
738 die;
739 }
740 if ($value == $oldvalue)
741 continue;
742
743 // Note if the queries succeed or not, it determines which page they see.
103b1e1e 744 $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value);
0dfb8a2a
DO
745 }
746
103b1e1e 747 if (in_array (FALSE, $result))
ebb5441d 748 return buildRedirectURL ('ERR');
0dfb8a2a 749
ebb5441d 750 return buildRedirectURL ('OK');
e673ee24
DO
751}
752
753function useupPort ()
754{
2c6c7645 755 assertUIntArg ('port_id', __FUNCTION__);
e673ee24 756 if (commitUseupPort ($_REQUEST['port_id']) === TRUE)
ebb5441d 757 return buildRedirectURL ('OK');
e673ee24 758 else
ebb5441d 759 return buildRedirectURL ('ERR');
e673ee24
DO
760}
761
4fe32e78
DY
762function updateUI ()
763{
2c6c7645 764 assertUIntArg ('num_vars', __FUNCTION__);
c461c579 765 $error = '';
4fe32e78 766
103b1e1e 767 for ($i = 0; $i < $_REQUEST['num_vars']; $i++)
4fe32e78 768 {
2c6c7645
DO
769 assertStringArg ("${i}_varname", __FUNCTION__);
770 assertStringArg ("${i}_varvalue", __FUNCTION__, TRUE);
4fe32e78 771 $varname = $_REQUEST["${i}_varname"];
4fe32e78 772 $varvalue = $_REQUEST["${i}_varvalue"];
4fe32e78 773
c461c579
DO
774 // If form value = value in DB, don't bother updating DB
775 if ($varvalue == getConfigVar ($varname))
4fe32e78
DY
776 continue;
777
778 // Note if the queries succeed or not, it determines which page they see.
c461c579
DO
779 $error = setConfigVar ($varname, $varvalue, TRUE);
780 if (!empty ($error))
781 break;
4fe32e78
DY
782 }
783
c461c579 784 if ($error != '')
ebb5441d 785 return buildRedirectURL ('ERR', array ($error));
4fe32e78 786
ebb5441d 787 return buildRedirectURL ('OK');
4fe32e78
DY
788}
789
b07f617c
DO
790function resetUIConfig()
791{
1f86e996 792 setConfigVar ('default_port_type','24');
b07f617c
DO
793 setConfigVar ('MASSCOUNT','15');
794 setConfigVar ('MAXSELSIZE','30');
795 setConfigVar ('NAMEFUL_OBJTYPES','4,7,8');
796 setConfigVar ('ROW_SCALE','2');
797 setConfigVar ('PORTS_PER_ROW','12');
798 setConfigVar ('IPV4_ADDRS_PER_PAGE','256');
799 setConfigVar ('DEFAULT_RACK_HEIGHT','42');
a6305acc 800 setConfigVar ('REQUIRE_ASSET_TAG_FOR','4,7,8');
b5ce46aa
DO
801 setConfigVar ('USER_AUTH_SRC','database');
802 setConfigVar ('DEFAULT_SLB_VS_PORT','');
803 setConfigVar ('DEFAULT_SLB_RS_PORT','');
d48e0a20 804 setConfigVar ('IPV4_PERFORMERS','1,4,7,8,12,14,445,447');
b5ce46aa 805 setConfigVar ('NATV4_PERFORMERS','4,7,8');
72281138 806 setConfigVar ('DETECT_URLS','no');
4b8d413e 807 setConfigVar ('RACK_PRESELECT_THRESHOLD','1');
b108de49 808 setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no');
8dfb997c 809 setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm');
194e3748
DO
810 setConfigVar ('SHOW_EXPLICIT_TAGS','yes');
811 setConfigVar ('SHOW_IMPLICIT_TAGS','yes');
812 setConfigVar ('SHOW_AUTOMATIC_TAGS','no');
a477e405 813 setConfigVar ('DEFAULT_OBJECT_TYPE','4');
2754cefc 814 setConfigVar ('IPV4_AUTO_RELEASE','1');
a53dc9df
DO
815 setConfigVar ('SHOW_LAST_TAB', 'no');
816 setConfigVar ('COOKIE_TTL', '1209600');
f0ed1181 817 setConfigVar ('EXT_IPV4_VIEW', 'yes');
efee2692 818 setConfigVar ('TREE_THRESHOLD', '25');
2be3fd23 819 setConfigVar ('IPV4_JAYWALK', 'no');
9318d2ef 820 setConfigVar ('ADDNEW_AT_TOP', 'yes');
ebb5441d 821 return buildRedirectURL ('OK');
b07f617c
DO
822}
823
732e4578 824// Add single record.
ca461127
DO
825function addRealServer ()
826{
2c6c7645
DO
827 assertUIntArg ('pool_id', __FUNCTION__);
828 assertIPv4Arg ('remoteip', __FUNCTION__);
79a9edb4 829 assertStringArg ('rsport', __FUNCTION__, TRUE);
2c6c7645 830 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
103b1e1e
DO
831 if (!addRStoRSPool (
832 $_REQUEST['pool_id'],
833 $_REQUEST['remoteip'],
834 $_REQUEST['rsport'],
835 getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'),
836 $_REQUEST['rsconfig']
837 ))
ebb5441d 838 return buildRedirectURL ('ERR');
d6517a21 839 else
ebb5441d 840 return buildRedirectURL ('OK');
d6517a21
DO
841}
842
732e4578
DO
843// Parse textarea submitted and try adding a real server for each line.
844function addRealServers ()
845{
cbadbb38 846 assertUIntArg ('pool_id', __FUNCTION__);
2c6c7645
DO
847 assertStringArg ('format', __FUNCTION__);
848 assertStringArg ('rawtext', __FUNCTION__);
732e4578
DO
849 $rawtext = str_replace ('\r', '', $_REQUEST['rawtext']);
850 $ngood = $nbad = 0;
851 $rsconfig = '';
852 // Keep in mind, that the text will have HTML entities (namely '>') escaped.
853 foreach (explode ('\n', $rawtext) as $line)
854 {
855 if (empty ($line))
856 continue;
857 $match = array ();
858 switch ($_REQUEST['format'])
859 {
860 case 'ipvs_2': // address and port only
861 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) /', $line, $match))
862 continue;
103b1e1e 863 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
732e4578
DO
864 $ngood++;
865 else
866 $nbad++;
867 break;
868 case 'ipvs_3': // address, port and weight
869 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match))
870 continue;
103b1e1e 871 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3]))
732e4578
DO
872 $ngood++;
873 else
874 $nbad++;
875 break;
e69c2aa3
DO
876 case 'ssv_2': // IP address and port
877 if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match))
878 continue;
103b1e1e 879 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
e69c2aa3
DO
880 $ngood++;
881 else
882 $nbad++;
883 break;
948c37e3
DO
884 case 'ssv_1': // IP address
885 if (!preg_match ('/^([0-9\.]+)$/', $line, $match))
886 continue;
887 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
888 $ngood++;
889 else
890 $nbad++;
891 break;
732e4578 892 default:
ebb5441d 893 return buildRedirectURL ('ERR1');
732e4578
DO
894 break;
895 }
896 }
897 if ($nbad == 0 and $ngood > 0)
ebb5441d 898 return buildRedirectURL ('OK', array ($ngood));
732e4578 899 else
ebb5441d 900 return buildRedirectURL ('ERR2', array ($ngood, $nbad));
732e4578
DO
901}
902
d6517a21
DO
903function addVService ()
904{
2c6c7645
DO
905 assertIPv4Arg ('vip', __FUNCTION__);
906 assertUIntArg ('vport', __FUNCTION__);
907 assertStringArg ('proto', __FUNCTION__);
103b1e1e 908 if ($_REQUEST['proto'] != 'TCP' and $_REQUEST['proto'] != 'UDP')
ebb5441d 909 return buildRedirectURL ('ERR1');
2c6c7645
DO
910 assertStringArg ('name', __FUNCTION__, TRUE);
911 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
912 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
c63a8d6e
DO
913 $error = commitCreateVS
914 (
103b1e1e
DO
915 $_REQUEST['vip'],
916 $_REQUEST['vport'],
7320b661 917 $_REQUEST['proto'],
103b1e1e
DO
918 $_REQUEST['name'],
919 $_REQUEST['vsconfig'],
c63a8d6e
DO
920 $_REQUEST['rsconfig'],
921 isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array()
922 );
923 if ($error != '')
ebb5441d 924 return buildRedirectURL ('ERR2', array ($error));
ca461127 925 else
ebb5441d 926 return buildRedirectURL ('OK');
fb1c4a54
DO
927}
928
929function deleteRealServer ()
930{
2c6c7645 931 assertUIntArg ('id', __FUNCTION__);
d6517a21 932 if (!commitDeleteRS ($_REQUEST['id']))
ebb5441d 933 return buildRedirectURL ('ERR');
fb1c4a54 934 else
ebb5441d 935 return buildRedirectURL ('OK');
fb1c4a54
DO
936}
937
3241551e
DO
938function deleteLoadBalancer ()
939{
2c6c7645
DO
940 assertUIntArg ('object_id', __FUNCTION__);
941 assertUIntArg ('pool_id', __FUNCTION__);
942 assertUIntArg ('vs_id', __FUNCTION__);
103b1e1e
DO
943 if (!commitDeleteLB (
944 $_REQUEST['object_id'],
945 $_REQUEST['pool_id'],
946 $_REQUEST['vs_id']
947 ))
ebb5441d 948 return buildRedirectURL ('ERR');
d6517a21 949 else
ebb5441d 950 return buildRedirectURL ('OK');
d6517a21
DO
951}
952
953function deleteVService ()
954{
e02e1941
DO
955 assertUIntArg ('vs_id', __FUNCTION__);
956 if (!commitDeleteVS ($_REQUEST['vs_id']))
ebb5441d 957 return buildRedirectURL ('ERR');
3241551e 958 else
ebb5441d 959 return buildRedirectURL ('OK');
3241551e
DO
960}
961
fb1c4a54
DO
962function updateRealServer ()
963{
2c6c7645
DO
964 assertUIntArg ('rs_id', __FUNCTION__);
965 assertIPv4Arg ('rsip', __FUNCTION__);
79a9edb4 966 assertStringArg ('rsport', __FUNCTION__, TRUE);
2c6c7645 967 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
103b1e1e
DO
968 if (!commitUpdateRS (
969 $_REQUEST['rs_id'],
970 $_REQUEST['rsip'],
971 $_REQUEST['rsport'],
972 $_REQUEST['rsconfig']
973 ))
ebb5441d 974 return buildRedirectURL ('ERR');
fb1c4a54 975 else
ebb5441d 976 return buildRedirectURL ('OK');
ca461127
DO
977}
978
c1ca768c 979function updateLoadBalancer ()
3241551e 980{
2c6c7645
DO
981 assertUIntArg ('object_id', __FUNCTION__);
982 assertUIntArg ('pool_id', __FUNCTION__);
983 assertUIntArg ('vs_id', __FUNCTION__);
984 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
985 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
103b1e1e
DO
986 if (!commitUpdateLB (
987 $_REQUEST['object_id'],
988 $_REQUEST['pool_id'],
989 $_REQUEST['vs_id'],
990 $_REQUEST['vsconfig'],
991 $_REQUEST['rsconfig']
992 ))
ebb5441d 993 return buildRedirectURL ('ERR');
d6517a21 994 else
ebb5441d 995 return buildRedirectURL ('OK');
d6517a21
DO
996}
997
998function updateVService ()
999{
e02e1941 1000 assertUIntArg ('vs_id', __FUNCTION__);
2c6c7645
DO
1001 assertIPv4Arg ('vip', __FUNCTION__);
1002 assertUIntArg ('vport', __FUNCTION__);
1003 assertStringArg ('proto', __FUNCTION__);
1004 assertStringArg ('name', __FUNCTION__, TRUE);
1005 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1006 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
103b1e1e
DO
1007 if (!commitUpdateVS (
1008 $_REQUEST['vs_id'],
1009 $_REQUEST['vip'],
1010 $_REQUEST['vport'],
1011 $_REQUEST['proto'],
1012 $_REQUEST['name'],
1013 $_REQUEST['vsconfig'],
1014 $_REQUEST['rsconfig']
1015 ))
ebb5441d 1016 return buildRedirectURL ('ERR');
3241551e 1017 else
ebb5441d 1018 return buildRedirectURL ('OK');
3241551e
DO
1019}
1020
1021function addLoadBalancer ()
1022{
2c6c7645
DO
1023 assertUIntArg ('pool_id', __FUNCTION__);
1024 assertUIntArg ('object_id', __FUNCTION__);
1025 assertUIntArg ('vs_id', __FUNCTION__);
1026 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1027 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
103b1e1e
DO
1028 if (!addLBtoRSPool (
1029 $_REQUEST['pool_id'],
1030 $_REQUEST['object_id'],
1031 $_REQUEST['vs_id'],
1032 $_REQUEST['vsconfig'],
1033 $_REQUEST['rsconfig']
1034 ))
ebb5441d 1035 return buildRedirectURL ('ERR');
3241551e 1036 else
ebb5441d 1037 return buildRedirectURL ('OK');
3241551e
DO
1038}
1039
5ad76f01
DO
1040function addRSPool ()
1041{
2c6c7645
DO
1042 assertStringArg ('name', __FUNCTION__, TRUE);
1043 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1044 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
c63a8d6e
DO
1045 $error = commitCreateRSPool
1046 (
103b1e1e
DO
1047 $_REQUEST['name'],
1048 $_REQUEST['vsconfig'],
c63a8d6e
DO
1049 $_REQUEST['rsconfig'],
1050 isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array()
1051 );
1052 if ($error != '')
ebb5441d 1053 return buildRedirectURL ('ERR', array ($error));
5ad76f01 1054 else
ebb5441d 1055 return buildRedirectURL ('OK');
5ad76f01
DO
1056}
1057
1058function deleteRSPool ()
1059{
2c6c7645 1060 assertUIntArg ('pool_id', __FUNCTION__);
841a7a7a 1061 if (!commitDeleteRSPool ($_REQUEST['pool_id']))
ebb5441d 1062 return buildRedirectURL ('ERR');
5ad76f01 1063 else
ebb5441d 1064 return buildRedirectURL ('OK');
5ad76f01
DO
1065}
1066
1067function updateRSPool ()
1068{
2c6c7645
DO
1069 assertUIntArg ('pool_id', __FUNCTION__);
1070 assertStringArg ('name', __FUNCTION__, TRUE);
1071 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1072 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
841a7a7a 1073 if (!commitUpdateRSPool ($_REQUEST['pool_id'], $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
ebb5441d 1074 return buildRedirectURL ('ERR');
5ad76f01 1075 else
ebb5441d 1076 return buildRedirectURL ('OK');
5ad76f01
DO
1077}
1078
1f7d18fa
DO
1079function updateRSInService ()
1080{
2c6c7645 1081 assertUIntArg ('rscount', __FUNCTION__);
841a7a7a 1082 $pool_id = $_REQUEST['pool_id'];
1f7d18fa
DO
1083 $orig = getRSPoolInfo ($pool_id);
1084 $nbad = $ngood = 0;
1085 for ($i = 1; $i <= $_REQUEST['rscount']; $i++)
1086 {
1087 $rs_id = $_REQUEST["rsid_${i}"];
1088 if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on')
1089 $newval = 'yes';
1090 else
1091 $newval = 'no';
1092 if ($newval != $orig['rslist'][$rs_id]['inservice'])
1093 {
1094 if (commitSetInService ($rs_id, $newval))
1095 $ngood++;
1096 else
1097 $nbad++;
1098 }
1099 }
1100 if (!$nbad)
ebb5441d 1101 return buildRedirectURL ('OK', array ($ngood));
1f7d18fa 1102 else
ebb5441d 1103 return buildRedirectURL ('ERR', array ($nbad, $ngood));
1f7d18fa
DO
1104}
1105
8d9c16e7
DO
1106// FIXME: check, that each submitted address belongs to the prefix we
1107// are operating on.
03eb5209
DO
1108function importPTRData ()
1109{
2c6c7645 1110 assertUIntArg ('addrcount', __FUNCTION__);
03eb5209 1111 $nbad = $ngood = 0;
03eb5209
DO
1112 for ($i = 0; $i < $_REQUEST['addrcount']; $i++)
1113 {
3f3bd41e 1114 $inputname = "import_${i}";
03eb5209
DO
1115 if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on')
1116 continue;
2c6c7645
DO
1117 assertIPv4Arg ("addr_${i}", __FUNCTION__);
1118 assertStringArg ("descr_${i}", __FUNCTION__, TRUE);
1119 assertStringArg ("rsvd_${i}", __FUNCTION__);
3f3bd41e
DO
1120 // Non-existent addresses will not have this argument set in request.
1121 $rsvd = 'no';
03eb5209
DO
1122 if ($_REQUEST["rsvd_${i}"] == 'yes')
1123 $rsvd = 'yes';
3f3bd41e 1124 if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '')
03eb5209
DO
1125 $ngood++;
1126 else
1127 $nbad++;
1128 }
1129 if (!$nbad)
ebb5441d 1130 return buildRedirectURL ('OK', array ($ngood));
03eb5209 1131 else
ebb5441d 1132 return buildRedirectURL ('ERR', array ($nbad, $ngood));
03eb5209
DO
1133}
1134
f3f0161f
DO
1135function generateAutoPorts ()
1136{
103b1e1e 1137 global $pageno;
2c6c7645 1138 assertUIntArg ('object_id', __FUNCTION__);
103b1e1e 1139 $info = getObjectInfo ($_REQUEST['object_id']);
f3f0161f 1140 // Navigate away in case of success, stay at the place otherwise.
103b1e1e 1141 if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id']))
ebb5441d 1142 return buildRedirectURL ('OK', array(), $pageno, 'ports');
f3f0161f 1143 else
ebb5441d 1144 return buildRedirectURL ('ERR');
f3f0161f
DO
1145}
1146
24cbe8af 1147// Filter out implicit tags before storing the new tag set.
3355ca56 1148function saveEntityTags ()
24cbe8af 1149{
3355ca56
DO
1150 $page2realm = array
1151 (
e1ae3fb4
AD
1152 'file' => 'file',
1153 'ipv4net' => 'ipv4net',
3854af78 1154 'ipv4rspool' => 'ipv4rspool',
e1ae3fb4 1155 'ipv4vs' => 'ipv4vs',
3355ca56 1156 'object' => 'object',
3355ca56 1157 'rack' => 'rack',
3355ca56
DO
1158 'user' => 'user'
1159 );
1160 global $explicit_tags, $implicit_tags, $page, $pageno;
1161 if (!isset ($page2realm[$pageno]) or !isset ($page[$pageno]['bypass']))
1162 {
1163 showError ('Internal error', __FUNCTION__);
1164 die;
1165 }
1166 $realm = $page2realm[$pageno];
1167 $bypass = $page[$pageno]['bypass'];
2c6c7645 1168 assertUIntArg ($bypass, __FUNCTION__);
2034d968 1169 $entity_id = $_REQUEST[$bypass];
e04931c8 1170 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
6e49bd1f 1171 // Build a chain from the submitted data, minimize it,
ab379543 1172 // then wipe existing records and store the new set instead.
01b6b4d6 1173 destroyTagsForEntity ($realm, $entity_id);
6e49bd1f 1174 $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist));
ab379543 1175 $n_succeeds = $n_errors = 0;
6e49bd1f 1176 foreach ($newchain as $taginfo)
eb6ea26f 1177 if (addTagForEntity ($realm, $entity_id, $taginfo['id']))
ab379543
DO
1178 $n_succeeds++;
1179 else
1180 $n_errors++;
ab379543 1181 if ($n_errors)
ebb5441d 1182 return buildRedirectURL ('ERR', array ($n_succeeds, $n_errors));
ab379543 1183 else
ebb5441d 1184 return buildRedirectURL ('OK', array ($n_succeeds));
2034d968
DO
1185}
1186
fe7044ad
DO
1187function destroyTag ()
1188{
49fb1027
DO
1189 assertUIntArg ('tag_id', __FUNCTION__);
1190 if (($ret = commitDestroyTag ($_REQUEST['tag_id'])) == '')
ebb5441d 1191 return buildRedirectURL ('OK');
fe7044ad 1192 else
ebb5441d 1193 return buildRedirectURL ('ERR');
fe7044ad
DO
1194}
1195
1196function createTag ()
1197{
49fb1027 1198 assertStringArg ('tag_name', __FUNCTION__);
2c6c7645 1199 assertUIntArg ('parent_id', __FUNCTION__, TRUE);
49fb1027 1200 $tagname = trim ($_REQUEST['tag_name']);
2eeeca80 1201 if (!validTagName ($tagname))
ebb5441d 1202 return buildRedirectURL ('ERR1', array ($tagname));
0f3c6639 1203 if (tagExistsInDatabase ($tagname))
ebb5441d 1204 return buildRedirectURL ('ERR2', array ($tagname));
fe7044ad
DO
1205 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1206 $parent_id = 'NULL';
1207 if (($ret = commitCreateTag ($tagname, $parent_id)) == '')
ebb5441d 1208 return buildRedirectURL ('OK', array ($tagname));
fe7044ad 1209 else
33b76fd5 1210 return buildRedirectURL ('ERR3', array ($tagname, $ret));
fe7044ad
DO
1211}
1212
49fb1027
DO
1213function updateTag ()
1214{
49fb1027
DO
1215 assertUIntArg ('tag_id', __FUNCTION__);
1216 assertUIntArg ('parent_id', __FUNCTION__, TRUE);
1217 assertStringArg ('tag_name', __FUNCTION__);
1218 $tagname = trim ($_REQUEST['tag_name']);
2eeeca80 1219 if (!validTagName ($tagname))
33b76fd5 1220 return buildRedirectURL ('ERR1', array ($tagname));
49fb1027
DO
1221 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1222 $parent_id = 'NULL';
1223 if (($ret = commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id)) == '')
ebb5441d 1224 return buildRedirectURL ('OK', array ($tagname));
49fb1027 1225 else
33b76fd5 1226 return buildRedirectURL ('ERR2', array ($tagname, $ret));
49fb1027
DO
1227}
1228
eb6ea26f
DO
1229function rollTags ()
1230{
eb6ea26f
DO
1231 assertUIntArg ('row_id', __FUNCTION__);
1232 assertStringArg ('sum', __FUNCTION__, TRUE);
1233 assertUIntArg ('realsum', __FUNCTION__);
eb6ea26f 1234 if ($_REQUEST['sum'] != $_REQUEST['realsum'])
ebb5441d 1235 return buildRedirectURL ('ERR');
abef7149
DO
1236 // Even if the user requested an empty tag list, don't bail out, but process existing
1237 // tag chains with "zero" extra. This will make sure, that the stuff processed will
1238 // have its chains refined to "normal" form.
1239 $extratags = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1240 $n_ok = 0;
1241 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
1242 // filter out the same tag again and again. It will have own noise to cancel.
1243 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
1244 foreach (getRacksForRow ($_REQUEST['row_id']) as $rackInfo)
1245 {
1246 if (rebuildTagChainForEntity ('rack', $rackInfo['id'], $extrachain))
1247 $n_ok++;
1248 foreach (stuffInRackspace (getRackData ($rackInfo['id'])) as $object_id)
1249 if (rebuildTagChainForEntity ('object', $object_id, $extrachain))
1250 $n_ok++;
1251 }
1252 return buildRedirectURL ('OK', array ($n_ok));
eb6ea26f
DO
1253}
1254
9457ca59 1255function changeMyPassword ()
cced6b7d 1256{
103b1e1e 1257 global $accounts, $remote_username;
9457ca59 1258 if (getConfigVar ('USER_AUTH_SRC') != 'database')
ebb5441d 1259 return buildRedirectURL ('ERR1');
0ac7e4b3
DO
1260 assertStringArg ('oldpassword', __FUNCTION__);
1261 assertStringArg ('newpassword1', __FUNCTION__);
1262 assertStringArg ('newpassword2', __FUNCTION__);
1263 if ($accounts[$remote_username]['user_password_hash'] != hash (PASSWORD_HASH, $_REQUEST['oldpassword']))
ebb5441d 1264 return buildRedirectURL ('ERR2');
cced6b7d 1265 if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2'])
ebb5441d 1266 return buildRedirectURL ('ERR3');
0ac7e4b3 1267 if (commitUpdateUserAccount ($accounts[$remote_username]['user_id'], $accounts[$remote_username]['user_name'], $accounts[$remote_username]['user_realname'], hash (PASSWORD_HASH, $_REQUEST['newpassword1'])))
ebb5441d 1268 return buildRedirectURL ('OK');
cced6b7d 1269 else
ebb5441d 1270 return buildRedirectURL ('ERR4');
cced6b7d
DO
1271}
1272
1273function saveRackCode ()
1274{
cced6b7d 1275 assertStringArg ('rackcode');
e6a4adb9
DO
1276 // For the test to succeed, unescape LFs, strip CRs.
1277 $newcode = str_replace ('\r', '', str_replace ('\n', "\n", $_REQUEST['rackcode']));
cf25e649
DO
1278 $parseTree = getRackCode ($newcode);
1279 if ($parseTree['result'] != 'ACK')
ebb5441d 1280 return buildRedirectURL ('ERR1', array ($parseTree['load']));
4a6a28f1 1281 saveScript ('RackCodeCache', '');
cf25e649 1282 if (saveScript ('RackCode', $newcode))
ebb5441d 1283 return buildRedirectURL ('OK');
cced6b7d 1284 else
ebb5441d 1285 return buildRedirectURL ('ERR2');
cced6b7d
DO
1286}
1287
46f92ff7
DO
1288// This handler's context is pre-built, but not authorized. It is assumed, that the
1289// handler will take existing context and before each commit check authorization
1290// on the base chain plus necessary context added.
1291function setPortVLAN ()
1292{
1293 assertUIntArg ('portcount', __FUNCTION__);
1294 $data = getSwitchVLANs ($_REQUEST['object_id']);
1295 if ($data === NULL)
ebb5441d 1296 return buildRedirectURL ('ERR1');
46f92ff7
DO
1297 list ($vlanlist, $portlist) = $data;
1298 // Here we just build up 1 set command for the gateway with all of the ports
1299 // included. The gateway is expected to filter unnecessary changes silently
1300 // and to provide a list of responses with either error or success message
1301 // for each of the rest.
1302 $nports = $_REQUEST['portcount'];
1303 $prefix = 'set ';
73067b6a 1304 $log = array ('v' => 2, 'm' => array());
46f92ff7
DO
1305 $setcmd = '';
1306 for ($i = 0; $i < $nports; $i++)
1307 if
1308 (
1309 !isset ($_REQUEST['portname_' . $i]) ||
1310 !isset ($_REQUEST['vlanid_' . $i]) ||
1311 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
1312 )
24dcb9d8 1313 $log['m'][] = array ('c' => 158, 'a' => array ($i));
46f92ff7
DO
1314 elseif
1315 (
1316 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
1317 $portlist[$i]['vlaind'] == 'TRUNK'
1318 )
1319 continue;
1320 else
1321 {
1322 $portname = $_REQUEST['portname_' . $i];
1323 $oldvlanid = $portlist[$i]['vlanid'];
1324 $newvlanid = $_REQUEST['vlanid_' . $i];
1325 // Finish the security context and evaluate it.
1326 $annex = array();
1327 $annex[] = array ('tag' => '$fromvlan_' . $oldvlanid);
1328 $annex[] = array ('tag' => '$tovlan_' . $newvlanid);
1329 if (!permitted (NULL, NULL, NULL, $annex))
1330 {
24dcb9d8 1331 $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid));
46f92ff7
DO
1332 continue;
1333 }
1334 $setcmd .= $prefix . $portname . '=' . $newvlanid;
1335 $prefix = ';';
1336 }
1337 // Feed the gateway and interpret its (non)response.
1338 if ($setcmd != '')
f0ff4930 1339 $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd));
46f92ff7 1340 else
24dcb9d8 1341 $log['m'][] = array ('c' => 201);
46f92ff7
DO
1342 return buildWideRedirectURL ($log);
1343}
1344
2987fc1f
DO
1345function submitSLBConfig ()
1346{
1347 assertUIntArg ('object_id', __FUNCTION__);
1348 $newconfig = buildLVSConfig ($_REQUEST['object_id']);
3dd72e34 1349 $msglog = gwSendFile ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8'));
2987fc1f
DO
1350 return buildWideRedirectURL ($msglog);
1351}
1352
345fd640
AD
1353function addRow ()
1354{
1355 assertStringArg ('name', __FUNCTION__);
1356
1357 if (commitSupplementDictionary (3, $_REQUEST['name']) === TRUE)
1358 return buildRedirectURL ('OK', array ($_REQUEST['name']));
1359 else
1360 return buildRedirectURL ('ERR', array ($_REQUEST['name']));
1361}
1362
1363function updateRow ()
1364{
1365 assertUIntArg ('row_id', __FUNCTION__);
1366 assertStringArg ('name', __FUNCTION__);
1367
1368 if (TRUE === commitUpdateDictionary (3, $_REQUEST['row_id'], $_REQUEST['name']))
1369 return buildRedirectURL ('OK', array ($_REQUEST['name']));
1370 else
1371 return buildRedirectURL ('ERR', array ($_REQUEST['name']));
1372}
1373
f19c75d6
DO
1374function addRack ()
1375{
1376 assertUIntArg ('row_id', __FUNCTION__);
1377 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1378 if (isset ($_REQUEST['got_data']))
1379 {
1380 assertStringArg ('rack_name', __FUNCTION__);
1381 assertUIntArg ('rack_height1', __FUNCTION__);
1382 assertStringArg ('rack_comment', __FUNCTION__, TRUE);
1383
1384 if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
1385 return buildRedirectURL ('OK', array ($_REQUEST['rack_name']));
1386 else
1387 return buildRedirectURL ('ERR1', array ($_REQUEST['rack_name']));
1388 }
1389 elseif (isset ($_REQUEST['got_mdata']))
1390 {
1391 assertUIntArg ('rack_height2', __FUNCTION__);
1392 assertStringArg ('rack_names', __FUNCTION__, TRUE);
1393 $log = array ('v' => 2);
1394 // copy-and-paste from renderAddMultipleObjectsForm()
1395 $names1 = explode ('\n', $_REQUEST['rack_names']);
1396 $names2 = array();
1397 foreach ($names1 as $line)
1398 {
1399 $parts = explode ('\r', $line);
1400 reset ($parts);
1401 if (empty ($parts[0]))
1402 continue;
1403 else
1404 $names2[] = rtrim ($parts[0]);
1405 }
1406 foreach ($names2 as $cname)
1407 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE)
1408 $log['m'][] = array ('c' => getMessageCode ('OK'), 'a' => array ($cname));
1409 else
1410 $log['m'][] = array ('c' => getMessageCode ('ERR1'), 'a' => array ($cname));
1411 return buildWideRedirectURL ($log);
1412 }
1413 else
1414 return buildRedirectURL ('ERR2');
f19c75d6
DO
1415}
1416
7056988c
DO
1417function updateRack ()
1418{
7056988c
DO
1419 assertUIntArg ('rack_id', __FUNCTION__);
1420 assertUIntArg ('rack_row_id', __FUNCTION__);
1421 assertUIntArg ('rack_height', __FUNCTION__);
1422 assertStringArg ('rack_name', __FUNCTION__);
1423 assertStringArg ('rack_comment', __FUNCTION__, TRUE);
7056988c 1424
7056988c 1425 resetThumbCache ($_REQUEST['rack_id']);
0c2b7c4a
DO
1426 if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
1427 return buildRedirectURL ('OK', array ($_REQUEST['rack_name']));
1428 else
1429 return buildRedirectURL ('ERR');
7056988c
DO
1430}
1431
1432function querySNMPData ()
1433{
1434 assertUIntArg ('object_id', __FUNCTION__);
1435 assertStringArg ('community', __FUNCTION__);
83fdf85f 1436 return buildWideRedirectURL (doSNMPmining ($_REQUEST['object_id'], $_REQUEST['community']));
7056988c
DO
1437}
1438
e1ae3fb4
AD
1439// File-related functions
1440function addFileWithoutLink ()
1441{
1442 assertStringArg ('comment', __FUNCTION__, TRUE);
1443
1444 // Make sure the file can be uploaded
1445 if (get_cfg_var('file_uploads') != 1)
1446 return buildRedirectURL ('ERR', array ("file uploads not allowed, change 'file_uploads' parameter in php.ini"));
1447
1448 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1449 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $_REQUEST['comment']);
1450
1451 if ($error != '')
1452 return buildRedirectURL ('ERR', array ($error));
1453
1454 return buildRedirectURL ('OK', array ($_FILES['file']['name']));
1455}
1456
1457function addFileToEntity ()
1458{
1459 assertStringArg ('entity_type', __FUNCTION__);
1460 assertUIntArg ('entity_id', __FUNCTION__);
1461 assertStringArg ('comment', __FUNCTION__, TRUE);
1462 if (empty ($_REQUEST['entity_type']) || empty ($_REQUEST['entity_id']))
1463 return buildRedirectURL ('ERR');
1464
1465 // Make sure the file can be uploaded
1466 if (get_cfg_var('file_uploads') != 1)
1467 return buildRedirectURL ('ERR', array ("file uploads not allowed, change 'file_uploads' parameter in php.ini"));
1468
1469 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1470 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $_REQUEST['comment']);
1471 if ($error != '')
1472 return buildRedirectURL ('ERR', array ($error));
1473
1474 $file_id = lastInsertID();
1475 $error = commitLinkFile ($file_id, $_REQUEST['entity_type'], $_REQUEST['entity_id']);
1476 if ($error != '')
1477 return buildRedirectURL ('ERR', array ($error));
1478
1479 return buildRedirectURL ('OK', array ($_FILES['file']['name']));
1480}
1481
1482function linkFileToEntity ()
1483{
1484 assertUIntArg ('entity_id', __FUNCTION__);
1485 assertUIntArg ('file_id', __FUNCTION__);
1486 assertStringArg ('file_name', __FUNCTION__);
1487
1488 $error = commitLinkFile ($_REQUEST['file_id'], $_REQUEST['entity_type'], $_REQUEST['entity_id']);
1489 if ($error != '')
1490 return buildRedirectURL ('ERR', array ($error));
1491
1492 return buildRedirectURL ('OK', array ($_REQUEST['file_name']));
1493}
1494
1495function updateFile ()
1496{
1497 assertUIntArg ('file_id', __FUNCTION__);
1498 assertStringArg ('name', __FUNCTION__);
1499 assertStringArg ('comment', __FUNCTION__, TRUE);
1500 $error = commitUpdateFile ($_REQUEST['file_id'], $_REQUEST['comment']);
1501 if ($error != '')
1502 return buildRedirectURL ('ERR', array ($error));
1503
1504 return buildRedirectURL ('OK', array ($_REQUEST['name']));
1505}
1506
1507function unlinkFile ()
1508{
1509 assertUIntArg ('link_id', __FUNCTION__);
1510 $error = commitUnlinkFile ($_REQUEST['link_id']);
1511
1512 if ($error != '')
1513 return buildRedirectURL ('ERR', array ($error));
1514
1515 return buildRedirectURL ('OK', array ($_REQUEST['name']));
1516}
1517
1518function deleteFile ()
1519{
1520 assertUIntArg ('file_id', __FUNCTION__);
1521 $error = commitDeleteFile ($_REQUEST['file_id']);
1522
1523 if ($error != '')
1524 return buildRedirectURL ('ERR', array ($error));
1525
1526 return buildRedirectURL ('OK', array ($_REQUEST['name']));
1527}
1528
e673ee24 1529?>