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