1 | <?php |
---|
2 | /** |
---|
3 | * @file index.php |
---|
4 | * @brief OpenGnsys REST API manager. |
---|
5 | * @warning All input and output messages are formatted in JSON. |
---|
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.0 |
---|
10 | * @date 2016-05-19 |
---|
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 | include_once("../includes/constantes.php"); |
---|
20 | include_once("../includes/comunes.php"); |
---|
21 | // REST functions. |
---|
22 | include_once("../includes/restfunctions.php"); |
---|
23 | // Slim framework. |
---|
24 | include_once("Slim/Slim.php"); |
---|
25 | \Slim\Slim::registerAutoloader(); |
---|
26 | |
---|
27 | // Server access control. |
---|
28 | $cmd = CreaComando($cnx); |
---|
29 | if (!$cmd) { |
---|
30 | die("Access Error"); |
---|
31 | } |
---|
32 | |
---|
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 | ]); |
---|
40 | $app->setName('opengnsys'); |
---|
41 | |
---|
42 | // Global variables. |
---|
43 | $userid = NULL; // User id. with access to REST API. |
---|
44 | |
---|
45 | // Common functions and routes. |
---|
46 | include("common.php"); |
---|
47 | |
---|
48 | // Check if services are running. |
---|
49 | $config = parse_ini_file("/etc/default/opengnsys"); |
---|
50 | |
---|
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"); |
---|
55 | include("remotepc.php"); |
---|
56 | } |
---|
57 | |
---|
58 | // If repository is running, include its routes. |
---|
59 | if ($config['RUN_OGADMREPO'] === "yes") { |
---|
60 | include("repository.php"); |
---|
61 | } |
---|
62 | |
---|
63 | // Showing API information page using Swagger-UI. |
---|
64 | $app->get('/', |
---|
65 | function() use ($app) { |
---|
66 | $app->response->redirect('swagger-ui/index.html?url=../../opengnsys-api.yml'); |
---|
67 | } |
---|
68 | ); |
---|
69 | |
---|
70 | |
---|
71 | // Execute REST using Slim. |
---|
72 | $app->run(); |
---|
73 | |
---|