3 # Create, update or delete an external auth program
5 require './squid-lib.pl';
6 &error_setup($text{'ext_err'});
7 $access{'actrl'} || &error($text{'eacl_ecannot'});
10 @exts = &find_config("external_acl_type", $conf);
11 $ext = $conf->[$in{'index'}] if (!$in{'new'});
14 # Just delete it (as long as there are no ACL references)
15 @used = grep { $_->{'values'}->[1] eq 'external' &&
16 $_->{'values'}->[2] eq $ext->{'values'}->[0] }
17 &find_config("acl", $conf);
18 &error($text{'ext_eused'}) if (@used);
19 splice(@exts, &indexof($ext, @exts), 1);
23 # Validate and store inputs
24 $in{'name'} =~ /^\S+$/ || &error($text{'ext_ename'});
25 if (!$ext || $in{'name'} ne $ext->{'values'}->[0]) {
27 local ($clash) = grep { $_->{'values'}->[0] eq $in{'name'} }
29 &error($text{'ext_eclash'}) if ($clash);
31 push(@vals, $in{'name'});
32 foreach $on ('ttl', 'negative_ttl', 'concurrency', 'cache') {
33 if (!$in{$on.'_def'}) {
34 $in{$on} =~ /^\d+$/ || &error($text{'ext_e'.$on});
35 push(@vals, $on."=".$in{$on});
38 $in{'format'} =~ /^\S+/ || &error($text{'ext_eformat'});
39 push(@vals, $in{'format'});
40 $in{'program'} =~ /^(\S+)/ && &has_command("$1") ||
41 &error($text{'ext_eprogram'});
42 push(@vals, $in{'program'});
45 $logext = $newext = { 'name' => 'external_acl_type',
47 if ($ext) { $exts[&indexof($ext, @exts)] = $newext; }
48 else { push(@exts, $newext); }
50 if ($ext && $in{'name'} ne $ext->{'values'}->[0]) {
51 # Fix any ACLs that referred to this external type
52 @acls = &find_config("acl", $conf);
54 if ($a->{'values'}->[1] eq 'external' &&
55 $a->{'values'}->[2] eq $ext->{'values'}->[0]) {
56 $a->{'values'}->[2] = $in{'name'};
59 &save_directive($conf, "acl", \@acls);
63 &save_directive($conf, "external_acl_type", \@exts);
65 &unlock_file($config{'squid_conf'});
66 &webmin_log($in{'delete'} ? 'delete' : $ext ? 'modify' : 'create',
67 'ext', $logext->{'values'}->[0]);
68 &redirect("edit_acl.cgi?mode=external");