-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathvirtual_feature.pl
209 lines (145 loc) · 3.66 KB
/
virtual_feature.pl
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
do 'virtualmin-nginx-lib.pl';
use File::Copy;
sub feature_always_links
{
}
sub feature_backup
{
}
sub feature_bandwidth
{
}
sub feature_check
{
if($config{'root'} eq "")
{
return "Nginx module needs a root path to your Nginx installation";
}
unless(-r $config{'root'} . "/sbin/nginx")
{
return "Nginx needs to be installed.";
}
if($config{'vhost_path'} eq "")
{
return "Nginx module needs a path to your vhost config directory. This directory is usually under the nginx conf path and included in the main nginx conf file.";
}
unless (-d $config{'root'} . "/conf/" . $config{'vhost_path'})
{
mkdir($config{'root'} . "/conf/" . $config{'vhost_path'});
}
unless (-d $config{'root'} . "/conf/" . $config{'vhost_path'} . "/enabled")
{
mkdir($config{'root'} . "/conf/" . $config{'vhost_path'}. "/enabled");
}
unless (-d $config{'root'} . "/conf/" . $config{'vhost_path'} . "/disabled")
{
mkdir($config{'root'} . "/conf/" . $config{'vhost_path'}. "/disabled");
}
open(CONF, $config{'root'} . "/conf/nginx.conf");
local $/ = undef;
my $filestring = <CONF>;
close(CONF);
my $pattern = "include " . $config{'vhost_path'} . "\\/enabled\\/\\*.conf;";
#print $pattern;
#print $filestring;
unless ($filestring =~ /$pattern/)
{
chop($filestring);
$filestring .= "\tinclude " . $config{'vhost_path'} . "/enabled/*.conf;\n}";
open(CONF, ">", $config{'root'} . "/conf/nginx.conf");
print(CONF $filestring);
close(CONF);
}
return undef;
}
sub feature_clash
{
return undef;
}
sub feature_delete
{
my ($d) = @_;
&$virtual_server::first_print("Deleting Nginx site ..");
unlink($config{'root'} . "/conf/" . $config{'vhost_path'} . "/enabled/" . $d->{'dom'} . ".conf");
&$virtual_server::second_print(".. done");
}
sub feature_depends
{
return undef;
}
sub feature_disable
{
my ($d) = @_;
&$virtual_server::first_print("Disabling Nginx website ..");
move($config{'root'} . "/conf/" . $config{'vhost_path'} . "/enabled/" . $d->{'dom'} . ".conf", $config{'root'} . "/conf/" . $config{'vhost_path'} . "/disabled/" . $d->{'dom'} . ".conf" );
&$virtual_server::second_print(".. done");
}
sub feature_disname
{
return "Nginx website";
}
sub feature_enable
{
my ($d) = @_;
&$virtual_server::first_print("Re-enabling Nginx website ..");
move($config{'root'} . "/conf/" . $config{'vhost_path'} . "/disabled/" . $d->{'dom'} . ".conf", $config{'root'} . "/conf/" . $config{'vhost_path'} . "/enabled/" . $d->{'dom'} . ".conf" );
&$virtual_server::second_print(".. done");
}
sub feature_import
{
}
sub feature_label
{
return "Setup Nginx website for domain?";
}
sub feature_links
{
}
sub feature_losing
{
return "The Nginx config file for this website will be deleted.";
}
sub feature_modify
{
my ($d, $oldd) = @_;
if ($d->{'dom'} ne $oldd->{'dom'}) {
}
}
sub feature_name
{
return "Nginx website";
}
sub feature_restore
{
}
sub feature_setup
{
my ($d) = @_;
&$virtual_server::first_print("Setting up Nginx site ..");
my $file;
open($file, ">" . $config{'root'} . "/conf/" . $config{'vhost_path'} . "/enabled/" . $d->{'dom'} . ".conf");
my $conf = <<CONFIG;
server {
listen $d->{'ip'}:80;
server_name $d->{'dom'} www.$d->{'dom'};
location / {
root $d->{'home'}/public_html;
index index.html index.htm;
}
}
CONFIG
print($file $conf);
close $file;
&$virtual_server::second_print(".. done");
}
sub feature_suitable
{
return 1;
}
sub feature_validate
{
return undef;
}
sub feature_webmin
{
}