Handle hostnames with upper-case letters
[webmin.git] / useradmin / edit_group.cgi
1 #!/usr/local/bin/perl
2 # edit_group.cgi
3 # Display a form for editing or creating a group
4
5 require './user-lib.pl';
6 &ReadParse();
7
8 # Get group and show page header
9 $n = $in{'group'};
10 if ($n eq "") {
11         $access{'gcreate'} == 1 || &error($text{'gedit_ecreate'});
12         &ui_print_header(undef, $text{'gedit_title2'}, "", "create_group");
13         }
14 else {
15         @glist = &list_groups();
16         ($ginfo_hash) = grep { $_->{'group'} eq $n } @glist;
17         $ginfo_hash || &error($text{'gedit_egone'});
18         %group = %$ginfo_hash;
19         &can_edit_group(\%access, \%group) ||
20                 &error($text{'gedit_eedit'});
21         &ui_print_header(undef, $text{'gedit_title'}, "", "edit_group");
22         }
23 @ulist = &list_users();
24
25 &build_group_used(\%gused);
26
27 # Start of form
28 print &ui_form_start("save_group.cgi", "post");
29 print &ui_hidden("old", $n) if ($n ne "");
30 print &ui_table_start($text{'gedit_details'}, "width=100%", 2, [ "width=30%" ]);
31
32 # Group name
33 print &ui_table_row(&hlink($text{'gedit_group'}, "ggroup"),
34         $n eq "" ? &ui_textbox("group", undef, 20)
35                  : "<tt>".&html_escape($group{'group'})."</tt>");
36
37 # Group ID
38 if ($n ne "") {
39         # Existing group, just show field to edit
40         $gidfield = &ui_textbox("gid", $group{'gid'}, 10);
41         }
42 else {
43         # Work out which GID modes are available
44         @gidmodes = ( );
45         $defgid = &allocate_gid(\%gused);
46         if ($access{'autogid'}) {
47                 push(@gidmodes, [ 1, $text{'gedit_gid_def'} ]);
48                 }
49         if ($access{'calcgid'}) {
50                 push(@gidmodes, [ 2, $text{'gedit_gid_calc'} ]);
51                 }
52         if ($access{'usergid'}) {
53                 push(@gidmodes, [ 0, &ui_textbox("gid", $defgid, 10) ]);
54                 }
55         if (@gidmodes == 1) {
56                 $gidfield = &ui_hidden("gid_def", $gidmodes[0]->[0]).
57                             $gidmodes[0]->[1];
58                 }
59         else {
60                 $gidfield = &ui_radio("gid_def", $config{'gid_mode'},
61                                       \@gidmodes);
62                 }
63         }
64 print &ui_table_row(&hlink($text{'gedit_gid'}, "ggid"), $gidfield);
65
66 # Group password (rarely used, but..)
67 print &ui_table_row(&hlink($text{'pass'}, "gpasswd"),
68         &ui_radio_table("passmode", $group{'pass'} eq "" ? 0 : 1,
69                 [ [ 0, $text{'none2'} ],
70                   [ 1, $text{'encrypted'},
71                        &ui_textbox("encpass", $group{'pass'}, 20) ],
72                   [ 2, $text{'clear'},
73                        &ui_textbox("pass", undef, 15) ] ]));
74
75 # Member chooser
76 @ulist = &sort_users(\@ulist, $config{'sort_mode'});
77 if ($config{'membox'} == 0) {
78         # Nicer left/right chooser
79         print &ui_table_row(&hlink($text{'gedit_members'}, "gmembers"),
80                 &ui_multi_select("members",
81                         [ map { [ $_, $_ ] }
82                               sort { lc($a) cmp lc($b) }
83                                    split(/,/ , &html_escape($group{'members'})) ],
84                         [ map { [ $_->{'user'}, &html_escape($_->{'user'}) ] } @ulist ],
85                         10, 1, 0,
86                         $text{'gedit_allu'}, $text{'gedit_selu'}, 150));
87         }
88 else {
89         # Text box
90         print &ui_table_row(&hlink($text{'gedit_members'}, "gmembers"),
91                 &ui_textarea("members",
92                              join("\n", split(/,/ , $group{'members'})),
93                              5, 30));
94         }
95
96 # Primary members (read-only)
97 if ($n ne "") {
98         @upri = grep { $_->{'gid'} == $group{'gid'} } @ulist;
99         if (@upri) {
100                 @uprilinks = ( );
101                 foreach $u (@upri) {
102                         if (&can_edit_user(\%access, $u)) {
103                                 push(@uprilinks, "<a href='edit_user.cgi?".
104                                   "user=$u->{'user'}'>".&html_escape($u->{'user'})."</a>");
105                                 }
106                         else {
107                                 push(@uprilinks, $u->{'user'});
108                                 }
109                         }
110                 $upri = &ui_links_row(\@uprilinks);
111                 }
112         else {
113                 $upri = $text{'gedit_prinone'};
114                 }
115         print &ui_table_row(&hlink($text{'gedit_pri'}, "gpri"), $upri, 3);
116         }
117
118 print &ui_table_end();
119
120 # Section for on-change and on-create events
121 if ($n ne "") {
122         if ($access{'chgid'} == 1 || $access{'mothers'} == 1) {
123                 print &ui_table_start($text{'onsave'}, "width=100%", 2,
124                                       [ "width=30%" ]);
125
126                 # Change file GIDs on save
127                 if ($access{'chgid'} == 1) {
128                         print &ui_table_row(
129                                 &hlink($text{'chgid'}, "gchgid"),
130                                 &ui_radio("chgid", 0,
131                                   [ [ 0, $text{'no'} ],
132                                     [ 1, $text{'gedit_homedirs'} ],
133                                     [ 2, $text{'gedit_allfiles'} ] ]));
134                         }
135
136                 # Update in other modules?
137                 if ($access{'mothers'} == 1) {
138                         print &ui_table_row(
139                                 &hlink($text{'gedit_mothers'}, "others"),
140                                 &ui_radio("others", $config{'default_other'},
141                                           [ [ 1, $text{'yes'} ],
142                                             [ 0, $text{'no'} ] ]));
143                         }
144
145                 print &ui_table_end();
146                 }
147         }
148 else {
149         if ($access{'cothers'} == 1) {
150                 print &ui_table_start($text{'uedit_oncreate'}, "width=100%", 2,
151                                       [ "width=30%" ]);
152
153                 # Create in other modules?
154                 print &ui_table_row(
155                         &hlink($text{'gedit_cothers'}, "others"),
156                         &ui_radio("others", $config{'default_other'},
157                                   [ [ 1, $text{'yes'} ],
158                                     [ 0, $text{'no'} ] ]));
159
160                 print &ui_table_end();
161                 }
162         }
163
164 # Save/delete/create buttons
165 if ($n ne "") {
166         print &ui_form_end([
167                 [ undef, $text{'save'} ],
168                 $access{'gdelete'} ? ( [ 'delete', $text{'delete'} ] ) : ( ),
169                 ]);
170         }
171 else {
172         print &ui_form_end([ [ undef, $text{'create'} ] ]);
173         }
174
175 &ui_print_footer("index.cgi?mode=groups", $text{'index_return'});
176