Rev 1412 | 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 | |||
1116 | daniel-mar | 28 | /** |
29 | * @param bool $html |
||
30 | * @return void |
||
31 | */ |
||
32 | public function init(bool $html=true) { |
||
635 | daniel-mar | 33 | } |
34 | |||
1116 | daniel-mar | 35 | /** |
36 | * @param string $id |
||
37 | * @param array $out |
||
38 | * @param bool $handled |
||
39 | * @return void |
||
40 | * @throws OIDplusConfigInitializationException |
||
41 | * @throws OIDplusException |
||
42 | */ |
||
43 | public function gui(string $id, array &$out, bool &$handled) { |
||
635 | daniel-mar | 44 | if (explode('$',$id)[0] == 'oidplus:rainfo') { |
45 | $handled = true; |
||
46 | |||
47 | $antispam_email = explode('$',$id.'$')[1]; |
||
48 | $ra_email = str_replace('&', '@', $antispam_email); |
||
49 | |||
801 | daniel-mar | 50 | $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/rainfo_icon.png'; |
635 | daniel-mar | 51 | |
704 | daniel-mar | 52 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
707 | daniel-mar | 53 | $listRaPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.500'); // OIDplusPageAdminListRAs |
54 | if (!is_null($listRaPlugin)) { |
||
55 | $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>'; |
||
56 | } |
||
704 | daniel-mar | 57 | } |
635 | daniel-mar | 58 | |
59 | if (empty($ra_email)) { |
||
60 | $out['title'] = _L('Object roots without RA'); |
||
61 | $out['text'] .= '<p>'._L('Following object roots have an undefined Registration Authority').':</p>'; |
||
62 | } else { |
||
63 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email)); |
||
64 | $out['title'] = ''; |
||
65 | if ($row = $res->fetch_array()) { |
||
66 | $out['title'] = $row['ra_name']; |
||
67 | } |
||
68 | if (empty($out['title'])) { |
||
69 | $out['title'] = $antispam_email; |
||
70 | } |
||
1410 | daniel-mar | 71 | $out['text'] .= $this->showRAInfo($ra_email, null); |
635 | daniel-mar | 72 | $out['text'] .= '<br><br>'; |
73 | } |
||
74 | |||
75 | $ra_roots = OIDplusObject::getRaRoots($ra_email); |
||
76 | if (count($ra_roots) == 0) { |
||
77 | if (empty($ra_email)) { |
||
78 | $out['text'] .= '<p><i>'._L('None').'</i></p>'; |
||
79 | } else { |
||
80 | $out['text'] .= '<p><i>'._L('This RA has no objects.').'</i></p>'; |
||
81 | } |
||
82 | } else { |
||
83 | foreach ($ra_roots as $loc_root) { |
||
84 | $ico = $loc_root->getIcon(); |
||
801 | daniel-mar | 85 | $icon = !is_null($ico) ? $ico : OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/link_icon16.png'; |
635 | daniel-mar | 86 | $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>'; |
87 | } |
||
88 | } |
||
89 | |||
90 | if (!empty($ra_email)) { |
||
91 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
||
790 | daniel-mar | 92 | if ($res->any()) { |
635 | daniel-mar | 93 | if (OIDplus::authUtils()->isRALoggedIn($ra_email) || OIDplus::authUtils()->isAdminLoggedIn()) { |
94 | $editContactDataPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.100'); // OIDplusPageRaEditContactData |
||
95 | if (!is_null($editContactDataPlugin)) { |
||
96 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:edit_ra$'.$ra_email).'>'._L('Edit contact data').'</a></p>'; |
||
97 | } |
||
1445 | daniel-mar | 98 | |
99 | $editContactDataPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.200'); // OIDplusPageRaLogEvents |
||
100 | if (!is_null($editContactDataPlugin)) { |
||
101 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:ra_log$'.$ra_email).'>'._L('Show log entries').'</a></p>'; |
||
102 | } |
||
635 | daniel-mar | 103 | } |
104 | |||
105 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
||
1082 | daniel-mar | 106 | $raBasePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.1.1'); // OIDplusPagePublicRaBaseUtils |
107 | if (!is_null($raBasePlugin)) { |
||
108 | $listRaPlugin = OIDplus::getPluginByOid("1.3.6.1.4.1.37476.2.5.2.4.3.500"); // OIDplusPageAdminListRAs |
||
109 | if (!is_null($listRaPlugin)) { |
||
110 | $delete_goback = 'oidplus:list_ra'; |
||
111 | } else { |
||
112 | $delete_goback = 'oidplus:system'; |
||
113 | } |
||
114 | $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 | 115 | } |
116 | |||
117 | $changePasswordPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.101'); // OIDplusPageRaChangePassword |
||
118 | if (!is_null($changePasswordPlugin)) { |
||
119 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_password$'.$ra_email).'>'._L('Change password of this RA').'</a>'; |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | |||
124 | if (OIDplus::authUtils()->isRALoggedIn($ra_email) || OIDplus::authUtils()->isAdminLoggedIn()) { |
||
125 | $res = OIDplus::db()->query("select lo.unix_ts, lo.addr, lo.event from ###log lo ". |
||
126 | "left join ###log_user lu on lu.log_id = lo.id ". |
||
127 | "where lu.username = ? " . |
||
128 | "order by lo.unix_ts desc", array($ra_email)); |
||
129 | $out['text'] .= '<h2>'._L('Log messages for RA %1',htmlentities($ra_email)).'</h2>'; |
||
790 | daniel-mar | 130 | if ($res->any()) { |
635 | daniel-mar | 131 | $out['text'] .= '<pre>'; |
132 | while ($row = $res->fetch_array()) { |
||
133 | $addr = empty($row['addr']) ? _L('no address') : $row['addr']; |
||
134 | |||
1223 | daniel-mar | 135 | $out['text'] .= date('Y-m-d H:i:s', (int)$row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr) . ")\n"; |
635 | daniel-mar | 136 | } |
137 | $out['text'] .= '</pre>'; |
||
138 | |||
139 | // TODO: List logs in a table instead of a <pre> text |
||
140 | // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down |
||
141 | } else { |
||
142 | $out['text'] .= '<p>'._L('Currently there are no log entries').'</p>'; |
||
143 | } |
||
144 | } |
||
145 | } |
||
146 | } |
||
147 | } |
||
148 | |||
1116 | daniel-mar | 149 | /** |
150 | * @param array $out |
||
151 | * @return void |
||
152 | * @throws OIDplusConfigInitializationException |
||
153 | * @throws OIDplusException |
||
154 | */ |
||
155 | public function publicSitemap(array &$out) { |
||
635 | daniel-mar | 156 | if (OIDplus::db()->getSlang()->id() == 'mysql') { |
1409 | daniel-mar | 157 | $res = OIDplus::db()->query("select distinct BINARY(email) as distinct_email from ###ra"); // "binary" because we want to ensure that 'distinct' is case sensitive |
635 | daniel-mar | 158 | } else { |
1171 | daniel-mar | 159 | $res = OIDplus::db()->query("select distinct email as distinct_email from ###ra"); // distinct in PGSQL is always case sensitive |
635 | daniel-mar | 160 | } |
161 | while ($row = $res->fetch_array()) { |
||
1171 | daniel-mar | 162 | $out[] = 'oidplus:rainfo$'.$row['distinct_email']; |
635 | daniel-mar | 163 | } |
164 | } |
||
165 | |||
1116 | daniel-mar | 166 | /** |
167 | * @param array $json |
||
168 | * @param string|null $ra_email |
||
169 | * @param bool $nonjs |
||
170 | * @param string $req_goto |
||
171 | * @return bool |
||
172 | */ |
||
173 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
||
635 | daniel-mar | 174 | return false; |
175 | } |
||
176 | |||
1116 | daniel-mar | 177 | /** |
1136 | daniel-mar | 178 | * @param string|null $email |
1410 | daniel-mar | 179 | * @param OIDplusObject|null $oid |
1130 | daniel-mar | 180 | * @return string |
1116 | daniel-mar | 181 | * @throws OIDplusException |
182 | */ |
||
1410 | daniel-mar | 183 | public static function showRAInfo(/*?string*/ $email, OIDplusObject $oid=null): string { |
635 | daniel-mar | 184 | $out = ''; |
185 | |||
186 | if (empty($email)) { |
||
187 | return '<p>'._L('The superior RA did not define a RA for this OID.').'</p>'; |
||
188 | } |
||
189 | |||
190 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
||
790 | daniel-mar | 191 | if (!$res->any()) { |
635 | daniel-mar | 192 | $out = '<p>'._L('The RA %1 is not registered in the database.','<a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a>').'</p>'; |
676 | daniel-mar | 193 | |
194 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
||
195 | $createRAPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.130'); // OIDplusPageAdminCreateRa |
||
196 | if (!is_null($createRAPlugin)) { |
||
1410 | daniel-mar | 197 | $out .= '<p><a class="btn btn-success" '.OIDplus::gui()->link('oidplus:create_ra$'.$email).'>'._L('Create RA manually').'</a></p>'; |
676 | daniel-mar | 198 | } |
1412 | daniel-mar | 199 | $out .= '<p><a class="btn btn-success" '.OIDplus::gui()->link('oidplus:invite_ra$'.$email).'>'._L('Invite RA to join OIDplus').'</a></p>'; |
200 | } else if (!is_null($oid) && $oid->userHasParentalWriteRights()) { |
||
1410 | daniel-mar | 201 | $out .= '<p><a class="btn btn-success" '.OIDplus::gui()->link('oidplus:invite_ra$'.$email.'$'.$oid->nodeId(true)).'>'._L('Invite RA to join OIDplus').'</a></p>'; |
202 | } |
||
676 | daniel-mar | 203 | |
635 | daniel-mar | 204 | } else { |
205 | $row = $res->fetch_array(); |
||
1219 | daniel-mar | 206 | $out = '<b>'.htmlentities($row['ra_name']??'').'</b><br>'; // TODO: if you are not already at the page "oidplus:rainfo", then link to it now |
635 | daniel-mar | 207 | $out .= _L('E-Mail').': <a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a><br>'; |
1219 | daniel-mar | 208 | if (trim($row['personal_name']??'') !== '') $out .= htmlentities($row['personal_name']).'<br>'; |
209 | if (trim($row['organization']??'') !== '') $out .= htmlentities($row['organization']).'<br>'; |
||
210 | if (trim($row['office']??'') !== '') $out .= htmlentities($row['office']).'<br>'; |
||
635 | daniel-mar | 211 | if ($row['privacy']) { |
212 | // TODO: Only show the message if the user has a street, address, etc. |
||
213 | // TODO: But the admin and the own user should see it (with a note that the data is not visible to the public) |
||
214 | $out .= '<p>'._L('The RA does not want to publish their personal information.').'</p>'; |
||
215 | } else { |
||
1219 | daniel-mar | 216 | if (trim($row['street']??'') !== '') $out .= htmlentities($row['street']).'<br>'; |
217 | if (trim($row['zip_town']??'') !== '') $out .= htmlentities($row['zip_town']).'<br>'; |
||
218 | if (trim($row['country']??'') !== '') $out .= htmlentities($row['country']).'<br>'; |
||
635 | daniel-mar | 219 | $out .= '<br>'; |
1219 | daniel-mar | 220 | if (trim($row['phone']??'') !== '') $out .= _L('Phone: %1',htmlentities($row['phone'])).'<br>'; |
221 | if (trim($row['fax']??'') !== '') $out .= _L('Fax: %1',htmlentities($row['fax'])).'<br>'; |
||
222 | if (trim($row['mobile']??'') !== '') $out .= _L('Mobile: %1',htmlentities($row['mobile'])).'<br>'; |
||
635 | daniel-mar | 223 | $out .= '<br>'; |
224 | } |
||
225 | } |
||
226 | |||
227 | return trim_br($out); |
||
228 | } |
||
229 | |||
1116 | daniel-mar | 230 | /** |
231 | * @param string $request |
||
232 | * @return array|false |
||
233 | */ |
||
234 | public function tree_search(string $request) { |
||
635 | daniel-mar | 235 | return false; |
236 | } |
||
237 | } |