-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.cgi
executable file
·123 lines (114 loc) · 3.33 KB
/
index.cgi
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
#!/usr/local/bin/perl
# Show Nginx virtual hosts and global config
use strict;
use warnings;
require './virtualmin-nginx-lib.pl';
my $ver = &get_nginx_version();
our (%text, %module_info, %config, $module_name, %access);
&ui_print_header($ver ? &text('index_version', $ver) : undef,
$module_info{'desc'}, "", undef, 1, 1);
# Check config
if (!-r $config{'nginx_config'}) {
&ui_print_endpage(
&text('index_econfig', "<tt>$config{'nginx_config'}</tt>",
"../config.cgi?$module_name"));
}
if (!&has_command($config{'nginx_cmd'})) {
&ui_print_endpage(
&text('index_ecmd', "<tt>$config{'nginx_cmd'}</tt>",
"../config.cgi?$module_name"));
}
my $conf = &get_config();
if ($access{'global'}) {
# Show icons for global config types
print &ui_subheading($text{'index_global'});
my @gpages = ( "net", "mime", "logs", "docs", "ssi", "misc", "manual" );
&icons_table(
[ map { "edit_".$_.".cgi" } @gpages ],
[ map { $text{$_."_title"} } @gpages ],
[ map { "images/".$_.".gif" } @gpages ],
);
print &ui_hr();
}
# Show list of virtual hosts
print &ui_subheading($text{'index_virts'});
my $http = &find("http", $conf);
if (!$http) {
&ui_print_endpage(
&text('index_ehttp', "<tt>$config{'nginx_config'}</tt>"));
}
my @allservers = &find("server", $http);
my @servers = grep { &can_edit_server($_) } @allservers;
my @links;
if (!$access{'vhosts'}) {
push(@links, "<a href='edit_server.cgi?new=1'>$text{'index_add'}</a>");
}
if (@servers) {
print &ui_links_row(\@links);
my @tds = ( "valign=top", undef, undef, "valign=top" );
print &ui_columns_start([ $text{'index_name'},
$text{'index_ip'},
$text{'index_port'},
$text{'index_root'} ], 100, 0, \@tds);
foreach my $s (@servers) {
my $name = &find_value("server_name", $s);
$name ||= "";
# Extract all IPs and ports from listen directives
my (@ips, @ports);
foreach my $l (&find_value("listen", $s)) {
my ($ip, $port) = &split_ip_port($l);
$ip ||= $text{'index_any'};
$ip = $text{'index_any6'} if ($ip eq "::");
push(@ips, $ip);
push(@ports, $port);
}
my $rootdir = &find_value("root", $s);
my $root = $rootdir;
if (!$root) {
my @locs = &find("location", $s);
my ($rootloc) = grep { $_->{'value'} eq '/' } @locs;
if ($rootloc) {
$rootdir = &find_value("root", $rootloc);
$root = $rootdir ||
"<i>$text{'index_noroot'}</i>";
}
else {
$root = "<i>$text{'index_norootloc'}</i>";
}
$rootdir ||= "";
}
my $id = $name.";".$rootdir;
print &ui_columns_row([
"<a href='edit_server.cgi?id=".&urlize($id)."'>".
($name ? &html_escape($name) : $text{'default'})."</a>",
join("<br>", @ips),
join("<br>", @ports),
$root ],
\@tds);
}
print &ui_columns_end();
}
elsif (@allservers) {
print "<b>$text{'index_noneaccess'}</b><p>\n";
}
else {
print "<b>$text{'index_none'}</b><p>\n";
}
print &ui_links_row(\@links);
# Show start / stop buttons
print &ui_hr();
print &ui_buttons_start();
if (&is_nginx_running()) {
if ($access{'stop'}) {
print &ui_buttons_row("stop.cgi", $text{'index_stop'},
$text{'index_stopdesc'});
}
print &ui_buttons_row("restart.cgi", $text{'index_restart'},
$text{'index_restartdesc'});
}
elsif ($access{'stop'}) {
print &ui_buttons_row("start.cgi", $text{'index_start'},
$text{'index_startdesc'});
}
print &ui_buttons_end();
&ui_print_footer("/", $text{'index'});