forked from al-caughey/YAMon-v4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alias.sh
116 lines (99 loc) · 3.55 KB
/
alias.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
#!/bin/sh
##########################################################################
# Yet Another Monitor (YAMon)
# Copyright (c) 2013-present Al Caughey
# All rights reserved.
#
# some useful aliases and shortcuts
# run: manually
# History
# 2020-01-26: 4.0.7 - replaced hard coded paths (thx tvlz)
# 2020-01-03: 4.0.6 - added fix (to launch run-fixes.sh)
# 2019-12-23: 4.0.5 - added blocked alias; separated block & unblock; added duration option to block and unblock; added syntax description and rudimentary error trapping for group name
# 2019-11-24: 4.0.4 - no changes (yet)
# 2019-06-18: development starts on initial v4 release
#
##########################################################################
d_baseDir=$(cd "$(dirname "$0")" && pwd)
[ -z "$(echo "$d_baseDir" | grep -i 'yamon')" ] && d_baseDir='/opt/YAMon4'
alias clearlog='> /tmp/yamon/yamon.log'
alias comp='${d_baseDir}/compare.sh'
alias copylog='${d_baseDir}/copy-log.sh'
alias cpa="cp ${d_baseDir}/alias.sh $HOME/.profile ; . $HOME/.profile"
alias fif='${d_baseDir}/fif.sh $1'
alias fix='${d_baseDir}/run-fixes.sh'
alias ipt='iptables -L YAMONv40 -vnx'
alias ip6='ip6tables -L YAMONv40 -vnx'
alias pau='${d_baseDir}/pause.sh'
alias psg="pscpa | grep -v grep | grep -i -e VSZ -e"
alias psy='ps | grep -v grep | grep YAMon'
alias sta='${d_baseDir}/start.sh'
alias setp='${d_baseDir}/setPaths.sh'
rr(){
${d_baseDir}/$1.sh
}
blocked(){
local bt=$(iptables -L | grep blocked -B 2)
if [ -z "$bt" ] ; then
echo ">>>Nothing is currently blocked"
else
echo -e ">>>The following chains are currently blocked:\n$bt"
fi
}
block(){
chainName=${1:-Unknown}
status='DROP'
duration=${2:-0}
gpl=$(echo $( iptables -L | grep 'Chain YAMONv40_' | awk '{print $2}' | cut -d'_' -f2))
if [ -z "${1}" ] ; then
echo -e "block --> prevent devices from accessing the web
Syntax: block <group> [<duration>]
- <group>: group name as defined in the YAMon reports (see below)
- <duration> [optional]: length of time (in minutes) to restrict access
(if null, access will be blocked indefinitely or until the end of
the next scheduled blockage)
Currently defined groups: "
echo ' -->' ${gpl// /, }
echo ''
return
fi
[ "$duration" -gt "0" ] && ds=" for $duration min"
echo "Blocking: $chainName $ds"
if [ -z "$(echo $gpl | grep "\b$chainName\b")" ] ; then
echo "Uh oh!!!! \`$chainName\` does not appear in the current list of groups
--> ${gpl// /, }"
return
fi
${d_baseDir}/block.sh "$chainName" "$status" "$duration"
iptables -L YAMONv40_$1 | grep -v "^target"
}
unblock(){
chainName=${1:-Unknown}
status='RETURN'
duration=${2:-0}
gpl=$(echo $( iptables -L | grep 'Chain YAMONv40_' | awk '{print $2}' | cut -d'_' -f2))
if [ -z "${1}" ] ; then
echo -e "unblock --> allow blocked devices to access the web
Syntax: unblock <group> [<duration>]
- <group>: group name as defined in the YAMon reports (see below)
- <duration> [optional]: length of time (in minutes) to allow access
(if null, access will be allowed indefinitely or until the start of
the next scheduled blockage)
Currently defined groups: "
echo ' -->' ${gpl// /, }
echo ''
return
fi
echo "Unblocking: $chainName"
if [ -z "$(echo $gpl | grep "\b$chainName\b")" ] ; then
echo "Uh oh!!!! \`$chainName\` does not appear in the current list of groups
--> ${gpl// /, }"
return
fi
${d_baseDir}/block.sh "$chainName" "$status" "$duration"
iptables -L YAMONv40_$1 | grep -v "^target"
}
echo "************************************************
************* Bash Aliases loaded **************
************************************************
"