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