Subversion Repositories oidplus

Rev

Rev 1275 | Rev 1277 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1275 Rev 1276
Line 64... Line 64...
64
         * @param string $endpoint
64
         * @param string $endpoint
65
         * @param array $json_in
65
         * @param array $json_in
66
         * @return array|false
66
         * @return array|false
67
         */
67
         */
68
        public function restApiCall(string $requestMethod, string $endpoint, array $json_in) {
68
        public function restApiCall(string $requestMethod, string $endpoint, array $json_in) {
69
                // TODO: Translate status bit-fields that are returned from action() into human readable JSON boolean fields
-
 
70
                if (str_starts_with($endpoint, 'objects/')) {
69
                if (str_starts_with($endpoint, 'objects/')) {
71
                        $id = substr($endpoint, strlen('objects/'));
70
                        $id = substr($endpoint, strlen('objects/'));
72
                        if ($requestMethod == "GET"/*Select*/) {
71
                        if ($requestMethod == "GET"/*Select*/) {
73
                                $output = array();
72
                                $output = array();
74
 
73
 
Line 93... Line 92...
93
                                $res_iri = OIDplus::db()->query("select name from ###iri where oid = ?", array($id));
92
                                $res_iri = OIDplus::db()->query("select name from ###iri where oid = ?", array($id));
94
                                while ($row_iri = $res_iri->fetch_array()) {
93
                                while ($row_iri = $res_iri->fetch_array()) {
95
                                        $output['iris'][] = $row_iri['name'];
94
                                        $output['iris'][] = $row_iri['name'];
96
                                }
95
                                }
97
 
96
 
-
 
97
                                $res['status_bits'] = [];
-
 
98
 
98
                                http_response_code(200);
99
                                http_response_code(200);
99
                                $output['status'] = 0/*OK*/;
100
                                $output['status'] = 0/*OK*/;
100
                                return $output;
101
                                return $output;
101
                        } else if ($requestMethod == "PUT"/*Replace*/) {
102
                        } else if ($requestMethod == "PUT"/*Replace*/) {
102
                                $obj = OIDplusObject::parse($id);
103
                                $obj = OIDplusObject::parse($id);
Line 118... Line 119...
118
                                } else {
119
                                } else {
119
                                        $params['parent'] = $obj->getParent();
120
                                        $params['parent'] = $obj->getParent();
120
                                        $params['id_fully_qualified'] = true;
121
                                        $params['id_fully_qualified'] = true;
121
                                        $res = self::action('Insert', $params);
122
                                        $res = self::action('Insert', $params);
122
                                }
123
                                }
-
 
124
 
-
 
125
                                $res['status_bits'] = [];
-
 
126
                                if (($res['status'] & 1) == 1) $res['status_bits'][1] = 'RA is not registered, but it can be invited';
-
 
127
                                if (($res['status'] & 2) == 2) $res['status_bits'][2] = 'RA is not registered and it cannot be invited';
-
 
128
                                if (($res['status'] & 4) == 4) $res['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset';
-
 
129
                                if (($res['status'] & 8) == 8) $res['status_bits'][8] = 'User has write rights to the freshly created OID';
-
 
130
 
123
                                http_response_code(200);
131
                                http_response_code(200);
124
                                return $res;
132
                                return $res;
125
                        } else if ($requestMethod == "POST"/*Insert*/) {
133
                        } else if ($requestMethod == "POST"/*Insert*/) {
126
                                $params = $json_in;
134
                                $params = $json_in;
127
                                $obj = OIDplusObject::parse($id);
135
                                $obj = OIDplusObject::parse($id);
128
                                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'GET', $id), null, 400);
136
                                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'GET', $id), null, 400);
129
                                $params['parent'] = $obj->getParent();
137
                                $params['parent'] = $obj->getParent();
130
                                $params['id_fully_qualified'] = true;
138
                                $params['id_fully_qualified'] = true;
131
                                $params['id'] = $id;
139
                                $params['id'] = $id;
132
                                $res = self::action('Insert', $params);
140
                                $res = self::action('Insert', $params);
-
 
141
 
-
 
142
                                $res['status_bits'] = [];
-
 
143
                                if (($res['status'] & 1) == 1) $res['status_bits'][1] = 'RA is not registered, but it can be invited';
-
 
144
                                if (($res['status'] & 2) == 2) $res['status_bits'][2] = 'RA is not registered and it cannot be invited';
-
 
145
                                if (($res['status'] & 4) == 4) $res['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset';
-
 
146
                                if (($res['status'] & 8) == 8) $res['status_bits'][8] = 'User has write rights to the freshly created OID';
-
 
147
 
133
                                http_response_code(200);
148
                                http_response_code(200);
134
                                return $res;
149
                                return $res;
135
                        } else if ($requestMethod == "PATCH"/*Modify*/) {
150
                        } else if ($requestMethod == "PATCH"/*Modify*/) {
136
                                $params = $json_in;
151
                                $params = $json_in;
137
                                $params['id'] = $id;
152
                                $params['id'] = $id;
138
                                $res = self::action('Update', $params);
153
                                $res = self::action('Update', $params);
-
 
154
 
-
 
155
                                $res['status_bits'] = [];
-
 
156
                                if (($res['status'] & 1) == 1) $res['status_bits'][1] = 'RA is not registered, but it can be invited';
-
 
157
                                if (($res['status'] & 2) == 2) $res['status_bits'][2] = 'RA is not registered and it cannot be invited';
-
 
158
                                if (($res['status'] & 4) == 4) $res['status_bits'][4] = 'OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset';
-
 
159
                                if (($res['status'] & 8) == 8) $res['status_bits'][8] = 'User has write rights to the freshly created OID';
-
 
160
 
139
                                http_response_code(200);
161
                                http_response_code(200);
140
                                return $res;
162
                                return $res;
141
                        } else if ($requestMethod == "DELETE"/*Delete*/) {
163
                        } else if ($requestMethod == "DELETE"/*Delete*/) {
142
                                $params = $json_in;
164
                                $params = $json_in;
143
                                $params['id'] = $id;
165
                                $params['id'] = $id;
144
                                $res = self::action('Delete', $params);
166
                                $res = self::action('Delete', $params);
-
 
167
 
-
 
168
                                $res['status_bits'] = [];
-
 
169
 
145
                                http_response_code(200);
170
                                http_response_code(200);
146
                                return $res;
171
                                return $res;
147
                        } else {
172
                        } else {
148
                                //throw new OIDplusException(_L("Not implemented"), null, 501);
173
                                //throw new OIDplusException(_L("Not implemented"), null, 501);
149
                                throw new OIDplusException(_L("Unsupported request method"), null, 400);
174
                                throw new OIDplusException(_L("Unsupported request method"), null, 400);
Line 152... Line 177...
152
                        return false;
177
                        return false;
153
                }
178
                }
154
        }
179
        }
155
 
180
 
156
        /**
181
        /**
157
         * @param array $struct
-
 
158
         * @return string
-
 
159
         */
-
 
160
        private function array_to_html_ul_li(array $struct): string {
-
 
161
                // TODO: put in includes/functions.inc.php
-
 
162
                $res = '';
-
 
163
                $res .= '<ul>';
-
 
164
                foreach ($struct as $name => $val) {
-
 
165
                        $res .= '<li>';
-
 
166
                        if (is_array($val)) {
-
 
167
                                $res .= $name . self::array_to_html_ul_li($val);
-
 
168
                        } else {
-
 
169
                                $res .= $val;
-
 
170
                        }
-
 
171
                        $res .= '</li>';
-
 
172
                }
-
 
173
                $res .= '</ul>';
-
 
174
                return $res;
-
 
175
        }
-
 
176
 
-
 
177
        /**
-
 
178
         * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9
182
         * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9
179
         * Outputs information about valid endpoints
183
         * Outputs information about valid endpoints
180
         * @param string $kind Reserved for different kind of output format (i.e. OpenAPI "TODO"). Currently only 'html' is implemented
184
         * @param string $kind Reserved for different kind of output format (i.e. OpenAPI "TODO"). Currently only 'html' is implemented
181
         * @return string
185
         * @return string
182
         */
186
         */
Line 188... Line 192...
188
                                        _L('Input parameters') => [
192
                                        _L('Input parameters') => [
189
                                                '<i>'._L('None').'</i>'
193
                                                '<i>'._L('None').'</i>'
190
                                        ],
194
                                        ],
191
                                        _L('Output parameters') => [
195
                                        _L('Output parameters') => [
192
                                                'status ('._L('<0 is error, >=0 is success').')',
196
                                                'status ('._L('<0 is error, >=0 is success').')',
-
 
197
                                                'status_bits',
193
                                                'error ('._L('if an error occurred').')',
198
                                                'error ('._L('if an error occurred').')',
194
                                                'ra_email',
199
                                                'ra_email',
195
                                                'comment',
200
                                                'comment',
196
                                                'iris',
201
                                                'iris',
197
                                                'asn1ids',
202
                                                'asn1ids',
Line 211... Line 216...
211
                                                'title ('._L('optional').')',
216
                                                'title ('._L('optional').')',
212
                                                'description ('._L('optional').')'
217
                                                'description ('._L('optional').')'
213
                                        ],
218
                                        ],
214
                                        _L('Output parameters') => [
219
                                        _L('Output parameters') => [
215
                                                'status ('._L('<0 is error, >=0 is success').')',
220
                                                'status ('._L('<0 is error, >=0 is success').')',
-
 
221
                                                'status_bits',
216
                                                'error ('._L('if an error occurred').')',
222
                                                'error ('._L('if an error occurred').')',
217
                                                'inserted_id ('._L('if it was created').')'
223
                                                'inserted_id ('._L('if it was created').')'
218
                                        ]
224
                                        ]
219
                                ],
225
                                ],
220
                                _L('Create') => [
226
                                _L('Create') => [
Line 228... Line 234...
228
                                                'title ('._L('optional').')',
234
                                                'title ('._L('optional').')',
229
                                                'description ('._L('optional').')'
235
                                                'description ('._L('optional').')'
230
                                        ],
236
                                        ],
231
                                        _L('Output parameters') => [
237
                                        _L('Output parameters') => [
232
                                                'status ('._L('<0 is error, >=0 is success').')',
238
                                                'status ('._L('<0 is error, >=0 is success').')',
-
 
239
                                                'status_bits',
233
                                                'error ('._L('if an error occurred').')',
240
                                                'error ('._L('if an error occurred').')',
234
                                                'inserted_id'
241
                                                'inserted_id'
235
                                        ]
242
                                        ]
236
                                ],
243
                                ],
237
                                _L('Update') => [
244
                                _L('Update') => [
Line 245... Line 252...
245
                                                'title ('._L('optional').')',
252
                                                'title ('._L('optional').')',
246
                                                'description ('._L('optional').')'
253
                                                'description ('._L('optional').')'
247
                                        ],
254
                                        ],
248
                                        _L('Output parameters') => [
255
                                        _L('Output parameters') => [
249
                                                'status ('._L('<0 is error, >=0 is success').')',
256
                                                'status ('._L('<0 is error, >=0 is success').')',
-
 
257
                                                'status_bits',
250
                                                'error ('._L('if an error occurred').')',
258
                                                'error ('._L('if an error occurred').')',
251
                                        ]
259
                                        ]
252
                                ],
260
                                ],
253
                                _L('Remove') => [
261
                                _L('Remove') => [
254
                                        '<b>DELETE</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>'.
262
                                        '<b>DELETE</b> '.OIDplus::webpath(null,OIDplus::PATH_ABSOLUTE_CANONICAL).'rest/v1/objects/<abbr title="'._L('e.g. %1', 'oid:2.999').'">[id]</abbr>',
255
                                        _L('Input parameters') => [
263
                                        _L('Input parameters') => [
256
                                                '<i>'._L('None').'</i>'
264
                                                '<i>'._L('None').'</i>'
257
                                        ],
265
                                        ],
258
                                        _L('Output parameters') => [
266
                                        _L('Output parameters') => [
259
                                                'status ('._L('<0 is error, >=0 is success').')',
267
                                                'status ('._L('<0 is error, >=0 is success').')',
-
 
268
                                                'status_bits',
260
                                                'error ('._L('if an error occurred').')',
269
                                                'error ('._L('if an error occurred').')',
261
                                        ]
270
                                        ]
262
                                ]
271
                                ]
263
                        ];
272
                        ];
264
                        return self::array_to_html_ul_li($struct);
273
                        return array_to_html_ul_li($struct);
265
                } else {
274
                } else {
266
                        throw new OIDplusException(_L('Invalid REST API information format'), null, 500);
275
                        throw new OIDplusException(_L('Invalid REST API information format'), null, 500);
267
                }
276
                }
268
        }
277
        }
269
 
278
 
Line 339... Line 348...
339
                }
348
                }
340
 
349
 
341
                // Action:     Update
350
                // Action:     Update
342
                // Parameters: id, ra_email, comment, iris, asn1ids, confidential, title, description
351
                // Parameters: id, ra_email, comment, iris, asn1ids, confidential, title, description
343
                // Outputs:    <0 Error, =0 Success, with following bitfields for further information:
352
                // Outputs:    <0 Error, =0 Success, with following bitfields for further information:
344
                //             x+1 = RA is not registered
353
                //             x+1 = RA is not registered, but it can be invited
345
                //             x+2 = RA is not registered, but it cannot be invited
354
                //             x+2 = RA is not registered and it cannot be invited
346
                //             x+4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset
355
                //             x+4 = OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset
347
                //             x+8 = User has write rights to the freshly created OID
356
                //             x+8 = User has write rights to the freshly created OID
348
                else if ($actionID == 'Update') {
357
                else if ($actionID == 'Update') {
349
                        _CheckParamExists($params, 'id');
358
                        _CheckParamExists($params, 'id');
350
                        $id = $params['id'];
359
                        $id = $params['id'];
351
                        $obj = OIDplusObject::parse($id);
360
                        $obj = OIDplusObject::parse($id);
Line 514... Line 523...
514
                }
523
                }
515
 
524
 
516
                // Action:     Insert
525
                // Action:     Insert
517
                // Parameters: parent, id (relative!), ra_email, comment, iris, asn1ids, confidential, title, description
526
                // Parameters: parent, id (relative!), ra_email, comment, iris, asn1ids, confidential, title, description
518
                // Outputs:    status=<0 Error, =0 Success, with following bitfields for further information:
527
                // Outputs:    status=<0 Error, =0 Success, with following bitfields for further information:
519
                //             x+1 = RA is not registered
528
                //             x+1 = RA is not registered, but it can be invited
520
                //             x+2 = RA is not registered, but it cannot be invited
529
                //             x+2 = RA is not registered and it cannot be invited
521
                //             x+4 = OID is a well-known OID, so RA, ASN.1 and IRI identifiers were reset
530
                //             x+4 = OID is a well-known OID, so RA, ASN.1, and IRI identifiers were reset
522
                //             x+8 = User has write rights to the freshly created OID
531
                //             x+8 = User has write rights to the freshly created OID
523
                else if ($actionID == 'Insert') {
532
                else if ($actionID == 'Insert') {
524
                        // Check if you have write rights on the parent (to create a new object)
533
                        // Check if you have write rights on the parent (to create a new object)
525
                        _CheckParamExists($params, 'parent');
534
                        _CheckParamExists($params, 'parent');
526
                        $objParent = OIDplusObject::parse($params['parent']);
535
                        $objParent = OIDplusObject::parse($params['parent']);