r4073 minor change in UI for recent change: VST form commit on ENTER and hints on...
[racktables] / ajax.php
CommitLineData
11048491 1<?php
90a3d6d8
DY
2ob_start();
3try {
11048491 4
da111736 5require 'inc/init.php';
65e557dd 6require_once 'inc/ajax-interface.php';
ef0503fc 7assertStringArg ('ac');
11048491 8
1dcdcc47 9switch ($_REQUEST['ac'])
11048491 10{
ef0503fc
DO
11case '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'];
11048491 26 break;
65e557dd
AA
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;
ef0503fc
DO
54default:
55 throw new InvalidRequestArgException ('ac', $_REQUEST['ac']);
11048491 56}
90a3d6d8
DY
57ob_end_flush();
58}
ef0503fc
DO
59catch (InvalidRequestArgException $e)
60{
61 ob_end_clean();
62 echo "NAK\nMalformed request";
63}
90a3d6d8
DY
64catch (Exception $e)
65{
66 ob_end_clean();
65e557dd 67 echo "NAK\nRuntime exception: ". $e->getMessage();
90a3d6d8 68}
11048491 69
11048491 70?>