]> git.datanom.net - qtadmin.git/blob - wblist.php
More functions for wblist page
[qtadmin.git] / wblist.php
1 <?php
2 /* vim: set ts=4 tw=0 sw=4 noet: */
3 require_once 'config.php';
4 require_once $CFG->root . 'lib/utils.inc.php';
5
6 function createHeader($data) {
7 $out = '<th>Id</th>';
8 foreach ($data as $head => $value) {
9 $out .= "<th>$head</th>";
10 }
11
12 return $out;
13 }
14
15 function parseResponse($raw) {
16 if (count($raw) < 1) {
17 return '';
18 }
19 $headers = createHeader($raw[0]);
20 $r = "<table><tr>$headers</tr>";
21 $i = 1;
22 foreach ($raw as $obj) {
23 $r .= "<tr><td>$i</td>";
24 foreach ($obj as $value) {
25 $r .= "<td>$value</td>";
26 }
27 $r .= '</tr>';
28 $i++;
29 }
30 $r .= '</table>';
31
32 return $r;
33 }
34
35 $util = new Utils;
36
37 if ($util->isLoggedIn()) {
38 $function = isset($_GET['p']) ? $_GET['p'] : null;
39 $subfunction = isset($_GET['s']) ? $_GET['s'] : null;
40 if (($function && $function == 'show' && !$subfunction) ||
41 ($function && $function == 'add' && $subfunction) ||
42 ($function && $function == 'del' && $subfunction)) {
43 header('Location: index.php');
44 } else if($function == 'show') {
45 if ($subfunction == 'all') {
46 if ($util->isAdmin()) {
47 $method = '/show';
48 } else {
49 $method = '/show/' . $util->getUser();
50 }
51 $list = $util->makeRestCall($method);
52 if ($list) {
53 $out = parseResponse($list);
54 } else {
55 $out = '<p>Connection to REST service failed</p>';
56 }
57 } else if ($subfunction == 'blacklist') {
58 if ($util->isAdmin()) {
59 $method = '/show/blacklist';
60 } else {
61 $method = '/show/blacklist' . $util->getUser();
62 }
63 $list = $util->makeRestCall($method);
64 if ($list) {
65 $out = parseResponse($list);
66 } else {
67 $out = '<p>Connection to REST service failed</p>';
68 }
69 } else if ($subfunction == 'whitelist') {
70 if ($util->isAdmin()) {
71 $method = '/show/whitelist';
72 } else {
73 $method = '/show/whitelist' . $util->getUser();
74 }
75 $list = $util->makeRestCall($method);
76 if ($list) {
77 $out = parseResponse($list);
78 } else {
79 $out = '<p>Connection to REST service failed</p>';
80 }
81 } else {
82 header('Location: index.php');
83 }
84 } else if($function == 'add') {
85 } else if($function == 'del') {
86 } else {
87 header('Location: index.php');
88 }
89 $util->setHeading('WB List and Quarantine Administration');
90 echo $util->getHeader();
91 echo $util->getHeading();
92 echo $out;
93 echo $util->getFooter();
94 } else {
95 header('Location: auth.php');
96 }
97 ?>
This page took 0.123569 seconds and 6 git commands to generate.