Handle hostnames with upper-case letters
[webmin.git] / squid / save_progs.cgi
1 #!/usr/local/bin/perl
2 # save_progs.cgi
3 # Save helper program options
4
5 require './squid-lib.pl';
6 $access{'hprogs'} || &error($text{'eprogs_ecannot'});
7 &ReadParse();
8 &lock_file($config{'squid_conf'});
9 $conf = &get_config();
10 $whatfailed = $text{'sprog_ftshpo'};
11
12 if ($squid_version < 2) {
13         &save_opt("ftpget_program", \&check_prog, $conf);
14         &save_opt("ftpget_options", \&check_opts, $conf);
15         }
16 else {
17         &save_opt("ftp_list_width", \&check_width, $conf);
18         }
19 &save_opt("ftp_user", \&check_ftpuser, $conf);
20 &save_opt("cache_dns_program", \&check_prog, $conf);
21 &save_opt("dns_children", \&check_children, $conf);
22 &save_choice("dns_defnames", "off", $conf);
23 if ($squid_version >= 2) {
24         &save_opt("dns_nameservers", \&check_dnsservers, $conf);
25         }
26 &save_opt("unlinkd_program", \&check_prog, $conf);
27 &save_opt("pinger_program", \&check_prog, $conf);
28 if ($squid_version >= 2.6) {
29         &save_opt("url_rewrite_program", \&check_prog, $conf);
30         &save_opt("url_rewrite_children", \&check_children, $conf);
31         }
32 else {
33         &save_opt("redirect_program", \&check_prog, $conf);
34         &save_opt("redirect_children", \&check_children, $conf);
35         }
36
37 &flush_file_lines();
38 &unlock_file($config{'squid_conf'});
39 &webmin_log("progs", undef, undef, \%in);
40 &redirect("");
41
42 sub check_opts
43 {
44 return $_[0] =~ /\S/ ? undef : $text{'sprog_emsg1'};
45 }
46
47 sub check_prog
48 {
49 $_[0] =~ /^(\/\S+)/ || return &text('sprog_emsg2', $_[0]);
50 return -x $1 ? undef : &text('sprog_emsg3',$_[0]); 
51 }
52
53 sub check_ftpuser
54 {
55 return $_[0] =~ /^\S+@\S*$/ ? undef : &text('sprog_emsg4',$_[0]);
56 }
57
58 sub check_children
59 {
60 return $_[0] =~ /^\d+$/ ? undef : &text('sprog_emsg5',$_[0]);
61 }
62
63 sub check_width
64 {
65 return $_[0] =~ /^\d+$/ ? undef : &text('sprog_emsg6',$_[0]);
66 }
67
68 sub check_dnsservers
69 {
70 local $dns;
71 local @dns = split(/\s+/, $_[0]);
72 return $text{'sprog_emsg7'} if (!@dns);
73 foreach $dns (@dns) {
74         &check_ipaddress($dns) || return &text('sprog_emsg8',$dns);
75         }
76 return undef;
77 }
78
79