forked from FMainz/iptraffic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
210 lines (180 loc) · 4.75 KB
/
install
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
# ipcop addon installer for IPfire
#
# created 01 January 2005 by Frank 'Darkmann' Koch <darkmann@black-empire.de>
# modified 02 January 2005 by Tom 'wintermute' Eichstaedt <wintermute@tom-e.de>
#
# extended 2006-02-24 by weizen_42
# even more modifications 2009-2011 by weizen_42
# more modifications 2014/2015 by RadioCarbon
# ported for IPFire 2020 by RadioCarbon
#
#####################################################################################################
#
# IPTraffic Addon for IPFire v2.x, 2020 by Frank Mainz (RadioCarbon)
#
# Mail : ipfire@cybermainzel.de
# URL : http://www.cybermainzel.de
#
# Version : v0.2
# Date : December 01, 2020
#
#####################################################################################################
CMD="$1"
path=`pwd`
addonname=iptraffic
addon=/var/ipfire/$addonname
cgi=/srv/web/ipfire/cgi-bin
html=/srv/web/ipfire/html
images=$html/images/$addonname
graphs=$html/graphs/$addonname
rrd=/var/log/rrd/$addonname
cron=/etc/fcron.minutely/$addonname
log=/var/log/$addonname
pics=(addblue.gif addfaint.gif addgray.gif addgreen.gif addorange.gif addred.gif blue.png graph.png gray.png green.png orange.png red.png)
#
RED="\\033[01;31m"
GREEN="\\033[01;32m"
BLUE="\\033[1;34m"
GREY="\\033[0m"
#error handling
err()
{
echo " "
echo "Error : $1 "
echo " "
echo "Choose your option:"
echo " "
echo "./install -i ---> to install"
echo "./install -u ---> to uninstall"
echo " "
exit
}
# installation
ai()
{
## verify already installed or uninstall
if [ -e $cgi/iptraffic.cgi ]; then
echo "Upgrading"
au
fi
echo "Copying images"
mkdir -p $images
chown -R nobody:nobody $images
for wert in "${pics[@]}"
do
cp -p $path/$addonname/$wert $images/$wert
chmod 644 $images/$wert
done
echo "Create graphs dir"
mkdir -p $graphs
chown -R nobody:nobody $graphs
echo "Copying Addon-files"
mkdir -p $addon
chown nobody:nobody $addon
cp -p iptraffic.pl $addon/iptraffic.pl
chown root.root $addon/iptraffic.pl
chmod 755 $addon/iptraffic.pl
if [ ! -d $log ]; then
mkdir -p $log
fi
if [ ! -e $log/iptraffic.db ]; then
touch $log/iptraffic.db
fi
chown -R nobody:nobody $log
if [ ! -d $rrd ]; then
mkdir -p $rrd
chown nobody:nobody $rrd
fi
# supported languages
echo "Adding language texts"
addtolanguage IPTraffic en,de lang
echo "Add CGI"
$subipfire->{'70.iptraffic'} = {
'caption' => $Lang::tr{'IPTraffic'},
'uri' => '/cgi-bin/iptraffic.cgi',
'title' => $Lang::tr{'IPTraffic'},
'enabled' => 1,
};
# run iptraffic.pl every 5 mins
echo "Adding cron job"
if [ ! -d $cron ]; then
mkdir -p $cron
chown nobody:nobody $cron
fi
}
# update
au()
{
if [ ! -e $cgi/iptraffic.cgi ]; then
echo "IPTraffic addon is not installed !"
exit
fi
echo "Remove CGI"
removecgi iptraffic.cgi
rm -r $images
rm -r $graphs
rm -r $addon
rm -r $log
rm -r $rrd
# remove cron job
echo "Removing cron job"
removefromfile IPTraffic $cron
# remove languages
echo "Removing language texts"
removefromlanguage IPTraffic
dbtest=`sqlite3 /var/log/iptraffic/iptraffic.db .fullschema | grep port`
if [ -z "$dbtest" ]; then
sqlite3 /var/log/iptraffic/iptraffic.db "ALTER TABLE 'IPTraffic' ADD port INT UNSIGNED;"
fi
}
# deinstallation
ar()
{
if [ ! -e $cgi/iptraffic.cgi ]; then
echo "IPTraffic addon is not installed !"
exit
fi
echo "Remove CGI"
removecgi iptraffic.cgi
rm -r $images
rm -r $graphs
rm -r $addon
rm -r $log
rm -r $rrd
# remove cron job
echo "Removing cron job"
removefromfile IPTraffic $cron
# remove languages
echo "Removing language texts"
removefromlanguage IPTraffic
# remove rules
echo "Removing IPTraffic rules"
number=iptables -L INPUT --line-numbers | grep CUSTOMINPUT | awk '{print $1}'
iptables -D INPUT $number
number=iptables -L OUTPUT --line-numbers | grep CUSTOMOUTPUT | awk '{print $1}'
iptables -D OUTPUT $number
number=iptables -L FORWARD --line-numbers | grep CUSTOMFORWARD | awk '{print $1}'
iptables -D FORWARD $number
}
case $CMD in
-i|i|install)
echo " "
echo "Installing now ..."
ai
echo "Successfully done!"
echo " ";;
-u|u|uninstall)
echo " "
echo "Deinstalling addon now ..."
ar
# reinstall fcrontab
fcrontab -z
rm -rf /var/ipcop/addons/iptraffic
echo "Successfully done!"
echo " ";;
*)
err "Invalid Option";;
esac
sync
#end of file