Make conversion scripts perl strict compliant

This commit is contained in:
Jamie Cameron
2013-12-16 16:20:24 -08:00
parent 8b5da8ca75
commit dbcd7467f9
2 changed files with 28 additions and 15 deletions

View File

@@ -2,15 +2,19 @@
# convert.cgi
# Convert unix to webmin users
use strict;
use warnings;
require './acl-lib.pl';
our (%in, %text, %config, %access, $config_directory);
&ReadParse();
&error_setup($text{'convert_err'});
$access{'sync'} && $access{'create'} || &error($text{'convert_ecannot'});
&foreign_require("useradmin", "user-lib.pl");
# Validate inputs
my (%users, %nusers, $gid);
if ($access{'gassign'} ne '*') {
@gcan = split(/\s+/, $access{'gassign'});
my @gcan = split(/\s+/, $access{'gassign'});
&indexof($in{'wgroup'}, @gcan) >= 0 ||
&error($text{'convert_ewgroup2'});
}
@@ -31,12 +35,15 @@ elsif ($in{'conv'} == 4) {
}
# Get the group to add to
foreach $g (&list_groups()) {
my $group;
my %exists;
foreach my $g (&list_groups()) {
$group = $g if ($g->{'name'} eq $in{'wgroup'});
$exists{$g->{'name'}}++;
}
$group || &error($text{'convert_ewgroup'});
my (@ginfo, @members);
if ($in{'conv'} == 3) {
# Find secondary members of group
@ginfo = getgrnam($in{'group'});
@@ -44,11 +51,12 @@ if ($in{'conv'} == 3) {
}
# Build the list of users
my @users;
if ($in{'sync'}) {
# Can just get from getpw* system calls, as password isn't needed
@users = ( );
setpwent();
while(@uinfo = getpwent()) {
while(my @uinfo = getpwent()) {
push(@users, { 'user' => $uinfo[0],
'pass' => $uinfo[1],
'uid' => $uinfo[2],
@@ -68,9 +76,9 @@ else {
print $text{'convert_msg'},"<p>\n";
print &ui_columns_start([ $text{'convert_user'}, $text{'convert_action'} ]);
map { $exists{$_->{'name'}}++ } &list_users();
$skipped = $exists = $invalid = $converted = 0;
foreach $u (@users) {
local $ok;
my ($skipped, $exists, $invalid, $converted) = (0, 0, 0, 0);
foreach my $u (@users) {
my $ok;
if ($in{'conv'} == 0) {
$ok = 1;
}
@@ -88,6 +96,7 @@ foreach $u (@users) {
$ok = $u->{'uid'} >= $in{'min'} &&
$u->{'uid'} <= $in{'max'};
}
my $msg;
if (!$ok) {
#print &text('convert_skip', $u->{'user'}),"\n";
$msg = undef;
@@ -104,14 +113,15 @@ foreach $u (@users) {
else {
# Actually add the user
$msg = "<b>".&text('convert_added', $u->{'user'})."</b>";
local $user = { 'name' => $u->{'user'},
'pass' => $in{'sync'} ? 'x' : $u->{'pass'},
'modules' => $group->{'modules'} };
my $user = { 'name' => $u->{'user'},
'pass' => $in{'sync'} ? 'x' : $u->{'pass'},
'modules' => $group->{'modules'} };
&create_user($user);
foreach $m (@{$group->{'modules'}}, "") {
local %groupacl;
if (&read_file("$config_directory/$m/$in{'wgroup'}.gacl",
\%groupacl)) {
foreach my $m (@{$group->{'modules'}}, "") {
my %groupacl;
if (&read_file(
"$config_directory/$m/$in{'wgroup'}.gacl",
\%groupacl)) {
&write_file(
"$config_directory/$m/$u->{'user'}.acl",
\%groupacl);

View File

@@ -2,13 +2,16 @@
# convert_form.cgi
# Display a form for converting unix users to webmin users
use strict;
use warnings;
require './acl-lib.pl';
our (%in, %text, %config, %access);
$access{'sync'} && $access{'create'} || &error($text{'convert_ecannot'});
&ui_print_header(undef, $text{'convert_title'}, "");
@glist = &list_groups();
my @glist = &list_groups();
if ($access{'gassign'} ne '*') {
@gcan = split(/\s+/, $access{'gassign'});
my @gcan = split(/\s+/, $access{'gassign'});
@glist = grep { &indexof($_->{'name'}, @gcan) >= 0 } @glist;
}
if (!@glist) {