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