diff options
Diffstat (limited to 'jsaccess/jstore.sh')
-rwxr-xr-x | jsaccess/jstore.sh | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/jsaccess/jstore.sh b/jsaccess/jstore.sh index 6f270c4..a82780c 100755 --- a/jsaccess/jstore.sh +++ b/jsaccess/jstore.sh @@ -17,7 +17,7 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -VERSION=0.2 +VERSION=0.3 PROHIBITED_FILE_NAMES="index.html index.txt" @@ -31,6 +31,7 @@ usage_exit() { echo " add-nocrypt <file> [store]" echo " rm <file_in_store> [store]" echo " rmall [store]" + echo " edit [store]" echo echo "actions on local store for all passphrases:" echo " init <store>" @@ -121,6 +122,43 @@ _index_encrypt() { echo "UPDATED file $enc_path/index.txt" } +_index_read() { + clear_name=$1 + index_entry=`egrep "^$clear_name .*$" $tmp 2>/dev/null` + if [ X"$index_entry" = X"" ]; then + echo "File does not exist for this passphrase" + clean_exit 1 + fi + meta=`echo $index_entry |awk '{ print $(NF) }' |sed s/"(\(.*\))"/\\\1/g` + size=`echo $meta |cut -d',' -f1` + crypt=`echo $meta |cut -d',' -f2` +} + +_index_check() { + clear_name=$1 + if [ `egrep -c "^$clear_name .*$" $tmp` -ne 0 ]; then + echo "File already present with this passphrase" + clean_exit 1 + fi +} + +_index_add() { + clear_name=$1 + size=$2 + do_crypt=$3 + if [ $do_crypt -eq 0 ]; then + index_text="$clear_name ($size,nocrypt)" + else + index_text="$clear_name ($size,base64+aes256)" + fi + echo $index_text >> $tmp +} + +_index_rm() { + clear_name=$1 + sed -i /"^$clear_name .*$"/d $tmp +} + __file_get_encname() { clear_name=$1 enc_name=`echo -n ${enc_dir_hash}${clear_name} |openssl rmd160 |cut -d' ' -f2` @@ -195,18 +233,15 @@ action_add() { clean_exit 1 _pass_read _index_decrypt - if [ `egrep -c "^$clear_name .*$" $tmp` -ne 0 ]; then - echo "File already present with this passphrase" - clean_exit 1 - fi + _index_check $clear_name _file_add $clear_path $clear_name $do_crypt _index_decrypt - if [ $do_crypt -eq 0 ]; then - index_text="$clear_name (nocrypt)" + if [ $do_crypt -eq 1 ]; then + size=`ls -sh $enc_path/$enc_name |cut -d' ' -f1` else - index_text="$clear_name (base64+aes256)" + size=`ls -sh $clear_path |cut -d' ' -f1` fi - echo $index_text >> $tmp + _index_add $clear_name $size $do_crypt _index_encrypt } @@ -214,16 +249,11 @@ action_rm() { clear_name=$1 _pass_read _index_decrypt - index_entry=`egrep "^$clear_name .*$" $tmp 2>/dev/null` - if [ X"$index_entry" = X"" ]; then - echo "File does not exist for this passphrase" - clean_exit 1 - fi - crypt=`echo $index_entry |awk '{ print $(NF) }'` - [ $crypt = "(nocrypt)" ] && do_crypt=0 || do_crypt=1 + _index_read $clear_name + [ $crypt = "nocrypt" ] && do_crypt=0 || do_crypt=1 _file_rm $clear_name $do_crypt _index_decrypt - sed -i /"^$clear_name .*$"/d $tmp + _index_rm $clear_name _index_encrypt } |