summaryrefslogtreecommitdiffstats
path: root/admin/WebConsole/rest/index.php
blob: aa7cd4830ab8a4bc73de7c308278f86ff8b67832 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
 * @file    index.php
 * @brief   OpenGnsys REST API manager.
 * @warning All input and output messages are formatted in JSON.
 * @note    Some ideas are based on article "How to create REST API for Android app using PHP, Slim and MySQL" by Ravi Tamada, thanx.
 * @license GNU GPLv3+
 * @author  Ramón M. Gómez, ETSII Univ. Sevilla
 * @version 1.1
 * @date    2016-05-19
 */

// Inclussion files.

// Server access data.
include_once("../controlacceso.php");
include_once("../clases/AdoPhp.php");
include_once("../includes/CreaComando.php");
// Connection class.
@include_once("../includes/constantes.php");
include_once("../includes/comunes.php");
include_once("../clases/SockHidra.php");
// REST functions.
@include_once("../includes/restfunctions.php");
// Slim framework.
include_once("Slim/Slim.php");
\Slim\Slim::registerAutoloader();

// Server access control.
$cmd = CreaComando($cnx);
if (!$cmd)
	die("Access Error");

// Install Slim application (development mode).
//$app = new \Slim\Slim(array('mode' => 'production', ... );
$app = new \Slim\Slim(array(
		'mode' => 'development',
		'log.enabled' => true,
		'log.level' => \Slim\Log::ERROR,
		'debug' => true));
$app->setName('opengnsys');

// Global variables.
$userid = NULL;			// User id. with access to REST API.

// Common funtions and routes.
include("common.php");

// Check if services are running.
$config = parse_ini_file("/etc/default/opengnsys");

// If server is running, include its routes and OGAgent push routes.
if ($config['RUN_OGADMSERVER'] === "yes") {
    include("server.php");
    include("ogagent.php");
    include("remotepc.php");
}

// If repository is running, include its routes.
if ($config['RUN_OGADMREPO'] === "yes") {
    include("repository.php");
}

// Showing API information page using Swagger-UI.
$app->get('/',
    function() use ($app) {
        $app->response->redirect('swagger-ui/index.html?url=../../opengnsys-api.yml');
    }
);


// Execute REST using Slim.
$app->run();