Handle hostnames with upper-case letters
[webmin.git] / newmods.pl
1 # newmods.pl
2 # Updates an acl file to include new modules. Called with the parameters
3 # <config directory> <module>+
4
5 for($i=1; $i<@ARGV; $i++) {
6         if (!(-d "$ARGV[0]/$ARGV[$i]")) {
7                 push(@new, $ARGV[$i]);
8                 }
9         }
10
11 if (@new) {
12         # Read in the existing file
13         open(ACL, "$ARGV[0]/webmin.acl");
14         @acl = <ACL>;
15         close(ACL);
16
17         # Get the list of users to grant new modules to
18         if (open(NEWMODS, "$ARGV[0]/newmodules")) {
19                 while(<NEWMODS>) {
20                         s/\r|\n//g;
21                         $users{$_}++ if (/\S/);
22                         }
23                 close(NEWMODS);
24                 $newmods++;
25                 }
26
27         if ($newmods) {
28                 # Find the users to add to
29                 for($i=0; $i<@acl; $i++) {
30                         if ($acl[$i] =~ /^(\S+):/ && $users{$1}) {
31                                 push(@pos, $i);
32                                 }
33                         }
34                 }
35         else {
36                 # Just use 'root' or 'admin' or the first user in the file
37                 $pos[0] = 0;
38                 for($i=0; $i<@acl; $i++) {
39                         if ($acl[$i] =~ /^(\S+):/ &&
40                             ($1 eq 'root' || $1 eq 'admin')) {
41                                 $pos[0] = $i;
42                                 last;
43                                 }
44                         }
45                 }
46
47         # Update it with new modules
48         foreach $pos (@pos) {
49                 $acl[$pos] =~ /^(\S+):\s*(.*)$/ || next;
50                 $name = $1; @list = split(/\s+/, $2);
51                 foreach $o (@list) { $old{$o}++; }
52                 foreach $n (@new) {
53                         push(@list, $n) if (!$old{$n});
54                         }
55                 $acl[$pos] = "$name: ".join(" ",@list)."\n";
56                 }
57
58         # Write it out
59         open(ACL, ">$ARGV[0]/webmin.acl");
60         print ACL @acl;
61         close(ACL);
62         }
63