Variable name reworking; laid foundation for GPG encryption (instead of OpenSSL)

This commit is contained in:
Jon-William Lewis
2016-01-25 17:20:05 -06:00
parent 908b93242c
commit 6a21731082
12 changed files with 180 additions and 102 deletions

View File

@@ -3,7 +3,7 @@ function create(){
printf "\nERROR: Note already exists\nHint: use -e to edit the note.\n"
exit
else
mkdir -p "$NOTEDIR"
mkdir -p "$NOTE_DIR"
fi
if [ -z "$ENCRYPTION" ]; then

View File

@@ -1,6 +1,10 @@
function w_conf {
if [ ! -r "$ROOTDIR" ]; then mkdir -p "$ROOTDIR"; fi
cat > "$CONFIGURATION" << EOF
if [ ! -r "$ROOT_DIR" ]; then mkdir -p "$ROOT_DIR"; fi
if [ ! -d "$TMP_DIR" ]; then mkdir -p "$TMP_DIR" ; fi
cat > "$CONFIG_FILE" << EOF
#==========================================================
# Simple Note System Config, v2.0a5
# Copyright 2014, Xenese Labs/Sicron-Perion XNF
@@ -16,9 +20,12 @@ fi
#Encryption
#WARNING: ANY PREVIOUSLY UNENCRYPTED NOTES WILL BE LOST
#ENCRYPTION="TRUE"
ENCRYPTION="FALSE"
ENC_KEY=""
PUBKEY=""
EOF
chmod 600 "$CONFIGURATION"
chmod 600 "$CONFIG_FILE"
}

View File

@@ -1,8 +1,18 @@
function encrypt(){
openssl enc -aes-256-cbc -salt -in "$TARGET" -out "$NOTE" -pass pass:"$ENC_KEY"
# This function, given a recipient, $PUBKEY; a file to encrypt, $TARGET; and an
# output file, "$NOTE", will encrypt $TARGET to $NOTE against $PUBKEY's private
# GPG key.
gpg -r "$PUBKEY" --encrypt-files "$TARGET" --output "$NOTE"
}
function decrypt(){
TARGET="$ROOTDIR"/tmp/"$RANDOM"
openssl enc -d -aes-256-cbc -in "$NOTE" -pass pass:"$ENC_KEY" > "$TARGET"
# This function, given a recipient, $PUBKEY; a file to decrypt, $TARGET; and an
# output file, "$NOTE", will decrpyt $TARGET to $NOTE against $PUBKEY's private
# GPG key.
if [ ! -d "$ROOT_DIR"/tmp ]; then mkdir "$ROOT_DIR"/tmp; fi
TARGET="$TMP_DIR/$RANDOM"
gpg -d "$NOTE" > "$TARGET"
}

View File

@@ -1,11 +1,15 @@
function list(){
if [ -d "$BASEDIR"/"$NOTEBOOK" ]; then
if [ -d "$BASE_DIR"/"$NOTEBOOK" ]; then
printf "\nNotes in %s:\n" "$(basename "$NOTEBOOK")"
NOTES=( $(find "$BASEDIR"/"$NOTEBOOK" -name "*.$EXT" -print0 | sed s:"$BASEDIR"/"$NOTEBOOK"/: " " :g | sed -e s:".$EXT"::g | tr "/" " ") )
NOTES=(
$(find "$BASE_DIR"/"$NOTEBOOK" -name "*.$EXT" -print0 |\
sed s:"$BASE_DIR"/"$NOTEBOOK"/: " " :g |\
sed -e s:".$EXT"::g | tr "/" " ")
)
let i=0
for NOTE in "${NOTES[@]}"; do
if [ -d "$BASEDIR"/"$NOTEBOOK"/"$NOTE" ]; then
if [ -d "$BASE_DIR"/"$NOTEBOOK"/"$NOTE" ]; then
if [ "$LAST_SECTION" != "$NOTE" ]; then
printf " Section: %s\n" "$NOTE"
fi

View File

@@ -1,4 +1,4 @@
function pause {
read -p " Press [Enter] to continue."
read -rp " Press [Enter] to continue."
echo ""
}

View File

@@ -1,30 +1,33 @@
#==============================================================================
# Section: Configuration
# Section: Configuration / Stage 1
#==============================================================================
if [ -r "$CONFIGURATION" ]; then
source "$CONFIGURATION"
if [ -r "$CONFIG_FILE" ]; then
source "$CONFIG_FILE"
else
w_conf
source "$CONFIGURATION"
create_sns_root
source "$CONFIG_FILE"
fi
if [ "$ENCRYPTION" == "TRUE" ]; then
if [ -z "$ENC_KEY" ]; then
ERR_NO_KEY="TRUE"
ENCRYPTION="FALSE"
fi
command -v openssl >/dev/null 2>&1 || { ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; }
if [ -z "$PUBKEY" ]; then
ERR_NO_KEY="TRUE"
ENCRYPTION="FALSE"
fi
command -v openssl >/dev/null 2>&1 ||\
{ ERR_NO_SSL="TRUE"; ENCRYPTION="FALSE"; }
fi
if [ "$ENCRYPTION" == "TRUE" ]; then
PROD_STR="Simple Note System (Encryption Enabled)"
EXT="$EXT"
if [ ! -d "$BASEDIR"/tmp ]; then
mkdir -p "$BASEDIR"/tmp
fi
PROD_STR="Simple Note System (Encryption Enabled)"
EXT="$EXT".gpg
if [ ! -d "$BASE_DIR"/tmp ]; then
mkdir -p "$BASE_DIR"/tmp
fi
fi
echo "$PROD_STR, $VER_STR"
if [ -n "$ERR_NO_SSL" ]; then
echo >&2 " Warning: OpenSSL not installed. Encryption disabled."
fi
@@ -37,5 +40,5 @@ pause
fi
#==============================================================================
# End Section: Configuration
# End Section: Configuration / Stage 1
#==============================================================================

View File

@@ -1,5 +1,5 @@
#==============================================================================
# Section: Argument Parsing
# Section: Argument Parsing / Stage 2
#==============================================================================
NAME=""
@@ -16,7 +16,7 @@ else
elif [ "$ARG" = "-p" ] || [ "$ARG" = "--print" ]; then PRINT="TRUE"
elif [ "$ARG" = "-l" ] || [ "$ARG" = "--list" ]; then LIST="TRUE"
elif [ "$ARG" = "-h" ] || [ "$ARG" == "--help" ]; then help; exit 0
elif [ "$ARG" = "-w" ] || [ "$ARG" == "--wconf" ]; then w_conf; exit 0
elif [ "$ARG" = "-w" ] || [ "$ARG" == "--wconf" ]; then create_sns_root; exit 0
else
if [ -z "$NAME" ] && [ -n "$ARG" ]; then NAME="$ARG"
elif [ -z "$NOTEBOOK" ] && [ -n "$ARG" ]; then NOTEBOOK="$ARG"
@@ -37,5 +37,5 @@ fi
# that can work without any arguments.
#==============================================================================
# End Section: Argument Parsing
# End Section: Argument Parsing / Stage 2
#==============================================================================

View File

@@ -1,6 +1,6 @@
# Help requires no arguments, and is exclusive.
if [ -n "$HELP" ]; then help; exit 0; fi
#==============================================================================
# Section: Actions / Stage 3
#==============================================================================
# List only requires a notebook, and is exclusive.
if [ -z "$NOTEBOOK" ]; then
echo " ERROR: Insufficient arguments:"
@@ -21,11 +21,16 @@ if [ -z "$NAME" ]; then
exit 30
fi
NOTEDIR="$BASEDIR"/"$NOTEBOOK"/"$SECTION"/
NOTE="$NOTEDIR""$NAME"."$EXT"
SESSION_ID="$RANDOM"
NOTE_DIR="$BASE_DIR"/"$NOTEBOOK"/"$SECTION"/
NOTE="$NOTE_DIR""$NAME"."$EXT"
if [ "$ENCRYPTION" == "TRUE" ]; then NOTE="$NOTE".enc; fi
if [ "$PRINT" == "TRUE" ]; then print; exit 0; fi
if [ "$DELETE" == "TRUE" ]; then delete; exit 0; fi
if [ "$CREATE" == "TRUE" ]; then create; fi
if [ "$EDIT" == "TRUE" ]; then edit; fi
if [ "$EDIT" == "TRUE" ]; then edit; fi
#==============================================================================
# End Section: Actions / Stage 3
#==============================================================================