Subversion Repositories oidplus

Rev

Rev 12 | Rev 21 | 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'] = '';
282
                $out['text'] = '';
283
 
284
                // === System ===
285
 
286
                if ($id === 'oidplus:system') {
287
                        $handled = true;
288
 
4 daniel-mar 289
                        $out['title'] = OIDplus::config()->systemTitle(); // 'Object Database of ' . $_SERVER['SERVER_NAME'];
2 daniel-mar 290
                        $out['text'] = file_get_contents('welcome.html');
291
                        return $out;
292
 
293
                // === Generic stuff ===
294
 
295
                } else if (explode('$',$id)[0] == 'oidplus:rainfo') {
296
                        $handled = true;
297
 
298
                        $ra_email = explode('$',$id)[1];
299
 
300
                        $out['title'] = 'Registration Authority Information'; // TODO: email addresse reinschreiben? aber wie vor anti spam schützen?
301
 
302
                        if (empty($ra_email)) {
303
                                $out['text'] = '<p>Following object roots have an undefined Registration Authority:</p>';
304
                        } else {
305
                                $out['text'] = self::showRAInfo($ra_email);
306
                        }
307
 
308
                        foreach (OIDplusObject::getRaRoots($ra_email) as $loc_root) {
5 daniel-mar 309
                                $ico = $loc_root->getIcon();
310
                                $icon = !is_null($ico) ? $ico : 'img/link.png';
2 daniel-mar 311
                                $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>';
312
                        }
313
 
314
 
315
                        if (OIDplus::authUtils()::isAdminLoggedIn()) {
5 daniel-mar 316
                                $out['text'] .= '<p><a href="#" onclick="return deleteRa('.js_escape($ra_email).',null)">Delete this RA</a></p>';
2 daniel-mar 317
                        }
318
 
319
                // === Forgot password ===
320
 
321
                } else if (explode('$',$id)[0] == 'oidplus:forgot_password') {
322
                        $handled = true;
323
 
324
                        $out['title'] = 'Forgot password';
325
 
326
                        try {
327
                                $out['text'] .= '<p>Please enter the email address of your account, and information about the password reset will be sent to you.</p>
328
                                  <form id="forgotPasswordForm" onsubmit="return forgotPasswordFormOnSubmit();">
329
                                    E-Mail: <input type="text" id="email" value=""/><br><br>'.
330
                                 (RECAPTCHA_ENABLED ? '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.RECAPTCHA_PUBLIC.'" }); </script>'.
331
                                                   '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.RECAPTCHA_PUBLIC.'"></div>' : '').
332
                                ' <br>
333
                                    <input type="submit" value="Send recovery information">
334
                                  </form>';
335
 
336
                        } catch (Exception $e) {
337
 
338
                                $out['text'] = "Error: ".$e->getMessage();
339
 
340
                        }
341
                } else if (explode('$',$id)[0] == 'oidplus:reset_password') {
342
                        $handled = true;
343
 
6 daniel-mar 344
                        $email = explode('$',$id)[1];
345
                        $timestamp = explode('$',$id)[2];
346
                        $auth = explode('$',$id)[3];
2 daniel-mar 347
 
348
                        $out['title'] = 'Reset password';
349
 
6 daniel-mar 350
                        if (!OIDplus::authUtils()::validateAuthKey('reset_password;'.$email.';'.$timestamp, $auth)) {
351
                                $out['text'] = 'Invalid authorization. Is the URL OK?';
352
                        } else {
2 daniel-mar 353
                                $out['text'] = '<p>E-Mail-Adress: <b>'.$email.'</b></p>
354
 
355
                                  <form id="resetPasswordForm" onsubmit="return resetPasswordFormOnSubmit();">
356
                                    <input type="hidden" id="email" value="'.htmlentities($email).'"/>
357
                                    <input type="hidden" id="timestamp" value="'.htmlentities($timestamp).'"/>
358
                                    <input type="hidden" id="auth" value="'.htmlentities($auth).'"/>
359
                                    New password: <input type="password" id="password1" value=""/><br><br>
360
                                    Again: <input type="password" id="password2" value=""/><br><br>
361
                                    <input type="submit" value="Change password">
362
                                  </form>';
363
                        }
364
 
365
 
366
                // === Invite ===
367
 
368
                } else if (explode('$',$id)[0] == 'oidplus:invite_ra') {
369
                        $handled = true;
370
 
371
                        $email = explode('$',$id)[1];
372
                        $origin = explode('$',$id)[2];
373
 
374
                        $out['title'] = 'Invite a Registration Authority';
375
 
376
                        try {
377
                                $cont = self::getInvitationText($email);
378
 
379
                                $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>
380
                                  <form id="inviteForm" onsubmit="return inviteFormOnSubmit();">
381
                                    <input type="hidden" id="email" value="'.htmlentities($email).'"/>
382
                                    <input type="hidden" id="origin" value="'.htmlentities($origin).'"/>'.
383
                                 (RECAPTCHA_ENABLED ? '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.RECAPTCHA_PUBLIC.'" }); </script>'.
384
                                                   '<div id="g-recaptcha" class="g-recaptcha" data-sitekey="'.RECAPTCHA_PUBLIC.'"></div>' : '').
385
                                ' <br>
386
                                    <input type="submit" value="Send invitation">
387
                                  </form>';
388
 
389
                        } catch (Exception $e) {
390
 
391
                                $out['text'] = "Error: ".$e->getMessage();
392
 
393
                        }
394
                } else if (explode('$',$id)[0] == 'oidplus:activate_ra') {
395
                        $handled = true;
396
 
6 daniel-mar 397
                        $email = explode('$',$id)[1];
398
                        $timestamp = explode('$',$id)[2];
399
                        $auth = explode('$',$id)[3];
2 daniel-mar 400
 
401
                        $out['title'] = 'Register as Registration Authority';
402
 
403
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."ra where email = '".OIDplus::db()->real_escape_string($email)."'");
404
                        if (OIDplus::db()->num_rows($res) > 0) {
6 daniel-mar 405
                                $out['text'] = 'This RA is already registered and does not need to be invited.';
2 daniel-mar 406
                        } else {
6 daniel-mar 407
                                if (!OIDplus::authUtils()::validateAuthKey('activate_ra;'.$email.';'.$timestamp, $auth)) {
408
                                        $out['text'] = 'Invalid authorization. Is the URL OK?';
409
                                } else {
2 daniel-mar 410
                                        // TODO: like in the FreeOID plugin, we could ask here at least for a name for the RA
411
                                        $out['text'] = '<p>E-Mail-Adress: <b>'.$email.'</b></p>
412
 
413
                                          <form id="activateRaForm" onsubmit="return activateRaFormOnSubmit();">
414
                                            <input type="hidden" id="email" value="'.htmlentities($email).'"/>
415
                                            <input type="hidden" id="timestamp" value="'.htmlentities($timestamp).'"/>
416
                                            <input type="hidden" id="auth" value="'.htmlentities($auth).'"/>
417
                                            New password: <input type="password" id="password1" value=""/><br><br>
418
                                            Again: <input type="password" id="password2" value=""/><br><br>
419
                                            <input type="submit" value="Register">
420
                                          </form>';
421
                                }
422
                        }
423
 
424
                // === Login ===
425
 
426
                } else if ($id === 'oidplus:login') {
427
                        $handled = true;
428
                        $out['title'] = 'Login';
429
 
430
                        $out['text'] .= '<script>function raLoginOnSubmit() {';
431
                        $out['text'] .= '       raLogin(document.getElementById("raLoginEMail").value, document.getElementById("raLoginPassword").value);';
432
                        $out['text'] .= '       return false;';
433
                        $out['text'] .= '}</script>';
434
 
435
                        $out['text'] .= (RECAPTCHA_ENABLED ? '<script> grecaptcha.render(document.getElementById("g-recaptcha"), { "sitekey" : "'.RECAPTCHA_PUBLIC.'" }); </script>'.
10 daniel-mar 436
                                                          '<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 437
 
10 daniel-mar 438
 
439
                        $out['text'] .= '<br>';
440
                        $out['text'] .= '<br>';
441
 
442
                        $out['text'] .= '<div id="loginTab" class="container" style="width:100%">';
443
                        $out['text'] .= '<ul  class="nav nav-pills">';
444
                        $out['text'] .= '                       <li class="active">';
445
                        $out['text'] .= '        <a  href="#1a" data-toggle="tab">Login as RA</a>';
446
                        $out['text'] .= '                       </li>';
16 daniel-mar 447
                        $out['text'] .= '                       <li><a href="#2a" data-toggle="tab">Login as administrator</a>';
10 daniel-mar 448
                        $out['text'] .= '                       </li>';
449
                        $out['text'] .= '               </ul>';
450
                        $out['text'] .= '                       <div class="tab-content clearfix">';
451
                        $out['text'] .= '                         <div class="tab-pane active" id="1a">';
452
 
2 daniel-mar 453
                        $out['text'] .= '<h2>Login as RA</h2>';
5 daniel-mar 454
 
455
                        $login_list = OIDplus::authUtils()->loggedInRaList();
456
                        if (count($login_list) > 0) {
457
                                foreach (OIDplus::authUtils()->loggedInRaList() as $x) {
458
                                        $out['text'] .= '<p>You are logged in as <b>'.$x.'</b> (<a href="#" onclick="return raLogout('.js_escape($x).');">Logout</a>)</p>';
459
                                }
460
                                $out['text'] .= '<p>If you have more accounts, you can log in with a new account:</p>';
461
                        } else {
462
                                $out['text'] .= '<p>Enter your email address and your password to log in as Registration Authority.</p>';
463
                        }
2 daniel-mar 464
                        $out['text'] .= '<form action="action.php" method="POST" onsubmit="return raLoginOnSubmit(this);">';
465
                        $out['text'] .= '<input type="hidden" name="action" value="ra_login">';
466
                        $out['text'] .= 'E-Mail: <input type="text" name="email" value="" id="raLoginEMail"><br>';
10 daniel-mar 467
                        $out['text'] .= 'Password: <input type="password" name="password" value="" id="raLoginPassword"><br><br>';
468
                        $out['text'] .= '<input type="submit" value="Login"><br><br>';
2 daniel-mar 469
                        $out['text'] .= '</form>';
470
                        $out['text'] .= '<p><a href="?goto=oidplus:forgot_password">Forgot password?</a><br>';
471
                        $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>';
472
                        $out['text'] .= '<script>function adminLoginOnSubmit() {';
473
                        $out['text'] .= '       adminLogin(document.getElementById("adminLoginPassword").value);';
474
                        $out['text'] .= '       return false;';
475
                        $out['text'] .= '}</script>';
476
 
10 daniel-mar 477
                        $out['text'] .= '                               </div>';
478
                        $out['text'] .= '                               <div class="tab-pane" id="2a">';
479
 
2 daniel-mar 480
                        if (OIDplus::authUtils()::isAdminLoggedIn()) {
481
                                $out['text'] .= '<h2>Admin login</h2>';
482
                                $out['text'] .= '<p>You are logged in as administrator.</p>';
5 daniel-mar 483
                                $out['text'] .= '<a href="#" onclick="return adminLogout();">Logout</a>';
2 daniel-mar 484
                        } else {
16 daniel-mar 485
                                $out['text'] .= '<h2>Login as administrator</h2>';
2 daniel-mar 486
                                $out['text'] .= '<form action="action.php" method="POST" onsubmit="return adminLoginOnSubmit(this);">';
487
                                $out['text'] .= '<input type="hidden" name="action" value="admin_login">';
10 daniel-mar 488
                                $out['text'] .= 'Password: <input type="password" name="password" value="" id="adminLoginPassword"><br><br>';
489
                                $out['text'] .= '<input type="submit" value="Login"><br><br>';
2 daniel-mar 490
                                $out['text'] .= '</form>';
491
                                $out['text'] .= '<p><abbr title="Delete the file includes/config.inc.php and reload the page to start Setup again">Forgot password?</abbr></p>';
492
                        }
10 daniel-mar 493
 
494
                        $out['text'] .= '                               </div>';
495
                        $out['text'] .= '                       </div>';
496
                        $out['text'] .= '  </div>';
2 daniel-mar 497
                }
498
 
499
                // === Plugins ===
500
 
501
                $ary = glob(__DIR__ . '/../../plugins/publicPages/'.'*'.'/gui.inc.php');
502
                sort($ary);
503
                foreach ($ary as $a) include $a;
504
 
505
                $ary = glob(__DIR__ . '/../../plugins/adminPages/'.'*'.'/gui.inc.php');
506
                sort($ary);
507
                foreach ($ary as $a) include $a;
508
 
509
                $ary = glob(__DIR__ . '/../../plugins/raPages/'.'*'.'/gui.inc.php');
510
                sort($ary);
511
                foreach ($ary as $a) include $a;
512
 
513
                // === Everything else (objects) ===
514
 
515
                if (!$handled) {
516
                        $obj = OIDplusObject::parse($id);
517
 
518
                        if ((!is_null($obj)) && (!$obj->userHasReadRights())) {
519
                                $out['title'] = 'Access denied';
520
                                $out['text'] = '<p>Please <a href="?goto=oidplus:login">log in</a> to receive information about this object.</p>';
521
                                return $out;
522
                        }
523
 
524
                        $res = OIDplus::db()->query("select * from ".OIDPLUS_TABLENAME_PREFIX."objects where id = '".OIDplus::db()->real_escape_string($id)."'");
525
                        $row = OIDplus::db()->fetch_array($res);
526
 
527
                        if (empty($row['title'])) {
528
                                $out['title'] = is_null($obj) ? $id : $obj->defaultTitle();
529
                        } else {
530
                                $out['title'] = $row['title'];
531
                        }
532
 
533
                        if (isset($row['description'])) {
534
                                $desc = empty($row['description']) ? '<p><i>No description for this object available</i></p>' : OIDplusGui::objDescription($row['description']);
535
                                if ($obj->userHasWriteRights()) {
536
                                        $rand = ++self::$crudCounter;
537
                                        $desc = '<noscript><p><b>You need to enable JavaScript to edit title or description of this object.</b></p>'.$desc.'</noscript>';
538
                                        $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">';
539
                                        $desc .= 'Title: <input type="text" name="title" id="titleedit" value="'.htmlentities($row['title']).'"><br><br>Description:<br>';
540
                                        $desc .= self::showMCE('description', $row['description']);
541
                                        $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="javascript:updateDesc()">Update description</button>';
542
                                        $desc .= '</div>';
543
                                        $desc .= '<script>document.getElementById("descbox_'.$rand.'").style.display = "block";</script>';
544
                                }
545
                        } else {
546
                                $desc = '';
547
                        }
548
 
549
                        $matches_any_registered_type = false;
550
                        foreach (OIDplusObject::$registeredObjectTypes as $ot) {
551
                                if ($obj = $ot::parse($id)) {
552
                                        $matches_any_registered_type = true;
553
                                        if ((OIDplus::db()->num_rows($res) == 0) && !$obj->isRoot()){
554
                                                http_response_code(404);
555
                                                $out['title'] = 'Object not found';
556
                                                $out['text'] = 'The object <code>'.htmlentities($id).'</code> was not found in this database.';
557
                                                return $out;
558
                                        } else {
559
                                                $obj->getContentPage($out['title'], $out['text']);
560
                                        }
561
                                }
562
                        }
563
                        if (!$matches_any_registered_type) {
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
                        }
569
 
570
                        if (strpos($out['text'], '%%DESC%%') !== false)
571
                                $out['text'] = str_replace('%%DESC%%',    $desc,                              $out['text']);
572
                        if (strpos($out['text'], '%%CRUD%%') !== false)
573
                                $out['text'] = str_replace('%%CRUD%%',    self::showCrud($id),                $out['text']);
574
                        if (strpos($out['text'], '%%RA_INFO%%') !== false)
575
                                $out['text'] = str_replace('%%RA_INFO%%', self::showRaInfo($row['ra_email']), $out['text']);
576
                }
577
 
578
                return $out;
579
        }
580
 
581
}