Rev 790 | Rev 801 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 790 | Rev 800 | ||
---|---|---|---|
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * OIDplus 2.0 |
4 | * OIDplus 2.0 |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2019 - 2021 Daniel Marschall, ViaThinkSoft |
6 | * |
6 | * |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * you may not use this file except in compliance with 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 |
9 | * You may obtain a copy of the License at |
10 | * |
10 | * |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | * |
12 | * |
13 | * Unless required by applicable law or agreed to in writing, software |
13 | * Unless required by applicable law or agreed to in writing, software |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | * See the License for the specific language governing permissions and |
16 | * See the License for the specific language governing permissions and |
17 | * limitations under the License. |
17 | * limitations under the License. |
18 | */ |
18 | */ |
19 | 19 | ||
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
20 | if (!defined('INSIDE_OIDPLUS')) die(); |
21 | 21 | ||
22 | class OIDplusPagePublicRaInfo extends OIDplusPagePluginPublic { |
22 | class OIDplusPagePublicRaInfo extends OIDplusPagePluginPublic { |
23 | 23 | ||
24 | public function init($html=true) { |
24 | public function init($html=true) { |
25 | } |
25 | } |
26 | 26 | ||
27 | public function gui($id, &$out, &$handled) { |
27 | public function gui($id, &$out, &$handled) { |
28 | if (explode('$',$id)[0] == 'oidplus:rainfo') { |
28 | if (explode('$',$id)[0] == 'oidplus:rainfo') { |
29 | $handled = true; |
29 | $handled = true; |
30 | 30 | ||
31 | $antispam_email = explode('$',$id.'$')[1]; |
31 | $antispam_email = explode('$',$id.'$')[1]; |
32 | $ra_email = str_replace('&', '@', $antispam_email); |
32 | $ra_email = str_replace('&', '@', $antispam_email); |
33 | 33 | ||
34 | $out['icon'] = OIDplus::webpath(__DIR__).'rainfo_big.png'; |
34 | $out['icon'] = OIDplus::webpath(__DIR__,true).'img/rainfo_icon.png'; |
35 | 35 | ||
36 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
36 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
37 | $listRaPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.500'); // OIDplusPageAdminListRAs |
37 | $listRaPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.500'); // OIDplusPageAdminListRAs |
38 | if (!is_null($listRaPlugin)) { |
38 | if (!is_null($listRaPlugin)) { |
39 | $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>'; |
39 | $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>'; |
40 | } |
40 | } |
41 | } |
41 | } |
42 | 42 | ||
43 | if (empty($ra_email)) { |
43 | if (empty($ra_email)) { |
44 | $out['title'] = _L('Object roots without RA'); |
44 | $out['title'] = _L('Object roots without RA'); |
45 | $out['text'] .= '<p>'._L('Following object roots have an undefined Registration Authority').':</p>'; |
45 | $out['text'] .= '<p>'._L('Following object roots have an undefined Registration Authority').':</p>'; |
46 | } else { |
46 | } else { |
47 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email)); |
47 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email)); |
48 | $out['title'] = ''; |
48 | $out['title'] = ''; |
49 | if ($row = $res->fetch_array()) { |
49 | if ($row = $res->fetch_array()) { |
50 | $out['title'] = $row['ra_name']; |
50 | $out['title'] = $row['ra_name']; |
51 | } |
51 | } |
52 | if (empty($out['title'])) { |
52 | if (empty($out['title'])) { |
53 | $out['title'] = $antispam_email; |
53 | $out['title'] = $antispam_email; |
54 | } |
54 | } |
55 | $out['text'] .= $this->showRAInfo($ra_email); |
55 | $out['text'] .= $this->showRAInfo($ra_email); |
56 | $out['text'] .= '<br><br>'; |
56 | $out['text'] .= '<br><br>'; |
57 | } |
57 | } |
58 | 58 | ||
59 | $ra_roots = OIDplusObject::getRaRoots($ra_email); |
59 | $ra_roots = OIDplusObject::getRaRoots($ra_email); |
60 | if (count($ra_roots) == 0) { |
60 | if (count($ra_roots) == 0) { |
61 | if (empty($ra_email)) { |
61 | if (empty($ra_email)) { |
62 | $out['text'] .= '<p><i>'._L('None').'</i></p>'; |
62 | $out['text'] .= '<p><i>'._L('None').'</i></p>'; |
63 | } else { |
63 | } else { |
64 | $out['text'] .= '<p><i>'._L('This RA has no objects.').'</i></p>'; |
64 | $out['text'] .= '<p><i>'._L('This RA has no objects.').'</i></p>'; |
65 | } |
65 | } |
66 | } else { |
66 | } else { |
67 | foreach ($ra_roots as $loc_root) { |
67 | foreach ($ra_roots as $loc_root) { |
68 | $ico = $loc_root->getIcon(); |
68 | $ico = $loc_root->getIcon(); |
69 | $icon = !is_null($ico) ? $ico : OIDplus::webpath(__DIR__).'treeicon_link.png'; |
69 | $icon = !is_null($ico) ? $ico : OIDplus::webpath(__DIR__,true).'img/link_icon16.png'; |
70 | $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>'; |
70 | $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>'; |
71 | } |
71 | } |
72 | } |
72 | } |
73 | 73 | ||
74 | if (!empty($ra_email)) { |
74 | if (!empty($ra_email)) { |
75 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
75 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($ra_email)); |
76 | if ($res->any()) { |
76 | if ($res->any()) { |
77 | if (OIDplus::authUtils()->isRALoggedIn($ra_email) || OIDplus::authUtils()->isAdminLoggedIn()) { |
77 | if (OIDplus::authUtils()->isRALoggedIn($ra_email) || OIDplus::authUtils()->isAdminLoggedIn()) { |
78 | $editContactDataPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.100'); // OIDplusPageRaEditContactData |
78 | $editContactDataPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.100'); // OIDplusPageRaEditContactData |
79 | if (!is_null($editContactDataPlugin)) { |
79 | if (!is_null($editContactDataPlugin)) { |
80 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:edit_ra$'.$ra_email).'>'._L('Edit contact data').'</a></p>'; |
80 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:edit_ra$'.$ra_email).'>'._L('Edit contact data').'</a></p>'; |
81 | } |
81 | } |
82 | } |
82 | } |
83 | 83 | ||
84 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
84 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
85 | if (class_exists("OIDplusPageAdminListRAs")) { |
85 | if (class_exists("OIDplusPageAdminListRAs")) { |
86 | $out['text'] .= '<p><a href="#" onclick="return OIDplusPagePublicRaBaseUtils.deleteRa('.js_escape($ra_email).','.js_escape('oidplus:list_ra').')">'._L('Delete this RA').'</a></p>'; |
86 | $out['text'] .= '<p><a href="#" onclick="return OIDplusPagePublicRaBaseUtils.deleteRa('.js_escape($ra_email).','.js_escape('oidplus:list_ra').')">'._L('Delete this RA').'</a></p>'; |
87 | } else { |
87 | } else { |
88 | $out['text'] .= '<p><a href="#" onclick="return OIDplusPagePublicRaBaseUtils.deleteRa('.js_escape($ra_email).','.js_escape('oidplus:system').')">'._L('Delete this RA').'</a></p>'; |
88 | $out['text'] .= '<p><a href="#" onclick="return OIDplusPagePublicRaBaseUtils.deleteRa('.js_escape($ra_email).','.js_escape('oidplus:system').')">'._L('Delete this RA').'</a></p>'; |
89 | } |
89 | } |
90 | 90 | ||
91 | $changePasswordPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.101'); // OIDplusPageRaChangePassword |
91 | $changePasswordPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.101'); // OIDplusPageRaChangePassword |
92 | if (!is_null($changePasswordPlugin)) { |
92 | if (!is_null($changePasswordPlugin)) { |
93 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_password$'.$ra_email).'>'._L('Change password of this RA').'</a>'; |
93 | $out['text'] .= '<p><a '.OIDplus::gui()->link('oidplus:change_ra_password$'.$ra_email).'>'._L('Change password of this RA').'</a>'; |
94 | } |
94 | } |
95 | } |
95 | } |
96 | } |
96 | } |
97 | 97 | ||
98 | if (OIDplus::authUtils()->isRALoggedIn($ra_email) || OIDplus::authUtils()->isAdminLoggedIn()) { |
98 | if (OIDplus::authUtils()->isRALoggedIn($ra_email) || OIDplus::authUtils()->isAdminLoggedIn()) { |
99 | $res = OIDplus::db()->query("select lo.unix_ts, lo.addr, lo.event from ###log lo ". |
99 | $res = OIDplus::db()->query("select lo.unix_ts, lo.addr, lo.event from ###log lo ". |
100 | "left join ###log_user lu on lu.log_id = lo.id ". |
100 | "left join ###log_user lu on lu.log_id = lo.id ". |
101 | "where lu.username = ? " . |
101 | "where lu.username = ? " . |
102 | "order by lo.unix_ts desc", array($ra_email)); |
102 | "order by lo.unix_ts desc", array($ra_email)); |
103 | $out['text'] .= '<h2>'._L('Log messages for RA %1',htmlentities($ra_email)).'</h2>'; |
103 | $out['text'] .= '<h2>'._L('Log messages for RA %1',htmlentities($ra_email)).'</h2>'; |
104 | if ($res->any()) { |
104 | if ($res->any()) { |
105 | $out['text'] .= '<pre>'; |
105 | $out['text'] .= '<pre>'; |
106 | while ($row = $res->fetch_array()) { |
106 | while ($row = $res->fetch_array()) { |
107 | $addr = empty($row['addr']) ? _L('no address') : $row['addr']; |
107 | $addr = empty($row['addr']) ? _L('no address') : $row['addr']; |
108 | 108 | ||
109 | $out['text'] .= date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr) . ")\n"; |
109 | $out['text'] .= date('Y-m-d H:i:s', $row['unix_ts']) . ': ' . htmlentities($row["event"])." (" . htmlentities($addr) . ")\n"; |
110 | } |
110 | } |
111 | $out['text'] .= '</pre>'; |
111 | $out['text'] .= '</pre>'; |
112 | 112 | ||
113 | // TODO: List logs in a table instead of a <pre> text |
113 | // TODO: List logs in a table instead of a <pre> text |
114 | // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down |
114 | // TODO: Load only X events and then re-load new events via AJAX when the user scrolls down |
115 | } else { |
115 | } else { |
116 | $out['text'] .= '<p>'._L('Currently there are no log entries').'</p>'; |
116 | $out['text'] .= '<p>'._L('Currently there are no log entries').'</p>'; |
117 | } |
117 | } |
118 | } |
118 | } |
119 | } |
119 | } |
120 | } |
120 | } |
121 | } |
121 | } |
122 | 122 | ||
123 | public function publicSitemap(&$out) { |
123 | public function publicSitemap(&$out) { |
124 | if (OIDplus::db()->getSlang()->id() == 'mysql') { |
124 | if (OIDplus::db()->getSlang()->id() == 'mysql') { |
125 | $res = OIDplus::db()->query("select distinct BINARY(email) as email from ###ra"); // "binary" because we want to ensure that 'distinct' is case sensitive |
125 | $res = OIDplus::db()->query("select distinct BINARY(email) as email from ###ra"); // "binary" because we want to ensure that 'distinct' is case sensitive |
126 | } else { |
126 | } else { |
127 | $res = OIDplus::db()->query("select distinct email as email from ###ra"); // distinct in PGSQL is always case sensitive |
127 | $res = OIDplus::db()->query("select distinct email as email from ###ra"); // distinct in PGSQL is always case sensitive |
128 | } |
128 | } |
129 | while ($row = $res->fetch_array()) { |
129 | while ($row = $res->fetch_array()) { |
130 | $out[] = 'oidplus:rainfo$'.$row['email']; |
130 | $out[] = 'oidplus:rainfo$'.$row['email']; |
131 | } |
131 | } |
132 | } |
132 | } |
133 | 133 | ||
134 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
134 | public function tree(&$json, $ra_email=null, $nonjs=false, $req_goto='') { |
135 | return false; |
135 | return false; |
136 | } |
136 | } |
137 | 137 | ||
138 | public static function showRAInfo($email) { |
138 | public static function showRAInfo($email) { |
139 | $out = ''; |
139 | $out = ''; |
140 | 140 | ||
141 | if (empty($email)) { |
141 | if (empty($email)) { |
142 | return '<p>'._L('The superior RA did not define a RA for this OID.').'</p>'; |
142 | return '<p>'._L('The superior RA did not define a RA for this OID.').'</p>'; |
143 | } |
143 | } |
144 | 144 | ||
145 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
145 | $res = OIDplus::db()->query("select * from ###ra where email = ?", array($email)); |
146 | if (!$res->any()) { |
146 | if (!$res->any()) { |
147 | $out = '<p>'._L('The RA %1 is not registered in the database.','<a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a>').'</p>'; |
147 | $out = '<p>'._L('The RA %1 is not registered in the database.','<a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a>').'</p>'; |
148 | 148 | ||
149 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
149 | if (OIDplus::authUtils()->isAdminLoggedIn()) { |
150 | $createRAPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.130'); // OIDplusPageAdminCreateRa |
150 | $createRAPlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.3.130'); // OIDplusPageAdminCreateRa |
151 | if (!is_null($createRAPlugin)) { |
151 | if (!is_null($createRAPlugin)) { |
152 | $out .= '<p><a '.OIDplus::gui()->link('oidplus:create_ra$'.$email).'>'._L('Create RA manually').'</a></p>'; |
152 | $out .= '<p><a '.OIDplus::gui()->link('oidplus:create_ra$'.$email).'>'._L('Create RA manually').'</a></p>'; |
153 | } |
153 | } |
154 | } |
154 | } |
155 | 155 | ||
156 | } else { |
156 | } else { |
157 | $row = $res->fetch_array(); |
157 | $row = $res->fetch_array(); |
158 | $out = '<b>'.htmlentities($row['ra_name']).'</b><br>'; // TODO: if you are not already at the page "oidplus:rainfo", then link to it now |
158 | $out = '<b>'.htmlentities($row['ra_name']).'</b><br>'; // TODO: if you are not already at the page "oidplus:rainfo", then link to it now |
159 | $out .= _L('E-Mail').': <a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a><br>'; |
159 | $out .= _L('E-Mail').': <a href="mailto:'.htmlentities($email).'">'.htmlentities($email).'</a><br>'; |
160 | if (trim($row['personal_name']) !== '') $out .= htmlentities($row['personal_name']).'<br>'; |
160 | if (trim($row['personal_name']) !== '') $out .= htmlentities($row['personal_name']).'<br>'; |
161 | if (trim($row['organization']) !== '') $out .= htmlentities($row['organization']).'<br>'; |
161 | if (trim($row['organization']) !== '') $out .= htmlentities($row['organization']).'<br>'; |
162 | if (trim($row['office']) !== '') $out .= htmlentities($row['office']).'<br>'; |
162 | if (trim($row['office']) !== '') $out .= htmlentities($row['office']).'<br>'; |
163 | if ($row['privacy']) { |
163 | if ($row['privacy']) { |
164 | // TODO: Only show the message if the user has a street, address, etc. |
164 | // TODO: Only show the message if the user has a street, address, etc. |
165 | // TODO: But the admin and the own user should see it (with a note that the data is not visible to the public) |
165 | // TODO: But the admin and the own user should see it (with a note that the data is not visible to the public) |
166 | $out .= '<p>'._L('The RA does not want to publish their personal information.').'</p>'; |
166 | $out .= '<p>'._L('The RA does not want to publish their personal information.').'</p>'; |
167 | } else { |
167 | } else { |
168 | if (trim($row['street']) !== '') $out .= htmlentities($row['street']).'<br>'; |
168 | if (trim($row['street']) !== '') $out .= htmlentities($row['street']).'<br>'; |
169 | if (trim($row['zip_town']) !== '') $out .= htmlentities($row['zip_town']).'<br>'; |
169 | if (trim($row['zip_town']) !== '') $out .= htmlentities($row['zip_town']).'<br>'; |
170 | if (trim($row['country']) !== '') $out .= htmlentities($row['country']).'<br>'; |
170 | if (trim($row['country']) !== '') $out .= htmlentities($row['country']).'<br>'; |
171 | $out .= '<br>'; |
171 | $out .= '<br>'; |
172 | if (trim($row['phone']) !== '') $out .= _L('Phone: %1',htmlentities($row['phone'])).'<br>'; |
172 | if (trim($row['phone']) !== '') $out .= _L('Phone: %1',htmlentities($row['phone'])).'<br>'; |
173 | if (trim($row['fax']) !== '') $out .= _L('Fax: %1',htmlentities($row['fax'])).'<br>'; |
173 | if (trim($row['fax']) !== '') $out .= _L('Fax: %1',htmlentities($row['fax'])).'<br>'; |
174 | if (trim($row['mobile']) !== '') $out .= _L('Mobile: %1',htmlentities($row['mobile'])).'<br>'; |
174 | if (trim($row['mobile']) !== '') $out .= _L('Mobile: %1',htmlentities($row['mobile'])).'<br>'; |
175 | $out .= '<br>'; |
175 | $out .= '<br>'; |
176 | } |
176 | } |
177 | } |
177 | } |
178 | 178 | ||
179 | return trim_br($out); |
179 | return trim_br($out); |
180 | } |
180 | } |
181 | 181 | ||
182 | public function tree_search($request) { |
182 | public function tree_search($request) { |
183 | return false; |
183 | return false; |
184 | } |
184 | } |
185 | } |
185 | } |
186 | 186 |