Subversion Repositories oidplus

Rev

Rev 1294 | Rev 1299 | Go to most recent revision | Show entire file | Regard 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
         * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9
-
 
81
         * @param string $requestMethod
-
 
82
         * @param string $endpoint
80
         * @param string $endpoint
83
         * @param array $json_in
81
         * @param array $json_in
84
         * @return array|false
82
         * @return never-return
85
         */
83
         */
86
        public function restApiCall(string $requestMethod, string $endpoint, array $json_in) {
84
        private function restApiCall_OPTIONS(string $endpoint, array $json_in) {
87
                if (str_starts_with($endpoint, 'objects/')) {
-
 
88
                        $id = substr($endpoint, strlen('objects/'));
-
 
89
                        if ($requestMethod == "OPTIONS") {
-
 
90
                                header("access-control-allow-credentials: true");
85
                header("access-control-allow-credentials: true");
91
                                header("access-control-allow-headers: Keep-Alive,User-Agent,Authorization");
86
                header("access-control-allow-headers: Keep-Alive,User-Agent,Authorization");
92
                                header("access-control-allow-methods: GET, PUT, POST, DELETE, PATCH, OPTIONS");
87
                header("access-control-allow-methods: GET, PUT, POST, DELETE, PATCH, OPTIONS");
93
                                header("access-control-allow-origin: *");
88
                header("access-control-allow-origin: *");
94
                                http_response_code(204/*No content*/);
89
                http_response_code(204/*No content*/);
95
                                OIDplus::invoke_shutdown();
90
                OIDplus::invoke_shutdown();
96
                                die(); // return array();
91
                die(); // return array();
97
                        }
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 {
98
                        else if ($requestMethod == "GET"/*Select*/) {
100
                $id = substr($endpoint, strlen('objects/'));
99
                                $obj = OIDplusObject::findFitting($id);
101
                $obj = OIDplusObject::findFitting($id);
100
                                if (!$obj) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404);
102
                if (!$obj) throw new OIDplusException(_L('The object %1 was not found in this database.', $id), null, 404);
101
 
103
 
102
                                if (!$obj->userHasReadRights()) throw new OIDplusException('Insufficient authorization to read information about this object.', null, 401);
104
                if (!$obj->userHasReadRights()) throw new OIDplusException('Insufficient authorization to read information about this object.', null, 401);
103
 
105
 
Line 125... Line 127...
125
                                        }
127
                        }
126
                                }
128
                }
127
 
129
 
128
                                http_response_code(200);
130
                http_response_code(200);
129
                                return $output;
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 {
130
                        } else if ($requestMethod == "PUT"/*Replace*/) {
140
                $id = substr($endpoint, strlen('objects/'));
131
                                $obj = OIDplusObject::parse($id);
141
                $obj = OIDplusObject::parse($id);
132
                                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'PUT', $id), null, 400);
142
                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'PUT', $id), null, 400);
133
 
143
 
134
                                $params = array();
144
                $params = array();
135
                                $params['id'] = $id;
145
                $params['id'] = $id;
Line 156... Line 166...
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';
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';
157
                                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
167
                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
158
 
168
 
159
                                http_response_code(200);
169
                http_response_code(200);
160
                                return $output;
170
                return $output;
-
 
171
        }
-
 
172
 
-
 
173
        /**
161
                        } else if ($requestMethod == "POST"/*Insert*/) {
174
         * @param string $endpoint
162
                                $params = $json_in;
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/'));
163
                                $obj = OIDplusObject::parse($id);
180
                $obj = OIDplusObject::parse($id);
164
                                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'GET', $id), null, 400);
181
                if (!$obj) throw new OIDplusException(_L('%1 action failed because object "%2" cannot be parsed!', 'GET', $id), null, 400);
-
 
182
                $params = $json_in;
165
                                $params['parent'] = $obj->getParent();
183
                $params['parent'] = $obj->getParent();
166
                                $params['id_fully_qualified'] = true;
184
                $params['id_fully_qualified'] = true;
167
                                $params['id'] = $id;
185
                $params['id'] = $id;
168
                                $output = self::action_Insert($params);
186
                $output = self::action_Insert($params);
169
 
187
 
Line 173... Line 191...
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';
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';
174
                                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
192
                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
175
 
193
 
176
                                http_response_code(200);
194
                http_response_code(200);
177
                                return $output;
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 {
178
                        } else if ($requestMethod == "PATCH"/*Modify*/) {
204
                $id = substr($endpoint, strlen('objects/'));
179
                                $params = $json_in;
205
                $params = $json_in;
180
                                $params['id'] = $id;
206
                $params['id'] = $id;
181
                                $output = self::action_Update($params);
207
                $output = self::action_Update($params);
182
 
208
 
183
                                $output['status_bits'] = [];
209
                $output['status_bits'] = [];
Line 186... Line 212...
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';
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';
187
                                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
213
                if (($output['status'] & 8) == 8) $output['status_bits'][8] = 'User has write rights to the freshly created OID';
188
 
214
 
189
                                http_response_code(200);
215
                http_response_code(200);
190
                                return $output;
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 {
191
                        } else if ($requestMethod == "DELETE"/*Delete*/) {
225
                $id = substr($endpoint, strlen('objects/'));
192
                                $params = $json_in;
226
                $params = $json_in;
193
                                $params['id'] = $id;
227
                $params['id'] = $id;
194
                                $output = self::action_Delete($params);
228
                $output = self::action_Delete($params);
195
 
229
 
196
                                $output['status_bits'] = [];
230
                $output['status_bits'] = [];
197
 
231
 
198
                                http_response_code(200);
232
                http_response_code(200);
199
                                return $output;
233
                return $output;
-
 
234
        }
-
 
235
 
-
 
236
        /**
-
 
237
         * Implements INTF_OID_1_3_6_1_4_1_37476_2_5_2_3_9
-
 
238
         * @param string $requestMethod
-
 
239
         * @param string $endpoint
-
 
240
         * @param array $json_in
-
 
241
         * @return array|false
-
 
242
         */
-
 
243
        public function restApiCall(string $requestMethod, string $endpoint, array $json_in) {
-
 
244
                if (str_starts_with($endpoint, 'objects/')) {
-
 
245
                        if ($requestMethod == "OPTIONS") {
-
 
246
                                $this->restApiCall_OPTIONS($endpoint, $json_in);
-
 
247
                        }  else if ($requestMethod == "GET"/*Select*/) {
-
 
248
                                return $this->restApiCall_GET($endpoint, $json_in);
-
 
249
                        } else if ($requestMethod == "PUT"/*Replace*/) {
-
 
250
                                return $this->restApiCall_PUT($endpoint, $json_in);
-
 
251
                        } else if ($requestMethod == "POST"/*Insert*/) {
-
 
252
                                return $this->restApiCall_POST($endpoint, $json_in);
-
 
253
                        } else if ($requestMethod == "PATCH"/*Modify*/) {
-
 
254
                                return $this->restApiCall_PATCH($endpoint, $json_in);
-
 
255
                        } else if ($requestMethod == "DELETE"/*Delete*/) {
-
 
256
                                return $this->restApiCall_DELETE($endpoint, $json_in);
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 {