Handle hostnames with upper-case letters
[webmin.git] / squid / save_auth.cgi
1 #!/usr/local/bin/perl
2 # save_auth.cgi
3 # Save authentication options
4
5 require './squid-lib.pl';
6 $access{'proxyauth'} || &error($text{'eauth_ecannot'});
7 &ReadParse();
8 &lock_file($config{'squid_conf'});
9 $conf = &get_config();
10 $whatfailed = $text{'sauth_ftsao'};
11
12 if ($in{'authfile_def'}) {
13         &save_directive($conf, "proxy_auth", [ ]);
14         }
15 else {
16         $in{'authfile'} =~ /^\// || &error($text{'sauth_iomuf'});
17         if (!-r $in{'authfile'}) {
18                 &open_tempfile(AUTH, ">$in{'authfile'}");
19                 &close_tempfile(AUTH);
20                 ($user, $group) = &get_squid_user($conf);
21                 if ($user) {
22                         @uinfo = getpwnam($user);
23                         @ginfo = getgrnam($group);
24                         chown($uinfo[2], $ginfo[2], $in{'authfile'});
25                         chmod(0644, $in{'authfile'});
26                         }
27                 }
28         push(@vals, $in{'authfile'});
29         if (!$in{'authdom_def'}) {
30                 $in{'authdom'}=~/^\S+$/ || &error($text{'sauth_iomd'});
31                 push(@vals, $in{'authdom'});
32                 }
33         &save_directive($conf, "proxy_auth",
34                         [ { 'name' => 'proxy_auth',
35                             'values' => \@vals } ]);
36         }
37 &flush_file_lines();
38
39 # check if the proxy_auth directive is supported
40 $out = `$config{'squid_path'} -f $config{'squid_conf'} -k check 2>&1`;
41 if ($out =~ /proxy_auth/) {
42         # it isn't .. roll back
43         &save_directive($conf, "proxy_auth", [ ]);
44         &flush_file_lines();
45         &error($text{'sauth_msg1'});
46         }
47 &unlock_file($config{'squid_conf'});
48 &redirect("");
49