r1723 + getAutoPorts(): new function to hold AutoPorts kitchen in one place
[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
8function addPortForwarding ()
9{
10 global $root, $pageno, $tabno;
11
c87fd3fe
DO
12 assertUIntArg ('object_id');
13 assertIPv4Arg ('localip');
14 assertIPv4Arg ('remoteip');
15 assertUIntArg ('localport');
16 assertUIntArg ('remoteport');
17 assertUIntArg ('proto');
18 assertStringArg ('description');
e673ee24
DO
19 $object_id = $_REQUEST['object_id'];
20 $localip = $_REQUEST['localip'];
21 $remoteip = $_REQUEST['remoteip'];
22 $localport = $_REQUEST['localport'];
23 $remoteport = $_REQUEST['remoteport'];
24 $proto = $_REQUEST['proto'];
e673ee24 25 $description = $_REQUEST['description'];
31fc4157
DO
26 if (empty ($remoteport))
27 $remoteport = $localport;
e673ee24
DO
28
29 $retpage="${root}?page=${pageno}&tab=${tabno}&object_id=$object_id";
30
31
32 $error=newPortForwarding($object_id, $localip, $localport, $remoteip, $remoteport, $proto, $description);
33
34 if ($error == '')
35 return "${retpage}&message=".urlencode('Port forwarding successfully added.');
36 else
37 {
38 return "${retpage}&error=".urlencode($error);
39 }
40
41}
42
43function delPortForwarding ()
44{
45 global $root, $pageno, $tabno;
46
47 $object_id = $_REQUEST['object_id'];
48 $localip = $_REQUEST['localip'];
49 $remoteip = $_REQUEST['remoteip'];
50 $localport = $_REQUEST['localport'];
51 $remoteport = $_REQUEST['remoteport'];
52 $proto = $_REQUEST['proto'];
e673ee24
DO
53
54 $retpage="${root}?page=${pageno}&tab=${tabno}&object_id=$object_id";
55
56 $error=deletePortForwarding($object_id, $localip, $localport, $remoteip, $remoteport, $proto);
57 if ($error == '')
58 return "${retpage}&message=".urlencode('Port forwarding successfully deleted.');
59 else
60 {
61 return "${retpage}&error=".urlencode($error);
62 }
63
64}
65
66function updPortForwarding ()
67{
68 global $root, $pageno, $tabno;
69
70 $object_id = $_REQUEST['object_id'];
71 $localip = $_REQUEST['localip'];
72 $remoteip = $_REQUEST['remoteip'];
73 $localport = $_REQUEST['localport'];
74 $remoteport = $_REQUEST['remoteport'];
75 $proto = $_REQUEST['proto'];
76 $description = $_REQUEST['description'];
77
78 $retpage="${root}?page=${pageno}&tab=${tabno}&object_id=$object_id";
79
80 $error=updatePortForwarding($object_id, $localip, $localport, $remoteip, $remoteport, $proto, $description);
81 if ($error == '')
82 return "${retpage}&message=".urlencode('Port forwarding successfully updated.');
83 else
84 {
85 return "${retpage}&error=".urlencode($error);
86 }
87
88}
89
e673ee24
DO
90function addPortForObject ()
91{
92 global $root, $pageno, $tabno;
93
94 $object_id = $_REQUEST['object_id'];
95 $port_name = $_REQUEST['port_name'];
96 $port_l2address = $_REQUEST['port_l2address'];
97 $port_label = $_REQUEST['port_label'];
98 $port_type_id = $_REQUEST['port_type_id'];
99
100
101 if ($port_name == '')
102 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode('Port name cannot be empty');
103 else
104 {
105 $error = commitAddPort ($object_id, $port_name, $port_type_id, $port_label, $port_l2address);
106 if ($error != '')
107 {
108 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode($error);
109 }
110 else
111 {
112 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=".urlencode("Port $port_name added successfully");
113 }
114 }
115
116}
117
118function editPortForObject ()
119{
120 global $root, $pageno, $tabno;
121
122 assertUIntArg ('port_id');
123 assertUIntArg ('object_id');
124 assertStringArg ('name');
125 $port_id = $_REQUEST['port_id'];
126 $object_id = $_REQUEST['object_id'];
127 $port_name = $_REQUEST['name'];
128 $port_l2address = $_REQUEST['l2address'];
129 $port_label = $_REQUEST['label'];
130 if (isset ($_REQUEST['reservation_comment']) and !empty ($_REQUEST['reservation_comment']))
131 $port_rc = '"' . $_REQUEST['reservation_comment'] . '"';
132 else
133 $port_rc = 'NULL';
134
135 if ($port_name == '')
136 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode('Port name cannot be empty');
137 else
138 {
139 $error = commitUpdatePort ($port_id, $port_name, $port_label, $port_l2address, $port_rc);
140 if ($error != '')
141 {
142 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode($error);
143 }
144 else
145 {
146 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=".urlencode("Port $port_name updated successfully");
147 }
148 }
149
150}
151
152function delPortFromObject ()
153{
154 global $root, $pageno, $tabno;
155
156 $port_id = $_REQUEST['port_id'];
157 $port_name = $_REQUEST['port_name'];
158 $object_id = $_REQUEST['object_id'];
159 $error = delObjectPort($port_id);
160
161 if ($error != '')
162 {
163 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode($error);
164 }
165 else
166 {
167 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=".urlencode("Port $port_name deleted successfully");
168 }
169}
170
171function linkPortForObject ()
172{
173 global $root, $pageno, $tabno;
174
175 $port_id = $_REQUEST['port_id'];
176 $remote_port_id = $_REQUEST['remote_port_id'];
177 $object_id = $_REQUEST['object_id'];
178 $port_name = $_REQUEST['port_name'];
179 $remote_port_name = $_REQUEST['remote_port_name'];
180 $remote_object_name = $_REQUEST['remote_object_name'];
181
182 $error = linkPorts($port_id, $remote_port_id);
183 if ($error != '')
184 {
185 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode($error);
186 }
187 else
188 {
189 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=".urlencode("Port $port_name successfully linked with port $remote_port_name at object $remote_object_name");
190 }
191}
192
193function unlinkPortForObject ()
194{
195 global $root, $pageno, $tabno;
196
197 $port_id = $_REQUEST['port_id'];
198 $object_id = $_REQUEST['object_id'];
199 $port_name = $_REQUEST['port_name'];
200 $remote_port_name = $_REQUEST['remote_port_name'];
201 $remote_object_name = $_REQUEST['remote_object_name'];
202
203 $error = unlinkPort($port_id);
204 if ($error != '')
205 {
206 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=".urlencode($error);
207 }
208 else
209 {
210 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=".urlencode("Port $port_name successfully unlinked from port $remote_port_name at object $remote_object_name");
211 }
212}
213
214function addMultiPorts ()
215{
216 global $root, $pageno, $tabno;
217 // Parse data.
218 assertStringArg ('format');
219 assertStringArg ('input');
220 assertUIntArg ('port_type');
221 assertUIntArg ('object_id');
222 $format = $_REQUEST['format'];
223 $port_type = $_REQUEST['port_type'];
224 $object_id = $_REQUEST['object_id'];
225 // Input lines are escaped, so we have to explode and to chop by 2-char
226 // \n and \r respectively.
227 $lines1 = explode ('\n', $_REQUEST['input']);
228 foreach ($lines1 as $line)
229 {
230 $parts = explode ('\r', $line);
231 reset ($parts);
232 if (empty ($parts[0]))
233 continue;
234 else
235 $lines2[] = rtrim ($parts[0]);
236 }
237 $ports = array();
238 foreach ($lines2 as $line)
239 {
240 switch ($format)
241 {
242 case 'fisxii':
243 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
244 list ($slot, $port) = explode ('/', $words[0]);
245 $ports[] = array
246 (
247 'name' => "e ${slot}/${port}",
248 'l2address' => $words[8],
249 'label' => "slot ${slot} port ${port}"
250 );
251 break;
252 case 'c3600asy':
253 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', trim (substr ($line, 3))));
254/*
255How Async Lines are Numbered in Cisco 3600 Series Routers
256http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00801ca70b.shtml
257
258Understanding 16- and 32-Port Async Network Modules
259http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00800a93f0.shtml
260*/
261 $async = $words[0];
262 $slot = floor (($async - 1) / 32);
263 $octalgroup = floor (($async - 1 - $slot * 32) / 8);
264 $cable = $async - $slot * 32 - $octalgroup * 8;
265 $og_label[0] = 'async 0-7';
266 $og_label[1] = 'async 8-15';
267 $og_label[2] = 'async 16-23';
268 $og_label[3] = 'async 24-31';
269 $ports[] = array
270 (
271 'name' => "async ${async}",
272 'l2address' => '',
273 'label' => "slot ${slot} " . $og_label[$octalgroup] . " cable ${cable}"
274 );
275 break;
276 case 'fiwg':
277 $words = explode (' ', ereg_replace ('[[:space:]]+', ' ', $line));
278 $ifnumber = $words[0] * 1;
279 $ports[] = array
280 (
281 'name' => "e ${ifnumber}",
282 'l2address' => "${words[8]}",
283 'label' => "${ifnumber}"
284 );
285 break;
351d4dbf 286 case 'ssv1':
5b585342 287 $words = explode (' ', $line);
351d4dbf
DO
288 if (empty ($words[0]) or empty ($words[1]))
289 continue;
290 $ports[] = array
291 (
292 'name' => $words[0],
293 'l2address' => $words[1],
294 'label' => ''
295 );
296 break;
e673ee24
DO
297 default:
298 return
299 "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=" .
300 urlencode('Cannot process submitted data: unknown format code.');
301 break;
302 }
303 }
304 // Create ports, if they don't exist.
305 $added_count = $updated_count = $error_count = 0;
306 foreach ($ports as $port)
307 {
308 $port_id = getPortID ($object_id, $port['name']);
309 if ($port_id === NULL)
310 {
311 $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
312 if ($result == '')
313 $added_count++;
314 else
315 $error_count++;
316 }
317 else
318 {
319 $result = commitUpdatePort ($port_id, $port['name'], $port['label'], $port['l2address']);
320 if ($result == '')
321 $updated_count++;
322 else
323 $error_count++;
324 }
325 }
326 return
327 "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" .
328 urlencode("Added ${added_count} ports, updated ${updated_count} ports, encountered ${error_count} errors.");
329}
330
331function editAddressFromObject ()
332{
333 global $root;
334
335 $ip = $_REQUEST['ip'];
336 $object_id = $_REQUEST['object_id'];
337 $name = $_REQUEST['bond_name'];
338 $type = $_REQUEST['bond_type'];
339 $error = updateBond($ip, $object_id, $name, $type);
340 if ($error != '')
341 {
342 return "${root}?page=object&tab=network&object_id=$object_id&error=".urlencode($error);
343 }
344 else
345 {
346 return "${root}?page=object&tab=network&object_id=$object_id&message=".urlencode("Interface successfully updated");
347 }
348}
349
350function delAddressFromObject ()
351{
352 global $root;
353
354 $ip = $_REQUEST['ip'];
355 $object_id = $_REQUEST['object_id'];
356 $error = unbindIpFromObject($ip, $object_id);
357 if ($error != '')
358 {
359 return "${root}?page=object&tab=network&object_id=$object_id&error=".urlencode($error);
360 }
361 else
362 {
363 return "${root}?page=object&tab=network&object_id=$object_id&message=".urlencode("Interface successfully deleted");
364 }
365}
366
367function delIpAssignment ()
368{
369 global $root;
370
371 $ip = $_REQUEST['ip'];
372 $object_id = $_REQUEST['object_id'];
373 $error = unbindIpFromObject($ip, $object_id);
374 if ($error != '')
375 {
376 return "${root}?page=ipaddress&tab=assignment&ip=$ip&error=".urlencode($error);
377 }
378 else
379 {
380 return "${root}?page=ipaddress&tab=assignment&ip=$ip&message=".urlencode("Interface successfully deleted");
381 }
382}
383
384function editIpAssignment ()
385{
386 global $root;
387
388 $ip = $_REQUEST['ip'];
389 $object_id = $_REQUEST['object_id'];
390 $name = $_REQUEST['bond_name'];
391 $type = $_REQUEST['bond_type'];
392 $error = updateBond($ip, $object_id, $name, $type);
393
394 if ($error != '')
395 {
396 return "${root}?page=ipaddress&tab=assignment&ip=$ip&error=".urlencode($error);
397 }
398 else
399 {
400 return "${root}?page=ipaddress&tab=assignment&ip=$ip&message=".urlencode("Interface successfully updated");
401 }
402}
403
404function addIpAssignment ()
405{
406 global $root;
407
408 $ip = $_REQUEST['ip'];
409 $object_id = $_REQUEST['object_id'];
410 $name = $_REQUEST['bond_name'];
411 $type = $_REQUEST['bond_type'];
412 $error = bindIpToObject($ip, $object_id, $name, $type);
413 if ($error != '')
414 {
415 return "${root}?page=ipaddress&tab=assignment&ip=$ip&error=".urlencode($error);
416 }
417 else
418 {
419 return "${root}?page=ipaddress&tab=assignment&ip=$ip&message=".urlencode("Interface successfully added");
420 }
421}
422
423function addNewRange ()
424{
425 global $root, $pageno, $tabno;
426
2a201216 427 $range = $_REQUEST['range'];
e673ee24 428 $name = $_REQUEST['name'];
2dee289e
DO
429 $is_bcast = $_REQUEST['is_bcast'];
430 $error = addRange($range, $name, $is_bcast == 'on');
e673ee24
DO
431 if ($error != '')
432 {
433 return "${root}?page=${pageno}&tab=${tabno}&error=".urlencode($error);
434 }
435 else
436 {
437 return "${root}?page=${pageno}&tab=${tabno}&message=".urlencode("Range successfully added");
438 }
439}
440
441function editRange ()
442{
443 global $root, $pageno, $tabno;
444
445 $id = $_REQUEST['id'];
446 $name = $_REQUEST['name'];
447 $error = updateRange($id, $name);
448 if ($error != '')
449 {
450 return "${root}?page=${pageno}&tab=${tabno}&id=$id&error=".urlencode($error);
451 }
452 else
453 {
454 return "${root}?page=${pageno}&tab=${tabno}&id=$id&message=".urlencode("Range updated");
455 }
456
457}
458
459function delRange ()
460{
461 global $root, $pageno, $tabno;
462
463 $id = $_REQUEST['id'];
464 $error = commitDeleteRange ($id);
465 if ($error != '')
466 {
467 return "${root}?page=${pageno}&tab=${tabno}&error=".urlencode($error);
468 }
469 else
470 {
471 return "${root}?page=${pageno}&tab=${tabno}&message=".urlencode("Range deleted");
472 }
473
474}
475
476function editAddress ()
477{
478 global $root, $pageno, $tabno;
479
480 $ip = $_REQUEST['ip'];
481 $name = $_REQUEST['name'];
482 if (isset ($_REQUEST['reserved']))
483 $reserved = $_REQUEST['reserved'];
484 else
485 $reserved = 'off';
486 $error = updateAddress($ip, $name, $reserved=='on'?'yes':'no');
487 if ($error != '')
488 {
489 return "${root}?page=${pageno}&tab=${tabno}&ip=$ip&error=".urlencode($error);
490 }
491 else
492 {
493 return "${root}?page=${pageno}&tab=${tabno}&ip=$ip&message=".urlencode("Address updated");
494 }
495
496}
497
498function addAddressToObject ()
499{
500 global $root, $pageno, $tabno;
501
502 $ip = $_REQUEST['ip'];
503 $object_id = $_REQUEST['object_id'];
504 $name = $_REQUEST['name'];
505 $type = $_REQUEST['type'];
506 $error = bindIpToObject($ip, $object_id, $name, $type);
507 if ($error != '')
508 {
509 return "${root}?page=${pageno}&tab=${tabno}&object_id=$object_id&error=".urlencode($error);
510 }
511 else
512 {
513 return "${root}?page=$pageno&tab=${tabno}&object_id=$object_id&message=".urlencode("Interface successfully added");
514 }
515}
516
517function createUserAccount ()
518{
519 global $root, $pageno, $tabno;
520 assertStringArg ('username');
521 assertStringArg ('realname', TRUE);
522 assertStringArg ('password');
523 $username = $_REQUEST['username'];
524 $password = hash (PASSWORD_HASH, $_REQUEST['password']);
525 $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password);
526 if ($result == TRUE)
527 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("User account ${username} created.");
528 else
529 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error creating user account ${username}.");
530}
531
532function updateUserAccount ()
533{
534 global $root, $pageno, $tabno;
535 assertUIntArg ('id');
536 assertStringArg ('username');
537 assertStringArg ('realname', TRUE);
538 assertStringArg ('password');
539 // We might be asked to change username, so use user ID only.
540 $id = $_REQUEST['id'];
541 $username = $_REQUEST['username'];
542 $new_password = $_REQUEST['password'];
543 $old_hash = getHashByID ($id);
544 if ($old_hash == NULL)
545 {
61e269b5 546 showError ('getHashByID() failed', __FUNCTION__);
e673ee24
DO
547 return;
548 }
549 // Update user password only if provided password is not the same as current password hash.
550 if ($new_password != $old_hash)
551 $new_password = hash (PASSWORD_HASH, $new_password);
552 $result = commitUpdateUserAccount ($_REQUEST['id'], $username, $_REQUEST['realname'], $new_password);
553 if ($result == TRUE)
554 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("User account ${username} updated.");
555 else
556 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error updating user account ${username}.");
557}
558
559function enableUserAccount ()
560{
561 global $root, $pageno, $tabno;
562 assertUIntArg ('id');
563 $id = $_REQUEST['id'];
564 $result = commitEnableUserAccount ($id, 'yes');
565 if ($result == TRUE)
566 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("User account enabled.");
567 else
568 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error enabling user account.");
569}
570
571function disableUserAccount ()
572{
573 global $root, $pageno, $tabno;
574 assertUIntArg ('id');
575 $id = $_REQUEST['id'];
576 if ($id == 1)
577 $result = FALSE;
578 else
579 $result = commitEnableUserAccount ($id, 'no');
580 if ($result == TRUE)
581 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("User account disabled.");
582 else
583 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error disabling user account.");
584}
585
586function revokePermission ()
587{
588 global $root, $pageno, $tabno;
589 assertUIntArg ('access_userid', TRUE);
590 assertStringArg ('access_page');
591 assertStringArg ('access_tab');
592 $result = commitRevokePermission
593 (
594 $_REQUEST['access_userid'],
595 $_REQUEST['access_page'],
596 $_REQUEST['access_tab']
597 );
598 if ($result == TRUE)
599 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Revoke successfull.");
600 else
601 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error revoking permission.");
602}
603
604function grantPermission ()
605{
606 global $root, $pageno, $tabno;
607 assertUIntArg ('access_userid', TRUE);
608 assertStringArg ('access_page');
609 assertStringArg ('access_tab');
610 assertStringArg ('access_value');
611 $result = commitGrantPermission
612 (
613 $_REQUEST['access_userid'],
614 $_REQUEST['access_page'],
615 $_REQUEST['access_tab'],
616 $_REQUEST['access_value']
617 );
618 if ($result == TRUE)
619 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Grant successfull.");
620 else
621 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Error granting permission.");
622}
623
624// This function find differences in users's submit and PortCompat table
625// and modifies database accordingly.
626function savePortMap ()
627{
628 global $root, $pageno, $tabno;
629 $ptlist = getPortTypes();
630 $oldCompat = getPortCompat();
631 $newCompat = array();
632 foreach (array_keys ($ptlist) as $leftKey)
633 foreach (array_keys ($ptlist) as $rightKey)
634 if (isset ($_REQUEST["atom_${leftKey}_${rightKey}"]))
635 $newCompat[] = array ('type1' => $leftKey, 'type2' => $rightKey);
636 // Build the new matrix from user's submit and compare it to
637 // the old matrix. Those pairs which appear on
638 // new matrix only, have to be stored in PortCompat table. Those who appear
639 // on the old matrix only, should be removed from PortCompat table.
640 // Those present in both matrices should be skipped.
641 $oldCompatTable = buildPortCompatMatrixFromList ($ptlist, $oldCompat);
642 $newCompatTable = buildPortCompatMatrixFromList ($ptlist, $newCompat);
643 $error_count = $success_count = 0;
644 foreach (array_keys ($ptlist) as $type1)
645 foreach (array_keys ($ptlist) as $type2)
646 if ($oldCompatTable[$type1][$type2] != $newCompatTable[$type1][$type2])
647 switch ($oldCompatTable[$type1][$type2])
648 {
649 case TRUE: // new value is FALSE
650 if (removePortCompat ($type1, $type2) === TRUE)
651 $success_count++;
652 else
653 $error_count++;
654 break;
655 case FALSE: // new value is TRUE
656 if (addPortCompat ($type1, $type2) === TRUE)
657 $success_count++;
658 else
659 $error_count++;
660 break;
661 default:
61e269b5 662 showError ('oldCompatTable is invalid', __FUNCTION__);
e673ee24
DO
663 break;
664 }
665 return
666 "${root}?page=${pageno}&tab=${tabno}&" .
667 ($error_count == 0 ? 'message' : 'error') .
668 "=" . urlencode ("${error_count} failures and ${success_count} successfull changes.");
669}
670
671function deleteDictWord ()
672{
673 global $root, $pageno, $tabno;
674 return
675 "${root}?page=${pageno}&tab=${tabno}&" .
676 "error=" . urlencode ('Dragon ate this word!');
677}
678
679function updateDictionary ()
680{
681 global $root, $pageno, $tabno;
682 assertUIntArg ('chapter_no');
683 assertUIntArg ('dict_key');
684 assertStringArg ('dict_value');
685 if (commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value']) === TRUE)
686 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Update succeeded.');
687 else
688 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Update failed!");
689}
690
691function supplementDictionary ()
692{
693 global $root, $pageno, $tabno;
694 assertUIntArg ('chapter_no');
695 assertStringArg ('dict_value');
696 if (commitSupplementDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_value']) === TRUE)
697 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Supplement succeeded.');
698 else
699 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Supplement failed!");
700}
701
702function reduceDictionary ()
703{
704 global $root, $pageno, $tabno;
705 assertUIntArg ('chapter_no');
706 assertUIntArg ('dict_key');
707 if (commitReduceDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key']) === TRUE)
708 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Reduction succeeded.');
709 else
710 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Reduction failed!");
711}
712
713function addChapter ()
714{
715 global $root, $pageno, $tabno;
716 assertStringArg ('chapter_name');
717 if (commitAddChapter ($_REQUEST['chapter_name']) === TRUE)
718 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Chapter was added.');
719 else
720 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error adding chapter.');
721}
722
723function updateChapter ()
724{
725 global $root, $pageno, $tabno;
726 assertUIntArg ('chapter_no');
727 assertStringArg ('chapter_name');
728 if (commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name']) === TRUE)
729 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Chapter was updated.');
730 else
731 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error updating chapter.');
732}
733
734function delChapter ()
735{
736 global $root, $pageno, $tabno;
737 assertUIntArg ('chapter_no');
738 if (commitDeleteChapter ($_REQUEST['chapter_no']))
739 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Chapter was deleted.');
740 else
741 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error deleting chapter.');
742}
743
744function changeAttribute ()
745{
746 global $root, $pageno, $tabno;
747 assertUIntArg ('attr_id');
748 assertStringArg ('attr_name');
749 if (commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name']))
750 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Rename successful.');
751 else
752 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error renaming attribute.');
753}
754
755function createAttribute ()
756{
757 global $root, $pageno, $tabno;
758 assertStringArg ('attr_name');
759 assertStringArg ('attr_type');
760 if (commitAddAttribute ($_REQUEST['attr_name'], $_REQUEST['attr_type']))
761 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Attribute '${_REQUEST['attr_name']}' created.");
762 else
763 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error creating attribute.');
764}
765
766function deleteAttribute ()
767{
768 global $root, $pageno, $tabno;
769 assertUIntArg ('attr_id');
770 if (commitDeleteAttribute ($_REQUEST['attr_id']))
771 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Attribute was deleted.');
772 else
773 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('Error deleting attribute.');
774}
775
776function supplementAttrMap ()
777{
778 global $root, $pageno, $tabno;
779 assertUIntArg ('attr_id');
780 assertUIntArg ('objtype_id');
781 assertUIntArg ('chapter_no');
782 if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $_REQUEST['chapter_no']) === TRUE)
783 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Supplement succeeded.');
784 else
785 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Supplement failed!");
786}
787
788function reduceAttrMap ()
789{
790 global $root, $pageno, $tabno;
791 assertUIntArg ('attr_id');
792 assertUIntArg ('objtype_id');
793 if (commitReduceAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id']) === TRUE)
794 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ('Reduction succeeded.');
795 else
796 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Reduction failed!");
797}
798
799function resetAttrValue ()
800{
801 global $root, $pageno, $tabno;
802 assertUIntArg ('attr_id');
803 assertUIntArg ('object_id');
804 $object_id = $_REQUEST['object_id'];
805 if (commitResetAttrValue ($object_id, $_REQUEST['attr_id']) === TRUE)
806 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" . urlencode ('Reset succeeded.');
807 else
808 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=" . urlencode ("Reset failed!");
809}
810
0dfb8a2a 811function updateAttrValues ()
e673ee24
DO
812{
813 global $root, $pageno, $tabno;
e673ee24 814 assertUIntArg ('object_id');
e673ee24 815 $object_id = $_REQUEST['object_id'];
0dfb8a2a
DO
816 $oldvalues = getAttrValues ($object_id);
817
818 assertUIntArg ('num_attrs');
819 $num_attrs = $_REQUEST['num_attrs'];
820 $result = array();
821
822 for ($i = 0; $i < $num_attrs; $i++)
823 {
824 assertUIntArg ("${i}_attr_id");
825 $attr_id = $_REQUEST["${i}_attr_id"];
826
827 // Field is empty, delete attribute and move on.
828 if (empty($_REQUEST["${i}_value"]))
829 {
830 commitResetAttrValue ($object_id, $attr_id);
831 continue;
832 }
833
834 // The value could be uint/float, but we don't know ATM. Let SQL
835 // server check this and complain.
836 assertStringArg ("${i}_value");
837 $value = $_REQUEST["${i}_value"];
838 switch ($oldvalues[$attr_id]['type'])
839 {
840 case 'uint':
841 case 'float':
842 case 'string':
843 $oldvalue = $oldvalues[$attr_id]['value'];
844 break;
845 case 'dict':
846 $oldvalue = $oldvalues[$attr_id]['key'];
847 break;
848 default:
61e269b5 849 showError ('Internal structure error', __FUNCTION__);
0dfb8a2a
DO
850 die;
851 }
852 if ($value == $oldvalue)
853 continue;
854
855 // Note if the queries succeed or not, it determines which page they see.
856 $result[] = commitUpdateAttrValue ($object_id, $attr_id, $value);
857 }
858
859 if (in_array(false, $result))
e673ee24 860 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=" . urlencode ("Update failed!");
0dfb8a2a
DO
861
862 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" . urlencode ('Update succeeded.');
e673ee24
DO
863}
864
865function useupPort ()
866{
867 global $root, $pageno, $tabno;
868 assertUIntArg ('port_id');
869 assertUIntArg ('object_id');
870 $object_id = $_REQUEST['object_id'];
871 if (commitUseupPort ($_REQUEST['port_id']) === TRUE)
872 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&message=" . urlencode ('Reservation removed.');
873 else
874 return "${root}?page=${pageno}&tab=${tabno}&object_id=${object_id}&error=" . urlencode ("Error removing reservation!");
875}
876
4fe32e78
DY
877function updateUI ()
878{
c461c579 879 global $root, $pageno, $tabno;
4fe32e78
DY
880 $oldvalues = loadConfigCache();
881
882 assertUIntArg ('num_vars');
883 $num_vars = $_REQUEST['num_vars'];
c461c579 884 $error = '';
4fe32e78
DY
885
886 for ($i = 0; $i < $num_vars; $i++)
887 {
888 assertStringArg ("${i}_varname");
1f464cff 889 assertStringArg ("${i}_varvalue", TRUE);
4fe32e78 890 $varname = $_REQUEST["${i}_varname"];
4fe32e78 891 $varvalue = $_REQUEST["${i}_varvalue"];
4fe32e78 892
c461c579
DO
893 // If form value = value in DB, don't bother updating DB
894 if ($varvalue == getConfigVar ($varname))
4fe32e78
DY
895 continue;
896
897 // Note if the queries succeed or not, it determines which page they see.
c461c579
DO
898 $error = setConfigVar ($varname, $varvalue, TRUE);
899 if (!empty ($error))
900 break;
4fe32e78
DY
901 }
902
c461c579
DO
903 if ($error != '')
904 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ("Update failed with error: " . $error);
4fe32e78 905
c461c579 906 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Update succeeded.");
4fe32e78
DY
907}
908
b07f617c
DO
909function resetUIConfig()
910{
6c12ef9b 911 global $root, $pageno, $tabno;
1f86e996 912 setConfigVar ('default_port_type','24');
b07f617c
DO
913 setConfigVar ('MASSCOUNT','15');
914 setConfigVar ('MAXSELSIZE','30');
915 setConfigVar ('NAMEFUL_OBJTYPES','4,7,8');
916 setConfigVar ('ROW_SCALE','2');
917 setConfigVar ('PORTS_PER_ROW','12');
918 setConfigVar ('IPV4_ADDRS_PER_PAGE','256');
919 setConfigVar ('DEFAULT_RACK_HEIGHT','42');
a6305acc 920 setConfigVar ('REQUIRE_ASSET_TAG_FOR','4,7,8');
b5ce46aa
DO
921 setConfigVar ('USER_AUTH_SRC','database');
922 setConfigVar ('DEFAULT_SLB_VS_PORT','');
923 setConfigVar ('DEFAULT_SLB_RS_PORT','');
924 setConfigVar ('IPV4_PERFORMERS','1,4,7,8,12,14');
925 setConfigVar ('NATV4_PERFORMERS','4,7,8');
72281138 926 setConfigVar ('DETECT_URLS','no');
4b8d413e 927 setConfigVar ('RACK_PRESELECT_THRESHOLD','1');
b108de49 928 setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no');
8dfb997c 929 setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm');
a477e405 930 setConfigVar ('DEFAULT_OBJECT_TYPE','4');
6c12ef9b 931 return "${root}?page=${pageno}&tab=default&message=" . urlencode ("Reset complete");
b07f617c
DO
932}
933
732e4578 934// Add single record.
ca461127
DO
935function addRealServer ()
936{
937 global $root, $pageno, $tabno;
938
939 assertUIntArg ('id');
d6517a21 940 assertIPv4Arg ('rsip');
ca461127
DO
941 assertUIntArg ('rsport');
942 assertStringArg ('rsconfig', TRUE);
943 $pool_id = $_REQUEST['id'];
7e7a8387 944 if (!addRStoRSPool ($pool_id, $_REQUEST['rsip'], $_REQUEST['rsport'], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), $_REQUEST['rsconfig']))
d6517a21
DO
945 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&error=" . urlencode ('addRStoRSPool() failed');
946 else
947 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&message=" . urlencode ("Real server was successfully added");
948}
949
732e4578
DO
950// Parse textarea submitted and try adding a real server for each line.
951function addRealServers ()
952{
953 global $root, $pageno, $tabno;
954
955 assertUIntArg ('id');
956 assertStringArg ('format');
957 assertStringArg ('rawtext');
958 $pool_id = $_REQUEST['id'];
959 $rawtext = str_replace ('\r', '', $_REQUEST['rawtext']);
960 $ngood = $nbad = 0;
961 $rsconfig = '';
962 // Keep in mind, that the text will have HTML entities (namely '>') escaped.
963 foreach (explode ('\n', $rawtext) as $line)
964 {
965 if (empty ($line))
966 continue;
967 $match = array ();
968 switch ($_REQUEST['format'])
969 {
970 case 'ipvs_2': // address and port only
971 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) /', $line, $match))
972 continue;
7e7a8387 973 if (addRStoRSPool ($pool_id, $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), ''))
732e4578
DO
974 $ngood++;
975 else
976 $nbad++;
977 break;
978 case 'ipvs_3': // address, port and weight
979 if (!preg_match ('/^ -&gt; ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match))
980 continue;
7e7a8387 981 if (addRStoRSPool ($pool_id, $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3]))
732e4578
DO
982 $ngood++;
983 else
984 $nbad++;
985 break;
986 default:
987 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&error=" . urlencode (__FUNCTION__ . ': invalid format requested');
988 break;
989 }
990 }
991 if ($nbad == 0 and $ngood > 0)
992 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&message=" . urlencode ("Successfully added ${ngood} real servers");
993 else
994 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&error=" . urlencode ("Added ${ngood} real servers and encountered ${nbad} errors");
995}
996
d6517a21
DO
997function addVService ()
998{
999 global $root, $pageno, $tabno;
1000
1001 assertIPv4Arg ('vip');
1002 assertUIntArg ('vport');
1003 assertStringArg ('proto');
1004 $proto = $_REQUEST['proto'];
1005 if ($proto != 'TCP' and $proto != 'UDP')
1006 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode (__FUNCTION__ . ': invalid protocol');
1007 assertStringArg ('name', TRUE);
1008 assertStringArg ('vsconfig', TRUE);
1009 assertStringArg ('rsconfig', TRUE);
1010 $pool_id = $_REQUEST['id'];
1011 if (!commitCreateVS ($_REQUEST['vip'], $_REQUEST['vport'], $proto, $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
1012 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('commitCreateVS() failed');
ca461127 1013 else
d6517a21 1014 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Virtual service was successfully created");
fb1c4a54
DO
1015}
1016
1017function deleteRealServer ()
1018{
1019 global $root, $pageno, $tabno;
1020
1021 assertUIntArg ('pool_id');
1022 assertUIntArg ('id');
fb1c4a54 1023 $pool_id = $_REQUEST['pool_id'];
d6517a21
DO
1024 if (!commitDeleteRS ($_REQUEST['id']))
1025 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&error=" . urlencode ('commitDeleteRS() failed');
fb1c4a54 1026 else
d6517a21 1027 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&message=" . urlencode ("Real server was successfully deleted");
fb1c4a54
DO
1028}
1029
3241551e
DO
1030function deleteLoadBalancer ()
1031{
1032 global $root, $pageno, $tabno;
1033
1034 assertUIntArg ('object_id');
1035 assertUIntArg ('pool_id');
c4d85fd1 1036 assertUIntArg ('vs_id');
3241551e 1037 $pool_id = $_REQUEST['pool_id'];
c4d85fd1 1038 if (!commitDeleteLB ($_REQUEST['object_id'], $pool_id, $_REQUEST['vs_id']))
d6517a21
DO
1039 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&error=" . urlencode ('commitDeleteLB() failed');
1040 else
1041 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&message=" . urlencode ("Load balancer was successfully deleted");
1042}
1043
1044function deleteVService ()
1045{
1046 global $root, $pageno, $tabno;
1047
1048 assertUIntArg ('id');
1049 if (!commitDeleteVS ($_REQUEST['id']))
1050 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('commitDeleteVS() failed');
3241551e 1051 else
d6517a21 1052 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Virtual service was successfully deleted");
3241551e
DO
1053}
1054
fb1c4a54
DO
1055function updateRealServer ()
1056{
1057 global $root, $pageno, $tabno;
1058
1059 assertUIntArg ('id');
732e4578 1060 assertUIntArg ('rs_id');
d6517a21 1061 assertIPv4Arg ('rsip');
fb1c4a54
DO
1062 assertUIntArg ('rsport');
1063 assertStringArg ('rsconfig', TRUE);
3241551e 1064 // only necessary for generating next URL
732e4578
DO
1065 $pool_id = $_REQUEST['id'];
1066 if (!commitUpdateRS ($_REQUEST['rs_id'], $_REQUEST['rsip'], $_REQUEST['rsport'], $_REQUEST['rsconfig']))
d6517a21 1067 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&error=" . urlencode ('commitUpdateRS() failed');
fb1c4a54 1068 else
d6517a21 1069 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&message=" . urlencode ("Real server was successfully updated");
ca461127
DO
1070}
1071
c1ca768c 1072function updateLoadBalancer ()
3241551e
DO
1073{
1074 global $root, $pageno, $tabno;
1075
1076 assertUIntArg ('object_id');
1077 assertUIntArg ('pool_id');
c1ca768c 1078 assertUIntArg ('vs_id');
3241551e
DO
1079 assertStringArg ('vsconfig', TRUE);
1080 assertStringArg ('rsconfig', TRUE);
1081 $pool_id = $_REQUEST['pool_id'];
c1ca768c 1082 if (!commitUpdateLB ($_REQUEST['object_id'], $pool_id, $_REQUEST['vs_id'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
d6517a21
DO
1083 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&error=" . urlencode ('commitUpdateLB() failed');
1084 else
28928596 1085 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&message=" . urlencode ("Load balancer info was successfully updated");
d6517a21
DO
1086}
1087
1088function updateVService ()
1089{
1090 global $root, $pageno, $tabno;
1091
1092 assertUIntArg ('id');
1093 assertIPv4Arg ('vip');
1094 assertUIntArg ('vport');
1095 assertStringArg ('proto');
1096 assertStringArg ('name', TRUE);
1097 assertStringArg ('vsconfig', TRUE);
1098 assertStringArg ('rsconfig', TRUE);
1099 if (!commitUpdateVS ($_REQUEST['id'], $_REQUEST['vip'], $_REQUEST['vport'], $_REQUEST['proto'], $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
1100 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('commitUpdateVS() failed');
3241551e 1101 else
d6517a21 1102 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Virtual service was successfully updated");
3241551e
DO
1103}
1104
1105function addLoadBalancer ()
1106{
1107 global $root, $pageno, $tabno;
1108
1109 assertUIntArg ('pool_id');
1110 assertUIntArg ('object_id');
c1ca768c 1111 assertUIntArg ('vs_id');
3241551e
DO
1112 assertStringArg ('vsconfig', TRUE);
1113 assertStringArg ('rsconfig', TRUE);
1114 $pool_id = $_REQUEST['pool_id'];
c1ca768c 1115 if (!addLBtoRSPool ($pool_id, $_REQUEST['object_id'], $_REQUEST['vs_id'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
d6517a21 1116 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&error=" . urlencode ('addLBtoRSPool() failed');
3241551e 1117 else
d6517a21 1118 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&message=" . urlencode ("Load balancer was successfully added");
3241551e
DO
1119}
1120
5ad76f01
DO
1121function addRSPool ()
1122{
1123 global $root, $pageno, $tabno;
1124
5ad76f01
DO
1125 assertStringArg ('name', TRUE);
1126 assertStringArg ('vsconfig', TRUE);
1127 assertStringArg ('rsconfig', TRUE);
70c24883 1128 if (!commitCreateRSPool ($_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
5ad76f01
DO
1129 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('commitCreateRSPool() failed');
1130 else
1131 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Real server pool was successfully created");
1132}
1133
1134function deleteRSPool ()
1135{
1136 global $root, $pageno, $tabno;
1137
1138 assertUIntArg ('id');
1139 if (!commitDeleteRSPool ($_REQUEST['id']))
1140 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('commitDeleteRSPool() failed');
1141 else
1142 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Real server pool was successfully deleted");
1143}
1144
1145function updateRSPool ()
1146{
1147 global $root, $pageno, $tabno;
1148
1149 assertUIntArg ('id');
1150 assertStringArg ('name', TRUE);
1151 assertStringArg ('vsconfig', TRUE);
1152 assertStringArg ('rsconfig', TRUE);
1153 if (!commitUpdateRSPool ($_REQUEST['id'], $_REQUEST['name'], $_REQUEST['vsconfig'], $_REQUEST['rsconfig']))
1154 return "${root}?page=${pageno}&tab=${tabno}&error=" . urlencode ('commitUpdateRSPool() failed');
1155 else
1156 return "${root}?page=${pageno}&tab=${tabno}&message=" . urlencode ("Real server pool was successfully updated");
1157}
1158
1f7d18fa
DO
1159function updateRSInService ()
1160{
1161 global $root, $pageno, $tabno;
1162 assertUIntArg ('id');
1163 assertUIntArg ('rscount');
1164 $pool_id = $_REQUEST['id'];
1165 $orig = getRSPoolInfo ($pool_id);
1166 $nbad = $ngood = 0;
1167 for ($i = 1; $i <= $_REQUEST['rscount']; $i++)
1168 {
1169 $rs_id = $_REQUEST["rsid_${i}"];
1170 if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on')
1171 $newval = 'yes';
1172 else
1173 $newval = 'no';
1174 if ($newval != $orig['rslist'][$rs_id]['inservice'])
1175 {
1176 if (commitSetInService ($rs_id, $newval))
1177 $ngood++;
1178 else
1179 $nbad++;
1180 }
1181 }
1182 if (!$nbad)
1183 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&message=" . urlencode ($ngood . " real server(s) were successfully (de)activated");
1184 else
1185 return "${root}?page=${pageno}&tab=${tabno}&id=${pool_id}&error=" . urlencode ("Encountered ${nbad} errors, (de)activated ${ngood} real servers");
1186}
1187
03eb5209
DO
1188function importPTRData ()
1189{
1190 global $root, $pageno, $tabno;
1191 assertUIntArg ('id');
1192 assertUIntArg ('addrcount');
1193 $nbad = $ngood = 0;
1194 $id = $_REQUEST['id'];
1195 for ($i = 0; $i < $_REQUEST['addrcount']; $i++)
1196 {
3f3bd41e 1197 $inputname = "import_${i}";
03eb5209
DO
1198 if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on')
1199 continue;
1200 assertIPv4Arg ("addr_${i}");
75aa085b
DO
1201 assertStringArg ("descr_${i}", TRUE);
1202 assertStringArg ("rsvd_${i}");
3f3bd41e
DO
1203 // Non-existent addresses will not have this argument set in request.
1204 $rsvd = 'no';
03eb5209
DO
1205 if ($_REQUEST["rsvd_${i}"] == 'yes')
1206 $rsvd = 'yes';
3f3bd41e 1207 if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '')
03eb5209
DO
1208 $ngood++;
1209 else
1210 $nbad++;
1211 }
1212 if (!$nbad)
0aa8633e 1213 return "${root}?page=${pageno}&tab=${tabno}&id=${id}&message=" . urlencode ($ngood . " IP address(es) were successfully updated");
03eb5209 1214 else
0aa8633e 1215 return "${root}?page=${pageno}&tab=${tabno}&id=${id}&error=" . urlencode ("Encountered ${nbad} errors, updated ${ngood} IP address(es)");
03eb5209
DO
1216}
1217
e673ee24 1218?>