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