mirror of
https://github.com/webmin/webmin.git
synced 2025-07-23 00:30:33 +00:00
strict and ui-lib conversion
This commit is contained in:
@ -2,7 +2,11 @@
|
||||
# edit_nauth.cgi
|
||||
# Display a list of proxy users
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our (%text, %in, %access, $squid_version, %config, $module_name);
|
||||
require './squid-lib.pl';
|
||||
|
||||
if ($config{'crypt_conf'} == 1) {
|
||||
eval "use MD5";
|
||||
if ($@) {
|
||||
@ -12,31 +16,29 @@ if ($config{'crypt_conf'} == 1) {
|
||||
|
||||
$access{'proxyauth'} || &error($text{'eauth_ecannot'});
|
||||
&ui_print_header(undef, $text{'eauth_header'}, "", undef, 0, 0, 0, &restart_button());
|
||||
$conf = &get_config();
|
||||
$authfile = &get_auth_file($conf);
|
||||
my $conf = &get_config();
|
||||
my $authfile = &get_auth_file($conf);
|
||||
|
||||
print &text('eauth_nmsgaccess', "<tt>$authfile</tt>"),"<p>\n";
|
||||
@users = &list_auth_users($authfile);
|
||||
my @users = &list_auth_users($authfile);
|
||||
if (@users) {
|
||||
print "<a href=\"edit_nuser.cgi?new=1\">$text{'eauth_addpuser'}</a><br>\n";
|
||||
print "<table border width=100%>\n";
|
||||
print "<tr $tb> <td><b>$text{'eauth_pusers'}</b></td> </tr>\n";
|
||||
print "<tr $cb> <td><table width=100%>\n";
|
||||
for($i=0; $i<@users; $i++) {
|
||||
local ($it, $unit) = $users[$i]->{'enabled'} ? ('', '') :
|
||||
print &ui_links_row([ &ui_link("edit_nuser.cgi?new=1",
|
||||
$text{'eauth_addpuser'}) ]);
|
||||
my @grid;
|
||||
for(my $i=0; $i<@users; $i++) {
|
||||
my ($it, $unit) = $users[$i]->{'enabled'} ? ('', '') :
|
||||
('<i>', '</i>');
|
||||
print "<tr>\n" if ($i%4 == 0);
|
||||
print "<td width=25%><a href=\"edit_nuser.cgi?",
|
||||
"index=$i\">$it$users[$i]->{'user'}$unit</a></td>\n";
|
||||
print "</tr>\n" if ($i%4 == 3);
|
||||
push(@grid, &ui_link("edit_nuser.cgi?index=$i",
|
||||
$it.$users[$i]->{'user'}.$unit));
|
||||
}
|
||||
while($i++%4) { print "<td width=25%></td>\n"; }
|
||||
print "</table></td></tr></table>\n";
|
||||
print &ui_grid_table(\@grid, 4, 100, undef, undef,
|
||||
$text{'eauth_pusers'});
|
||||
}
|
||||
else {
|
||||
print "<b>$text{'eauth_nopusers'}</b> <p>\n";
|
||||
}
|
||||
print "<a href=\"edit_nuser.cgi?new=1\">$text{'eauth_addpuser'}</a><p>\n";
|
||||
print &ui_links_row([ &ui_link("edit_nuser.cgi?new=1",
|
||||
$text{'eauth_addpuser'}) ]);
|
||||
|
||||
&ui_print_footer("", $text{'eauth_return'});
|
||||
|
||||
|
@ -2,54 +2,55 @@
|
||||
# edit_user.cgi
|
||||
# A form for adding or editing a squid user
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our (%text, %in, %access, $squid_version, %config);
|
||||
require './squid-lib.pl';
|
||||
$access{'proxyauth'} || &error($text{'eauth_ecannot'});
|
||||
&ReadParse();
|
||||
|
||||
my %user;
|
||||
if ($in{'new'}) {
|
||||
&ui_print_header(undef, $text{'euser_header'}, "");
|
||||
}
|
||||
else {
|
||||
&ui_print_header(undef, $text{'euser_header1'}, "");
|
||||
$conf = &get_config();
|
||||
@users = &list_auth_users(&get_auth_file($conf));
|
||||
my $conf = &get_config();
|
||||
my @users = &list_auth_users(&get_auth_file($conf));
|
||||
%user = %{$users[$in{'index'}]};
|
||||
}
|
||||
|
||||
print "<form action=save_nuser.cgi>\n";
|
||||
print "<input type=hidden name=index value=$in{'index'}>\n";
|
||||
print "<input type=hidden name=new value=$in{'new'}>\n";
|
||||
print "<table border>\n";
|
||||
print "<tr $tb> <td><b>$text{'euser_pud'}</b></td> </tr>\n";
|
||||
print "<tr $cb> <td><table>\n";
|
||||
print &ui_form_start("save_nuser.cgi", "post");
|
||||
print &ui_hidden("index", $in{'index'});
|
||||
print &ui_hidden("new", $in{'new'});
|
||||
print &ui_table_start($text{'euser_pud'}, undef, 2);
|
||||
|
||||
print "<tr> <td><b>$text{'euser_u'}</b></td>\n";
|
||||
print "<td><input name=user size=25 value=\"$user{'user'}\"></td> </tr>\n";
|
||||
# Username
|
||||
print &ui_table_row($text{'euser_u'},
|
||||
&ui_textbox("user", $user{'user'}, 30));
|
||||
|
||||
print "<tr> <td><b>$text{'euser_p'}</b></td> <td>\n";
|
||||
# Password
|
||||
if (%user) {
|
||||
print "<input type=radio name=pass_def value=1 checked> $text{'euser_u1'}\n";
|
||||
print "<input type=radio name=pass_def value=0>\n";
|
||||
print "<input name=pass size=20 type=password></td> </tr>\n";
|
||||
print &ui_table_row($text{'euser_p'},
|
||||
&ui_opt_textbox("pass", undef, 30, $text{'euser_u1'}));
|
||||
}
|
||||
else {
|
||||
print "<input name=pass size=20 type=password></td> </tr>\n";
|
||||
print &ui_table_row($text{'euser_p'},
|
||||
&ui_textbox("pass", undef, 30));
|
||||
}
|
||||
|
||||
print "<tr> <td><b>$text{'euser_e'}</b></td>\n";
|
||||
printf "<td><input type=radio name=enabled value=1 %s> %s\n",
|
||||
$user{'enabled'} || !%user ? 'checked' : '', $text{'yes'};
|
||||
printf "<input type=radio name=enabled value=0 %s> %s</td> </tr>\n",
|
||||
$user{'enabled'} || !%user ? '' : 'checked', $text{'no'};
|
||||
# Enabled?
|
||||
print &ui_table_row($text{'euser_e'},
|
||||
&ui_yesno_radio("enabled", $user{'enabled'} || !%user));
|
||||
|
||||
print "</table></td></tr></table>\n";
|
||||
print &ui_table_end();
|
||||
if (%user) {
|
||||
print "<input type=submit value=\"$text{'save'}\">\n";
|
||||
print "<input type=submit name=delete value=\"$text{'delete'}\">\n";
|
||||
print &ui_form_end([ [ undef, $text{'save'} ],
|
||||
[ 'delete', $text{'delete'} ] ]);
|
||||
}
|
||||
else {
|
||||
print "<input type=submit value=\"$text{'create'}\">\n";
|
||||
print &ui_form_end([ [ undef, $text{'create'} ] ]);
|
||||
}
|
||||
print "</form>\n";
|
||||
|
||||
&ui_print_footer("edit_nauth.cgi", $text{'euser_return'},
|
||||
"", $text{'index_return'});
|
||||
|
@ -2,6 +2,9 @@
|
||||
# save_nuser.cgi
|
||||
# Save, create or delete a proxy user
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
our (%text, %in, %access, $squid_version, %config, $module_name);
|
||||
require './squid-lib.pl';
|
||||
if ($config{'crypt_conf'} == 1) {
|
||||
eval "use MD5";
|
||||
@ -12,32 +15,33 @@ if ($config{'crypt_conf'} == 1) {
|
||||
|
||||
$access{'proxyauth'} || &error($text{'eauth_ecannot'});
|
||||
&ReadParse();
|
||||
$conf = &get_config();
|
||||
$file = &get_auth_file($conf);
|
||||
my $conf = &get_config();
|
||||
my $file = &get_auth_file($conf);
|
||||
&lock_file($file);
|
||||
@users = &list_auth_users($file);
|
||||
my @users = &list_auth_users($file);
|
||||
|
||||
$user = $users[$in{'index'}];
|
||||
my $user = $users[$in{'index'}];
|
||||
if ($in{'delete'}) {
|
||||
&replace_file_line($file, $user->{'line'});
|
||||
}
|
||||
else {
|
||||
$whatfailed = $text{'suser_ftsu'};
|
||||
&error_setup($text{'suser_ftsu'});
|
||||
$in{'user'} =~ /^[^:\s]+$/ || &error($text{'suser_emsg1'});
|
||||
local ($same) = grep { $_->{'user'} eq $in{'user'} } @users;
|
||||
local $cmt = $in{'enabled'} ? "" : "#";
|
||||
my ($same) = grep { $_->{'user'} eq $in{'user'} } @users;
|
||||
my $cmt = $in{'enabled'} ? "" : "#";
|
||||
if ($in{'new'}) {
|
||||
!$same || &error($text{'suser_etaken'});
|
||||
$pass = &encryptpwd($in{'pass'}, $salt);
|
||||
&open_tempfile(FILE,">>$file");
|
||||
&print_tempfile(FILE, "$cmt$in{'user'}:$pass\n");
|
||||
&close_tempfile(FILE);
|
||||
my $pass = &encryptpwd($in{'pass'}, undef);
|
||||
my $fh = "FILE";
|
||||
&open_tempfile($fh, ">>$file");
|
||||
&print_tempfile($fh, "$cmt$in{'user'}:$pass\n");
|
||||
&close_tempfile($fh);
|
||||
}
|
||||
else {
|
||||
!$same || $same->{'user'} eq $user->{'user'} ||
|
||||
&error($text{'suser_etaken'});
|
||||
$pass = $in{'pass_def'} ? $user->{'pass'}
|
||||
: &encryptpwd($in{'pass'}, $salt);
|
||||
my $pass = $in{'pass_def'} ? $user->{'pass'}
|
||||
: &encryptpwd($in{'pass'}, undef);
|
||||
&replace_file_line($file, $user->{'line'},
|
||||
"$cmt$in{'user'}:$pass\n");
|
||||
}
|
||||
@ -48,6 +52,7 @@ else {
|
||||
&redirect("edit_nauth.cgi");
|
||||
|
||||
sub encryptpwd {
|
||||
my ($pass, $salt) = @_;
|
||||
if ($config{'crypt_conf'}) {
|
||||
my $pwd = $_[0];
|
||||
my $encryptpwd = new MD5;
|
||||
@ -58,8 +63,8 @@ sub encryptpwd {
|
||||
return $pwd;
|
||||
}
|
||||
else {
|
||||
$salt = substr(time(), -2);
|
||||
my $pwd = &unix_crypt($_[0], $_[1]);
|
||||
$salt ||= substr(time(), -2);
|
||||
my $pwd = &unix_crypt($pass, $salt);
|
||||
return $pwd;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user