forked from eastmaple/easytrojan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmytrojan.sh
63 lines (61 loc) · 1.88 KB
/
mytrojan.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
#!/bin/bash
#
# Notes: EasyMyTrojan for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
#
# Project home page:
# https://github.com/eastmaple/easytrojan
[ "$(id -u)" != "0" ] && { echo "Error: You must be root to run this script"; exit 1; }
case $1 in
add)
shift
for i in "$@" ; do
if curl -X POST -H "Content-Type: application/json" -d "{\"password\": \"$i\"}" http://127.0.0.1:2019/trojan/users/add ; then
echo "$i" >> /etc/caddy/trojan/passwd.txt &&
sort /etc/caddy/trojan/passwd.txt | uniq > /etc/caddy/trojan/passwd.tmp &&
mv -f /etc/caddy/trojan/passwd.tmp /etc/caddy/trojan/passwd.txt &&
echo "Add Succeeded"
else
echo "Add $i Failed"
fi
done
;;
del)
shift
for i in "$@" ; do
if curl -X DELETE -H "Content-Type: application/json" -d "{\"password\": \"$i\"}" http://127.0.0.1:2019/trojan/users/delete ; then
sed -i "/^${i}$/d" /etc/caddy/trojan/passwd.txt &&
echo "Delete Succeeded"
else
echo "Delete $i Failed"
fi
done
;;
status)
shift
for i in "$@" ; do
hash=$(echo -n "$i" | sha224sum | cut -d ' ' -f1)
echo "$i data usage: $(cat /etc/caddy/trojan/"$hash")"
done
;;
rotate)
mkdate=$(date +%Y%m%d-%H%M%S)
cpdate=$(find /etc/caddy/trojan -maxdepth 1 -type f -not -path "*passwd.txt*")
mkdir -p /etc/caddy/trojan/data/"$mkdate"
for alldate in $cpdate; do
cp -f "$alldate" /etc/caddy/trojan/data/"$mkdate" &&
sed -i -r -e "s|[0-9]+|0|g" "$alldate"
done
echo "Clear all data usage successful"
;;
list)
cat /etc/caddy/trojan/passwd.txt
;;
*)
echo "Command Examples:"
echo "./mytrojan.sh add passwd1 passwd2 ..."
echo "./mytrojan.sh del passwd1 passwd2 ..."
echo "./mytrojan.sh status passwd1 passwd2 ..."
echo "./mytrojan.sh rotate"
echo "./mytrojan.sh list"
;;
esac