fix cache and clipboard

This commit is contained in:
zawz 2021-04-16 14:11:19 +02:00
parent d437da40fe
commit 5148e66a94
7 changed files with 70 additions and 40 deletions

View file

@ -15,7 +15,7 @@ unpack() {
pack()
{
# clean empty dirs
archive="archive_$(randalnum 5)"
archive="archive_$(randalnum 20)"
(
cd "$1" || exit $?
if [ -n "$2" ]
@ -46,8 +46,8 @@ archive_exec()
{
err=0
# tmp files
tmpdir="$TMPDIR/zpass_$(randalnum 5)"
keyfile="$tmpdir/$(randalnum 5).key"
tmpdir="$TMPDIR/zpass_$(randalnum 20)"
keyfile="$tmpdir/$(randalnum 20).key"
# operation
(
# unpack
@ -67,7 +67,7 @@ archive_exec()
create() {
if [ -f "$file" ]
then
tmpdir="$TMPDIR/zpass_$(randalnum 5)"
tmpdir="$TMPDIR/zpass_$(randalnum 20)"
# pack n repack with no tmp key: create new
unpack "$tmpdir" || return $?
pack "$tmpdir" || { echo "Encryption error" >&2 && return 1 ; }

View file

@ -20,11 +20,7 @@ get_key_cached() {
delete_cache() {
if [ "$1" -gt 0 ] 2>/dev/null
then
for I in $(screen -ls | grep "zpass_$(keyfile)" | awk '{print $1}')
do
screen -S "$I" -X stuff "^C"
done
screen -dmS "zpass_$(keyfile)" sh -c "sleep $1 ; $0 rmc" # call zpass with cache delete
nohup sh -c "sleep $1;rm -f '$cachepath/$(keyfile)'" >/dev/null 2>&1 &
else
rm -f "$cachepath/$(keyfile)" 2>/dev/null
fi

View file

@ -9,22 +9,48 @@ clipboard()
in="$in
$ln"
done
printf "%s" "$in" | xclip -selection clipboard
which wl-copy >/dev/null 2>&1 && printf "%s" "$in" | wl-copy
if [ "$XDG_SESSION_TYPE" = x11 ] ; then
printf "%s" "$in" | xclip -selection clipboard
elif [ "$XDG_SESSION_TYPE" = wayland ] ; then
printf "%s" "$in" | wl-copy
fi
}
get_clipboard() {
if [ "$XDG_SESSION_TYPE" = x11 ] ; then
xclip -selection clipboard -o
elif [ "$XDG_SESSION_TYPE" = wayland ] ; then
wl-paste
fi
}
# $1 = delay in sec
clipboard_clear() {
if [ -n "$1" ]
then
for I in $(screen -ls | grep "$fname"_clipboard | awk '{print $1}')
do
screen -S "$I" -X stuff "^C"
done
screen -dmS "$fname"_clipboard sh -c "sleep $1
xclip -selection clipboard < /dev/null
which wl-copy 2>&1 && wl-copy < /dev/null
sleep 1"
clipval=$(get_clipboard | sed 's|"|\"|g;s|\\|\\|g;' )
tmpfifo="$TMPDIR/zpass_tmpfifo_$(randalnum 20)"
mkfifo "$tmpfifo"
nohup sh -c '#LXSH_PARSE_MINIFY
pass=$(cat "$2")
rm -f "$2"
sleep $1
clip=$(
if [ "$XDG_SESSION_TYPE" = x11 ] ; then
xclip -selection clipboard -o 2>/dev/null
elif [ "$XDG_SESSION_TYPE" = wayland ] ; then
wl-paste
fi
)
[ "$clip" != "$pass" ] && exit 1
if [ "$XDG_SESSION_TYPE" = x11 ] ; then
xclip -selection clipboard < /dev/null
elif [ "$XDG_SESSION_TYPE" = wayland ] ; then
wl-copy < /dev/null
fi
' zpass_clipclear "$1" "$tmpfifo" >/dev/null 2>&1 &
get_clipboard > "$tmpfifo"
else
echo | clipboard
fi
@ -32,14 +58,15 @@ clipboard_clear() {
copy_check()
{
if ps -e | grep -qi wayland
if [ "$XDG_SESSION_TYPE" = wayland ]
then
which wl-copy >/dev/null 2>&1 || error 1 "ERROR: running wayland but wl-clipboard is not installed"
elif [ -n "$DISPLAY" ]
elif [ "$XDG_SESSION_TYPE" = x11 ]
then
which xclip >/dev/null 2>&1 || error 1 "ERROR: running X but xclip is not installed"
else
error 1 "ERROR: no graphical server detected"
fi
return 0
}

View file

@ -12,7 +12,7 @@ configpath="$HOME/.config/zpass"
[ -z "$TMPDIR" ] && TMPDIR=/tmp
# stash env config
tmpenv="$TMPDIR/zpassenv_$(randalnum 5)"
tmpenv="$TMPDIR/zpassenv_$(randalnum 20)"
env | grep '^ZPASS_.*=' | sed "s/'/'\\\''/g;s/=/='/;s/$/'/g" > "$tmpenv"
# load config file
@ -41,6 +41,7 @@ datapath="${datapath#\~/}"
[ -z "$ZPASS_REMOTE_ADDR" ] && [ "$(echo "$datapath" | cut -c1)" != '/' ] && datapath="$HOME/$datapath"
file="$datapath/$ZPASS_FILE$ZPASS_EXTENSION"
FILE=$file
[ -z "$ZPASS_REMOTE_ADDR" ] && { mkdir -p "$datapath" 2>/dev/null || error 1 "Could not create '$datapath'"; }
mkdir -p "$cachepath" 2>/dev/null && chmod -R go-rwx "$cachepath" 2>/dev/null

View file

@ -17,8 +17,8 @@ case $arg in
lsf|list-files) list_files ;;
rmf|rm-file) remove_files "$@" ;;
cc|cache-clear) clear_cache 2>/dev/null ;;
ch|cached) get_key_cached >/dev/null 2>&1 ;;
rmc|rm-cache) delete_cache 0 >/dev/null 2>&1 ;;
ch|cached) get_key_cached >/dev/null ;;
rmc|rm-cache) delete_cache 0 >/dev/null ;;
c|create) create ;;
t|tree) sanitize_paths "$@" && _tree "$@" ;;
s|set) sanitize_paths "$1" && _set "$@" ;;

View file

@ -10,7 +10,7 @@ _tree()
for N
do
[ $# -gt 1 ] && echo "> $N:"
echo "$fulltree" | grep "^$(escape_chars "$N")" | sed "s|^$N||g ; "' s|^/||g ; /\/$/d ; /^$/d'
echo "$fulltree" | grep "^$(escape_chars "$N")" | sed "s|^$N||g;s|^/||g;/\/$/d;/^$/d"
done
else
@ -22,7 +22,7 @@ _tree()
get()
{
[ $# -lt 1 ] && return 1
__NOPACK=y archive_exec sh -c '
__NOPACK=y archive_exec sh -c '#LXSH_PARSE_MINIFY
for N
do
(
@ -31,7 +31,7 @@ get()
exit 1
) || { echo "$N: not found" >&2 && exit 1; }
done
' sh "$@"
' zpass "$@"
}
# $1 = path
@ -45,13 +45,15 @@ copy()
new()
{
[ $# -lt 1 ] && return 1
archive_exec sh -c "
archive_exec sh -c '#LXSH_PARSE_MINIFY
len=$1
shift 1
for N
do
mkdir -p \"\$(dirname \"\$N\")\" || exit \$?
{ tr -cd 'a-zA-Z0-9!-.' < /dev/urandom | head -c $ZPASS_RAND_LEN && echo; } > \"\$N\" || exit \$?
mkdir -p "$(dirname "$N")" || exit $?
{ tr -cd "a-zA-Z0-9\!-." < /dev/urandom | head -c$len && echo; } > "$N" || exit $?
done
" sh "$@"
' zpass "$ZPASS_RAND_LEN" "$@"
}
# $1 = path , $@ = value
@ -60,7 +62,9 @@ _set()
[ $# -lt 1 ] && return 1
ref=$1
shift 1
archive_exec sh -c "mkdir -p '$(dirname "$ref")' && printf '%s\n' '$*' > '$ref'"
archive_exec sh -c '#LXSH_PARSE_MINIFY
mkdir -p "$(dirname "$1")" && printf "%s\n" "$2" > "$1"
' zpass "$ref" "$*"
}
add()
@ -77,13 +81,14 @@ add()
fileset()
{
contents=$(cat "$2") || return $?
_set "$1" "$2"
_set "$1" "$contents"
}
move()
{
[ $# -lt 1 ] && return 1
archive_exec sh -c 'set -e
archive_exec sh -c '#LXSH_PARSE_MINIFY
set -e
for last ; do true ; done
if [ "$#" -gt 2 ] ; then
mkdir -p "$last"
@ -91,5 +96,5 @@ move()
mkdir -p "$(dirname "$last")"
fi
mv -f -- "$@"
' sh "$@"
' zpass "$@"
}

View file

@ -30,17 +30,18 @@ sanitize_paths()
# $1 = file
getpath() {
if [ -n "$ZPASS_REMOTE_ADDR" ]
then
echo "$ZPASS_REMOTE_PORT:$ZPASS_REMOTE_ADDR:$file"
if [ -n "$ZPASS_REMOTE_ADDR" ] ; then
echo "$ZPASS_REMOTE_PORT:$ZPASS_REMOTE_ADDR:$FILE"
elif [ "$(echo "$FILE" | cut -c1)" = / ] ; then
echo "$FILE"
else
echo "$(pwd)/$file"
echo "$(pwd)/$FILE"
fi
}
# $1 = file
filehash(){
getpath "$file" | md5sum | cut -d' ' -f1
getpath "$FILE" | md5sum | cut -d' ' -f1
}
keyfile(){