Subversion Repositories oidplus

Rev

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