-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.php
executable file
·100 lines (84 loc) · 2.41 KB
/
index.php
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
//Import
if(isset($_GET['q']) && $_GET['q'] == 'import'){
include_once('classes/Importer.php');
$imp = new Importer();
$imp->run();
exit(0);
}
//Test if LODSPeaKr is configured
if(!file_exists('settings.inc.php')){
echo 'Need to configure lodspeakr first. Please run "install.sh". Alternatively, you can <a href="import">import an existing application</a>';
exit(0);
}
include_once('common.inc.php');
//Debug output
$conf['logfile'] = null;
if($conf['debug']){
include_once('classes/Logging.php');
if(isset($_GET['q']) && $_GET['q'] == 'logs'){
Logging::init();
exit(0);
}else{
$conf['logfile'] = Logging::createLogFile($_GET['q']);
//error_reporting(E_ALL);
}
}else{
error_reporting(E_ERROR);
}
include_once('classes/HTTPStatus.php');
include_once('classes/Utils.php');
include_once('classes/Queries.php');
include_once('classes/Endpoint.php');
include_once('classes/Convert.php');
$results = array();
$firstResults = array();
$endpoints = array();
$endpoints['local'] = new Endpoint($conf['endpoint']['local'], $conf['endpointParams']['config']);
$acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT']);
$extension = Utils::getExtension($acceptContentType);
//Check content type is supported by LODSPeaKr
if($acceptContentType == NULL){
HTTPStatus::send406($uri);
}
//Export
if($conf['export'] && $_GET['q'] == 'export'){
include_once('settings.inc.php');
include_once('classes/Exporter.php');
$exp = new Exporter();
header('Content-Type: text/plain');
$exp->run();
exit(0);
}
//Redirect to root URL if necessary
$uri = $conf['basedir'].$_GET['q'];
$localUri = $uri;
if($uri == $conf['basedir']){
header('Location: '.$conf['root']);
exit(0);
}
//Configure external URIs if necessary
$localUri = $conf['basedir'].$_GET['q'];
$uri = Utils::getMirroredUri($localUri);
//Modules
foreach($conf['modules']['available'] as $i){
$className = $i.'Module';
$currentModule = $conf['modules']['directory'].$className.'.php';
if(!is_file($currentModule)){
HTTPStatus::send500("<br/>Can't load or error in module <tt>".$currentModule."</tt>" );
exit(1);
}
require_once($currentModule);
$module = new $className();
$matching = $module->match($uri);
if($matching != FALSE){
$module->execute($matching);
if($conf['logfile'] != null){
fwrite($conf['logfile'], "]}");
fclose($conf['logfile']);
}
exit(0);
}
}
HTTPStatus::send404($uri);
?>