Subversion Repositories oidplus

Rev

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