Lock – Un simple bloqueador de consola para Linux

d
Autor: @matiaskatz
Descripcion: Script que permite bloquear una terminal con password momentaneo sin comprometer el de usuario root o el tuyo

#!/bin/bash
#Version 1.0, March 10th, 2012
#Written by Matias Katz (@matiaskatz - www.matiaskatz.com). 2012, Buenos Aires, Argentina.

signal_trapper () #This is where the signal traps are sent
{
 echo "****** Nope :) ******"
}

menu () #Main menu
{
       echo ""
 echo -n "Hi, I'm '$host' and I'm locked. Please, type the password to unlock: "

       read -s x

       case $x in
               $password)
   echo ""
                       echo "Bye! :)"
                       exit 0
                       ;;
               *)
                       menu
                       ;;
       esac
}

#Start of excecution
case $1 in
 "-h"|"--help")
  echo "Lock v1.0 - A simple Linux console locking tool, written in Bash-Scripting"
  echo "Written by Matias Katz (@matiaskatz - www.matiaskatz.com). 2012, Buenos Aires, Argentina."
  echo ""
  echo "To use it, just type 'lock' and input the unlock password twice."
  echo ""
  echo "Warning: Spaces are ignored, unless they're within other characters:"
  echo ""
  echo "The password '    1' will be taken as '1'."
  echo "The password '1    ' will be taken as '1'."
  echo "The password '1   1' will be taken as '1   1'."
  echo ""
  echo "Enjoy :)"
  echo ""
  exit 0
  ;;
 "")
  read -s -p "Password: " password #Ask the user for a password
  echo ""
  read -s -p "Password (again): " password2 #Ask for confirmation
  echo ""
  if [ "$password" != "$password2" ]
  then
   echo "Passwords don't match"
   exit 0
  fi
  ;;
 *)
  echo "Invalid option"
  echo "Hit 'lock -h' or 'lock --help' to find out more."
  exit 0
  #password=$1 #Take the first argument as a password <--- It's dangerous, use it as your own risk :)   ;; esac  #Prohibimos ^Z y ^C trap 'clear; echo -e "Password:\c";' 2 20 #trap signal_trapper SIGINT #Trap the CTRL+C signal to avoid bypass #trap signal_trapper SIGTSTP #Trap the CTRL+Z signal to avoid bypass host=$(hostname) clear #<--- if you want to :) menu


Forma de Uso:

1) Mover al directorio /usr/bin.
sudo mv lock.sh /usr/bin/lock


2) Asignar permisos
sudo chmod 755 /usr/bin/lock


3) Ejecucion
lock


4) Para acceder a la ayuda
lock -h

Fuente

0 comentarios: