Handle hostnames with upper-case letters
[webmin.git] / squid / save_logs.cgi
1 #!/usr/local/bin/perl
2 # save_logs.cgi
3 # Save logging options
4
5 require './squid-lib.pl';
6 $access{'logging'} || &error($text{'elogs_ecannot'});
7 &ReadParse();
8 &lock_file($config{'squid_conf'});
9 $conf = &get_config();
10 $whatfailed = $text{'slogs_ftslo'};
11
12 if ($squid_version < 2.6) {
13         # Just a single logging directive
14         &save_opt("cache_access_log", \&check_file, $conf);
15         }
16 else {
17         # Supports definition of log formats and files
18         for($i=0; defined($fname = $in{"fname_$i"}); $i++) {
19                 $ffmt = $in{"ffmt_$i"};
20                 next if (!$fname);
21                 $fname =~ /^\S+$/ || &error(&text('slogs_efname', $i+1));
22                 $ffmt =~ /\S/ || &error(&text('slogs_effmt', $i+1));
23                 push(@logformat, { 'name' => 'logformat',
24                                    'values' => [ $fname, $ffmt ] });
25                 }
26         &save_directive($conf, "logformat", \@logformat);
27
28         # Save log files
29         for($i=0; defined($afile = $in{"afile_$i"}); $i++) {
30                 $adef = $in{"afile_def_$i"};
31                 next if ($adef == 1);
32                 $adef == 2 || $afile =~ /^\/\S+$/ ||
33                         &error(&text('slogs_eafile', $i+1));
34                 $afmt = $in{"afmt_$i"};
35                 $aacls = $in{"aacls_$i"};
36                 push(@access,
37                   { 'name' => 'access_log',
38                     'values' => [ $adef == 2 ? "none" : $afile,
39                                   $afmt ? ( $afmt ) :
40                                    $aacls ? ( "squid" ) : ( ),
41                                   split(/\s+/, $aacls) ] } );
42                 }
43         &save_directive($conf, "access_log", \@access);
44         }
45
46 &save_opt("cache_log", \&check_file, $conf);
47 if ($in{'cache_store_log_def'} == 2) {
48         &save_directive($conf, "cache_store_log",
49                         [ { 'name' => 'cache_store_log',
50                             'values' => [ "none" ] } ]);
51         }
52 else {
53         &save_opt("cache_store_log", \&check_file, $conf);
54         }
55 &save_opt("cache_swap_log", \&check_file, $conf);
56 &save_choice("emulate_httpd_log", "off", $conf);
57 &save_choice("log_mime_hdrs", "off", $conf);
58 &save_opt("useragent_log", \&check_file, $conf);
59 &save_opt("pid_filename", \&check_pid_file, $conf);
60 if ($squid_version >= 2.2) {
61         if (!$in{'complex_ident'}) {
62                 local @ila = split(/\0/, $in{'ident_lookup_access'});
63                 &save_directive($conf, "ident_lookup_access", !@ila ? [ ] :
64                                 [ { 'name' => 'ident_lookup_access',
65                                     'values' => [ 'allow', @ila ] } ]);
66                 }
67         &save_opt_time("ident_timeout", $conf);
68         }
69 else {
70         &save_choice("ident_lookup", "off", $conf);
71         }
72 &save_choice("log_fqdn", "off", $conf);
73 &save_opt("client_netmask", \&check_netmask, $conf);
74 &save_opt("debug_options", \&check_debug, $conf);
75 if ($squid_version >= 2) {
76         &save_opt("mime_table", \&check_file, $conf);
77         }
78
79 &flush_file_lines();
80 &unlock_file($config{'squid_conf'});
81 &webmin_log("logs", undef, undef, \%in);
82 &redirect("");
83
84 sub check_pid_file
85 {
86 return $_[0] eq 'none' ? undef : &check_file($_[0]);
87 }
88
89 sub check_file
90 {
91 $_[0] =~ /^\// || return &text('slogs_emsg1',$_[0]);
92 $_[0] =~ /^(\S*\/)([^\/\s]+)$/ || return &text('slogs_emsg2',$_[0]);
93 (-d $1) || return &text('slogs_emsg3',$1);
94 return undef;
95 }
96
97 sub check_netmask
98 {
99 &check_ipaddress($_[0]) || return &text('slogs_emsg4',$_[0]);
100 return undef;
101 }
102
103 sub check_debug
104 {
105 $_[0] =~ /\S+/ || return &text('slogs_emsg5',$_[0]);
106 return undef;
107 }
108