forked from loadavg/loadavg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·195 lines (147 loc) · 4.38 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
/**
* LoadAvg - Server Monitoring & Analytics
* http://www.loadavg.com
*
* Main index file
*
* @version SVN: $Id$
* @link https://github.com/loadavg/loadavg
* @author Karsten Becker
* @copyright 2014 Sputnik7
*
* This file is licensed under the Affero General Public License version 3 or
* later.
*/
require_once '../globals.php';
/* Session */
ob_start();
session_start();
if (DEBUG) $memory_usage['start'] = memory_get_usage();
/* Initialize LoadAvg Utility Class */
include_once 'class.Utility.php';
if (DEBUG) $memory_usage['utility'] = memory_get_usage();
/* Initialize LoadAvg Utility Class */
/* Initialize LoadAvg */
include_once 'class.LoadAvg.php';
$loadavg = new LoadAvg();
if (DEBUG) $memory_usage['loadavg'] = memory_get_usage();
//http://mobiledetect.net/
require_once 'Mobile_Detect.php';
$detect = new Mobile_Detect;
if ( $detect->isMobile() )
LoadAvg::$isMobile = true;
/* Initialize LoadAvg Charts module */
include_once 'class.Modules.php';
$loadModules = new LoadModules();
if (DEBUG) $memory_usage['modules'] = memory_get_usage();
/* Initialize LoadAvg Charts module */
include_once 'class.Plugins.php';
$loadPlugins = new loadPlugins();
if (DEBUG) $memory_usage['plugins'] = memory_get_usage();
/* initialize timer */
include_once 'class.Timer.php';
$timer = new Timer();
if (DEBUG) $memory_usage['timer'] = memory_get_usage();
//grab core settings
$settings = LoadAvg::$_settings->general;
/*
* Force https when in https mode
* really needs to be a function called on all pages... to really force it
*
*/
if ( $settings['settings']['https'] == "true" && !isset($_SERVER["HTTPS"])) {
header("Location: https://" . $_SERVER['SERVER_NAME'] .$_SERVER['REQUEST_URI']);
}
//array of modules and status either on or off
//$loadedModules = LoadModules::$_settings->general['modules'];
//var_dump ($loadedModules);
//get plugins//
$plugins = LoadPlugins::$_settings->general['plugins'];
//var_dump ($plugins);
if (DEBUG)
$loadavg->memoryDebugData($memory_usage);
//draw the header
require_once APP_PATH . '/layout/header.php';
/*
* check for successful installation
*/
//check if installation is complete passed over by installer
if ( isset( $_GET['check'] ) )
{
$loadavg->cleanUpInstaller();
} else {
//check installation has been cleaned up for security reasons
$loadavg->checkInstall();
}
/*
* start polling time to generate charts
*/
$timer->setStartTime(); // Setting page load start time
/*
* draw the current page view
*/
//grab the log diretory - needs to be dynamic really
//as this is also set in settings.ini.php !!!
$logdir = LOG_PATH;
//check to see if ip is banned before going on
$banned = false;
$flooding = false;
if ( isset($settings['ban_ip']) && $settings['ban_ip'] == "true" ) {
$banned = $loadavg->checkIpBan();
if ( $banned ) {
//clean up session
$loadavg->logOut();
}
}
//used for remember me at login time
//if no session exists check for cookies
if ( (!isset($_SESSION['logged_in']) || ($_SESSION['logged_in'] == false)) && ($banned == false) )
{
//if cookies are here and match log them in
if ($loadavg->checkCookies()) {
$_SESSION['logged_in'] = true;
header("Location: /index.php");
}
}
//first lets see if a name has been set...
$pageName = "";
//security check for all access
if ( (isset($settings['settings']['allow_anyone'])
&& $settings['settings']['allow_anyone'] == "false"
&& !$loadavg->isLoggedIn()) || ($banned == true) )
{
include( APP_PATH . '/views/login.php');
}
else
{
if ( isset($_GET['page']) && ($_GET['page'] != "") )
$pageName = $_GET['page'];
//first check to see if its a plugin based module
//if (in_array($pageName, $plugins)) array_key_exists
if (array_key_exists($pageName, $plugins))
{
require_once PLUGIN_PATH . $pageName . '/' . $pageName . '.php';
}
//if not check to see if its a view page
else if ( file_exists( APP_PATH . '/views/' . $pageName . '.php' ) )
{
require_once APP_PATH . '/views/' . $pageName . '.php';
}
//if not draw default index page
else
{
//if page doesnt exist redirect to index, can be modified to a page not found if need be
require_once APP_PATH . '/views/index.php';
}
}
/*
* finish polling time to generate charts
*/
// set page load finish time
$timer->setFinishTime();
// Calculating total page load time
$page_load = $timer->getPageLoadTime();
//draw the footer
require_once APP_PATH . '/layout/footer.php';
?>