Advertisement
raggesilver

PHP + MYSQL + Bash <3

Jul 19th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.61 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Written by Paulo @ http://github.com/raggesilver
  4. # To compile: shc -f file_name.sh -o output_name
  5.  
  6. YELLOW='\033[1;33m'
  7. RED='\033[0;31m'
  8. GREEN='\033[0;32m'
  9. NC='\033[0m'
  10.  
  11. showLogo() {
  12.     clear
  13.     figlet -c PimScript
  14.     sleep 3
  15.     clear
  16. }
  17.  
  18. getParams() {
  19.     while [ "$1" != "" ]; do
  20.         case $1 in
  21.            
  22.             -t | --target ) shift
  23.                             echo -e "${YELLOW}Warning ping target manually overwritten to: \"$1\"${NC}"
  24.                             target=$1
  25.                             ;;
  26.  
  27.             *)  echo "Unknown option $1."
  28.                 exit -1
  29.  
  30.         esac
  31.         shift
  32.     done
  33. }
  34.  
  35. checkInternetConnection() {
  36.     wget -q --tries=5 --timeout=20 --spider "$target"
  37.     if [[ ! $? -eq 0 ]]; then
  38.         echo -e "${RED}This script requires internet connection!${NC}"
  39.         exit 1
  40.     fi
  41. }
  42.  
  43. checkDependencies() {
  44.     status=`dpkg -s figlet`
  45.     if [[ ! "$status" == *"Status: install ok installed"* ]]; then
  46.         zenity --warning --title "Dependencies" --text "PimSript Login depends on figlet to work. Please install it."
  47.         sudo -K
  48.         # PASSWD="$(zenity --password --title=Authentication --text='Install figlet')\n"
  49.         gksu "apt-get install -y figlet"
  50.         if [[ ! $? -eq 0 ]]; then exit 1; fi
  51.     fi
  52. }
  53.  
  54. printCenter() {
  55.     COLUMNS=$(tput cols)
  56.     while [ "$1" != "" ]; do
  57.         text=$1
  58.         printf "%*s\n" $(((${#text}+$COLUMNS)/2)) "$text"
  59.         shift
  60.     done
  61. }
  62.  
  63. register() {
  64.     clear
  65.     printCenter "*~.REGISTER.~*"
  66.     echo -n "Username> "
  67.     read username
  68.     echo -n "Password> "
  69.     read -s password
  70.     echo ""
  71.     echo -n "Confirm password> "
  72.     read -s confpassword
  73.     if [[ "$password" != "$confpassword" ]]; then echo -e "\n${RED}Passwords don't match.${NC}"; sleep 3; register; return; fi
  74.     echo ""
  75.     password=`echo $password | md5sum | awk '{print $1}'`
  76.     echo `curl "localhost/shell_app/register.php?username=$username&password=$password" -s`
  77.     doLogin
  78. }
  79.  
  80. doLogin() {
  81.     if [[ $# -le 0 ]]; then
  82.         clear
  83.         printCenter "*~.LOGIN.~*" "type register as username to register"
  84.     fi
  85.     echo -n "Username> "
  86.     read username
  87.     if [[ "$username" == "register" ]]; then register; return; fi
  88.     echo -n "Password> "
  89.     read -s password
  90.     echo ""
  91.     password=`echo $password | md5sum | awk '{print $1}'`
  92.     response=$(curl "localhost/shell_app/index.php?username=$username&password=$password" -s)
  93.     case $response in
  94.  
  95.         0) echo -e "${GREEN}Logged in, welcome \e[1m\e[93m\e[5m$username\e[0m!${NC}";;
  96.  
  97.         1) echo -e "\nPlease fill in all the fields\n"; doLogin "false";;
  98.  
  99.         2) echo -e "\nIncorrect credentials\n"; doLogin "false";;
  100.  
  101.         *) echo "Unknown response from server. > $response"
  102.  
  103.     esac
  104. }
  105.  
  106. params=$@
  107.  
  108. target="http://google.com"
  109.  
  110. getParams $getParams
  111.  
  112. checkInternetConnection
  113. con=$?
  114.  
  115. checkDependencies
  116.  
  117. showLogo
  118.  
  119. doLogin
  120.  
  121. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement