-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
253 lines (202 loc) · 7.41 KB
/
Copy pathindex.php
File metadata and controls
253 lines (202 loc) · 7.41 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?php
include("config/config.php");
include("incs/required.php");
try {
// we use this to detect cross-site request forgeries in conjunction
// with the validate_post_session() method
if (isset($_POST['session_id']) && ($_POST['session_id'] != session_id())) {
throw new Exception(ERR_INVALID_SESSION);
} else if (isset($_POST['session_id'])) {
global $valid_session;
$valid_session = true;
}
// and we run by default
validate_post_session();
$get_order = array('page','section','id','action','key','req');
$get = mysql_escape_string(substr($_SERVER['REQUEST_URI'], 1));
$get = explode('/', $get);
$index = 0;
$reqset = false;
while(($index < sizeof($get_order)) && !$reqset) {
$part = $get_order[$index];
if (!$index) {
if (strstr($get[$index], ':')) {
$parts = explode(':', $get[$index]);
$GLOBALS['ctype'] = $ctype = clean_get($parts[0]);
$GLOBALS['page'] = $page = clean_get($parts[1]);
} else {
$GLOBALS['page'] = $page = clean_get($get[$index]);
}
} else {
if (!strstr($get[$index], ':')) {
$GLOBALS[$part] = $$part = clean_get($get[$index]);
} else {
$GLOBALS['reqstring'] = $reqstring = clean_get(implode('/', array_slice($get, $index)));
$GLOBALS['req'] = $req = parse_req(implode('/', array_slice($get, $index)));
$reqset = true;
}
}
$index++;
}
$GLOBALS['ctype'] = $ctype = $ctype ? $ctype : CTYPE_HTML;
$_GET['page'] = $GLOBALS['page'] = $page = $page ? $page : 'base';
$_GET['section'] = $GLOBALS['section'] = $section = $section ? $section : 'index';
$GLOBALS['iref'] = $page . '/' . $section . '/' . $id;
// if we aren't hitting a public page and we aren't logged in, require a login
// note that this will load a login form, which will get auto processed by the require script
// that contains the logic for building the authentication
if (!Util::check_authed() && !in_array($page, $GLOBALS['public_pages'])) {
if (!isset($_POST['req_auth']) && !isset($_POST['reg_auth'])) {
Util::user_error(ERR_NO_LOGIN);
}
require_login();
} else {
if (isset($_POST['req_auth']) || isset($_POST['reg_auth'])) {
$_POST = array();
if (in_array($page, $GLOBALS['public_pages']) && !Util::check_authed()) {
// this is because its killing the form data unless we process it and load the logic
// however, the logic loader is also causing a script bounce since we do need a shift
// therefore we only fill this variable in if the login failed
$GLOBALS['forced_auth'] = true;
}
}
if ((($GLOBALS['ctype'] != CTYPE_GRAPH) &&
!(isset($_SERVER['HTTPS']) && ($GLOBALS['ctype'] == CTYPE_HTML) && !in_array($page, $GLOBALS['secure_pages']))) ||
(isset($GLOBALS['forced_auth']))) {
define_logic($page, $section);
} else {
shift_page($page, $section, $id, $action, $key, $reqstring);
}
}
if (!(isset($_SERVER['HTTPS']) && ($GLOBALS['ctype'] == CTYPE_HTML) && !in_array($page, $GLOBALS['secure_pages']))) {
if (($GLOBALS['ctype'] != CTYPE_SPREAD) && ($GLOBALS['ctype'] != CTYPE_GRAPH)) {
$t_page = $page;
if (!file_exists('pages/'.$GLOBALS['ctype'].'/'.$page)) {
$t_page = 'base';
}
$t_section = $section;
if (!file_exists('pages/'.$GLOBALS['ctype'].'/'.$page.'/'.$section.'.php')) {
$t_section = 'index';
}
if ((($t_page != $page) || ($t_section != $section)) && ($GLOBALS['ctype'] != CTYPE_HTML_AUTH) && ($GLOBALS['ctype'] != CTYPE_AJAL_AUTH)) {
$GLOBALS['page'] = $page = $t_page;
$GLOBALS['section'] = $section = $t_section;
define_logic($page, $section);
}
}
global $render_custom;
switch($GLOBALS['ctype']) {
case CTYPE_HTML_AUTH:
header("Content-type: text/html; charset=utf-8");
include("incs/htmllogin.php");
break;
case CTYPE_HTML:
header("Content-type: text/html; charset=utf-8");
if ($render_custom) {
include($render_custom);
} else {
include("pages/html/" . $page . "/" . $section . ".php");
}
include("incs/htmlpage.php");
break;
case CTYPE_XML:
header("Content-Type: text/xml; charset=utf-8");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
if ($render_custom) {
include($render_custom);
} else {
include('pages/xml/'.$page.'/'.$section.'.php');
}
break;
case CTYPE_AJ:
if (isset($_SESSION['errors']) && $_SESSION['errors']) {
echo 0;
} else {
echo 1;
}
$_SESSION['errors'] = array();
$_SESSION['messages'] = array();
break;
case CTYPE_AJAT:
header("Content-type: text/html; charset=utf-8");
if (file_exists('pages/ajat/'.$page.'/'.$section.'.php')) {
if ($render_custom) {
include($render_custom);
} else {
include('pages/ajat/'.$page.'/'.$section.'.php');
}
}
break;
case CTYPE_AJAL:
header("Content-Type: text/xml; charset=utf-8");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<lb_res>\n";
echo "<lb_msg><![CDATA[\n";
Util::ajax_messages();
echo "\n]]></lb_msg>";
if (Util::check_authed()) {
echo "<lb_script><![CDATA[logout_show();]]></lb_script>";
}
if (file_exists('pages/ajal/'.$page.'/'.$section.'.php')) {
if ($render_custom) {
include($render_custom);
} else {
include('pages/ajal/'.$page.'/'.$section.'.php');
}
}
echo "</lb_res>";
break;
case CTYPE_AJAL_AUTH:
header("Content-Type: text/xml; charset=utf-8");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<lb_res>\n";
echo "<lb_msg><![CDATA[\n";
Util::ajax_messages();
echo "\n]]></lb_msg>";
include('incs/ajalauth.php');
echo "</lb_res>";
break;
case CTYPE_AJAX:
header("Content-Type: text/xml; charset=utf-8");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<sw_res>\n";
echo "<sw_msg><![CDATA[\n";
Util::ajax_messages();
echo "\n]]></sw_msg>";
if ($render_custom) {
include($render_custom);
} else {
if (file_exists('pages/ajax/'.$page.'/'.$section.'.php')) {
include('pages/ajax/'.$page.'/'.$section.'.php');
}
}
echo "</sw_res>";
break;
case CTYPE_SPREAD:
header("Content-type: text/html; charset=utf-8");
if (file_exists('pages/spread/'.$section.'.php')) {
include ('pages/spread/'.$section.'.php');
}
break;
case CTYPE_GRAPH:
if (file_exists('pages/graph/'.$page.'/'.$section.'.php')) {
load_page_cache($page,$section);
}
break;
default:
if ($render_custom) {
include($render_custom);
} else {
if (file_exists('pages/' . $GLOBALS['ctype'] . '/'.$page.'/'.$section.'.php')) {
include('pages/' . $GLOBALS['ctype'] . '/'.$page.'/'.$section.'.php');
}
}
break;
}
}
session_write_close();
} catch (Exception $e) {
include('incs/error.php');
error_log($e->getMessage());
}
?>