-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
214 lines (187 loc) · 7.04 KB
/
index.php
File metadata and controls
214 lines (187 loc) · 7.04 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/*
====================================
AppPH Design (c) 2012 SHIN Solutions
====================================
Index class
*/
error_reporting(E_ALL);
// "reset" error messages
@trigger_error("");
/*
========
including files
========
*/
$configSet = true;
// config-file
include_once('includes/config.php');
// classes
include_once('lib/classes/apphierarchy.class.php'); // creates the app hierarchy
include_once('lib/classes/database.class.php'); // database connection
include_once('lib/classes/devicetypes.class.php'); // handling different devicetypes
include_once('lib/classes/filecreator.class.php'); // creates the xml-files for output
include_once('lib/classes/language.class.php'); // language support
include_once('lib/classes/logger.class.php'); // logger
include_once('lib/classes/navigation.class.php'); // creates the navigation / structure of the app
include_once('lib/classes/permissions.class.php'); // handles permissions for users
include_once('lib/classes/template.class.php'); // template engine
// interfaces and abstract classes
include_once('modules/basicmodule.module.php');
include_once('modules/ifilecreator.module.php');
class adpMainContainer
{
public $appHierarchy;
public $database;
public $devicetypes;
public $filecreator;
public $language;
public $logger;
public $navigation;
public $permissions;
public $template;
public $config;
function adpMainContainer($config)
{
$this->config = $config;
/*
==============
initialisation
==============
*/
// apphierarchy generates the structure of the app
$this->appHierarchy = new apdAppHierarchy($this);
// init the database and connect
$this->database = new apdDatabase($this);
// handling different devicetypes
$this->devicetypes = new apdDeviceTypes($this);
// creates the xml-files for the final app
$this->filecreator = new apdFileCreator($this);
// multi language support
$this->language = new apdLanguage($this);
// default logger for errors
$this->logger = new apdLogger();
// navigation, creating the visible app hierarchy for navigation
$this->navigation = new apdNavigation($this);
// handles permissions for users
$this->permissions = new apdPermissions($this);
// template engine
$this->template = new apdTemplate($this);
}
}
/*
==================================
init container and template engine
==================================
*/
$mainContainer = new adpMainContainer($config);
// check if error happened so far
$mainContainer->logger->errorHappened();
$mainContainer->template->initTemplate();
/*
=====================================
load respective current active module
=====================================
*/
// module and parameter
$currentModule = 'home';
if(isset($_REQUEST['m']) && file_exists('lib/views/' . basename($_REQUEST['m']) . '.view.php'))
{
$currentModule = basename($_REQUEST['m']);
}
$mainContainer->config['user_rank'] = -1;
if(isset($_COOKIE[$config['user_cookie'] . 'userid']) && trim($_COOKIE[$config['user_cookie'] . 'userid']) != '')
{
$selectUserRank = $mainContainer->database->query("SELECT `group_id`, `user_passkey` FROM `" . $config['database_pref'] . "users` WHERE `user_id` = ?", array(array($_COOKIE[$config['user_cookie'] . 'userid'])));
if(count($selectUserRank->rows) > 0) // check if user is existing anyway
{
// if password in database is equal to password in cookie, set user-rank
if($_COOKIE[$config['user_cookie'] . 'passkey'] === $selectUserRank->rows[0]->user_passkey)
{
// save rank from database in config-array
$mainContainer->config['user_rank'] = $selectUserRank->rows[0]->group_id;
}
}
}
if($mainContainer->config['user_rank'] == -1 && isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'login')
{
$getPasswordFromDB = $mainContainer->database->query("SELECT `user_id`, `group_id`, `user_passkey` FROM `" . $config['database_pref'] . "users` WHERE `user_name` = ?", array(array($_REQUEST['loginname'])));
// if password is equal with sha1-hash from DB, set cookie
if(sha1($config['user_pw_salt'] . sha1($_REQUEST['loginpassword'])) == $getPasswordFromDB->rows[0]->user_passkey)
{ // cookie is valid for 1 year
setcookie($config['user_cookie'] . 'userid', $getPasswordFromDB->rows[0]->user_id, (time() + 60*60*24*365)); // username
setcookie($config['user_cookie'] . 'passkey', $getPasswordFromDB->rows[0]->user_passkey, (time() + 60*60*24*365)); // sha1-hash with password
setcookie($config['user_cookie'] . 'logindate', time(), (time() + 60*60*24*365)); // login-date
}
header("Location: index.php");
}
if(isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'logout')
{
$currentModule = 'home';
$mainContainer->config['user_rank'] = -1;
}
if($mainContainer->config['user_rank'] == -1 && $currentModule != 'login')
{
setcookie($config['user_cookie'] . 'userid', '', (time() - 60*60*24*365));
setcookie($config['user_cookie'] . 'passkey', '', (time() - 60*60*24*365));
// if filelist should be downloaded from app, do not forward to login-page,
// but put HTTP statuscode/error 500 in header
if(isset($_REQUEST['m']) && $_REQUEST['m'] == 'filemanager' && isset($_REQUEST['type']) && ($_REQUEST['type'] == 'filelist' || $_REQUEST['type'] == 'getfile'))
{
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
exit();
}
else
{
// go to login screen
header("Location: index.php?m=login");
}
}
// check if error happened so far
$mainContainer->logger->errorHappened();
/*
===============
form processing
===============
*/
if(isset($_REQUEST['submit']) && $_REQUEST['submit'] == 'form')
{
// check if processing module exists
if(file_exists('modules/' . $currentModule . '.module.php'))
{
include_once('modules/' . $currentModule . '.module.php');
if(function_exists('initCurrentModule'))
{
// check if error happened so far
$mainContainer->logger->errorHappened();
// initialise an instance of the processing class
$currentProcessingModule = initCurrentModule($mainContainer);
// process the current form
$currentProcessingModule->processForm();
}
}
}
/*
==========================
create the navigation menu
==========================
*/
$mainContainer->template->template = preg_replace('#\{NAVIGATION\}#si', $mainContainer->navigation->createStructureOutput(), $mainContainer->template->template);
$mainContainer->template->navigationLoaded = true;
/*
=============
view (output)
=============
*/
include_once('lib/views/' . $currentModule . '.view.php');
if(function_exists('initCurrentView'))
{
// check if error happened so far
$mainContainer->logger->errorHappened();
$currentViewModule = initCurrentView($mainContainer);
$currentViewModule->initTemplate();
$mainContainer->template->template = preg_replace('#\{CONTENT\}#si', $currentViewModule->printTemplate(), $mainContainer->template->template);
}
// prepare the template for presentation
echo stripslashes($mainContainer->template->prepareTemplate());
?>