forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_chooser.cgi
executable file
·206 lines (201 loc) · 7.3 KB
/
user_chooser.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/local/bin/perl
# user_chooser.cgi
# This CGI generated the HTML for choosing a user or list of users.
$trust_unknown_referers = 1;
BEGIN { push(@INC, ".."); };
use WebminCore;
&init_config();
if (&get_product_name() eq 'usermin') {
&switch_to_remote_user();
}
&ReadParse(undef, undef, 2);
%access = &get_module_acl();
if ($in{'multi'}) {
# selecting multiple users.
if ($in{'frame'} == 0) {
# base frame
&PrintHeader();
print "<script type='text/javascript'>\n";
@ul = &split_quoted_string(/\s+/, &filter_javascript($in{'user'}));
$len = @ul;
print "sel = new Array($len);\n";
print "selr = new Array($len);\n";
for($i=0; $i<$len; $i++) {
print "sel[$i] = \"".
"e_javascript($ul[$i])."\";\n";
# samba valid system user can start with @ + &
$gn = $ul[$i];
$gn =~ s/^(@|\+|&)+//g;
@uinfo = getpwnam($gn);
if (@uinfo) {
print "selr[$i] = \"".
"e_javascript($uinfo[6])."\";\n";
}
else {
print "selr[$i] = \"???\";\n";
}
}
print "</script>\n";
print "<title>$text{'users_title1'}</title>\n";
print "<frameset cols='50%,50%'>\n";
print "<frame src=\"$gconfig{'webprefix'}/user_chooser.cgi?frame=1&multi=1\">\n";
print "<frameset rows='*,50' frameborder=no>\n";
print " <frame src=\"$gconfig{'webprefix'}/user_chooser.cgi?frame=2&multi=1\">\n";
print " <frame src=\"$gconfig{'webprefix'}/user_chooser.cgi?frame=3&multi=1\" scrolling=no>\n";
print "</frameset>\n";
print "</frameset>\n";
}
elsif ($in{'frame'} == 1) {
# list of all users to choose from
&popup_header();
print "<script type='text/javascript'>\n";
print "function adduser(u, r)\n";
print "{\n";
print "top.sel[top.sel.length] = u\n";
print "top.selr[top.selr.length] = r\n";
print "top.frames[1].location = top.frames[1].location\n";
print "return false;\n";
print "}\n";
print "</script>\n";
print "<div id='filter_box' style='display:none;margin:0px;padding:0px;width:100%;clear:both;'>";
print &ui_textbox("filter",$text{'ui_filterbox'}, 50, 0, undef,"style='width:100%;color:#aaa;' onkeyup=\"filter_match(this.value);\" onfocus=\"if (this.value == '".$text{'ui_filterbox'}."') {this.value = '';this.style.color='#000';}\" onblur=\"if (this.value == '') {this.value = '".$text{'ui_filterbox'}."';this.style.color='#aaa';}\"");
print &ui_hr("style='width:100%;'")."</div>";
print "<font size=+1>$text{'users_all'}</font>\n";
print "<table width=100%>\n";
my $cnt = 0;
foreach $u (&get_users_list()) {
if ($in{'user'} eq $u->[0]) { print "<tr class='filter_match' $cb>\n"; }
else { print "<tr class='filter_match'>\n"; }
$u->[6] =~ s/'/'/g;
$u->[0] =~ s/\\/\\\\/g;
print "<td width=20%><a href=\"\" onClick='return adduser(\"$u->[0]\", \"$u->[6]\")'>$u->[0]</a></td>\n";
print "<td>",&html_escape($u->[6]),"</td> </tr>\n";
$cnt++;
}
print "</table>\n";
if ( $cnt >= 10 ) {
print "<script type='text/javascript' src='$gconfig{'webprefix'}/unauthenticated/filter_match.js?28112013'></script>";
print "<script type='text/javascript'>filter_match_box();</script>";
}
&popup_footer();
}
elsif ($in{'frame'} == 2) {
# show chosen users
&popup_header();
print "<font size=+1>$text{'users_sel'}</font>\n";
print <<'EOF';
<table width=100%>
<script type='text/javascript'>
function sub(j)
{
sel2 = new Array(); selr2 = new Array();
for(k=0,l=0; k<top.sel.length; k++) {
if (k != j) {
sel2[l] = top.sel[k];
selr2[l] = top.selr[k];
l++;
}
}
top.sel = sel2; top.selr = selr2;
top.frames[1].location = top.frames[1].location;
return false;
}
function html_escape(s)
{
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
}
for(i=0; i<top.sel.length; i++) {
document.write("<tr>\n");
document.write("<td><a href=\"\" onClick='return sub("+i+")'>"+html_escape(top.sel[i])+"</a></td>\n");
document.write("<td>"+html_escape(top.selr[i])+"</td>\n");
}
</script>
</table>
EOF
&popup_footer();
}
elsif ($in{'frame'} == 3) {
# output OK and Cancel buttons
&popup_header();
print "<script type='text/javascript'>\n";
print "function qjoin(l)\n";
print "{\n";
print "rv = \"\";\n";
print "for(i=0; i<l.length; i++) {\n";
print " if (rv != '') rv += ' ';\n";
print " if (l[i].indexOf(' ') < 0) rv += l[i];\n";
print " else rv += '\"'+l[i]+'\"'\n";
print " }\n";
print "return rv;\n";
print "}\n";
print "</script>\n";
print "<form>\n";
print "<input type=button value=\"$text{'users_ok'}\" ",
"onClick='top.opener.ifield.value = qjoin(top.sel); ",
"top.close()'>\n";
print "<input type=button value=\"$text{'users_cancel'}\" ",
"onClick='top.close()'>\n";
print " <input type=button value=\"$text{'users_clear'}\" onClick='top.sel = new Array(); top.selr = new Array(); top.frames[1].location = top.frames[1].location'>\n";
print "</form>\n";
&popup_footer();
}
}
else {
# selecting just one user .. display a list of all users to choose from
&popup_header($text{'users_title2'});
print "<script type='text/javascript'>\n";
print "function select(f)\n";
print "{\n";
print "top.opener.ifield.value = f;\n";
print "top.close();\n";
print "return false;\n";
print "}\n";
print "</script>\n";
print "<div id='filter_box' style='display:none;margin:0px;padding:0px;width:100%;clear:both;'>";
print &ui_textbox("filter",$text{'ui_filterbox'}, 50, 0, undef,"style='width:100%;color:#aaa;' onkeyup=\"filter_match(this.value);\" onfocus=\"if (this.value == '".$text{'ui_filterbox'}."') {this.value = '';this.style.color='#000'}\" onblur=\"if (this.value == '') {this.value = '".$text{'ui_filterbox'}."';this.style.color='#aaa';}\"");
print &ui_hr("style='width:100%;'")."</div>";
print "<table width=100%>\n";
my $cnt = 0;
foreach $u (&get_users_list()) {
if ($in{'user'} eq $u->[0]) { print "<tr class='filter_match' $cb>\n"; }
else { print "<tr class='filter_match'>\n"; }
print "<td width=20%><a href=\"\" onClick='return select(\"$u->[0]\")'>$u->[0]</a></td>\n";
print "<td>$u->[6]</td> </tr>\n";
$cnt++;
}
print "</table>\n";
if ( $cnt >= 10 ) {
print "<script type='text/javascript' src='$gconfig{'webprefix'}/unauthenticated/filter_match.js?28112013'></script>";
print "<script type='text/javascript'>filter_match_box();</script>";
}
&popup_footer();
}
sub get_users_list
{
local(@uinfo, @users, %ucan, %found);
if ($access{'uedit_mode'} == 2 || $access{'uedit_mode'} == 3) {
map { $ucan{$_}++ } split(/\s+/, $access{'uedit'});
}
setpwent();
local %doneu;
while(@uinfo = getpwent()) {
next if ($doneu{$uinfo[0]}++);
if ($access{'uedit_mode'} == 5 && $access{'uedit'} !~ /^\d+$/) {
# Get group for matching by group name
@ginfo = getgrgid($uinfo[3]);
}
if ($access{'uedit_mode'} == 0 ||
$access{'uedit_mode'} == 2 && $ucan{$uinfo[0]} ||
$access{'uedit_mode'} == 3 && !$ucan{$uinfo[0]} ||
$access{'uedit_mode'} == 4 &&
(!$access{'uedit'} || $uinfo[2] >= $access{'uedit'}) &&
(!$access{'uedit2'} || $uinfo[2] <= $access{'uedit2'}) ||
$access{'uedit_mode'} == 5 &&
($access{'uedit'} =~ /^\d+$/ && $uinfo[3] == $access{'uedit'} ||
$ginfo[0] eq $access{'uedit'})) {
push(@users, [ @uinfo ]) if (!$found{$uinfo[0]}++);
}
}
endpwent() if ($gconfig{'os_type'} ne 'hpux');
return sort { $a->[0] cmp $b->[0] } @users;
}