Handle hostnames with upper-case letters
[webmin.git] / squid / index.cgi
1 #!/usr/local/bin/perl
2 # index.cgi
3 # Display a menu of different kinds of options
4
5 require './squid-lib.pl';
6
7 # Check for the squid executable
8 if (!&has_command($config{'squid_path'})) {
9         &ui_print_header(undef, $text{'index_header'}, "", undef, 1, 1);
10         print &text('index_msgnoexe',$config{'squid_path'},
11                 $module_name),"<p>\n";
12
13         &foreign_require("software", "software-lib.pl");
14         $lnk = &software::missing_install_link("squid", $text{'index_squid'},
15                         "../$module_name/", $text{'index_header'});
16         print $lnk,"<p>\n" if ($lnk);
17
18         &ui_print_footer("/", $text{'index_return'});
19         exit;
20         }
21
22 # Check for squid config file
23 if (!-r $config{'squid_conf'}) {
24         &ui_print_header(undef, $text{'index_header'}, "", undef, 1, 1);
25         print &text('index_msgnoconfig',$config{'squid_conf'},
26                 $module_name);
27         print "\n<p>\n";
28         &ui_print_footer("/", $text{'index_return'});
29         exit;
30         }
31
32 # Check the version number
33 $fullver = $ver = `$config{'squid_path'} -v 2>&1`;
34 if ($ver =~ /version\s+(\S+)/i) {
35         $ver = $1;
36         }
37 if ($ver =~ /(1\.1)\.\d+/ || $ver =~ /(1)\.NOVM/ ||
38     $ver =~ /(2\.[01234567])\./ || $ver =~ /(3\.[01])/) {
39         # Save version number
40         open(VERSION, ">$module_config_directory/version");
41         print VERSION $1,"\n";
42         close(VERSION);
43         $squid_version = $1;
44         }
45 else {
46         &ui_print_header(undef, $text{'index_header'}, "", undef, 1, 1);
47         print &text('index_msgnosupported2', "<tt>1.1</tt>", "<tt>2.7</tt>"),
48               "<p>\n";
49         print &text('index_squidver', "$config{'squid_path'} -v"),"\n";
50         print "<pre>$fullver</pre>\n";
51         &ui_print_footer("/", $text{'index_return'});
52         exit;
53         }
54
55 # Check for the cache directory
56 $conf = &get_config();
57 if (!&check_cache($conf, \@caches)) {
58         &ui_print_header(undef, $text{'index_header'}, "", undef, 1, 1);
59         print "<center>\n";
60         if (@caches > 1) {
61                 print &text('index_msgnodir1', join(", ", @caches));
62                 }
63         else {
64                 print &text('index_msgnodir2', $caches[0]);
65                 }
66         print $text{'index_msgnodir3'},"<br>\n";
67         print "<form action=init_cache.cgi>\n";
68         print "<input type=submit value=\"$text{'index_buttinit'}\">\n";
69         local $def = defined(getpwnam("squid")) ? "squid" :
70                      defined(getpwnam("httpd")) ? "httpd" : undef;
71         if (!&find_config("cache_effective_user", $conf)) {
72                 print $text{'index_asuser'}," ",&unix_user_input("user", $def),
73                         "<p>\n";
74                 }
75         else {
76                 print "<input type=hidden name=nouser value=1>\n";
77                 }
78         print "<input type=hidden name=caches value=\"",
79                 join(" ",@caches),"\">\n";
80         print "</form></center>\n";
81         print &ui_hr();
82         }
83 else {
84         &ui_print_header(undef, $text{'index_header'}, "", "intro",
85                 1, 1, 0, &restart_button()."<br>".
86                          &help_search_link("squid", "doc", "google"),
87                 undef, undef, &text('index_version', $squid_version));
88         }
89
90 if ($squid_version < 2) {
91         $auth = 1;
92         }
93 else {
94         local $file = &get_auth_file($conf);
95         $auth = 2 if ($file);
96         }
97 $calamaris = &has_command($config{'calamaris'});
98 $delay = $squid_version >= 2.3;
99 $authparam = $squid_version >= 2;
100 $headeracc = $squid_version >= 2.5;
101 $iptables = &foreign_check("firewall");
102
103 @otitles = ( 'portsnets', 'othercaches', 'musage', 'logging',
104              'copts', 'hprogs', 'actrl', 'admopts',
105              ( $auth ? ( 'proxyauth' ) : ( ) ),
106              ( $authparam ? ( 'authparam' ) : ( ) ),
107              ( $delay ? ( 'delay' ) : ( ) ),
108              ( $headeracc ? ( 'headeracc' ) : ( ) ),
109              'refresh',
110              'miscopt',
111              ( $iptables ? ( 'iptables' ) : ( ) ),
112              'cms', 'cachemgr', 'rebuild',
113              ( $calamaris ? ( 'calamaris' ) : ( ) ) );
114 @olinks =  ( "edit_ports.cgi", "edit_icp.cgi", "edit_mem.cgi",
115              "edit_logs.cgi", "edit_cache.cgi", "edit_progs.cgi",
116              "edit_acl.cgi", "edit_admin.cgi",
117              ( $auth == 1 ? ( "edit_auth.cgi" ) :
118                $auth == 2 ? ( "edit_nauth.cgi" ) : ( ) ),
119              ( $authparam ? ( "edit_authparam.cgi" ) : ( ) ),
120              ( $delay ? ( 'edit_delay.cgi' ) : ( ) ),
121              ( $headeracc ? ( 'list_headeracc.cgi' ) : ( ) ),
122              "list_refresh.cgi",
123              "edit_misc.cgi",
124              ( $iptables ? ( "edit_iptables.cgi" ) : ( ) ),
125              "cachemgr.cgi", "edit_cachemgr.cgi", "clear.cgi",
126              ( $calamaris ? ( "calamaris.cgi" ) : ( ) ) );
127 for($i=0; $i<@otitles; $i++) {
128         if (!$access{$otitles[$i]}) {
129                 splice(@otitles, $i, 1);
130                 splice(@olinks, $i, 1);
131                 $i--;
132                 }
133         else {
134                 $otitles[$i] = $text{'index_'.$otitles[$i]};
135                 }
136         }
137 @oicons =  map { $t=$_; $t=~s/cgi/gif/; $t=~s/edit_// if ($t ne 'edit_cachemgr.gif'); "images/$t" } @olinks;
138 &icons_table(\@olinks, \@otitles, \@oicons);
139
140 # Show start/stop/apply buttons
141 if ($config{'restart_pos'} != 1) {
142         print &ui_hr();
143         print &ui_buttons_start();
144         if ($pid = &is_squid_running()) {
145                 if ($access{'restart'}) {
146                         print &ui_buttons_row("restart.cgi", $text{'index_restart'},
147                                               $text{'index_restartdesc'},
148                                               &ui_hidden("pid", $pid).
149                                               &ui_hidden("redir", "index.cgi"));
150                         }
151                 if ($access{'start'}) {
152                         print &ui_buttons_row("stop.cgi", $text{'index_stop'},
153                                               $text{'index_stopdesc'},
154                                               &ui_hidden("pid", $pid).
155                                               &ui_hidden("redir", "index.cgi"));
156                         }
157                 }
158         else {
159                 if ($access{'start'}) {
160                         print &ui_buttons_row("start.cgi", $text{'index_start'},
161                                               $text{'index_startdesc'},
162                                               &ui_hidden("redir", "index.cgi"));
163                         }
164                 }
165         print &ui_buttons_end();
166         }
167
168 &ui_print_footer("/", $text{'index_return'});
169