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