criarteste 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. IP=$(cat /etc/IP)
  3. if [ ! -d /etc/SSHPlus/userteste ]; then
  4. mkdir /etc/SSHPlus/userteste
  5. fi
  6. echo -e "\033[0;34m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\033[0m"
  7. echo -e "\033[0;34m┃\E[44;1;37m CRIAR USUARIO TESTE \E[0m\033[0;34m┃"
  8. echo -e "\033[0;34m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\033[0m"
  9. echo ""
  10. [ "$(ls -A /etc/SSHPlus/userteste)" ] && echo -e "\033[1;32mTeste Ativo!\033[1;37m" || echo -e "\033[1;31mNenhum test ativo!\033[0m"
  11. echo ""
  12. for testeson in $(ls /etc/SSHPlus/userteste |sort |sed 's/.sh//g')
  13. do
  14. echo "$testeson"
  15. done
  16. echo ""
  17. echo -ne "\033[1;32mNome do usuario\033[1;37m: "; read nome
  18. if [[ -z $nome ]]
  19. then
  20. echo ""
  21. tput setaf 7 ; tput setab 1 ; tput bold ; echo "" ; echo "Nome vazio ou invalido." ; echo "" ; tput sgr0
  22. exit 1
  23. fi
  24. awk -F : ' { print $1 }' /etc/passwd > /tmp/users
  25. if grep -Fxq "$nome" /tmp/users
  26. then
  27. tput setaf 7 ; tput setab 1 ; tput bold ; echo "" ; echo "Este usuário já existe." ; echo "" ; tput sgr0
  28. exit 1
  29. fi
  30. echo -ne "\033[1;32mSenha\033[1;37m: "; read pass
  31. if [[ -z $pass ]]
  32. then
  33. echo ""
  34. tput setaf 7 ; tput setab 1 ; tput bold ; echo "" ; echo "Senha vazia ou invalida." ; echo "" ; tput sgr0
  35. exit 1
  36. fi
  37. echo -ne "\033[1;32mLimite\033[1;37m: "; read limit
  38. if [[ -z $limit ]]
  39. then
  40. echo ""
  41. tput setaf 7 ; tput setab 1 ; tput bold ; echo "" ; echo "Limite vazio ou invalido." ; echo "" ; tput sgr0
  42. exit 1
  43. fi
  44. echo -ne "\033[1;32mMinutos \033[1;33m(\033[1;31mEx: \033[1;37m60\033[1;33m)\033[1;37m: "; read u_temp
  45. if [[ -z $limit ]]
  46. then
  47. echo ""
  48. tput setaf 7 ; tput setab 1 ; tput bold ; echo "" ; echo "Limite vazio ou invalido." ; echo "" ; tput sgr0
  49. exit 1
  50. fi
  51. useradd -M -s /bin/false $nome
  52. (echo $pass;echo $pass) |passwd $nome > /dev/null 2>&1
  53. echo "$pass" > /etc/SSHPlus/senha/$nome
  54. echo "$nome $limit" >> /root/usuarios.db
  55. echo "#!/bin/bash
  56. pkill -f "$nome"
  57. userdel --force $nome
  58. grep -v ^$nome[[:space:]] /root/usuarios.db > /tmp/ph ; cat /tmp/ph > /root/usuarios.db
  59. rm /etc/SSHPlus/senha/$nome > /dev/null 2>&1
  60. rm -rf /etc/SSHPlus/userteste/$nome.sh
  61. exit" > /etc/SSHPlus/userteste/$nome.sh
  62. chmod +x /etc/SSHPlus/userteste/$nome.sh
  63. at -f /etc/SSHPlus/userteste/$nome.sh now + $u_temp min > /dev/null 2>&1
  64. clear
  65. echo -e "\033[0;34m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\033[0m"
  66. echo -e "\033[0;34m┃\E[44;1;37m USUARIO TESTE CRIADO \E[0m\033[0;34m┃"
  67. echo -e "\033[0;34m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\033[0m"
  68. echo ""
  69. echo -e "\033[1;32mIP:\033[1;37m $IP"
  70. echo -e "\033[1;32mUsuario:\033[1;37m $nome"
  71. echo -e "\033[1;32mSenha:\033[1;37m $pass"
  72. echo -e "\033[1;32mLimite:\033[1;37m $limit"
  73. echo -e "\033[1;32mValidade:\033[1;37m $u_temp Minutos"
  74. echo ""
  75. echo -e "\033[1;33mApos o tempo definido o usuario"
  76. echo -e "\033[1;32m$nome \033[1;33msera desconectado e deletado.\033[0m"
  77. exit