Rev 1290 | Rev 1292 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1290 | Rev 1291 | ||
---|---|---|---|
Line 141... | Line 141... | ||
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'; |
Line 163... | Line 163... | ||
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'; |
Line 176... | Line 176... | ||
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'; |
Line 189... | Line 189... | ||
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; |
Line 303... | Line 303... | ||
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 |
- | |
309 | * @param array $params |
308 | * @param array $params id |
310 | * @return array |
309 | * @return array status<0 Error, =0 Success |
311 | * @throws OIDplusConfigInitializationException |
310 | * @throws OIDplusConfigInitializationException |
312 | * @throws OIDplusException |
311 | * @throws OIDplusException |
313 | */ |
312 | */ |
314 | public function action(string $actionID, array $params): array { |
313 | private function action_Delete(array $params): array { |
315 | - | ||
316 | // Action: Delete |
- | |
317 | // Parameters: id |
- | |
318 | // Outputs: <0 Error, =0 Success |
- | |
319 | if ($actionID == 'Delete') { |
- | |
320 | _CheckParamExists($params, 'id'); |
314 | _CheckParamExists($params, 'id'); |
321 | $id = $params['id']; |
315 | $id = $params['id']; |
322 | $obj = OIDplusObject::parse($id); |
316 | $obj = OIDplusObject::parse($id); |
323 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id)); |
317 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','DELETE',$id)); |
324 | 318 | ||
Line 373... | Line 367... | ||
373 | } |
367 | } |
374 | 368 | ||
375 | return array("status" => 0); |
369 | return array("status" => 0); |
376 | } |
370 | } |
377 | 371 | ||
378 | // Action: Update |
372 | /** |
379 | // Parameters: id, ra_email, comment, iris, asn1ids, confidential, title, description |
373 | * @param array $params id, ra_email, comment, iris, asn1ids, confidential, title, description |
380 | // Outputs: <0 Error, =0 Success, with following bitfields for further information: |
374 | * @return array status<0 Error, =0 Success, with the following bitfields for further information: |
381 | // x+1 = RA is not registered, but it can be invited |
375 | * x+1 = RA is not registered, but it can be invited |
382 | // x+2 = RA is not registered and it cannot be invited |
376 | * 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 |
377 | * 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 |
378 | * x+8 = User has write rights to the freshly created OID |
- | 379 | * @throws OIDplusConfigInitializationException |
|
- | 380 | * @throws OIDplusException |
|
- | 381 | */ |
|
385 | else if ($actionID == 'Update') { |
382 | public function action_Update(array $params): array { |
386 | _CheckParamExists($params, 'id'); |
383 | _CheckParamExists($params, 'id'); |
387 | $id = $params['id']; |
384 | $id = $params['id']; |
388 | $obj = OIDplusObject::parse($id); |
385 | $obj = OIDplusObject::parse($id); |
389 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id)); |
386 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','UPDATE',$id)); |
390 | 387 | ||
Line 537... | Line 534... | ||
537 | } |
534 | } |
538 | 535 | ||
539 | return array("status" => $status); |
536 | return array("status" => $status); |
540 | } |
537 | } |
541 | 538 | ||
542 | // Generate UUID |
- | |
543 | else if ($actionID == 'generate_uuid') { |
- | |
544 | $uuid = gen_uuid(OIDplus::config()->getValue('uuid_prefer_timebased', '1') == '1'); |
- | |
545 | if (!$uuid) return array("status" => 1); |
- | |
546 | return array( |
- | |
547 | "status" => 0, |
- | |
548 | "uuid" => $uuid, |
- | |
549 | "intval" => substr(uuid_to_oid($uuid),strlen('2.25.')) |
- | |
550 | ); |
- | |
551 | } |
539 | /** |
552 | - | ||
553 | // Action: Insert |
- | |
554 | // Parameters: parent, id (relative!), ra_email, comment, iris, asn1ids, confidential, title, description |
540 | * @param array $params parent, id (relative!), ra_email, comment, iris, asn1ids, confidential, title, description |
555 | // Outputs: status=<0 Error, =0 Success, with following bitfields for further information: |
541 | * @return array status=<0 Error, =0 Success, with the following bitfields for further information: |
556 | // x+1 = RA is not registered, but it can be invited |
542 | * x+1 = RA is not registered, but it can be invited |
557 | // x+2 = RA is not registered and it cannot be invited |
543 | * 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 |
544 | * 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 |
545 | * x+8 = User has write rights to the freshly created OID |
- | 546 | * @throws OIDplusConfigInitializationException |
|
- | 547 | * @throws OIDplusException |
|
- | 548 | */ |
|
560 | else if ($actionID == 'Insert') { |
549 | public function action_Insert(array $params): array { |
561 | // Check if you have write rights on the parent (to create a new object) |
550 | // Check if you have write rights on the parent (to create a new object) |
562 | _CheckParamExists($params, 'parent'); |
551 | _CheckParamExists($params, 'parent'); |
563 | $objParent = OIDplusObject::parse($params['parent']); |
552 | $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'])); |
553 | if (!$objParent) throw new OIDplusException(_L('%1 action failed because parent object "%2" cannot be parsed!','INSERT',$params['parent'])); |
565 | 554 | ||
Line 591... | Line 580... | ||
591 | } |
580 | } |
592 | } |
581 | } |
593 | 582 | ||
594 | // Determine absolute OID name |
583 | // Determine absolute OID name |
595 | // Note: At addString() and parse(), the syntax of the ID will be checked |
584 | // Note: At addString() and parse(), the syntax of the ID will be checked |
596 | if (isset($params['id_fully_qualified']) && is_string($params['id_fully_qualified'])) $params['id_fully_qualified'] = $params['id_fully_qualified'] == 'true'; |
585 | $is_absolute = isset($params['id_fully_qualified']) && $params['id_fully_qualified'] == 'true';; |
597 | if ($params['id_fully_qualified'] ?? false) { |
586 | if ($is_absolute) { |
- | 587 | // For REST API, the ID is absolute (because this is what is in the URL). We need to verify that ID and Parent matches. |
|
598 | $id = $params['id']; |
588 | $id = $params['id']; |
599 | $obj = OIDplusObject::parse($id); |
589 | $obj = OIDplusObject::parse($id); |
600 | $objParentTest = $obj->getParent(); |
590 | $objParentTest = !$obj ? null : $obj->getParent(); |
601 | if (!$objParentTest || !$objParentTest->equals($objParent)) throw new OIDplusException(_L('Cannot verify that %1 has parent %2', $obj->nodeId(), $objParent->nodeId())); |
591 | if (!$objParentTest || !$objParentTest->equals($objParent)) throw new OIDplusException(_L('Cannot verify that %1 has parent %2', $obj->nodeId(), $objParent->nodeId())); |
602 | } else { |
592 | } else { |
- | 593 | // For AJAX/UI, the ID is relative to the parent. The absolute ID will be created by PHP's addString(), because JavaScript cannot know the syntax of the Object Type plugin |
|
603 | $id = $objParent->addString($params['id']); |
594 | $id = $objParent->addString($params['id']); |
604 | $obj = OIDplusObject::parse($id); |
595 | $obj = OIDplusObject::parse($id); |
605 | } |
596 | } |
606 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id)); |
597 | if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!','INSERT',$id)); |
607 | 598 | ||
Line 715... | Line 706... | ||
715 | 706 | ||
716 | return array( |
707 | return array( |
717 | "status" => $status, |
708 | "status" => $status, |
718 | "inserted_id" => $id |
709 | "inserted_id" => $id |
719 | ); |
710 | ); |
- | 711 | } |
|
- | 712 | ||
- | 713 | /** |
|
- | 714 | * @param string $actionID |
|
- | 715 | * @param array $params |
|
- | 716 | * @return array |
|
- | 717 | * @throws OIDplusConfigInitializationException |
|
- | 718 | * @throws OIDplusException |
|
- | 719 | */ |
|
- | 720 | public function action(string $actionID, array $params): array { |
|
- | 721 | if ($actionID == 'Delete') { |
|
- | 722 | return $this->action_Delete($params); |
|
- | 723 | } else if ($actionID == 'Update') { |
|
- | 724 | return $this->action_Update($params); |
|
- | 725 | } else if ($actionID == 'Insert') { |
|
- | 726 | return $this->action_Insert($params); |
|
- | 727 | } else if ($actionID == 'generate_uuid') { |
|
- | 728 | // Generate UUID (will be used by a few plugins) |
|
- | 729 | $uuid = gen_uuid(OIDplus::config()->getValue('uuid_prefer_timebased', '1') == '1'); |
|
- | 730 | if (!$uuid) return array("status" => 1); |
|
- | 731 | return array( |
|
- | 732 | "status" => 0, |
|
- | 733 | "uuid" => $uuid, |
|
- | 734 | "intval" => substr(uuid_to_oid($uuid),strlen('2.25.')) |
|
- | 735 | ); |
|
720 | } else { |
736 | } else { |
721 | return parent::action($actionID, $params); |
737 | return parent::action($actionID, $params); |
722 | } |
738 | } |
723 | } |
739 | } |
724 | 740 |