-
Notifications
You must be signed in to change notification settings - Fork 3
/
save_user.cgi
58 lines (50 loc) · 1.42 KB
/
save_user.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
#!/usr/bin/perl
# Create, update or delete a user
use strict;
use warnings;
require 'virtualmin-nginx-lib.pl';
&foreign_require("htaccess-htpasswd");
our (%text, %in, %access);
&ReadParse();
&error_setup($text{'user_err'});
$in{'file'} || &error($text{'users_efile'});
# Get the user being edited
&lock_file($in{'file'});
&switch_write_user(1);
my $users = &htaccess_htpasswd::list_users($in{'file'});
my $user;
if (!$in{'new'}) {
($user) = grep { $_->{'user'} eq $in{'old'} } @$users;
$user || &error($text{'user_egone'});
}
else {
$user = { };
}
if ($in{'delete'}) {
# Just delete him
&htaccess_htpasswd::delete_user($user);
}
else {
# Validate inputs
$in{'htuser'} || &error($htaccess_htpasswd::text{'save_euser1'});
$in{'htuser'} =~ /:/ && &error($htaccess_htpasswd::text{'save_euser2'});
$user->{'user'} = $in{'htuser'};
if (!$in{'htpass_def'}) {
$user->{'pass'} = &htaccess_htpasswd::encrypt_password(
$in{'htpass'});
}
$user->{'enabled'} = $in{'enabled'};
# Create or update user
if ($in{'new'}) {
&htaccess_htpasswd::create_user($user, $in{'file'});
}
else {
&htaccess_htpasswd::modify_user($user);
}
}
&switch_write_user(0);
&unlock_file($in{'file'});
&webmin_log($in{'new'} ? "create" : $in{'delete'} ? "delete" : "modify",
"user", $user->{'user'}, { 'file' => $in{'file'} });
&redirect("list_users.cgi?file=".&urlize($in{'file'}).
"&id=".&urlize($in{'id'})."&path=".&urlize($in{'path'}));