-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyb_proxy
executable file
·66 lines (50 loc) · 1.75 KB
/
myb_proxy
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
#!/usr/local/bin/cbsd
MYARG=
MYOPTARG="mode"
MYDESC="Manage Proxy settings for MyBee appliance"
CBSDMODULE="myb"
ADDHELP="
${H3_COLOR}Description${N0_COLOR}:
Manage /etc/rc.conf and ~cbsd/etc/global.conf for SOCKS5_PROXY= variable.
We do not configure proxy service, settings only.
"
EXTHELP=
. ${subrdir}/tools.subr
mode=
. ${subrdir}/cbsdinit.subr
. ${subrdir}/system.subr
WHITELIST_FILE="/usr/local/etc/nginx/acl.txt"
WHITELIST_NGINX="/usr/local/etc/nginx/acl.conf"
[ ! -d /usr/local/etc/nginx ] && ${MKDIR_CMD} -p /usr/local/etc/nginx
[ ! -r ${WHITELIST_FILE} ] && ${TOUCH_CMD} ${WHITELIST_FILE}
[ ! -r ${WHITELIST_NGINX} ] && ${TOUCH_CMD} ${WHITELIST_NGINX}
[ -n "${MYIP}" ] && SHOWIP="e.g. your IP: ${MYIP}"
TEMP_FILE=$( mktemp )
${CAT_CMD} > ${TEMP_FILE} <<EOF
# use one IP per line, e.g:
# 192.168.0.1;
# 192.168.0.2;
# ${SHOWIP}
EOF
${GREP_CMD} -v '^#' ${WHITELIST_FILE} | ${GREP_CMD} . | ${GREP_CMD} -v "deny|allow" | ${SORT_CMD} -u | ${TR_CMD} -d ';' >> ${TEMP_FILE}
trap "[ -r ${TEMP_FILE} ] && ${RM_CMD} -f ${TEMP_FILE}" HUP INT ABRT BUS TERM EXIT
. ${distdir}/subr/settings-tui-virtual.subr
. ${distdir}/subr/tools.subr
# disable ACL
if [ "${mode}" = "off" ]; then
echo "allow all;" > ${WHITELIST_NGINX}
${SERVICE_CMD} nginx reload
exit 0
fi
/usr/local/bin/mcedit -b +1024 ${TEMP_FILE}
${GREP_CMD} -v ^# ${TEMP_FILE} | ${GREP_CMD} . | ${SORT_CMD} -u > ${WHITELIST_FILE}.tmp
${ECHO} "${N1_COLOR}${CBSD_APP}: whitelist changed${N0_COLOR}"
${ECHO} "${N1_COLOR}Install new whitelist..${N0_COLOR}"
${MV_CMD} ${WHITELIST_FILE}.tmp ${WHITELIST_FILE}
${TRUNCATE_CMD} -s0 ${WHITELIST_NGINX}
${GREP_CMD} . ${WHITELIST_FILE} | while read _ip; do
echo "allow ${_ip};" >> ${WHITELIST_NGINX}
done
echo "deny all;" >> ${WHITELIST_NGINX}
${SERVICE_CMD} nginx reload
exit 0