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.

79 lines
1.6KB

  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 fun1($){
  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. # printf("checking username %s\n", $username);
  30. if(length($username) > 31 || !($username =~ /^[A-Za-z][A-Za-z0-9]+$/)){
  31. printf("%s has an INVALID username\n", $id);
  32. die ("oh no");
  33. }
  34. {
  35. my $cmd;
  36. $cmd = "useradd -m -s " . $shell_pref . " " . $username;
  37. printf("Y/N is this command OK?: %s\n", $cmd);
  38. if(<STDIN> ne "Y\n"){
  39. die "invalid characters?!!";
  40. }
  41. system($cmd);
  42. #system("mkdir /home/$username/.ssh");
  43. system("chmod 700 /home/$username/.ssh");
  44. system("mv $FULL_PATH/$id.pub /home/$username/.ssh/authorized_keys");
  45. system("chmod 600 /home/$username/.ssh/authorized_keys");
  46. system("chown $username:$username /home/$username/.ssh");
  47. system("chown $username:$username /home/$username/.ssh/authorized_keys");
  48. system("rm $FULL_PATH/$id.ident");
  49. }
  50. close FILE;
  51. }
  52. fun1("00004");
  53. die "test 0";
  54. @g = glob("$FULL_PATH*");
  55. @g = map { s/.*\/([^\/]*).pub$/$1/; $_ } grep {$_ =~ /pub$/} @g;
  56. for my $fn (@g){
  57. printf("%s\n", $fn);
  58. }