Facebook
From AntekN, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 127
  1. #!/bin/bash
  2.  
  3. PASSWORD_FILE="passwords.csv"
  4. ENCRYPTED_PASSWORD_FILE="passwords.enc"
  5. MASTER_PASSWORD="supersecret"  # Zmień to na swoje hasło
  6.  
  7. # Funkcja do odszyfrowywania pliku z hasłami
  8. decrypt_password_file() {
  9.     if [[ -f $ENCRYPTED_PASSWORD_FILE ]]; then
  10.         openssl enc -d -aes-256-cbc -salt -in $ENCRYPTED_PASSWORD_FILE -out $PASSWORD_FILE -pass pass:$MASTER_PASSWORD
  11.     else
  12.         touch $PASSWORD_FILE
  13.     fi
  14. }
  15.  
  16. # Funkcja do szyfrowania pliku z hasłami
  17. encrypt_password_file() {
  18.     openssl enc -aes-256-cbc -salt -in $PASSWORD_FILE -out $ENCRYPTED_PASSWORD_FILE -pass pass:$MASTER_PASSWORD
  19.     rm -f $PASSWORD_FILE
  20. }
  21.  
  22. # Funkcja logowania użytkownika
  23. login() {
  24.     password=$(zenity --password --title="Logowanie")
  25.     if [[ $password != $MASTER_PASSWORD ]]; then
  26.         zenity --error --text="Niepoprawne hasło!"
  27.         exit 1
  28.     fi
  29. }
  30.  
  31. # Funkcja wyświetlania menu
  32. display_menu() {
  33.     option=$(zenity --list --radiolist --title="Menedżer haseł" --column="Wybór" --column="Opcja" TRUE "Wyświetl zapisane hasła" FALSE "Dodaj nowe hasło" FALSE "Usuń hasło" FALSE "Wyjdź")
  34. }
  35.  
  36. # Funkcja do wyświetlania zapisanych haseł
  37. view_passwords() {
  38.     if [[ ! -s $PASSWORD_FILE ]]; then
  39.         zenity --info --text="Brak zapisanych haseł."
  40.         return
  41.     fi
  42.  
  43.     selection=$(awk -F, '{print NR ". " $1}' $PASSWORD_FILE | zenity --list --title="Zapisane hasła" --column="Hasła" --text="Wybierz stronę, aby wyświetlić dane")
  44.  
  45.     if [[ -n $selection ]]; then
  46.         line_number=$(echo $selection | cut -d. -f1)
  47.         details=$(sed -n "${line_number}p" $PASSWORD_FILE | awk -F, '{print "Strona: " $1 "\nLogin: " $2 "\nHasło: " $3}')
  48.         zenity --info --text="$details"
  49.     fi
  50. }
  51.  
  52. # Funkcja do dodawania nowego hasła
  53. add_password() {
  54.     site=$(zenity --entry --title="Dodaj nowe hasło" --text="Podaj nazwę strony:")
  55.     login=$(zenity --entry --title="Dodaj nowe hasło" --text="Podaj login/email:")
  56.     password=$(zenity --entry --title="Dodaj nowe hasło" --text="Podaj hasło:")
  57.  
  58.     echo "$site,$login,$password" >> $PASSWORD_FILE
  59. }
  60.  
  61. # Funkcja do usuwania hasła
  62. delete_password() {
  63.     if [[ ! -s $PASSWORD_FILE ]]; then
  64.         zenity --info --text="Brak zapisanych haseł."
  65.         return
  66.     fi
  67.  
  68.     selection=$(awk -F, '{print NR ". " $1}' $PASSWORD_FILE | zenity --list --title="Usuń hasło" --column="Hasła" --text="Wybierz stronę do usunięcia")
  69.  
  70.     if [[ -n $selection ]]; then
  71.         line_number=$(echo $selection | cut -d. -f1)
  72.         sed -i "${line_number}d" $PASSWORD_FILE
  73.         zenity --info --text="Usunięto hasło numer $line_number."
  74.     fi
  75. }
  76.  
  77. # Główna pętla programu
  78. main() {
  79.     login
  80.     decrypt_password_file
  81.  
  82.     while true; do
  83.         display_menu
  84.  
  85.         case $option in
  86.             "Wyświetl zapisane hasła") view_passwords ;;
  87.             "Dodaj nowe hasło") add_password ;;
  88.             "Usuń hasło") delete_password ;;
  89.             "Wyjdź") encrypt_password_file; exit 0 ;;
  90.             *) zenity --error --text="Niepoprawna opcja." ;;
  91.         esac
  92.     done
  93. }
  94.  
  95. main