scripts and tools to administer the lingy.in public unix / tilde
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.7KB

  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. my $WORKING_DIR = "/home/gashapwn/lyadmin/";
  5. my $ACCOUNT_DIR = "test/";
  6. my $FULL_PATH = "$WORKING_DIR$ACCOUNT_DIR";
  7. my $SHELL_ENUM = {
  8. "SHELL_BASH" => "/usr/local/bin/bash",
  9. "SHELL_KSH" => "/bin/ksh"
  10. };
  11. my @g;
  12. sub create($){
  13. my $id = $_[0];
  14. my $fn1 = $FULL_PATH.$id.".ident";
  15. my $fn2 = $FULL_PATH.$id.".pub";
  16. my $username;
  17. my $shell_pref;
  18. my $user_email;
  19. open FILE, $fn1 or die "could not open file";
  20. $username = <FILE>;
  21. chomp $username;
  22. $user_email = <FILE>;
  23. chomp $user_email;
  24. {
  25. my $shell_var = <FILE>;
  26. chomp $shell_var;
  27. $shell_pref = $SHELL_ENUM->{$shell_var};
  28. }
  29. if(length($username) > 31 || !($username =~ /^[A-Za-z][A-Za-z0-9]+$/)){
  30. printf("%s has an INVALID username\n", $id);
  31. die ("oh no");
  32. }
  33. {
  34. my $cmd;
  35. $cmd = "useradd -m -s " . $shell_pref . " " . $username;
  36. printf("Y/N is this command OK?: %s\n", $cmd);
  37. if(<STDIN> ne "Y\n"){
  38. die "invalid characters?!!";
  39. }
  40. system($cmd);
  41. #system("mkdir /home/$username/.ssh");
  42. #system("chmod 700 /home/$username/.ssh");
  43. system("cat $FULL_PATH/$id.pub > /home/$username/.ssh/authorized_keys");
  44. #system("mv $FULL_PATH/$id.pub /home/$username/.ssh/authorized_keys");
  45. #system("chmod 600 /home/$username/.ssh/authorized_keys");
  46. system("chmod 711 /home/$username");
  47. #system("chown $username:$username /home/$username/.ssh");
  48. #system("chown $username:$username /home/$username/.ssh/authorized_keys");
  49. system("rm $FULL_PATH/$id.ident");
  50. system("rm $FULL_PATH/$id.pub");
  51. }
  52. close FILE;
  53. }
  54. @g = glob("$FULL_PATH*");
  55. @g = map { s/.*\/([^\/]*).pub$/$1/; $_ } grep {$_ =~ /pub$/} @g;
  56. for my $fn (@g){
  57. create($fn);
  58. }