Rev 1277 | Rev 1279 | 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 | |||
1131 | daniel-mar | 26 | class OIDplusPagePublicObjects extends OIDplusPagePluginPublic |
27 | implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1, /* oobeEntry, oobeRequested */ |
||
1278 | daniel-mar | 28 | INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2, /* modifyContent */ |
1265 | daniel-mar | 29 | INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8, /* getNotifications */ |
1275 | daniel-mar | 30 | INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9 /* restApi* */ |
1131 | daniel-mar | 31 | // Important: Do NOT implement INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7, because our getAlternativesForQuery() is the one that calls others! |
32 | { |
||
635 | daniel-mar | 33 | |
1116 | daniel-mar | 34 | /** |
1130 | daniel-mar | 35 | * @param string|OIDplusObject $ot |
1116 | daniel-mar | 36 | * @return string|null |
37 | */ |
||
38 | private function get_treeicon_root($ot)/*: ?string*/ { |
||
1127 | daniel-mar | 39 | $root = $ot::parse($ot::root()); |
40 | if (!$root) return null; |
||
41 | return $root->getIcon(); |
||
635 | daniel-mar | 42 | } |
43 | |||
1116 | daniel-mar | 44 | /** |
1130 | daniel-mar | 45 | * @param string $id |
46 | * @param string $old_ra |
||
47 | * @param string $new_ra |
||
1116 | daniel-mar | 48 | * @return void |
49 | * @throws OIDplusConfigInitializationException |
||
50 | * @throws OIDplusException |
||
51 | */ |
||
1130 | daniel-mar | 52 | private function ra_change_rec(string $id, string $old_ra, string $new_ra) { |
635 | daniel-mar | 53 | OIDplus::db()->query("update ###objects set ra_email = ?, updated = ".OIDplus::db()->sqlDate()." where id = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($new_ra, $id, $old_ra)); |
978 | daniel-mar | 54 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 55 | |
56 | $res = OIDplus::db()->query("select id from ###objects where parent = ? and ".OIDplus::db()->getSlang()->isNullFunction('ra_email',"''")." = ?", array($id, $old_ra)); |
||
57 | while ($row = $res->fetch_array()) { |
||
58 | $this->ra_change_rec($row['id'], $old_ra, $new_ra); |
||
59 | } |
||
60 | } |
||
61 | |||
1116 | daniel-mar | 62 | /** |
1278 | daniel-mar | 63 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2 |
64 | * @param string $id |
||
65 | * @param string $title |
||
66 | * @param string $icon |
||
67 | * @param string $text |
||
68 | * @return void |
||
69 | * @throws \ViaThinkSoft\OIDplus\OIDplusException |
||
70 | */ |
||
71 | public function modifyContent(string $id, string &$title, string &$icon, string &$text) { |
||
72 | // TODO: How can we achieve that RDAP, REST, WHOIS links are grouped together? |
||
73 | $text .= '<br /> <a href="'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE) |
||
74 | .'rest/v1/objects/'.htmlentities($id).'" class="gray_footer_font" target="_blank">'._L('REST API').'</a> ' |
||
75 | .'(<a '.OIDplus::gui()->link('oidplus:rest_api_information_admin$endpoints:1.3.6.1.4.1.37476.2.5.2.4.1.0').' class="gray_footer_font">'._L('Documentation').'</a>)'; |
||
76 | } |
||
77 | |||
78 | /** |
||
1265 | daniel-mar | 79 | * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9 |
80 | * @param string $requestMethod |
||
81 | * @param string $endpoint |
||
1275 | daniel-mar | 82 | * @param array $json_in |
1265 | daniel-mar | 83 | * @return array|false |
84 | */ |
||
1275 | daniel-mar | 85 | public function restApiCall(string $requestMethod, string $endpoint, array $json_in) { |
1265 | daniel-mar | 86 | if (str_starts_with($endpoint, 'objects/')) { |
87 | $id = substr($endpoint, strlen('objects/')); |
||
1269 | daniel-mar | 88 | if ($requestMethod == "GET"/*Select*/) { |
1271 | daniel-mar | 89 | $output = array(); |
90 | |||
91 | $res = OIDplus::db()->query("select id, ra_email, comment, confidential, title, description from ###objects where id = ?", array($id)); |
||
92 | if (!$res->any()) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404); |
||
93 | $row = $res->fetch_array(); |
||
94 | |||
95 | //$output['id'] = $row['id']; |
||
96 | $output['ra_email'] = $row['ra_email']; |
||
97 | $output['comment'] = $row['comment']; |
||
98 | $output['confidential'] = $row['confidential']; |
||
99 | $output['title'] = $row['title']; |
||
100 | $output['description'] = $row['description']; |
||
101 | |||
102 | $output['asn1ids'] = array(); |
||
103 | $res_asn = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($id)); |
||
104 | while ($row_asn = $res_asn->fetch_array()) { |
||
105 | $output['asn1ids'][] = $row_asn['name']; |
||
106 | } |
||
107 | |||
108 | $output['iris'] = array(); |
||
109 | $res_iri = OIDplus::db()->query("select name from ###iri where oid = ?", array($id)); |
||
110 | while ($row_iri = $res_iri->fetch_array()) { |
||
111 | $output['iris'][] = $row_iri['name']; |
||
112 | } |
||
113 | |||
1277 | daniel-mar | 114 | $output['status'] = 0/*OK*/; |
115 | $output['status_bits'] = []; |
||
1276 | daniel-mar | 116 | |
1271 | daniel-mar | 117 | http_response_code(200); |
118 | return $output; |
||
1269 | daniel-mar | 119 | } else if ($requestMethod == "PUT"/*Replace*/) { |
1271 | daniel-mar | 120 | $obj = OIDplusObject::parse($id); |
121 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'PUT', $id), null, 400); |
||
122 | |||
123 | $params = array(); |
||
124 | $params['id'] = $id; |
||
1275 | daniel-mar | 125 | $params['ra_email'] = $json_in['ra_email'] ?? ''; |
126 | $params['comment'] = $json_in['comment'] ?? ''; |
||
127 | $params['confidential'] = $json_in['confidential'] ?? false; |
||
128 | $params['title'] = $json_in['title'] ?? ''; |
||
129 | $params['description'] = $json_in['description'] ?? ''; |
||
130 | $params['asn1ids'] = $json_in['asn1ids'] ?? array(); |
||
131 | $params['iris'] = $json_in['iris'] ?? array(); |
||
1271 | daniel-mar | 132 | |
133 | if (OIDplusObject::exists($id)) { |
||
134 | // TODO: Problem: The superior RA cannot set title/description, so they cannot perform the PUT command! |
||
1277 | daniel-mar | 135 | $output = self::action('Update', $params); |
1271 | daniel-mar | 136 | } else { |
137 | $params['parent'] = $obj->getParent(); |
||
138 | $params['id_fully_qualified'] = true; |
||
1277 | daniel-mar | 139 | $output = self::action('Insert', $params); |
1271 | daniel-mar | 140 | } |
1276 | daniel-mar | 141 | |
1277 | daniel-mar | 142 | $output['status_bits'] = []; |
143 | if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited'; |
||
144 | if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
||
145 | if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
||
146 | if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID'; |
||
1276 | daniel-mar | 147 | |
1271 | daniel-mar | 148 | http_response_code(200); |
1277 | daniel-mar | 149 | return $output; |
1269 | daniel-mar | 150 | } else if ($requestMethod == "POST"/*Insert*/) { |
1275 | daniel-mar | 151 | $params = $json_in; |
1271 | daniel-mar | 152 | $obj = OIDplusObject::parse($id); |
153 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'GET', $id), null, 400); |
||
154 | $params['parent'] = $obj->getParent(); |
||
155 | $params['id_fully_qualified'] = true; |
||
1269 | daniel-mar | 156 | $params['id'] = $id; |
1277 | daniel-mar | 157 | $output = self::action('Insert', $params); |
1276 | daniel-mar | 158 | |
1277 | daniel-mar | 159 | $output['status_bits'] = []; |
160 | if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited'; |
||
161 | if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
||
162 | if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
||
163 | if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID'; |
||
1276 | daniel-mar | 164 | |
1269 | daniel-mar | 165 | http_response_code(200); |
1277 | daniel-mar | 166 | return $output; |
1268 | daniel-mar | 167 | } else if ($requestMethod == "PATCH"/*Modify*/) { |
1275 | daniel-mar | 168 | $params = $json_in; |
1268 | daniel-mar | 169 | $params['id'] = $id; |
1277 | daniel-mar | 170 | $output = self::action('Update', $params); |
1276 | daniel-mar | 171 | |
1277 | daniel-mar | 172 | $output['status_bits'] = []; |
173 | if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited'; |
||
174 | if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
||
175 | if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
||
176 | if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID'; |
||
1276 | daniel-mar | 177 | |
1268 | daniel-mar | 178 | http_response_code(200); |
1277 | daniel-mar | 179 | return $output; |
1269 | daniel-mar | 180 | } else if ($requestMethod == "DELETE"/*Delete*/) { |
1275 | daniel-mar | 181 | $params = $json_in; |
1269 | daniel-mar | 182 | $params['id'] = $id; |
1277 | daniel-mar | 183 | $output = self::action('Delete', $params); |
1276 | daniel-mar | 184 | |
1277 | daniel-mar | 185 | $output['status_bits'] = []; |
1276 | daniel-mar | 186 | |
1269 | daniel-mar | 187 | http_response_code(200); |
1277 | daniel-mar | 188 | return $output; |
1265 | daniel-mar | 189 | } else { |
1271 | daniel-mar | 190 | //throw new OIDplusException(_L("Not implemented"), null, 501); |
191 | throw new OIDplusException(_L("Unsupported request method"), null, 400); |
||
1265 | daniel-mar | 192 | } |
193 | } else { |
||
194 | return false; |
||
195 | } |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9 |
||
200 | * Outputs information about valid endpoints |
||
201 | * @param string $kind Reserved for different kind of output format (i.e. OpenAPI "TODO"). Currently only 'html' is implemented |
||
202 | * @return string |
||
203 | */ |
||
204 | public function restApiInfo(string $kind='html'): string { |
||
205 | if ($kind === 'html') { |
||
1271 | daniel-mar | 206 | $struct = [ |
1273 | daniel-mar | 207 | _L('Receive') => [ |
208 | '<b>GET</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>', |
||
1272 | daniel-mar | 209 | _L('Input parameters') => [ |
210 | '<i>'._L('None').'</i>' |
||
1271 | daniel-mar | 211 | ], |
1272 | daniel-mar | 212 | _L('Output parameters') => [ |
1275 | daniel-mar | 213 | 'status ('._L('<0 is error, >=0 is success').')', |
1276 | daniel-mar | 214 | 'status_bits', |
1275 | daniel-mar | 215 | 'error ('._L('if an error occurred').')', |
1272 | daniel-mar | 216 | 'ra_email', |
217 | 'comment', |
||
218 | 'iris', |
||
219 | 'asn1ids', |
||
220 | 'confidential', |
||
221 | 'title', |
||
222 | 'description' |
||
223 | ] |
||
224 | ], |
||
1273 | daniel-mar | 225 | _L('Re-Create') => [ |
226 | '<b>PUT</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>', |
||
1272 | daniel-mar | 227 | _L('Input parameters') => [ |
228 | 'ra_email ('._L('optional').')', |
||
229 | 'comment ('._L('optional').')', |
||
230 | 'iris ('._L('optional').')', |
||
231 | 'asn1ids ('._L('optional').')', |
||
232 | 'confidential ('._L('optional').')', |
||
233 | 'title ('._L('optional').')', |
||
234 | 'description ('._L('optional').')' |
||
1271 | daniel-mar | 235 | ], |
1272 | daniel-mar | 236 | _L('Output parameters') => [ |
1275 | daniel-mar | 237 | 'status ('._L('<0 is error, >=0 is success').')', |
1276 | daniel-mar | 238 | 'status_bits', |
1275 | daniel-mar | 239 | 'error ('._L('if an error occurred').')', |
1272 | daniel-mar | 240 | 'inserted_id ('._L('if it was created').')' |
241 | ] |
||
242 | ], |
||
1273 | daniel-mar | 243 | _L('Create') => [ |
244 | '<b>POST</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>', |
||
1272 | daniel-mar | 245 | _L('Input parameters') => [ |
246 | 'ra_email ('._L('optional').')', |
||
247 | 'comment ('._L('optional').')', |
||
248 | 'iris ('._L('optional').')', |
||
249 | 'asn1ids ('._L('optional').')', |
||
250 | 'confidential ('._L('optional').')', |
||
251 | 'title ('._L('optional').')', |
||
252 | 'description ('._L('optional').')' |
||
1271 | daniel-mar | 253 | ], |
1272 | daniel-mar | 254 | _L('Output parameters') => [ |
1275 | daniel-mar | 255 | 'status ('._L('<0 is error, >=0 is success').')', |
1276 | daniel-mar | 256 | 'status_bits', |
1275 | daniel-mar | 257 | 'error ('._L('if an error occurred').')', |
1272 | daniel-mar | 258 | 'inserted_id' |
259 | ] |
||
260 | ], |
||
1273 | daniel-mar | 261 | _L('Update') => [ |
262 | '<b>PATCH</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>', |
||
1272 | daniel-mar | 263 | _L('Input parameters') => [ |
264 | 'ra_email ('._L('optional').')', |
||
265 | 'comment ('._L('optional').')', |
||
266 | 'iris ('._L('optional').')', |
||
267 | 'asn1ids ('._L('optional').')', |
||
268 | 'confidential ('._L('optional').')', |
||
269 | 'title ('._L('optional').')', |
||
270 | 'description ('._L('optional').')' |
||
1271 | daniel-mar | 271 | ], |
1272 | daniel-mar | 272 | _L('Output parameters') => [ |
1275 | daniel-mar | 273 | 'status ('._L('<0 is error, >=0 is success').')', |
1276 | daniel-mar | 274 | 'status_bits', |
1275 | daniel-mar | 275 | 'error ('._L('if an error occurred').')', |
1271 | daniel-mar | 276 | ] |
1272 | daniel-mar | 277 | ], |
1273 | daniel-mar | 278 | _L('Remove') => [ |
1276 | daniel-mar | 279 | '<b>DELETE</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>', |
1272 | daniel-mar | 280 | _L('Input parameters') => [ |
281 | '<i>'._L('None').'</i>' |
||
282 | ], |
||
283 | _L('Output parameters') => [ |
||
1275 | daniel-mar | 284 | 'status ('._L('<0 is error, >=0 is success').')', |
1276 | daniel-mar | 285 | 'status_bits', |
1275 | daniel-mar | 286 | 'error ('._L('if an error occurred').')', |
1272 | daniel-mar | 287 | ] |
1271 | daniel-mar | 288 | ] |
289 | ]; |
||
1276 | daniel-mar | 290 | return array_to_html_ul_li($struct); |
1265 | daniel-mar | 291 | } else { |
1271 | daniel-mar | 292 | throw new OIDplusException(_L('Invalid REST API information format'), null, 500); |
1265 | daniel-mar | 293 | } |
294 | } |
||
295 | |||
296 | /** |
||
1116 | daniel-mar | 297 | * @param string $actionID |
298 | * @param array $params |
||
1143 | daniel-mar | 299 | * @return array |
1116 | daniel-mar | 300 | * @throws OIDplusConfigInitializationException |
301 | * @throws OIDplusException |
||
302 | */ |
||
303 | public function action(string $actionID, array $params): array { |
||
635 | daniel-mar | 304 | |
305 | // Action: Delete |
||
306 | // Parameters: id |
||
307 | // Outputs: <0 Error, =0 Success |
||
308 | if ($actionID == 'Delete') { |
||
309 | _CheckParamExists($params, 'id'); |
||
310 | $id = $params['id']; |
||
311 | $obj = OIDplusObject::parse($id); |
||
1116 | daniel-mar | 312 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id)); |
635 | daniel-mar | 313 | |
977 | daniel-mar | 314 | if (!OIDplusObject::exists($id)) { |
1271 | daniel-mar | 315 | throw new OIDplusException(_L('Object %1 does not exist',$id), null, 404); |
635 | daniel-mar | 316 | } |
317 | |||
318 | // Check if permitted |
||
1266 | daniel-mar | 319 | if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to delete this OID.'), null, 401); |
635 | daniel-mar | 320 | |
1005 | daniel-mar | 321 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 322 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
323 | $plugin->beforeObjectDelete($id); |
||
635 | daniel-mar | 324 | } |
325 | } |
||
326 | |||
1267 | daniel-mar | 327 | OIDplus::logger()->log("V2:[WARN]OID(%1)+[OK/WARN]SUPOIDRA(%1)+[OK/INFO]A", "Object '%1' (recursively) deleted", $id); |
328 | OIDplus::logger()->log("V2:[CRIT]OIDRA(%1)", "Lost ownership of object '%1' because it was deleted", $id); |
||
635 | daniel-mar | 329 | |
330 | if ($parentObj = $obj->getParent()) { |
||
331 | $parent_oid = $parentObj->nodeId(); |
||
1267 | daniel-mar | 332 | OIDplus::logger()->log("V2:[WARN]OID(%2)", "Object '%1' (recursively) deleted", $id, $parent_oid); |
635 | daniel-mar | 333 | } |
334 | |||
335 | // Delete object |
||
336 | OIDplus::db()->query("delete from ###objects where id = ?", array($id)); |
||
978 | daniel-mar | 337 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 338 | |
339 | // Delete orphan stuff |
||
340 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
341 | do { |
||
342 | $res = OIDplus::db()->query("select tchild.id from ###objects tchild " . |
||
343 | "left join ###objects tparent on tparent.id = tchild.parent " . |
||
344 | "where tchild.parent <> ? and tchild.id like ? and tparent.id is null;", array($ot::root(), $ot::root().'%')); |
||
790 | daniel-mar | 345 | if (!$res->any()) break; |
635 | daniel-mar | 346 | |
347 | while ($row = $res->fetch_array()) { |
||
348 | $id_to_delete = $row['id']; |
||
1267 | daniel-mar | 349 | OIDplus::logger()->log("V2:[CRIT]OIDRA(%2)", "Lost ownership of object '%2' because one of the superior objects ('%1') was recursively deleted", $id, $id_to_delete); |
635 | daniel-mar | 350 | OIDplus::db()->query("delete from ###objects where id = ?", array($id_to_delete)); |
978 | daniel-mar | 351 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 352 | } |
353 | } while (true); |
||
354 | } |
||
355 | OIDplus::db()->query("delete from ###asn1id where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false)); |
||
356 | OIDplus::db()->query("delete from ###iri where well_known = ? and oid not in (select id from ###objects where id like 'oid:%')", array(false)); |
||
357 | |||
1005 | daniel-mar | 358 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 359 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
360 | $plugin->afterObjectDelete($id); |
||
635 | daniel-mar | 361 | } |
362 | } |
||
363 | |||
364 | return array("status" => 0); |
||
365 | } |
||
366 | |||
367 | // Action: Update |
||
1269 | daniel-mar | 368 | // Parameters: id, ra_email, comment, iris, asn1ids, confidential, title, description |
635 | daniel-mar | 369 | // Outputs: <0 Error, =0 Success, with following bitfields for further information: |
1276 | daniel-mar | 370 | // x+1 = RA is not registered, but it can be invited |
371 | // x+2 = RA is not registered and it cannot be invited |
||
372 | // x+4 = OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset |
||
1269 | daniel-mar | 373 | // x+8 = User has write rights to the freshly created OID |
635 | daniel-mar | 374 | else if ($actionID == 'Update') { |
375 | _CheckParamExists($params, 'id'); |
||
376 | $id = $params['id']; |
||
377 | $obj = OIDplusObject::parse($id); |
||
1116 | daniel-mar | 378 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id)); |
635 | daniel-mar | 379 | |
977 | daniel-mar | 380 | if (!OIDplusObject::exists($id)) { |
1271 | daniel-mar | 381 | throw new OIDplusException(_L('Object %1 does not exist',$id), null, 404); |
635 | daniel-mar | 382 | } |
383 | |||
384 | // Check if permitted |
||
1269 | daniel-mar | 385 | if (isset($params['title']) || isset($params['description'])) { |
386 | if (!$obj->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the RA to update this OID.'), null, 401); |
||
387 | } |
||
388 | if (isset($params['ra_email']) || isset($params['comment']) || isset($params['iris']) || isset($params['asn1ids']) || isset($params['confidential'])) { |
||
389 | if (!$obj->userHasParentalWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the superior RA to update this OID.'), null, 401); |
||
390 | } |
||
635 | daniel-mar | 391 | |
1005 | daniel-mar | 392 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 393 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
394 | $plugin->beforeObjectUpdateSuperior($id, $params); |
||
635 | daniel-mar | 395 | } |
396 | } |
||
397 | |||
398 | // First, do a simulation for ASN.1 IDs and IRIs to check if there are any problems (then an Exception will be thrown) |
||
399 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 400 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 401 | if (!$obj->isWellKnown()) { |
402 | if (isset($params['iris'])) { |
||
1271 | daniel-mar | 403 | $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris'])); |
635 | daniel-mar | 404 | $ids = array_map('trim',$ids); |
405 | $obj->replaceIris($ids, true); |
||
406 | } |
||
407 | |||
408 | if (isset($params['asn1ids'])) { |
||
1271 | daniel-mar | 409 | $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids'])); |
635 | daniel-mar | 410 | $ids = array_map('trim',$ids); |
411 | $obj->replaceAsn1Ids($ids, true); |
||
412 | } |
||
413 | } |
||
414 | } |
||
415 | |||
416 | // RA E-Mail change |
||
417 | if (isset($params['ra_email'])) { |
||
418 | // Validate RA email address |
||
1137 | daniel-mar | 419 | $new_ra = $params['ra_email'] ?? ''; |
635 | daniel-mar | 420 | if ($obj::ns() == 'oid') { |
1116 | daniel-mar | 421 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 422 | if ($obj->isWellKnown()) { |
423 | $new_ra = ''; |
||
424 | } |
||
425 | } |
||
426 | if (!empty($new_ra) && !OIDplus::mailUtils()->validMailAddress($new_ra)) { |
||
427 | throw new OIDplusException(_L('Invalid RA email address')); |
||
428 | } |
||
429 | |||
430 | // Change RA recursively |
||
1130 | daniel-mar | 431 | $current_ra = $obj->getRaMail() ?? ''; |
977 | daniel-mar | 432 | if ($new_ra != $current_ra) { |
1267 | daniel-mar | 433 | OIDplus::logger()->log("V2:[INFO]OID(%1)+[OK/INFO]SUPOIDRA(%1)+[OK/INFO]A", "RA of object '%1' changed from '%2' to '%3'", $id, $current_ra, $new_ra); |
1275 | daniel-mar | 434 | if (!empty($current_ra)) OIDplus::logger()->log("V2:[WARN]RA(%2)", "Lost ownership of object '%1' due to RA transfer of superior RA / admin.", $id, $current_ra, $new_ra); |
435 | if (!empty($new_ra)) OIDplus::logger()->log("V2:[INFO]RA(%3)", "Gained ownership of object '%1' due to RA transfer of superior RA / admin.", $id, $current_ra, $new_ra); |
||
977 | daniel-mar | 436 | if ($parentObj = $obj->getParent()) { |
437 | $parent_oid = $parentObj->nodeId(); |
||
1267 | daniel-mar | 438 | OIDplus::logger()->log("V2:[INFO]OID(%4)", "RA of object '%1' changed from '%2' to '%3'", $id, $current_ra, $new_ra, $parent_oid); |
635 | daniel-mar | 439 | } |
977 | daniel-mar | 440 | $this->ra_change_rec($id, $current_ra, $new_ra); // Recursively change inherited RAs |
635 | daniel-mar | 441 | } |
442 | } |
||
443 | |||
444 | // Log if confidentially flag was changed |
||
1267 | daniel-mar | 445 | OIDplus::logger()->log("V2:[INFO]OID(%1)+[OK/INFO]SUPOIDRA(%1)+[OK/INFO]A", "Identifiers/Confidential flag of object '%1' updated", $id); // TODO: Check if they were ACTUALLY updated! |
635 | daniel-mar | 446 | if ($parentObj = $obj->getParent()) { |
447 | $parent_oid = $parentObj->nodeId(); |
||
1267 | daniel-mar | 448 | OIDplus::logger()->log("V2:[INFO]OID(%2)", "Identifiers/Confidential flag of object '%1' updated", $id, $parent_oid); // TODO: Check if they were ACTUALLY updated! |
635 | daniel-mar | 449 | } |
450 | |||
451 | // Replace ASN.1 IDs und IRIs |
||
452 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 453 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 454 | if (!$obj->isWellKnown()) { |
455 | if (isset($params['iris'])) { |
||
1271 | daniel-mar | 456 | $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris'])); |
635 | daniel-mar | 457 | $ids = array_map('trim',$ids); |
458 | $obj->replaceIris($ids, false); |
||
459 | } |
||
460 | |||
461 | if (isset($params['asn1ids'])) { |
||
1271 | daniel-mar | 462 | $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids'])); |
635 | daniel-mar | 463 | $ids = array_map('trim',$ids); |
464 | $obj->replaceAsn1Ids($ids, false); |
||
465 | } |
||
466 | } |
||
467 | |||
468 | // TODO: Check if any identifiers have been actually changed, |
||
469 | // and log it to OID($id), OID($parent), ... (see above) |
||
470 | } |
||
471 | |||
472 | if (isset($params['confidential'])) { |
||
473 | $confidential = $params['confidential'] == 'true'; |
||
474 | OIDplus::db()->query("UPDATE ###objects SET confidential = ? WHERE id = ?", array($confidential, $id)); |
||
978 | daniel-mar | 475 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 476 | } |
477 | |||
478 | if (isset($params['comment'])) { |
||
479 | $comment = $params['comment']; |
||
480 | OIDplus::db()->query("UPDATE ###objects SET comment = ? WHERE id = ?", array($comment, $id)); |
||
978 | daniel-mar | 481 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 482 | } |
483 | |||
1269 | daniel-mar | 484 | if (isset($params['title']) || isset($params['description'])) { |
485 | OIDplus::logger()->log("V2:[INFO]OID(%1)+[OK/INFO]OIDRA(%1)+[OK/INFO]A", "Title/Description of object '%1' updated", $id); |
||
486 | } |
||
487 | |||
488 | if (isset($params['title'])) { |
||
489 | $title = $params['title']; |
||
490 | OIDplus::db()->query("UPDATE ###objects SET title = ? WHERE id = ?", array($title, $id)); |
||
491 | OIDplusObject::resetObjectInformationCache(); |
||
492 | } |
||
493 | |||
494 | if (isset($params['description'])) { |
||
495 | $description = $params['description']; |
||
496 | OIDplus::db()->query("UPDATE ###objects SET description = ? WHERE id = ?", array($description, $id)); |
||
497 | OIDplusObject::resetObjectInformationCache(); |
||
498 | } |
||
499 | |||
635 | daniel-mar | 500 | OIDplus::db()->query("UPDATE ###objects SET updated = ".OIDplus::db()->sqlDate()." WHERE id = ?", array($id)); |
978 | daniel-mar | 501 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 502 | |
503 | $status = 0; |
||
504 | |||
505 | if (!empty($new_ra)) { |
||
506 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($new_ra)); |
||
507 | $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite |
||
790 | daniel-mar | 508 | if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2; |
635 | daniel-mar | 509 | } |
510 | |||
511 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 512 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 513 | if ($obj->isWellKnown()) { |
514 | $status += 4; |
||
515 | } |
||
516 | } |
||
517 | |||
1269 | daniel-mar | 518 | if ($obj->userHasWriteRights()) { |
519 | $status += 8; |
||
520 | } |
||
521 | |||
1005 | daniel-mar | 522 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 523 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
524 | $plugin->afterObjectUpdateSuperior($id, $params); |
||
635 | daniel-mar | 525 | } |
526 | } |
||
527 | |||
528 | return array("status" => $status); |
||
529 | } |
||
530 | |||
531 | // Generate UUID |
||
532 | else if ($actionID == 'generate_uuid') { |
||
1259 | daniel-mar | 533 | $uuid = gen_uuid(OIDplus::config()->getValue('uuid_prefer_timebased', '1') == '1'); |
635 | daniel-mar | 534 | if (!$uuid) return array("status" => 1); |
535 | return array( |
||
536 | "status" => 0, |
||
537 | "uuid" => $uuid, |
||
538 | "intval" => substr(uuid_to_oid($uuid),strlen('2.25.')) |
||
539 | ); |
||
540 | } |
||
541 | |||
542 | // Action: Insert |
||
1271 | daniel-mar | 543 | // Parameters: parent, id (relative!), ra_email, comment, iris, asn1ids, confidential, title, description |
635 | daniel-mar | 544 | // Outputs: status=<0 Error, =0 Success, with following bitfields for further information: |
1276 | daniel-mar | 545 | // x+1 = RA is not registered, but it can be invited |
546 | // x+2 = RA is not registered and it cannot be invited |
||
547 | // x+4 = OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset |
||
1269 | daniel-mar | 548 | // x+8 = User has write rights to the freshly created OID |
635 | daniel-mar | 549 | else if ($actionID == 'Insert') { |
550 | // Check if you have write rights on the parent (to create a new object) |
||
551 | _CheckParamExists($params, 'parent'); |
||
552 | $objParent = OIDplusObject::parse($params['parent']); |
||
1116 | daniel-mar | 553 | if (!$objParent) throw new OIDplusException(_L('%1 action failed because parent object "%2" cannot be parsed!','INSERT',$params['parent'])); |
635 | daniel-mar | 554 | |
977 | daniel-mar | 555 | if (!$objParent->isRoot()) { |
556 | $idParent = $objParent->nodeId(); |
||
557 | if (!OIDplusObject::exists($idParent)) { |
||
1271 | daniel-mar | 558 | throw new OIDplusException(_L('Parent object %1 does not exist',$idParent), null, 404); |
977 | daniel-mar | 559 | } |
635 | daniel-mar | 560 | } |
561 | |||
1266 | daniel-mar | 562 | if (!$objParent->userHasWriteRights()) throw new OIDplusException(_L('Authentication error. Please log in as the correct RA to insert an OID at this arc.'), null, 401); |
635 | daniel-mar | 563 | |
564 | // Check if the ID is valid |
||
565 | _CheckParamExists($params, 'id'); |
||
566 | if ($params['id'] == '') throw new OIDplusException(_L('ID may not be empty')); |
||
567 | |||
772 | daniel-mar | 568 | // For the root objects, let the user also enter a WEID |
569 | if ($objParent::ns() == 'oid') { |
||
1116 | daniel-mar | 570 | assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
772 | daniel-mar | 571 | if (strtolower(substr(trim($params['id']),0,5)) === 'weid:') { |
572 | if ($objParent->isRoot()) { |
||
1050 | daniel-mar | 573 | $params['id'] = \Frdl\Weid\WeidOidConverter::weid2oid($params['id']); |
772 | daniel-mar | 574 | if ($params['id'] === false) { |
575 | throw new OIDplusException(_L('Invalid WEID')); |
||
576 | } |
||
577 | } else { |
||
578 | throw new OIDplusException(_L('You can use the WEID syntax only at your object tree root.')); |
||
579 | } |
||
580 | } |
||
581 | } |
||
582 | |||
635 | daniel-mar | 583 | // Determine absolute OID name |
584 | // Note: At addString() and parse(), the syntax of the ID will be checked |
||
1271 | daniel-mar | 585 | if ($params['id_fully_qualified'] ?? false) { |
586 | $id = $params['id']; |
||
587 | $obj = OIDplusObject::parse($id); |
||
588 | $objParentTest = $obj->getParent(); |
||
589 | if (!$objParentTest || !$objParentTest->equals($objParent)) throw new OIDplusException(_L('Cannot verify that %1 has parent %2', $obj->nodeId(), $objParent->nodeId())); |
||
590 | } else { |
||
591 | $id = $objParent->addString($params['id']); |
||
592 | $obj = OIDplusObject::parse($id); |
||
593 | } |
||
594 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id)); |
||
635 | daniel-mar | 595 | |
596 | // Check, if the OID exists |
||
977 | daniel-mar | 597 | if (OIDplusObject::exists($id)) { |
635 | daniel-mar | 598 | throw new OIDplusException(_L('Object %1 already exists!',$id)); |
599 | } |
||
600 | |||
1005 | daniel-mar | 601 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 602 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
603 | $plugin->beforeObjectInsert($id, $params); |
||
635 | daniel-mar | 604 | } |
605 | } |
||
606 | |||
607 | // First simulate if there are any problems of ASN.1 IDs und IRIs |
||
608 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 609 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 610 | if (!$obj->isWellKnown()) { |
611 | if (isset($params['iris'])) { |
||
1271 | daniel-mar | 612 | $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris'])); |
635 | daniel-mar | 613 | $ids = array_map('trim',$ids); |
614 | $obj->replaceIris($ids, true); |
||
615 | } |
||
616 | |||
617 | if (isset($params['asn1ids'])) { |
||
1271 | daniel-mar | 618 | $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids'])); |
635 | daniel-mar | 619 | $ids = array_map('trim',$ids); |
620 | $obj->replaceAsn1Ids($ids, true); |
||
621 | } |
||
622 | } |
||
623 | } |
||
624 | |||
625 | // Apply superior RA change |
||
626 | $parent = $params['parent']; |
||
1130 | daniel-mar | 627 | $ra_email = $params['ra_email'] ?? ''; |
635 | daniel-mar | 628 | if ($obj::ns() == 'oid') { |
1116 | daniel-mar | 629 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 630 | if ($obj->isWellKnown()) { |
631 | $ra_email = ''; |
||
632 | } |
||
633 | } |
||
634 | if (!empty($ra_email) && !OIDplus::mailUtils()->validMailAddress($ra_email)) { |
||
635 | throw new OIDplusException(_L('Invalid RA email address')); |
||
636 | } |
||
637 | |||
1199 | daniel-mar | 638 | if (empty($ra_email)) { |
1267 | daniel-mar | 639 | OIDplus::logger()->log("V2:[INFO]OID(%2)+[INFO]OID(%1)+[OK/INFO]OIDRA(%2)+[OK/INFO]A", "Object '%1' created, without defined RA, superior object is '%2'", $id, $parent); |
1199 | daniel-mar | 640 | } else { |
1267 | daniel-mar | 641 | OIDplus::logger()->log("V2:[INFO]OID(%2)+[INFO]OID(%1)+[OK/INFO]OIDRA(%2)+[OK/INFO]A", "Object '%1' created, given to RA '%3', superior object is '%2'", $id, $parent, $ra_email); |
1199 | daniel-mar | 642 | } |
635 | daniel-mar | 643 | if (!empty($ra_email)) { |
1267 | daniel-mar | 644 | OIDplus::logger()->log("V2:[INFO]RA(%2)", "Gained ownership of newly created object '%1'", $id, $ra_email); |
635 | daniel-mar | 645 | } |
646 | |||
1130 | daniel-mar | 647 | $confidential = isset($params['confidential']) && $params['confidential'] == 'true'; |
648 | $comment = $params['comment'] ?? ''; |
||
1271 | daniel-mar | 649 | $title = $params['title'] ?? ''; // This is very special (only useable in REST API): The superior RA can set the title during creation, even if they lose their ownership by delegating afterwards! |
650 | $description = $params['description'] ?? ''; // This is very special (only useable in REST API): The superior RA can set the title during creation, even if they lose their ownership by delegating afterwards! |
||
635 | daniel-mar | 651 | |
652 | if (strlen($id) > OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH')) { |
||
653 | $maxlen = OIDplus::baseConfig()->getValue('LIMITS_MAX_ID_LENGTH'); |
||
654 | throw new OIDplusException(_L('The identifier %1 is too long (max allowed length: %2)',$id,$maxlen)); |
||
655 | } |
||
656 | |||
657 | OIDplus::db()->query("INSERT INTO ###objects (id, parent, ra_email, confidential, comment, created, title, description) VALUES (?, ?, ?, ?, ?, ".OIDplus::db()->sqlDate().", ?, ?)", array($id, $parent, $ra_email, $confidential, $comment, $title, $description)); |
||
978 | daniel-mar | 658 | OIDplusObject::resetObjectInformationCache(); |
635 | daniel-mar | 659 | |
660 | // Set ASN.1 IDs und IRIs |
||
661 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 662 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 663 | if (!$obj->isWellKnown()) { |
664 | if (isset($params['iris'])) { |
||
1271 | daniel-mar | 665 | $ids = ($params['iris'] == '') ? array() : (is_array($params['iris']) ? $params['iris'] : explode(',',$params['iris'])); |
635 | daniel-mar | 666 | $ids = array_map('trim',$ids); |
667 | $obj->replaceIris($ids, false); |
||
668 | } |
||
669 | |||
670 | if (isset($params['asn1ids'])) { |
||
1271 | daniel-mar | 671 | $ids = ($params['asn1ids'] == '') ? array() : (is_array($params['asn1ids']) ? $params['asn1ids'] : explode(',',$params['asn1ids'])); |
635 | daniel-mar | 672 | $ids = array_map('trim',$ids); |
673 | $obj->replaceAsn1Ids($ids, false); |
||
674 | } |
||
675 | } |
||
676 | } |
||
677 | |||
678 | $status = 0; |
||
679 | |||
680 | if (!empty($ra_email)) { |
||
681 | // Do we need to notify that the RA does not exist? |
||
682 | $res = OIDplus::db()->query("select ra_name from ###ra where email = ?", array($ra_email)); |
||
683 | $invitePlugin = OIDplus::getPluginByOid('1.3.6.1.4.1.37476.2.5.2.4.2.92'); // OIDplusPageRaInvite |
||
790 | daniel-mar | 684 | if (!$res->any()) $status = !is_null($invitePlugin) && OIDplus::config()->getValue('ra_invitation_enabled') ? 1 : 2; |
635 | daniel-mar | 685 | } |
686 | |||
687 | if ($obj::ns() == 'oid') { |
||
1116 | daniel-mar | 688 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
635 | daniel-mar | 689 | if ($obj->isWellKnown()) { |
690 | $status += 4; |
||
691 | } |
||
692 | } |
||
693 | |||
1269 | daniel-mar | 694 | if ($obj->userHasWriteRights()) { |
695 | $status += 8; |
||
696 | } |
||
697 | |||
1005 | daniel-mar | 698 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 699 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_3) { |
700 | $plugin->afterObjectInsert($id, $params); |
||
635 | daniel-mar | 701 | } |
702 | } |
||
703 | |||
704 | return array( |
||
705 | "status" => $status, |
||
706 | "inserted_id" => $id |
||
707 | ); |
||
708 | } else { |
||
1116 | daniel-mar | 709 | return parent::action($actionID, $params); |
635 | daniel-mar | 710 | } |
711 | } |
||
712 | |||
1116 | daniel-mar | 713 | /** |
714 | * @param bool $html |
||
715 | * @return void |
||
716 | * @throws OIDplusException |
||
717 | */ |
||
718 | public function init(bool $html=true) { |
||
635 | daniel-mar | 719 | OIDplus::config()->prepareConfigKey('oobe_objects_done', '"Out Of Box Experience" wizard for OIDplusPagePublicObjects done once?', '0', OIDplusConfig::PROTECTION_HIDDEN, function($value) {}); |
693 | daniel-mar | 720 | OIDplus::config()->prepareConfigKey('oid_grid_show_weid', 'Show WEID/Base36 column in CRUD grid of OIDs?', '1', OIDplusConfig::PROTECTION_EDITABLE, function($value) { |
721 | if (!is_numeric($value) || ($value < 0) || ($value > 1)) { |
||
722 | throw new OIDplusException(_L('Please enter a valid value (0=no, 1=yes).')); |
||
723 | } |
||
724 | }); |
||
1259 | daniel-mar | 725 | OIDplus::config()->prepareConfigKey('uuid_prefer_timebased', 'Preferred UUID Generator version? 1=Timebased (Very secure, but reveals the MAC address of the server); 4=Random (has a very, very tiny change to generate duplicates)', '1', OIDplusConfig::PROTECTION_HIDDEN, function($value) { |
726 | if (($value != '1') && ($value != '4')) { |
||
727 | throw new OIDplusException(_L('Please enter a valid value (1=Timebased, 4=Random).')); |
||
728 | } |
||
729 | }); |
||
635 | daniel-mar | 730 | } |
731 | |||
1116 | daniel-mar | 732 | /** |
1130 | daniel-mar | 733 | * @param string $id |
734 | * @param array $out |
||
1116 | daniel-mar | 735 | * @return array|false |
736 | * @throws OIDplusException |
||
737 | */ |
||
1130 | daniel-mar | 738 | private function tryObject(string $id, array &$out) { |
951 | daniel-mar | 739 | $parent = null; |
740 | $res = null; |
||
741 | $row = null; |
||
954 | daniel-mar | 742 | $obj = OIDplusObject::parse($id); |
1116 | daniel-mar | 743 | if (!$obj) return false; |
954 | daniel-mar | 744 | if ($obj->isRoot()) { |
745 | $obj->getContentPage($out['title'], $out['text'], $out['icon']); |
||
977 | daniel-mar | 746 | $objParent = null; // $obj->getParent(); |
954 | daniel-mar | 747 | } else { |
977 | daniel-mar | 748 | $obj = OIDplusObject::findFitting($id); // this time, the object will be found, not just the object type |
749 | if (!$obj) { |
||
954 | daniel-mar | 750 | return false; |
751 | } else { |
||
752 | $obj->getContentPage($out['title'], $out['text'], $out['icon']); |
||
1261 | daniel-mar | 753 | if (empty($out['title'])) $out['title'] = $obj->defaultTitle(); |
954 | daniel-mar | 754 | if (empty($out['title'])) $out['title'] = explode(':',$obj->nodeId(),2)[1]; |
977 | daniel-mar | 755 | $objParent = $obj->getParent(); |
953 | daniel-mar | 756 | } |
951 | daniel-mar | 757 | } |
977 | daniel-mar | 758 | return array($id, $obj, $objParent); |
951 | daniel-mar | 759 | } |
760 | |||
1116 | daniel-mar | 761 | /** |
1130 | daniel-mar | 762 | * @param string $id |
1116 | daniel-mar | 763 | * @return array |
764 | */ |
||
1130 | daniel-mar | 765 | public static function getAlternativesForQuery(string $id): array { |
1131 | daniel-mar | 766 | // Attention: This is NOT an implementation of INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7! |
767 | // This is the function that calls getAlternativesForQuery() of every plugin that implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7 |
||
968 | daniel-mar | 768 | |
951 | daniel-mar | 769 | // e.g. used for "Reverse Alt Id" |
770 | $alternatives = array(); |
||
1005 | daniel-mar | 771 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 772 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_7) { |
773 | $tmp = $plugin->getAlternativesForQuery($id); |
||
951 | daniel-mar | 774 | if (is_array($tmp)) { |
775 | $alternatives = array_merge($tmp, $alternatives); |
||
776 | } |
||
777 | } |
||
778 | } |
||
968 | daniel-mar | 779 | |
780 | // If something is more than one time, remove it |
||
951 | daniel-mar | 781 | $alternatives = array_unique($alternatives); |
968 | daniel-mar | 782 | |
783 | // If a plugin accidentally added the own ID, remove it. This function lists only alternatives, not the own ID |
||
784 | $alternatives_tmp = array(); |
||
785 | foreach ($alternatives as $alt) { |
||
786 | if ($alt !== $id) $alternatives_tmp[] = $alt; |
||
787 | } |
||
1130 | daniel-mar | 788 | return $alternatives_tmp; |
951 | daniel-mar | 789 | } |
790 | |||
1116 | daniel-mar | 791 | /** |
792 | * @param string $id |
||
793 | * @param array $out |
||
794 | * @param bool $handled |
||
795 | * @return void |
||
796 | * @throws OIDplusConfigInitializationException |
||
797 | * @throws OIDplusException |
||
798 | */ |
||
799 | public function gui(string $id, array &$out, bool &$handled) { |
||
635 | daniel-mar | 800 | if ($id === 'oidplus:system') { |
801 | $handled = true; |
||
802 | |||
803 | $out['title'] = OIDplus::config()->getValue('system_title'); |
||
801 | daniel-mar | 804 | $out['icon'] = OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon.png'; |
635 | daniel-mar | 805 | |
806 | if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html')) { |
||
807 | $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome$'.OIDplus::getCurrentLang().'.html'); |
||
808 | } else if (file_exists(OIDplus::localpath() . 'userdata/welcome/welcome.html')) { |
||
809 | $cont = file_get_contents(OIDplus::localpath() . 'userdata/welcome/welcome.html'); |
||
810 | } else if (file_exists(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html')) { |
||
811 | $cont = file_get_contents(__DIR__ . '/welcome$'.OIDplus::getCurrentLang().'.html'); |
||
812 | } else if (file_exists(__DIR__ . '/welcome.html')) { |
||
813 | $cont = file_get_contents(__DIR__ . '/welcome.html'); |
||
814 | } else { |
||
815 | $cont = ''; |
||
816 | } |
||
817 | |||
1143 | daniel-mar | 818 | if ($cont) { |
819 | list($html, $js, $css) = extractHtmlContents($cont); |
||
820 | $cont = ''; |
||
821 | if (!empty($js)) $cont .= "<script>\n$js\n</script>"; |
||
822 | if (!empty($css)) $cont .= "<style>\n$css\n</style>"; |
||
823 | $cont .= stripHtmlComments($html); |
||
824 | } |
||
635 | daniel-mar | 825 | |
826 | $out['text'] = $cont; |
||
827 | |||
828 | if (strpos($out['text'], '%%OBJECT_TYPE_LIST%%') !== false) { |
||
829 | $tmp = '<ul>'; |
||
830 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
831 | $tmp .= '<li><a '.OIDplus::gui()->link($ot::root()).'>'.htmlentities($ot::objectTypeTitle()).'</a></li>'; |
||
832 | } |
||
833 | $tmp .= '</ul>'; |
||
834 | $out['text'] = str_replace('%%OBJECT_TYPE_LIST%%', $tmp, $out['text']); |
||
835 | } |
||
836 | } |
||
837 | |||
957 | daniel-mar | 838 | // Never answer to an object type that is called 'oidplus:', |
839 | // otherwise, an object type plugin could break the whole system! |
||
840 | else if ((strpos($id,':') !== false) && (!str_starts_with($id,'oidplus:'))) { |
||
635 | daniel-mar | 841 | |
955 | daniel-mar | 842 | // --- Try to find the object or an alternative |
635 | daniel-mar | 843 | |
951 | daniel-mar | 844 | $test = $this->tryObject($id, $out); |
845 | if ($test === false) { |
||
955 | daniel-mar | 846 | // try to find an alternative |
952 | daniel-mar | 847 | $alternatives = $this->getAlternativesForQuery($id); |
951 | daniel-mar | 848 | foreach ($alternatives as $alternative) { |
849 | $test = $this->tryObject($alternative, $out); |
||
955 | daniel-mar | 850 | if ($test !== false) break; // found something |
635 | daniel-mar | 851 | } |
852 | } |
||
955 | daniel-mar | 853 | if ($test !== false) { |
977 | daniel-mar | 854 | list($id, $obj, $objParent) = $test; |
1132 | daniel-mar | 855 | } else { |
856 | $objParent = null; // to avoid warnings |
||
955 | daniel-mar | 857 | } |
858 | |||
859 | // --- If the object type is disabled or not an object at all (e.g. "oidplus:"), then $handled=false |
||
860 | // If the object type is enabled but object not found, $handled=true |
||
861 | |||
970 | daniel-mar | 862 | $obj = OIDplusObject::parse($id); |
955 | daniel-mar | 863 | |
951 | daniel-mar | 864 | if ($test === false) { |
1116 | daniel-mar | 865 | if (!$obj) { |
955 | daniel-mar | 866 | // Object type disabled or not known (e.g. ObjectType "oidplus:"). |
867 | $handled = false; |
||
868 | return; |
||
869 | } else { |
||
870 | // Object type enabled but identifier not in database |
||
871 | $handled = true; |
||
872 | if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box |
||
873 | http_response_code(404); |
||
874 | } |
||
1206 | daniel-mar | 875 | throw new OIDplusHtmlException(_L('The object %1 was not found in this database.','<code>'.htmlentities($id).'</code>'), _L('Object not found')); |
955 | daniel-mar | 876 | } |
877 | } else { |
||
878 | $handled = true; |
||
879 | } |
||
880 | |||
881 | unset($test); |
||
882 | |||
883 | // --- If found, do we have read rights? |
||
884 | |||
885 | if (!$obj->userHasReadRights()) { |
||
843 | daniel-mar | 886 | if (isset($_SERVER['SCRIPT_FILENAME']) && (strtolower(basename($_SERVER['SCRIPT_FILENAME'])) !== 'ajax.php')) { // don't send HTTP error codes in ajax.php, because we want a page and not a JavaScript alert box, when someone enters an invalid OID in the GoTo-Box |
955 | daniel-mar | 887 | http_response_code(403); |
843 | daniel-mar | 888 | } |
1266 | daniel-mar | 889 | throw new OIDplusHtmlException(_L('Please <a %1>log in</a> to receive information about this object.',OIDplus::gui()->link('oidplus:login')), _L('Access denied'), 401); |
635 | daniel-mar | 890 | } |
891 | |||
892 | // --- |
||
893 | |||
977 | daniel-mar | 894 | if ($objParent) { |
895 | if ($objParent->isRoot()) { |
||
896 | $parent_link_text = $objParent->objectTypeTitle(); |
||
897 | $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->root()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text']; |
||
635 | daniel-mar | 898 | } else { |
977 | daniel-mar | 899 | $parent_title = $objParent->getTitle(); |
900 | if (empty($parent_title) && ($objParent->ns() == 'oid')) { |
||
1116 | daniel-mar | 901 | assert($objParent instanceof OIDplusOid); //assert(get_class($objParent) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
977 | daniel-mar | 902 | // If not title is available, then use an ASN.1 identifier |
903 | $res_asn = OIDplus::db()->query("select name from ###asn1id where oid = ?", array($objParent->nodeId())); |
||
904 | if ($res_asn->any()) { |
||
905 | $row_asn = $res_asn->fetch_array(); |
||
906 | $parent_title = $row_asn['name']; // TODO: multiple ASN1 ids? |
||
635 | daniel-mar | 907 | } |
977 | daniel-mar | 908 | } |
635 | daniel-mar | 909 | |
977 | daniel-mar | 910 | $parent_link_text = empty($parent_title) ? explode(':',$objParent->nodeId())[1] : $parent_title.' ('.explode(':',$objParent->nodeId())[1].')'; |
635 | daniel-mar | 911 | |
977 | daniel-mar | 912 | $out['text'] = '<p><a '.OIDplus::gui()->link($objParent->nodeId()).'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '._L('Parent node: %1',htmlentities($parent_link_text)).'</a></p>' . $out['text']; |
635 | daniel-mar | 913 | } |
914 | } else { |
||
915 | $parent_link_text = _L('Go back to front page'); |
||
916 | $out['text'] = '<p><a '.OIDplus::gui()->link('oidplus:system').'><img src="img/arrow_back.png" width="16" alt="'._L('Go back').'"> '.htmlentities($parent_link_text).'</a></p>' . $out['text']; |
||
917 | } |
||
918 | |||
919 | // --- |
||
920 | |||
977 | daniel-mar | 921 | if ($obj) { |
1144 | daniel-mar | 922 | $title = $obj->getTitle() ?? ''; |
923 | $description = $obj->getDescription() ?? ''; |
||
999 | daniel-mar | 924 | if (empty(strip_tags($description)) && (stripos($description,'<img') === false)) { |
977 | daniel-mar | 925 | if (empty($title)) { |
635 | daniel-mar | 926 | $desc = '<p><i>'._L('No description for this object available').'</i></p>'; |
927 | } else { |
||
977 | daniel-mar | 928 | $desc = $title; |
635 | daniel-mar | 929 | } |
930 | } else { |
||
977 | daniel-mar | 931 | $desc = self::objDescription($description); |
635 | daniel-mar | 932 | } |
933 | |||
1144 | daniel-mar | 934 | // $description is the description in the OID table (which the user edits) |
935 | // $desc is the thing that is shown (it can be a title if no description is there, or an MCE editor if the user has write rights) |
||
936 | |||
635 | daniel-mar | 937 | if ($obj->userHasWriteRights()) { |
938 | $rand = ++self::$crudCounter; |
||
939 | $desc = '<noscript><p><b>'._L('You need to enable JavaScript to edit title or description of this object.').'</b></p>'.$desc.'</noscript>'; |
||
940 | $desc .= '<div class="container box" style="display:none" id="descbox_'.$rand.'">'; |
||
977 | daniel-mar | 941 | $desc .= _L('Title').': <input type="text" name="title" id="titleedit" value="'.htmlentities($title).'"><br><br>'._L('Description').':<br>'; |
942 | $desc .= self::showMCE('description', $description); |
||
635 | daniel-mar | 943 | $desc .= '<button type="button" name="update_desc" id="update_desc" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.updateDesc()">'._L('Update description').'</button>'; |
944 | $desc .= '</div>'; |
||
945 | $desc .= '<script>$("#descbox_'.$rand.'")[0].style.display = "block";</script>'; |
||
946 | } |
||
947 | } else { |
||
948 | $desc = ''; |
||
949 | } |
||
950 | |||
951 | // --- |
||
952 | |||
953 | if (strpos($out['text'], '%%DESC%%') !== false) |
||
954 | $out['text'] = str_replace('%%DESC%%', $desc, $out['text']); |
||
955 | if (strpos($out['text'], '%%CRUD%%') !== false) |
||
856 | daniel-mar | 956 | $out['text'] = str_replace('%%CRUD%%', self::showCrud($obj->nodeId()), $out['text']); |
635 | daniel-mar | 957 | if (strpos($out['text'], '%%RA_INFO%%') !== false) |
977 | daniel-mar | 958 | $out['text'] = str_replace('%%RA_INFO%%', OIDplusPagePublicRaInfo::showRaInfo($obj->getRaMail()), $out['text']); |
635 | daniel-mar | 959 | |
960 | $alt_ids = $obj->getAltIds(); |
||
961 | if (count($alt_ids) > 0) { |
||
962 | $out['text'] .= '<h2>'._L('Alternative Identifiers').'</h2>'; |
||
1138 | daniel-mar | 963 | |
964 | // Sorty by namespace |
||
965 | usort($alt_ids, function(OIDplusAltId $a, OIDplusAltId $b) { |
||
966 | if($a->getNamespace() > $b->getNamespace()) { |
||
967 | return 1; |
||
968 | } |
||
969 | elseif($a->getNamespace() < $b->getNamespace()) { |
||
970 | return -1; |
||
971 | } |
||
972 | else { |
||
973 | return 0; |
||
974 | } |
||
975 | }); |
||
976 | |||
977 | $out['text'] .= '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
||
978 | $out['text'] .= '<table class="table table-bordered table-striped">'; |
||
979 | $out['text'] .= '<thead>'; |
||
980 | $out['text'] .= '<tr><th>'._L('Identifier').'</th><th>'._L('Description').'</th></tr>'; |
||
981 | $out['text'] .= '</thead>'; |
||
982 | $out['text'] .= '<tbody>'; |
||
635 | daniel-mar | 983 | foreach ($alt_ids as $alt_id) { |
984 | $ns = $alt_id->getNamespace(); |
||
985 | $aid = $alt_id->getId(); |
||
986 | $aiddesc = $alt_id->getDescription(); |
||
945 | daniel-mar | 987 | $suffix = $alt_id->getSuffix(); |
1138 | daniel-mar | 988 | $out['text'] .= '<tr><td>'.htmlentities($ns.':'.$aid).($suffix ? '<br/><font size="-1">'.htmlentities($suffix).'</font>' : '').'</td><td>'.htmlentities($aiddesc).'</td></tr>'; |
635 | daniel-mar | 989 | } |
1138 | daniel-mar | 990 | $out['text'] .= '</tbody>'; |
991 | $out['text'] .= '</table>'; |
||
992 | $out['text'] .= '</div></div>'; |
||
635 | daniel-mar | 993 | } |
994 | |||
1005 | daniel-mar | 995 | foreach (OIDplus::getAllPlugins() as $plugin) { |
1131 | daniel-mar | 996 | if ($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_2) { |
997 | $plugin->modifyContent($obj->nodeId(), $out['title'], $out['icon'], $out['text']); |
||
635 | daniel-mar | 998 | } |
999 | } |
||
1000 | } |
||
1001 | } |
||
1002 | |||
1116 | daniel-mar | 1003 | /** |
1130 | daniel-mar | 1004 | * @param array $json |
1005 | * @param array $out |
||
1116 | daniel-mar | 1006 | * @return void |
1007 | */ |
||
1130 | daniel-mar | 1008 | private function publicSitemap_rec(array $json, array &$out) { |
635 | daniel-mar | 1009 | foreach ($json as $x) { |
1010 | if (isset($x['id']) && $x['id']) { |
||
1011 | $out[] = $x['id']; |
||
1012 | } |
||
1013 | if (isset($x['children'])) { |
||
1014 | $this->publicSitemap_rec($x['children'], $out); |
||
1015 | } |
||
1016 | } |
||
1017 | } |
||
1018 | |||
1116 | daniel-mar | 1019 | /** |
1020 | * @param array $out |
||
1021 | * @return void |
||
1022 | */ |
||
1023 | public function publicSitemap(array &$out) { |
||
635 | daniel-mar | 1024 | $json = array(); |
1116 | daniel-mar | 1025 | $this->tree($json, null/*RA EMail*/, false/*HTML tree algorithm*/, "*"/*display all*/); |
635 | daniel-mar | 1026 | $this->publicSitemap_rec($json, $out); |
1027 | } |
||
1028 | |||
1116 | daniel-mar | 1029 | /** |
1030 | * @param array $json |
||
1031 | * @param string|null $ra_email |
||
1032 | * @param bool $nonjs |
||
1033 | * @param string $req_goto |
||
1034 | * @return bool |
||
1035 | * @throws OIDplusConfigInitializationException |
||
1036 | * @throws OIDplusException |
||
1037 | */ |
||
1038 | public function tree(array &$json, string $ra_email=null, bool $nonjs=false, string $req_goto=''): bool { |
||
635 | daniel-mar | 1039 | if ($nonjs) { |
1040 | $json[] = array( |
||
1041 | 'id' => 'oidplus:system', |
||
801 | daniel-mar | 1042 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png', |
635 | daniel-mar | 1043 | 'text' => _L('System') |
1044 | ); |
||
1045 | |||
977 | daniel-mar | 1046 | $objGoto = OIDplusObject::findFitting($req_goto); |
998 | daniel-mar | 1047 | $objGotoParent = $objGoto ? $objGoto->getParent() : null; |
977 | daniel-mar | 1048 | $parent = $objGotoParent ? $objGotoParent->nodeId() : ''; |
635 | daniel-mar | 1049 | |
1050 | $objTypesChildren = array(); |
||
1051 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
1052 | $icon = $this->get_treeicon_root($ot); |
||
1053 | |||
1054 | $json[] = array( |
||
1055 | 'id' => $ot::root(), |
||
1056 | 'icon' => $icon, |
||
1057 | 'text' => $ot::objectTypeTitle() |
||
1058 | ); |
||
1059 | |||
954 | daniel-mar | 1060 | $tmp = OIDplusObject::parse($req_goto); |
1116 | daniel-mar | 1061 | if ($tmp && ($ot == get_class($tmp))) { |
635 | daniel-mar | 1062 | // TODO: Instead of just having 3 levels (parent, this and children), it would be better if we'd had a full tree of all parents |
1063 | // on the other hand, for giving search engines content, this is good enough |
||
1064 | if (empty($parent)) { |
||
1065 | $res = OIDplus::db()->query("select * from ###objects where " . |
||
1066 | "parent = ? or " . |
||
1148 | daniel-mar | 1067 | "id = ? ", array($req_goto, $req_goto)); |
635 | daniel-mar | 1068 | } else { |
1069 | $res = OIDplus::db()->query("select * from ###objects where " . |
||
1070 | "parent = ? or " . |
||
1071 | "id = ? or " . |
||
1148 | daniel-mar | 1072 | "id = ? ", array($req_goto, $req_goto, $parent)); |
635 | daniel-mar | 1073 | } |
1156 | daniel-mar | 1074 | $res->naturalSortByField('id'); |
635 | daniel-mar | 1075 | |
1076 | $z_used = 0; |
||
1077 | $y_used = 0; |
||
1078 | $x_used = 0; |
||
1079 | $stufe = 0; |
||
1080 | $menu_entries = array(); |
||
1081 | $stufen = array(); |
||
1082 | while ($row = $res->fetch_object()) { |
||
1083 | $obj = OIDplusObject::parse($row->id); |
||
1116 | daniel-mar | 1084 | if (!$obj) continue; // might happen if the objectType is not available/loaded |
635 | daniel-mar | 1085 | if (!$obj->userHasReadRights()) continue; |
1219 | daniel-mar | 1086 | $txt = ($row->title ?? '') == '' ? '' : ' -- '.htmlentities($row->title); |
635 | daniel-mar | 1087 | |
1088 | if ($row->id == $parent) { $stufe=0; $z_used++; } |
||
1089 | if ($row->id == $req_goto) { $stufe=1; $y_used++; } |
||
1090 | if ($row->parent == $req_goto) { $stufe=2; $x_used++; } |
||
1091 | |||
1092 | $menu_entry = array('id' => $row->id, 'icon' => '', 'text' => $txt, 'indent' => 0); |
||
1093 | $menu_entries[] = $menu_entry; |
||
1094 | $stufen[] = $stufe; |
||
1095 | } |
||
1096 | if ($x_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 2) $menu_entry['indent'] += 1; |
||
1097 | if ($y_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 1) $menu_entry['indent'] += 1; |
||
1098 | if ($z_used) foreach ($menu_entries as $i => &$menu_entry) if ($stufen[$i] >= 0) $menu_entry['indent'] += 1; |
||
1099 | $json = array_merge($json, $menu_entries); |
||
1100 | } |
||
1101 | } |
||
1102 | |||
1103 | return true; |
||
1104 | } else { |
||
1116 | daniel-mar | 1105 | if ($req_goto === "*") { |
635 | daniel-mar | 1106 | $goto_path = true; // display everything recursively |
1116 | daniel-mar | 1107 | } else if ($req_goto !== "") { |
635 | daniel-mar | 1108 | $goto = $req_goto; |
1109 | $path = array(); |
||
1110 | while (true) { |
||
1111 | $path[] = $goto; |
||
977 | daniel-mar | 1112 | $objGoto = OIDplusObject::findFitting($goto); |
1113 | if (!$objGoto) break; |
||
1114 | $objGotoParent = $objGoto->getParent(); |
||
1115 | $goto = $objGotoParent ? $objGotoParent->nodeId() : ''; |
||
635 | daniel-mar | 1116 | if ($goto == '') continue; |
1117 | } |
||
1118 | |||
1119 | $goto_path = array_reverse($path); |
||
1120 | } else { |
||
1121 | $goto_path = null; |
||
1122 | } |
||
1123 | |||
1124 | $objTypesChildren = array(); |
||
1125 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
1126 | $icon = $this->get_treeicon_root($ot); |
||
1127 | |||
1128 | $child = array('id' => $ot::root(), |
||
1129 | 'text' => $ot::objectTypeTitle(), |
||
1130 | 'state' => array("opened" => true), |
||
1131 | 'icon' => $icon, |
||
1132 | 'children' => OIDplus::menuUtils()->tree_populate($ot::root(), $goto_path) |
||
1133 | ); |
||
1122 | daniel-mar | 1134 | if ($child['icon'] && !file_exists($child['icon'])) $child['icon'] = null; // default icon (folder) |
635 | daniel-mar | 1135 | $objTypesChildren[] = $child; |
1136 | } |
||
1137 | |||
1138 | $json[] = array( |
||
1139 | 'id' => "oidplus:system", |
||
1140 | 'text' => _L('Objects'), |
||
1141 | 'state' => array( |
||
1142 | "opened" => true, |
||
1143 | // "selected" => true) // "selected" is buggy: |
||
1144 | // 1) The select-event will not be triggered upon loading |
||
1145 | // 2) The nodes directly blow cannot be opened (loading infinite time) |
||
1146 | ), |
||
801 | daniel-mar | 1147 | 'icon' => OIDplus::webpath(__DIR__,OIDplus::PATH_RELATIVE).'img/main_icon16.png', |
635 | daniel-mar | 1148 | 'children' => $objTypesChildren |
1149 | ); |
||
1150 | |||
1151 | return true; |
||
1152 | } |
||
1153 | } |
||
1154 | |||
1116 | daniel-mar | 1155 | /** |
1156 | * @param string $request |
||
1157 | * @return array|false |
||
1158 | */ |
||
1159 | public function tree_search(string $request) { |
||
635 | daniel-mar | 1160 | $ary = array(); |
951 | daniel-mar | 1161 | $found_leaf = false; |
635 | daniel-mar | 1162 | if ($obj = OIDplusObject::parse($request)) { |
951 | daniel-mar | 1163 | $found_leaf = OIDplusObject::exists($request); |
1164 | do { |
||
1165 | if ($obj->userHasReadRights()) { |
||
635 | daniel-mar | 1166 | $ary[] = $obj->nodeId(); |
951 | daniel-mar | 1167 | } |
1168 | } while ($obj = $obj->getParent()); |
||
1169 | $ary = array_reverse($ary); |
||
1170 | } |
||
1171 | if (!$found_leaf) { |
||
952 | daniel-mar | 1172 | $alternatives = $this->getAlternativesForQuery($request); |
951 | daniel-mar | 1173 | foreach ($alternatives as $alternative) { |
1174 | $ary_ = array(); |
||
1175 | if ($obj = OIDplusObject::parse($alternative)) { |
||
1176 | if ($obj->userHasReadRights() && OIDplusObject::exists($alternative)) { |
||
1177 | do { |
||
1178 | $ary_[] = $obj->nodeId(); |
||
1179 | } while ($obj = $obj->getParent()); |
||
1180 | $ary_ = array_reverse($ary_); |
||
1181 | } |
||
1182 | } |
||
1183 | if (!empty($ary_)) { |
||
1184 | $ary = $ary_; |
||
1185 | break; |
||
1186 | } |
||
635 | daniel-mar | 1187 | } |
1188 | } |
||
1189 | return $ary; |
||
1190 | } |
||
1191 | |||
1116 | daniel-mar | 1192 | /** |
1193 | * @var int |
||
1194 | */ |
||
635 | daniel-mar | 1195 | private static $crudCounter = 0; |
1196 | |||
1116 | daniel-mar | 1197 | /** |
1121 | daniel-mar | 1198 | * @param string $parent |
1199 | * @return string |
||
1116 | daniel-mar | 1200 | * @throws OIDplusConfigInitializationException |
1201 | * @throws OIDplusException |
||
1202 | */ |
||
1121 | daniel-mar | 1203 | protected static function showCrud(string $parent='oid:'): string { |
635 | daniel-mar | 1204 | $items_total = 0; |
1205 | $items_hidden = 0; |
||
1206 | |||
1207 | $objParent = OIDplusObject::parse($parent); |
||
1121 | daniel-mar | 1208 | if (!$objParent) return ''; |
635 | daniel-mar | 1209 | $parentNS = $objParent::ns(); |
1210 | |||
1211 | // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20identifiers |
||
1212 | $no_asn1 = array( |
||
1213 | 'oid:1.3.6.1.4.1', |
||
1214 | 'oid:1.3.6.1.4.1.37476.9000', |
||
1215 | 'oid:1.3.6.1.4.1.37553.8.8', |
||
1216 | 'oid:2.16.276.1', |
||
719 | daniel-mar | 1217 | //'oid:2.25', // according to Olivier, it is OK that UUID owners define their own ASN.1 ID, since the ASN.1 ID is not required to be unique |
1218 | //'oid:1.2.840.113556.1.8000.2554' // Adhoc (GUID/UUID-based) customer use. It is probably the same case as the UUID OIDs, after all, these are UUIDs, too. |
||
635 | daniel-mar | 1219 | ); |
1220 | |||
1221 | // http://www.oid-info.com/cgi-bin/display?a=list-by-category&category=Not%20allocating%20Unicode%20labels |
||
1222 | $no_iri = array( |
||
1223 | 'oid:1.2.250.1', |
||
1224 | 'oid:1.3.6.1.4.1', |
||
1225 | 'oid:1.3.6.1.4.1.37476.9000', |
||
1226 | 'oid:1.3.6.1.4.1.37553.8.8', |
||
1227 | 'oid:2.16.276.1', |
||
1228 | 'oid:2.25' |
||
1229 | ); |
||
1230 | |||
1231 | $accepts_asn1 = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_asn1)) && (!is_uuid_oid($objParent->nodeId(),true)); |
||
1232 | $accepts_iri = ($parentNS == 'oid') && (!in_array($objParent->nodeId(), $no_iri)) && (!is_uuid_oid($objParent->nodeId(),true)); |
||
1233 | |||
1234 | $result = OIDplus::db()->query("select o.*, r.ra_name " . |
||
1235 | "from ###objects o " . |
||
1236 | "left join ###ra r on r.email = o.ra_email " . |
||
1148 | daniel-mar | 1237 | "where parent = ? ", array($parent)); |
1156 | daniel-mar | 1238 | $result->naturalSortByField('id'); |
635 | daniel-mar | 1239 | |
693 | daniel-mar | 1240 | $rows = array(); |
1241 | while ($row = $result->fetch_object()) { |
||
1242 | $obj = OIDplusObject::parse($row->id); |
||
1121 | daniel-mar | 1243 | if ($obj) $rows[] = array($obj,$row); |
693 | daniel-mar | 1244 | } |
1245 | |||
1246 | $enable_weid_presentation = OIDplus::config()->getValue('oid_grid_show_weid'); |
||
1247 | |||
1116 | daniel-mar | 1248 | $output = '<div class="container box"><div id="suboid_table" class="table-responsive">'; |
1259 | daniel-mar | 1249 | $output .= '<table id="crudTable" class="table table-bordered table-striped">'; |
1138 | daniel-mar | 1250 | $output .= '<thead>'; |
635 | daniel-mar | 1251 | $output .= ' <tr>'; |
1252 | $output .= ' <th>'._L('ID').(($parentNS == 'gs1') ? ' '._L('(without check digit)') : '').'</th>'; |
||
692 | daniel-mar | 1253 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
693 | daniel-mar | 1254 | $output .= ' <th><abbr title="'._L('Binary-to-text encoding used for WEIDs').'">'._L('Base36').'</abbr></th>'; |
1255 | } |
||
635 | daniel-mar | 1256 | if ($parentNS == 'oid') { |
1257 | if ($accepts_asn1) $output .= ' <th>'._L('ASN.1 IDs (comma sep.)').'</th>'; |
||
1258 | if ($accepts_iri) $output .= ' <th>'._L('IRI IDs (comma sep.)').'</th>'; |
||
1259 | } |
||
1260 | $output .= ' <th>'._L('RA').'</th>'; |
||
1261 | $output .= ' <th>'._L('Comment').'</th>'; |
||
1262 | if ($objParent->userHasWriteRights()) { |
||
1263 | $output .= ' <th>'._L('Hide').'</th>'; |
||
1264 | $output .= ' <th>'._L('Update').'</th>'; |
||
1265 | $output .= ' <th>'._L('Delete').'</th>'; |
||
1266 | } |
||
1267 | $output .= ' <th>'._L('Created').'</th>'; |
||
1268 | $output .= ' <th>'._L('Updated').'</th>'; |
||
1269 | $output .= ' </tr>'; |
||
1138 | daniel-mar | 1270 | $output .= '</thead>'; |
1141 | daniel-mar | 1271 | |
1138 | daniel-mar | 1272 | $output .= '<tbody>'; |
635 | daniel-mar | 1273 | foreach ($rows as list($obj,$row)) { |
1274 | $items_total++; |
||
1275 | if (!$obj->userHasReadRights()) { |
||
1276 | $items_hidden++; |
||
1277 | continue; |
||
1278 | } |
||
1279 | |||
1280 | $show_id = $obj->crudShowId($objParent); |
||
1281 | |||
1282 | $asn1ids = array(); |
||
1283 | $res2 = OIDplus::db()->query("select name from ###asn1id where oid = ? order by lfd", array($row->id)); |
||
1284 | while ($row2 = $res2->fetch_array()) { |
||
1285 | $asn1ids[] = $row2['name']; |
||
1286 | } |
||
1287 | |||
1288 | $iris = array(); |
||
1289 | $res2 = OIDplus::db()->query("select name from ###iri where oid = ? order by lfd", array($row->id)); |
||
1290 | while ($row2 = $res2->fetch_array()) { |
||
1291 | $iris[] = $row2['name']; |
||
1292 | } |
||
1293 | |||
1058 | daniel-mar | 1294 | $date_created = is_null($row->created) || (explode(' ', $row->created)[0] == '0000-00-00') ? '' : explode(' ', $row->created)[0]; |
1295 | $date_updated = is_null($row->updated) || (explode(' ', $row->updated)[0] == '0000-00-00') ? '' : explode(' ', $row->updated)[0]; |
||
635 | daniel-mar | 1296 | |
1297 | $output .= '<tr>'; |
||
693 | daniel-mar | 1298 | $output .= ' <td><a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.htmlentities($show_id).'</a>'; |
1299 | if ($enable_weid_presentation && ($parentNS == 'oid') && $objParent->isRoot()) { |
||
1300 | // To save space horizontal space, the WEIDs were written below the OIDs |
||
1116 | daniel-mar | 1301 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
693 | daniel-mar | 1302 | $output .= '<br>'.$obj->getWeidNotation(true); |
1303 | } |
||
1304 | $output .= '</td>'; |
||
1305 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
||
1116 | daniel-mar | 1306 | assert($obj instanceof OIDplusOid); //assert(get_class($obj) === "ViaThinkSoft\OIDplus\OIDplusOid"); |
693 | daniel-mar | 1307 | $output .= ' <td>'.htmlentities($obj->weidArc()).'</td>'; |
1308 | } |
||
635 | daniel-mar | 1309 | if ($objParent->userHasWriteRights()) { |
1310 | if ($parentNS == 'oid') { |
||
1311 | if ($accepts_asn1) $output .= ' <td><input type="text" id="asn1ids_'.$row->id.'" value="'.implode(', ', $asn1ids).'"></td>'; |
||
1312 | if ($accepts_iri) $output .= ' <td><input type="text" id="iris_'.$row->id.'" value="'.implode(', ', $iris).'"></td>'; |
||
1313 | } |
||
1219 | daniel-mar | 1314 | $output .= ' <td><input type="text" id="ra_email_'.$row->id.'" value="'.htmlentities($row->ra_email ?? '').'"></td>'; |
1315 | $output .= ' <td><input type="text" id="comment_'.$row->id.'" value="'.htmlentities($row->comment ?? '').'"></td>'; |
||
635 | daniel-mar | 1316 | $output .= ' <td><input type="checkbox" id="hide_'.$row->id.'" '.($row->confidential ? 'checked' : '').'></td>'; |
1317 | $output .= ' <td><button type="button" name="update_'.$row->id.'" id="update_'.$row->id.'" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionUpdate('.js_escape($row->id).', '.js_escape($parent).')">'._L('Update').'</button></td>'; |
||
1318 | $output .= ' <td><button type="button" name="delete_'.$row->id.'" id="delete_'.$row->id.'" class="btn btn-danger btn-xs delete" onclick="OIDplusPagePublicObjects.crudActionDelete('.js_escape($row->id).', '.js_escape($parent).')">'._L('Delete').'</button></td>'; |
||
1319 | $output .= ' <td>'.$date_created.'</td>'; |
||
1320 | $output .= ' <td>'.$date_updated.'</td>'; |
||
1321 | } else { |
||
1322 | if ($parentNS == 'oid') { |
||
693 | daniel-mar | 1323 | if ($asn1ids == '') $asn1ids = '<i>'._L('(none)').'</i>'; |
1324 | if ($iris == '') $iris = '<i>'._L('(none)').'</i>'; |
||
635 | daniel-mar | 1325 | $asn1ids_ext = array(); |
1326 | foreach ($asn1ids as $asn1id) { |
||
1327 | $asn1ids_ext[] = '<a href="?goto='.urlencode($row->id).'" onclick="openAndSelectNode('.js_escape($row->id).', '.js_escape($parent).'); return false;">'.$asn1id.'</a>'; |
||
1328 | } |
||
1329 | if ($accepts_asn1) $output .= ' <td>'.implode(', ', $asn1ids_ext).'</td>'; |
||
1330 | if ($accepts_iri) $output .= ' <td>'.implode(', ', $iris).'</td>'; |
||
1331 | } |
||
1219 | daniel-mar | 1332 | $output .= ' <td><a '.OIDplus::gui()->link('oidplus:rainfo$'.str_replace('@','&',$row->ra_email??'')).'>'.htmlentities(empty($row->ra_name??'') ? str_replace('@','&',$row->ra_email??'') : $row->ra_name).'</a></td>'; |
1333 | $output .= ' <td>'.htmlentities($row->comment ?? '').'</td>'; |
||
635 | daniel-mar | 1334 | $output .= ' <td>'.$date_created.'</td>'; |
1335 | $output .= ' <td>'.$date_updated.'</td>'; |
||
1336 | } |
||
1337 | $output .= '</tr>'; |
||
1338 | } |
||
1141 | daniel-mar | 1339 | $output .= '</tbody>'; |
635 | daniel-mar | 1340 | |
1121 | daniel-mar | 1341 | $parent_ra_email = $objParent->getRaMail() ; |
693 | daniel-mar | 1342 | |
692 | daniel-mar | 1343 | // "Create OID" row |
635 | daniel-mar | 1344 | if ($objParent->userHasWriteRights()) { |
1141 | daniel-mar | 1345 | $output .= '<tfoot>'; |
635 | daniel-mar | 1346 | $output .= '<tr>'; |
1121 | daniel-mar | 1347 | $prefix = $objParent->crudInsertPrefix(); |
693 | daniel-mar | 1348 | |
1121 | daniel-mar | 1349 | $suffix = $objParent->crudInsertSuffix(); |
693 | daniel-mar | 1350 | foreach (OIDplus::getObjectTypePlugins() as $plugin) { |
1137 | daniel-mar | 1351 | if (($plugin instanceof INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_6) && ($plugin::getObjectTypeClassName()::ns() == $parentNS)) { |
1131 | daniel-mar | 1352 | $suffix .= $plugin->gridGeneratorLinks($objParent); |
693 | daniel-mar | 1353 | } |
1354 | } |
||
1355 | |||
1356 | if ($parentNS == 'guid') { |
||
695 | daniel-mar | 1357 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:275px">'.$suffix.'</td>'; |
693 | daniel-mar | 1358 | } else if ($parentNS == 'oid') { |
635 | daniel-mar | 1359 | // TODO: Idea: Give a class name, e.g. "OID" and then with a oid-specific CSS make the width individual. So, every plugin has more control over the appearance and widths of the input fields |
693 | daniel-mar | 1360 | if ($objParent->nodeId() === 'oid:2.25') { |
695 | daniel-mar | 1361 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>'; |
693 | daniel-mar | 1362 | if ($enable_weid_presentation) $output .= ' <td> </td>'; // For UUID-OIDs, you must generate a valid one. Don't be tempted to create one using the Base36 input! |
1363 | } else if ($objParent->isRoot()) { |
||
695 | daniel-mar | 1364 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:345px">'.$suffix.'</td>'; |
693 | daniel-mar | 1365 | if ($enable_weid_presentation) $output .= ''; // WEID-editor not available for root nodes at the moment. For the moment you need to enter the OID (TODO: Create JavaScript WEID encoder/decoder) |
635 | daniel-mar | 1366 | } else { |
693 | daniel-mar | 1367 | if ($enable_weid_presentation) { |
695 | daniel-mar | 1368 | $output .= ' <td>'.$prefix.' <input oninput="OIDplusPagePublicObjects.frdl_oidid_change()" type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>'; |
693 | daniel-mar | 1369 | $output .= ' <td><input type="text" name="weid" id="weid" value="" oninput="OIDplusPagePublicObjects.frdl_weid_change()" style="width:100%;min-width:100px"></td>'; |
1370 | } else { |
||
695 | daniel-mar | 1371 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>'; |
693 | daniel-mar | 1372 | } |
635 | daniel-mar | 1373 | } |
1374 | } else { |
||
695 | daniel-mar | 1375 | $output .= ' <td>'.$prefix.' <input type="text" id="id" value="" style="width:100%;min-width:100px">'.$suffix.'</td>'; |
635 | daniel-mar | 1376 | } |
1377 | if ($accepts_asn1) $output .= ' <td><input type="text" id="asn1ids" value=""></td>'; |
||
1378 | if ($accepts_iri) $output .= ' <td><input type="text" id="iris" value=""></td>'; |
||
1137 | daniel-mar | 1379 | $output .= ' <td><input type="text" id="ra_email" value="'.htmlentities($parent_ra_email ?? '').'"></td>'; |
635 | daniel-mar | 1380 | $output .= ' <td><input type="text" id="comment" value=""></td>'; |
1381 | $output .= ' <td><input type="checkbox" id="hide"></td>'; |
||
1382 | $output .= ' <td><button type="button" name="insert" id="insert" class="btn btn-success btn-xs update" onclick="OIDplusPagePublicObjects.crudActionInsert('.js_escape($parent).')">'._L('Insert').'</button></td>'; |
||
1383 | $output .= ' <td></td>'; |
||
1384 | $output .= ' <td></td>'; |
||
1385 | $output .= ' <td></td>'; |
||
1386 | $output .= '</tr>'; |
||
1141 | daniel-mar | 1387 | $output .= '</tfoot>'; |
635 | daniel-mar | 1388 | } else { |
1389 | if ($items_total-$items_hidden == 0) { |
||
1390 | $cols = ($parentNS == 'oid') ? 7 : 5; |
||
692 | daniel-mar | 1391 | if ($enable_weid_presentation && ($parentNS == 'oid') && !$objParent->isRoot()) { |
1392 | $cols++; |
||
693 | daniel-mar | 1393 | } |
1138 | daniel-mar | 1394 | $output .= '<tfoot>'; |
635 | daniel-mar | 1395 | $output .= '<tr><td colspan="'.$cols.'">'._L('No items available').'</td></tr>'; |
1138 | daniel-mar | 1396 | $output .= '</tfoot>'; |
635 | daniel-mar | 1397 | } |
1398 | } |
||
1399 | |||
1400 | $output .= '</table>'; |
||
1401 | $output .= '</div></div>'; |
||
1402 | |||
1403 | if ($items_hidden == 1) { |
||
1404 | $output .= '<p>'._L('One item is hidden. Please <a %1>log in</a> to see it.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>'; |
||
1405 | } else if ($items_hidden > 1) { |
||
1406 | $output .= '<p>'._L('%1 items are hidden. Please <a %2>log in</a> to see them.',$items_hidden,OIDplus::gui()->link('oidplus:login')).'</p>'; |
||
1407 | } |
||
1408 | |||
1409 | return $output; |
||
1410 | } |
||
1411 | |||
1116 | daniel-mar | 1412 | /** |
1130 | daniel-mar | 1413 | * @param string $html |
1414 | * @return string |
||
1116 | daniel-mar | 1415 | */ |
1130 | daniel-mar | 1416 | protected static function objDescription(string $html): string { |
635 | daniel-mar | 1417 | // We allow HTML, but no hacking |
1418 | $html = anti_xss($html); |
||
1419 | |||
1420 | return trim_br($html); |
||
1421 | } |
||
1422 | |||
1116 | daniel-mar | 1423 | /** |
1424 | * 'quickbars' added 11 July 2019: Disabled because of two problems: |
||
1425 | * 1. When you load TinyMCE via AJAX using the left menu, the quickbar is immediately shown, even if TinyMCE does not have the focus |
||
1426 | * 2. When you load a page without TinyMCE using the left menu, the quickbar is still visible, although there is no edit |
||
1427 | * 'colorpicker', 'textcolor' and 'contextmenu' added in 07 April 2020, because it is built in in the core. |
||
1428 | * 'importcss' added 17 September 2020, because it breaks the "Format/Style" dropdown box ("styleselect" toolbar) |
||
1429 | * 'legacyoutput' added 24 September 2021, because it is declared as deprecated |
||
1430 | * 'spellchecker' added 6 October 2021, because it is declared as deprecated and marked for removal in TinyMCE 6.0 |
||
1431 | * 'imagetools' and 'toc' added 23 February 2022, because they are declared as deprecated and marked for removal in TinyMCE 6.0 ("moving to premium") |
||
1432 | * @var string[] |
||
1433 | */ |
||
753 | daniel-mar | 1434 | public static $exclude_tinymce_plugins = array('fullpage', 'bbcode', 'quickbars', 'colorpicker', 'textcolor', 'contextmenu', 'importcss', 'legacyoutput', 'spellchecker', 'imagetools', 'toc'); |
635 | daniel-mar | 1435 | |
1116 | daniel-mar | 1436 | /** |
1130 | daniel-mar | 1437 | * @param string $name |
1438 | * @param string $content |
||
1116 | daniel-mar | 1439 | * @return string |
1440 | * @throws OIDplusConfigInitializationException |
||
1441 | * @throws OIDplusException |
||
1442 | */ |
||
1130 | daniel-mar | 1443 | protected static function showMCE(string $name, string $content): string { |
635 | daniel-mar | 1444 | $mce_plugins = array(); |
1445 | foreach (glob(OIDplus::localpath().'vendor/tinymce/tinymce/plugins/*') as $m) { // */ |
||
1446 | $mce_plugins[] = basename($m); |
||
1447 | } |
||
1448 | |||
1449 | foreach (self::$exclude_tinymce_plugins as $exclude) { |
||
1450 | $index = array_search($exclude, $mce_plugins); |
||
1451 | if ($index !== false) unset($mce_plugins[$index]); |
||
1452 | } |
||
1453 | |||
1454 | $oidplusLang = OIDplus::getCurrentLang(); |
||
1455 | |||
1456 | $langCandidates = array( |
||
1457 | strtolower(substr($oidplusLang,0,2)).'_'.strtoupper(substr($oidplusLang,2,2)), // de_DE |
||
1458 | strtolower(substr($oidplusLang,0,2)) // de |
||
1459 | ); |
||
1460 | $tinyMCELang = ''; |
||
1461 | foreach ($langCandidates as $candidate) { |
||
1462 | if (file_exists(OIDplus::localpath().'vendor/tweeb/tinymce-i18n/langs/'.$candidate.'.js')) { |
||
1463 | $tinyMCELang = $candidate; |
||
1464 | break; |
||
1465 | } |
||
1466 | } |
||
1467 | |||
1468 | $out = '<script> |
||
1469 | tinymce.EditorManager.baseURL = "vendor/tinymce/tinymce"; |
||
1470 | tinymce.init({ |
||
801 | daniel-mar | 1471 | document_base_url: "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'", |
635 | daniel-mar | 1472 | selector: "#'.$name.'", |
1473 | height: 200, |
||
1474 | statusbar: false, |
||
1475 | // menubar:false, |
||
1476 | // toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | table | fontsizeselect", |
||
1477 | toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect", |
||
1478 | plugins: "'.implode(' ', $mce_plugins).'", |
||
1479 | mobile: { |
||
1480 | theme: "mobile", |
||
1481 | toolbar: "undo redo | styleselect | bold italic underline forecolor | bullist numlist | outdent indent | table | fontsizeselect", |
||
1482 | plugins: "'.implode(' ', $mce_plugins).'" |
||
1483 | } |
||
1484 | '.($tinyMCELang == '' ? '' : ', language : "'.$tinyMCELang.'"').' |
||
801 | daniel-mar | 1485 | '.($tinyMCELang == '' ? '' : ', language_url : "'.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'vendor/tweeb/tinymce-i18n/langs/'.$tinyMCELang.'.js"').' |
635 | daniel-mar | 1486 | }); |
1487 | |||
1488 | pageChangeRequestCallbacks.push([OIDplusPagePublicObjects.cbQueryTinyMCE, "#'.$name.'"]); |
||
1489 | pageChangeCallbacks.push([OIDplusPagePublicObjects.cbRemoveTinyMCE, "#'.$name.'"]); |
||
1490 | </script>'; |
||
1491 | |||
1492 | $content = htmlentities($content); // For some reason, if we want to display the text "<xyz>" in TinyMCE, we need to double-encode things! < will not be accepted, we need &lt; ... why? |
||
1493 | |||
1494 | $out .= '<textarea name="'.htmlentities($name).'" id="'.htmlentities($name).'">'.trim($content).'</textarea><br>'; |
||
1495 | |||
1496 | return $out; |
||
1497 | } |
||
1498 | |||
1116 | daniel-mar | 1499 | /** |
1131 | daniel-mar | 1500 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1 |
1116 | daniel-mar | 1501 | * @return bool |
1502 | * @throws OIDplusException |
||
1503 | */ |
||
635 | daniel-mar | 1504 | public function oobeRequested(): bool { |
1505 | return OIDplus::config()->getValue('oobe_objects_done') == '0'; |
||
1506 | } |
||
1507 | |||
1116 | daniel-mar | 1508 | /** |
1131 | daniel-mar | 1509 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_1 |
1125 | daniel-mar | 1510 | * @param int $step |
1511 | * @param bool $do_edits |
||
1512 | * @param bool $errors_happened |
||
1116 | daniel-mar | 1513 | * @return void |
1514 | */ |
||
1125 | daniel-mar | 1515 | public function oobeEntry(int $step, bool $do_edits, bool &$errors_happened)/*: void*/ { |
1055 | daniel-mar | 1516 | echo '<h2>'._L('Step %1: Enable/Disable object type plugins',$step).'</h2>'; |
635 | daniel-mar | 1517 | echo '<p>'._L('Which object types do you want to manage using OIDplus?').'</p>'; |
1518 | |||
1519 | $enabled_ary = array(); |
||
1520 | |||
1521 | foreach (OIDplus::getEnabledObjectTypes() as $ot) { |
||
1522 | echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"'; |
||
1033 | daniel-mar | 1523 | if (isset($_POST['sent'])) { |
1524 | if (isset($_POST['enable_ot_'.$ot::ns()])) { |
||
635 | daniel-mar | 1525 | echo ' checked'; |
1526 | $enabled_ary[] = $ot::ns(); |
||
1527 | } |
||
1528 | } else { |
||
1529 | echo ' checked'; |
||
1530 | } |
||
1531 | echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>'; |
||
1532 | } |
||
1533 | |||
1534 | foreach (OIDplus::getDisabledObjectTypes() as $ot) { |
||
1535 | echo '<input type="checkbox" name="enable_ot_'.$ot::ns().'" id="enable_ot_'.$ot::ns().'"'; |
||
1033 | daniel-mar | 1536 | if (isset($_POST['sent'])) { |
1537 | if (isset($_POST['enable_ot_'.$ot::ns()])) { |
||
635 | daniel-mar | 1538 | echo ' checked'; |
1539 | $enabled_ary[] = $ot::ns(); |
||
1540 | } |
||
1541 | } else { |
||
1542 | echo ''; // <-- difference |
||
1543 | } |
||
1544 | echo '> <label for="enable_ot_'.$ot::ns().'">'.htmlentities($ot::objectTypeTitle()).'</label><br>'; |
||
1545 | } |
||
1546 | |||
1201 | daniel-mar | 1547 | $htmlmsg = ''; |
635 | daniel-mar | 1548 | if ($do_edits) { |
1549 | try { |
||
1550 | OIDplus::config()->setValue('objecttypes_enabled', implode(';', $enabled_ary)); |
||
1551 | OIDplus::config()->setValue('oobe_objects_done', '1'); |
||
1050 | daniel-mar | 1552 | } catch (\Exception $e) { |
1201 | daniel-mar | 1553 | $htmlmsg = $e instanceof OIDplusException ? $e->getHtmlMessage() : htmlentities($e->getMessage()); |
635 | daniel-mar | 1554 | $errors_happened = true; |
1555 | } |
||
1556 | } |
||
1557 | |||
1201 | daniel-mar | 1558 | echo ' <font color="red"><b>'.$htmlmsg.'</b></font>'; |
635 | daniel-mar | 1559 | } |
1560 | |||
1116 | daniel-mar | 1561 | /** |
1131 | daniel-mar | 1562 | * Implements interface INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_8 |
1130 | daniel-mar | 1563 | * @param string|null $user |
1116 | daniel-mar | 1564 | * @return array |
1565 | * @throws OIDplusException |
||
1566 | */ |
||
1130 | daniel-mar | 1567 | public function getNotifications(string $user=null): array { |
1000 | daniel-mar | 1568 | $notifications = array(); |
1148 | daniel-mar | 1569 | $res = OIDplus::db()->query("select id, title from ###objects"); |
1156 | daniel-mar | 1570 | $res->naturalSortByField('id'); |
1000 | daniel-mar | 1571 | if ($res->any()) { |
1572 | $is_admin_logged_in = OIDplus::authUtils()->isAdminLoggedIn(); // run just once, for performance |
||
1573 | while ($row = $res->fetch_array()) { |
||
1574 | if (empty($row['title'])) { |
||
1575 | if ($user === 'admin') { |
||
1576 | $accept = $is_admin_logged_in; |
||
1577 | } else { |
||
1578 | $accept = false; |
||
1579 | if ($obj = OIDplusObject::parse($row['id'])) { |
||
1580 | if ($obj->userHasWriteRights($user)) { |
||
1581 | $accept = true; |
||
1582 | } |
||
1583 | } |
||
1584 | } |
||
1585 | |||
1586 | if ($accept) { |
||
1202 | daniel-mar | 1587 | $notifications[] = new OIDplusNotification('WARN', _L('Object %1 has no title.', '<a '.OIDplus::gui()->link($row['id']).'>'.htmlentities($row['id']).'</a>')); |
1000 | daniel-mar | 1588 | } |
1589 | } |
||
1590 | } |
||
1591 | } |
||
1592 | return $notifications; |
||
1593 | } |
||
1594 | |||
693 | daniel-mar | 1595 | } |