forked from tony-landis/agilebill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
htaccess_index.php
266 lines (227 loc) · 11.9 KB
/
htaccess_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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php
ob_start();
# Define the file types
$_IncludeFiles = Array ( 'htm', 'html', 'php', 'php3', 'php4', 'phtml', 'inc', 'phps' );
$_VirtualFiles = Array ( 'cgi', 'shtml', 'pl' );
$_PassFiles = Array
(
Array ('name' => 'jpg', 'type' => 'image/jpeg', 'disposition' => 'inline'),
Array ('name' => 'jpeg', 'type' => 'image/jpeg', 'disposition' => 'inline'),
Array ('name' => 'jpe', 'type' => 'image/jpeg', 'disposition' => 'inline'),
Array ('name' => 'gif', 'type' => 'image/gif', 'disposition' => 'inline'),
Array ('name' => 'bmp', 'type' => 'image/bmp', 'disposition' => 'inline'),
Array ('name' => 'tif', 'type' => 'image/tif', 'disposition' => 'inline'),
Array ('name' => 'png', 'type' => 'image/png', 'disposition' => 'inline'),
Array ('name' => 'wbmp', 'type' => 'image/vnd.wap.wbmp', 'disposition' => 'inline'),
Array ('name' => 'pdf', 'type' => 'application/pdf', 'disposition' => 'inline'),
Array ('name' => 'exe', 'type' => 'application/octet-stream', 'disposition'=> 'attatchment'),
Array ('name' => 'zip', 'type' => 'application/x-zip', 'disposition' => 'attatchment'),
Array ('name' => 'gzip', 'type' => 'application/gzip', 'disposition' => 'attatchment'),
Array ('name' => 'tgz', 'type' => 'application/tgz', 'disposition' => 'attatchment'),
Array ('name' => 'gz', 'type' => 'application/gz', 'disposition' => 'attatchment'),
Array ('name' => 'doc', 'type' => 'application/ms-word', 'disposition' => 'inline'),
Array ('name' => 'xls', 'type' => 'application/ms-excel', 'disposition' => 'inline'),
Array ('name' => 'csv', 'type' => 'application/ms-excel', 'disposition' => 'inline'),
Array ('name' => 'swf', 'type' => 'application/x-shockwave-flash', 'disposition' => 'inline'),
Array ('name' => 'txt', 'type' => 'text/plain', 'disposition' => 'inline'),
Array ('name' => 'text', 'type' => 'text/plain', 'disposition' => 'inline'),
Array ('name' => 'rtf', 'type' => 'text/richtext', 'disposition' => 'inline'),
Array ('name' => 'xml', 'type' => 'text/xml', 'disposition' => 'inline'),
Array ('name' => 'css', 'type' => 'text/css', 'disposition' => 'inline'),
Array ('name' => 'js', 'type' => 'text/plain', 'disposition' => 'inline'),
Array ('name' => 'wml', 'type' => 'text/vnd.wap.wml', 'disposition' => 'inline'),
Array ('name' => 'avi', 'type' => 'video/avi', 'disposition' => 'attatchment'),
Array ('name' => 'mpg', 'type' => 'video/mpeg', 'disposition' => 'attatchment'),
Array ('name' => 'mpeg', 'type' => 'video/mpeg', 'disposition' => 'attatchment'),
Array ('name' => 'mpe', 'type' => 'video/mpeg', 'disposition' => 'attatchment'),
Array ('name' => 'wmv', 'type' => 'video/x-ms-wmv', 'disposition' => 'attatchment'),
Array ('name' => 'asf', 'type' => 'video/x-ms-asf', 'disposition' => 'attatchment')
);
# Load the config file:
require_once('config.inc.php');
# Require the needed files...
require_once(PATH_ADODB . 'adodb.inc.php');
require_once(PATH_CORE . 'auth.inc.php');
require_once(PATH_CORE . 'database.inc.php');
require_once(PATH_CORE . 'method.inc.php');
require_once(PATH_CORE . 'session.inc.php');
require_once(PATH_CORE . 'translate.inc.php');
require_once(PATH_CORE . 'setup.inc.php');
require_once(PATH_CORE . 'vars.inc.php');
require_once(PATH_CORE . 'xml.inc.php');
## Path to the error file
define ( 'ERROR_GIF', PATH_THEMES.DEF_THEME_N.'/images/htaccess_error.gif' );
# start the debugger
$C_debug = new CORE_debugger;
# initialize the GET/POST vars
$C_vars = new CORE_vars;
$VAR = $C_vars->f;
# initialize the site setup
$C_setup = new CORE_setup;
# initialize the session handler
$C_sess = new CORE_session;
# define the other session variables as constants
$C_sess->session_constant();
# initialize the translation handler
$C_translate = new CORE_translate;
# update the session constants
$C_sess->session_constant_log();
# initialze the authentication handler
$force = false;
$C_auth = new CORE_auth ($force);
########################################################################
# Verify the User's Access
$authorized = false;
if(defined("SESS_LOGGED"))
if(SESS_LOGGED == "1" && check_auth($VAR['_HTACCESS_ID']))
$authorized = true;
############################################################################
## If this was a GET:
if ( isset($REQUEST_URI ) )
{
$ARRAY = explode ( '?', $REQUEST_URI);
$REQUEST_URI = $ARRAY[0] ;
}
## Define global system vars...
if(!isset($DOCUMENT_ROOT)) $DOCUMENT_ROOT = $_SERVER["DOCUMENT_ROOT"];
if(!isset($REQUEST_URI)) $REQUEST_URI = $_SERVER["REQUEST_URI"];
if(!isset($SCRIPT_FILENAME)) $SCRIPT_FILENAME = $_SERVER["SCRIPT_FILENAME"];
############################################################################
### Check if File Exists:
if (file_exists($DOCUMENT_ROOT.$REQUEST_URI) &&
($SCRIPT_FILENAME != $DOCUMENT_ROOT.$REQUEST_URI) &&
($REQUEST_URI != "/") &&
(!ereg( '[////]{2,}$', $REQUEST_URI ) ) )
{
$url = $REQUEST_URI;
########################################################################
# Check Passthu File Types:
for ($i=0; $i<count($_PassFiles); $i++)
{
$ext = substr (strrchr ($DOCUMENT_ROOT.$url, "."), 1);
if ( strtolower ( $ext ) == $_PassFiles[$i]["name"] )
{
if ($authorized)
{
# determine the filename:
$ext1 = $_PassFiles[$i]['name'];
@$arr2 = explode('/', $REQUEST_URI);
$file_name = 'download.'.$ext1;
for($ii=0; $ii<count($arr2); $ii++)
$file_name = $arr2[$ii];
# Set the correct header info:
header("Content-type: " . $_PassFiles[$i]['type']);
header("Content-Disposition: " . $_PassFiles[$i]['disposition'] . ";filename=$file_name");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
@readfile ($DOCUMENT_ROOT.$url, "r");
exit();
}
else
{
# Display the error gif:
header("Content-type: image/gif");
header("Content-Disposition: inline;filename=error.gif");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
@readfile (ERROR_GIF, "r");
exit();
}
}
}
########################################################################
# Check Include File Types:
for ($i=0; $i<count($_IncludeFiles); $i++)
{
$ext = substr (strrchr ($DOCUMENT_ROOT.$url, "."), 1);
if ( strtolower ( $ext ) == $_IncludeFiles[$i] )
{
if ($authorized)
{
## run:
include_once ( $DOCUMENT_ROOT.$url );
exit();
}
else
{
## forward to login page:
header("Location: ".URL."?_page=account:login_htaccess&_htaccess_id=" . $VAR['_HTACCESS_ID'] . '&_htaccess_dir_id=' . $VAR['_HTACCESS_DIR_ID']);
}
}
}
########################################################################
# Check Virtual File Types:
for ($i=0; $i<count($_VirtualFiles); $i++)
{
$ext = substr (strrchr ($DOCUMENT_ROOT.$url, "."), 1);
if ( strtolower ( $ext ) == $_VirtualFiles[$i] )
{
virtual ( $DOCUMENT_ROOT.$url . "?" . $variables); // < needs some work!
exit();
}
}
}
########################################################################
### Load the index file:
$url=strip_tags($REQUEST_URI);
$url_array=explode("/",$url);
array_shift($url_array);
if ( $authorized ) {
if(!empty($url_array) && file_exists($DOCUMENT_ROOT.$url.INDEX_FILE) ) {
include(INDEX_FILE);
exit();
} else {
## Locate the index file, if any
for($i=0; $i<count($_IncludeFiles); $i++) {
if(file_exists($DOCUMENT_ROOT.$url.'index.'.$_IncludeFiles[$i])) {
include($DOCUMENT_ROOT.$url.'index.'.$_IncludeFiles[$i]);
exit();
}
}
## No index located!
echo "<BR><BR><B><CENTER>PAGE NOT FOUND</CENTER></B>";
exit();
}
} else {
## forward to login page:
header("Location: ".URL."?_page=account:login_htaccess&_htaccess_id=" . $VAR['_HTACCESS_ID'] . '&_htaccess_dir_id=' . $VAR['_HTACCESS_DIR_ID']);
exit();
}
########################################################################
# Filetype not defined, force download:
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".@basename($DOCUMENT_ROOT.$url).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($DOCUMENT_ROOT.$url));
@readfile("$DOCUMENT_ROOT.$url");
exit();
##############################
## Check Authentication ##
##############################
function check_auth($id)
{
### Check if user is a member of one of the authorized groups:
$db = &DB();
$sql = 'SELECT status,group_avail FROM ' . AGILE_DB_PREFIX . 'htaccess WHERE
site_id = ' . $db->qstr(DEFAULT_SITE) . ' AND
status = ' . $db->qstr('1') . ' AND
id = ' . $db->qstr($id);
$result = $db->Execute($sql);
if($result->RecordCount() > 0) {
global $C_auth;
@$arr = unserialize($result->fields['group_avail']);
for($i=0; $i<count($arr); $i++)
if($C_auth->auth_group_by_id($arr[$i]))
return true;
}
return false;
}
ob_end_flush();
?>