Compare commits

..

2 Commits

Author SHA1 Message Date
gashapwn
210c71ef9d ident files now can be marked as done 2020-11-26 22:36:27 +00:00
gashapwn
e0d7030f6f changed format of new user files 2020-11-26 22:31:34 +00:00

View File

@ -19,13 +19,13 @@ 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 $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 +33,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 +51,21 @@ 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("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("mv $fn1 $fn1.done");
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);