-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.php
205 lines (172 loc) · 6.4 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
196
197
198
199
200
201
202
203
204
205
<?php
/**
*
* sSSs .S S. .S_sSSs .S sSSs
* d%%SP .SS SS. .SS~YS%%b .SS d%%SP
* d%S' S%S S%S S%S `S%b S%S d%S'
* S%S S%S S%S S%S S%S S%S S%|
* S&S S%S SSSS%S S%S d* S S&S S&S
* S&S S&S SSS&S S&S .S* S S&S Y&Ss
* S&S S&S S&S S&S_sdSSS S&S `S&&S
* S&S S&S S&S S&S~YSY%b S&S `S*S
* S*b S*S S*S S*S `S%b S*S l*S
* S*S. S*S S*S S*S S%S S*S .S*P
* SSSbs S*S S*S S*S S&S S*S sSS*S
* YSSP SSS S*S S*S SSS S*S YSS'
* SP SP SP
* Y Y Y
*
* R E L O A D E D
*
* (c) 2012 Fetal-Neonatal Neuroimaging & Developmental Science Center
* Boston Children's Hospital
*
* http://childrenshospital.org/FNNDSC/
*
*/
// we define a valid entry point
define('__CHRIS_ENTRY_POINT__', 666);
//define('CHRIS_CONFIG_DEBUG', true);
// include the configuration
require_once ('config.inc.php');
// include the classes
require_once (joinPaths(CHRIS_CONTROLLER_FOLDER, 'security.controller.php'));
require_once (joinPaths(CHRIS_CONTROLLER_FOLDER, 'template.class.php'));
require_once (joinPaths(CHRIS_CONTROLLER_FOLDER, 'plugin.controller.php'));
require_once (joinPaths(CHRIS_VIEW_FOLDER, 'plugin.view.php'));
require_once (joinPaths(CHRIS_CONTROLLER_FOLDER, 'data.controller.php'));
require_once (joinPaths(CHRIS_CONTROLLER_FOLDER, 'feed.controller.php'));
require_once (joinPaths(CHRIS_CONTROLLER_FOLDER, 'tag.controller.php'));
// create the login page
function loginPage() {
// create the login page
$t = new Template('login.html');
$t -> replace('CSS', 'css.html');
$t -> replace('FOOTER', 'footer.html');
$t -> replace('JAVASCRIPT_LIBS', 'javascript.libs.php');
if (CHRIS_MAINTENANCE) {
$t -> replace('MAINTENANCE', 'display:block');
} else {
$t -> replace('MAINTENANCE', 'display:none');
}
return $t;
}
// create the homepage
function homePage() {
$t = new Template('home.html');
$t -> replace('BACKGROUND', $_SESSION['userconf']['general']['background']);
$t -> replace('CSS', 'css.html');
$t -> replace('NAVBAR', 'navbar.html');
$t -> replace('DATA_COUNT', DataC::getCount($_SESSION['userid']));
$t -> replace('FEED_COUNT', FeedC::getCount($_SESSION['userid']));
$t -> replace('RUNNING_COUNT', FeedC::getRunningCount($_SESSION['userid']));
$t -> replace('PLUGIN', PluginC::getHTML());
$t -> replace('FEED_ALL', FeedC::getAllHTML($_SESSION['userid']));
$t -> replace('MODAL_DDROP', 'modal_ddrop.html');
$t -> replace('MODAL_TAG', 'modal_tag.html');
$t -> replace('TAGS_LIST', TagC::getTagsList());
$t -> replace('PLUGINS_LIST', PluginC::getPluginsList());
$t -> replace('MODAL_PREVIEW', 'feed_data_preview.html');
$t -> replace('FOOTER', 'footer.html');
$t -> replace('JAVASCRIPT_LIBS', 'javascript.libs.php');
$t -> replace('JAVASCRIPT_CHRIS', 'javascript.chris.html');
$t -> replace('USERNAME', ucfirst($_SESSION['username']));
$t -> replace('CHRIS_VERSION', CHRIS_VERSION);
// ui
$t -> replace('CHRIS_UI_CHECKBOX', 'ui_checkbox.html');
if (CHRIS_MAINTENANCE) {
$t -> replace('MAINTENANCE', 'display:block');
} else {
$t -> replace('MAINTENANCE', 'display:none');
}
return $t;
}
// check if this is a logout attempt
if (SecurityC::logout_attempt()) {
echo 'LOGOUT ATTEMP'.PHP_EOL;
// perform the logout
SecurityC::logout();
exit();
}
// check if this is a login attempt
if (SecurityC::login_attempt()) {
// login could be requested using a session or a post request
// perform the login
if (!SecurityC::login()) {
// invalid credentials
// destroy the session
session_destroy();
// .. and forward to the sorry page
header('Location: ?sorry');
exit();
}
// check if query required
$parsed_url = parse_url($_SERVER["REQUEST_URI"]);
// we have args, let's have a look at them
if(isset($parsed_url['query']) && !empty($parsed_url['query'])){
// if anything, might want to CURL it :)
foreach (explode('&', $parsed_url['query']) as $chunk) {
$param = explode("=", $chunk);
if ($param) {
$parameter_name = urldecode($param[0]);
$$parameter_name = urldecode($param[1]);
}
}
if(isset($launch_plugin) && $launch_plugin == 1){
// need the following defined
//echo $plugin.PHP_EOL;
//echo $script.PHP_EOL;
//echo $feedname.PHP_EOL;
//echo $status.PHP_EOL;
$command = PluginC::getExecutable(sanitize($plugin.PHP_EOL));
$command .= ' '.$ncommand;
$command .= ' --output {OUTPUT}/';
echo $command.PHP_EOL;
$username = $_SESSION['username'];
$password = $_SESSION['password'];
$feed_id = -1;
$jobid = '';
$memory = 2048;
// import launcher.php
ob_start();
include('controller/launcher.php');
ob_end_clean();
}
// then clean URL, back to main entry point
header("Location: ?");
exit();
}
// quick (and dirty) hack to ensure that there is always a '?' in the URL
// we add it to ensure that a user is always logged in at chris/? or chris/experimental/?
// if not, in collaboration mode it can happend that
// user 1 is at: chris/
// user 2 is at: chris/?
// then the collaboration is buggy
if ( $_SERVER["REQUEST_URI"][ strlen($_SERVER["REQUEST_URI"]) -1] !== '?') {
header("Location: ?");
exit();
}
// update user-specific configuration
// BACKGROUND
if(isset($_SESSION['userconf']['general']) && isset($_SESSION['userconf']['general']['background'])){
$prefix = '';
if(dirname($_SESSION['userconf']['general']['background']) == '.'){
$prefix .= 'users/' . $_SESSION['username'] . '/'.CHRIS_USERS_CONFIG_DIR.'/';
}
$_SESSION['userconf']['general']['background'] = $prefix.$_SESSION['userconf']['general']['background'];
}
else{
$_SESSION['userconf']['general']['background'] = "view/gfx/fnndsc_1920x1200.jpg";
}
// EMAIL ADDRESS
if(isset($_SESSION['userconf']['general']) && isset($_SESSION['userconf']['general']['email'])){
UserC::setEmail($_SESSION['userid'], $_SESSION['userconf']['general']['email']);
}
// show the homepage
echo homePage();
exit();
}
// otherwise show the login screen
echo loginPage();
?>