r2312 - forward-porting to trunk
[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{
cdd3efe9 675 assertUIntArg ('num_attrs', __FUNCTION__);
22bb04da
DO
676 assertUIntArg ('object_id', __FUNCTION__);
677 assertUIntArg ('object_type_id', __FUNCTION__);
678 assertStringArg ('object_name', __FUNCTION__, TRUE);
679 assertStringArg ('object_label', __FUNCTION__, TRUE);
680 assertStringArg ('object_barcode', __FUNCTION__, TRUE);
681 assertStringArg ('object_asset_no', __FUNCTION__, TRUE);
682 if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on')
683 $has_problems = 'yes';
684 else
685 $has_problems = 'no';
686
687 if (commitUpdateObject (
688 $_REQUEST['object_id'],
689 $_REQUEST['object_name'],
690 $_REQUEST['object_label'],
691 $_REQUEST['object_barcode'],
692 $_REQUEST['object_type_id'],
693 $has_problems,
694 $_REQUEST['object_asset_no'],
695 $_REQUEST['object_comment']
696 ) !== TRUE)
ebb5441d 697 return buildRedirectURL ('ERR');
22bb04da 698
cdd3efe9 699 // Update optional attributes
f59e8cf5 700 $oldvalues = getAttrValues ($_REQUEST['object_id']);
0dfb8a2a 701 $result = array();
103b1e1e 702 for ($i = 0; $i < $_REQUEST['num_attrs']; $i++)
0dfb8a2a 703 {
2c6c7645 704 assertUIntArg ("${i}_attr_id", __FUNCTION__);
0dfb8a2a
DO
705 $attr_id = $_REQUEST["${i}_attr_id"];
706
707 // Field is empty, delete attribute and move on.
708 if (empty($_REQUEST["${i}_value"]))
709 {
103b1e1e 710 commitResetAttrValue ($_REQUEST['object_id'], $attr_id);
0dfb8a2a
DO
711 continue;
712 }
713
714 // The value could be uint/float, but we don't know ATM. Let SQL
715 // server check this and complain.
2c6c7645 716 assertStringArg ("${i}_value", __FUNCTION__);
0dfb8a2a
DO
717 $value = $_REQUEST["${i}_value"];
718 switch ($oldvalues[$attr_id]['type'])
719 {
720 case 'uint':
721 case 'float':
722 case 'string':
723 $oldvalue = $oldvalues[$attr_id]['value'];
724 break;
725 case 'dict':
726 $oldvalue = $oldvalues[$attr_id]['key'];
727 break;
728 default:
61e269b5 729 showError ('Internal structure error', __FUNCTION__);
0dfb8a2a
DO
730 die;
731 }
732 if ($value == $oldvalue)
733 continue;
734
735 // Note if the queries succeed or not, it determines which page they see.
103b1e1e 736 $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value);
0dfb8a2a 737 }
103b1e1e 738 if (in_array (FALSE, $result))
ebb5441d 739 return buildRedirectURL ('ERR');
0dfb8a2a 740
cdd3efe9
AD
741 // Invalidate thumb cache of all racks objects could occupy.
742 foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id)
743 resetThumbCache ($rack_id);
744
ebb5441d 745 return buildRedirectURL ('OK');
e673ee24
DO
746}
747
748function useupPort ()
749{
2c6c7645 750 assertUIntArg ('port_id', __FUNCTION__);
e673ee24 751 if (commitUseupPort ($_REQUEST['port_id']) === TRUE)
ebb5441d 752 return buildRedirectURL ('OK');
e673ee24 753 else
ebb5441d 754 return buildRedirectURL ('ERR');
e673ee24
DO
755}
756
4fe32e78
DY
757function updateUI ()
758{
2c6c7645 759 assertUIntArg ('num_vars', __FUNCTION__);
c461c579 760 $error = '';
4fe32e78 761
103b1e1e 762 for ($i = 0; $i < $_REQUEST['num_vars']; $i++)
4fe32e78 763 {
2c6c7645
DO
764 assertStringArg ("${i}_varname", __FUNCTION__);
765 assertStringArg ("${i}_varvalue", __FUNCTION__, TRUE);
4fe32e78 766 $varname = $_REQUEST["${i}_varname"];
4fe32e78 767 $varvalue = $_REQUEST["${i}_varvalue"];
4fe32e78 768
c461c579
DO
769 // If form value = value in DB, don't bother updating DB
770 if ($varvalue == getConfigVar ($varname))
4fe32e78
DY
771 continue;
772
773 // Note if the queries succeed or not, it determines which page they see.
c461c579
DO
774 $error = setConfigVar ($varname, $varvalue, TRUE);
775 if (!empty ($error))
776 break;
4fe32e78
DY
777 }
778
c461c579 779 if ($error != '')
ebb5441d 780 return buildRedirectURL ('ERR', array ($error));
4fe32e78 781
ebb5441d 782 return buildRedirectURL ('OK');
4fe32e78
DY
783}
784
b07f617c
DO
785function resetUIConfig()
786{
1f86e996 787 setConfigVar ('default_port_type','24');
b07f617c
DO
788 setConfigVar ('MASSCOUNT','15');
789 setConfigVar ('MAXSELSIZE','30');
790 setConfigVar ('NAMEFUL_OBJTYPES','4,7,8');
791 setConfigVar ('ROW_SCALE','2');
792 setConfigVar ('PORTS_PER_ROW','12');
793 setConfigVar ('IPV4_ADDRS_PER_PAGE','256');
794 setConfigVar ('DEFAULT_RACK_HEIGHT','42');
a6305acc 795 setConfigVar ('REQUIRE_ASSET_TAG_FOR','4,7,8');
b5ce46aa
DO
796 setConfigVar ('USER_AUTH_SRC','database');
797 setConfigVar ('DEFAULT_SLB_VS_PORT','');
798 setConfigVar ('DEFAULT_SLB_RS_PORT','');
d48e0a20 799 setConfigVar ('IPV4_PERFORMERS','1,4,7,8,12,14,445,447');
b5ce46aa 800 setConfigVar ('NATV4_PERFORMERS','4,7,8');
72281138 801 setConfigVar ('DETECT_URLS','no');
4b8d413e 802 setConfigVar ('RACK_PRESELECT_THRESHOLD','1');
b108de49 803 setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no');
8dfb997c 804 setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm');
194e3748
DO
805 setConfigVar ('SHOW_EXPLICIT_TAGS','yes');
806 setConfigVar ('SHOW_IMPLICIT_TAGS','yes');
807 setConfigVar ('SHOW_AUTOMATIC_TAGS','no');
a477e405 808 setConfigVar ('DEFAULT_OBJECT_TYPE','4');
2754cefc 809 setConfigVar ('IPV4_AUTO_RELEASE','1');
a53dc9df
DO
810 setConfigVar ('SHOW_LAST_TAB', 'no');
811 setConfigVar ('COOKIE_TTL', '1209600');
f0ed1181 812 setConfigVar ('EXT_IPV4_VIEW', 'yes');
efee2692 813 setConfigVar ('TREE_THRESHOLD', '25');
2be3fd23 814 setConfigVar ('IPV4_JAYWALK', 'no');
9318d2ef 815 setConfigVar ('ADDNEW_AT_TOP', 'yes');
ebb5441d 816 return buildRedirectURL ('OK');
b07f617c
DO
817}
818
732e4578 819// Add single record.
ca461127
DO
820function addRealServer ()
821{
2c6c7645
DO
822 assertUIntArg ('pool_id', __FUNCTION__);
823 assertIPv4Arg ('remoteip', __FUNCTION__);
79a9edb4 824 assertStringArg ('rsport', __FUNCTION__, TRUE);
2c6c7645 825 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
103b1e1e
DO
826 if (!addRStoRSPool (
827 $_REQUEST['pool_id'],
828 $_REQUEST['remoteip'],
829 $_REQUEST['rsport'],
830 getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'),
831 $_REQUEST['rsconfig']
832 ))
ebb5441d 833 return buildRedirectURL ('ERR');
d6517a21 834 else
ebb5441d 835 return buildRedirectURL ('OK');
d6517a21
DO
836}
837
732e4578
DO
838// Parse textarea submitted and try adding a real server for each line.
839function addRealServers ()
840{
cbadbb38 841 assertUIntArg ('pool_id', __FUNCTION__);
2c6c7645
DO
842 assertStringArg ('format', __FUNCTION__);
843 assertStringArg ('rawtext', __FUNCTION__);
732e4578
DO
844 $rawtext = str_replace ('\r', '', $_REQUEST['rawtext']);
845 $ngood = $nbad = 0;
846 $rsconfig = '';
847 // Keep in mind, that the text will have HTML entities (namely '>') escaped.
848 foreach (explode ('\n', $rawtext) as $line)
849 {
850 if (empty ($line))
851 continue;
852 $match = array ();
853 switch ($_REQUEST['format'])
854 {
855 case 'ipvs_2': // address and port only
856 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) /', $line, $match))
857 continue;
103b1e1e 858 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
732e4578
DO
859 $ngood++;
860 else
861 $nbad++;
862 break;
863 case 'ipvs_3': // address, port and weight
864 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match))
865 continue;
103b1e1e 866 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3]))
732e4578
DO
867 $ngood++;
868 else
869 $nbad++;
870 break;
e69c2aa3
DO
871 case 'ssv_2': // IP address and port
872 if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match))
873 continue;
103b1e1e 874 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
e69c2aa3
DO
875 $ngood++;
876 else
877 $nbad++;
878 break;
948c37e3
DO
879 case 'ssv_1': // IP address
880 if (!preg_match ('/^([0-9\.]+)$/', $line, $match))
881 continue;
882 if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
883 $ngood++;
884 else
885 $nbad++;
886 break;
732e4578 887 default:
ebb5441d 888 return buildRedirectURL ('ERR1');
732e4578
DO
889 break;
890 }
891 }
892 if ($nbad == 0 and $ngood > 0)
ebb5441d 893 return buildRedirectURL ('OK', array ($ngood));
732e4578 894 else
ebb5441d 895 return buildRedirectURL ('ERR2', array ($ngood, $nbad));
732e4578
DO
896}
897
d6517a21
DO
898function addVService ()
899{
2c6c7645
DO
900 assertIPv4Arg ('vip', __FUNCTION__);
901 assertUIntArg ('vport', __FUNCTION__);
902 assertStringArg ('proto', __FUNCTION__);
103b1e1e 903 if ($_REQUEST['proto'] != 'TCP' and $_REQUEST['proto'] != 'UDP')
ebb5441d 904 return buildRedirectURL ('ERR1');
2c6c7645
DO
905 assertStringArg ('name', __FUNCTION__, TRUE);
906 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
907 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
c63a8d6e
DO
908 $error = commitCreateVS
909 (
103b1e1e
DO
910 $_REQUEST['vip'],
911 $_REQUEST['vport'],
7320b661 912 $_REQUEST['proto'],
103b1e1e
DO
913 $_REQUEST['name'],
914 $_REQUEST['vsconfig'],
c63a8d6e
DO
915 $_REQUEST['rsconfig'],
916 isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array()
917 );
918 if ($error != '')
ebb5441d 919 return buildRedirectURL ('ERR2', array ($error));
ca461127 920 else
ebb5441d 921 return buildRedirectURL ('OK');
fb1c4a54
DO
922}
923
924function deleteRealServer ()
925{
2c6c7645 926 assertUIntArg ('id', __FUNCTION__);
d6517a21 927 if (!commitDeleteRS ($_REQUEST['id']))
ebb5441d 928 return buildRedirectURL ('ERR');
fb1c4a54 929 else
ebb5441d 930 return buildRedirectURL ('OK');
fb1c4a54
DO
931}
932
3241551e
DO
933function deleteLoadBalancer ()
934{
2c6c7645
DO
935 assertUIntArg ('object_id', __FUNCTION__);
936 assertUIntArg ('pool_id', __FUNCTION__);
937 assertUIntArg ('vs_id', __FUNCTION__);
103b1e1e
DO
938 if (!commitDeleteLB (
939 $_REQUEST['object_id'],
940 $_REQUEST['pool_id'],
941 $_REQUEST['vs_id']
942 ))
ebb5441d 943 return buildRedirectURL ('ERR');
d6517a21 944 else
ebb5441d 945 return buildRedirectURL ('OK');
d6517a21
DO
946}
947
948function deleteVService ()
949{
e02e1941
DO
950 assertUIntArg ('vs_id', __FUNCTION__);
951 if (!commitDeleteVS ($_REQUEST['vs_id']))
ebb5441d 952 return buildRedirectURL ('ERR');
3241551e 953 else
ebb5441d 954 return buildRedirectURL ('OK');
3241551e
DO
955}
956
fb1c4a54
DO
957function updateRealServer ()
958{
2c6c7645
DO
959 assertUIntArg ('rs_id', __FUNCTION__);
960 assertIPv4Arg ('rsip', __FUNCTION__);
79a9edb4 961 assertStringArg ('rsport', __FUNCTION__, TRUE);
2c6c7645 962 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
103b1e1e
DO
963 if (!commitUpdateRS (
964 $_REQUEST['rs_id'],
965 $_REQUEST['rsip'],
966 $_REQUEST['rsport'],
967 $_REQUEST['rsconfig']
968 ))
ebb5441d 969 return buildRedirectURL ('ERR');
fb1c4a54 970 else
ebb5441d 971 return buildRedirectURL ('OK');
ca461127
DO
972}
973
c1ca768c 974function updateLoadBalancer ()
3241551e 975{
2c6c7645
DO
976 assertUIntArg ('object_id', __FUNCTION__);
977 assertUIntArg ('pool_id', __FUNCTION__);
978 assertUIntArg ('vs_id', __FUNCTION__);
979 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
980 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
103b1e1e
DO
981 if (!commitUpdateLB (
982 $_REQUEST['object_id'],
983 $_REQUEST['pool_id'],
984 $_REQUEST['vs_id'],
985 $_REQUEST['vsconfig'],
986 $_REQUEST['rsconfig']
987 ))
ebb5441d 988 return buildRedirectURL ('ERR');
d6517a21 989 else
ebb5441d 990 return buildRedirectURL ('OK');
d6517a21
DO
991}
992
993function updateVService ()
994{
e02e1941 995 assertUIntArg ('vs_id', __FUNCTION__);
2c6c7645
DO
996 assertIPv4Arg ('vip', __FUNCTION__);
997 assertUIntArg ('vport', __FUNCTION__);
998 assertStringArg ('proto', __FUNCTION__);
999 assertStringArg ('name', __FUNCTION__, TRUE);
1000 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1001 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
103b1e1e
DO
1002 if (!commitUpdateVS (
1003 $_REQUEST['vs_id'],
1004 $_REQUEST['vip'],
1005 $_REQUEST['vport'],
1006 $_REQUEST['proto'],
1007 $_REQUEST['name'],
1008 $_REQUEST['vsconfig'],
1009 $_REQUEST['rsconfig']
1010 ))
ebb5441d 1011 return buildRedirectURL ('ERR');
3241551e 1012 else
ebb5441d 1013 return buildRedirectURL ('OK');
3241551e
DO
1014}
1015
1016function addLoadBalancer ()
1017{
2c6c7645
DO
1018 assertUIntArg ('pool_id', __FUNCTION__);
1019 assertUIntArg ('object_id', __FUNCTION__);
1020 assertUIntArg ('vs_id', __FUNCTION__);
1021 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1022 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
103b1e1e
DO
1023 if (!addLBtoRSPool (
1024 $_REQUEST['pool_id'],
1025 $_REQUEST['object_id'],
1026 $_REQUEST['vs_id'],
1027 $_REQUEST['vsconfig'],
1028 $_REQUEST['rsconfig']
1029 ))
ebb5441d 1030 return buildRedirectURL ('ERR');
3241551e 1031 else
ebb5441d 1032 return buildRedirectURL ('OK');
3241551e
DO
1033}
1034
5ad76f01
DO
1035function addRSPool ()
1036{
2c6c7645
DO
1037 assertStringArg ('name', __FUNCTION__, TRUE);
1038 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1039 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
c63a8d6e
DO
1040 $error = commitCreateRSPool
1041 (
103b1e1e
DO
1042 $_REQUEST['name'],
1043 $_REQUEST['vsconfig'],
c63a8d6e
DO
1044 $_REQUEST['rsconfig'],
1045 isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array()
1046 );
1047 if ($error != '')
ebb5441d 1048 return buildRedirectURL ('ERR', array ($error));
5ad76f01 1049 else
ebb5441d 1050 return buildRedirectURL ('OK');
5ad76f01
DO
1051}
1052
1053function deleteRSPool ()
1054{
2c6c7645 1055 assertUIntArg ('pool_id', __FUNCTION__);
841a7a7a 1056 if (!commitDeleteRSPool ($_REQUEST['pool_id']))
ebb5441d 1057 return buildRedirectURL ('ERR');
5ad76f01 1058 else
ebb5441d 1059 return buildRedirectURL ('OK');
5ad76f01
DO
1060}
1061
1062function updateRSPool ()
1063{
2c6c7645
DO
1064 assertUIntArg ('pool_id', __FUNCTION__);
1065 assertStringArg ('name', __FUNCTION__, TRUE);
1066 assertStringArg ('vsconfig', __FUNCTION__, TRUE);
1067 assertStringArg ('rsconfig', __FUNCTION__, TRUE);
841a7a7a 1068 if (!commitUpdateRSPool ($_REQUEST['pool_id'], $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
ebb5441d 1069 return buildRedirectURL ('ERR');
5ad76f01 1070 else
ebb5441d 1071 return buildRedirectURL ('OK');
5ad76f01
DO
1072}
1073
1f7d18fa
DO
1074function updateRSInService ()
1075{
2c6c7645 1076 assertUIntArg ('rscount', __FUNCTION__);
841a7a7a 1077 $pool_id = $_REQUEST['pool_id'];
1f7d18fa
DO
1078 $orig = getRSPoolInfo ($pool_id);
1079 $nbad = $ngood = 0;
1080 for ($i = 1; $i <= $_REQUEST['rscount']; $i++)
1081 {
1082 $rs_id = $_REQUEST["rsid_${i}"];
1083 if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on')
1084 $newval = 'yes';
1085 else
1086 $newval = 'no';
1087 if ($newval != $orig['rslist'][$rs_id]['inservice'])
1088 {
1089 if (commitSetInService ($rs_id, $newval))
1090 $ngood++;
1091 else
1092 $nbad++;
1093 }
1094 }
1095 if (!$nbad)
ebb5441d 1096 return buildRedirectURL ('OK', array ($ngood));
1f7d18fa 1097 else
ebb5441d 1098 return buildRedirectURL ('ERR', array ($nbad, $ngood));
1f7d18fa
DO
1099}
1100
8d9c16e7
DO
1101// FIXME: check, that each submitted address belongs to the prefix we
1102// are operating on.
03eb5209
DO
1103function importPTRData ()
1104{
2c6c7645 1105 assertUIntArg ('addrcount', __FUNCTION__);
03eb5209 1106 $nbad = $ngood = 0;
03eb5209
DO
1107 for ($i = 0; $i < $_REQUEST['addrcount']; $i++)
1108 {
3f3bd41e 1109 $inputname = "import_${i}";
03eb5209
DO
1110 if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on')
1111 continue;
2c6c7645
DO
1112 assertIPv4Arg ("addr_${i}", __FUNCTION__);
1113 assertStringArg ("descr_${i}", __FUNCTION__, TRUE);
1114 assertStringArg ("rsvd_${i}", __FUNCTION__);
3f3bd41e
DO
1115 // Non-existent addresses will not have this argument set in request.
1116 $rsvd = 'no';
03eb5209
DO
1117 if ($_REQUEST["rsvd_${i}"] == 'yes')
1118 $rsvd = 'yes';
3f3bd41e 1119 if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '')
03eb5209
DO
1120 $ngood++;
1121 else
1122 $nbad++;
1123 }
1124 if (!$nbad)
ebb5441d 1125 return buildRedirectURL ('OK', array ($ngood));
03eb5209 1126 else
ebb5441d 1127 return buildRedirectURL ('ERR', array ($nbad, $ngood));
03eb5209
DO
1128}
1129
f3f0161f
DO
1130function generateAutoPorts ()
1131{
103b1e1e 1132 global $pageno;
2c6c7645 1133 assertUIntArg ('object_id', __FUNCTION__);
103b1e1e 1134 $info = getObjectInfo ($_REQUEST['object_id']);
f3f0161f 1135 // Navigate away in case of success, stay at the place otherwise.
103b1e1e 1136 if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id']))
ebb5441d 1137 return buildRedirectURL ('OK', array(), $pageno, 'ports');
f3f0161f 1138 else
ebb5441d 1139 return buildRedirectURL ('ERR');
f3f0161f
DO
1140}
1141
24cbe8af 1142// Filter out implicit tags before storing the new tag set.
3355ca56 1143function saveEntityTags ()
24cbe8af 1144{
3355ca56
DO
1145 $page2realm = array
1146 (
e1ae3fb4
AD
1147 'file' => 'file',
1148 'ipv4net' => 'ipv4net',
3854af78 1149 'ipv4rspool' => 'ipv4rspool',
e1ae3fb4 1150 'ipv4vs' => 'ipv4vs',
3355ca56 1151 'object' => 'object',
3355ca56 1152 'rack' => 'rack',
3355ca56
DO
1153 'user' => 'user'
1154 );
1155 global $explicit_tags, $implicit_tags, $page, $pageno;
1156 if (!isset ($page2realm[$pageno]) or !isset ($page[$pageno]['bypass']))
1157 {
1158 showError ('Internal error', __FUNCTION__);
1159 die;
1160 }
1161 $realm = $page2realm[$pageno];
1162 $bypass = $page[$pageno]['bypass'];
2c6c7645 1163 assertUIntArg ($bypass, __FUNCTION__);
2034d968 1164 $entity_id = $_REQUEST[$bypass];
e04931c8 1165 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
6e49bd1f 1166 // Build a chain from the submitted data, minimize it,
ab379543 1167 // then wipe existing records and store the new set instead.
01b6b4d6 1168 destroyTagsForEntity ($realm, $entity_id);
6e49bd1f 1169 $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist));
ab379543 1170 $n_succeeds = $n_errors = 0;
6e49bd1f 1171 foreach ($newchain as $taginfo)
eb6ea26f 1172 if (addTagForEntity ($realm, $entity_id, $taginfo['id']))
ab379543
DO
1173 $n_succeeds++;
1174 else
1175 $n_errors++;
ab379543 1176 if ($n_errors)
ebb5441d 1177 return buildRedirectURL ('ERR', array ($n_succeeds, $n_errors));
ab379543 1178 else
ebb5441d 1179 return buildRedirectURL ('OK', array ($n_succeeds));
2034d968
DO
1180}
1181
fe7044ad
DO
1182function destroyTag ()
1183{
49fb1027
DO
1184 assertUIntArg ('tag_id', __FUNCTION__);
1185 if (($ret = commitDestroyTag ($_REQUEST['tag_id'])) == '')
ebb5441d 1186 return buildRedirectURL ('OK');
fe7044ad 1187 else
ebb5441d 1188 return buildRedirectURL ('ERR');
fe7044ad
DO
1189}
1190
1191function createTag ()
1192{
49fb1027 1193 assertStringArg ('tag_name', __FUNCTION__);
2c6c7645 1194 assertUIntArg ('parent_id', __FUNCTION__, TRUE);
49fb1027 1195 $tagname = trim ($_REQUEST['tag_name']);
2eeeca80 1196 if (!validTagName ($tagname))
ebb5441d 1197 return buildRedirectURL ('ERR1', array ($tagname));
0f3c6639 1198 if (tagExistsInDatabase ($tagname))
ebb5441d 1199 return buildRedirectURL ('ERR2', array ($tagname));
fe7044ad
DO
1200 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1201 $parent_id = 'NULL';
1202 if (($ret = commitCreateTag ($tagname, $parent_id)) == '')
ebb5441d 1203 return buildRedirectURL ('OK', array ($tagname));
fe7044ad 1204 else
33b76fd5 1205 return buildRedirectURL ('ERR3', array ($tagname, $ret));
fe7044ad
DO
1206}
1207
49fb1027
DO
1208function updateTag ()
1209{
49fb1027
DO
1210 assertUIntArg ('tag_id', __FUNCTION__);
1211 assertUIntArg ('parent_id', __FUNCTION__, TRUE);
1212 assertStringArg ('tag_name', __FUNCTION__);
1213 $tagname = trim ($_REQUEST['tag_name']);
2eeeca80 1214 if (!validTagName ($tagname))
33b76fd5 1215 return buildRedirectURL ('ERR1', array ($tagname));
49fb1027
DO
1216 if (($parent_id = $_REQUEST['parent_id']) <= 0)
1217 $parent_id = 'NULL';
1218 if (($ret = commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id)) == '')
ebb5441d 1219 return buildRedirectURL ('OK', array ($tagname));
49fb1027 1220 else
33b76fd5 1221 return buildRedirectURL ('ERR2', array ($tagname, $ret));
49fb1027
DO
1222}
1223
eb6ea26f
DO
1224function rollTags ()
1225{
eb6ea26f
DO
1226 assertUIntArg ('row_id', __FUNCTION__);
1227 assertStringArg ('sum', __FUNCTION__, TRUE);
1228 assertUIntArg ('realsum', __FUNCTION__);
eb6ea26f 1229 if ($_REQUEST['sum'] != $_REQUEST['realsum'])
ebb5441d 1230 return buildRedirectURL ('ERR');
abef7149
DO
1231 // Even if the user requested an empty tag list, don't bail out, but process existing
1232 // tag chains with "zero" extra. This will make sure, that the stuff processed will
1233 // have its chains refined to "normal" form.
1234 $extratags = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1235 $n_ok = 0;
1236 // Minimizing the extra chain early, so that tag rebuilder doesn't have to
1237 // filter out the same tag again and again. It will have own noise to cancel.
1238 $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags));
1239 foreach (getRacksForRow ($_REQUEST['row_id']) as $rackInfo)
1240 {
1241 if (rebuildTagChainForEntity ('rack', $rackInfo['id'], $extrachain))
1242 $n_ok++;
1243 foreach (stuffInRackspace (getRackData ($rackInfo['id'])) as $object_id)
1244 if (rebuildTagChainForEntity ('object', $object_id, $extrachain))
1245 $n_ok++;
1246 }
1247 return buildRedirectURL ('OK', array ($n_ok));
eb6ea26f
DO
1248}
1249
9457ca59 1250function changeMyPassword ()
cced6b7d 1251{
103b1e1e 1252 global $accounts, $remote_username;
9457ca59 1253 if (getConfigVar ('USER_AUTH_SRC') != 'database')
ebb5441d 1254 return buildRedirectURL ('ERR1');
0ac7e4b3
DO
1255 assertStringArg ('oldpassword', __FUNCTION__);
1256 assertStringArg ('newpassword1', __FUNCTION__);
1257 assertStringArg ('newpassword2', __FUNCTION__);
1258 if ($accounts[$remote_username]['user_password_hash'] != hash (PASSWORD_HASH, $_REQUEST['oldpassword']))
ebb5441d 1259 return buildRedirectURL ('ERR2');
cced6b7d 1260 if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2'])
ebb5441d 1261 return buildRedirectURL ('ERR3');
0ac7e4b3 1262 if (commitUpdateUserAccount ($accounts[$remote_username]['user_id'], $accounts[$remote_username]['user_name'], $accounts[$remote_username]['user_realname'], hash (PASSWORD_HASH, $_REQUEST['newpassword1'])))
ebb5441d 1263 return buildRedirectURL ('OK');
cced6b7d 1264 else
ebb5441d 1265 return buildRedirectURL ('ERR4');
cced6b7d
DO
1266}
1267
1268function saveRackCode ()
1269{
cced6b7d 1270 assertStringArg ('rackcode');
e6a4adb9
DO
1271 // For the test to succeed, unescape LFs, strip CRs.
1272 $newcode = str_replace ('\r', '', str_replace ('\n', "\n", $_REQUEST['rackcode']));
cf25e649
DO
1273 $parseTree = getRackCode ($newcode);
1274 if ($parseTree['result'] != 'ACK')
ebb5441d 1275 return buildRedirectURL ('ERR1', array ($parseTree['load']));
4a6a28f1 1276 saveScript ('RackCodeCache', '');
cf25e649 1277 if (saveScript ('RackCode', $newcode))
ebb5441d 1278 return buildRedirectURL ('OK');
cced6b7d 1279 else
ebb5441d 1280 return buildRedirectURL ('ERR2');
cced6b7d
DO
1281}
1282
46f92ff7
DO
1283// This handler's context is pre-built, but not authorized. It is assumed, that the
1284// handler will take existing context and before each commit check authorization
1285// on the base chain plus necessary context added.
1286function setPortVLAN ()
1287{
1288 assertUIntArg ('portcount', __FUNCTION__);
1289 $data = getSwitchVLANs ($_REQUEST['object_id']);
1290 if ($data === NULL)
ebb5441d 1291 return buildRedirectURL ('ERR1');
46f92ff7
DO
1292 list ($vlanlist, $portlist) = $data;
1293 // Here we just build up 1 set command for the gateway with all of the ports
1294 // included. The gateway is expected to filter unnecessary changes silently
1295 // and to provide a list of responses with either error or success message
1296 // for each of the rest.
1297 $nports = $_REQUEST['portcount'];
1298 $prefix = 'set ';
73067b6a 1299 $log = array ('v' => 2, 'm' => array());
46f92ff7
DO
1300 $setcmd = '';
1301 for ($i = 0; $i < $nports; $i++)
1302 if
1303 (
1304 !isset ($_REQUEST['portname_' . $i]) ||
1305 !isset ($_REQUEST['vlanid_' . $i]) ||
1306 $_REQUEST['portname_' . $i] != $portlist[$i]['portname']
1307 )
24dcb9d8 1308 $log['m'][] = array ('c' => 158, 'a' => array ($i));
46f92ff7
DO
1309 elseif
1310 (
1311 $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] ||
1312 $portlist[$i]['vlaind'] == 'TRUNK'
1313 )
1314 continue;
1315 else
1316 {
1317 $portname = $_REQUEST['portname_' . $i];
1318 $oldvlanid = $portlist[$i]['vlanid'];
1319 $newvlanid = $_REQUEST['vlanid_' . $i];
1320 // Finish the security context and evaluate it.
1321 $annex = array();
1322 $annex[] = array ('tag' => '$fromvlan_' . $oldvlanid);
1323 $annex[] = array ('tag' => '$tovlan_' . $newvlanid);
1324 if (!permitted (NULL, NULL, NULL, $annex))
1325 {
24dcb9d8 1326 $log['m'][] = array ('c' => 159, 'a' => array ($portname, $oldvlanid, $newvlanid));
46f92ff7
DO
1327 continue;
1328 }
1329 $setcmd .= $prefix . $portname . '=' . $newvlanid;
1330 $prefix = ';';
1331 }
1332 // Feed the gateway and interpret its (non)response.
1333 if ($setcmd != '')
f0ff4930 1334 $log['m'] = array_merge ($log['m'], setSwitchVLANs ($_REQUEST['object_id'], $setcmd));
46f92ff7 1335 else
24dcb9d8 1336 $log['m'][] = array ('c' => 201);
46f92ff7
DO
1337 return buildWideRedirectURL ($log);
1338}
1339
2987fc1f
DO
1340function submitSLBConfig ()
1341{
1342 assertUIntArg ('object_id', __FUNCTION__);
1343 $newconfig = buildLVSConfig ($_REQUEST['object_id']);
3dd72e34 1344 $msglog = gwSendFile ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8'));
2987fc1f
DO
1345 return buildWideRedirectURL ($msglog);
1346}
1347
345fd640
AD
1348function addRow ()
1349{
1350 assertStringArg ('name', __FUNCTION__);
1351
1352 if (commitSupplementDictionary (3, $_REQUEST['name']) === TRUE)
1353 return buildRedirectURL ('OK', array ($_REQUEST['name']));
1354 else
1355 return buildRedirectURL ('ERR', array ($_REQUEST['name']));
1356}
1357
1358function updateRow ()
1359{
1360 assertUIntArg ('row_id', __FUNCTION__);
1361 assertStringArg ('name', __FUNCTION__);
1362
1363 if (TRUE === commitUpdateDictionary (3, $_REQUEST['row_id'], $_REQUEST['name']))
1364 return buildRedirectURL ('OK', array ($_REQUEST['name']));
1365 else
1366 return buildRedirectURL ('ERR', array ($_REQUEST['name']));
1367}
1368
f19c75d6
DO
1369function addRack ()
1370{
1371 assertUIntArg ('row_id', __FUNCTION__);
1372 $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array();
1373 if (isset ($_REQUEST['got_data']))
1374 {
1375 assertStringArg ('rack_name', __FUNCTION__);
1376 assertUIntArg ('rack_height1', __FUNCTION__);
1377 assertStringArg ('rack_comment', __FUNCTION__, TRUE);
1378
1379 if (commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist) === TRUE)
1380 return buildRedirectURL ('OK', array ($_REQUEST['rack_name']));
1381 else
1382 return buildRedirectURL ('ERR1', array ($_REQUEST['rack_name']));
1383 }
1384 elseif (isset ($_REQUEST['got_mdata']))
1385 {
1386 assertUIntArg ('rack_height2', __FUNCTION__);
1387 assertStringArg ('rack_names', __FUNCTION__, TRUE);
1388 $log = array ('v' => 2);
1389 // copy-and-paste from renderAddMultipleObjectsForm()
1390 $names1 = explode ('\n', $_REQUEST['rack_names']);
1391 $names2 = array();
1392 foreach ($names1 as $line)
1393 {
1394 $parts = explode ('\r', $line);
1395 reset ($parts);
1396 if (empty ($parts[0]))
1397 continue;
1398 else
1399 $names2[] = rtrim ($parts[0]);
1400 }
1401 foreach ($names2 as $cname)
1402 if (commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist) === TRUE)
1403 $log['m'][] = array ('c' => getMessageCode ('OK'), 'a' => array ($cname));
1404 else
1405 $log['m'][] = array ('c' => getMessageCode ('ERR1'), 'a' => array ($cname));
1406 return buildWideRedirectURL ($log);
1407 }
1408 else
1409 return buildRedirectURL ('ERR2');
f19c75d6
DO
1410}
1411
7056988c
DO
1412function updateRack ()
1413{
7056988c
DO
1414 assertUIntArg ('rack_id', __FUNCTION__);
1415 assertUIntArg ('rack_row_id', __FUNCTION__);
1416 assertUIntArg ('rack_height', __FUNCTION__);
1417 assertStringArg ('rack_name', __FUNCTION__);
1418 assertStringArg ('rack_comment', __FUNCTION__, TRUE);
7056988c 1419
7056988c 1420 resetThumbCache ($_REQUEST['rack_id']);
0c2b7c4a
DO
1421 if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment']))
1422 return buildRedirectURL ('OK', array ($_REQUEST['rack_name']));
1423 else
1424 return buildRedirectURL ('ERR');
7056988c
DO
1425}
1426
1427function querySNMPData ()
1428{
1429 assertUIntArg ('object_id', __FUNCTION__);
1430 assertStringArg ('community', __FUNCTION__);
83fdf85f 1431 return buildWideRedirectURL (doSNMPmining ($_REQUEST['object_id'], $_REQUEST['community']));
7056988c
DO
1432}
1433
e1ae3fb4
AD
1434// File-related functions
1435function addFileWithoutLink ()
1436{
1437 assertStringArg ('comment', __FUNCTION__, TRUE);
1438
1439 // Make sure the file can be uploaded
1440 if (get_cfg_var('file_uploads') != 1)
1441 return buildRedirectURL ('ERR', array ("file uploads not allowed, change 'file_uploads' parameter in php.ini"));
1442
1443 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1444 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $_REQUEST['comment']);
1445
1446 if ($error != '')
1447 return buildRedirectURL ('ERR', array ($error));
1448
1449 return buildRedirectURL ('OK', array ($_FILES['file']['name']));
1450}
1451
1452function addFileToEntity ()
1453{
1454 assertStringArg ('entity_type', __FUNCTION__);
1455 assertUIntArg ('entity_id', __FUNCTION__);
1456 assertStringArg ('comment', __FUNCTION__, TRUE);
1457 if (empty ($_REQUEST['entity_type']) || empty ($_REQUEST['entity_id']))
1458 return buildRedirectURL ('ERR');
1459
1460 // Make sure the file can be uploaded
1461 if (get_cfg_var('file_uploads') != 1)
1462 return buildRedirectURL ('ERR', array ("file uploads not allowed, change 'file_uploads' parameter in php.ini"));
1463
1464 $fp = fopen($_FILES['file']['tmp_name'], 'rb');
1465 $error = commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $_REQUEST['comment']);
1466 if ($error != '')
1467 return buildRedirectURL ('ERR', array ($error));
1468
1469 $file_id = lastInsertID();
1470 $error = commitLinkFile ($file_id, $_REQUEST['entity_type'], $_REQUEST['entity_id']);
1471 if ($error != '')
1472 return buildRedirectURL ('ERR', array ($error));
1473
1474 return buildRedirectURL ('OK', array ($_FILES['file']['name']));
1475}
1476
1477function linkFileToEntity ()
1478{
1479 assertUIntArg ('entity_id', __FUNCTION__);
1480 assertUIntArg ('file_id', __FUNCTION__);
1481 assertStringArg ('file_name', __FUNCTION__);
1482
1483 $error = commitLinkFile ($_REQUEST['file_id'], $_REQUEST['entity_type'], $_REQUEST['entity_id']);
1484 if ($error != '')
1485 return buildRedirectURL ('ERR', array ($error));
1486
1487 return buildRedirectURL ('OK', array ($_REQUEST['file_name']));
1488}
1489
1490function updateFile ()
1491{
1492 assertUIntArg ('file_id', __FUNCTION__);
1493 assertStringArg ('name', __FUNCTION__);
1494 assertStringArg ('comment', __FUNCTION__, TRUE);
1495 $error = commitUpdateFile ($_REQUEST['file_id'], $_REQUEST['comment']);
1496 if ($error != '')
1497 return buildRedirectURL ('ERR', array ($error));
1498
1499 return buildRedirectURL ('OK', array ($_REQUEST['name']));
1500}
1501
1502function unlinkFile ()
1503{
1504 assertUIntArg ('link_id', __FUNCTION__);
1505 $error = commitUnlinkFile ($_REQUEST['link_id']);
1506
1507 if ($error != '')
1508 return buildRedirectURL ('ERR', array ($error));
1509
1510 return buildRedirectURL ('OK', array ($_REQUEST['name']));
1511}
1512
1513function deleteFile ()
1514{
1515 assertUIntArg ('file_id', __FUNCTION__);
1516 $error = commitDeleteFile ($_REQUEST['file_id']);
1517
1518 if ($error != '')
1519 return buildRedirectURL ('ERR', array ($error));
1520
1521 return buildRedirectURL ('OK', array ($_REQUEST['name']));
1522}
1523
e673ee24 1524?>