-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpass_mgt.sh
executable file
·185 lines (134 loc) · 3.76 KB
/
pass_mgt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
trap ctrl_c INT
function ctrl_c() {
echo "** WARNING HIT CTRL^C MAKE LOSS YOUR pass.enc File **"
}
file="pass.txt"
filenc="pass.enc"
if [ ! -f "$filenc" ];then
echo "file pass.enc not found"
echo "please create password for db pass.enc"
echo "" | openssl aes-256-cbc -a -salt > pass.enc
fi
echo "please enter password for db pass.enc"
cat pass.enc | openssl aes-256-cbc -a -d > $file
if [ "$?" == "0" ];then
#echo -e "This text is ${RED}red${NONE} and ${GREEN}green${NONE} and ${BOLD}bold${NONE} and ${UNDERLINE}underlined${NONE}."
echo "-------------------------------";
echo "Password utilities with OpenSSL";
echo "-------------------------------";
echo "1. Add Entry. ";
echo "2. See Entry ";
echo "3. Delete Entry ";
echo "4. Quit ";
echo "-------------------------------";
echo -n "Choose Menu (1/2/3/4): "
read menu
NONE='\033[00m'
RED='\033[01;31m'
GREEN='\033[01;32m'
YELLOW='\033[01;33m'
PURPLE='\033[01;35m'
CYAN='\033[01;36m'
WHITE='\033[01;37m'
BOLD='\033[1m'
UNDERLINE='\033[4m'
until [ "$menu" == "4" ];
do
file="pass.txt"
count=`wc -l $file | awk '{print $1}'`
num=`expr $count + 1`
cat $file | awk -F \. '{print $1}' | grep $num > /dev/null
until [ "$?" == "1" ];
do
num=`expr $num + 1`
cat $file | awk -F \. '{print $1}' | grep $num > /dev/null
done
if [ "$menu" == "1" ];
then
echo -n "Entry Name: "
read entry
echo -n "Username: "
read username
echo -n "Pass: "
read pass
echo -n "$num. $entry:" >> $file
echo "$username:$pass" | openssl aes-256-cbc -a -salt >> $file
cat $file | grep $num > /dev/null
if [ "$?" == "0" ];then
echo -e "${GREEN}New entry was added${NONE}";
else
echo -e "${RED}New entry can't added${NONE}";
fi
fi
if [ "$menu" == "2" ];
then
cat $file | awk -F \: '{print $1}'
echo "-----------------";
echo -n "Choose entry number: ";
read numkey
cat pass.txt | grep $numkey > /dev/null
if [ "$?" == "0" ];then
numkey=`grep -w "${numkey}\." pass.txt -n | cut -d \: -f 1`
tail -n+$numkey $file | head -n1 | cut -d \: -f 2 | openssl aes-256-cbc -a -d
if [ "$?" == "1" ];then
echo "Wrong Password";
fi
else
echo -e "${RED}Entry number that you select does not exist${NONE}"
fi
fi
if [ "$menu" == "3" ];
then
cat $file | awk -F \: '{print $1}'
echo "-----------------";
echo -n "Choose entry number: ";
read numkey
cat pass.txt | grep $numkey > /dev/null
if [ "$?" == "0" ];then
numkey=`grep -w "${numkey}\." pass.txt -n | cut -d \: -f 1`
tail -n+$numkey $file | head -n1 | cut -d \: -f 2 | openssl aes-256-cbc -a -d
if [ "$?" == "0" ];then
sed "${numkey}d" $file > .tmpass.txt && mv -f .tmpass.txt $file
echo -e "${GREEN}Deleted.${NONE}";
else
echo -e "${RED}Wrong Password ${NONE}";
fi
else
echo -e "${RED}Entry number that you select does not exist${NONE}"
fi
fi
file="pass.txt"
echo "-------------------------------";
echo "Password utilities with OpenSSL";
echo "-------------------------------";
echo "1. Add Entry. ";
echo "2. See Entry ";
echo "3. Delete Entry ";
echo "4. Quit ";
echo "-------------------------------";
echo -n "Choose Menu (1/2/3/4): "
read menu
NONE='\033[00m'
RED='\033[01;31m'
GREEN='\033[01;32m'
YELLOW='\033[01;33m'
PURPLE='\033[01;35m'
CYAN='\033[01;36m'
WHITE='\033[01;37m'
BOLD='\033[1m'
UNDERLINE='\033[4m'
done
echo "Enter password for db pass.enc file";
cat pass.txt | openssl aes-256-cbc -a -salt > pass.enc
until [ "$?" == "0" ];
do
echo "Enter password for db pass.enc file";
cat pass.txt | openssl aes-256-cbc -a -salt > pass.enc
done
rm -rf pass.txt
echo "---best of password storage is the brain of your head given by God Almighty--"
else
echo "Wrong password for db pass.enc file";
rm -rf pass.txt;
fi