#!/usr/bin/perl # save_user.cgi # Modify or create a webmin user use strict; use warnings; no warnings 'redefine'; no warnings 'uninitialized'; require './acl-lib.pl'; our (%in, %text, %config, %access, $config_directory, $base_remote_user); &foreign_require("webmin", "webmin-lib.pl"); &ReadParse(); # Check for special button clicks, and redirect if ($in{'but_clone'}) { &redirect("edit_user.cgi?clone=".&urlize($in{'old'})); exit; } elsif ($in{'but_log'}) { &redirect("../webminlog/search.cgi?uall=0&mall=1&tall=1&user=". &urlize($in{'old'})); exit; } elsif ($in{'but_switch'}) { &redirect("switch.cgi?user=".&urlize($in{'old'})); exit; } elsif ($in{'but_delete'}) { &redirect("delete_user.cgi?user=".&urlize($in{'old'})); exit; } elsif ($in{'twofactor'}) { &redirect("twofactor_form.cgi?user=".&urlize($in{'old'})); exit; } # Get the user object my (%user, $old); if ($in{'old'}) { %user = ( ); $in{'name'} = $in{'old'} if (!$access{'rename'}); &can_edit_user($in{'old'}) || &error($text{'save_euser'}); $old = &get_user($in{'old'}); $old || &error($text{'edit_egone'}); $user{'proto'} = $old->{'proto'}; $user{'id'} = $old->{'id'}; $user{'twofactor_provider'} = $old->{'twofactor_provider'}; $user{'twofactor_id'} = $old->{'twofactor_id'}; } else { $access{'create'} || &error($text{'save_ecreate'}); } &error_setup($text{'save_err'}); # Validate username, and check for a clash $in{'name'} =~ /^[A-z0-9\-\_\.\@]+$/ && $in{'name'} !~ /^\@/ || &error(&text('save_ename', &html_escape($in{'name'}))); $in{'name'} eq 'webmin' && &error($text{'save_enamewebmin'}); if (!$in{'old'} || $in{'old'} ne $in{'name'}) { my $clash = &get_user($in{'name'}); $clash && &error(&text('save_edup', &html_escape($in{'name'}))); } !$access{'logouttime'} || $in{'logouttime_def'} || $in{'logouttime'} =~ /^\d+$/ || &error($text{'save_elogouttime'}); !$access{'minsize'} || $in{'minsize_def'} || $in{'minsize'} =~ /^\d+$/ || &error($text{'save_eminsize'}); if ($in{'safe'} && !$in{'unsafe'}) { getpwnam($in{'name'}) || &error(&text('save_eunixname', &html_escape($in{'name'}))); } # Validate password if ($in{'pass_def'} == 0) { $in{'pass'} =~ /:/ && &error($text{'save_ecolon'}); if (!$in{'temp'}) { # Check password quality, unless this is a temp password my $perr = &check_password_restrictions($in{'name'}, $in{'pass'}); $perr && &error(&text('save_epass', $perr)); } } # Validate force change if ($in{'temp'}) { my %miniserv; &get_miniserv_config(\%miniserv); $miniserv{'passwd_mode'} == 2 || &error(&text('save_etemp', '../webmin/edit_session.cgi')); } # Find logged-in webmin user my @ulist = &list_users(); my $me; foreach my $u (@ulist) { if ($u->{'name'} eq $base_remote_user) { $me = $u; } } # Find the current group my $oldgroup = $in{'old'} ? &get_users_group($in{'old'}) : undef; if (&supports_rbac()) { # Save RBAC mode $user{'rbacdeny'} = $in{'rbacdeny'}; } my $newgroup; if (defined($in{'group'})) { # Check if group is allowed if ($access{'gassign'} ne '*') { my @gcan = split(/\s+/, $access{'gassign'}); $in{'group'} && &indexof($in{'group'}, @gcan) >= 0 || !$in{'group'} && &indexof('_none', @gcan) >= 0 || $oldgroup && $oldgroup->{'name'} eq $in{'group'} || &error($text{'save_egroup'}); } # Store group membership $newgroup = &get_group($in{'group'}); if ($in{'group'} ne ($oldgroup ? $oldgroup->{'name'} : '')) { # Group has changed - update the member lists if ($oldgroup) { # Take out of old $oldgroup->{'members'} = [ grep { $_ ne $in{'old'} } @{$oldgroup->{'members'}} ]; &modify_group($oldgroup->{'name'}, $oldgroup); } if ($newgroup) { # Put into new push(@{$newgroup->{'members'}}, $in{'name'}); &modify_group($in{'group'}, $newgroup); } } elsif ($in{'old'} ne $in{'name'} && $oldgroup && $newgroup) { # Name has changed - rename in group my $idx = &indexof( $in{'old'}, @{$oldgroup->{'members'}}); $oldgroup->{'members'}->[$idx] = $in{'name'}; &modify_group($oldgroup->{'name'}, $oldgroup); } } # Store manually selected modules my @mcan = $access{'mode'} == 1 ? @{$me->{'modules'}} : $access{'mode'} == 2 ? split(/\s+/, $access{'mods'}) : &list_modules(); my %mcan = map { $_, 1 } @mcan; my @mods = split(/\0/, $in{'mod'}); foreach my $m (@mods) { $mcan{$m} || &error(&text('save_emod', $m)); } if ($in{'old'}) { # Add modules that this user already has, but were not # allowed to be changed or are not available for this OS foreach my $m (@{$old->{'modules'}}) { push(@mods, $m) if (!$mcan{$m}); } } if ($oldgroup) { # Remove modules from the old group @mods = grep { &indexof($_, @{$oldgroup->{'modules'}}) < 0 } @mods; } if ($base_remote_user eq $in{'old'} && &indexof("acl", @mods) == -1 && (!$newgroup || &indexof("acl", @{$newgroup->{'modules'}}) == -1)) { &error($text{'save_edeny'}); } if (!$in{'old'} && $access{'perms'}) { # Copy .acl files from creator to new user ©_acl_files($me->{'name'}, $in{'name'}, $me->{'modules'}); } if ($newgroup) { # Add modules from group to list my @ownmods; foreach my $m (@mods) { push(@ownmods, $m) if (&indexof($m, @{$newgroup->{'modules'}}) < 0); } @mods = &unique(@mods, @{$newgroup->{'modules'}}); $user{'ownmods'} = \@ownmods; # Copy ACL files for group my $name = $in{'old'} ? $in{'old'} : $in{'name'}; ©_group_user_acl_files($in{'group'}, $name, [ @{$newgroup->{'modules'}}, "" ]); } $user{'modules'} = \@mods; # Update user object my $salt = chr(int(rand(26))+65).chr(int(rand(26))+65); $user{'name'} = $in{'name'}; $user{'lang'} = !$access{'lang'} ? $old->{'lang'} : $in{'lang_def'} ? undef : $in{'lang'}; $user{'locale'} = !$access{'locale'} ? $old->{'locale'} : $in{'locale_def'} ? undef : $in{'locale'}; if (!$access{'theme'}) { $user{'theme'} = $old->{'theme'}; $user{'overlay'} = $old->{'overlay'}; } else { $user{'theme'} = $in{'theme_def'} ? undef : $in{'theme'}; $user{'overlay'} = $in{'overlay_def'} ? undef : $in{'overlay'}; if ($user{'overlay'} && !$user{'theme'}) { &error($text{'save_eoverlay'}); } } $user{'cert'} = !$access{'chcert'} ? $old->{'cert'} : $in{'cert_def'} ? undef : $in{'cert'}; $user{'notabs'} = !$access{'cats'} ? $old->{'notabs'} : $in{'notabs'}; $user{'logouttime'} = !$access{'logouttime'} ? $old->{'logouttime'} : $in{'logouttime_def'} ? undef : $in{'logouttime'}; $user{'minsize'} = !$access{'minsize'} ? $old->{'minsize'} : $in{'minsize_def'} ? undef : $in{'minsize'}; $user{'nochange'} = !$access{'nochange'} || !defined($in{'nochange'}) ? $old->{'nochange'} : $in{'nochange'}; $user{'lastchange'} = $old->{'lastchange'}; $user{'olds'} = $old->{'olds'}; $user{'real'} = $in{'real'} =~ /\S/ ? $in{'real'} : undef; my $raddr = $ENV{'REMOTE_ADDR'}; my @ips; if ($access{'ips'}) { if ($in{'ipmode'}) { my @hosts = split(/\s+/, $in{"ips"}); @hosts || &error($text{'save_enone'}); foreach my $h (@hosts) { my $err = &webmin::valid_allow($h); &error($err) if ($err); push(@ips, $h); } } if ($in{'ipmode'} == 1) { $user{'allow'} = join(" ", @ips); if ($old->{'name'} eq $base_remote_user && !&webmin::ip_match($raddr, @ips)) { &error(&text('save_eself', $raddr)); } } elsif ($in{'ipmode'} == 2) { $user{'deny'} = join(" ", @ips); if ($old->{'name'} eq $base_remote_user && &webmin::ip_match($raddr, @ips)) { &error(&text('save_eself', $raddr)); } } } else { $user{'allow'} = $old->{'allow'}; $user{'deny'} = $old->{'deny'}; } if ($in{'pass_def'} == 0) { # New password $user{'pass'} = &encrypt_password($in{'pass'}); $user{'sync'} = 0; } elsif ($in{'pass_def'} == 1) { # No change in password $user{'pass'} = $in{'oldpass'}; $user{'sync'} = 0; } elsif ($in{'pass_def'} == 3) { # Unix authentication $user{'pass'} = 'x'; $user{'sync'} = 0; } elsif ($in{'pass_def'} == 4) { # Account is locked $user{'pass'} = '*LK*'; $user{'sync'} = 0; } elsif ($in{'pass_def'} == 5) { # External authentcation $user{'pass'} = 'e'; $user{'sync'} = 0; } else { # Password synchronization (deprecated) &foreign_check("useradmin") || &error($text{'save_eos'}); &foreign_require("useradmin", "user-lib.pl"); foreach my $uu (&useradmin::list_users()) { $user{'pass'} = $uu->{'pass'} if ($uu->{'user'} eq $in{'name'}); } defined($user{'pass'}) || &error(&text('save_eunix', $in{'name'})); $user{'sync'} = 1; } # Update allowed days and hours if ($access{'times'}) { # Save the allowed days if (!$in{'days_def'}) { my @days = split(/\0/, $in{'days'}); @days || &error($text{'save_edays'}); $user{'days'} = join(",", @days); } if (!$in{'hours_def'}) { my %mins; foreach my $t ('from', 'to') { my $h = $in{'hours_h'.$t}; my $m = $in{'hours_m'.$t}; $h =~ /^\d+$/ && $h >= 0 && $h < 24 || &error($text{'save_ehours'}); $m =~ /^\d+$/ && $m >= 0 && $m < 60 || &error($text{'save_ehours'}); $user{'hours'.$t} = "$h.$m"; $mins{$t} = $h*60+$m; } $mins{'from'} < $mins{'to'} || &error($text{'save_ehours2'}); } } else { $user{'days'} = $old->{'days'}; $user{'hoursfrom'} = $old->{'hoursfrom'}; $user{'hoursto'} = $old->{'hoursto'}; } # Check for temporary password lock if (!$in{'lock'} && $user{'pass'} =~ /^\!(.*)$/) { $user{'pass'} = $1; } elsif ($in{'lock'} && $user{'pass'} !~ /^\!/ && $in{'pass_def'} <= 1) { $user{'pass'} = "!".$user{'pass'}; } # Check for force change $user{'temppass'} = $in{'temp'}; # Cancel two-factor if requested if ($in{'cancel'}) { $user{'twofactor_provider'} = undef; $user{'twofactor_id'} = undef; $user{'twofactor_apikey'} = undef; } if ($in{'old'}) { # update user and all ACLs &modify_user($in{'old'}, \%user); if ($in{'old'} ne $user{'name'}) { # Change username in other user's ACLs foreach my $u (&list_users()) { my %uaccess = &get_module_acl($u->{'name'}); my @au = split(/\s+/, $uaccess{'users'}); my $idx = &indexof($in{'old'}, @au); if ($idx != -1) { $au[$idx] = $in{'name'}; $uaccess{'users'} = join(" ", @au); &save_module_acl(\%uaccess, $u->{'name'}); } } } } else { # create and add to access list &create_user(\%user, $in{'clone'}); if ($access{'users'} ne '*') { $access{'users'} .= " ".$in{'name'}; &save_module_acl(\%access); } } my $aclfile = "$config_directory/$in{'name'}.acl"; if ($in{'old'} && $in{'acl_security_form'} && !$newgroup && !$in{'safe'}) { # Update user's global ACL &foreign_require("", "acl_security.pl"); my %uaccess; &foreign_call("", "acl_security_save", \%uaccess, \%in); &lock_file($aclfile); &save_module_acl(\%uaccess, $in{'name'}, "", 1); &set_ownership_permissions(undef, undef, 0640, $aclfile); &unlock_file($aclfile); } # Clear safe setting if ($in{'unsafe'}) { &lock_file($aclfile); my %uaccess = &get_module_acl($in{'name'}, "", 1, 1); delete($uaccess{'_safe'}); &save_module_acl(\%uaccess, $in{'name'}, "", 1); &unlock_file($aclfile); } # If the user is in safe mode, set ACLs on all new modules if ($in{'safe'}) { foreach my $m ("", @mods) { my %macl = &get_module_acl($in{'name'}, $m, 0, 1); my $safe = &get_safe_acl($m); if (!%macl && $safe) { %macl = %$safe; $macl{'_safe'} = 1; $macl{'noconfig'} = 1; &save_module_acl(\%macl, $in{'name'}, $m); } } } # Log the event delete($in{'pass'}); delete($in{'oldpass'}); if ($in{'old'}) { &webmin_log("modify", "user", $in{'old'}, \%in); } else { &webmin_log("create", "user", $user{'name'}, \%in); } &reload_miniserv(); &redirect("index.cgi?refresh=1");
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
help | Folder | 0755 |
|
|
images | Folder | 0755 |
|
|
lang | Folder | 0755 |
|
|
CHANGELOG | File | 5.15 KB | 0644 |
|
acl-lib.pl | File | 62.4 KB | 0755 |
|
acl_security.pl | File | 2.33 KB | 0755 |
|
backup_config.pl | File | 2.64 KB | 0755 |
|
cert_form.cgi | File | 1.48 KB | 0755 |
|
cert_issue.cgi | File | 1.69 KB | 0755 |
|
cert_output.cgi | File | 445 B | 0755 |
|
cgi_args.pl | File | 767 B | 0755 |
|
config | File | 61 B | 0644 |
|
config-ALL-linux | File | 42 B | 0644 |
|
config-freebsd | File | 42 B | 0644 |
|
config-macos | File | 42 B | 0644 |
|
config-netbsd | File | 42 B | 0644 |
|
config-openbsd | File | 42 B | 0644 |
|
config-solaris-10-ALL | File | 46 B | 0644 |
|
config-syno-linux | File | 51 B | 0644 |
|
config.info | File | 258 B | 0644 |
|
config.info.ar | File | 385 B | 0644 |
|
config.info.bg | File | 397 B | 0644 |
|
config.info.ca | File | 295 B | 0644 |
|
config.info.cs | File | 265 B | 0644 |
|
config.info.da | File | 259 B | 0644 |
|
config.info.de | File | 273 B | 0644 |
|
config.info.es | File | 265 B | 0644 |
|
config.info.eu | File | 298 B | 0644 |
|
config.info.fa | File | 394 B | 0644 |
|
config.info.fr | File | 308 B | 0644 |
|
config.info.hr | File | 0 B | 0644 |
|
config.info.hu | File | 353 B | 0644 |
|
config.info.it | File | 279 B | 0644 |
|
config.info.ja | File | 319 B | 0644 |
|
config.info.ko | File | 233 B | 0644 |
|
config.info.ms | File | 248 B | 0644 |
|
config.info.nl | File | 268 B | 0644 |
|
config.info.no | File | 260 B | 0644 |
|
config.info.pl | File | 270 B | 0644 |
|
config.info.pt_BR | File | 271 B | 0644 |
|
config.info.ru | File | 439 B | 0644 |
|
config.info.sk | File | 278 B | 0644 |
|
config.info.sv | File | 53 B | 0644 |
|
config.info.tr | File | 309 B | 0644 |
|
config.info.uk | File | 303 B | 0644 |
|
config.info.zh | File | 47 B | 0644 |
|
config.info.zh_TW | File | 146 B | 0644 |
|
convert.cgi | File | 3.79 KB | 0755 |
|
convert_form.cgi | File | 1.6 KB | 0755 |
|
defaultacl | File | 239 B | 0644 |
|
delete_group.cgi | File | 1.36 KB | 0755 |
|
delete_groups.cgi | File | 1.45 KB | 0755 |
|
delete_session.cgi | File | 485 B | 0755 |
|
delete_user.cgi | File | 668 B | 0755 |
|
delete_users.cgi | File | 2.93 KB | 0755 |
|
edit_acl.cgi | File | 2.75 KB | 0755 |
|
edit_group.cgi | File | 4.38 KB | 0755 |
|
edit_pass.cgi | File | 1.82 KB | 0755 |
|
edit_rbac.cgi | File | 951 B | 0755 |
|
edit_sql.cgi | File | 3.78 KB | 0755 |
|
edit_sync.cgi | File | 1.22 KB | 0755 |
|
edit_unix.cgi | File | 2.76 KB | 0755 |
|
edit_user.cgi | File | 14.2 KB | 0755 |
|
feedback_files.pl | File | 336 B | 0755 |
|
index.cgi | File | 8.29 KB | 0755 |
|
list_sessions.cgi | File | 2.39 KB | 0755 |
|
log_parser.pl | File | 1.78 KB | 0755 |
|
makedn.cgi | File | 1.75 KB | 0755 |
|
maketables.cgi | File | 1.23 KB | 0755 |
|
md5-lib.pl | File | 7.58 KB | 0755 |
|
module.info | File | 187 B | 0644 |
|
module.info.af | File | 0 B | 0644 |
|
module.info.af.auto | File | 139 B | 0644 |
|
module.info.ar | File | 193 B | 0644 |
|
module.info.ar.auto | File | 19 B | 0644 |
|
module.info.be | File | 0 B | 0644 |
|
module.info.be.auto | File | 271 B | 0644 |
|
module.info.bg | File | 43 B | 0644 |
|
module.info.bg.auto | File | 192 B | 0644 |
|
module.info.ca | File | 129 B | 0644 |
|
module.info.ca.auto | File | 19 B | 0644 |
|
module.info.cs | File | 28 B | 0644 |
|
module.info.cs.auto | File | 116 B | 0644 |
|
module.info.da | File | 23 B | 0644 |
|
module.info.da.auto | File | 115 B | 0644 |
|
module.info.de | File | 146 B | 0644 |
|
module.info.de.auto | File | 19 B | 0644 |
|
module.info.el | File | 0 B | 0644 |
|
module.info.el.auto | File | 253 B | 0644 |
|
module.info.es | File | 125 B | 0644 |
|
module.info.es.auto | File | 24 B | 0644 |
|
module.info.eu | File | 0 B | 0644 |
|
module.info.eu.auto | File | 159 B | 0644 |
|
module.info.fa | File | 0 B | 0644 |
|
module.info.fa.auto | File | 238 B | 0644 |
|
module.info.fi | File | 0 B | 0644 |
|
module.info.fi.auto | File | 150 B | 0644 |
|
module.info.fr | File | 28 B | 0644 |
|
module.info.fr.auto | File | 154 B | 0644 |
|
module.info.he | File | 0 B | 0644 |
|
module.info.he.auto | File | 193 B | 0644 |
|
module.info.hr | File | 0 B | 0644 |
|
module.info.hr.auto | File | 147 B | 0644 |
|
module.info.hu | File | 30 B | 0644 |
|
module.info.hu.auto | File | 152 B | 0644 |
|
module.info.it | File | 22 B | 0644 |
|
module.info.it.auto | File | 123 B | 0644 |
|
module.info.ja | File | 25 B | 0644 |
|
module.info.ja.auto | File | 137 B | 0644 |
|
module.info.ko | File | 25 B | 0644 |
|
module.info.ko.auto | File | 128 B | 0644 |
|
module.info.lt | File | 0 B | 0644 |
|
module.info.lt.auto | File | 182 B | 0644 |
|
module.info.lv | File | 0 B | 0644 |
|
module.info.lv.auto | File | 177 B | 0644 |
|
module.info.ms | File | 120 B | 0644 |
|
module.info.ms.auto | File | 19 B | 0644 |
|
module.info.mt | File | 0 B | 0644 |
|
module.info.mt.auto | File | 166 B | 0644 |
|
module.info.nl | File | 26 B | 0644 |
|
module.info.nl.auto | File | 119 B | 0644 |
|
module.info.no | File | 23 B | 0644 |
|
module.info.no.auto | File | 113 B | 0644 |
|
module.info.pl | File | 133 B | 0644 |
|
module.info.pl.auto | File | 19 B | 0644 |
|
module.info.pt | File | 31 B | 0644 |
|
module.info.pt.auto | File | 126 B | 0644 |
|
module.info.pt_BR | File | 31 B | 0644 |
|
module.info.pt_BR.auto | File | 132 B | 0644 |
|
module.info.ro | File | 0 B | 0644 |
|
module.info.ro.auto | File | 156 B | 0644 |
|
module.info.ru | File | 40 B | 0644 |
|
module.info.ru.auto | File | 190 B | 0644 |
|
module.info.sk | File | 29 B | 0644 |
|
module.info.sk.auto | File | 129 B | 0644 |
|
module.info.sl | File | 0 B | 0644 |
|
module.info.sl.auto | File | 156 B | 0644 |
|
module.info.sv | File | 26 B | 0644 |
|
module.info.sv.auto | File | 122 B | 0644 |
|
module.info.th | File | 0 B | 0644 |
|
module.info.th.auto | File | 248 B | 0644 |
|
module.info.tr | File | 32 B | 0644 |
|
module.info.tr.auto | File | 152 B | 0644 |
|
module.info.uk | File | 0 B | 0644 |
|
module.info.uk.auto | File | 246 B | 0644 |
|
module.info.ur | File | 0 B | 0644 |
|
module.info.ur.auto | File | 240 B | 0644 |
|
module.info.vi | File | 0 B | 0644 |
|
module.info.vi.auto | File | 183 B | 0644 |
|
module.info.zh | File | 28 B | 0644 |
|
module.info.zh.auto | File | 106 B | 0644 |
|
module.info.zh_TW | File | 28 B | 0644 |
|
module.info.zh_TW.auto | File | 112 B | 0644 |
|
negativeacl | File | 13 B | 0644 |
|
openssl.cnf | File | 6.02 KB | 0644 |
|
postinstall.pl | File | 996 B | 0755 |
|
prefs.info | File | 22 B | 0644 |
|
save_acl.cgi | File | 2.85 KB | 0755 |
|
save_group.cgi | File | 3.76 KB | 0755 |
|
save_pass.cgi | File | 1.72 KB | 0755 |
|
save_sql.cgi | File | 3.38 KB | 0755 |
|
save_sync.cgi | File | 730 B | 0755 |
|
save_twofactor.cgi | File | 2.25 KB | 0755 |
|
save_unix.cgi | File | 2.2 KB | 0755 |
|
save_user.cgi | File | 11.32 KB | 0755 |
|
schema.cgi | File | 612 B | 0755 |
|
switch.cgi | File | 726 B | 0755 |
|
system_info.pl | File | 2.27 KB | 0644 |
|
twofactor.pl | File | 709 B | 0755 |
|
twofactor_form.cgi | File | 2.01 KB | 0755 |
|
useradmin_update.pl | File | 3.12 KB | 0755 |
|
webmin.schema | File | 1.34 KB | 0644 |
|