Rev 1294 | Rev 1299 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1294 | Rev 1295 | ||
---|---|---|---|
Line 75... | Line 75... | ||
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 | * @param string $endpoint |
|
- | 81 | * @param array $json_in |
|
- | 82 | * @return never-return |
|
- | 83 | */ |
|
- | 84 | private function restApiCall_OPTIONS(string $endpoint, array $json_in) { |
|
- | 85 | header("access-control-allow-credentials: true"); |
|
- | 86 | header("access-control-allow-headers: Keep-Alive,User-Agent,Authorization"); |
|
- | 87 | header("access-control-allow-methods: GET, PUT, POST, DELETE, PATCH, OPTIONS"); |
|
- | 88 | header("access-control-allow-origin: *"); |
|
- | 89 | http_response_code(204/*No content*/); |
|
- | 90 | OIDplus::invoke_shutdown(); |
|
- | 91 | die(); // return array(); |
|
- | 92 | } |
|
- | 93 | ||
- | 94 | /** |
|
- | 95 | * @param string $endpoint |
|
- | 96 | * @param array $json_in |
|
- | 97 | * @return array |
|
- | 98 | */ |
|
- | 99 | private function restApiCall_GET(string $endpoint, array $json_in): array { |
|
- | 100 | $id = substr($endpoint, strlen('objects/')); |
|
- | 101 | $obj = OIDplusObject::findFitting($id); |
|
- | 102 | if (!$obj) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404); |
|
- | 103 | ||
- | 104 | if (!$obj->userHasReadRights()) throw new OIDplusException('Insufficient authorization to read information about this object.', null, 401); |
|
- | 105 | ||
- | 106 | $output = array(); |
|
- | 107 | ||
- | 108 | $output['status'] = 0/*OK*/; |
|
- | 109 | $output['status_bits'] = []; |
|
- | 110 | ||
- | 111 | //$output['id'] = $obj->nodeId(true); |
|
- | 112 | $output['ra_email'] = $obj->getRaMail(); |
|
- | 113 | $output['comment'] = $obj->getComment(); |
|
- | 114 | $output['confidential'] = $obj->isConfidential(); |
|
- | 115 | $output['title'] = $obj->getTitle(); |
|
- | 116 | $output['description'] = $obj->getDescription(); |
|
- | 117 | ||
- | 118 | if ($obj instanceof OIDplusOid) { |
|
- | 119 | $output['asn1ids'] = array(); // TODO: Rename to oid-alphanum-id ? |
|
- | 120 | foreach ($obj->getAsn1Ids() as $asn) { |
|
- | 121 | $output['asn1ids'][] = $asn->getName(); |
|
- | 122 | } |
|
- | 123 | ||
- | 124 | $output['iris'] = array(); // TODO: Rename to oid-unicode-label ? |
|
- | 125 | foreach ($obj->getIris() as $iri) { |
|
- | 126 | $output['iris'][] = $iri->getName(); |
|
- | 127 | } |
|
- | 128 | } |
|
- | 129 | ||
- | 130 | http_response_code(200); |
|
- | 131 | return $output; |
|
- | 132 | } |
|
- | 133 | ||
- | 134 | /** |
|
- | 135 | * @param string $endpoint |
|
- | 136 | * @param array $json_in |
|
- | 137 | * @return array |
|
- | 138 | */ |
|
- | 139 | private function restApiCall_PUT(string $endpoint, array $json_in): array { |
|
- | 140 | $id = substr($endpoint, strlen('objects/')); |
|
- | 141 | $obj = OIDplusObject::parse($id); |
|
- | 142 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'PUT', $id), null, 400); |
|
- | 143 | ||
- | 144 | $params = array(); |
|
- | 145 | $params['id'] = $id; |
|
- | 146 | $params['ra_email'] = $json_in['ra_email'] ?? ''; |
|
- | 147 | $params['comment'] = $json_in['comment'] ?? ''; |
|
- | 148 | $params['confidential'] = $json_in['confidential'] ?? false; |
|
- | 149 | $params['title'] = $json_in['title'] ?? ''; |
|
- | 150 | $params['description'] = $json_in['description'] ?? ''; |
|
- | 151 | $params['asn1ids'] = $json_in['asn1ids'] ?? array(); |
|
- | 152 | $params['iris'] = $json_in['iris'] ?? array(); |
|
- | 153 | ||
- | 154 | if (OIDplusObject::exists($id)) { |
|
- | 155 | // TODO: Problem: The superior RA cannot set title/description, so they cannot perform the PUT command! |
|
- | 156 | $output = self::action_Update($params); |
|
- | 157 | } else { |
|
- | 158 | $params['parent'] = $obj->getParent(); |
|
- | 159 | $params['id_fully_qualified'] = true; |
|
- | 160 | $output = self::action_Insert($params); |
|
- | 161 | } |
|
- | 162 | ||
- | 163 | $output['status_bits'] = []; |
|
- | 164 | if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited'; |
|
- | 165 | if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
|
- | 166 | if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
|
- | 167 | if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID'; |
|
- | 168 | ||
- | 169 | http_response_code(200); |
|
- | 170 | return $output; |
|
- | 171 | } |
|
- | 172 | ||
- | 173 | /** |
|
- | 174 | * @param string $endpoint |
|
- | 175 | * @param array $json_in |
|
- | 176 | * @return array |
|
- | 177 | */ |
|
- | 178 | private function restApiCall_POST(string $endpoint, array $json_in): array { |
|
- | 179 | $id = substr($endpoint, strlen('objects/')); |
|
- | 180 | $obj = OIDplusObject::parse($id); |
|
- | 181 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'GET', $id), null, 400); |
|
- | 182 | $params = $json_in; |
|
- | 183 | $params['parent'] = $obj->getParent(); |
|
- | 184 | $params['id_fully_qualified'] = true; |
|
- | 185 | $params['id'] = $id; |
|
- | 186 | $output = self::action_Insert($params); |
|
- | 187 | ||
- | 188 | $output['status_bits'] = []; |
|
- | 189 | if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited'; |
|
- | 190 | if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
|
- | 191 | if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
|
- | 192 | if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID'; |
|
- | 193 | ||
- | 194 | http_response_code(200); |
|
- | 195 | return $output; |
|
- | 196 | } |
|
- | 197 | ||
- | 198 | /** |
|
- | 199 | * @param string $endpoint |
|
- | 200 | * @param array $json_in |
|
- | 201 | * @return array |
|
- | 202 | */ |
|
- | 203 | private function restApiCall_PATCH(string $endpoint, array $json_in): array { |
|
- | 204 | $id = substr($endpoint, strlen('objects/')); |
|
- | 205 | $params = $json_in; |
|
- | 206 | $params['id'] = $id; |
|
- | 207 | $output = self::action_Update($params); |
|
- | 208 | ||
- | 209 | $output['status_bits'] = []; |
|
- | 210 | if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited'; |
|
- | 211 | if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
|
- | 212 | if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
|
- | 213 | if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID'; |
|
- | 214 | ||
- | 215 | http_response_code(200); |
|
- | 216 | return $output; |
|
- | 217 | } |
|
- | 218 | ||
- | 219 | /** |
|
- | 220 | * @param string $endpoint |
|
- | 221 | * @param array $json_in |
|
- | 222 | * @return array |
|
- | 223 | */ |
|
- | 224 | private function restApiCall_DELETE(string $endpoint, array $json_in): array { |
|
- | 225 | $id = substr($endpoint, strlen('objects/')); |
|
- | 226 | $params = $json_in; |
|
- | 227 | $params['id'] = $id; |
|
- | 228 | $output = self::action_Delete($params); |
|
- | 229 | ||
- | 230 | $output['status_bits'] = []; |
|
- | 231 | ||
- | 232 | http_response_code(200); |
|
- | 233 | return $output; |
|
- | 234 | } |
|
- | 235 | ||
- | 236 | /** |
|
80 | * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9 |
237 | * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9 |
81 | * @param string $requestMethod |
238 | * @param string $requestMethod |
82 | * @param string $endpoint |
239 | * @param string $endpoint |
83 | * @param array $json_in |
240 | * @param array $json_in |
84 | * @return array|false |
241 | * @return array|false |
85 | */ |
242 | */ |
86 | public function restApiCall(string $requestMethod, string $endpoint, array $json_in) { |
243 | public function restApiCall(string $requestMethod, string $endpoint, array $json_in) { |
87 | if (str_starts_with($endpoint, 'objects/')) { |
244 | if (str_starts_with($endpoint, 'objects/')) { |
88 | $id = substr($endpoint, strlen('objects/')); |
- | |
89 | if ($requestMethod == "OPTIONS") { |
245 | if ($requestMethod == "OPTIONS") { |
90 | header("access-control-allow-credentials: true"); |
- | |
91 | header("access-control-allow-headers: Keep-Alive,User-Agent,Authorization"); |
- | |
92 | header("access-control-allow-methods: GET, PUT, POST, DELETE, PATCH, OPTIONS"); |
- | |
93 | header("access-control-allow-origin: *"); |
- | |
94 | http_response_code(204/*No content*/); |
246 | $this->restApiCall_OPTIONS($endpoint, $json_in); |
95 | OIDplus::invoke_shutdown(); |
- | |
96 | die(); // return array(); |
- | |
97 | } |
- | |
98 | else if ($requestMethod == "GET"/*Select*/) { |
247 | } else if ($requestMethod == "GET"/*Select*/) { |
99 | $obj = OIDplusObject::findFitting($id); |
- | |
100 | if (!$obj) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404); |
- | |
101 | - | ||
102 | if (!$obj->userHasReadRights()) throw new OIDplusException('Insufficient authorization to read information about this object.', null, 401); |
- | |
103 | - | ||
104 | $output = array(); |
- | |
105 | - | ||
106 | $output['status'] = 0/*OK*/; |
- | |
107 | $output['status_bits'] = []; |
- | |
108 | - | ||
109 | //$output['id'] = $obj->nodeId(true); |
- | |
110 | $output['ra_email'] = $obj->getRaMail(); |
- | |
111 | $output['comment'] = $obj->getComment(); |
- | |
112 | $output['confidential'] = $obj->isConfidential(); |
248 | return $this->restApiCall_GET($endpoint, $json_in); |
113 | $output['title'] = $obj->getTitle(); |
- | |
114 | $output['description'] = $obj->getDescription(); |
- | |
115 | - | ||
116 | if ($obj instanceof OIDplusOid) { |
- | |
117 | $output['asn1ids'] = array(); // TODO: Rename to oid-alphanum-id ? |
- | |
118 | foreach ($obj->getAsn1Ids() as $asn) { |
- | |
119 | $output['asn1ids'][] = $asn->getName(); |
- | |
120 | } |
- | |
121 | - | ||
122 | $output['iris'] = array(); // TODO: Rename to oid-unicode-label ? |
- | |
123 | foreach ($obj->getIris() as $iri) { |
- | |
124 | $output['iris'][] = $iri->getName(); |
- | |
125 | } |
- | |
126 | } |
- | |
127 | - | ||
128 | http_response_code(200); |
- | |
129 | return $output; |
- | |
130 | } else if ($requestMethod == "PUT"/*Replace*/) { |
249 | } else if ($requestMethod == "PUT"/*Replace*/) { |
131 | $obj = OIDplusObject::parse($id); |
- | |
132 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'PUT', $id), null, 400); |
- | |
133 | - | ||
134 | $params = array(); |
- | |
135 | $params['id'] = $id; |
- | |
136 | $params['ra_email'] = $json_in['ra_email'] ?? ''; |
- | |
137 | $params['comment'] = $json_in['comment'] ?? ''; |
- | |
138 | $params['confidential'] = $json_in['confidential'] ?? false; |
- | |
139 | $params['title'] = $json_in['title'] ?? ''; |
- | |
140 | $params['description'] = $json_in['description'] ?? ''; |
- | |
141 | $params['asn1ids'] = $json_in['asn1ids'] ?? array(); |
- | |
142 | $params['iris'] = $json_in['iris'] ?? array(); |
- | |
143 | - | ||
144 | if (OIDplusObject::exists($id)) { |
- | |
145 | // TODO: Problem: The superior RA cannot set title/description, so they cannot perform the PUT command! |
- | |
146 | $output = self::action_Update($params); |
250 | return $this->restApiCall_PUT($endpoint, $json_in); |
147 | } else { |
- | |
148 | $params['parent'] = $obj->getParent(); |
- | |
149 | $params['id_fully_qualified'] = true; |
- | |
150 | $output = self::action_Insert($params); |
- | |
151 | } |
- | |
152 | - | ||
153 | $output['status_bits'] = []; |
- | |
154 | if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited'; |
- | |
155 | if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
- | |
156 | if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
- | |
157 | if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID'; |
- | |
158 | - | ||
159 | http_response_code(200); |
- | |
160 | return $output; |
- | |
161 | } else if ($requestMethod == "POST"/*Insert*/) { |
251 | } else if ($requestMethod == "POST"/*Insert*/) { |
162 | $params = $json_in; |
- | |
163 | $obj = OIDplusObject::parse($id); |
- | |
164 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'GET', $id), null, 400); |
- | |
165 | $params['parent'] = $obj->getParent(); |
- | |
166 | $params['id_fully_qualified'] = true; |
- | |
167 | $params['id'] = $id; |
- | |
168 | $output = self::action_Insert($params); |
252 | return $this->restApiCall_POST($endpoint, $json_in); |
169 | - | ||
170 | $output['status_bits'] = []; |
- | |
171 | if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited'; |
- | |
172 | if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
- | |
173 | if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
- | |
174 | if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID'; |
- | |
175 | - | ||
176 | http_response_code(200); |
- | |
177 | return $output; |
- | |
178 | } else if ($requestMethod == "PATCH"/*Modify*/) { |
253 | } else if ($requestMethod == "PATCH"/*Modify*/) { |
179 | $params = $json_in; |
- | |
180 | $params['id'] = $id; |
- | |
181 | $output = self::action_Update($params); |
254 | return $this->restApiCall_PATCH($endpoint, $json_in); |
182 | - | ||
183 | $output['status_bits'] = []; |
- | |
184 | if (($output['status'] & 1) == 1) $output['status_bits'][1] = 'RA is not registered, but it can be invited'; |
- | |
185 | if (($output['status'] & 2) == 2) $output['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
- | |
186 | if (($output['status'] & 4) == 4) $output['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
- | |
187 | if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID'; |
- | |
188 | - | ||
189 | http_response_code(200); |
- | |
190 | return $output; |
- | |
191 | } else if ($requestMethod == "DELETE"/*Delete*/) { |
255 | } else if ($requestMethod == "DELETE"/*Delete*/) { |
192 | $params = $json_in; |
- | |
193 | $params['id'] = $id; |
- | |
194 | $output = self::action_Delete($params); |
256 | return $this->restApiCall_DELETE($endpoint, $json_in); |
195 | - | ||
196 | $output['status_bits'] = []; |
- | |
197 | - | ||
198 | http_response_code(200); |
- | |
199 | return $output; |
- | |
200 | } else { |
257 | } else { |
201 | //throw new OIDplusException(_L("Not implemented"), null, 501); |
258 | //throw new OIDplusException(_L("Not implemented"), null, 501); |
202 | throw new OIDplusException(_L("Unsupported request method"), null, 400); |
259 | throw new OIDplusException(_L("Unsupported request method"), null, 400); |
203 | } |
260 | } |
204 | } else { |
261 | } else { |