[7829e4e] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * @file index.php |
---|
| 4 | * @brief OpenGnsys REST API manager. |
---|
[b584da5] | 5 | * @warning All input and output messages are formatted in JSON. |
---|
[7829e4e] | 6 | * @note Some ideas are based on article "How to create REST API for Android app using PHP, Slim and MySQL" by Ravi Tamada, thanx. |
---|
| 7 | * @license GNU GPLv3+ |
---|
| 8 | * @author Ramón M. Gómez, ETSII Univ. Sevilla |
---|
[49ac797] | 9 | * @version 1.1.0 |
---|
[1485b99] | 10 | * @date 2016-05-19 |
---|
[7829e4e] | 11 | */ |
---|
| 12 | |
---|
| 13 | // Inclussion files. |
---|
| 14 | |
---|
| 15 | // Server access data. |
---|
| 16 | include_once("../controlacceso.php"); |
---|
| 17 | include_once("../clases/AdoPhp.php"); |
---|
| 18 | include_once("../includes/CreaComando.php"); |
---|
[49ac797] | 19 | include_once("../includes/constantes.php"); |
---|
[7829e4e] | 20 | include_once("../includes/comunes.php"); |
---|
[353c112] | 21 | // REST functions. |
---|
[49ac797] | 22 | include_once("../includes/restfunctions.php"); |
---|
[7829e4e] | 23 | // Slim framework. |
---|
| 24 | include_once("Slim/Slim.php"); |
---|
| 25 | \Slim\Slim::registerAutoloader(); |
---|
| 26 | |
---|
| 27 | // Server access control. |
---|
| 28 | $cmd = CreaComando($cnx); |
---|
[49ac797] | 29 | if (!$cmd) { |
---|
| 30 | die("Access Error"); |
---|
| 31 | } |
---|
[7829e4e] | 32 | |
---|
[49ac797] | 33 | // Install Slim application. |
---|
| 34 | $app = new \Slim\Slim([ |
---|
| 35 | 'mode' => 'development', // Mode (production or development). |
---|
| 36 | 'log.enabled' => true, // Using logs. |
---|
| 37 | 'log.level' => \Slim\Log::ERROR, // Log level. |
---|
| 38 | 'debug' => true, // Generating debug info. |
---|
| 39 | ]); |
---|
[7829e4e] | 40 | $app->setName('opengnsys'); |
---|
| 41 | |
---|
| 42 | // Global variables. |
---|
[49ac797] | 43 | $userid = NULL; // User id. with access to REST API. |
---|
[7829e4e] | 44 | |
---|
[49ac797] | 45 | // Common functions and routes. |
---|
[3551804] | 46 | include("common.php"); |
---|
| 47 | |
---|
[fb2ee20] | 48 | // Check if services are running. |
---|
| 49 | $config = parse_ini_file("/etc/default/opengnsys"); |
---|
[7829e4e] | 50 | |
---|
[fb2ee20] | 51 | // If server is running, include its routes and OGAgent push routes. |
---|
| 52 | if ($config['RUN_OGADMSERVER'] === "yes") { |
---|
| 53 | include("server.php"); |
---|
| 54 | include("ogagent.php"); |
---|
[e0b6a5e] | 55 | include("remotepc.php"); |
---|
[7829e4e] | 56 | } |
---|
| 57 | |
---|
[fb2ee20] | 58 | // If repository is running, include its routes. |
---|
| 59 | if ($config['RUN_OGADMREPO'] === "yes") { |
---|
| 60 | include("repository.php"); |
---|
[7829e4e] | 61 | } |
---|
| 62 | |
---|
[8b8e948] | 63 | // Showing API information page using Swagger-UI. |
---|
[036cb22] | 64 | $app->get('/', |
---|
[8b8e948] | 65 | function() use ($app) { |
---|
| 66 | $app->response->redirect('swagger-ui/index.html?url=../../opengnsys-api.yml'); |
---|
[ac8b234e] | 67 | } |
---|
| 68 | ); |
---|
| 69 | |
---|
[b1735a7] | 70 | |
---|
| 71 | // Execute REST using Slim. |
---|
[7829e4e] | 72 | $app->run(); |
---|
| 73 | |
---|