Subversion Repositories oidplus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
226 daniel-mar 1
<?php
2
 
3
include_once __DIR__ . '/includes/oid_plus.inc.php';
4
include_once __DIR__ . '/includes/oid_utils.inc.php';
5
include_once __DIR__ . '/includes/config.inc.php';
6
include_once __DIR__ . '/includes/gui.inc.php';
7
 
8
define('START_PAGE', 'welcome');
9
 
10
$db = new OIDPlus(__DIR__ . '/db/local.conf', true);
11
 
12
// The inclusion of get_current_user() solves a Problem with suPHP, when multiple users run different instances of OID+ with the same SystemID
13
session_name('OIDPLUS_SESS_'.sha1(strtolower($db->getSystemID()).get_current_user()));
14
session_start();
15
 
16
$title = $db->getConfigValue('webinterface_title');
17
if ($title === false) $title = 'OID+ web interface';
18
 
19
$systemID = $db->getConfigValue('system_unique_id');
20
 
21
try {
22
        $db->addDir(__DIR__ . '/db');
23
        echo page_header($title, $systemID); // TODO: dynamischer titel, z.B. die aktuell angezeigte OID
24
} catch (VolcanoException $e) {
25
        echo showException($e);
26
        exit;
27
}
28
 
29
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : START_PAGE;
30
$query  = isset($_REQUEST['query'])  ? $_REQUEST['query']  : '';
31
 
32
# ---
33
 
34
if (isset($_REQUEST['new_auth_token'])) {
35
        if (!isset($_SESSION['auth_tokens'])) {
36
                $_SESSION['auth_tokens'] = array();
37
        }
38
        if (!in_array($_REQUEST['new_auth_token'], $_SESSION['auth_tokens'])) {
39
                $_SESSION['auth_tokens'][] = $_REQUEST['new_auth_token'];
40
        }
41
} else if (isset($_REQUEST['delete_all_auth_tokens'])) {
42
        unset($_SESSION['auth_tokens']);
43
}
44
 
45
if (isset($_SESSION['auth_tokens'])) {
46
        $auth_tokens = ' #'.implode(',',$_SESSION['auth_tokens']);
47
} else {
48
        $auth_tokens = '';
49
}
50
 
51
$auth_token_count = (isset($_SESSION['auth_tokens'])) ? count($_SESSION['auth_tokens']) : 0;
52
 
53
# TODO: auth tokens schreiben bei allen "executed query" usw?
54
 
55
# ---
56
 
57
echo '<form action="index.php" method="get">';
58
echo '<table border="0" cellpadding="5" cellspacing="0" width="100%" id="headertable">';
59
 
60
echo '<tr>';
61
echo '<td colspan="2" align="center">';
62
        echo '<h1>'.htmlentities($title).'</h1>';
63
echo '</td>';
64
echo '</tr>';
65
 
66
echo '<tr>';
67
echo '<td>';
68
        if ($action != 'welcome') echo '<a href="?action=welcome">'; else echo '<b>';
69
        echo 'Welcome';
70
        if ($action != 'welcome') echo '</a>'; else echo '</b>';
71
        echo ' | ';
72
 
73
        if ($action != 'roots') echo '<a href="?action=roots">'; else echo '<b>';
74
        echo 'Roots';
75
        if ($action != 'roots') echo '</a>'; else echo '</b>';
76
        echo ' (' . $db->count_roots() . ')';
77
        echo ' | ';
78
 
79
        if ($action != 'indexes') echo '<a href="?action=indexes">'; else echo '<b>';
80
        echo 'Indexes';
81
        if ($action != 'indexes') echo '</a>'; else echo '</b>';
82
        echo ' (' . $db->count_indexes() . ')';
83
        echo ' | ';
84
 
85
        if ($action != 'list_all') echo '<a href="?action=list_all">'; else echo '<b>';
86
        echo 'List all';
87
        if ($action != 'list_all') echo '</a>'; else echo '</b>';
88
        echo ' (' . $db->count_oids() . ')';
89
        echo ' | ';
90
 
91
        if ($action != 'auth_tokens') echo '<a href="?action=auth_tokens">'; else echo '<b>';
92
        echo 'Auth tokens';
93
        if ($action != 'auth_tokens') echo '</a>'; else echo '</b>';
94
        echo ' ('.$auth_token_count.')';
95
echo '</td>';
96
echo '<td align="right">';
97
        echo '<input type="hidden" name="action" value="query" />';
98
 
99
        if ($action == 'roots') {
100
                $query = 'oidplus:!listRoots';
101
        } else if ($action == 'indexes') {
102
                $query = 'oidplus:!listIndexes';
103
        } else if ($action == 'list_all') {
104
                $query = 'oidplus:!list';
105
        } else if ($action == 'help') {
106
                $query = 'help';
107
        } else if ($action == 'show_oid') {
108
                if (isset($_REQUEST['oid'])) {
109
                        $query = 'oidplus:'.$_REQUEST['oid'];
110
                } else {
111
                        die('</td></tr></table><h2>Invalid request</h2><p>Paramter "oid" is missing</p>'.page_footer());
112
                }
113
        } else if ($action == 'show_index') {
114
                if ($_REQUEST['index']) {
115
                        if (isset($_REQUEST['ns'])) {
116
                                $query = $_REQUEST['ns'].':'.$_REQUEST['index'];
117
                        } else {
118
                                $query = 'oidplus:'.$_REQUEST['index'];
119
                        }
120
                } else {
121
                        die('</td></tr></table><h2>Invalid request</h2><p>Paramter "index" is missing</p>'.page_footer());
122
                }
123
        }
124
 
125
        echo 'Manual query (<a href="?action=help">help</a>): <input size="50" type="text" name="query" value="'.htmlentities($query).'" />'."\n";
126
        echo '<input type="submit" value="OK" />';
127
echo '</td>';
128
echo '</tr>';
129
echo '</table>';
130
echo '</form>';
131
 
132
# ---
133
 
134
try {
135
        # TODO: codeduplikate vermeiden
136
        if ($action == 'welcome') {
137
                # TODO
138
                include 'welcome.php';
139
        } else if ($action == 'uuid_info') {
140
                $uuid = $_REQUEST['uuid'];
141
 
142
                if (!preg_match('@^([A-Fa-f0-9]{8}\\-[A-Fa-f0-9]{4}\\-[A-Fa-f0-9]{4}\\-[A-Fa-f0-9]{4}\\-[A-Fa-f0-9]{12})$@', $uuid, $m)) {
143
                        echo "\n\n<h2>Information about an UUID</h2>\n\n";
144
 
145
                        echo '<p><font color="red">';
146
                        echo 'Error: '.htmlentities($uuid).' is not a valid UUID.';
147
                        echo '</font></p>';
148
                } else {
149
                        echo "\n\n<h2>Information about UUID $uuid</h2>\n\n";
150
 
151
                        $url = 'https://misc.daniel-marschall.de/tools/uuid_mac_decoder/interprete_uuid.php?uuid='.$uuid;
152
 
153
                        echo '<p class="green">Querying <a href="'.$url.'" target="_blank">'.htmlentities($url).'</a></p>';
154
 
155
                        $c = @file_get_contents($url);
156
 
157
                        if (preg_match('@<pre>(.*)</pre>@ismU', $c, $m)) {
158
                                echo showHTML($m[1], $db);
159
                        } else {
160
                                echo '<p><font color="red">';
161
                                echo 'Error while parsing <a href="'.$url.'" target="_blank">'.htmlentities($url).'</a>';
162
                                echo '</font></p>';
163
                        }
164
                }
165
 
166
                $query = '.'.uuid_to_oid($uuid);
167
                if ($db->oidDescribed($query)) {
168
                        echo "\n\n<h2>Information about UUID OID ".htmlentities($query)."</h2>\n\n";
169
                        echo queryInfo($query);
170
                        ob_start();
171
                        $db->query($query.$auth_tokens);
172
                        $cont = ob_get_contents();
173
                        ob_end_clean();
174
                        echo showHTML($cont, $db);
175
                }
176
 
177
                # Alle OIDs durchgehen und schauen, ob namebased irgendwo passt
178
                $x = $db->listAllOIDs('.');
179
                foreach ($x as $oid) {
180
                        $query = $oid;
181
                        if (gen_uuid_md5_namebased(UUID_NAMEBASED_NS_OID, $oid) == $uuid) {
182
                                echo "\n\n<h2>Information about ".htmlentities($query)." (MD5 namebased UUID)</h2>\n\n";
183
                                echo queryInfo($query);
184
                                ob_start();
185
                                $db->query($query.$auth_tokens);
186
                                $cont = ob_get_contents();
187
                                ob_end_clean();
188
                                echo showHTML($cont, $db);
189
                        }
190
                        if (gen_uuid_sha1_namebased(UUID_NAMEBASED_NS_OID, $oid) == $uuid) {
191
                                echo "\n\n<h2>Information about ".htmlentities($query)." (SHA1 namebased UUID)</h2>\n\n";
192
                                echo queryInfo($query);
193
                                ob_start();
194
                                $db->query($query.$auth_tokens);
195
                                $cont = ob_get_contents();
196
                                ob_end_clean();
197
                                echo showHTML($cont, $db);
198
                        }
199
                }
200
        } else if ($action == 'roots') {
201
                echo "\n\n<h2>Roots</h2>\n\n";
202
                echo queryInfo($query);
203
                $r = $db->findRoots();
204
                foreach ($r as $root) {
205
                        echo "\n\n<h2>Root $root</h2>\n\n";
206
                        echo queryInfo("oidplus:$root");
207
                        ob_start();
208
                        $db->query('oidplus:'.$root.$auth_tokens);
209
                        $cont = ob_get_contents();
210
                        ob_end_clean();
211
                        echo showHTML($cont, $db);
212
                }
213
        } else if ($action == 'indexes') {
214
                echo "\n\n<h2>Indexes</h2>\n\n";
215
                echo queryInfo($query);
216
                ob_start();
217
                $db->query($query.$auth_tokens);
218
                $cont = ob_get_contents();
219
                ob_end_clean();
220
                echo showHTML($cont, $db);
221
        } else if ($action == 'list_all') {
222
                echo "\n\n<h2>List all</h2>\n\n";
223
                echo queryInfo($query);
224
                ob_start();
225
                $db->query($query.$auth_tokens);
226
                $cont = ob_get_contents();
227
                ob_end_clean();
228
                echo showHTML($cont, $db);
229
        } else if ($action == 'help') {
230
                echo "\n\n<h2>Help</h2>\n\n";
231
                echo queryInfo($query);
232
                ob_start();
233
                $db->query($query.$auth_tokens);
234
                $cont = ob_get_contents();
235
                ob_end_clean();
236
                echo showHTML($cont, $db);
237
        } else if ($action == 'show_oid') {
238
                echo "\n\n<h2>OID ".htmlentities($_REQUEST['oid'])."</h2>\n\n";
239
                echo queryInfo($query);
240
                ob_start();
241
                $db->query($query.$auth_tokens);
242
                $cont = ob_get_contents();
243
                ob_end_clean();
244
                echo showHTML($cont, $db);
245
        } else if ($action == 'show_index') {
246
                echo "\n\n<h2>Index ".htmlentities($_REQUEST['index'])."</h2>\n\n";
247
                echo queryInfo($query);
248
                ob_start();
249
                $db->query($query.$auth_tokens);
250
                $cont = ob_get_contents();
251
                ob_end_clean();
252
                echo showHTML($cont, $db);
253
        } else if ($action == 'query') {
254
                echo "\n\n<h2>Query ".htmlentities($query)."</h2>\n\n";
255
                echo queryInfo($query);
256
                ob_start();
257
                $db->query($query.$auth_tokens);
258
                $cont = ob_get_contents();
259
                ob_end_clean();
260
                echo showHTML($cont, $db);
261
        } else if ($action == 'auth_tokens') {
262
                echo "\n\n<h2>Auth tokens</h2>\n\n";
263
 
264
                echo '<form action="index.php" method="get">';
265
                echo '<input type="hidden" name="action" value="'.htmlentities($action).'" />';
266
 
267
                if ($auth_token_count == 0) {
268
                        echo "<p>No auth tokens have been added.</p>";
269
                } else {
270
                        echo "<p><font color=\"red\">Registered auth tokens: $auth_token_count</font></p>";
271
                }
272
 
273
                echo '<p>Add new auth token: <input type="password" name="new_auth_token" value="" />'."\n";
274
                echo '<input type="submit" value="Add"></p>';
275
 
276
                echo '<p><a href="?action='.htmlentities($action).'&amp;delete_all_auth_tokens=1">Delete all tokens</a></p>';
277
 
278
                echo '</form>';
279
        } else {
280
                echo '<p><font color="red">';
281
                echo 'Unknown command "'.htmlentities($action).'"';
282
                echo '</font></p>';
283
        }
284
} catch (VolcanoException $e) {
285
        echo showException($e);
286
        exit;
287
}
288
 
289
# ---
290
 
291
session_write_close();
292
echo page_footer();