Handle hostnames with upper-case letters
[webmin.git] / squid / save_admin.cgi
1 #!/usr/local/bin/perl
2 # save_admin.cgi
3 # Save admin options
4
5 require './squid-lib.pl';
6 $access{'admopts'} || &error($text{'eadm_ecannot'});
7 &ReadParse();
8 &lock_file($config{'squid_conf'});
9 $conf = &get_config();
10 $whatfailed = $text{'sadmin_ftsao'};
11
12 ($olduser, $oldgroup) = &get_squid_user($conf);
13 if ($squid_version < 2) {
14         if ($in{'effective_def'}) {
15                 &save_directive($conf, "cache_effective_user", [ ]);
16                 }
17         else {
18                 %dir = ( 'name', 'cache_effective_user',
19                          'values', [ $in{'effective_u'}, $in{'effective_g'} ] );
20                 &save_directive($conf, "cache_effective_user", [ \%dir ]);
21                 }
22         }
23 else {
24         &save_opt("cache_effective_user", undef, $conf);
25         &save_opt("cache_effective_group", undef, $conf);
26         }
27 &save_opt("cache_mgr", \&check_email, $conf);
28 &save_opt("visible_hostname", \&check_hostname, $conf);
29 if ($squid_version < 2) {
30         &save_opt("announce_to", undef, $conf);
31         &save_opt("cache_announce", \&check_announce, $conf);
32         }
33 else {
34         &save_opt("unique_hostname", \&check_hostname, $conf);
35         if ($squid_version >= 2.4) {
36                 &save_opt("hostname_aliases", undef, $conf);
37                 }
38         &save_opt("announce_host", \&check_hostname, $conf);
39         &save_opt("announce_port", \&check_port, $conf);
40         &save_opt("announce_file", undef, $conf);
41         &save_opt_time("announce_period", $conf);
42         }
43 &flush_file_lines();
44 &unlock_file($config{'squid_conf'});
45 &webmin_log("admin", undef, undef, \%in);
46
47 ($user, $group) = &get_squid_user($conf);
48 if (($olduser ne $user || $oldgroup ne $group) && $user && $group) {
49         # User/group has changed! Ask user if he wants to chown log/cache/pid
50         &ui_print_header(undef, $text{'sadmin_header'}, "");
51         print $text{'sadmin_msg1'},"\n"; 
52         print "<center><form action=chown.cgi>\n";
53         print "<input type=submit value=\"$text{'sadmin_buttco'}\">\n";
54         print "</form></center>\n";
55         &ui_print_footer("", $text{'sadmin_return'});
56         }
57 else { &redirect(""); }
58
59 sub check_email
60 {
61 return $_[0] =~ /^\S+$/ ? undef : &text('sadmin_inavea',$_[0]);
62 }
63
64 sub check_hostname
65 {
66 return $_[0] =~ /^\S+$/ ? undef : &text('sadmin_inavh',$_[0]);
67 }
68
69 sub check_announce
70 {
71 return $_[0] =~ /^\d+$/ ? undef : &text('sadmin_inavap',$_[0]);
72 }
73
74 sub check_port
75 {
76 return $_[0] =~ /^\d+$/ ? undef : &text('sadmin_inavp',$_[0]);
77 }
78