-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathsave_admin.cgi
executable file
·112 lines (103 loc) · 2.95 KB
/
save_admin.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
#!/usr/local/bin/perl
# Create, update or delete an extra administrator
require './virtual-server-lib.pl';
&ReadParse();
&licence_status();
$d = &get_domain($in{'dom'});
&can_edit_domain($d) || &error($text{'edit_ecannot'});
&can_edit_admins($d) || &error($text{'admins_ecannot'});
&obtain_lock_webmin() if (!$in{'switch'});
@admins = &list_extra_admins($d);
&require_acl();
if (!$in{'new'}) {
($admin) = grep { $_->{'name'} eq $in{'old'} } @admins;
$admin || &error($text{'admin_egone'});
$oldadmin = { %$admin };
}
else {
$admin = { };
}
if ($in{'switch'}) {
# Special case - switch to this Webmin user
&ui_print_header(&domain_in($d), $text{'admin_title2'}, "");
print &text('admin_switching', "<tt>$in{'old'}</tt>"),"<p>\n";
print "<script>\n";
print "var w = window;\n";
print "while(w.parent && w.parent != w) { w = w.parent; }\n";
print "w.location = \"switch_user.cgi?dom=$in{'dom'}&admin=$in{'old'}\";\n";
print "</script>\n";
&ui_print_footer();
exit;
}
elsif ($in{'delete'}) {
# Just delete him
&delete_extra_admin($admin, $d);
}
else {
# Validate inputs
&error_setup($text{'admin_err'});
$tmpl = &get_template($d->{'template'});
$in{'name'} =~ /^[a-z0-9\.\_\-]+$/i || &error($text{'admin_ename'});
$in{'name'} eq 'webmin' && &error($text{'resel_ewebmin'});
if ($tmpl->{'extra_prefix'} ne "none") {
# Force-prepend prefix
$pfx = &substitute_domain_template($tmpl->{'extra_prefix'}, $d);
if ($in{'new'} || $admin->{'name'} =~ /^\Q$pfx\E(.*)/) {
$admin->{'name'} = $pfx.$in{'name'};
}
elsif (&master_admin()) {
$admin->{'name'} = $in{'name'};
}
}
else {
$admin->{'name'} = $in{'name'};
}
if ($in{'new'} || $in{'name'} ne $in{'old'}) {
($clash) = grep { $_->{'name'} eq $in{'name'} }
&acl::list_users();
$clash && &error($text{'admin_eclash'});
}
if (!$in{'pass_def'}) {
$admin->{'pass'} = $in{'pass'};
}
$admin->{'desc'} = $in{'desc'};
if ($in{'email_def'}) {
delete($admin->{'email'});
}
else {
$in{'email'} =~ /^\S+\@\S+$/ ||
&error($text{'admin_eemail'});
$admin->{'email'} = $in{'email'};
}
# Save edit options
$admin->{'create'} = $in{'create'};
$admin->{'norename'} = $in{'norename'};
$admin->{'features'} = $in{'features'};
$admin->{'modules'} = $in{'modules'};
%sel_edits = map { $_, 1 } split(/\0/, $in{'edit'});
foreach $ed (@edit_limits) {
if ($d->{'edit_'.$ed}) {
$admin->{"edit_".$ed} = $sel_edits{$ed};
}
}
# Save allowed domains
if ($in{'doms_def'}) {
delete($admin->{'doms'});
}
else {
$in{'doms'} || &error($text{'admin_edoms'});
$admin->{'doms'} = join(" ", split(/\0/, $in{'doms'}));
}
# Save or create the admin
if ($in{'new'}) {
&create_extra_admin($admin, $d);
}
else {
&modify_extra_admin($admin, $oldadmin, $d);
}
}
&release_lock_webmin();
&run_post_actions_silently();
&webmin_log($in{'new'} ? "create" : $in{'delete'} ? "delete" : "modify",
"admin", $oldadmin ? $oldadmin->{'name'} : $admin->{'name'});
&redirect("list_admins.cgi?dom=$d->{'id'}");