[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 |
---|
| 9 | * @version 1.1 |
---|
[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"); |
---|
| 19 | // Connection class. |
---|
[c03c7c3] | 20 | @include_once("../includes/constantes.php"); |
---|
[7829e4e] | 21 | include_once("../includes/comunes.php"); |
---|
| 22 | include_once("../clases/SockHidra.php"); |
---|
[353c112] | 23 | // REST functions. |
---|
| 24 | @include_once("../includes/restfunctions.php"); |
---|
[7829e4e] | 25 | // Slim framework. |
---|
| 26 | include_once("Slim/Slim.php"); |
---|
| 27 | \Slim\Slim::registerAutoloader(); |
---|
| 28 | |
---|
| 29 | // Server access control. |
---|
| 30 | $cmd = CreaComando($cnx); |
---|
| 31 | if (!$cmd) |
---|
| 32 | die("Access Error"); |
---|
| 33 | |
---|
| 34 | // Install Slim application (development mode). |
---|
[1ab1b31d] | 35 | //$app = new \Slim\Slim(array('mode' => 'production', ... ); |
---|
[7829e4e] | 36 | $app = new \Slim\Slim(array( |
---|
| 37 | 'mode' => 'development', |
---|
[1ab1b31d] | 38 | 'log.enabled' => true, |
---|
| 39 | 'log.level' => \Slim\Log::ERROR, |
---|
[13dc959] | 40 | 'debug' => true)); |
---|
[7829e4e] | 41 | $app->setName('opengnsys'); |
---|
| 42 | |
---|
| 43 | // Global variables. |
---|
[4454169b] | 44 | $userid = NULL; // User id. with access to REST API. |
---|
[7829e4e] | 45 | |
---|
[3551804] | 46 | // Common funtions and routes. |
---|
| 47 | include("common.php"); |
---|
| 48 | |
---|
[fb2ee20] | 49 | // Check if services are running. |
---|
| 50 | $config = parse_ini_file("/etc/default/opengnsys"); |
---|
[7829e4e] | 51 | |
---|
[fb2ee20] | 52 | // If server is running, include its routes and OGAgent push routes. |
---|
| 53 | if ($config['RUN_OGADMSERVER'] === "yes") { |
---|
| 54 | include("server.php"); |
---|
| 55 | include("ogagent.php"); |
---|
[e0b6a5e] | 56 | include("remotepc.php"); |
---|
[7829e4e] | 57 | } |
---|
| 58 | |
---|
[fb2ee20] | 59 | // If repository is running, include its routes. |
---|
| 60 | if ($config['RUN_OGADMREPO'] === "yes") { |
---|
| 61 | include("repository.php"); |
---|
[7829e4e] | 62 | } |
---|
| 63 | |
---|
[8b8e948] | 64 | // Showing API information page using Swagger-UI. |
---|
[036cb22] | 65 | $app->get('/', |
---|
[8b8e948] | 66 | function() use ($app) { |
---|
| 67 | $app->response->redirect('swagger-ui/index.html?url=../../opengnsys-api.yml'); |
---|
[ac8b234e] | 68 | } |
---|
| 69 | ); |
---|
| 70 | |
---|
[b1735a7] | 71 | |
---|
| 72 | // Execute REST using Slim. |
---|
[7829e4e] | 73 | $app->run(); |
---|
| 74 | |
---|
| 75 | ?> |
---|