-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_virtualhost.php
164 lines (131 loc) · 4.79 KB
/
generate_virtualhost.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
<?php
// Init
header('Content-type: text/html; charset=utf-8');
// Parametres
$fqdn_vhost = $_POST['fqdn_vhost'];
$description_vhost = $_POST['description_vhost'];
//$email_vhost = $_POST['email_vhost'];
$log_vhost = $_POST['log_vhost'];
$http_vhost = $_POST['http_vhost'];
$redir_https_vhost = $_POST['redir_https_vhost'];
$https_vhost = $_POST['https_vhost'];
$special_vhost = $_POST['special_vhost'];
$auth_vhost = $_POST['auth_vhost'];
// On calcul le nom court du vhost
$name_vhost = explode(".", $fqdn_vhost, 2);
$domain_vhost = $name_vhost[1];
$name_vhost = $name_vhost[0];
// Une tabulation :D
$t = " ";
// Traitement
// Entete
$out_entete = "#\n# VirtualHost $fqdn_vhost\n# $description_vhost\n#\n";
// Fichiers log
$out_logfiles = $t.$t."CustomLog /var/log/httpd/$name_vhost-access.log combined\n";
$out_logfiles .= $t.$t."ErrorLog /var/log/httpd/$name_vhost-error.log\n";
$out_logfiles .= $t.$t."LogLevel warn\n";
// Authentifications
// CAS
if($auth_vhost == "cas") {
$out_auth = $t.$t.$t."AuthType CAS\n";
$out_auth .= $t.$t.$t."AuthName \"$description_vhost\"\n";
$out_auth .= $t.$t.$t."Require valid-user\n";
}
// SHibb
if($auth_vhost == "shibb") {
$out_auth = $t.$t.$t."AuthType shibboleth\n";
$out_auth .= $t.$t.$t."ShibRequestSetting requireSession 1\n";
$out_auth .= $t.$t.$t."ShibRequestSetting applicationId default\n";
$out_auth .= $t.$t.$t."Require valid-user\n";
}
// Directory /
$out_dir = $t.$t."DocumentRoot /var/www/$name_vhost\n";
$out_dir .= $t.$t."<Directory />\n";
if($special_vhost == "cgi") {
$out_dir .= $t.$t.$t."AddHandler perl-script .cgi\n";
$out_dir .= $t.$t.$t."Options FollowSymLinks ExecCGI\n";
}else{
$out_dir .= $t.$t.$t."Options FollowSymLinks\n";
}
$out_dir .= $t.$t.$t."AllowOverride none\n";
$out_dir .= $t.$t.$t."Order allow,deny\n";
$out_dir .= $t.$t.$t."Allow from all\n";
// Auth
if($auth_vhost != "") {
$out_dir .= $t.$t.$t."\n";
$out_dir .= $out_auth;
}
// Secu PHP
if($special_vhost == "php") {
$out_dir .= $t.$t.$t."\n";
$out_dir .= $t.$t.$t."php_admin_flag safemode 1\n";
$out_dir .= $t.$t.$t."php_admin_value open_basedir \"/var/www/$name_vhost:/tmp/\"\n";
$out_dir .= $t.$t.$t."php_admin_value include_path \".:/usr/share/pear\"\n";
}
$out_dir .= $t.$t."</Directory>\n";
// Location / for Reverse Proxy
$out_loc = $t.$t."<Location />\n";
$out_loc .= $t.$t.$t."Order allow,deny\n";
$out_loc .= $t.$t.$t."Allow from all\n";
// Auth
if($auth_vhost != "") {
$out_loc .= $t.$t.$t."\n";
$out_loc .= $out_auth;
}
$out_loc .= $t.$t.$t."\n";
$out_loc .= $t.$t.$t."ProxyPass http://localhost:8080/\n";
$out_loc .= $t.$t.$t."ProxyPassReverse http://localhost:8080/\n";
$out_loc .= $t.$t."</Location>\n";
// Redir HTTP -> HTTPS
$out_redir = $t.$t."RedirectMatch permanent ^/(.*)$ https://$fqdn_vhost/$1\n";
// Partie HTTP
if($http_vhost == "true") {
$out_http = $t."<VirtualHost *:80>\n";
$out_http .= $t.$t."ServerName $fqdn_vhost\n";
$out_http .= $t.$t."ServerAlias $name_vhost\n";
$out_http .= $t.$t."ServerAdmin admin@$domain_vhost\n";
$out_http .= $t.$t."\n";
if($redir_https_vhost == "true" AND $https_vhost == "true") {
$out_http .= $out_redir;
}elseif($special_vhost == "rproxy") {
$out_http .= $out_loc;
}else{
$out_http .= $out_dir;
}
// Ajout log si activé
if($log_vhost == "true") {
$out_http .= "\n".$out_logfiles;
}
$out_http .= $t."</VirtualHost>\n";
if($https_vhost == "true") {
// Un saut de ligne si il y a un vhost 443 en plus du 80
$out_http .= "\n";
}
}
// Partie HTTPS
if($https_vhost == "true") {
$out_https = $t."<VirtualHost *:443>\n";
$out_https .= $t.$t."ServerName $fqdn_vhost\n";
$out_https .= $t.$t."ServerAlias $name_vhost\n";
$out_https .= $t.$t."ServerAdmin admin@$domain_vhost\n";
$out_https .= $t.$t."\n";
if($special_vhost == "rproxy") {
$out_https .= $out_loc."\n";
}else{
$out_https .= $out_dir."\n";
}
// Partie mod_ssl
$out_https .= $t.$t."SSLEngine on\n";
$out_https .= $t.$t."SSLCertificateFile /etc/httpd/conf/ssl/$fqdn_vhost.crt\n";
$out_https .= $t.$t."SSLCertificateChainFile /etc/httpd/conf/ssl/cachain.crt\n";
$out_https .= $t.$t."SSLCertificateKeyFile /etc/httpd/conf/ssl/key/$fqdn_vhost.key\n";
// Ajout log si activé
if($log_vhost == "true") {
$out_https .= "\n".$out_logfiles;
}
$out_https .= $t."</VirtualHost>\n";
}
// Affichage
$output = "<pre>".htmlentities($out_entete.$out_http.$out_https)."</pre>";
echo utf8_encode($output);
?>