Subversion Repositories oidplus

Rev

Rev 52 | Rev 71 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
5
 * Copyright 2019 Daniel Marschall, ViaThinkSoft
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 *     http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 */
19
 
20
class OIDplusGui {
21
 
22
        private static $crudCounter = 0;
23
 
24
        protected static function objDescription($html) {
25
                // We allow HTML, but no hacking
12 daniel-mar 26
                $html = anti_xss($html);
11 daniel-mar 27
 
28
                return trim_br($html);
2 daniel-mar 29
        }
30
 
31
        protected static function showRAInfo($email) {
32
                $out = '';
33
 
52 daniel-mar 34
                if (empty($email)) {
35
                        $out = '<p>The superior RA did not define a RA for this OID.</p>';
36
                        return $out;
37
                }
38
 
2 daniel-mar 39
                $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = '".OIDplus::db()->real_escape_string($email)."'");
40
                if (OIDplus::db()->num_rows($res) === 0) {
41
                        $out = '<p>The RA <a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a> is not registered in the database.</p>';
42
 
43
                } else {
44
                        $row = OIDplus::db()->fetch_array($res);
45
                        $out = '<b>'.htmlentities($row['ra_name']).'</b><br>';
46
                        $out .= 'E-Mail: <a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a><br>';
47
                        if (trim($row['personal_name']) !== '') $out .= htmlentities($row['personal_name']).'<br>';
48
                        if (trim($row['organization']) !== '') $out .= htmlentities($row['organization']).'<br>';
49
                        if (trim($row['office']) !== '') $out .= htmlentities($row['office']).'<br>';
50
                        if ($row['privacy']) {
51
                                // TODO: meldung nur anzeigen, wenn benutzer überhaupt straße, adresse etc hat
52
                                // TODO: aber der admin soll es sehen, und der user selbst (mit anmerkung, dass es privat ist)
53
                                $out .= '<p>The RA does not want to publish their personal information.</p>';
54
                        } else {
55
                                if (trim($row['street']) !== '') $out .= htmlentities($row['street']).'<br>';
56
                                if (trim($row['zip_town']) !== '') $out .= htmlentities($row['zip_town']).'<br>';
57
                                if (trim($row['country']) !== '') $out .= htmlentities($row['country']).'<br>';
58
                                $out .= '<br>';
59
                                if (trim($row['phone']) !== '') $out .= htmlentities($row['phone']).'<br>';
60
                                if (trim($row['fax']) !== '') $out .= htmlentities($row['fax']).'<br>';
61
                                if (trim($row['mobile']) !== '') $out .= htmlentities($row['mobile']).'<br>';
62
                                $out .= '<br>';
63
                        }
64
                }
65
 
11 daniel-mar 66
                return trim_br($out);
2 daniel-mar 67
        }
68
 
69
        protected static function showCrud($parent='oid:') {
70
                $items_total = 0;
71
                $items_hidden = 0;
72
 
73
                $objParent = OIDplusObject::parse($parent);
74
 
75
                $output = '';
76
                if (!$objParent->userHasWriteRights()) {
77
                        // TODO: wir sollten eigentlich bei noscript die buttons und edits ausblenden
78
                        $output .= '<noscript><b>Please enable JavaScript to edit the subsequent OIDs.</b></noscript>';
79
                }
80
                $output .= '<div class="container box"><div id="suboid_table" class="table-responsive">';
81
                $output .= '<table class="table table-bordered table-striped">';
82
                $output .= '    <tr>';
83
                $output .= '         <th>ID'.(($objParent::ns() == 'gs1') ? ' (without check digit)' : '').'</th>';
84
                if ($objParent::ns() == 'oid') $output .= '          <th>ASN.1 IDs (comma sep.)</th>';
85
                if ($objParent::ns() == 'oid') $output .= '          <th>IRI IDs (comma sep.)</th>';
86
                $output .= '         <th>RA</th>';
87
                if ($objParent->userHasWriteRights()) {
88
                        $output .= '         <th>Hide</th>';
89
                        $output .= '         <th>Update</th>';
90
                        $output .= '         <th>Delete</th>';
91
                }
92
                $output .= '         <th>Created</th>';
93
                $output .= '         <th>Updated</th>';
94
                $output .= '    </tr>';
95
 
96
                $result = OIDplus::db()->query("select o.*, r.ra_name from ".OIDPLUS_TABLENAME_PREFIX."objects o left join ".OIDPLUS_TABLENAME_PREFIX."ra r on r.email = o.ra_email where parent = '".OIDplus::db()->real_escape_string($parent)."' order by ".OIDplus::db()->natOrder('id'));
97
                while ($row = OIDplus::db()->fetch_object($result)) {
98
                        $obj = OIDplusObject::parse($row->id);
99
 
100
                        $items_total++;
101
                        if (!$obj->userHasReadRights()) {
102
                                $items_hidden++;
103
                                continue;
104
                        }
105
 
106
                        $show_id = $obj->crudShowId($objParent);
107
 
108
                        $asn1ids = array();
109
                        $res2 = OIDplus::db()->query("select name from ".OIDPLUS_TABLENAME_PREFIX."asn1id where oid = '".OIDplus::db()->real_escape_string($row->id)."' order by lfd");
110
                        while ($row2 = OIDplus::db()->fetch_array($res2)) {
111
                                $asn1ids[] = $row2['name'];
112
                        }
113
 
114
                        $iris = array();
115
                        $res2 = OIDplus::db()->query("select name from ".OIDPLUS_TABLENAME_PREFIX."iri where oid = '".OIDplus::db()->real_escape_string($row->id)."' order by lfd");
116
                        while ($row2 = OIDplus::db()->fetch_array($res2)) {
117
                                $iris[] = $row2['name'];
118
                        }
119
 
120
                        $output .= '<tr>';
5 daniel-mar 121
                        // TODO: if no scripts are allowed, we cannot open this link using openAndSelectNode()
122
                        $output .= '     <td><a href="#" onclick="return openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).')">'.htmlentities($show_id).'</a></td>';
2 daniel-mar 123
                        if ($objParent->userHasWriteRights()) {
5 daniel-mar 124
                                if ($obj::ns() == 'oid') {
125
                                        $output .= '     <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>';
126
                                        $output .= '     <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>';
127
                                }
2 daniel-mar 128
                                $output .= '     <td><input type="text" id="ra_email_'.$row->id.'" value="'.$row->ra_email.'"></td>';
129
                                $output .= '     <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>';
130
                                $output .= '     <td><button type="button" name="update_'.$row->id.'" id="update_'.$row->id.'" class="btn btn-success btn-xs update" onclick="javascript:crudActionUpdate('.js_escape($row->id).', '.js_escape($parent).')">Update</button></td>';
131
                                $output .= '     <td><button type="button" name="delete_'.$row->id.'" id="delete_'.$row->id.'" class="btn btn-danger btn-xs delete" onclick="javascript:crudActionDelete('.js_escape($row->id).', '.js_escape($parent).')">Delete</button></td>';
132
                                $output .= '     <td>'.oiddb_formatdate($row->created).'</td>';
133
                                $output .= '     <td>'.oiddb_formatdate($row->updated).'</td>';
134
                        } else {
135
                                if ($asn1ids == '') $asn1ids = '<i>(none)</i>';
136
                                if ($iris == '') $iris = '<i>(none)</i>';
5 daniel-mar 137
                                if ($obj::ns() == 'oid') {
138
                                        $asn1ids_ext = array();
139
                                        foreach ($asn1ids as $asn1id) {
140
                                                // TODO: if no scripts are allowed, we cannot open the rainfo: pages using openOidInPanel()
141
                                                $asn1ids_ext[] = '<a href="#" onclick="return openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).')">'.$asn1id.'</a>';
142
                                        }
143
                                        $output .= '     <td>'.implode(', ', $asn1ids_ext).'</td>';
144
                                        $output .= '     <td>'.implode(', ', $iris).'</td>';
145
                                }
146
                                // TODO: if no scripts are allowed, we cannot open the rainfo: pages using openOidInPanel()
147
                                $output .= '     <td><a href="#" onclick="return openOidInPanel('.js_escape('oidplus:rainfo$'.str_replace('@', "'+'@'+'", $row->ra_email)).', true)">'.htmlentities(empty($row->ra_name) ? str_replace('@','&',$row->ra_email) : $row->ra_name).'</a></td>';
2 daniel-mar 148
                                $output .= '     <td>'.oiddb_formatdate($row->created).'</td>';
149
                                $output .= '     <td>'.oiddb_formatdate($row->updated).'</td>';
150
                        }
151
                        $output .= '</tr>';
152
                }
153
 
154
                $result = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where id = '".OIDplus::db()->real_escape_string($parent)."'");
155
                $parent_ra_email = OIDplus::db()->num_rows($result) > 0 ? OIDplus::db()->fetch_object($result)->ra_email : '';
156
 
157
                if ($objParent->userHasWriteRights()) {
158
                        $output .= '<tr>';
159
                        $prefix = is_null($objParent) ? '' : $objParent->crudInsertPrefix();
160
                        if ($objParent::ns() == 'oid') {
161
                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:50px"></td>'; // TODO: idee classname vergeben, z.B. "OID" und dann mit einem oid-spezifischen css die breite einstellbar machen, somit hat das plugin mehr kontrolle über das aussehen und die mindestbreiten
162
                        } else {
163
                                $output .= '     <td>'.$prefix.' <input type="text" id="id" value=""></td>';
164
                        }
165
                        if ($objParent::ns() == 'oid') $output .= '     <td><input type="text" id="asn1ids" value=""></td>';
166
                        if ($objParent::ns() == 'oid') $output .= '     <td><input type="text" id="iris" value=""></td>';
167
                        $output .= '     <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email).'"></td>';
168
                        $output .= '     <td><input type="checkbox" id="hide"></td>';
169
                        $output .= '     <td><button type="button" name="insert" id="insert" class="btn btn-success btn-xs update" onclick="javascript:crudActionInsert('.js_escape($parent).')">Insert</button></td>';
170
                        $output .= '     <td></td>';
171
                        $output .= '     <td></td>';
172
                        $output .= '     <td></td>';
173
                        $output .= '</tr>';
174
                } else {
175
                        if ($items_total-$items_hidden == 0) {
176
                                $cols = ($objParent::ns() == 'oid') ? 7 : 5;
177
                                $output .= '<tr><td colspan="'.$cols.'">No items available</td></tr>';
178
                        }
179
                }
180
 
181
                $output .= '</table>';
182
                $output .= '</div></div>';
183
 
184
                if ($items_hidden == 1) {
185
                        $output .= '<p>'.$items_hidden.' item is hidden. Please <a href="?goto=oidplus:login">log in</a> to see it.</p>';
186
                } else if ($items_hidden > 1) {
187
                        $output .= '<p>'.$items_hidden.' items are hidden. Please <a href="?goto=oidplus:login">log in</a> to see them.</p>';
188
                }
189
 
190
                return $output;
191
        }
192
 
193
        public static $exclude_tinymce_plugins = array('fullpage', 'bbcode');
194
 
195
        protected static function showMCE($name, $content) {
196
                $mce_plugins = array();
4 daniel-mar 197
                foreach (glob(__DIR__ . '/../../3p/tinymce/plugins/*') as $m) { // */
2 daniel-mar 198
                        $mce_plugins[] = basename($m);
199
                }
200
 
201
                foreach (self::$exclude_tinymce_plugins as $exclude) {
202
                        $index = array_search($exclude, $mce_plugins);
203
                        if ($index !== false) unset($mce_plugins[$index]);
204
                }
205
 
4 daniel-mar 206
                $out = '<script>
207
                                tinymce.remove("#'.$name.'");
2 daniel-mar 208
                                tinymce.init({
4 daniel-mar 209
                                        selector: "#'.$name.'",
210
                                        height: 200,
211
                                        statusbar: false,
212
//                                      menubar:false,
213
//                                      toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect",
214
                                        toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect",
215
                                        plugins: "'.implode(' ', $mce_plugins).'"
2 daniel-mar 216
                                });
4 daniel-mar 217
                        </script>';
2 daniel-mar 218
 
4 daniel-mar 219
                $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>';
2 daniel-mar 220
 
221
                return $out;
222
        }
223
 
224
        public static function getInvitationText($email) {
225
                $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = '".OIDplus::db()->real_escape_string($email)."'");
226
                if (OIDplus::db()->num_rows($res) > 0) {
227
                        throw new Exception("This RA is already registered and does not need to be invited.");
228
                }
229
 
230
                if (!OIDplus::authUtils()::isAdminLoggedIn()) {
231
                        // Check if the RA may invite the user (i.e. the they are the parent of an OID of that person)
232
                        $ok = false;
233
                        $res = OIDplus::db()->query("select parent from ".OIDPLUS_TABLENAME_PREFIX."objects where ra_email = '".OIDplus::db()->real_escape_string($email)."'");
234
                        while ($row = OIDplus::db()->fetch_array($res)) {
235
                                $objParent = OIDplusObject::parse($row['parent']);
236
                                if (is_null($objParent)) throw new Exception("Type of ".$row['parent']." unknown");
237
                                if ($objParent->userHasWriteRights()) {
238
                                        $ok = true;
239
                                }
240
                        }
241
                        if (!$ok) {
242
                                throw new Exception('You may not invite this RA. Maybe you need to log in again.');
243
                        }
244
                }
245
 
246
                $list_of_oids = array();
247
                $res = OIDplus::db()->query("select id from ".OIDPLUS_TABLENAME_PREFIX."objects where ra_email = '".OIDplus::db()->real_escape_string($email)."'");
248
                while ($row = OIDplus::db()->fetch_array($res)) {
249
                        $list_of_oids[] = $row['id'];
250
                }
251
 
252
                $message = file_get_contents(__DIR__ . '/../invite_msg.tpl');
253
 
254
                // Resolve stuff
255
                $message = str_replace('{{SYSTEM_URL}}', OIDplus::system_url(), $message);
256
                $message = str_replace('{{OID_LIST}}', implode("\n", $list_of_oids), $message);
257
                $message = str_replace('{{ADMIN_EMAIL}}', OIDPLUS_ADMIN_EMAIL, $message);
258
                $message = str_replace('{{PARTY}}', OIDplus::authUtils()::isAdminLoggedIn() ? 'the system administrator' : 'a superior Registration Authority', $message);
259
 
260
                // {{ACTIVATE_URL}} will be resolved in action.php
261
 
262
                return $message;
263
        }
264
 
265
        public static function getForgotPasswordText($email) {
266
                $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = '".OIDplus::db()->real_escape_string($email)."'");
267
                if (OIDplus::db()->num_rows($res) == 0) {
268
                        throw new Exception("This RA does not exist.");
269
                }
270
 
271
                $message = file_get_contents(__DIR__ . '/../forgot_password.tpl');
272
 
273
                // Resolve stuff
274
                $message = str_replace('{{SYSTEM_URL}}', OIDplus::system_url(), $message);
275
                $message = str_replace('{{ADMIN_EMAIL}}', OIDPLUS_ADMIN_EMAIL, $message);
276
 
277
                // {{ACTIVATE_URL}} will be resolved in action.php
278
 
279
                return $message;
280
        }
281
 
282
        public static function generateContentPage($id) {
283
                $out = array();
284
 
285
                $handled = false;
286
                $out['title'] = '';
32 daniel-mar 287
                $out['icon'] = '';
2 daniel-mar 288
                $out['text'] = '';
289
 
290
                // === System ===
291
 
292
                if ($id === 'oidplus:system') {
293
                        $handled = true;
294
 
4 daniel-mar 295
                        $out['title'] = OIDplus::config()->systemTitle(); // 'Object Database of ' . $_SERVER['SERVER_NAME'];
32 daniel-mar 296
                        $out['icon'] = 'img/system_big.png';
2 daniel-mar 297
                        $out['text'] = file_get_contents('welcome.html');
298
                        return $out;
299
 
300
                // === Generic stuff ===
301
 
302
                } else if (explode('$',$id)[0] == 'oidplus:rainfo') {
303
                        $handled = true;
304
 
305
                        $ra_email = explode('$',$id)[1];
306
 
307
                        $out['title'] = 'Registration Authority Information'; // TODO: email addresse reinschreiben? aber wie vor anti spam schützen?
34 daniel-mar 308
                        $out['icon'] = 'img/rainfo_big.png';
2 daniel-mar 309
 
310
                        if (empty($ra_email)) {
311
                                $out['text'] = '<p>Following object roots have an undefined Registration Authority:</p>';
312
                        } else {
313
                                $out['text'] = self::showRAInfo($ra_email);
314
                        }
315
 
37 daniel-mar 316
                        $out['text'] .= '<br><br>';
317
 
2 daniel-mar 318
                        foreach (OIDplusObject::getRaRoots($ra_email) as $loc_root) {
5 daniel-mar 319
                                $ico = $loc_root->getIcon();
320
                                $icon = !is_null($ico) ? $ico : 'img/link.png';
2 daniel-mar 321
                                $out['text'] .= '<p><a href="?goto='.$loc_root->nodeId().'"><img src="'.$icon.'"> Jump to RA root '.$loc_root->objectTypeTitleShort().' '.$loc_root->crudShowId(OIDplusObject::parse($loc_root::root())).'</a></p>';
322
                        }
323
 
37 daniel-mar 324
                        if (OIDplus::authUtils()::isRALoggedIn($ra_email)) {
325
                                $out['text'] .= '<br><p><a href="?goto=oidplus:edit_ra$'.urlencode($ra_email).'">Edit contact info</a></p>';
326
                        }
2 daniel-mar 327
 
328
                        if (OIDplus::authUtils()::isAdminLoggedIn()) {
37 daniel-mar 329
                                $out['text'] .= '<br><p><a href="#" onclick="return deleteRa('.js_escape($ra_email).',null)">Delete this RA</a></p>';
2 daniel-mar 330
                        }
331
 
332
                // === Forgot password ===
333
 
334
                } else if (explode('$',$id)[0] == 'oidplus:forgot_password') {
335
                        $handled = true;
336
 
337
                        $out['title'] = 'Forgot password';
34 daniel-mar 338
                        $out['icon'] = 'img/forgot_password_big.png';
2 daniel-mar 339
 
340
                        try {
341
                                $out['text'] .= '<p>Please enter the email address of your account, and information about the password reset will be sent to you.</p>
342
                                  <form id="forgotPasswordForm" onsubmit="return forgotPasswordFormOnSubmit();">
343
                                    E-Mail: <input type="text" id="email" value=""/><br><br>'.
344
                                 (RECAPTCHA_ENABLED ? '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.RECAPTCHA_PUBLIC.'" }); </script>'.
345
                                                   '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.RECAPTCHA_PUBLIC.'"></div>' : '').
346
                                ' <br>
347
                                    <input type="submit" value="Send recovery information">
348
                                  </form>';
349
 
350
                        } catch (Exception $e) {
351
 
46 daniel-mar 352
                                $out['icon'] = 'img/error_big.png';
2 daniel-mar 353
                                $out['text'] = "Error: ".$e->getMessage();
354
 
355
                        }
356
                } else if (explode('$',$id)[0] == 'oidplus:reset_password') {
357
                        $handled = true;
358
 
6 daniel-mar 359
                        $email = explode('$',$id)[1];
360
                        $timestamp = explode('$',$id)[2];
361
                        $auth = explode('$',$id)[3];
2 daniel-mar 362
 
363
                        $out['title'] = 'Reset password';
34 daniel-mar 364
                        $out['icon'] = 'img/reset_password_big.png';
2 daniel-mar 365
 
6 daniel-mar 366
                        if (!OIDplus::authUtils()::validateAuthKey('reset_password;'.$email.';'.$timestamp, $auth)) {
46 daniel-mar 367
                                $out['icon'] = 'img/error_big.png';
6 daniel-mar 368
                                $out['text'] = 'Invalid authorization. Is the URL OK?';
369
                        } else {
2 daniel-mar 370
                                $out['text'] = '<p>E-Mail-Adress: <b>'.$email.'</b></p>
371
 
372
                                  <form id="resetPasswordForm" onsubmit="return resetPasswordFormOnSubmit();">
373
                                    <input type="hidden" id="email" value="'.htmlentities($email).'"/>
374
                                    <input type="hidden" id="timestamp" value="'.htmlentities($timestamp).'"/>
375
                                    <input type="hidden" id="auth" value="'.htmlentities($auth).'"/>
43 daniel-mar 376
                                    <label class="padding_label">New password:</label><input type="password" id="password1" value=""/><br><br>
377
                                    <label class="padding_label">Again:</label><input type="password" id="password2" value=""/><br><br>
2 daniel-mar 378
                                    <input type="submit" value="Change password">
379
                                  </form>';
380
                        }
381
 
382
 
383
                // === Invite ===
384
 
385
                } else if (explode('$',$id)[0] == 'oidplus:invite_ra') {
386
                        $handled = true;
387
 
388
                        $email = explode('$',$id)[1];
389
                        $origin = explode('$',$id)[2];
390
 
391
                        $out['title'] = 'Invite a Registration Authority';
34 daniel-mar 392
                        $out['icon'] = 'img/invite_ra_big.png';
2 daniel-mar 393
 
394
                        try {
395
                                $cont = self::getInvitationText($email);
396
 
397
                                $out['text'] .= '<p>You have chosen to invite <b>'.$email.'</b> as an Registration Authority. If you click "Send", the following email will be sent to '.$email.':</p><p><i>'.nl2br(htmlentities($cont)).'</i></p>
398
                                  <form id="inviteForm" onsubmit="return inviteFormOnSubmit();">
399
                                    <input type="hidden" id="email" value="'.htmlentities($email).'"/>
400
                                    <input type="hidden" id="origin" value="'.htmlentities($origin).'"/>'.
401
                                 (RECAPTCHA_ENABLED ? '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.RECAPTCHA_PUBLIC.'" }); </script>'.
402
                                                   '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.RECAPTCHA_PUBLIC.'"></div>' : '').
403
                                ' <br>
404
                                    <input type="submit" value="Send invitation">
405
                                  </form>';
406
 
407
                        } catch (Exception $e) {
408
 
46 daniel-mar 409
                                $out['icon'] = 'img/error_big.png';
2 daniel-mar 410
                                $out['text'] = "Error: ".$e->getMessage();
411
 
412
                        }
413
                } else if (explode('$',$id)[0] == 'oidplus:activate_ra') {
414
                        $handled = true;
415
 
6 daniel-mar 416
                        $email = explode('$',$id)[1];
417
                        $timestamp = explode('$',$id)[2];
418
                        $auth = explode('$',$id)[3];
2 daniel-mar 419
 
420
                        $out['title'] = 'Register as Registration Authority';
34 daniel-mar 421
                        $out['icon'] = 'img/activate_ra_big.png';
2 daniel-mar 422
 
423
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = '".OIDplus::db()->real_escape_string($email)."'");
424
                        if (OIDplus::db()->num_rows($res) > 0) {
6 daniel-mar 425
                                $out['text'] = 'This RA is already registered and does not need to be invited.';
2 daniel-mar 426
                        } else {
6 daniel-mar 427
                                if (!OIDplus::authUtils()::validateAuthKey('activate_ra;'.$email.';'.$timestamp, $auth)) {
46 daniel-mar 428
                                        $out['icon'] = 'img/error_big.png';
6 daniel-mar 429
                                        $out['text'] = 'Invalid authorization. Is the URL OK?';
430
                                } else {
2 daniel-mar 431
                                        // TODO: like in the FreeOID plugin, we could ask here at least for a name for the RA
432
                                        $out['text'] = '<p>E-Mail-Adress: <b>'.$email.'</b></p>
433
 
434
                                          <form id="activateRaForm" onsubmit="return activateRaFormOnSubmit();">
435
                                            <input type="hidden" id="email" value="'.htmlentities($email).'"/>
436
                                            <input type="hidden" id="timestamp" value="'.htmlentities($timestamp).'"/>
437
                                            <input type="hidden" id="auth" value="'.htmlentities($auth).'"/>
43 daniel-mar 438
                                            <label class="padding_label">New password:</label><input type="password" id="password1" value=""/><br><br>
439
                                            <label class="padding_label">Again:</label><input type="password" id="password2" value=""/><br><br>
2 daniel-mar 440
                                            <input type="submit" value="Register">
441
                                          </form>';
442
                                }
443
                        }
444
 
445
                // === Login ===
446
 
447
                } else if ($id === 'oidplus:login') {
448
                        $handled = true;
449
                        $out['title'] = 'Login';
32 daniel-mar 450
                        $out['icon'] = 'img/login_big.png';
2 daniel-mar 451
 
452
                        $out['text'] .= '<script>function raLoginOnSubmit() {';
453
                        $out['text'] .= '       raLogin(document.getElementById("raLoginEMail").value, document.getElementById("raLoginPassword").value);';
454
                        $out['text'] .= '       return false;';
455
                        $out['text'] .= '}</script>';
456
 
457
                        $out['text'] .= (RECAPTCHA_ENABLED ? '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.RECAPTCHA_PUBLIC.'" }); </script>'.
10 daniel-mar 458
                                                          '<p>Before logging in, please solve the following CAPTCHA</p><div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.RECAPTCHA_PUBLIC.'"></div>' : '');
2 daniel-mar 459
 
10 daniel-mar 460
 
461
                        $out['text'] .= '<br>';
462
                        $out['text'] .= '<br>';
463
 
464
                        $out['text'] .= '<div id="loginTab" class="container" style="width:100%">';
465
                        $out['text'] .= '<ul  class="nav nav-pills">';
466
                        $out['text'] .= '                       <li class="active">';
467
                        $out['text'] .= '        <a  href="#1a" data-toggle="tab">Login as RA</a>';
468
                        $out['text'] .= '                       </li>';
16 daniel-mar 469
                        $out['text'] .= '                       <li><a href="#2a" data-toggle="tab">Login as administrator</a>';
10 daniel-mar 470
                        $out['text'] .= '                       </li>';
471
                        $out['text'] .= '               </ul>';
472
                        $out['text'] .= '                       <div class="tab-content clearfix">';
473
                        $out['text'] .= '                         <div class="tab-pane active" id="1a">';
474
 
2 daniel-mar 475
                        $out['text'] .= '<h2>Login as RA</h2>';
5 daniel-mar 476
 
477
                        $login_list = OIDplus::authUtils()->loggedInRaList();
478
                        if (count($login_list) > 0) {
479
                                foreach (OIDplus::authUtils()->loggedInRaList() as $x) {
480
                                        $out['text'] .= '<p>You are logged in as <b>'.$x.'</b> (<a href="#" onclick="return raLogout('.js_escape($x).');">Logout</a>)</p>';
481
                                }
482
                                $out['text'] .= '<p>If you have more accounts, you can log in with a new account:</p>';
483
                        } else {
484
                                $out['text'] .= '<p>Enter your email address and your password to log in as Registration Authority.</p>';
485
                        }
2 daniel-mar 486
                        $out['text'] .= '<form action="action.php" method="POST" onsubmit="return raLoginOnSubmit(this);">';
487
                        $out['text'] .= '<input type="hidden" name="action" value="ra_login">';
43 daniel-mar 488
                        $out['text'] .= '<label class="padding_label">E-Mail:</label><input type="text" name="email" value="" id="raLoginEMail"><br>';
489
                        $out['text'] .= '<label class="padding_label">Password:</label><input type="password" name="password" value="" id="raLoginPassword"><br><br>';
10 daniel-mar 490
                        $out['text'] .= '<input type="submit" value="Login"><br><br>';
2 daniel-mar 491
                        $out['text'] .= '</form>';
492
                        $out['text'] .= '<p><a href="?goto=oidplus:forgot_password">Forgot password?</a><br>';
493
                        $out['text'] .= '<abbr title="To receive login data, the superior RA needs to send you an invitation. After creating or updating your OID, the system will ask them if they want to send you an invitation. If they accept, you will receive an email with an activation link.">How to register?</abbr></p>';
494
                        $out['text'] .= '<script>function adminLoginOnSubmit() {';
495
                        $out['text'] .= '       adminLogin(document.getElementById("adminLoginPassword").value);';
496
                        $out['text'] .= '       return false;';
497
                        $out['text'] .= '}</script>';
498
 
10 daniel-mar 499
                        $out['text'] .= '                               </div>';
500
                        $out['text'] .= '                               <div class="tab-pane" id="2a">';
501
 
2 daniel-mar 502
                        if (OIDplus::authUtils()::isAdminLoggedIn()) {
503
                                $out['text'] .= '<h2>Admin login</h2>';
504
                                $out['text'] .= '<p>You are logged in as administrator.</p>';
5 daniel-mar 505
                                $out['text'] .= '<a href="#" onclick="return adminLogout();">Logout</a>';
2 daniel-mar 506
                        } else {
16 daniel-mar 507
                                $out['text'] .= '<h2>Login as administrator</h2>';
2 daniel-mar 508
                                $out['text'] .= '<form action="action.php" method="POST" onsubmit="return adminLoginOnSubmit(this);">';
509
                                $out['text'] .= '<input type="hidden" name="action" value="admin_login">';
43 daniel-mar 510
                                $out['text'] .= '<label class="padding_label">Password:</label><input type="password" name="password" value="" id="adminLoginPassword"><br><br>';
10 daniel-mar 511
                                $out['text'] .= '<input type="submit" value="Login"><br><br>';
2 daniel-mar 512
                                $out['text'] .= '</form>';
513
                                $out['text'] .= '<p><abbr title="Delete the file includes/config.inc.php and reload the page to start Setup again">Forgot password?</abbr></p>';
514
                        }
10 daniel-mar 515
 
516
                        $out['text'] .= '                               </div>';
517
                        $out['text'] .= '                       </div>';
518
                        $out['text'] .= '  </div>';
2 daniel-mar 519
                }
520
 
521
                // === Plugins ===
522
 
61 daniel-mar 523
                foreach (OIDplus::getPagePlugins('*') as $plugin) {
524
                        $plugin->gui($id, $out, $handled);
525
                }
2 daniel-mar 526
 
527
                // === Everything else (objects) ===
528
 
529
                if (!$handled) {
530
                        $obj = OIDplusObject::parse($id);
531
 
532
                        if ((!is_null($obj)) && (!$obj->userHasReadRights())) {
533
                                $out['title'] = 'Access denied';
34 daniel-mar 534
                                $out['icon'] = 'img/error_big.png';
2 daniel-mar 535
                                $out['text'] = '<p>Please <a href="?goto=oidplus:login">log in</a> to receive information about this object.</p>';
536
                                return $out;
537
                        }
538
 
539
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where id = '".OIDplus::db()->real_escape_string($id)."'");
540
                        $row = OIDplus::db()->fetch_array($res);
541
 
542
                        if (empty($row['title'])) {
543
                                $out['title'] = is_null($obj) ? $id : $obj->defaultTitle();
544
                        } else {
545
                                $out['title'] = $row['title'];
546
                        }
34 daniel-mar 547
                        $out['icon'] = 'img/object_big.png';
2 daniel-mar 548
 
549
                        if (isset($row['description'])) {
550
                                $desc = empty($row['description']) ? '<p><i>No description for this object available</i></p>' : OIDplusGui::objDescription($row['description']);
551
                                if ($obj->userHasWriteRights()) {
552
                                        $rand = ++self::$crudCounter;
553
                                        $desc = '<noscript><p><b>You need to enable JavaScript to edit title or description of this object.</b></p>'.$desc.'</noscript>';
554
                                        $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">';
555
                                        $desc .= 'Title: <input type="text" name="title" id="titleedit" value="'.htmlentities($row['title']).'"><br><br>Description:<br>';
556
                                        $desc .= self::showMCE('description', $row['description']);
557
                                        $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="javascript:updateDesc()">Update description</button>';
558
                                        $desc .= '</div>';
559
                                        $desc .= '<script>document.getElementById("descbox_'.$rand.'").style.display = "block";</script>';
560
                                }
561
                        } else {
562
                                $desc = '';
563
                        }
564
 
565
                        $matches_any_registered_type = false;
61 daniel-mar 566
                        foreach (OIDplus::getRegisteredObjectTypes() as $ot) {
2 daniel-mar 567
                                if ($obj = $ot::parse($id)) {
568
                                        $matches_any_registered_type = true;
569
                                        if ((OIDplus::db()->num_rows($res) == 0) && !$obj->isRoot()){
570
                                                http_response_code(404);
571
                                                $out['title'] = 'Object not found';
34 daniel-mar 572
                                                $out['icon'] = 'img/error_big.png';
2 daniel-mar 573
                                                $out['text'] = 'The object <code>'.htmlentities($id).'</code> was not found in this database.';
574
                                                return $out;
575
                                        } else {
34 daniel-mar 576
                                                $obj->getContentPage($out['title'], $out['text'], $out['icon']);
2 daniel-mar 577
                                        }
578
                                }
579
                        }
580
                        if (!$matches_any_registered_type) {
581
                                http_response_code(404);
582
                                $out['title'] = 'Object not found';
34 daniel-mar 583
                                $out['icon'] = 'img/error_big.png';
2 daniel-mar 584
                                $out['text'] = 'The object <code>'.htmlentities($id).'</code> was not found in this database.';
585
                                return $out;
586
                        }
587
 
21 daniel-mar 588
                        if (strpos($out['text'], '%%WHOIS%%') !== false)
589
                                $out['text'] = str_replace('%%WHOIS%%',   '<a href="whois/webwhois.php?query='.urlencode($id).'">Whois</a>', $out['text']);
2 daniel-mar 590
                        if (strpos($out['text'], '%%DESC%%') !== false)
591
                                $out['text'] = str_replace('%%DESC%%',    $desc,                              $out['text']);
592
                        if (strpos($out['text'], '%%CRUD%%') !== false)
593
                                $out['text'] = str_replace('%%CRUD%%',    self::showCrud($id),                $out['text']);
594
                        if (strpos($out['text'], '%%RA_INFO%%') !== false)
595
                                $out['text'] = str_replace('%%RA_INFO%%', self::showRaInfo($row['ra_email']), $out['text']);
596
                }
597
 
598
                return $out;
599
        }
600
 
601
}