Handle hostnames with upper-case letters
[webmin.git] / acl / edit_group.cgi
1 #!/usr/local/bin/perl
2 # edit_group.cgi
3 # Edit or create a webmin group
4
5 require './acl-lib.pl';
6 &ReadParse();
7 $access{'groups'} || &error($text{'gedit_ecannot'});
8 if ($in{'group'}) {
9         # Editing an existing group
10         &ui_print_header(undef, $text{'gedit_title'}, "");
11         $g = &get_group($in{'group'});
12         $g || &error($text{'gedit_egone'});
13         %group = %$g;
14         }
15 else {
16         # Creating a new group
17         &ui_print_header(undef, $text{'gedit_title2'}, "");
18         %group = ( );
19         if ($in{'clone'}) {
20                 # Copy modules from clone
21                 $g = &get_group($in{'clone'});
22                 if ($g) {
23                         $group{'modules'} = $g->{'modules'};
24                         }
25                 }
26         }
27
28 print &ui_form_start("save_group.cgi", "post");
29 print &ui_hidden("old", $in{'group'});
30 if ($in{'clone'}) {
31         print &ui_hidden("clone", $in{'clone'});
32         }
33 print &ui_hidden_table_start($text{'gedit_rights'}, "width=100%", 2, "rights",
34                              1, [ "width=30%" ]);
35
36 # Show the group name
37 print &ui_table_row($text{'gedit_group'},
38         &ui_textbox("name", $group{'name'}, 30, 0, undef, "autocomplete=off"));
39
40 # Show group description
41 print &ui_table_row($text{'gedit_desc'},
42         &ui_textbox("desc", $group{'desc'}, 60));
43
44 # Find and show the parent group
45 @glist = grep { $_->{'name'} ne $group{'name'} } &list_groups();
46 @mcan = $access{'gassign'} eq '*' ?
47                 ( ( map { $_->{'name'} } @glist ), '_none' ) :
48                 split(/\s+/, $access{'gassign'});
49 map { $gcan{$_}++ } @mcan;
50 if (@glist && %gcan) {
51         @opts = ( );
52         if ($gcan{'_none'}) {
53                 push(@opts, [ undef, "<$text{'edit_none'}>" ]);
54                 }
55         $memg = undef;
56         foreach $g (@glist) {
57                 if (&indexof('@'.$group{'name'}, @{$g->{'members'}}) >= 0) {
58                         $memg = $g->{'name'};
59                         }
60                 next if (!$gcan{$g->{'name'}} && $memg ne $g->{'name'});
61                 push(@opts, [ $g->{'name'} ]);
62                 }
63         print &ui_table_row($text{'edit_group'},
64                 &ui_select("group", $memg, \@opts));
65         }
66
67 if ($in{'group'}) {
68         # Show all current members
69         @grid = map { $_ =~ /^\@(.*)$/ ? "<a href='edit_group.cgi?group=$1'><i>$1</i></a>" : "<a href='edit_user.cgi?user=$_'>$_</a>" }
70                     @{$group{'members'}};
71         if (@grid) {
72                 print &ui_table_row($text{'gedit_members'},
73                                     &ui_links_row(\@grid));
74                 }
75         }
76
77 # Storage type
78 if ($in{'group'}) {
79         print &ui_table_row($text{'edit_proto'},
80                 $text{'edit_proto_'.$group{'proto'}});
81         }
82
83 print &ui_hidden_table_end("basic");
84
85 # Start of modules section
86 print &ui_hidden_table_start(@groups ? $text{'edit_modsg'} : $text{'edit_mods'},
87                              "width=100%", 2, "mods");
88
89 # Show available modules, under categories
90 @mlist = &list_module_infos();
91 map { $has{$_}++ } @{$group{'modules'}};
92 @links = ( &select_all_link("mod", 0, $text{'edit_selall'}),
93            &select_invert_link("mod", 0, $text{'edit_invert'}) );
94 @cats = &unique(map { $_->{'category'} } @mlist);
95 &read_file("$config_directory/webmin.catnames", \%catnames);
96 $grids = "";
97 foreach $c (sort { $b cmp $a } @cats) {
98         @cmlist = grep { $_->{'category'} eq $c } @mlist;
99         $grids .= "<b>".($catnames{$c} || $text{'category_'.$c})."</b><br>\n";
100         @grid = ( );
101         $sw = 0;
102         foreach $m (@cmlist) {
103                 local $md = $m->{'dir'};
104                 $label = "";
105                 if ($access{'acl'} && $in{'group'}) {
106                         # Show link for editing ACL
107                         $label = sprintf "<a href='edit_acl.cgi?".
108                                          "mod=%s&%s=%s'>%s</a>\n",
109                                 &urlize($m->{'dir'}),
110                                 "group", &urlize($in{'group'}),
111                                 $m->{'desc'};
112                         }
113                 else {
114                         $label = $m->{'desc'};
115                         }
116                 push(@grid, &ui_checkbox("mod", $md, $label,$has{$md}));
117                 }
118         $grids .= &ui_grid_table(\@grid, 2, 100, [ "width=50%", "width=50%" ]);
119         }
120 print &ui_table_row(undef, &ui_links_row(\@links).
121                            $grids.
122                            &ui_links_row(\@links), 2);
123 print &ui_hidden_table_end("mods");
124
125 # Add global ACL section
126 if ($access{'acl'} && $in{'group'}) {
127         print &ui_hidden_table_start($text{'edit_global'}, "width=100%", 2,
128                                      "global", 0, [ "width=30%" ]);
129         %uaccess = &get_group_module_acl($in{'group'}, "");
130         print &ui_hidden("acl_security_form", 1);
131         &foreign_require("", "acl_security.pl");
132         &foreign_call("", "acl_security_form", \%uaccess);
133         print &ui_hidden_table_end("global");
134         }
135
136 # Generate form end buttons
137 @buts = ( );
138 push(@buts, [ undef, $in{'group'} ? $text{'save'} : $text{'create'} ]);
139 if ($in{'group'}) {
140         push(@buts, [ "but_clone", $text{'edit_clone'} ]);
141         push(@buts, [ "but_delete", $text{'delete'} ]);
142         }
143 print &ui_form_end(\@buts);
144
145 &ui_print_footer("", $text{'index_return'});
146