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