summaryrefslogtreecommitdiff
path: root/fancyIP
diff options
context:
space:
mode:
Diffstat (limited to 'fancyIP')
-rwxr-xr-xfancyIP72
1 files changed, 49 insertions, 23 deletions
diff --git a/fancyIP b/fancyIP
index b6521e7..d727ab7 100755
--- a/fancyIP
+++ b/fancyIP
@@ -35,8 +35,43 @@ containsElement () {
}
showDB () {
- getcomment=$(sqlite3 $filename "SELECT * FROM iplist;")
- echo "$getcomment"
+ kip=()
+ ipc=()
+ uip=()
+ OLDIFS=$IFS
+ IFS=$'\n'
+ getall=$(sqlite3 $filename "SELECT * FROM iplist;")
+ #split into lines
+ IFS=$'\n' read -r -a allin <<< "getall"
+ for f in ${getall[@]}; do
+ IFS=$'|' read -r -a line <<< "$f"
+ if [[ "${line[3]}" == "empty" ]]; then
+ #echo "emp ${line[1]} ${line[3]}"
+ uip+=("${line[1]}")
+ else
+ #echo "some ${line[1]} ${line[3]}"
+ kip+=("${line[1]}")
+ ipc+=("${line[3]}")
+ fi
+ #echo "$f"
+ #IFS=$'\n'
+ done
+ echo " === ${green}Identified${reset} Addresses ==="
+ for v in "${!kip[@]}"
+ do
+ echo "${kip[$v]} : ${ipc[$v]}"
+ done
+ echo " === ${tan}Known${reset} Addresses ==="
+ for v in "${uip[@]}"
+ do
+ echo "$v"
+ done
+ #IFS='\n' read -ra outl <<< "$getcomment"
+ #for i in "${outl[@]}"; do
+ # echo "$i"
+ # done
+ #echo "$getcomment"
+ IFS=$OLDIFS
}
commentDB () {
@@ -132,11 +167,9 @@ if [ $# -eq 0 ] && [ -t 0 ]; then
esac
else
case $comm in
- c | comment) #echo "$part comments?"
- commentDB $part
+ c | comment) commentDB $part
;;
- d | delete) #echo "delete shiti $part"
- removeDB $part
+ d | delete) removeDB $part
;;
*) usage >&2
exit 1
@@ -144,13 +177,10 @@ if [ $# -eq 0 ] && [ -t 0 ]; then
esac
fi
ITER=$(expr $ITER + 1)
- #$ITER+=1
- #shift
done
done
exit
fi
-#else
#Any Other Posix shell call with arguments show help
if [ -t 0 ]; then
@@ -184,15 +214,18 @@ done
# Yourcode here
#find current terminal
-#PPID=`ps -o ppid -p $$ 2>/dev/null`
-PPID=$$
+#PPID=`ps -o ppid -p $$`
+#PPID=$$
if [ $verbose -eq 1 ]; then
- echo parent PID $PPID
+ # echo parent PID $PPID
+ echo parent PID $$
fi
-PTTY=`ps -p $PPID -o tty --no-headers`
+#PTTY=`ps -p $PPID -o tty --no-headers`
+PTTY=`ps -p $$ -o tty --no-headers`
if [ $verbose -eq 1 ]; then
echo parent TTY $PTTY
fi
+
#Empty arrays to be filled
iparray=()
niparray=()
@@ -234,18 +267,15 @@ do
replacement="${red}"
getcomment=$(sqlite3 $filename "INSERT INTO iplist (ip,comment) VALUES ('$u','empty');")
niparray+=("${red}$u${reset} is yet unknown")
- #echo "${red}$u${reset} is yet unknown"
else
#if no usercomment has been set colour it tan
if [[ "${getcomment// }" == "empty" ]]; then
replacement="${tan}"
niparray+=("${tan}$u${reset} is known but unidentified")
- #echo "$u is known but unidentified"
else
#use green and display comment
replacement="${green}"
niparray+=("${green}$u${reset} is $getcomment")
- #echo "$u is $getcomment"
fi
fi
@@ -272,7 +302,6 @@ if [ $bottom -eq 0 ] && [ $silent -eq 0 ]; then
echo " "
fi
-
for v in "${outarray[@]}"
do
echo "$v"
@@ -297,17 +326,16 @@ if [ $nocomment -eq 0 ]; then
[yY][eE][sS]|[yY]) echo "Enter New Comments or leave empty for unchanged comments"
break
;;
- [nN][oO]|[nN]) #echo "You said $response"
- exit
- #break
+ [nN][oO]|[nN]) exit
;;
- *) #usage >&2
+ *)
#exit 1
;;
esac
shift
done < /dev/$PTTY
+ #Step through all ips in iparray and read new comments
ITER=0
for v in "${iparray[@]}"
do
@@ -317,10 +345,8 @@ if [ $nocomment -eq 0 ]; then
if [[ ! -z "${comm// }" ]]; then
putcomment=$(sqlite3 $filename "UPDATE iplist SET comment = '$comm' WHERE ip = '$v';")
- #echo "Not Empty :'$comm'"
break
else
- #echo "Empty :'$comm'"
break
fi
done < /dev/$PTTY