changed format of new user files
This commit is contained in:
parent
d60e2ac726
commit
e0d7030f6f
@ -19,13 +19,14 @@ sub create($){
|
|||||||
my $id = $_[0];
|
my $id = $_[0];
|
||||||
|
|
||||||
my $fn1 = $FULL_PATH.$id.".ident";
|
my $fn1 = $FULL_PATH.$id.".ident";
|
||||||
my $fn2 = $FULL_PATH.$id.".pub";
|
# my $fn2 = $FULL_PATH.$id.".pub";
|
||||||
|
|
||||||
my $username;
|
my $username;
|
||||||
my $shell_pref;
|
my $shell_pref;
|
||||||
my $user_email;
|
my $user_email;
|
||||||
|
my $pub_key;
|
||||||
|
|
||||||
open FILE, $fn1 or die "could not open file";
|
open FILE, $fn1 or die "could not open file $fn1";
|
||||||
$username = <FILE>;
|
$username = <FILE>;
|
||||||
chomp $username;
|
chomp $username;
|
||||||
|
|
||||||
@ -33,11 +34,14 @@ sub create($){
|
|||||||
chomp $user_email;
|
chomp $user_email;
|
||||||
|
|
||||||
{
|
{
|
||||||
my $shell_var = <FILE>;
|
my $s0 = <FILE>;
|
||||||
chomp $shell_var;
|
chomp $s0;
|
||||||
$shell_pref = $SHELL_ENUM->{$shell_var};
|
$shell_pref = $SHELL_ENUM->{$s0};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$pub_key = <FILE>;
|
||||||
|
chomp $pub_key;
|
||||||
|
|
||||||
if(length($username) > 31 || !($username =~ /^[A-Za-z][A-Za-z0-9]+$/)){
|
if(length($username) > 31 || !($username =~ /^[A-Za-z][A-Za-z0-9]+$/)){
|
||||||
printf("%s has an INVALID username\n", $id);
|
printf("%s has an INVALID username\n", $id);
|
||||||
die ("oh no");
|
die ("oh no");
|
||||||
@ -48,22 +52,23 @@ sub create($){
|
|||||||
$cmd = "useradd -m -s " . $shell_pref . " " . $username;
|
$cmd = "useradd -m -s " . $shell_pref . " " . $username;
|
||||||
printf("Y/N is this command OK?: %s\n", $cmd);
|
printf("Y/N is this command OK?: %s\n", $cmd);
|
||||||
|
|
||||||
if(<STDIN> ne "Y\n"){
|
if(!(<STDIN> =~ /^y/i)){
|
||||||
die "invalid characters?!!";
|
die "invalid characters?!!";
|
||||||
}
|
}
|
||||||
|
|
||||||
system($cmd);
|
system($cmd);
|
||||||
system("cat $FULL_PATH/$id.pub > /home/$username/.ssh/authorized_keys");
|
# system("cat $FULL_PATH/$id.pub > /home/$username/.ssh/authorized_keys");
|
||||||
|
system("echo '$pub_key' > /home/$username/.ssh/authorized_keys");
|
||||||
system("chmod 711 /home/$username");
|
system("chmod 711 /home/$username");
|
||||||
system("rm $FULL_PATH/$id.ident");
|
system("rm $fn1");
|
||||||
system("rm $FULL_PATH/$id.pub");
|
# system("rm $FULL_PATH/$id.pub");
|
||||||
system("echo $username >> user_list.txt");
|
system("echo $username >> user_list.txt");
|
||||||
}
|
}
|
||||||
close FILE;
|
close FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@g = glob("$FULL_PATH*");
|
@g = glob("$FULL_PATH*");
|
||||||
@g = map { s/.*\/([^\/]*).pub$/$1/; $_ } grep {$_ =~ /pub$/} @g;
|
@g = map { s/.*\/([^\/]*).ident$/$1/; $_ } grep {$_ =~ /ident$/} @g;
|
||||||
|
|
||||||
for my $fn (@g){
|
for my $fn (@g){
|
||||||
create($fn);
|
create($fn);
|
||||||
|
Loading…
Reference in New Issue
Block a user