File api/api.php
Last commit: Sun Sep 6 20:14:18 2026 +0200 Jan Dankert Fix: Validate REST-URL, respond API-Requests with JSON instead of HTML.
1 <?php 2 3 const API_CALL = true; 4 5 $paths = explode('/', trim($_SERVER['PATH_INFO'],'/')); 6 7 // respond to CORS preflight request 8 if ( $_SERVER['REQUEST_METHOD'] == 'OPTIONS' ) { 9 10 header('Access-Control-Allow-Origin: *'); 11 header('Access-Control-Allow-Headers: *'); 12 header('Access-Control-Allow-Methods: GET,POST'); 13 header('204 No content'); 14 exit; 15 } 16 17 header('Access-Control-Allow-Origin: *'); 18 19 // Validate the REST url, there must be exact 3 parts: /$action/$id/$subaction 20 if ( sizeof($paths) != 3 ) 21 { 22 header('Access-Control-Allow-Origin: *'); 23 header('Access-Control-Allow-Headers: *'); 24 header('Access-Control-Allow-Methods: GET,POST'); 25 header('Content-Type: text/plain'); 26 header('400 Bad Request'); 27 echo ("Invalid REST url.\n"); 28 echo ("Required: \"/<action>/<id>/<subaction>\".\n"); 29 exit; 30 } 31 define("API_ACTION" , $paths[0]); 32 define("API_SUBACTION", @$paths[2]); 33 define("API_ID" , @$paths[1]); 34 35 require_once("../index.php");
Downloadapi/api.php
History Sun, 6 Sep 2026 20:14:18 +0200 Jan Dankert Fix: Validate REST-URL, respond API-Requests with JSON instead of HTML. Thu, 24 Apr 2025 00:13:35 +0200 Jan Dankert New: OpenAPI with REST interface for all actions and methods