Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
 
3
/***************************************************************************
4
                  AutoIndex PHP Script, by Justin Hagstrom
5
                             -------------------
6
 
7
   filename             : config.php
8
   version              : 1.5.2
9
   date                 : January 04, 2005
10
 
11
   copyright            : Copyright (C) 2002-2005 Justin Hagstrom
12
   license              : GNU General Public License (GPL)
13
 
14
   website & forum      : http://autoindex.sourceforge.net
15
   e-mail               : JustinHagstrom [at] yahoo [dot] com
16
 
17
 
18
   AutoIndex PHP Script is free software; you can redistribute it and/or modify
19
   it under the terms of the GNU General Public License as published by
20
   the Free Software Foundation; either version 2 of the License, or
21
   (at your option) any later version.
22
 
23
   AutoIndex PHP Script is distributed in the hope that it will be useful,
24
   but WITHOUT ANY WARRANTY; without even the implied warranty of
25
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
   GNU General Public License for more details.
27
 
28
   You should have received a copy of the GNU General Public License
29
   along with this program; if not, write to the Free Software
30
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
31
 
32
 ***************************************************************************/
33
 
34
if (!defined('CONFIG') || CONFIG !== true)
35
//make sure this file is being included from index.php
36
{
37
	die('<p>This file cannot be accessed directly.</p>');
38
}
39
if (!isset($stored_config, $config_generator))
40
//make sure variables in index.php are set
41
{
42
	die('<p>Error: Filenames not defined. Check index.php to make sure $stored_config and $config_generator are set.</p>');
43
}
44
 
45
if (count($_POST) == 38)
46
{
47
	$final_output = "<?php\n\n/*\n$stored_config generated by $config_generator\n"
48
		."Part of AutoIndex PHP Script\nhttp://autoindex.sourceforge.net\n*/\n\n\n";
49
	foreach ($_POST as $key => $current)
50
	{
51
		$current = str_replace('\'', '\\\'', str_replace('\\', '/', trim($current)));
52
		switch ($key)
53
		{
54
			case 'base_dir':
55
				if ($current == '')
56
				{
57
					die('<p>Error: Make sure $base_dir has been assigned a value.</p>');
58
				}
59
				if (!preg_match('#/$#', $current))
60
				//make sure there is a slash at the end of base_dir
61
				{
62
					$current .= '/';
63
				}
64
				if (!@is_dir($current))
65
				{
66
					die('<p>Error: $base_dir is not a valid directory.</p>');
67
				}
68
				$final_output .= "\n/*  Required settings:  */\n\n\$$key = '$current';\n";
69
				break;
70
			case 'icon_path':
71
				while (preg_match('#/$#', $current))
72
				//make sure there is not a slash at the end
73
				{
74
					$current = substr($current, 0, -1);
75
				}
76
			case 'stylesheet':
77
			case 'user_list':
78
			case 'log_file':
79
			case 'download_count':
80
			case 'links_file':
81
			case 'description_file':
82
			case 'index':
83
			case 'header':
84
			case 'footer':
85
			case 'path_to_language_files':
86
			case 'lang':
87
			case 'banned_list':
88
				//strings
89
				$final_output .= "\$$key = '$current';\n";
90
				break;
91
			case 'use_login_system':
92
				$final_output .= "\n\n/*  Optional settings:  */\n\n";
93
			case 'allow_uploads':
94
			case 'must_login_to_download':
95
			case 'allow_file_overwrites':
96
			case 'sub_folder_access':
97
			case 'force_download':
98
			case 'anti_leech':
99
			case 'enable_searching':
100
			case 'show_dir_size':
101
			case 'folder_expansion':
102
			case 'show_folder_count':
103
			case 'header_per_folder':
104
			case 'footer_per_folder':
105
			case 'show_type_column':
106
			case 'show_size_column':
107
			case 'show_date_column':
108
			case 'select_language':
109
				//booleans
110
				if ($current != 'true' && $current != 'false')
111
				{
112
					die('<p><strong>$'.htmlentities($key).'</strong> must be set to "true" or "false".</p>');
113
				}
114
				$final_output .= "\$$key = $current;\n";
115
				break;
116
			case 'thumbnail_height':
117
			case 'bandwidth_limit':
118
			case 'days_new':
119
			case 'md5_show':
120
				//numbers
121
				$current = (string)((float)$current);
122
				$final_output .= "\$$key = $current;\n";
123
				break;
124
			case 'dont_log_these_ips':
125
			case 'hidden_files':
126
			case 'show_only_these_files':
127
				//arrays
128
				if ($current == '')
129
				{
130
					$temp = 'array();';
131
				}
132
				else
133
				{
134
					$temp = 'array(';
135
					foreach (explode(',', $current) as $a)
136
					{
137
						$a = trim($a);
138
						if ($a != '')
139
						{
140
							$temp .= "\n\t\"$a\",";
141
						}
142
					}
143
					$temp = substr($temp, 0, -1) . ');';
144
				}
145
				$final_output .= "\$$key = $temp\n";
146
				break;
147
			default:
148
				die('<p><strong>$'.htmlentities($key).'</strong> is not a valid configuration setting.</p>');
149
		}
150
	}
151
	$final_output .= "\n?>";
152
 
153
	$_POST['base_dir'] = str_replace('\\', '/', trim($_POST['base_dir']));
154
	if ((preg_match('#^(/|[a-z]\:)#i', $_POST['base_dir']) || $_POST['bandwidth_limit'] != '0') && $_POST['force_download'] == 'false')
155
	{
156
		die('<p>Error: It seems you\'re using an absolute path for the <strong>base_dir</strong>, or <strong>bandwidth_limit</strong> is being used.
157
		<br />This requires that you have <strong>force_download</strong> turned on.</p>
158
		<p>You must set <strong>force_download</strong> to "true" so files can be downloaded.
159
		Otherwise, use a relative path instead of an absolute path or turn off <strong>bandwidth_limit</strong>.</p>');
160
	}
161
	if ($_POST['use_login_system'] == 'true' && !@is_file(trim($_POST['user_list'])))
162
	{
163
		die('<p>Error: Could not open the $user_list file.
164
		<br />Set $user_list to the correct file, or turn off the login system.</p>');
165
	}
166
	if ($_POST['icon_path'] == '' && $_POST['folder_expansion'] == 'true')
167
	{
168
		die('<p>Error: You must use icons for the folder_expansion feature to work.
169
		<br />Set icon_path to the path where the icons can be found.</p>');
170
	}
171
 
172
	if (@is_file($stored_config))
173
	//if the file already exists, back it up
174
	{
175
		$temp_name = $stored_config.'.bak';
176
		for ($i=1; @file_exists($temp_name); $i++)
177
		{
178
			$temp_name = $stored_config.'.bak'.(string)$i;
179
		}
180
		@copy($stored_config, $temp_name);
181
	}
182
 
183
	if ($h = @fopen($stored_config, 'wb'))
184
	//the file was opened successfully, so write to it
185
	{
186
		fwrite($h, $final_output);
187
		fclose($h);
188
		die('<h3>Write successful!<br />AutoIndex configuration is finished.</h3><h3><a href="'
189
			.$_SERVER['PHP_SELF'].'">Continue.</a></h3>');
190
	}
191
	else
192
	//the file could not be written to, so now it must be downloaded through the browser
193
	{
194
		header("Content-Type: text/plain; name=\"$stored_config\"");
195
		header("Content-Disposition: attachment; filename=\"$stored_config\"");
196
		die($final_output);
197
	}
198
}
199
 
200
//begin display of main configuration page
201
echo '<?xml version="1.0" encoding="iso-8859-1"?>';
202
?>
203
 
204
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
205
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
206
<head>
207
	<link href="stylesheet.css" rel="stylesheet" title="AutoIndex Default" type="text/css" />
208
	<title>AutoIndex Configuration Generator</title>
209
</head>
210
<body class='autoindex_body'>
211
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?config=true">
212
 
213
<h3 style="text-align: center;">
214
	<a class="black_link" href="http://autoindex.sourceforge.net/">AutoIndex PHP Script</a>
215
	<br />Configuration
216
</h3>
217
<p>
218
	<strong>The default options are currently selected, so just press the configure button at the bottom to use them.</strong>
219
	<br /><span class="small">If you want to change them, though, it is important that you read the readme.html file, since it explains what each setting does.</span>
220
</p>
221
 
222
<hr class="default_hr" />
223
 
224
<p>
225
	<strong>Required Settings</strong>:
226
</p>
227
 
228
<table width="650" cellpadding="8"><tr class="paragraph"><td class="default_td">
229
base_dir = <input type="text" name="base_dir" value="./" />
230
<br />icon_path = <input type="text" name="icon_path" value="index_icons/winxp" />
231
<br />stylesheet = <input type="text" name="stylesheet" value="stylesheet.css" />
232
</td></tr></table>
233
 
234
<hr class="default_hr" />
235
 
236
<p>
237
	<strong>Optional Settings</strong>:
238
</p>
239
 
240
<table width="650" cellpadding="8"><tr class="paragraph"><td class="default_td">
241
use_login_system = <select name="use_login_system"><option selected="selected" value="false">false</option><option value="true">true</option></select>
242
<br />allow_uploads = <select name="allow_uploads"><option selected="selected" value="false">false</option><option value="true">true</option></select>
243
<br />must_login_to_download = <select name="must_login_to_download"><option selected="selected" value="false">false</option><option value="true">true</option></select>
244
<br />user_list = <input type="text" name="user_list" value=".htpasswd.autoindex" />
245
<br />allow_file_overwrites = <select name="allow_file_overwrites"><option selected="selected" value="false">false</option><option value="true">true</option></select>
246
</td></tr></table>
247
 
248
<p />
249
<table width="650" cellpadding="8"><tr class="paragraph"><td class="default_td">
250
log_file = <input type="text" name="log_file" />
251
<br />dont_log_these_ips = <input type="text" size="30" name="dont_log_these_ips" value="127.0.0.*" /> <span class="small">(Separate multiple items with commas.)</span>
252
<br />banned_list = <input type="text" name="banned_list" />
253
<br />download_count = <input type="text" name="download_count" />
254
<br />links_file = <input type="text" name="links_file" />
255
<br />description_file = <input type="text" name="description_file" />
256
</td></tr></table>
257
 
258
<p />
259
<table width="650" cellpadding="8"><tr class="paragraph"><td class="default_td">
260
sub_folder_access = <select name="sub_folder_access"><option selected="selected" value="true">true</option><option value="false">false</option></select>
261
<br />index = <input type="text" name="index" />
262
<br />hidden_files = <input type="text" name="hidden_files" size="80" value="$log_file, $links_file, $description_file, $banned_list, $stylesheet, $download_count, index_icons, languages, *.php, .ht*" />
263
<br /><span class="small">(Separate multiple items with commas.)</span>
264
<br />show_only_these_files = <input type="text" size="30" name="show_only_these_files" /> <span class="small">(Separate multiple items with commas.)</span>
265
</td></tr></table>
266
 
267
<p />
268
<table width="650" cellpadding="8"><tr class="paragraph"><td class="default_td">
269
force_download = <select name="force_download"><option selected="selected" value="false">false</option><option value="true">true</option></select>
270
<br />bandwidth_limit = <input type="text" name="bandwidth_limit" size="3" value="0" /> KB/s
271
<br />anti_leech = <select name="anti_leech"><option selected="selected" value="false">false</option><option value="true">true</option></select>
272
</td></tr></table>
273
 
274
<p />
275
<table width="650" cellpadding="8"><tr class="paragraph"><td class="default_td">
276
enable_searching = <select name="enable_searching"><option selected="selected" value="true">true</option><option value="false">false</option></select>
277
</td></tr></table>
278
 
279
<p />
280
<table width="650" cellpadding="8"><tr class="paragraph"><td class="default_td">
281
show_dir_size = <select name="show_dir_size"><option selected="selected" value="true">true</option><option value="false">false</option></select>
282
<br />folder_expansion = <select name="folder_expansion"><option selected="selected" value="false">false</option><option value="true">true</option></select>
283
<br />show_folder_count = <select name="show_folder_count"><option selected="selected" value="false">false</option><option value="true">true</option></select>
284
<br />days_new = <input type="text" name="days_new" size="3" value="0" /> days
285
<br />md5_show = <input type="text" name="md5_show" size="3" value="0" /> max size (MB)
286
<br />thumbnail_height = <input type="text" name="thumbnail_height" size="6" value="0" /> <span class="small">(in pixels, 0 to disable. GDlib 2.0.1 or higher is required.)</span>
287
</td></tr></table>
288
 
289
<p />
290
<table width="650" cellpadding="8"><tr class="paragraph"><td class="default_td">
291
header = <input type="text" name="header" />
292
<br />footer = <input type="text" name="footer" />
293
<br />header_per_folder = <select name="header_per_folder"><option selected="selected" value="false">false</option><option value="true">true</option></select>
294
<br />footer_per_folder = <select name="footer_per_folder"><option selected="selected" value="false">false</option><option value="true">true</option></select>
295
</td></tr></table>
296
 
297
<p />
298
<table width="650" cellpadding="8"><tr class="paragraph"><td class="default_td">
299
show_type_column = <select name="show_type_column"><option selected="selected" value="false">false</option><option value="true">true</option></select>
300
<br />show_size_column = <select name="show_size_column"><option selected="selected" value="true">true</option><option value="false">false</option></select>
301
<br />show_date_column = <select name="show_date_column"><option selected="selected" value="true">true</option><option value="false">false</option></select>
302
</td></tr></table>
303
 
304
<hr class="default_hr" />
305
 
306
<p>
307
	<strong>Language Settings</strong>:
308
</p>
309
 
310
<p />
311
<table width="650" cellpadding="8"><tr class="paragraph"><td class="default_td">
312
path_to_language_files = <input type="text" name="path_to_language_files" value="./languages/" />
313
<br />lang = <select name="lang">
314
<?php
315
 
316
function get_all_langs($path)
317
{
318
	if (($hndl = @opendir($path)) === false)
319
	{
320
		return array('en.php');
321
	}
322
	$list = array();
323
	while (($file = readdir($hndl)) !== false)
324
	{
325
		if (@is_file($path.$file) && preg_match('/^[a-z]{2}(_[a-z]{2})?\.php$/i', $file))
326
		{
327
			$list[] = $file;
328
		}
329
	}
330
	closedir($hndl);
331
	return $list;
332
}
333
 
334
$l = get_all_langs('./languages/');
335
sort($l);
336
for ($i=0; $i<count($l); $i++)
337
{
338
	$f = substr($l[$i], 0, -4);
339
	$sel = (($f == 'en') ? ' selected="selected"' : '');
340
	echo "\t<option$sel>$f</option>\n";
341
}
342
 
343
?>
344
</select>
345
<br />select_language = <select name="select_language"><option selected="selected" value="false">false</option><option value="true">true</option></select>
346
</td></tr></table>
347
<hr class="default_hr" />
348
<p>
349
	<input type="submit" value="Configure" />
350
</p>
351
<p>
352
	When you press <em>Configure</em>, the script will attempt to write the config data to the file.
353
	<br />If it cannot (for example if it does not have write permission in the directory) the config file will be downloaded, and you will have to upload it to your server.
354
	<br />(It should be named <em><?php echo $stored_config; ?></em> and put in the same folder as <em>index.php</em>)
355
</p>
356
 
357
</form>
358
 
359
<!--
360
 
361
Powered by AutoIndex PHP Script (version <?php echo VERSION; ?>)
362
Copyright (C) 2002-2005 Justin Hagstrom
363
http://autoindex.sourceforge.net
364
 
365
Page generated in <?php echo round((get_microtime() - $start_time) * 1000, 1); ?> milliseconds.
366
 
367
-->
368
 
369
</body></html>