| 1 | package WWW::Suffit::Server::API::Admin; | ||
| 2 | use strict; | ||
| 3 | use utf8; | ||
| 4 | |||
| 5 | =encoding utf8 | ||
| 6 | |||
| 7 | =head1 NAME | ||
| 8 | |||
| 9 | WWW::Suffit::Server::API::Admin - The Suffit API controller for admin management | ||
| 10 | |||
| 11 | =head1 SYNOPSIS | ||
| 12 | |||
| 13 | use WWW::Suffit::Server::API::Admin; | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | The Suffit API controller for admin management | ||
| 18 | |||
| 19 | This module uses the following configuration directives: | ||
| 20 | |||
| 21 | =over 8 | ||
| 22 | |||
| 23 | =item JWS_Algorithm | ||
| 24 | |||
| 25 | Allowed JWS signing algorithms: B<HS256>, B<HS384>, B<HS512>, B<RS256>, B<RS384>, B<RS512> | ||
| 26 | |||
| 27 | HS256 HMAC+SHA256 integrity | ||
| 28 | HS384 HMAC+SHA384 integrity | ||
| 29 | HS512 HMAC+SHA512 integrity | ||
| 30 | RS256 RSA+PKCS1-V1_5 + SHA256 signature | ||
| 31 | RS384 RSA+PKCS1-V1_5 + SHA384 signature | ||
| 32 | RS512 RSA+PKCS1-V1_5 + SHA512 signature | ||
| 33 | |||
| 34 | Default: B<HS256> | ||
| 35 | |||
| 36 | =item SessionExpires | ||
| 37 | |||
| 38 | SessionExpires +1h | ||
| 39 | SessionExpires 3600 | ||
| 40 | |||
| 41 | This directive defines time of session expiration in formatted time units | ||
| 42 | |||
| 43 | Default: 3600 (1 hour) | ||
| 44 | |||
| 45 | =item TokenExpires | ||
| 46 | |||
| 47 | TokenExpires +1d | ||
| 48 | TokenExpires 86400 | ||
| 49 | TokenExpires 20h | ||
| 50 | TokenExpires 1M | ||
| 51 | |||
| 52 | This directive defines expiration period of the issued JWT tokens | ||
| 53 | |||
| 54 | Default: 86400 (1 day) | ||
| 55 | |||
| 56 | =back | ||
| 57 | |||
| 58 | =head1 METHODS | ||
| 59 | |||
| 60 | List of internal methods | ||
| 61 | |||
| 62 | =head2 group_enroll | ||
| 63 | |||
| 64 | See L</"POST /api/admin/group/GROUPNAME/enroll"> | ||
| 65 | |||
| 66 | =head2 group_del | ||
| 67 | |||
| 68 | See L</"DELETE /api/admin/group/GROUPNAME"> | ||
| 69 | |||
| 70 | =head2 group_members | ||
| 71 | |||
| 72 | See L</"GET /api/admin/group/GROUPNAME/members"> | ||
| 73 | |||
| 74 | =head2 group_get | ||
| 75 | |||
| 76 | See L</"GET /api/admin/group"> | ||
| 77 | and L</"GET /api/admin/group/GROUPNAME"> | ||
| 78 | |||
| 79 | =head2 group_set | ||
| 80 | |||
| 81 | See L</"POST /api/admin/group"> | ||
| 82 | and L</"PUT /api/admin/group/GROUPNAME"> | ||
| 83 | |||
| 84 | =head2 settings | ||
| 85 | |||
| 86 | See L</"GET /api/admin/settings"> | ||
| 87 | |||
| 88 | =head2 realm_del | ||
| 89 | |||
| 90 | See L</"DELETE /api/admin/realm/REALMNAME"> | ||
| 91 | |||
| 92 | =head2 realm_get | ||
| 93 | |||
| 94 | See L</"GET /api/admin/realm"> | ||
| 95 | and L</"GET /api/admin/realm/REALMNAME"> | ||
| 96 | |||
| 97 | =head2 realm_set | ||
| 98 | |||
| 99 | See L</"POST /api/admin/realm"> | ||
| 100 | and L</"PUT /api/admin/realm/REALMNAME"> | ||
| 101 | |||
| 102 | =head2 requirement_get | ||
| 103 | |||
| 104 | See L</"GET /api/admin/requirement"> | ||
| 105 | |||
| 106 | =head2 route_del | ||
| 107 | |||
| 108 | See L</"DELETE /api/admin/route/ROUTENAME"> | ||
| 109 | |||
| 110 | =head2 route_get | ||
| 111 | |||
| 112 | See L</"GET /api/admin/route"> | ||
| 113 | and L</"GET /api/admin/route/ROUTENAME"> | ||
| 114 | |||
| 115 | =head2 route_set | ||
| 116 | |||
| 117 | See L</"POST /api/admin/route"> | ||
| 118 | and L</"PUT /api/admin/route/ROUTENAME"> | ||
| 119 | |||
| 120 | =head2 route_search | ||
| 121 | |||
| 122 | See L</"GET /api/admin/search/route"> | ||
| 123 | |||
| 124 | =head2 route_sysadd | ||
| 125 | |||
| 126 | See L</"POST /api/admin/sysroute"> | ||
| 127 | |||
| 128 | =head2 route_sysget | ||
| 129 | |||
| 130 | See L</"GET /api/admin/sysroute"> | ||
| 131 | |||
| 132 | =head2 user_del | ||
| 133 | |||
| 134 | See L</"DELETE /api/admin/user/USERNAME"> | ||
| 135 | |||
| 136 | =head2 user_get | ||
| 137 | |||
| 138 | See L</"GET /api/admin/user"> | ||
| 139 | and L</"GET /api/admin/user/USERNAME"> | ||
| 140 | |||
| 141 | =head2 user_groups | ||
| 142 | |||
| 143 | See L</"GET /api/admin/user/USERNAME/groups"> | ||
| 144 | |||
| 145 | =head2 user_passwd | ||
| 146 | |||
| 147 | See L</"PUT /api/admin/user/USERNAME/passwd"> | ||
| 148 | |||
| 149 | =head2 user_search | ||
| 150 | |||
| 151 | See L</"GET /api/admin/search/user"> | ||
| 152 | |||
| 153 | =head2 user_set | ||
| 154 | |||
| 155 | See L</"POST /api/admin/user"> | ||
| 156 | and L</"PUT /api/admin/user/USERNAME"> | ||
| 157 | |||
| 158 | =head1 API METHODS | ||
| 159 | |||
| 160 | List of API methods | ||
| 161 | |||
| 162 | =head2 GET /api/admin/group | ||
| 163 | |||
| 164 | Gets list of all existing groups | ||
| 165 | |||
| 166 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 167 | https://owl.localhost:8695/api/admin/group | ||
| 168 | |||
| 169 | > GET /api/admin/group HTTP/1.1 | ||
| 170 | > Host: owl.localhost:8695 | ||
| 171 | > User-Agent: curl/7.68.0 | ||
| 172 | > Accept: */* | ||
| 173 | > Authorization: OWL eyJh...Bh7g | ||
| 174 | > | ||
| 175 | < HTTP/1.1 200 OK | ||
| 176 | < Server: OWL/1.00 | ||
| 177 | < Date: Mon, 15 May 2023 14:48:22 GMT | ||
| 178 | < Content-Length: 292 | ||
| 179 | < Content-Type: application/json;charset=UTF-8 | ||
| 180 | < | ||
| 181 | [ | ||
| 182 | { | ||
| 183 | "description": "OWL Administrators", | ||
| 184 | "groupname": "admin", | ||
| 185 | "id": 3 | ||
| 186 | } | ||
| 187 | ] | ||
| 188 | |||
| 189 | =head2 POST /api/admin/group | ||
| 190 | |||
| 191 | Adds new group | ||
| 192 | |||
| 193 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 194 | -X POST -d '{ | ||
| 195 | "groupname": "FooBar", | ||
| 196 | "description": "Test group", | ||
| 197 | "members": ["alice", "test"] | ||
| 198 | }' \ | ||
| 199 | https://owl.localhost:8695/api/admin/group | ||
| 200 | |||
| 201 | > POST /api/admin/group HTTP/1.1 | ||
| 202 | > Host: owl.localhost:8695 | ||
| 203 | > User-Agent: curl/7.68.0 | ||
| 204 | > Accept: */* | ||
| 205 | > Authorization: OWL eyJh...Bh7g | ||
| 206 | > Content-Length: 112 | ||
| 207 | > Content-Type: application/x-www-form-urlencoded | ||
| 208 | > | ||
| 209 | < HTTP/1.1 200 OK | ||
| 210 | < Date: Mon, 15 May 2023 15:00:57 GMT | ||
| 211 | < Content-Length: 70 | ||
| 212 | < Server: OWL/1.00 | ||
| 213 | < Content-Type: application/json;charset=UTF-8 | ||
| 214 | < | ||
| 215 | { | ||
| 216 | "description": "Test group", | ||
| 217 | "groupname": "FooBar", | ||
| 218 | "id": 9, | ||
| 219 | "status": true | ||
| 220 | } | ||
| 221 | |||
| 222 | =head2 GET /api/admin/group/GROUPNAME | ||
| 223 | |||
| 224 | Gets group's data by groupname | ||
| 225 | |||
| 226 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 227 | https://owl.localhost:8695/api/admin/group/admin | ||
| 228 | |||
| 229 | > GET /api/admin/group/admin HTTP/1.1 | ||
| 230 | > Host: owl.localhost:8695 | ||
| 231 | > User-Agent: curl/7.68.0 | ||
| 232 | > Accept: */* | ||
| 233 | > Authorization: OWL eyJh...Bh7g | ||
| 234 | > | ||
| 235 | < HTTP/1.1 200 OK | ||
| 236 | < Content-Length: 77 | ||
| 237 | < Content-Type: application/json;charset=UTF-8 | ||
| 238 | < Date: Mon, 15 May 2023 14:50:45 GMT | ||
| 239 | < Server: OWL/1.00 | ||
| 240 | < | ||
| 241 | { | ||
| 242 | "description": "OWL Administrators", | ||
| 243 | "groupname": "admin", | ||
| 244 | "id": 3, | ||
| 245 | "status": true | ||
| 246 | } | ||
| 247 | |||
| 248 | =head2 PUT /api/admin/group/GROUPNAME | ||
| 249 | |||
| 250 | Edit the group | ||
| 251 | |||
| 252 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 253 | -X PUT -d '{ | ||
| 254 | "id": 9, | ||
| 255 | "description": "Test group", | ||
| 256 | "members": ["test"] | ||
| 257 | }' \ | ||
| 258 | https://owl.localhost:8695/api/admin/group/FooBar | ||
| 259 | |||
| 260 | > PUT /api/admin/group/FooBar HTTP/1.1 | ||
| 261 | > Host: owl.localhost:8695 | ||
| 262 | > User-Agent: curl/7.68.0 | ||
| 263 | > Accept: */* | ||
| 264 | > Authorization: OWL eyJh...Bh7g | ||
| 265 | > Content-Length: 91 | ||
| 266 | > Content-Type: application/x-www-form-urlencoded | ||
| 267 | > | ||
| 268 | < HTTP/1.1 200 OK | ||
| 269 | < Content-Type: application/json;charset=UTF-8 | ||
| 270 | < Date: Mon, 15 May 2023 15:06:28 GMT | ||
| 271 | < Content-Length: 70 | ||
| 272 | < Server: OWL/1.00 | ||
| 273 | < | ||
| 274 | { | ||
| 275 | "description": "Test group", | ||
| 276 | "groupname": "FooBar", | ||
| 277 | "id": 9, | ||
| 278 | "status": true | ||
| 279 | } | ||
| 280 | |||
| 281 | =head2 DELETE /api/admin/group/GROUPNAME | ||
| 282 | |||
| 283 | Delete group by groupname | ||
| 284 | |||
| 285 | # curl -v -X DELETE -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 286 | https://owl.localhost:8695/api/admin/group/FooBar | ||
| 287 | |||
| 288 | > DELETE /api/admin/group/FooBar HTTP/1.1 | ||
| 289 | > Host: owl.localhost:8695 | ||
| 290 | > User-Agent: curl/7.68.0 | ||
| 291 | > Accept: */* | ||
| 292 | > Authorization: OWL eyJh...Bh7g | ||
| 293 | > | ||
| 294 | < HTTP/1.1 200 OK | ||
| 295 | < Date: Mon, 15 May 2023 15:13:31 GMT | ||
| 296 | < Server: OWL/1.00 | ||
| 297 | < Content-Type: application/json;charset=UTF-8 | ||
| 298 | < Content-Length: 30 | ||
| 299 | < | ||
| 300 | { | ||
| 301 | "code": "E0000", | ||
| 302 | "status":true | ||
| 303 | } | ||
| 304 | |||
| 305 | =head2 POST /api/admin/group/GROUPNAME/enroll | ||
| 306 | |||
| 307 | Add user to group members | ||
| 308 | |||
| 309 | # curl -v -H "Authorization: OWL eyJh...j1rM" \ | ||
| 310 | -X POST -d '{ | ||
| 311 | "groupname": "wheel", | ||
| 312 | "username": "bob" | ||
| 313 | }' \ | ||
| 314 | https://owl.localhost:8695/api/admin/group/wheel/enroll | ||
| 315 | |||
| 316 | > POST /api/admin/group/wheel/enroll HTTP/1.1 | ||
| 317 | > Host: owl.localhost:8695 | ||
| 318 | > User-Agent: curl/7.68.0 | ||
| 319 | > Accept: */* | ||
| 320 | > Authorization: OWL eyJh...j1rM | ||
| 321 | > Content-Length: 65 | ||
| 322 | > Content-Type: application/x-www-form-urlencoded | ||
| 323 | > | ||
| 324 | < HTTP/1.1 200 OK | ||
| 325 | < Content-Length: 52 | ||
| 326 | < Date: Fri, 12 May 2023 13:18:34 GMT | ||
| 327 | < Content-Type: application/json;charset=UTF-8 | ||
| 328 | < Server: OWL/1.00 | ||
| 329 | < | ||
| 330 | { | ||
| 331 | "groupname": "wheel", | ||
| 332 | "status": true, | ||
| 333 | "username": "bob" | ||
| 334 | } | ||
| 335 | |||
| 336 | =head2 GET /api/admin/group/GROUPNAME/members | ||
| 337 | |||
| 338 | Gets user list of group by groupname | ||
| 339 | |||
| 340 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 341 | https://owl.localhost:8695/api/admin/group/admin/members | ||
| 342 | |||
| 343 | > GET /api/admin/group/admin/members HTTP/1.1 | ||
| 344 | > Host: owl.localhost:8695 | ||
| 345 | > User-Agent: curl/7.68.0 | ||
| 346 | > Accept: */* | ||
| 347 | > Authorization: OWL eyJh...Bh7g | ||
| 348 | > | ||
| 349 | < HTTP/1.1 200 OK | ||
| 350 | < Server: OWL/1.00 | ||
| 351 | < Date: Mon, 15 May 2023 15:19:23 GMT | ||
| 352 | < Content-Length: 161 | ||
| 353 | < Content-Type: application/json;charset=UTF-8 | ||
| 354 | < | ||
| 355 | [ | ||
| 356 | { | ||
| 357 | "id": 2, | ||
| 358 | "name": "Administrator", | ||
| 359 | "role": "Project's Administrator", | ||
| 360 | "username": "admin" | ||
| 361 | } | ||
| 362 | ] | ||
| 363 | |||
| 364 | =head2 GET /api/admin/realm | ||
| 365 | |||
| 366 | Gets list of all existing realms | ||
| 367 | |||
| 368 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 369 | https://owl.localhost:8695/api/admin/realm | ||
| 370 | |||
| 371 | > GET /api/admin/realm HTTP/1.1 | ||
| 372 | > Host: owl.localhost:8695 | ||
| 373 | > User-Agent: curl/7.68.0 | ||
| 374 | > Accept: */* | ||
| 375 | > Authorization: OWL eyJh...Bh7g | ||
| 376 | > | ||
| 377 | < HTTP/1.1 200 OK | ||
| 378 | < Content-Type: application/json;charset=UTF-8 | ||
| 379 | < Server: OWL/1.00 | ||
| 380 | < Content-Length: 281 | ||
| 381 | < Date: Mon, 15 May 2023 15:40:09 GMT | ||
| 382 | < | ||
| 383 | [ | ||
| 384 | { | ||
| 385 | "description": "This is restricted zone for test only", | ||
| 386 | "id": 13, | ||
| 387 | "realm": "Restricted zone", | ||
| 388 | "realmname": "MagicalForest", | ||
| 389 | "satisfy": "Any" | ||
| 390 | } | ||
| 391 | ] | ||
| 392 | |||
| 393 | =head2 POST /api/admin/realm | ||
| 394 | |||
| 395 | Adds new realm | ||
| 396 | |||
| 397 | # curl -v -H "Authorization: OWL eyJh...ISuA" \ | ||
| 398 | -X POST -d '{ | ||
| 399 | "realmname": "MagicalForest", | ||
| 400 | "realm": "Restricted zone", | ||
| 401 | "satisfy": "Any", | ||
| 402 | "description": "This is restricted zone for test only", | ||
| 403 | "requirements": [1], | ||
| 404 | "provider1": "User/Group", | ||
| 405 | "entity1": "Group", | ||
| 406 | "op1": "eq", | ||
| 407 | "value1": "user", | ||
| 408 | "routes": [ | ||
| 409 | "Stump" | ||
| 410 | ] | ||
| 411 | }' \ | ||
| 412 | https://owl.localhost:8695/api/admin/realm | ||
| 413 | |||
| 414 | > POST /api/admin/realm HTTP/1.1 | ||
| 415 | > Host: owl.localhost:8695 | ||
| 416 | > User-Agent: curl/7.68.0 | ||
| 417 | > Accept: */* | ||
| 418 | > Authorization: OWL eyJh...ISuA | ||
| 419 | > Content-Length: 360 | ||
| 420 | > Content-Type: application/x-www-form-urlencoded | ||
| 421 | > | ||
| 422 | < HTTP/1.1 200 OK | ||
| 423 | < Content-Length: 147 | ||
| 424 | < Content-Type: application/json;charset=UTF-8 | ||
| 425 | < Date: Mon, 15 May 2023 09:17:39 GMT | ||
| 426 | < Server: OWL/1.00 | ||
| 427 | < | ||
| 428 | { | ||
| 429 | "description": "This is restricted zone for test only", | ||
| 430 | "id": 13, | ||
| 431 | "realm": "Restricted zone", | ||
| 432 | "realmname": "MagicalForest", | ||
| 433 | "satisfy": "Any", | ||
| 434 | "status": true | ||
| 435 | } | ||
| 436 | |||
| 437 | =head2 GET /api/admin/realm/REALMNAME | ||
| 438 | |||
| 439 | Gets realm's data by realmname | ||
| 440 | |||
| 441 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 442 | https://owl.localhost:8695/api/admin/realm/MagicalForest | ||
| 443 | |||
| 444 | > GET /api/admin/realm/MagicalForest HTTP/1.1 | ||
| 445 | > Host: owl.localhost:8695 | ||
| 446 | > User-Agent: curl/7.68.0 | ||
| 447 | > Accept: */* | ||
| 448 | > Authorization: OWL eyJh...Bh7g | ||
| 449 | > | ||
| 450 | < HTTP/1.1 200 OK | ||
| 451 | < Server: OWL/1.00 | ||
| 452 | < Content-Type: application/json;charset=UTF-8 | ||
| 453 | < Date: Mon, 15 May 2023 15:42:05 GMT | ||
| 454 | < Content-Length: 149 | ||
| 455 | < | ||
| 456 | { | ||
| 457 | "description": "This is restricted zone for test only", | ||
| 458 | "id": 13, | ||
| 459 | "realm": "Restricted zone", | ||
| 460 | "realmname": "MagicalForest", | ||
| 461 | "satisfy": "Any", | ||
| 462 | "status":true | ||
| 463 | } | ||
| 464 | |||
| 465 | =head2 PUT /api/admin/realm/REALMNAME | ||
| 466 | |||
| 467 | Sets realm's data | ||
| 468 | |||
| 469 | curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 470 | -X PUT -d '{ | ||
| 471 | "id": 13, | ||
| 472 | "realmname": "MagicalForest", | ||
| 473 | "realm": "Restricted zone", | ||
| 474 | "satisfy": "Any", | ||
| 475 | "description": "This is restricted zone for test only 2", | ||
| 476 | "requirements": [1], | ||
| 477 | "provider1": "User/Group", | ||
| 478 | "entity1": "Group", | ||
| 479 | "op1": "eq", | ||
| 480 | "value1": "user", | ||
| 481 | "routes": [ | ||
| 482 | "Stump" | ||
| 483 | ] | ||
| 484 | }' \ | ||
| 485 | https://owl.localhost:8695/api/admin/realm/MagicalForest | ||
| 486 | |||
| 487 | > PUT /api/admin/realm/MagicalForest HTTP/1.1 | ||
| 488 | > Host: owl.localhost:8695 | ||
| 489 | > User-Agent: curl/7.68.0 | ||
| 490 | > Accept: */* | ||
| 491 | > Authorization: OWL eyJh...ISuA | ||
| 492 | > Content-Length: 380 | ||
| 493 | > Content-Type: application/x-www-form-urlencoded | ||
| 494 | > | ||
| 495 | < HTTP/1.1 200 OK | ||
| 496 | < Date: Mon, 15 May 2023 09:23:12 GMT | ||
| 497 | < Content-Type: application/json;charset=UTF-8 | ||
| 498 | < Content-Length: 149 | ||
| 499 | < Server: OWL/1.00 | ||
| 500 | < | ||
| 501 | { | ||
| 502 | "description": "This is restricted zone for test only 2", | ||
| 503 | "id": 13, | ||
| 504 | "realm": "Restricted zone", | ||
| 505 | "realmname": "MagicalForest", | ||
| 506 | "satisfy": "Any", | ||
| 507 | "status": true | ||
| 508 | } | ||
| 509 | |||
| 510 | =head2 DELETE /api/admin/realm/REALMNAME | ||
| 511 | |||
| 512 | Delete realm by realmname | ||
| 513 | |||
| 514 | # curl -v -X DELETE -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 515 | https://owl.localhost:8695/api/admin/realm/MagicalForest | ||
| 516 | |||
| 517 | > DELETE /api/admin/realm/MagicalForest HTTP/1.1 | ||
| 518 | > Host: owl.localhost:8695 | ||
| 519 | > User-Agent: curl/7.68.0 | ||
| 520 | > Accept: */* | ||
| 521 | > Authorization: OWL eyJh...Bh7g | ||
| 522 | > | ||
| 523 | < HTTP/1.1 200 OK | ||
| 524 | < Server: OWL/1.00 | ||
| 525 | < Date: Mon, 15 May 2023 15:51:02 GMT | ||
| 526 | < Content-Length: 30 | ||
| 527 | < Content-Type: application/json;charset=UTF-8 | ||
| 528 | < | ||
| 529 | { | ||
| 530 | "code": "E0000", | ||
| 531 | "status": true | ||
| 532 | } | ||
| 533 | |||
| 534 | =head2 GET /api/admin/requirement | ||
| 535 | |||
| 536 | GET /api/admin/requirement?realmname=<REALMNAME> | ||
| 537 | |||
| 538 | Get list of realm's requirement | ||
| 539 | |||
| 540 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 541 | https://owl.localhost:8695/api/admin/requirement?realmname=Default | ||
| 542 | |||
| 543 | > GET /api/admin/requirement?realmname=Default HTTP/1.1 | ||
| 544 | > Host: owl.localhost:8695 | ||
| 545 | > User-Agent: curl/7.68.0 | ||
| 546 | > Accept: */* | ||
| 547 | > Authorization: OWL eyJh...Bh7g | ||
| 548 | > | ||
| 549 | < HTTP/1.1 200 OK | ||
| 550 | < Server: OWL/1.00 | ||
| 551 | < Content-Type: application/json;charset=UTF-8 | ||
| 552 | < Content-Length: 302 | ||
| 553 | < Date: Mon, 15 May 2023 15:58:04 GMT | ||
| 554 | < | ||
| 555 | [ | ||
| 556 | { | ||
| 557 | "entity": "Group", | ||
| 558 | "id": 113, | ||
| 559 | "op": "eq", | ||
| 560 | "provider": "User\/Group", | ||
| 561 | "realmname": "Default", | ||
| 562 | "value": "admin" | ||
| 563 | } | ||
| 564 | ] | ||
| 565 | |||
| 566 | =head2 GET /api/admin/route | ||
| 567 | |||
| 568 | Get list of all existing routes | ||
| 569 | |||
| 570 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 571 | https://owl.localhost:8695/api/admin/route | ||
| 572 | |||
| 573 | > GET /api/admin/route HTTP/1.1 | ||
| 574 | > Host: owl.localhost:8695 | ||
| 575 | > User-Agent: curl/7.68.0 | ||
| 576 | > Accept: */* | ||
| 577 | > Authorization: OWL eyJh...Bh7g | ||
| 578 | > | ||
| 579 | < HTTP/1.1 200 OK | ||
| 580 | < Date: Mon, 15 May 2023 16:07:18 GMT | ||
| 581 | < Content-Length: 783 | ||
| 582 | < Server: OWL/1.00 | ||
| 583 | < Content-Type: application/json;charset=UTF-8 | ||
| 584 | < | ||
| 585 | [ | ||
| 586 | { | ||
| 587 | "base": "https://owl.localhost:8695", | ||
| 588 | "id": 14, | ||
| 589 | "is_sysroute": 0, | ||
| 590 | "method": "ANY", | ||
| 591 | "path": "/api/admin/*", | ||
| 592 | "realmname": "Default", | ||
| 593 | "routename": "AdminAPI", | ||
| 594 | "url": "https://owl.localhost:8695/api/admin/*" | ||
| 595 | } | ||
| 596 | ] | ||
| 597 | |||
| 598 | =head2 POST /api/admin/route | ||
| 599 | |||
| 600 | Adds route's data | ||
| 601 | |||
| 602 | # curl -v -H "Authorization: OWL eyJh...ISuA" \ | ||
| 603 | -X POST -d '{ | ||
| 604 | "realmname": "Default", | ||
| 605 | "routename": "AdminAPI", | ||
| 606 | "method": "ANY", | ||
| 607 | "url": "https://owl.localhost:8695/api/admin/*" | ||
| 608 | }' \ | ||
| 609 | https://owl.localhost:8695/api/admin/route | ||
| 610 | |||
| 611 | > POST /api/admin/route HTTP/1.1 | ||
| 612 | > Host: owl.localhost:8695 | ||
| 613 | > User-Agent: curl/7.68.0 | ||
| 614 | > Accept: */* | ||
| 615 | > Authorization: OWL eyJh...ISuA | ||
| 616 | > Content-Length: 156 | ||
| 617 | > Content-Type: application/x-www-form-urlencoded | ||
| 618 | > | ||
| 619 | < HTTP/1.1 200 OK | ||
| 620 | < Content-Length: 199 | ||
| 621 | < Content-Type: application/json;charset=UTF-8 | ||
| 622 | < Date: Sun, 07 May 2023 13:14:59 GMT | ||
| 623 | < Server: OWL/1.00 | ||
| 624 | < | ||
| 625 | { | ||
| 626 | base": "https://owl.localhost:8695", | ||
| 627 | "id":20, | ||
| 628 | "method":"ANY", | ||
| 629 | "path":"/api/admin/*", | ||
| 630 | "realmname":"Default", | ||
| 631 | "routename":"AdminAPI", | ||
| 632 | "status":true, | ||
| 633 | "url":"https://owl.localhost:8695/api/admin/*" | ||
| 634 | } | ||
| 635 | |||
| 636 | =head2 GET /api/admin/route/ROUTENAME | ||
| 637 | |||
| 638 | Get route's data by routename | ||
| 639 | |||
| 640 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 641 | https://owl.localhost:8695/api/admin/route/AdminAPI | ||
| 642 | |||
| 643 | > GET /api/admin/route/AdminAPI HTTP/1.1 | ||
| 644 | > Host: owl.localhost:8695 | ||
| 645 | > User-Agent: curl/7.68.0 | ||
| 646 | > Accept: */* | ||
| 647 | > Authorization: OWL eyJh...Bh7g | ||
| 648 | > | ||
| 649 | < HTTP/1.1 200 OK | ||
| 650 | < Content-Length: 214 | ||
| 651 | < Date: Mon, 15 May 2023 16:09:28 GMT | ||
| 652 | < Content-Type: application/json;charset=UTF-8 | ||
| 653 | < Server: OWL/1.00 | ||
| 654 | < | ||
| 655 | { | ||
| 656 | "base": "https://owl.localhost:8695", | ||
| 657 | "id": 14, | ||
| 658 | "is_sysroute": 0, | ||
| 659 | "method": "ANY", | ||
| 660 | "path": "/api/admin/*", | ||
| 661 | "realmname": "Default", | ||
| 662 | "routename": "AdminAPI", | ||
| 663 | "status": true, | ||
| 664 | "url": "https://owl.localhost:8695/api/admin/*" | ||
| 665 | } | ||
| 666 | |||
| 667 | =head2 PUT /api/admin/route/ROUTENAME | ||
| 668 | |||
| 669 | Sets route's data | ||
| 670 | |||
| 671 | # curl -v -H "Authorization: OWL eyJh...ISuA" \ | ||
| 672 | -X PUT -d '{ | ||
| 673 | "id": 20, | ||
| 674 | "realmname": "Default", | ||
| 675 | "method": "ANY", | ||
| 676 | "url": "https://localhost:8695/api/admin/*" | ||
| 677 | }' \ | ||
| 678 | https://owl.localhost:8695/api/admin/route/AdminAPI | ||
| 679 | |||
| 680 | > PUT /api/admin/route/AdminAPI HTTP/1.1 | ||
| 681 | > Host: owl.localhost:8695 | ||
| 682 | > User-Agent: curl/7.68.0 | ||
| 683 | > Accept: */* | ||
| 684 | > Authorization: OWL eyJh...ISuA | ||
| 685 | > Content-Length: 136 | ||
| 686 | > Content-Type: application/x-www-form-urlencoded | ||
| 687 | > | ||
| 688 | < HTTP/1.1 200 OK | ||
| 689 | < Content-Type: application/json;charset=UTF-8 | ||
| 690 | < Content-Length: 191 | ||
| 691 | < Server: OWL/1.00 | ||
| 692 | < Date: Sun, 07 May 2023 13:22:01 GMT | ||
| 693 | < | ||
| 694 | { | ||
| 695 | "base":"https://localhost:8695", | ||
| 696 | "id":20, | ||
| 697 | "method":"ANY", | ||
| 698 | "path":"/api/admin/*", | ||
| 699 | "realmname":"Default", | ||
| 700 | "routename":"AdminAPI", | ||
| 701 | "status":true, | ||
| 702 | "url":"https://localhost:8695/api/admin/*" | ||
| 703 | } | ||
| 704 | |||
| 705 | =head2 DELETE /api/admin/route/ROUTENAME | ||
| 706 | |||
| 707 | Delete route by routename | ||
| 708 | |||
| 709 | # curl -v -X DELETE -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 710 | https://owl.localhost:8695/api/admin/route/api-backups | ||
| 711 | |||
| 712 | > DELETE /api/admin/route/api-backups HTTP/1.1 | ||
| 713 | > Host: owl.localhost:8695 | ||
| 714 | > User-Agent: curl/7.68.0 | ||
| 715 | > Accept: */* | ||
| 716 | > Authorization: OWL eyJh...Bh7g | ||
| 717 | > | ||
| 718 | < HTTP/1.1 200 OK | ||
| 719 | < Server: OWL/1.00 | ||
| 720 | < Content-Type: application/json;charset=UTF-8 | ||
| 721 | < Content-Length: 30 | ||
| 722 | < Date: Mon, 15 May 2023 16:55:39 GMT | ||
| 723 | < | ||
| 724 | { | ||
| 725 | "code": "E0000", | ||
| 726 | "status": true | ||
| 727 | } | ||
| 728 | |||
| 729 | =head2 GET /api/admin/search/route | ||
| 730 | |||
| 731 | GET /api/admin/search/route?text=<FRAGMENT> | ||
| 732 | |||
| 733 | Performs search route by fragment | ||
| 734 | |||
| 735 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 736 | https://owl.localhost:8695/api/admin/search/route?text=a | ||
| 737 | |||
| 738 | > GET /api/admin/search/route?text=a HTTP/1.1 | ||
| 739 | > Host: owl.localhost:8695 | ||
| 740 | > User-Agent: curl/7.68.0 | ||
| 741 | > Accept: */* | ||
| 742 | > Authorization: OWL eyJh...Bh7g | ||
| 743 | > | ||
| 744 | < HTTP/1.1 200 OK | ||
| 745 | < Server: OWL/1.00 | ||
| 746 | < Content-Length: 592 | ||
| 747 | < Content-Type: application/json;charset=UTF-8 | ||
| 748 | < Date: Mon, 15 May 2023 16:17:50 GMT | ||
| 749 | < | ||
| 750 | [ | ||
| 751 | { | ||
| 752 | "base": "https://owl.localhost:8695", | ||
| 753 | "id": 14, | ||
| 754 | "is_sysroute": 0, | ||
| 755 | "method": "ANY", | ||
| 756 | "path": "/api/admin/*", | ||
| 757 | "realmname": "Default", | ||
| 758 | "routename": "AdminAPI", | ||
| 759 | "url": "https://owl.localhost:8695/api/admin/*" | ||
| 760 | } | ||
| 761 | ] | ||
| 762 | |||
| 763 | =head2 GET /api/admin/search/user | ||
| 764 | |||
| 765 | GET /api/admin/search/user?text=<FRAGMENT> | ||
| 766 | |||
| 767 | Performs search user by fragment | ||
| 768 | |||
| 769 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 770 | https://owl.localhost:8695/api/admin/search/user?text=te | ||
| 771 | |||
| 772 | > GET /api/admin/search/user?text=te HTTP/1.1 | ||
| 773 | > Host: owl.localhost:8695 | ||
| 774 | > User-Agent: curl/7.68.0 | ||
| 775 | > Accept: */* | ||
| 776 | > Authorization: OWL eyJh...Bh7g | ||
| 777 | > | ||
| 778 | < HTTP/1.1 200 OK | ||
| 779 | < Content-Length: 66 | ||
| 780 | < Date: Mon, 15 May 2023 12:21:29 GMT | ||
| 781 | < Server: OWL/1.00 | ||
| 782 | < Content-Type: application/json;charset=UTF-8 | ||
| 783 | < | ||
| 784 | [ | ||
| 785 | { | ||
| 786 | "id": 3, | ||
| 787 | "name": "Test User", | ||
| 788 | "role": "Test user", | ||
| 789 | "username": "test" | ||
| 790 | } | ||
| 791 | ] | ||
| 792 | |||
| 793 | =head2 GET /api/admin/settings | ||
| 794 | |||
| 795 | Gets settings | ||
| 796 | |||
| 797 | # curl -v -H "Authorization: OWL eyJh...r3bo" \ | ||
| 798 | https://owl.localhost:8695/api/admin/settings | ||
| 799 | |||
| 800 | > GET /api/admin/settings HTTP/1.1 | ||
| 801 | > Host: owl.localhost:8695 | ||
| 802 | > User-Agent: curl/7.68.0 | ||
| 803 | > Accept: */* | ||
| 804 | > Authorization: OWL eyJh...r3bo | ||
| 805 | > | ||
| 806 | < HTTP/1.1 200 OK | ||
| 807 | < Content-Type: application/json;charset=UTF-8 | ||
| 808 | < Date: Sat, 29 Apr 2023 04:56:56 GMT | ||
| 809 | < Content-Length: 30 | ||
| 810 | < Server: OWL/1.00 | ||
| 811 | < | ||
| 812 | { | ||
| 813 | "message": "Ok", | ||
| 814 | "status": true | ||
| 815 | } | ||
| 816 | |||
| 817 | =head2 GET /api/admin/sysroute | ||
| 818 | |||
| 819 | Returns list of all existing system routes | ||
| 820 | |||
| 821 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 822 | https://owl.localhost:8695/api/admin/sysroute | ||
| 823 | |||
| 824 | > GET /api/admin/sysroute HTTP/1.1 | ||
| 825 | > Host: owl.localhost:8695 | ||
| 826 | > User-Agent: curl/7.68.0 | ||
| 827 | > Accept: */* | ||
| 828 | > Authorization: OWL eyJh...Bh7g | ||
| 829 | > | ||
| 830 | < HTTP/1.1 200 OK | ||
| 831 | < Content-Type: application/json;charset=UTF-8 | ||
| 832 | < Date: Mon, 15 May 2023 16:24:11 GMT | ||
| 833 | < Content-Length: 7860 | ||
| 834 | < Server: OWL/1.00 | ||
| 835 | < | ||
| 836 | [ | ||
| 837 | { | ||
| 838 | "method": "GET", | ||
| 839 | "route": "/api", | ||
| 840 | "routename": "api", | ||
| 841 | "url": "https://owl.localhost:8695/api" | ||
| 842 | } | ||
| 843 | ] | ||
| 844 | |||
| 845 | =head2 POST /api/admin/sysroute | ||
| 846 | |||
| 847 | Adds system route to route list | ||
| 848 | |||
| 849 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 850 | -X POST -d '{ | ||
| 851 | "routes": ["api-checkits", "api-backups"] | ||
| 852 | }' \ | ||
| 853 | https://owl.localhost:8695/api/admin/sysroute | ||
| 854 | |||
| 855 | > POST /api/admin/sysroute HTTP/1.1 | ||
| 856 | > Host: owl.localhost:8695 | ||
| 857 | > User-Agent: curl/7.68.0 | ||
| 858 | > Accept: */* | ||
| 859 | > Authorization: OWL eyJh...Bh7g | ||
| 860 | > Content-Length: 59 | ||
| 861 | > Content-Type: application/x-www-form-urlencoded | ||
| 862 | > | ||
| 863 | < HTTP/1.1 200 OK | ||
| 864 | < Date: Mon, 15 May 2023 16:43:20 GMT | ||
| 865 | < Server: OWL/1.00 | ||
| 866 | < Content-Type: application/json;charset=UTF-8 | ||
| 867 | < Content-Length: 30 | ||
| 868 | < | ||
| 869 | { | ||
| 870 | "code": "E0000", | ||
| 871 | "status": true | ||
| 872 | } | ||
| 873 | |||
| 874 | =head2 GET /api/admin/user | ||
| 875 | |||
| 876 | Gets list of all existing users | ||
| 877 | |||
| 878 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 879 | https://owl.localhost:8695/api/admin/user | ||
| 880 | |||
| 881 | > GET /api/admin/user HTTP/1.1 | ||
| 882 | > Host: owl.localhost:8695 | ||
| 883 | > User-Agent: curl/7.68.0 | ||
| 884 | > Accept: */* | ||
| 885 | > Authorization: OWL eyJh...Bh7g | ||
| 886 | > | ||
| 887 | < HTTP/1.1 200 OK | ||
| 888 | < Server: OWL/1.00 | ||
| 889 | < Date: Mon, 15 May 2023 11:53:55 GMT | ||
| 890 | < Content-Length: 10517 | ||
| 891 | < Content-Type: application/json;charset=UTF-8 | ||
| 892 | < | ||
| 893 | [ | ||
| 894 | { | ||
| 895 | "algorithm": "SHA256", | ||
| 896 | "attributes": "", | ||
| 897 | "comment": "Test user for internal testing only", | ||
| 898 | "created": 1678741533, | ||
| 899 | "email": "test@owl.localhost", | ||
| 900 | "flags": 0, | ||
| 901 | "id": 3, | ||
| 902 | "name": "Test User", | ||
| 903 | "not_after": null, | ||
| 904 | "not_before": 1678741533, | ||
| 905 | "password": "9f86...0a08", | ||
| 906 | "private_key": "", | ||
| 907 | "public_key": "", | ||
| 908 | "role": "Test user", | ||
| 909 | "username": "test" | ||
| 910 | } | ||
| 911 | ] | ||
| 912 | |||
| 913 | =head2 POST /api/admin/user | ||
| 914 | |||
| 915 | Adds user's data | ||
| 916 | |||
| 917 | # curl -v -H "Authorization: OWL eyJh...j1rM" \ | ||
| 918 | -X POST -d '{ | ||
| 919 | "username": "bob", | ||
| 920 | "name": "Bob", | ||
| 921 | "email": "bob@example.com", | ||
| 922 | "password": "bob", | ||
| 923 | "algorithm": "SHA256", | ||
| 924 | "role": "Test user", | ||
| 925 | "flags": 0, | ||
| 926 | "not_after": null, | ||
| 927 | "public_key": null, | ||
| 928 | "private_key": null, | ||
| 929 | "attributes": null, | ||
| 930 | "comment": "Test user for unit testing only" | ||
| 931 | }' \ | ||
| 932 | https://owl.localhost:8695/api/admin/user | ||
| 933 | |||
| 934 | > POST /api/admin/user HTTP/1.1 | ||
| 935 | > Host: owl.localhost:8695 | ||
| 936 | > User-Agent: curl/7.68.0 | ||
| 937 | > Accept: */* | ||
| 938 | > Authorization: OWL eyJh...j1rM | ||
| 939 | > Content-Length: 367 | ||
| 940 | > Content-Type: application/x-www-form-urlencoded | ||
| 941 | > | ||
| 942 | < HTTP/1.1 200 OK | ||
| 943 | < Date: Fri, 12 May 2023 12:15:50 GMT | ||
| 944 | < Content-Type: application/json;charset=UTF-8 | ||
| 945 | < Content-Length: 1530 | ||
| 946 | < Server: OWL/1.00 | ||
| 947 | < | ||
| 948 | { | ||
| 949 | "algorithm": "SHA256", | ||
| 950 | "attributes": "", | ||
| 951 | "comment": "Test user for unit testing only", | ||
| 952 | "created": 1683893750, | ||
| 953 | "email": "bob@example.com", | ||
| 954 | "flags": 0, | ||
| 955 | "id": 13, | ||
| 956 | "name": "Bob", | ||
| 957 | "not_after": 0, | ||
| 958 | "not_before": 1683893750, | ||
| 959 | "password": "81b6...8ce9", | ||
| 960 | "private_key": "-----BEGIN RSA PRIVATE KEY-----...", | ||
| 961 | "public_key": "-----BEGIN RSA PUBLIC KEY-----...", | ||
| 962 | "role": "Test user", | ||
| 963 | "status": true, | ||
| 964 | "username": "bob" | ||
| 965 | } | ||
| 966 | |||
| 967 | =head2 GET /api/admin/user/USERNAME | ||
| 968 | |||
| 969 | GET /api/admin/user/<USERNAME> | ||
| 970 | GET /api/admin/user/?username=<USERNAME> | ||
| 971 | |||
| 972 | Gets user's data by username | ||
| 973 | |||
| 974 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 975 | https://owl.localhost:8695/api/admin/user/test | ||
| 976 | |||
| 977 | > GET /api/admin/user/test HTTP/1.1 | ||
| 978 | > Host: owl.localhost:8695 | ||
| 979 | > User-Agent: curl/7.68.0 | ||
| 980 | > Accept: */* | ||
| 981 | > Authorization: OWL eyJh...Bh7g | ||
| 982 | > | ||
| 983 | < HTTP/1.1 200 OK | ||
| 984 | < Server: OWL/1.00 | ||
| 985 | < Content-Length: 1544 | ||
| 986 | < Content-Type: application/json;charset=UTF-8 | ||
| 987 | < Date: Mon, 15 May 2023 12:03:36 GMT | ||
| 988 | < | ||
| 989 | { | ||
| 990 | "algorithm": "SHA256", | ||
| 991 | "attributes": "", | ||
| 992 | "comment": "Test user for internal testing only", | ||
| 993 | "created": 1678741533, | ||
| 994 | "email": "test@owl.localhost", | ||
| 995 | "flags": 0, | ||
| 996 | "id": 3, | ||
| 997 | "name": "Test User", | ||
| 998 | "not_after": null, | ||
| 999 | "not_before": 1678741533, | ||
| 1000 | "password": "9f86...0a08", | ||
| 1001 | "private_key": "", | ||
| 1002 | "public_key": "", | ||
| 1003 | "role": "Test user", | ||
| 1004 | "status": true, | ||
| 1005 | "username": "test" | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | =head2 PUT /api/admin/user/USERNAME | ||
| 1009 | |||
| 1010 | Sets user's data | ||
| 1011 | |||
| 1012 | # curl -v -H "Authorization: OWL eyJh...j1rM" \ | ||
| 1013 | -X PUT -d '{ | ||
| 1014 | "id": 13, | ||
| 1015 | "username": "bob", | ||
| 1016 | "name": "Bob Bob", | ||
| 1017 | "email": "bob@example.com", | ||
| 1018 | "password": "bob", | ||
| 1019 | "algorithm": "SHA256", | ||
| 1020 | "role": "Test user", | ||
| 1021 | "flags": 0, | ||
| 1022 | "not_after": null, | ||
| 1023 | "public_key": null, | ||
| 1024 | "private_key": null, | ||
| 1025 | "attributes": null, | ||
| 1026 | "comment": "Test user for unit testing only" | ||
| 1027 | }' \ | ||
| 1028 | https://owl.localhost:8695/api/admin/user/bob | ||
| 1029 | |||
| 1030 | > PUT /api/admin/user/bob HTTP/1.1 | ||
| 1031 | > Host: owl.localhost:8695 | ||
| 1032 | > User-Agent: curl/7.68.0 | ||
| 1033 | > Accept: */* | ||
| 1034 | > Authorization: OWL eyJh...j1rM | ||
| 1035 | > Content-Length: 389 | ||
| 1036 | > Content-Type: application/x-www-form-urlencoded | ||
| 1037 | > | ||
| 1038 | < HTTP/1.1 200 OK | ||
| 1039 | < Date: Fri, 12 May 2023 12:21:07 GMT | ||
| 1040 | < Content-Type: application/json;charset=UTF-8 | ||
| 1041 | < Server: OWL/1.00 | ||
| 1042 | < Content-Length: 1536 | ||
| 1043 | < | ||
| 1044 | { | ||
| 1045 | "algorithm": "SHA256", | ||
| 1046 | "attributes": "", | ||
| 1047 | "comment": "Test user for unit testing only", | ||
| 1048 | "created": 1683893750, | ||
| 1049 | "email": "bob@example.com", | ||
| 1050 | "flags": 0, | ||
| 1051 | "id": 13, | ||
| 1052 | "name": "Bob Bob", | ||
| 1053 | "not_after": 0, | ||
| 1054 | "not_before": 1683894066, | ||
| 1055 | "password": "81b6...8ce9", | ||
| 1056 | "private_key": "-----BEGIN RSA PRIVATE KEY-----...", | ||
| 1057 | "public_key": "-----BEGIN RSA PUBLIC KEY-----...", | ||
| 1058 | "role": "Test user", | ||
| 1059 | "status": true, | ||
| 1060 | "username": "bob" | ||
| 1061 | } | ||
| 1062 | |||
| 1063 | =head2 DELETE /api/admin/user/USERNAME | ||
| 1064 | |||
| 1065 | Delete user by username | ||
| 1066 | |||
| 1067 | # curl -v -X DELETE -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 1068 | https://owl.localhost:8695/api/admin/user/bob.bob | ||
| 1069 | |||
| 1070 | > DELETE /api/admin/user/bob.bob HTTP/1.1 | ||
| 1071 | > Host: owl.localhost:8695 | ||
| 1072 | > User-Agent: curl/7.68.0 | ||
| 1073 | > Accept: */* | ||
| 1074 | > Authorization: OWL eyJh...Bh7g | ||
| 1075 | > | ||
| 1076 | < HTTP/1.1 200 OK | ||
| 1077 | < Content-Length: 30 | ||
| 1078 | < Date: Mon, 15 May 2023 12:11:42 GMT | ||
| 1079 | < Content-Type: application/json;charset=UTF-8 | ||
| 1080 | < Server: OWL/1.00 | ||
| 1081 | < | ||
| 1082 | { | ||
| 1083 | "code": "E0000", | ||
| 1084 | "status": true | ||
| 1085 | } | ||
| 1086 | |||
| 1087 | =head2 GET /api/admin/user/USERNAME/groups | ||
| 1088 | |||
| 1089 | Returns list user's groups | ||
| 1090 | |||
| 1091 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 1092 | https://owl.localhost:8695/api/admin/user/test/groups | ||
| 1093 | |||
| 1094 | > GET /api/admin/user/test/groups HTTP/1.1 | ||
| 1095 | > Host: owl.localhost:8695 | ||
| 1096 | > User-Agent: curl/7.68.0 | ||
| 1097 | > Accept: */* | ||
| 1098 | > Authorization: OWL eyJh...Bh7g | ||
| 1099 | > | ||
| 1100 | < HTTP/1.1 200 OK | ||
| 1101 | < Date: Mon, 15 May 2023 12:27:43 GMT | ||
| 1102 | < Server: OWL/1.00 | ||
| 1103 | < Content-Length: 64 | ||
| 1104 | < Content-Type: application/json;charset=UTF-8 | ||
| 1105 | < | ||
| 1106 | [ | ||
| 1107 | { | ||
| 1108 | "description": "Unprivileged users", | ||
| 1109 | "groupname": "user", | ||
| 1110 | "id": 2 | ||
| 1111 | } | ||
| 1112 | ] | ||
| 1113 | |||
| 1114 | =head2 PUT /api/admin/user/USERNAME/passwd | ||
| 1115 | |||
| 1116 | Set password for user | ||
| 1117 | |||
| 1118 | # curl -v -H "Authorization: OWL eyJh...Bh7g" \ | ||
| 1119 | -X PUT -d '{"password": "test"}' \ | ||
| 1120 | https://owl.localhost:8695/api/admin/user/test/passwd | ||
| 1121 | |||
| 1122 | > PUT /api/admin/user/test/passwd HTTP/1.1 | ||
| 1123 | > Host: owl.localhost:8695 | ||
| 1124 | > User-Agent: curl/7.68.0 | ||
| 1125 | > Accept: */* | ||
| 1126 | > Authorization: OWL eyJh...Bh7g | ||
| 1127 | > Content-Length: 20 | ||
| 1128 | > Content-Type: application/x-www-form-urlencoded | ||
| 1129 | > | ||
| 1130 | < HTTP/1.1 200 OK | ||
| 1131 | < Content-Length: 30 | ||
| 1132 | < Date: Mon, 15 May 2023 12:34:18 GMT | ||
| 1133 | < Content-Type: application/json;charset=UTF-8 | ||
| 1134 | < Server: OWL/1.00 | ||
| 1135 | < | ||
| 1136 | { | ||
| 1137 | "code": "E0000", | ||
| 1138 | "status": true | ||
| 1139 | } | ||
| 1140 | |||
| 1141 | =head1 ERROR CODES | ||
| 1142 | |||
| 1143 | The list of Admin Suffit API error codes | ||
| 1144 | |||
| 1145 | API | HTTP | DESCRIPTION | ||
| 1146 | -------+-------+------------------------------------------------- | ||
| 1147 | E1200 [400] Incorrect username | ||
| 1148 | E1201 [404] User not found | ||
| 1149 | E1202 [400] Incorrect password | ||
| 1150 | E1203 [400] Incorrect search text | ||
| 1151 | E1204 [400] Incorrect groupname | ||
| 1152 | E1205 [400] Incorrect email address | ||
| 1153 | E1206 [400] Incorrect full name | ||
| 1154 | E1207 [400] Incorrect digest algorithm | ||
| 1155 | E1208 [400] Incorrect role | ||
| 1156 | E1209 [400] Incorrect flags | ||
| 1157 | E1210 [404] Group not found | ||
| 1158 | E1211 [400] Incorrect realmname | ||
| 1159 | E1212 [400] Incorrect type of requirements list. Array expected | ||
| 1160 | E1213 [400] Incorrect type of routes list. Array expected | ||
| 1161 | E1214 [404] Realm not found | ||
| 1162 | E1215 [500] Can't generate RSA keys (user_set) | ||
| 1163 | E1216 [500] Can't set user data to database (user_set) | ||
| 1164 | E1217 [500] Can't get data from database by username (user_set) | ||
| 1165 | E1218 [500] Can't get data from database by groupname (group_set) | ||
| 1166 | E1219 [500] Can't set realm data | ||
| 1167 | E1220 [500] Can't group delete (group_del) | ||
| 1168 | E1221 [500] Can't set group data (group_set) | ||
| 1169 | E1222 [500] Can't user delete (user_del) | ||
| 1170 | E1223 [500] Can't set password (user_passwd) | ||
| 1171 | E1224 [500] Can't group enroll (group_enroll) | ||
| 1172 | E1225 [500] Can't get data from database by realmname (realm_set) | ||
| 1173 | E1226 [500] Can't realm delete (realm_del) | ||
| 1174 | E1227 [400] Incorrect routename | ||
| 1175 | E1228 [404] Route not found | ||
| 1176 | E1229 [400] Incorrect URL | ||
| 1177 | E1230 [500] Can't set route data (route_set) | ||
| 1178 | E1231 [500] Can't get data from database by routename (route_set) | ||
| 1179 | E1232 [500] Can't route delete (route_del) | ||
| 1180 | E1233 [500] Can't route set (route_sysadd) | ||
| 1181 | E1234 [400] Incorrect JWS algorithm (settings) | ||
| 1182 | E1235 [400] Incorrect session expires value in seconds (settings) | ||
| 1183 | E1236 [400] Incorrect token expires value in seconds (settings) | ||
| 1184 | E1237 [500] Can't save meta parameter | ||
| 1185 | |||
| 1186 | B<*> -- this code will be defined later on the interface side | ||
| 1187 | |||
| 1188 | See also list of common Suffit API error codes in L<WWW::Suffit::API/"ERROR CODES"> | ||
| 1189 | |||
| 1190 | =head1 HISTORY | ||
| 1191 | |||
| 1192 | See C<Changes> file | ||
| 1193 | |||
| 1194 | =head1 TO DO | ||
| 1195 | |||
| 1196 | See C<TODO> file | ||
| 1197 | |||
| 1198 | =head1 SEE ALSO | ||
| 1199 | |||
| 1200 | L<Mojolicious>, L<WWW::Suffit>, L<WWW::Suffit::Server>, L<WWW::Suffit::API> | ||
| 1201 | |||
| 1202 | =head1 AUTHOR | ||
| 1203 | |||
| 1204 | Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt> | ||
| 1205 | |||
| 1206 | =head1 COPYRIGHT | ||
| 1207 | |||
| 1208 | Copyright (C) 1998-2026 D&D Corporation | ||
| 1209 | |||
| 1210 | =head1 LICENSE | ||
| 1211 | |||
| 1212 | This program is distributed under the terms of the Artistic License Version 2.0 | ||
| 1213 | |||
| 1214 | See the C<LICENSE> file or L<https://opensource.org/license/artistic-2-0> for details | ||
| 1215 | |||
| 1216 | =cut | ||
| 1217 | |||
| 1218 | use Mojo::Base 'Mojolicious::Controller'; | ||
| 1219 | |||
| 1220 | use Mojo::JSON qw/ true false /; | ||
| 1221 | use Mojo::Util qw/ trim /; | ||
| 1222 | use Mojo::URL; | ||
| 1223 | |||
| 1224 | use Acrux::Util qw/ parse_time_offset /; | ||
| 1225 | use Acrux::RefUtil qw/ is_array_ref is_integer is_hash_ref /; | ||
| 1226 | |||
| 1227 | use WWW::Suffit::Const qw/ :security :session :misc /; | ||
| 1228 | |||
| 1229 | sub settings { | ||
| 1230 | my $self = shift; | ||
| 1231 | my $authdb = $self->authdb->clean; | ||
| 1232 | |||
| 1233 | # POST (Save) | ||
| 1234 | if ($self->req->method eq 'POST') { | ||
| 1235 | # Get jwt_jws_algorithm | ||
| 1236 | my $algorithm = trim($self->req->json('/jwt_jws_algorithm') // ''); | ||
| 1237 | return $self->reply->json_error(400 => "E1234" => "Incorrect JWS algorithm") | ||
| 1238 | unless length($algorithm) && scalar(grep {$algorithm eq $_} qw/HS256 HS384 HS512 RS256 RS384 RS512/); | ||
| 1239 | |||
| 1240 | # Get session_expires | ||
| 1241 | my $session_expires = trim($self->req->json('/session_expires') || 0); | ||
| 1242 | return $self->reply->json_error(400 => "E1235" => "Incorrect session expires value in seconds") | ||
| 1243 | unless is_integer($session_expires) && $session_expires >= 0; | ||
| 1244 | |||
| 1245 | # Get token_expires | ||
| 1246 | my $token_expires = trim($self->req->json('/token_expires') || 0); | ||
| 1247 | return $self->reply->json_error(400 => "E1236" => "Incorrect token expires value in seconds") | ||
| 1248 | unless is_integer($token_expires) && $token_expires >= 0; | ||
| 1249 | |||
| 1250 | # Save settings | ||
| 1251 | $authdb->meta(jws_algorithm => $algorithm) | ||
| 1252 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1237: Can't save meta parameter"); | ||
| 1253 | $authdb->meta(sessionexpires => $session_expires) | ||
| 1254 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1237: Can't save meta parameter"); | ||
| 1255 | $authdb->meta(tokenexpires => $token_expires) | ||
| 1256 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1237: Can't save meta parameter"); | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | # Render ok | ||
| 1260 | my $jws_algorithm = $authdb->meta('jws_algorithm') || $self->conf->latest("/jws_algorithm"); | ||
| 1261 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1262 | my $sessionexpires = $authdb->meta('sessionexpires') || parse_time_offset($self->conf->latest("/sessionexpires") || SESSION_EXPIRATION); | ||
| 1263 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1264 | my $tokenexpires = $authdb->meta('tokenexpires') || parse_time_offset($self->conf->latest("/tokenexpires") || TOKEN_EXPIRATION); | ||
| 1265 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1266 | |||
| 1267 | # Render ok | ||
| 1268 | return $self->reply->json_ok({ | ||
| 1269 | 'time' => time, | ||
| 1270 | jwt_jws_algorithms => [ | ||
| 1271 | {name => 'HS256', title => 'HMAC+SHA256 integrity', is_default => true}, | ||
| 1272 | {name => 'HS384', title => 'HMAC+SHA384 integrity'}, | ||
| 1273 | {name => 'HS512', title => 'HMAC+SHA512 integrity'}, | ||
| 1274 | {name => 'RS256', title => 'RSA+PKCS1-V1_5 + SHA256 signature'}, | ||
| 1275 | {name => 'RS384', title => 'RSA+PKCS1-V1_5 + SHA384 signature'}, | ||
| 1276 | {name => 'RS512', title => 'RSA+PKCS1-V1_5 + SHA512 signature'}, | ||
| 1277 | ], | ||
| 1278 | jwt_jws_algorithm => $jws_algorithm, | ||
| 1279 | session_expires => $sessionexpires, | ||
| 1280 | token_expires => $tokenexpires, | ||
| 1281 | public_key => $self->app->public_key, | ||
| 1282 | }); | ||
| 1283 | } | ||
| 1284 | sub user_del { | ||
| 1285 | my $self = shift; | ||
| 1286 | my $authdb = $self->authdb->clean; | ||
| 1287 | |||
| 1288 | # Get username from path | ||
| 1289 | my $username = trim($self->param('username') // ''); | ||
| 1290 | return $self->reply->json_error(400 => "E1200" => "Incorrect username") | ||
| 1291 | unless length($username) && (length($username) <= 64) && $username =~ USERNAME_REGEXP; | ||
| 1292 | |||
| 1293 | # Get pure data from AuthDB | ||
| 1294 | my %data = $authdb->user_get($username); | ||
| 1295 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1296 | return $self->reply->json_error(404 => "E1201" => "User not found") unless $data{id}; | ||
| 1297 | |||
| 1298 | # Delete from database | ||
| 1299 | $authdb->user_del($username) | ||
| 1300 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1222: Can't user delete"); | ||
| 1301 | |||
| 1302 | # Render ok | ||
| 1303 | return $self->reply->json_ok; | ||
| 1304 | } | ||
| 1305 | sub user_get { | ||
| 1306 | my $self = shift; | ||
| 1307 | my $authdb = $self->authdb->clean; | ||
| 1308 | |||
| 1309 | # Get username from query or path | ||
| 1310 | my $username = trim($self->param('username') // ''); | ||
| 1311 | if (length($username)) { | ||
| 1312 | return $self->reply->json_error(400 => "E1200" => "Incorrect username") | ||
| 1313 | unless (length($username) <= 64) && $username =~ USERNAME_REGEXP; | ||
| 1314 | |||
| 1315 | # Get user data from AuthDB | ||
| 1316 | my %data = $authdb->user_get($username); | ||
| 1317 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1318 | return $self->reply->json_error(404 => "E1201" => "User not found") unless $data{id}; | ||
| 1319 | |||
| 1320 | # Render ok | ||
| 1321 | return $self->reply->json_ok({%data}); | ||
| 1322 | } | ||
| 1323 | |||
| 1324 | # Get user list | ||
| 1325 | my @users = $authdb->user_get; | ||
| 1326 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1327 | |||
| 1328 | # Render collection | ||
| 1329 | return $self->render(json => [@users]); | ||
| 1330 | } | ||
| 1331 | sub user_set { | ||
| 1332 | my $self = shift; | ||
| 1333 | my %data = (); | ||
| 1334 | my $authdb = $self->authdb->clean; | ||
| 1335 | |||
| 1336 | # Get data from request | ||
| 1337 | my $id = $self->req->json('/id') || 0; | ||
| 1338 | $data{id} = $id; | ||
| 1339 | |||
| 1340 | # Get username | ||
| 1341 | my $username = trim($self->param('username') // $self->req->json('/username') // ''); | ||
| 1342 | return $self->reply->json_error(400 => "E1200" => "Incorrect username") | ||
| 1343 | unless length($username) && (length($username) <= 64) && $username =~ USERNAME_REGEXP; | ||
| 1344 | $data{username} = $username; | ||
| 1345 | |||
| 1346 | # Get email | ||
| 1347 | my $email = trim($self->req->json('/email') // ''); | ||
| 1348 | return $self->reply->json_error(400 => "E1205" => "Incorrect email address") | ||
| 1349 | unless length($email) && (length($email) <= 255) && $email =~ EMAIL_REGEXP; | ||
| 1350 | $data{email} = $email; | ||
| 1351 | |||
| 1352 | # Get name | ||
| 1353 | my $name = trim($self->req->json('/name') // ''); | ||
| 1354 | return $self->reply->json_error(400 => "E1206" => "Incorrect full name") | ||
| 1355 | unless length($name) && (length($name) <= 255); | ||
| 1356 | $data{name} = $name; | ||
| 1357 | |||
| 1358 | # Get password | ||
| 1359 | my $password = trim($self->req->json('/password') // ''); | ||
| 1360 | unless ($id) { # If add user - check password! | ||
| 1361 | return $self->reply->json_error(400 => "E1202" => "Incorrect password") | ||
| 1362 | unless length($password) && (length($password) <= 255); | ||
| 1363 | } | ||
| 1364 | $data{password} = $password; | ||
| 1365 | |||
| 1366 | # Get algorithm | ||
| 1367 | my $algorithm = uc(trim($self->req->json('/algorithm') // '')); | ||
| 1368 | return $self->reply->json_error(400 => "E1207" => "Incorrect digest algorithm") | ||
| 1369 | unless length($algorithm) && grep {$_ eq $algorithm} @{(DIGEST_ALGORITHMS())}; | ||
| 1370 | $data{algorithm} = $algorithm; | ||
| 1371 | |||
| 1372 | # Get role | ||
| 1373 | my $role = trim($self->req->json('/role') // ''); | ||
| 1374 | return $self->reply->json_error(400 => "E1208" => "Incorrect role") | ||
| 1375 | unless length($role) && (length($role) <= 255); | ||
| 1376 | $data{role} = $role; | ||
| 1377 | |||
| 1378 | # Get flags | ||
| 1379 | my $flags = trim($self->req->json('/flags') || 0); | ||
| 1380 | return $self->reply->json_error(400 => "E1209" => "Incorrect flags") | ||
| 1381 | unless is_integer($flags); | ||
| 1382 | $data{flags} = $flags; | ||
| 1383 | |||
| 1384 | # Get not_after | ||
| 1385 | my $is_disabled = $self->req->json('/disabled') || 0; | ||
| 1386 | $data{not_after} = $is_disabled ? time() : undef; | ||
| 1387 | |||
| 1388 | # Text fields | ||
| 1389 | foreach my $k (qw/public_key private_key attributes comment/) { | ||
| 1390 | my $v = $self->req->json("/$k") // ''; | ||
| 1391 | $data{$k} = $v; | ||
| 1392 | } | ||
| 1393 | |||
| 1394 | # Gen RSA keys | ||
| 1395 | unless (length($data{public_key}) || length($data{private_key})) { | ||
| 1396 | my %ks = $self->gen_rsakeys(); | ||
| 1397 | return $self->reply->json_error(500 => "E1215" => $ks{error}) if $ks{error}; | ||
| 1398 | $data{$_} = $ks{$_} for qw/public_key private_key/; | ||
| 1399 | } | ||
| 1400 | |||
| 1401 | # Set user data | ||
| 1402 | $authdb->user_set(%data) | ||
| 1403 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1216: Can't set user data to authorization database"); | ||
| 1404 | |||
| 1405 | # Get pure data from AuthDB | ||
| 1406 | my %user_data = $authdb->user_get($username); | ||
| 1407 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1408 | |||
| 1409 | # Check id | ||
| 1410 | return $self->reply->json_error(500 => "E1217" => "Can't get data from authorization database by username") | ||
| 1411 | unless $user_data{id}; | ||
| 1412 | |||
| 1413 | # Render ok | ||
| 1414 | return $self->reply->json_ok({%user_data}); | ||
| 1415 | } | ||
| 1416 | sub user_groups { | ||
| 1417 | my $self = shift; | ||
| 1418 | my $authdb = $self->authdb->clean; | ||
| 1419 | |||
| 1420 | # Get username from path | ||
| 1421 | my $username = trim($self->param('username') // ''); | ||
| 1422 | return $self->reply->json_error(400 => "E1200" => "Incorrect username") | ||
| 1423 | unless length($username) && (length($username) <= 64) && $username =~ USERNAME_REGEXP; | ||
| 1424 | |||
| 1425 | # Groups list | ||
| 1426 | my @groups = $authdb->user_groups($username); | ||
| 1427 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1428 | |||
| 1429 | # Render collection | ||
| 1430 | return $self->render(json => [@groups]); | ||
| 1431 | } | ||
| 1432 | sub user_passwd { | ||
| 1433 | my $self = shift; | ||
| 1434 | my %data = (); | ||
| 1435 | my $authdb = $self->authdb->clean; | ||
| 1436 | |||
| 1437 | # Get username | ||
| 1438 | my $username = trim($self->param('username') // $self->req->json('/username') // ''); | ||
| 1439 | return $self->reply->json_error(400 => "E1200" => "Incorrect username") | ||
| 1440 | unless length($username) && (length($username) <= 64) && $username =~ USERNAME_REGEXP; | ||
| 1441 | $data{username} = $username; | ||
| 1442 | |||
| 1443 | # Get password | ||
| 1444 | my $password = trim($self->req->json('/password') // ''); | ||
| 1445 | return $self->reply->json_error(400 => "E1202" => "Incorrect password") | ||
| 1446 | unless length($password) && (length($password) <= 255); | ||
| 1447 | $data{password} = $password; | ||
| 1448 | |||
| 1449 | # Store data | ||
| 1450 | $authdb->user_passwd(%data) | ||
| 1451 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1223: Can't set password"); | ||
| 1452 | |||
| 1453 | # Render ok | ||
| 1454 | return $self->reply->json_ok; | ||
| 1455 | } | ||
| 1456 | sub user_search { | ||
| 1457 | my $self = shift; | ||
| 1458 | my $authdb = $self->authdb->clean; | ||
| 1459 | |||
| 1460 | # Get searchstring from query | ||
| 1461 | my $text = trim($self->param('text') // ''); | ||
| 1462 | return $self->reply->json_error(400 => "E1203" => "Incorrect search text") | ||
| 1463 | unless length($text) <= 64; | ||
| 1464 | |||
| 1465 | # User search | ||
| 1466 | my @users = $authdb->user_search($text); | ||
| 1467 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1468 | |||
| 1469 | # Render collection | ||
| 1470 | return $self->render(json => [@users]); | ||
| 1471 | } | ||
| 1472 | sub group_enroll { | ||
| 1473 | my $self = shift; | ||
| 1474 | my $authdb = $self->authdb->clean; | ||
| 1475 | |||
| 1476 | # Get username | ||
| 1477 | my $username = $self->req->json('/username') // ''; | ||
| 1478 | return $self->reply->json_error(400 => "E1200" => "Incorrect username") | ||
| 1479 | unless length($username) && (length($username) <= 64) && $username =~ USERNAME_REGEXP; | ||
| 1480 | |||
| 1481 | # Get groupname | ||
| 1482 | my $groupname = trim($self->param('groupname')) // $self->req->json('/groupname') // ''; | ||
| 1483 | return $self->reply->json_error(400 => "E1204" => "Incorrect groupname") | ||
| 1484 | unless length($groupname) && (length($groupname) <= 64) && $groupname =~ USERNAME_REGEXP; | ||
| 1485 | |||
| 1486 | # Set data | ||
| 1487 | $authdb->group_enroll( | ||
| 1488 | username => $username, | ||
| 1489 | groupname => $groupname, | ||
| 1490 | ) or return $self->reply->json_error($authdb->code, $authdb->error || "E1224: Can't group enroll"); | ||
| 1491 | |||
| 1492 | # Render ok | ||
| 1493 | return $self->reply->json_ok({groupname => $groupname, username => $username}); | ||
| 1494 | } | ||
| 1495 | sub group_del { | ||
| 1496 | my $self = shift; | ||
| 1497 | my $authdb = $self->authdb->clean; | ||
| 1498 | |||
| 1499 | # Get groupname from path | ||
| 1500 | my $groupname = trim($self->param('groupname') // ''); | ||
| 1501 | return $self->reply->json_error(400 => "E1204" => "Incorrect groupname") | ||
| 1502 | unless length($groupname) && (length($groupname) <= 64) && $groupname =~ USERNAME_REGEXP; | ||
| 1503 | |||
| 1504 | # Get pure data from AuthDB | ||
| 1505 | my %data = $authdb->group_get($groupname); | ||
| 1506 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1507 | return $self->reply->json_error(404 => "E1210" => "Group not found") unless $data{id}; | ||
| 1508 | |||
| 1509 | # Delete from database | ||
| 1510 | $authdb->group_del($groupname) | ||
| 1511 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1220: Can't group delete"); | ||
| 1512 | |||
| 1513 | # Render ok | ||
| 1514 | return $self->reply->json_ok; | ||
| 1515 | } | ||
| 1516 | sub group_get { | ||
| 1517 | my $self = shift; | ||
| 1518 | my $authdb = $self->authdb->clean; | ||
| 1519 | |||
| 1520 | # Get groupname from query or path | ||
| 1521 | my $groupname = trim($self->param('groupname') // ''); | ||
| 1522 | if (length($groupname)) { | ||
| 1523 | return $self->reply->json_error(400 => "E1204" => "Incorrect groupname") | ||
| 1524 | unless (length($groupname) <= 64) && $groupname =~ USERNAME_REGEXP; | ||
| 1525 | |||
| 1526 | # Get pure data from AuthDB | ||
| 1527 | my %data = $authdb->group_get($groupname); | ||
| 1528 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1529 | return $self->reply->json_error(404 => "E1210" => "Group not found") unless $data{id}; | ||
| 1530 | |||
| 1531 | # Render ok | ||
| 1532 | return $self->reply->json_ok({%data}); | ||
| 1533 | } | ||
| 1534 | |||
| 1535 | # Groups list | ||
| 1536 | my @groups = $authdb->group_get; | ||
| 1537 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1538 | |||
| 1539 | # Render collection | ||
| 1540 | return $self->render(json => [@groups]); | ||
| 1541 | } | ||
| 1542 | sub group_set { | ||
| 1543 | my $self = shift; | ||
| 1544 | my %data = (); | ||
| 1545 | my $authdb = $self->authdb->clean; | ||
| 1546 | |||
| 1547 | # Get data from request | ||
| 1548 | my $id = $self->req->json('/id') || 0; | ||
| 1549 | $data{id} = $id; | ||
| 1550 | |||
| 1551 | # Get groupname | ||
| 1552 | my $groupname = trim($self->param('groupname') // $self->req->json('/groupname') // ''); | ||
| 1553 | return $self->reply->json_error(400 => "E1204" => "Incorrect groupname") | ||
| 1554 | unless length($groupname) && (length($groupname) <= 64) && $groupname =~ USERNAME_REGEXP; | ||
| 1555 | $data{groupname} = $groupname; | ||
| 1556 | |||
| 1557 | # Description | ||
| 1558 | $data{description} = $self->req->json("/description") // ''; | ||
| 1559 | |||
| 1560 | # Members | ||
| 1561 | $data{users} = $self->req->json("/members") || []; | ||
| 1562 | |||
| 1563 | # Set group data | ||
| 1564 | $authdb->group_set(%data) | ||
| 1565 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1221: Can't set group data"); | ||
| 1566 | |||
| 1567 | # Get pure data from AuthDB | ||
| 1568 | my %group_data = $authdb->group_get($groupname); | ||
| 1569 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1570 | |||
| 1571 | # Check id | ||
| 1572 | return $self->reply->json_error(500 => "E1218" => "Can't get data from authorization database by groupname") | ||
| 1573 | unless $group_data{id}; | ||
| 1574 | |||
| 1575 | # Render ok | ||
| 1576 | return $self->reply->json_ok({%group_data}); | ||
| 1577 | } | ||
| 1578 | sub group_members { | ||
| 1579 | my $self = shift; | ||
| 1580 | my $authdb = $self->authdb->clean; | ||
| 1581 | |||
| 1582 | # Get groupname from query | ||
| 1583 | my $groupname = trim($self->param('groupname') // ''); | ||
| 1584 | return $self->reply->json_error(400 => "E1204" => "Incorrect groupname") | ||
| 1585 | unless length($groupname) && (length($groupname) <= 64) && $groupname =~ USERNAME_REGEXP; | ||
| 1586 | |||
| 1587 | # Members list | ||
| 1588 | my @members = $authdb->group_members($groupname); | ||
| 1589 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1590 | |||
| 1591 | # Render collection | ||
| 1592 | return $self->render(json => [@members]); | ||
| 1593 | } | ||
| 1594 | sub realm_del { | ||
| 1595 | my $self = shift; | ||
| 1596 | my $authdb = $self->authdb->clean; | ||
| 1597 | |||
| 1598 | # Get realmname from path | ||
| 1599 | my $realmname = trim($self->param('realmname') // ''); | ||
| 1600 | return $self->reply->json_error(400 => "E1211" => "Incorrect realmname") | ||
| 1601 | unless length($realmname) && (length($realmname) <= 64) && $realmname =~ USERNAME_REGEXP; | ||
| 1602 | |||
| 1603 | # Get pure data from AuthDB | ||
| 1604 | my %data = $authdb->realm_get($realmname); | ||
| 1605 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1606 | return $self->reply->json_error(404 => "E1214" => "Realm not found") unless $data{id}; | ||
| 1607 | |||
| 1608 | # Delete from database | ||
| 1609 | $authdb->realm_del($realmname) | ||
| 1610 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1226: Can't realm delete"); | ||
| 1611 | |||
| 1612 | # Render ok | ||
| 1613 | return $self->reply->json_ok; | ||
| 1614 | } | ||
| 1615 | sub realm_get { | ||
| 1616 | my $self = shift; | ||
| 1617 | my $authdb = $self->authdb->clean; | ||
| 1618 | |||
| 1619 | # Get realmname from query or path | ||
| 1620 | my $realmname = trim($self->param('realmname') // ''); | ||
| 1621 | if (length($realmname)) { | ||
| 1622 | return $self->reply->json_error(400 => "E1211" => "Incorrect realmname") | ||
| 1623 | unless (length($realmname) <= 64) && $realmname =~ USERNAME_REGEXP; | ||
| 1624 | |||
| 1625 | # Get pure data from AuthDB | ||
| 1626 | my %data = $authdb->realm_get($realmname); | ||
| 1627 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1628 | return $self->reply->json_error(404 => "E1214" => "Realm not found") unless $data{id}; | ||
| 1629 | |||
| 1630 | # Render ok | ||
| 1631 | return $self->reply->json_ok({%data}); | ||
| 1632 | } | ||
| 1633 | |||
| 1634 | # Realms list | ||
| 1635 | my @realms = $authdb->realm_get; | ||
| 1636 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1637 | |||
| 1638 | # Render collection | ||
| 1639 | return $self->render(json => [@realms]); | ||
| 1640 | } | ||
| 1641 | sub realm_set { | ||
| 1642 | my $self = shift; | ||
| 1643 | my $authdb = $self->authdb->clean; | ||
| 1644 | my %data = (); | ||
| 1645 | |||
| 1646 | # Get data from request | ||
| 1647 | my $id = $self->req->json('/id') || 0; | ||
| 1648 | $data{id} = $id; | ||
| 1649 | |||
| 1650 | # Get realmname | ||
| 1651 | my $realmname = trim($self->param('realmname') // $self->req->json('/realmname') // ''); | ||
| 1652 | return $self->reply->json_error(400 => "E1211" => "Incorrect realmname") | ||
| 1653 | unless length($realmname) && (length($realmname) <= 64) && $realmname =~ USERNAME_REGEXP; | ||
| 1654 | $data{realmname} = $realmname; | ||
| 1655 | |||
| 1656 | # Realm | ||
| 1657 | $data{realm} = $self->req->json("/realm") // ''; | ||
| 1658 | |||
| 1659 | # Satisfy | ||
| 1660 | $data{satisfy} = $self->req->json("/satisfy") // ''; | ||
| 1661 | |||
| 1662 | # Description | ||
| 1663 | $data{description} = $self->req->json("/description") // ''; | ||
| 1664 | |||
| 1665 | # Requirements | ||
| 1666 | my @requirements = (); | ||
| 1667 | my $reqs = $self->req->json("/requirements") || []; | ||
| 1668 | return $self->reply->json_error(400 => "E1212" => "Incorrect type of requirements list. Array expected") | ||
| 1669 | unless is_array_ref($reqs); | ||
| 1670 | foreach my $cid (@$reqs) { | ||
| 1671 | next unless $cid; | ||
| 1672 | push @requirements, { | ||
| 1673 | provider => $self->req->json("/provider$cid") || '', | ||
| 1674 | entity => $self->req->json("/entity$cid") || '', | ||
| 1675 | op => $self->req->json("/op$cid") || '', | ||
| 1676 | value => $self->req->json("/value$cid") || '', | ||
| 1677 | }; | ||
| 1678 | } | ||
| 1679 | $data{requirements} = [@requirements]; | ||
| 1680 | #$self->log->warn($self->dumper( $data{requirements} )); | ||
| 1681 | |||
| 1682 | # Requirements | ||
| 1683 | $data{routes} = $self->req->json("/routes") || []; | ||
| 1684 | return $self->reply->json_error(400 => "E1213" => "Incorrect type of routes list. Array expected") | ||
| 1685 | unless is_array_ref($data{routes}); | ||
| 1686 | |||
| 1687 | # Set data | ||
| 1688 | $authdb->realm_set(%data) | ||
| 1689 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1219: Can't set realm data"); | ||
| 1690 | |||
| 1691 | # Get pure data from AuthDB | ||
| 1692 | my %ret = $authdb->realm_get($realmname); | ||
| 1693 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1694 | |||
| 1695 | # Check id | ||
| 1696 | return $self->reply->json_error(500 => "E1225" => "Can't get data from database by realmname ($realmname)") | ||
| 1697 | unless $ret{id}; | ||
| 1698 | |||
| 1699 | # Render ok | ||
| 1700 | return $self->reply->json_ok({%ret}); | ||
| 1701 | } | ||
| 1702 | sub requirement_get { | ||
| 1703 | my $self = shift; | ||
| 1704 | my $authdb = $self->authdb->clean; | ||
| 1705 | |||
| 1706 | # Requirements list | ||
| 1707 | my $realmname = trim($self->param('realmname') // ''); | ||
| 1708 | return $self->reply->json_error(400 => "E1211" => "Incorrect realmname") | ||
| 1709 | unless length($realmname) && (length($realmname) <= 64) && $realmname =~ USERNAME_REGEXP; | ||
| 1710 | |||
| 1711 | # Requirements list | ||
| 1712 | my @requirements = $authdb->realm_requirements($realmname); | ||
| 1713 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1714 | |||
| 1715 | # Render collection | ||
| 1716 | return $self->render(json => [@requirements]); | ||
| 1717 | } | ||
| 1718 | sub route_get { | ||
| 1719 | my $self = shift; | ||
| 1720 | my $authdb = $self->authdb->clean; | ||
| 1721 | |||
| 1722 | # Sysroute names | ||
| 1723 | my %sysroutes; | ||
| 1724 | $sysroutes{$_->{routename}} = 1 for $self->_get_sysroutes(); | ||
| 1725 | |||
| 1726 | # Get routename from query or path | ||
| 1727 | my $routename = trim($self->param('routename') // ''); | ||
| 1728 | if (length($routename)) { | ||
| 1729 | return $self->reply->json_error(400 => "E1227" => "Incorrect routename") | ||
| 1730 | unless (length($routename) <= 64) && $routename =~ USERNAME_REGEXP; | ||
| 1731 | |||
| 1732 | # Get pure data from AuthDB | ||
| 1733 | my %data = $authdb->route_get($routename); | ||
| 1734 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1735 | return $self->reply->json_error(404 => "E1228" => "Route not found") unless $data{id}; | ||
| 1736 | |||
| 1737 | # Render ok | ||
| 1738 | $data{is_sysroute} = $sysroutes{$routename} ? 1 : 0; | ||
| 1739 | return $self->reply->json_ok({%data}); | ||
| 1740 | } | ||
| 1741 | |||
| 1742 | # Routes list | ||
| 1743 | my $realmname = trim($self->param('realmname') // ''); | ||
| 1744 | my @routes = $realmname ? $authdb->realm_routes($realmname) : $authdb->route_get(); | ||
| 1745 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1746 | |||
| 1747 | # Render collection | ||
| 1748 | return $self->render(json => [map {$_->{is_sysroute} = $sysroutes{$_->{routename}} ? 1 : 0; $_} @routes]); | ||
| 1749 | } | ||
| 1750 | sub route_set { | ||
| 1751 | my $self = shift; | ||
| 1752 | my %data = (); | ||
| 1753 | my $authdb = $self->authdb->clean; | ||
| 1754 | |||
| 1755 | # Get data from request | ||
| 1756 | my $id = $self->req->json('/id') || 0; | ||
| 1757 | $data{id} = $id; | ||
| 1758 | |||
| 1759 | # Get routename | ||
| 1760 | my $routename = trim($self->param('routename') // $self->req->json('/routename') // ''); | ||
| 1761 | return $self->reply->json_error(400 => "E1227" => "Incorrect routename") | ||
| 1762 | unless length($routename) && (length($routename) <= 64) && $routename =~ USERNAME_REGEXP; | ||
| 1763 | $data{routename} = $routename; | ||
| 1764 | |||
| 1765 | # Method | ||
| 1766 | $data{method} = $self->req->json("/method") // ''; | ||
| 1767 | |||
| 1768 | # URL | ||
| 1769 | $data{url} = $self->req->json("/url") // ''; | ||
| 1770 | return $self->reply->json_error(400 => "E1229" => "Incorrect URL") | ||
| 1771 | unless length($data{url}); | ||
| 1772 | my $url = Mojo::URL->new( $data{url} ); | ||
| 1773 | $data{path} = $url->path->to_string // '/'; | ||
| 1774 | $data{path} = '/' unless length($data{path}); | ||
| 1775 | $data{base} = $url->path_query('/')->to_string // ''; | ||
| 1776 | $data{base} =~ s/\/+$//; | ||
| 1777 | #$self->log->warn("Path = " . $data{path}); | ||
| 1778 | |||
| 1779 | # Realmname | ||
| 1780 | my $realmname = trim($self->req->json('/realmname') // ''); | ||
| 1781 | if (length($realmname)) { | ||
| 1782 | return $self->reply->json_error(400 => "E1211" => "Incorrect realmname") | ||
| 1783 | unless (length($realmname) <= 64) && $realmname =~ USERNAME_REGEXP; | ||
| 1784 | } | ||
| 1785 | $data{realmname} = $realmname; | ||
| 1786 | |||
| 1787 | # Set data | ||
| 1788 | #return $self->reply->json_error(500 => "E1566" => $authdb->error) unless ; | ||
| 1789 | $authdb->route_set(%data) | ||
| 1790 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1230: Can't set route data"); | ||
| 1791 | |||
| 1792 | # Get pure data from AuthDB | ||
| 1793 | my %ret = $authdb->route_get($routename); | ||
| 1794 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1795 | |||
| 1796 | # Check id | ||
| 1797 | return $self->reply->json_error(500 => "E1231" => "Can't get data from database by routename ($routename)") | ||
| 1798 | unless $ret{id}; | ||
| 1799 | |||
| 1800 | # Render ok | ||
| 1801 | return $self->reply->json_ok({%ret}); | ||
| 1802 | } | ||
| 1803 | sub route_search { | ||
| 1804 | my $self = shift; | ||
| 1805 | my $authdb = $self->authdb->clean; | ||
| 1806 | |||
| 1807 | # Sysroute names | ||
| 1808 | my %sysroutes; | ||
| 1809 | $sysroutes{$_->{routename}} = 1 for $self->_get_sysroutes(); | ||
| 1810 | |||
| 1811 | # Get searchstring from query | ||
| 1812 | my $text = trim($self->param('text') // ''); | ||
| 1813 | return $self->reply->json_error(400 => "E1203" => "Incorrect search text") | ||
| 1814 | unless length($text) <= 64; | ||
| 1815 | |||
| 1816 | # Groups list | ||
| 1817 | my @routes = $authdb->route_search($text); | ||
| 1818 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1819 | |||
| 1820 | # Render collection | ||
| 1821 | return $self->render(json => [map {$_->{is_sysroute} = $sysroutes{$_->{routename}} ? 1 : 0; $_} @routes]); | ||
| 1822 | } | ||
| 1823 | sub route_sysadd { | ||
| 1824 | my $self = shift; | ||
| 1825 | my $authdb = $self->authdb->clean; | ||
| 1826 | my %routes = (); | ||
| 1827 | foreach my $r ($self->_get_sysroutes()) { | ||
| 1828 | $routes{$r->{routename}} = $r | ||
| 1829 | } | ||
| 1830 | |||
| 1831 | # Get form routes | ||
| 1832 | my $frmroutes = $self->req->json("/routes") || []; | ||
| 1833 | foreach my $r (@$frmroutes) { | ||
| 1834 | my $data = $routes{$r}; | ||
| 1835 | next unless $data && is_hash_ref($data); | ||
| 1836 | $authdb->route_set(%$data) | ||
| 1837 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1233: Can't route set"); | ||
| 1838 | } | ||
| 1839 | |||
| 1840 | # Render ok | ||
| 1841 | return $self->reply->json_ok; | ||
| 1842 | } | ||
| 1843 | sub route_sysget { | ||
| 1844 | my $self = shift; | ||
| 1845 | my @routes = $self->_get_sysroutes(); | ||
| 1846 | |||
| 1847 | # Render collection | ||
| 1848 | return $self->render(json => [@routes]); | ||
| 1849 | } | ||
| 1850 | sub route_del { | ||
| 1851 | my $self = shift; | ||
| 1852 | my $authdb = $self->authdb->clean; | ||
| 1853 | |||
| 1854 | # Get routename from path | ||
| 1855 | my $routename = trim($self->param('routename') // ''); | ||
| 1856 | return $self->reply->json_error(400 => "E1227" => "Incorrect routename") | ||
| 1857 | unless length($routename) && (length($routename) <= 64) && $routename =~ USERNAME_REGEXP; | ||
| 1858 | |||
| 1859 | # Get pure data from AuthDB | ||
| 1860 | my %data = $authdb->route_get($routename); | ||
| 1861 | return $self->reply->json_error($authdb->code, $authdb->error) if $authdb->error; | ||
| 1862 | return $self->reply->json_error(404 => "E1228" => "Route not found") unless $data{id}; | ||
| 1863 | |||
| 1864 | # Delete from database | ||
| 1865 | $authdb->route_del($routename) | ||
| 1866 | or return $self->reply->json_error($authdb->code, $authdb->error || "E1232: Can't route delete"); | ||
| 1867 | |||
| 1868 | # Render ok | ||
| 1869 | return $self->reply->json_ok; | ||
| 1870 | } | ||
| 1871 | |||
| 1872 | sub _get_sysroutes { | ||
| 1873 | my $self = shift; | ||
| 1874 | my @routes = (); | ||
| 1875 | my $children = $self->app->routes->children; | ||
| 1876 | my $url = $self->req->url->base->clone; | ||
| 1877 | my $walk = sub { | ||
| 1878 | my $this = shift; | ||
| 1879 | my $child = shift || []; | ||
| 1880 | foreach my $route (@$child) { | ||
| 1881 | if ($route->is_endpoint && !$route->partial) { | ||
| 1882 | my $methods = $route->can("methods") ? $route->methods : $route->via; # Fix for old Mojo | ||
| 1883 | push @routes, { | ||
| 1884 | routename => $route->name, | ||
| 1885 | route => $route->to_string || '/', | ||
| 1886 | method => uc(join ',', @{$methods // []}) || '*', | ||
| 1887 | url => $url->path($route->to_string)->to_string, | ||
| 1888 | }; | ||
| 1889 | } | ||
| 1890 | $this->($this, $route->children); | ||
| 1891 | } | ||
| 1892 | }; | ||
| 1893 | $walk->($walk, $children); | ||
| 1894 | return sort {$a->{routename} cmp $b->{routename}} @routes; | ||
| 1895 | } | ||
| 1896 | |||
| 1897 | 1; | ||
| 1898 | |||
| 1899 | __END__ |