Subversion Repositories oidplus

Rev

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

Rev Author Line No. Line
635 daniel-mar 1
<?php
2
 
3
/*
4
 * OIDplus 2.0
1086 daniel-mar 5
 * Copyright 2019 - 2023 Daniel Marschall, ViaThinkSoft
635 daniel-mar 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
 
1050 daniel-mar 20
namespace ViaThinkSoft\OIDplus;
635 daniel-mar 21
 
1086 daniel-mar 22
// phpcs:disable PSR1.Files.SideEffects
23
\defined('INSIDE_OIDPLUS') or die;
24
// phpcs:enable PSR1.Files.SideEffects
25
 
635 daniel-mar 26
class OIDplusPagePublicRaInfo extends OIDplusPagePluginPublic {
27
 
28
        public function init($html=true) {
29
        }
30
 
31
        public function gui($id, &$out, &$handled) {
32
                if (explode('$',$id)[0] == 'oidplus:rainfo') {
33
                        $handled = true;
34
 
35
                        $antispam_email = explode('$',$id.'$')[1];
36
                        $ra_email = str_replace('&', '@', $antispam_email);
37
 
801 daniel-mar 38
                        $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/rainfo_icon.png';
635 daniel-mar 39
 
704 daniel-mar 40
                        if (OIDplus::authUtils()->isAdminLoggedIn()) {
707 daniel-mar 41
                                $listRaPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.500'); // OIDplusPageAdminListRAs
42
                                if (!is_null($listRaPlugin)) {
43
                                        $out['text'] = '<p><a '.OIDplus::gui()->link('oidplus:list_ra').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Go back to RA listing').'</a></p>';
44
                                }
704 daniel-mar 45
                        }
635 daniel-mar 46
 
47
                        if (empty($ra_email)) {
48
                                $out['title'] = _L('Object roots without RA');
49
                                $out['text'] .= '<p>'._L('Following object roots have an undefined Registration Authority').':</p>';
50
                        } else {
51
                                $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email));
52
                                $out['title'] = '';
53
                                if ($row = $res->fetch_array()) {
54
                                        $out['title'] = $row['ra_name'];
55
                                }
56
                                if (empty($out['title'])) {
57
                                        $out['title'] = $antispam_email;
58
                                }
59
                                $out['text'] .= $this->showRAInfo($ra_email);
60
                                $out['text'] .= '<br><br>';
61
                        }
62
 
63
                        $ra_roots = OIDplusObject::getRaRoots($ra_email);
64
                        if (count($ra_roots) == 0) {
65
                                if (empty($ra_email)) {
66
                                        $out['text'] .= '<p><i>'._L('None').'</i></p>';
67
                                } else {
68
                                        $out['text'] .= '<p><i>'._L('This RA has no objects.').'</i></p>';
69
                                }
70
                        } else {
71
                                foreach ($ra_roots as $loc_root) {
72
                                        $ico = $loc_root->getIcon();
801 daniel-mar 73
                                        $icon = !is_null($ico) ? $ico : OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/link_icon16.png';
635 daniel-mar 74
                                        $out['text'] .= '<p><a '.OIDplus::gui()->link($loc_root->nodeId()).'><img src="'.$icon.'"> '._L('Jump to RA root %1',$loc_root->objectTypeTitleShort().' '.$loc_root->crudShowId(OIDplusObject::parse($loc_root::root()))).'</a></p>';
75
                                }
76
                        }
77
 
78
                        if (!empty($ra_email)) {
79
                                $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email));
790 daniel-mar 80
                                if ($res->any()) {
635 daniel-mar 81
                                        if (OIDplus::authUtils()->isRALoggedIn($ra_email) || OIDplus::authUtils()->isAdminLoggedIn()) {
82
                                                $editContactDataPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.100'); // OIDplusPageRaEditContactData
83
                                                if (!is_null($editContactDataPlugin)) {
84
                                                        $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:edit_ra$'.$ra_email).'>'._L('Edit contact data').'</a></p>';
85
                                                }
86
                                        }
87
 
88
                                        if (OIDplus::authUtils()->isAdminLoggedIn()) {
1082 daniel-mar 89
                                                $raBasePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.1.1'); // OIDplusPagePublicRaBaseUtils
90
                                                if (!is_null($raBasePlugin)) {
91
                                                        $listRaPlugin = OIDplus::getPluginByOid("1.3.6.1.4.1.37476.2.5.2.4.3.500"); // OIDplusPageAdminListRAs
92
                                                        if (!is_null($listRaPlugin)) {
93
                                                                $delete_goback = 'oidplus:list_ra';
94
                                                        } else {
95
                                                                $delete_goback = 'oidplus:system';
96
                                                        }
97
                                                        $out['text'] .= '<p><a href="#" onclick="return OIDplusPagePublicRaBaseUtils.deleteRa('.js_escape($ra_email).','.js_escape($delete_goback).')">'._L('Delete this RA').'</a></p>';
635 daniel-mar 98
                                                }
99
 
100
                                                $changePasswordPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.101'); // OIDplusPageRaChangePassword
101
                                                if (!is_null($changePasswordPlugin)) {
102
                                                        $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_password$'.$ra_email).'>'._L('Change password of this RA').'</a>';
103
                                                }
104
                                        }
105
                                }
106
 
107
                                if (OIDplus::authUtils()->isRALoggedIn($ra_email) || OIDplus::authUtils()->isAdminLoggedIn()) {
108
                                        $res = OIDplus::db()->query("select lo.unix_ts, lo.addr, lo.event from ###log lo ".
109
                                                                    "left join ###log_user lu on lu.log_id = lo.id ".
110
                                                                    "where lu.username = ? " .
111
                                                                    "order by lo.unix_ts desc", array($ra_email));
112
                                        $out['text'] .= '<h2>'._L('Log messages for RA %1',htmlentities($ra_email)).'</h2>';
790 daniel-mar 113
                                        if ($res->any()) {
635 daniel-mar 114
                                                $out['text'] .= '<pre>';
115
                                                while ($row = $res->fetch_array()) {
116
                                                        $addr = empty($row['addr']) ? _L('no address') : $row['addr'];
117
 
118
                                                        $out['text'] .= date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr) . ")\n";
119
                                                }
120
                                                $out['text'] .= '</pre>';
121
 
122
                                                // TODO: List logs in a table instead of a <pre> text
123
                                                // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down
124
                                        } else {
125
                                                $out['text'] .= '<p>'._L('Currently there are no log entries').'</p>';
126
                                        }
127
                                }
128
                        }
129
                }
130
        }
131
 
132
        public function publicSitemap(&$out) {
133
                if (OIDplus::db()->getSlang()->id() == 'mysql') {
134
                        $res = OIDplus::db()->query("select distinct BINARY(email) as email from ###ra"); // "binary" because we want to ensure that 'distinct' is case sensitive
135
                } else {
136
                        $res = OIDplus::db()->query("select distinct email as email from ###ra"); // distinct in PGSQL is always case sensitive
137
                }
138
                while ($row = $res->fetch_array()) {
139
                        $out[] = 'oidplus:rainfo$'.$row['email'];
140
                }
141
        }
142
 
143
        public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') {
144
                return false;
145
        }
146
 
147
        public static function showRAInfo($email) {
148
                $out = '';
149
 
150
                if (empty($email)) {
151
                        return '<p>'._L('The superior RA did not define a RA for this OID.').'</p>';
152
                }
153
 
154
                $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email));
790 daniel-mar 155
                if (!$res->any()) {
635 daniel-mar 156
                        $out = '<p>'._L('The RA %1 is not registered in the database.','<a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a>').'</p>';
676 daniel-mar 157
 
158
                        if (OIDplus::authUtils()->isAdminLoggedIn()) {
159
                                $createRAPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.130'); // OIDplusPageAdminCreateRa
160
                                if (!is_null($createRAPlugin)) {
161
                                        $out .= '<p><a '.OIDplus::gui()->link('oidplus:create_ra$'.$email).'>'._L('Create RA manually').'</a></p>';
162
                                }
163
                        }
164
 
635 daniel-mar 165
                } else {
166
                        $row = $res->fetch_array();
167
                        $out = '<b>'.htmlentities($row['ra_name']).'</b><br>'; // TODO: if you are not already at the page "oidplus:rainfo", then link to it now
168
                        $out .= _L('E-Mail').': <a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a><br>';
169
                        if (trim($row['personal_name']) !== '') $out .= htmlentities($row['personal_name']).'<br>';
170
                        if (trim($row['organization']) !== '') $out .= htmlentities($row['organization']).'<br>';
171
                        if (trim($row['office']) !== '') $out .= htmlentities($row['office']).'<br>';
172
                        if ($row['privacy']) {
173
                                // TODO: Only show the message if the user has a street, address, etc.
174
                                // TODO: But the admin and the own user should see it (with a note that the data is not visible to the public)
175
                                $out .= '<p>'._L('The RA does not want to publish their personal information.').'</p>';
176
                        } else {
177
                                if (trim($row['street']) !== '') $out .= htmlentities($row['street']).'<br>';
178
                                if (trim($row['zip_town']) !== '') $out .= htmlentities($row['zip_town']).'<br>';
179
                                if (trim($row['country']) !== '') $out .= htmlentities($row['country']).'<br>';
180
                                $out .= '<br>';
181
                                if (trim($row['phone']) !== '') $out .= _L('Phone: %1',htmlentities($row['phone'])).'<br>';
182
                                if (trim($row['fax']) !== '') $out .= _L('Fax: %1',htmlentities($row['fax'])).'<br>';
183
                                if (trim($row['mobile']) !== '') $out .= _L('Mobile: %1',htmlentities($row['mobile'])).'<br>';
184
                                $out .= '<br>';
185
                        }
186
                }
187
 
188
                return trim_br($out);
189
        }
190
 
191
        public function tree_search($request) {
192
                return false;
193
        }
194
}