66,7 → 66,6 |
* @return array|false |
*/ |
public function restApiCall(string $requestMethod, string $endpoint, array $json_in) { |
// TODO: Translate status bit-fields that are returned from action() into human readable JSON boolean fields |
if (str_starts_with($endpoint, 'objects/')) { |
$id = substr($endpoint, strlen('objects/')); |
if ($requestMethod == "GET"/*Select*/) { |
95,6 → 94,8 |
$output['iris'][] = $row_iri['name']; |
} |
|
$res['status_bits'] = []; |
|
http_response_code(200); |
$output['status'] = 0/*OK*/; |
return $output; |
120,6 → 121,13 |
$params['id_fully_qualified'] = true; |
$res = self::action('Insert', $params); |
} |
|
$res['status_bits'] = []; |
if (($res['status'] & 1) == 1) $res['status_bits'][1] = 'RA is not registered, but it can be invited'; |
if (($res['status'] & 2) == 2) $res['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
if (($res['status'] & 4) == 4) $res['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
if (($res['status'] & 8) == 8) $res['status_bits'][8] = 'User has write rights to the freshly created OID'; |
|
http_response_code(200); |
return $res; |
} else if ($requestMethod == "POST"/*Insert*/) { |
130,6 → 138,13 |
$params['id_fully_qualified'] = true; |
$params['id'] = $id; |
$res = self::action('Insert', $params); |
|
$res['status_bits'] = []; |
if (($res['status'] & 1) == 1) $res['status_bits'][1] = 'RA is not registered, but it can be invited'; |
if (($res['status'] & 2) == 2) $res['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
if (($res['status'] & 4) == 4) $res['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
if (($res['status'] & 8) == 8) $res['status_bits'][8] = 'User has write rights to the freshly created OID'; |
|
http_response_code(200); |
return $res; |
} else if ($requestMethod == "PATCH"/*Modify*/) { |
136,6 → 151,13 |
$params = $json_in; |
$params['id'] = $id; |
$res = self::action('Update', $params); |
|
$res['status_bits'] = []; |
if (($res['status'] & 1) == 1) $res['status_bits'][1] = 'RA is not registered, but it can be invited'; |
if (($res['status'] & 2) == 2) $res['status_bits'][2] = 'RA is not registered and it cannot be invited'; |
if (($res['status'] & 4) == 4) $res['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset'; |
if (($res['status'] & 8) == 8) $res['status_bits'][8] = 'User has write rights to the freshly created OID'; |
|
http_response_code(200); |
return $res; |
} else if ($requestMethod == "DELETE"/*Delete*/) { |
142,6 → 164,9 |
$params = $json_in; |
$params['id'] = $id; |
$res = self::action('Delete', $params); |
|
$res['status_bits'] = []; |
|
http_response_code(200); |
return $res; |
} else { |
154,27 → 179,6 |
} |
|
/** |
* @param array $struct |
* @return string |
*/ |
private function array_to_html_ul_li(array $struct): string { |
// TODO: put in includes/functions.inc.php |
$res = ''; |
$res .= '<ul>'; |
foreach ($struct as $name => $val) { |
$res .= '<li>'; |
if (is_array($val)) { |
$res .= $name . self::array_to_html_ul_li($val); |
} else { |
$res .= $val; |
} |
$res .= '</li>'; |
} |
$res .= '</ul>'; |
return $res; |
} |
|
/** |
* Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9 |
* Outputs information about valid endpoints |
* @param string $kind Reserved for different kind of output format (i.e. OpenAPI "TODO"). Currently only 'html' is implemented |
190,6 → 194,7 |
], |
_L('Output parameters') => [ |
'status ('._L('<0 is error, >=0 is success').')', |
'status_bits', |
'error ('._L('if an error occurred').')', |
'ra_email', |
'comment', |
213,6 → 218,7 |
], |
_L('Output parameters') => [ |
'status ('._L('<0 is error, >=0 is success').')', |
'status_bits', |
'error ('._L('if an error occurred').')', |
'inserted_id ('._L('if it was created').')' |
] |
230,6 → 236,7 |
], |
_L('Output parameters') => [ |
'status ('._L('<0 is error, >=0 is success').')', |
'status_bits', |
'error ('._L('if an error occurred').')', |
'inserted_id' |
] |
247,21 → 254,23 |
], |
_L('Output parameters') => [ |
'status ('._L('<0 is error, >=0 is success').')', |
'status_bits', |
'error ('._L('if an error occurred').')', |
] |
], |
_L('Remove') => [ |
'<b>DELETE</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>'. |
'<b>DELETE</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>', |
_L('Input parameters') => [ |
'<i>'._L('None').'</i>' |
], |
_L('Output parameters') => [ |
'status ('._L('<0 is error, >=0 is success').')', |
'status_bits', |
'error ('._L('if an error occurred').')', |
] |
] |
]; |
return self::array_to_html_ul_li($struct); |
return array_to_html_ul_li($struct); |
} else { |
throw new OIDplusException(_L('Invalid REST API information format'), null, 500); |
} |
341,9 → 350,9 |
// Action: Update |
// Parameters: id, ra_email, comment, iris, asn1ids, confidential, title, description |
// Outputs: <0 Error, =0 Success, with following bitfields for further information: |
// x+1 = RA is not registered |
// x+2 = RA is not registered, but it cannot be invited |
// x+4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset |
// x+1 = RA is not registered, but it can be invited |
// x+2 = RA is not registered and it cannot be invited |
// x+4 = OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset |
// x+8 = User has write rights to the freshly created OID |
else if ($actionID == 'Update') { |
_CheckParamExists($params, 'id'); |
516,9 → 525,9 |
// Action: Insert |
// Parameters: parent, id (relative!), ra_email, comment, iris, asn1ids, confidential, title, description |
// Outputs: status=<0 Error, =0 Success, with following bitfields for further information: |
// x+1 = RA is not registered |
// x+2 = RA is not registered, but it cannot be invited |
// x+4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset |
// x+1 = RA is not registered, but it can be invited |
// x+2 = RA is not registered and it cannot be invited |
// x+4 = OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset |
// x+8 = User has write rights to the freshly created OID |
else if ($actionID == 'Insert') { |
// Check if you have write rights on the parent (to create a new object) |