-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightyvhost
executable file
·82 lines (66 loc) · 2.62 KB
/
lightyvhost
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
#!/usr/bin/php
<?php
$userName = $argv[1];
$domainRegExp = $argv[2];
$httpAuth = intval($argv[3]);
$httpAuthText = '
auth.debug = 0
auth.backend = "plain"
auth.backend.plain.userfile = "/home/projects/%%userName%%/conf/passwd.conf"
auth.require = ( "/" =>
(
"method" => "basic",
"realm" => "Password protected area",
"require" => "user=%%userName%%"
)
)
';
if ($userName != '' && $domainRegExp != '')
{
#$skeleton = file_get_contents('/etc/lighttpd/virt/skeleton.conf');
$skeleton = '$HTTP["host"] =~ "%%domainRegExp%%" {
username = "%%userName%%"
nproc = "4"
%%httpAuth%%
server.document-root = "/home/projects/%%userName%%/www/"
accesslog.filename = "/home/projects/%%userName%%/logs/access_log"
include "phpmyadmin.conf"
include "php5.conf"
server.error-handler-404 = "/generator.php"
}';
if ($httpAuth == 1)
{
$httpAuthText = str_replace('%%userName%%', $userName, $httpAuthText);
file_put_contents('/home/projects/' . $userName . '/conf/passwd.conf', $userName . ':' . preg_replace('/[aeiou]/i', '', $userName) . '1');
}
else
{
$httpAuthText = '';
}
$skeleton = str_replace(array('%%userName%%', '%%domainRegExp%%', '%%httpAuth%%'), array($userName, $domainRegExp, $httpAuthText), $skeleton);
file_put_contents('/etc/lighttpd/virt/' . $userName . '.conf', $skeleton);
$vhosts = file_get_contents('/etc/lighttpd/virt.conf');
$vhosts = preg_split('/\s*\r?\n\s*/ism', $vhosts, -1, PREG_SPLIT_NO_EMPTY);
if (!in_array('include "virt/' . $userName . '.conf"', $vhosts))
{
$vhosts[] = 'include "virt/' . $userName . '.conf"';
}
sort($vhosts);
$vhosts = implode("\n", $vhosts);
file_put_contents('/etc/lighttpd/virt.conf', $vhosts);
$phpFpmSkeleton = file_get_contents('/etc/php5/fpm/pool.d/www.conf.skeleton');
$phpFpmSkeleton = str_replace('%%userName%%', $userName, $phpFpmSkeleton);
file_put_contents('/etc/php5/fpm/pool.d/' . $userName . '.conf', $phpFpmSkeleton);
# $spawn = file_get_contents('/etc/init.d/spawn-fcgi');
# if (preg_match('/FCGI_USER_LIST="(.+?)"/', $spawn, $matches))
# {
# $workers = preg_split('/\s+/ism', $matches[1], -1, PREG_SPLIT_NO_EMPTY);
# if (!in_array($userName, $workers))
# {
# $workers[] = $userName;
# }
# $spawn = preg_replace('/FCGI_USER_LIST="(.+?)"/', 'FCGI_USER_LIST="' . implode(' ', $workers) . '"', $spawn);
# file_put_contents('/etc/init.d/spawn-fcgi', $spawn);
# }
}
?>