extras/gtomb: replaced soft with hard tabs to maintain code standard.

This commit is contained in:
nerun 2023-06-25 14:14:32 -03:00 committed by Jaromil
parent 364a457fbc
commit 4e3221e937

View File

@ -46,162 +46,162 @@ echo -e "$ICONB64" | base64 --decode > $MONMORT
# {{{ Zenity dialogs # {{{ Zenity dialogs
function _zenques { function _zenques {
zenity \ zenity \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--question \ --question \
--text="$1" --text="$1"
} }
function _fsel { function _fsel {
zenity \ zenity \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--file-selection \ --file-selection \
--title="$1" --title="$1"
} }
function _fsave { function _fsave {
zenity \ zenity \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--file-selection \ --file-selection \
--save \ --save \
--title="$1" \ --title="$1" \
--filename="$2" --filename="$2"
} }
function _zenwarn { function _zenwarn {
zenity \ zenity \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--warning \ --warning \
--title="$1" \ --title="$1" \
--text="$2" --text="$2"
} }
function _info { function _info {
which notify-send > /dev/null which notify-send > /dev/null
if [[ $? == "0" ]]; then if [[ $? == "0" ]]; then
_zenotif $* _zenotif $*
else else
_zeninfo $* _zeninfo $*
fi fi
} }
function _zenotif { function _zenotif {
zenity \ zenity \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--notification \ --notification \
--title="$1" \ --title="$1" \
--text="$2" --text="$2"
} }
function _zeninfo { function _zeninfo {
zenity \ zenity \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--info \ --info \
--title="$1" \ --title="$1" \
--text="$2" --text="$2"
} }
function _zenerr { function _zenerr {
zenity \ zenity \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--error \ --error \
--title="$1" \ --title="$1" \
--text="$2" --text="$2"
} }
function _zenprog { function _zenprog {
zenity \ zenity \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--progress \ --progress \
--auto-close \ --auto-close \
--pulsate \ --pulsate \
--title="$1" \ --title="$1" \
--text="$2" --text="$2"
} }
function _zenprognc { function _zenprognc {
zenity \ zenity \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--progress \ --progress \
--auto-close \ --auto-close \
--no-cancel \ --no-cancel \
--pulsate \ --pulsate \
--title="$1" \ --title="$1" \
--text="$2" --text="$2"
} }
function _zenentry { function _zenentry {
zenity \ zenity \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--entry \ --entry \
--title="$1" \ --title="$1" \
--text="$2" \ --text="$2" \
--entry-text="$3" --entry-text="$3"
} }
# }}} # }}}
# {{{ _clean - Clean function, removes sensitive stuff from memory # {{{ _clean - Clean function, removes sensitive stuff from memory
function _clean { function _clean {
unset $? unset $?
local rr="$RANDOM" local rr="$RANDOM"
while [[ ${#rr} -lt 500 ]]; do while [[ ${#rr} -lt 500 ]]; do
rr+="$RANDOM" rr+="$RANDOM"
done done
cmnd="$rr"; unset cmnd cmnd="$rr"; unset cmnd
tombname="$rr"; unset tombname tombname="$rr"; unset tombname
tombsize="$rr"; unset tombsize tombsize="$rr"; unset tombsize
keyfile="$rr"; unset keyfile keyfile="$rr"; unset keyfile
tombtmp="/tmp/tombtmp" tombtmp="/tmp/tombtmp"
if [ -f $tombtmp ]; then if [ -f $tombtmp ]; then
dd if=/dev/urandom of=$tombtmp bs=800 count=1 dd if=/dev/urandom of=$tombtmp bs=800 count=1
rm -f $tombtmp rm -f $tombtmp
fi fi
tombtmp="$rr"; unset tombtmp tombtmp="$rr"; unset tombtmp
newkey="$rr"; unset newkey newkey="$rr"; unset newkey
jpegfile="$rr"; unset jpegfile jpegfile="$rr"; unset jpegfile
} }
# }}} # }}}
# {{{ _main - Main window # {{{ _main - Main window
function _main { function _main {
_clean _clean
cmnd=`zenity \ cmnd=`zenity \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--title="gtomb" \ --title="gtomb" \
--width=400 \ --width=400 \
--height=445 \ --height=445 \
--list \ --list \
--hide-header \ --hide-header \
--text="gtomb v$ver\nThe GUI wrapper for Tomb, the crypto undertaker." \ --text="gtomb v$ver\nThe GUI wrapper for Tomb, the crypto undertaker." \
--separator=" & " \ --separator=" & " \
--column=Function \ --column=Function \
--column=Description \ --column=Description \
"dig" "Dig a new tomb of chosen size" \ "dig" "Dig a new tomb of chosen size" \
"forge" "Forge a new key used to lock tombs" \ "forge" "Forge a new key used to lock tombs" \
"lock" "Lock a non-locked tomb using an existing key" \ "lock" "Lock a non-locked tomb using an existing key" \
"open" "Open an existing tomb" \ "open" "Open an existing tomb" \
"index" "Index the contents of all tombs." \ "index" "Index the contents of all tombs." \
"search" "Search the content of indexed tombs." \ "search" "Search the content of indexed tombs." \
"list" "List all open tombs and information on them" \ "list" "List all open tombs and information on them" \
"close" "Close a specific tomb (or all)" \ "close" "Close a specific tomb (or all)" \
"slam" "Slam a tomb (or all) killing all programs using it" \ "slam" "Slam a tomb (or all) killing all programs using it" \
"resize" "Resize a tomb to a new size (can only grow)" \ "resize" "Resize a tomb to a new size (can only grow)" \
"passwd" "Change the passphrase of a key" \ "passwd" "Change the passphrase of a key" \
"setkey" "Change the key of an existing tomb" \ "setkey" "Change the key of an existing tomb" \
"engrave" "Generates a QR code of a key to be saved on paper" \ "engrave" "Generates a QR code of a key to be saved on paper" \
"bury" "Hide a key inside a JPEG image" \ "bury" "Hide a key inside a JPEG image" \
"exhume" "Extract a key from a JPEG image"` "exhume" "Extract a key from a JPEG image"`
if [[ "$?" = 1 && $SWAPOFF = "true" ]]; then if [[ "$?" = 1 && $SWAPOFF = "true" ]]; then
zenity --password --title="sudo swapon -a" | sudo swapon -a zenity --password --title="sudo swapon -a" | sudo swapon -a
unset $? unset $?
fi fi
eval "_$cmnd" eval "_$cmnd"
} }
# }}} # }}}
# {{{ dig - Dig a new tomb # {{{ dig - Dig a new tomb
function _dig { function _dig {
tombname=`_fsave "Choose where to dig your tomb" "secret.tomb"` tombname=`_fsave "Choose where to dig your tomb" "secret.tomb"`
res=$? res=$?
if [[ -f "$tombname" ]]; then if [[ -f "$tombname" ]]; then
_zenerr "Error" "This tomb already exists. I am not digging here." _zenerr "Error" "This tomb already exists. I am not digging here."
exec _main exec _main
elif [[ -z "$tombname" ]]; then elif [[ -z "$tombname" ]]; then
_info "gtomb" "Cancelled" _info "gtomb" "Cancelled"
exec _main exec _main
fi fi
[[ $res = 0 ]] || exec _main [[ $res = 0 ]] || exec _main
@ -243,38 +243,38 @@ function _dig {
# {{{ forge - Forge a new key # {{{ forge - Forge a new key
function _forge { function _forge {
keyfile=`_fsave "Choose where to forge your key" "secret.tomb.key"` keyfile=`_fsave "Choose where to forge your key" "secret.tomb.key"`
res=$? res=$?
if [[ -f $keyfile ]]; then if [[ -f $keyfile ]]; then
_zenerr "Error" "This key already exists. I am not overwriting." _zenerr "Error" "This key already exists. I am not overwriting."
exec _main exec _main
elif [[ -z $keyfile ]]; then elif [[ -z $keyfile ]]; then
_info "gtomb" "Canceled" _info "gtomb" "Canceled"
exec _main exec _main
fi fi
kdf="" kdf=""
kdfiter="" kdfiter=""
if [[ -x $HEXENC ]] && [[ -x $GENSALT ]] && [[ -x $GETITER ]] && [[ -x $PBKDF ]]; then if [[ -x $HEXENC ]] && [[ -x $GENSALT ]] && [[ -x $GETITER ]] && [[ -x $PBKDF ]]; then
_zenques "Do you want to use KDF? (Generates passwords armored against dictionary attacks)" _zenques "Do you want to use KDF? (Generates passwords armored against dictionary attacks)"
if [[ $? == "0" ]]; then if [[ $? == "0" ]]; then
kdf="--kdf" kdf="--kdf"
kdfiter=`_zenentry "Iterations" "Enter the delay (itertime) in seconds for each time \n\ kdfiter=`_zenentry "Iterations" "Enter the delay (itertime) in seconds for each time \n\
this key is used:" "2"` this key is used:" "2"`
re='^[0-9]+$' re='^[0-9]+$'
if ! [[ $kdfiter =~ $re ]]; then if ! [[ $kdfiter =~ $re ]]; then
_zenerr "Error" "Please choose a valid number." _zenerr "Error" "Please choose a valid number."
exec _main exec _main
elif [[ -z $kdfiter ]]; then elif [[ -z $kdfiter ]]; then
_info "gtomb" "Canceled" _info "gtomb" "Canceled"
exec _main exec _main
fi fi
fi fi
else else
_zenotif "gtomb" "KDF binaries not found." _zenotif "gtomb" "KDF binaries not found."
fi fi
[[ $? = 0 ]] || exec _main [[ $? = 0 ]] || exec _main
@ -302,8 +302,8 @@ You can move your mouse around and use your computer to speed up the process." &
# {{{ lock - Lock a non-locked tomb # {{{ lock - Lock a non-locked tomb
function _lock { function _lock {
tombname=`_fsel "Select a tomb to lock"` tombname=`_fsel "Select a tomb to lock"`
[[ -n $tombname ]] || { _zenotif "gtomb" "Cancelled" ; exec _main } [[ -n $tombname ]] || { _zenotif "gtomb" "Cancelled" ; exec _main }
[[ $? = 0 ]] || exec _main [[ $? = 0 ]] || exec _main
keyfile=`_fsel "Choose the key for your tomb"` keyfile=`_fsel "Choose the key for your tomb"`
@ -319,7 +319,7 @@ function _lock {
# {{{ open - Open an existing tomb # {{{ open - Open an existing tomb
function _open { function _open {
tombname=`_fsel "Choose a tomb to open"` tombname=`_fsel "Choose a tomb to open"`
[[ $? = 0 ]] || exec _main [[ $? = 0 ]] || exec _main
keyfile=`_fsel "Choose the key for your tomb"` keyfile=`_fsel "Choose the key for your tomb"`
@ -333,20 +333,20 @@ function _open {
# {{{ list - list all open tombs, along with their mountpoint # {{{ list - list all open tombs, along with their mountpoint
function _list { function _list {
tombtmp="/tmp/tombtmp" tombtmp="/tmp/tombtmp"
"$TOMBPATH" list --get-mountpoint > $tombtmp "$TOMBPATH" list --get-mountpoint > $tombtmp
tombname=`cat $tombtmp | \ tombname=`cat $tombtmp | \
sed 's/.*\/\([^\/]*\)$/\1\n &/' | \ sed 's/.*\/\([^\/]*\)$/\1\n &/' | \
zenity \ zenity \
--title="Currently open tombs" \ --title="Currently open tombs" \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--width=400 --height=380 --list \ --width=400 --height=380 --list \
--separator=" & " \ --separator=" & " \
--text="Here are your open tombs" \ --text="Here are your open tombs" \
--column="Tomb" \ --column="Tomb" \
--column="Path" ` --column="Path" `
tombname=`echo "$tombname" | cut -c1-16` tombname=`echo "$tombname" | cut -c1-16`
[[ $? = 0 ]] || exec _main [[ $? = 0 ]] || exec _main
@ -359,7 +359,7 @@ function _list {
--column="Command" \ --column="Command" \
--column="Description" \ --column="Description" \
"disindex" "Disable indexing of this tomb." \ "disindex" "Disable indexing of this tomb." \
"enindex" "Enable indexing of this tomb." \ "enindex" "Enable indexing of this tomb." \
"close" "Close the selected tomb." \ "close" "Close the selected tomb." \
"slam" "Slam the selected tomb." \ "slam" "Slam the selected tomb." \
"binds" "Edit current bind-hooks." \ "binds" "Edit current bind-hooks." \
@ -421,18 +421,18 @@ function _list {
# {{{ close - Close open tomb(s) # {{{ close - Close open tomb(s)
function _close { function _close {
tombtmp="/tmp/tombtmp" tombtmp="/tmp/tombtmp"
"$TOMBPATH" list --get-mountpoint > $tombtmp "$TOMBPATH" list --get-mountpoint > $tombtmp
echo "/all" >> $tombtmp echo "/all" >> $tombtmp
tombname=`cat $tombtmp | \ tombname=`cat $tombtmp | \
sed 's/.*\/\([^\/]*\)$/\1\n &/' | \ sed 's/.*\/\([^\/]*\)$/\1\n &/' | \
zenity \ zenity \
--title="Choose a tomb to close" \ --title="Choose a tomb to close" \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--width=640 --height=380 --list \ --width=640 --height=380 --list \
--separator=" & " \ --separator=" & " \
--column=Tomb \ --column=Tomb \
--column=Path ` --column=Path `
[[ $? = 0 ]] || exec _main [[ $? = 0 ]] || exec _main
@ -445,18 +445,18 @@ function _close {
# {{{ slam - Slam open tombs # {{{ slam - Slam open tombs
function _slam { function _slam {
tombtmp="/tmp/tombtmp" tombtmp="/tmp/tombtmp"
"$TOMBPATH" list --get-mountpoint > $tombtmp "$TOMBPATH" list --get-mountpoint > $tombtmp
echo "/all" >> $tombtmp echo "/all" >> $tombtmp
tombname=`cat $tombtmp | \ tombname=`cat $tombtmp | \
sed 's/.*\/\([^\/]*\)$/\1\n &/' | \ sed 's/.*\/\([^\/]*\)$/\1\n &/' | \
zenity \ zenity \
--title="Choose a tomb to slam" \ --title="Choose a tomb to slam" \
--window-icon="$MONMORT" \ --window-icon="$MONMORT" \
--width=640 --height=380 --list \ --width=640 --height=380 --list \
--separator=" & " \ --separator=" & " \
--column=Tomb \ --column=Tomb \
--column=Path ` --column=Path `
[[ $? = 0 ]] || exec _main [[ $? = 0 ]] || exec _main
@ -469,9 +469,9 @@ function _slam {
# {{{ resize - Resize an existing *closed* tomb # {{{ resize - Resize an existing *closed* tomb
function _resize { function _resize {
tombname=`_fsel "Choose a tomb to resize"` tombname=`_fsel "Choose a tomb to resize"`
res=$? res=$?
_zenques "Is your tomb closed?" _zenques "Is your tomb closed?"
[[ $? = 0 ]] || { _zenwarn "gtomb" "Please close the tomb before resizing." ; exec _main } [[ $? = 0 ]] || { _zenwarn "gtomb" "Please close the tomb before resizing." ; exec _main }
@ -503,7 +503,7 @@ function _resize {
# {{{ passwd - Change existing key's passphrase # {{{ passwd - Change existing key's passphrase
function _passwd { function _passwd {
keyfile=`_fsel "Choose a keyfile"` keyfile=`_fsel "Choose a keyfile"`
[[ $? = 0 ]] || exec _main [[ $? = 0 ]] || exec _main
"$TOMBPATH" passwd -k "$keyfile" "$FLAG" | \ "$TOMBPATH" passwd -k "$keyfile" "$FLAG" | \
@ -516,7 +516,7 @@ function _passwd {
# {{{ setkey - Change a tomb's keyfile # {{{ setkey - Change a tomb's keyfile
function _setkey { function _setkey {
tombname=`_fsel "Choose a tomb to change its keyfile"` tombname=`_fsel "Choose a tomb to change its keyfile"`
[[ $? = 0 ]] || exec _main [[ $? = 0 ]] || exec _main
keyfile=`_fsel "Chosse your tomb's old keyfile"` keyfile=`_fsel "Chosse your tomb's old keyfile"`
@ -529,14 +529,14 @@ function _setkey {
_zenprognc "Changing key" "Please wait while your tomb's key is being changed..." _zenprognc "Changing key" "Please wait while your tomb's key is being changed..."
_info "Success" "$tombname keyfile successfully changed! Now using $newkey" _info "Success" "$tombname keyfile successfully changed! Now using $newkey"
exec _main exec _main
} }
# }}} # }}}
# {{{ engrave - generate QR code of a key # {{{ engrave - generate QR code of a key
function _engrave { function _engrave {
which qrencode || _zenwarn "Warning" "qrencode is not installed. Install it and try again" which qrencode || _zenwarn "Warning" "qrencode is not installed. Install it and try again"
keyfile=`_fsel "Choose a keyfile to engrave"` keyfile=`_fsel "Choose a keyfile to engrave"`
[[ $? = 0 ]] || exec _main [[ $? = 0 ]] || exec _main
jpegfile=`_fsave "Choose where to save your keyfile (PNG format)"` jpegfile=`_fsave "Choose where to save your keyfile (PNG format)"`
@ -552,8 +552,8 @@ function _engrave {
# {{{ bury - hide a keyfile in a JPEG image # {{{ bury - hide a keyfile in a JPEG image
function _bury { function _bury {
which steghide || _zenwarn "Warning" "steghide is not installed. Install it and try again" which steghide || _zenwarn "Warning" "steghide is not installed. Install it and try again"
keyfile=`_fsel "Choose keyfile"` keyfile=`_fsel "Choose keyfile"`
[[ $? = 0 ]] || exec _main [[ $? = 0 ]] || exec _main
jpegfile=`_fsel "Choose JPEG file"` jpegfile=`_fsel "Choose JPEG file"`
@ -567,8 +567,8 @@ function _bury {
# {{{ exhume - extract keyfile from JPEG # {{{ exhume - extract keyfile from JPEG
function _exhume { function _exhume {
which steghide || _zenwarn "Warning" "steghide is not installed. Install it and try again" which steghide || _zenwarn "Warning" "steghide is not installed. Install it and try again"
jpegfile=`_fsel "Choose JPEG file"` jpegfile=`_fsel "Choose JPEG file"`
[[ $? = 0 ]] || exec _main [[ $? = 0 ]] || exec _main
keyfile=`_fsave "Choose where to extract your key"` keyfile=`_fsave "Choose where to extract your key"`
@ -582,18 +582,18 @@ function _exhume {
# {{{ index - index the contents of open tombs # {{{ index - index the contents of open tombs
function _index { function _index {
which locate || _zenwarn "Warning" "mlocate is not installed. Install it and try again" which locate || _zenwarn "Warning" "mlocate is not installed. Install it and try again"
"$TOMBPATH" index | _zenprognc "Indexing" "Please wait while the open tombs are being indexed..." "$TOMBPATH" index | _zenprognc "Indexing" "Please wait while the open tombs are being indexed..."
_info "Success" "Tombs indexed!" _info "Success" "Tombs indexed!"
exec _main exec _main
} }
# }}} # }}}
# {{{ search - searches the contents of indexed tombs # {{{ search - searches the contents of indexed tombs
function _search { function _search {
strings="" strings=""
_searchstring _searchstring
exec _main exec _main
} }
function _searchstring { function _searchstring {
@ -621,15 +621,15 @@ function _searchstring {
function _ { _clean } # I like cleaning :) function _ { _clean } # I like cleaning :)
[[ -x $TOMBPATH ]] || { [[ -x $TOMBPATH ]] || {
_zenwarn "Warning" "Tomb binary is not executable or doesn't exist in the current path. Install it or edit the script to point to the correct path." _zenwarn "Warning" "Tomb binary is not executable or doesn't exist in the current path. Install it or edit the script to point to the correct path."
exit 1 } exit 1 }
if [[ $SWAPOFF = "true" ]]; then if [[ $SWAPOFF = "true" ]]; then
FLAG="" FLAG=""
zenity --password --title="sudo swapoff -a" | sudo swapoff -a zenity --password --title="sudo swapoff -a" | sudo swapoff -a
unset $? unset $?
else else
FLAG="-f" FLAG="-f"
fi fi
_main _main