r4178 bugfix: PHP warnings were appearing before rackspace on SLB object page, defaul...
[racktables] / ajax.php
1 <?php
2 ob_start();
3 try {
4
5 require 'inc/init.php';
6 require_once 'inc/ajax-interface.php';
7 assertStringArg ('ac');
8
9 switch ($_REQUEST['ac'])
10 {
11 case 'verifyCode':
12 $pageno = 'perms';
13 $tabno = 'edit';
14 fixContext();
15 if (!permitted())
16 {
17 echo "NAK\nPermission denied";
18 exit();
19 }
20 assertStringArg ('code');
21 $result = getRackCode (dos2unix ($_REQUEST['code']));
22 if ($result['result'] == 'ACK')
23 echo "ACK\n";
24 else
25 echo "NAK\n" . $result['load'];
26 break;
27 case 'get-port-link': // returns JSON-encoded text
28 assertUIntArg ('object_id');
29 $object = spotEntity ('object', $_REQUEST['object_id']);
30 fixContext ($object);
31 if (! permitted ('object', 'liveports', 'get_link_status'))
32 throw new RacktablesError ('Permission denied: $op_get_link_status check failed');
33 $data = formatPortLinkHints ($_REQUEST['object_id']);
34 echo json_encode ($data);
35 break;
36 case 'get-port-mac': // returns JSON-encoded text
37 assertUIntArg ('object_id');
38 $object = spotEntity ('object', $_REQUEST['object_id']);
39 fixContext ($object);
40 if (! permitted ('object', 'liveports', 'get_mac_list'))
41 throw new RacktablesError ('Permission denied: $op_get_mac_list check failed');
42 $data = formatPortMacHints ($_REQUEST['object_id']);
43 echo json_encode ($data);
44 break;
45 case 'get-port-conf': // returns JSON-encoded text
46 assertUIntArg ('object_id');
47 $object = spotEntity ('object', $_REQUEST['object_id']);
48 fixContext ($object);
49 if (! permitted ('object', 'liveports', 'get_port_conf'))
50 throw new RacktablesError ('Permission denied: $op_get_port_conf check failed');
51 $data = formatPortConfigHints ($_REQUEST['object_id']);
52 echo json_encode ($data);
53 break;
54 default:
55 throw new InvalidRequestArgException ('ac', $_REQUEST['ac']);
56 }
57 ob_end_flush();
58 }
59 catch (InvalidRequestArgException $e)
60 {
61 ob_end_clean();
62 echo "NAK\nMalformed request";
63 }
64 catch (Exception $e)
65 {
66 ob_end_clean();
67 echo "NAK\nRuntime exception: ". $e->getMessage();
68 }
69
70 ?>