forked from fabriceb/symfttpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genconf
executable file
·81 lines (72 loc) · 1.94 KB
/
genconf
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
#!/usr/bin/env php
<?php
/**
* @author Laurent Bachelier <[email protected]>
*/
error_reporting(E_ALL|E_STRICT);
$opts = getopt('d:oa:n:');
$opt_keys = array(
'd'=>'default',
'o'=>'only',
'a'=>'allow',
'n'=>'nophp',
);
$options = array('default'=>'index', 'allow'=>false, 'nophp'=>false);
foreach ($opts as $kopt => $opt)
{
$options[$opt_keys[$kopt]] = $opt;
}
$options['only'] = isset($options['only']);
$options['allow'] = $options['allow']
? explode(',', $options['allow'])
: array();
$options['nophp'] = $options['nophp']
? explode(',', $options['nophp'])
: array('uploads');
// Not using __FILE__ since it resolves symlinks
$path = realpath(dirname($argv[0]).'/../web');
$files = array('dir'=>array(), 'php'=>array(), 'file'=>array());
foreach (new DirectoryIterator($path) as $file)
{
$name = $file->getFilename();
if ($name[0] != '.')
{
if ($file->isDir())
{
$files['dir'][] = $name;
}
elseif (!preg_match('/\.php$/', $name))
{
$files['file'][] = $name;
}
elseif (empty($options['only']))
{
$files['php'][] = $name;
}
}
}
foreach ($options['allow'] as $name)
{
$files['php'][] = $name.'.php';
}
?>
server.document-root = "<?php echo $path ?>"
url.rewrite-once = (
<?php foreach ($files['dir'] as $name): ?>
"^/<?php echo preg_quote($name) ?>/.+" => "$0",
<?php endforeach ?>
<?php foreach ($files['file'] as $name): ?>
"^/<?php echo preg_quote($name) ?>$" => "$0",
<?php endforeach ?>
<?php foreach ($files['php'] as $name): ?>
"^/<?php echo preg_quote($name) ?>(/[^\?]*)?(\?.*)?" => "/<?php echo $name ?>$1$2",
<?php endforeach ?>
"^(/[^\?]*)(\?.*)?" => "/<?php echo $options['default'] ?>.php$1$2"
)
<?php foreach ($options['nophp'] as $name): ?>
<?php if (in_array($name, $files['dir'])): ?>
$HTTP["url"] =~ "^/<?php echo $name ?>/" {
url.access-deny = (".php")
}
<?php endif ?>
<?php endforeach ?>