Subversion Repositories ALCASAR

Rev

Rev 2466 | Rev 2470 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
672 richard 1
#!/bin/bash
62 franck 2
# $Id: alcasar-uninstall.sh 2467 2017-12-24 16:12:53Z richard $
3
 
1 root 4
# alcasar-uninstall.sh
672 richard 5
# by Franck BOUIJOUX, Pascal LEVANT and Richard REY
1 root 6
# This script is distributed under the Gnu General Public License (GPL)
518 stephane 7
 
2206 richard 8
# Désisntallation ou mise à jour d'ALCASAR
9
# Uninstall or update ALCASAR
672 richard 10
 
88 richard 11
SED="/bin/sed -i"
2206 richard 12
 
2464 richard 13
init ()
14
{
15
	echo -en "(3) : "
16
	rm -f /root/ALCASAR* && echo -n "1, " # The files in /usr/local/ will be removed at the end (still usefull here)
17
	[ -e /boot/grub2/user.cfg ] && rm -f /boot/grub2/user.cfg && echo -n "2, "
18
	[ -e /root/grub.default ] && mv -f /root/grub.default /etc/grub.d/10_linux && echo -n "3"
19
}
20
 
21
ACC ()
22
{
23
	echo -en "(11) : "
24
	[ -d /var/www/html ] && rm -rf /var/www/html && echo -n "1, "
25
	[ -d /etc/freeradius-web ] && rm -rf /etc/freeradius-webl && echo -n "2, "
26
	[ -e /etc/php.ini.default ] && mv -f /etc/php.ini.default /etc/php.ini && echo -n "3, "
27
	[ -e /etc/httpd/conf/httpd.conf.default ] && mv /etc/httpd/conf/httpd.conf.default /etc/httpd/conf/httpd.conf && echo -n "4, "
28
	[ -e /etc/httpd/conf/modules.d/00_base.conf.default ] && mv /etc/httpd/conf/modules.d/00_base.conf.default /etc/httpd/conf/modules.d/00_base.conf && echo -n "5, "
29
	[ -e /etc/httpd/conf/conf.d/ssl.conf.default ] && mv /etc/httpd/conf/conf.d/ssl.conf.default /etc/httpd/conf/conf.d/ssl.conf && echo -n "6, "
30
	[ -e /etc/httpd/conf/conf.d/multilang-errordoc.conf.default ] && mv /etc/httpd/conf/conf.d/multilang-errordoc.conf.default /etc/httpd/conf/conf.d/multilang-errordoc.conf && echo -n "7, "
31
	[ -e /usr/share/httpd/error/include/top.html.default ] && mv /usr/share/httpd/error/include/top.html.default /usr/share/httpd/error/include/top.html && echo -n "8, "
32
	[ -e /usr/share/httpd/error/include/bottom.html.default ] && mv /usr/share/httpd/error/include/bottom.html.default /usr/share/httpd/error/include/top.html && echo -n "9, "
33
	[ -d /usr/local/etc/digest ] && rm -rf /usr/local/etc/digest && echo -n "10, "
34
	[ -e /etc/httpd/conf/webapps.d/alcasar.conf ] && rm -f /etc/httpd/conf/webapps.d/alcasar.conf && echo -n "11"
35
}
36
 
37
CA ()
38
{
39
	echo -en "(5) : "
40
	[ -e /etc/pki/CA/alcasar-ca.crt ] && rm -f /etc/pki/CA/alcasar-ca.crt && echo -n "1, "
41
	[ -e /etc/pki/CA/private/alcasar-ca.key ] && rm -f /etc/pki/CA/private/alcasar-ca.key && echo -n "2, "
42
	[ -e /etc/pki/tls/certs/alcasar.crt ] && rm -f /etc/pki/tls/certs/alcasar.crt && echo -n "3, "
43
	[ -e /etc/pki/tls/private/alcasar.key ] && rm -f /etc/pki/tls/private/alcasar.key && echo -n "4, "
44
	[ -e /etc/httpd/conf/vhosts-ssl.default ] && FIC_VIRTUAL_SSL=`find /etc/httpd/conf -type f -name *default_ssl_vhost.conf` && mv /etc/httpd/conf/vhosts-ssl.default $FIC_VIRTUAL_SSL && echo -n "5"
45
}
46
 
47
time_server ()
48
{
49
	echo -en "(2) : "
50
	[ -e /etc/ntp/step-tickers.default ] && mv /etc/ntp/step-tickers.default /etc/ntp/step-tickers && echo -n "1, "
51
	[ -e /etc/ntp.conf.default ] && mv /etc/ntp.conf.default /etc/ntp.conf && echo -n "2"
52
}
53
 
54
init_db ()
55
{
56
	echo -en "(2) : "
57
	[ -e /etc/my.cnf.default ] && mv -f /etc/my.cnf.default /etc/my.cnf && echo -n "1, "
58
	[ -e /lib/systemd/system/mysqld.service.default ] && mv -f /lib/systemd/system/mysqld.service.default /lib/systemd/system/mysqld.service && echo -n "2"
59
	/usr/bin/systemctl daemon-reload
60
	rm -rf /var/lib/mysql
61
}
62
 
63
freeradius ()
64
{
2467 richard 65
	echo -en "(14) : "
2464 richard 66
	[ -e /etc/raddb/empty-radiusd-db.sql ] && rm -f /etc/raddb/empty-radiusd-db.sql && echo -n "1, "
67
	[ -e /etc/raddb/radiusd.conf.default ] && mv /etc/raddb/radiusd.conf.default /etc/raddb/radiusd.conf && echo -n "2, "
68
	[ -e /etc/raddb/sites-enabled/alcasar ] && rm /etc/raddb/sites-enabled/alcasar && echo -n "3, "
69
	[ -e /etc/raddb/sites-available/alcasar ] && rm /etc/raddb/sites-available/alcasar && echo -n "4, "
2467 richard 70
	[ -e /etc/raddb/sites-available/alcasar-with-ldap ] && rm /etc/raddb/sites-available/alcasar-with-ldap && echo -n "5, "
71
	[ -e /etc/raddb/clients.conf.default ] && mv /etc/raddb/clients.conf.default /etc/raddb/clients.conf && echo -n "6, "
72
	[ -e /etc/raddb/mods-enabled/ldap ] && rm /etc/raddb/mods-enabled/ldap && echo -n "7, " #Add here other mods
73
	[ -e /etc/raddb/mods-enabled/sql ] && rm /etc/raddb/mods-enabled/sql && echo -n "7bis, " #Add here other mods
74
	[ -e /etc/raddb/mods-available/ldap-alcasar ] && rm /etc/raddb/mods-available/ldap-alcasar && echo -n "8, "
75
	[ -e /etc/raddb/mods-available/sql.default ] && mv /etc/raddb/mods-available/sql.default /etc/raddb/mods-available/sql && echo -n "9, "
76
	[ -e /etc/raddb/mods-config/sql/main/mysql/queries.conf.default ] && mv /etc/raddb/mods-config/sql/main/mysql/queries.conf.default /etc/raddb/mods-config/sql/main/mysql/queries.conf && echo -n "10, "
77
	[ -e /etc/raddb/mods-config/sql/counter/mysql/dailycounter.conf.default ] && mv /etc/raddb/mods-config/sql/counter/mysql/dailycounter.conf.default /etc/raddb/mods-config/sql/counter/mysql/dailycounter.conf && echo -n "11, "
78
	[ -e /etc/raddb/mods-config/sql/counter/mysql/monthlycounter.conf.default ] && mv /etc/raddb/mods-config/sql/counter/mysql/monthlycounter.conf.default /etc/raddb/mods-config/sql/counter/mysql/monthlycounter.conf && echo -n "12, "
79
	[ -e /etc/raddb/mods-config/sql/counter/mysql/noresetcounter.conf.default ] && mv /etc/raddb/mods-config/sql/counter/mysql/noresetcounter.conf.default /etc/raddb/mods-config/sql/counter/mysql/noresetcounter.conf && echo -n "13, "
80
	[ -e /lib/systemd/system/radiusd.service.default ] && mv /lib/systemd/system/radiusd.service.default /lib/systemd/system/radiusd.service && echo -n "14"
2464 richard 81
}
82
 
83
chilli ()
84
{
85
	echo -en "(4) : "
86
	[ -e /etc/init.d/chilli.default ] && mv /etc/init.d/chilli.default /etc/init.d/chilli && echo -n "1, "
87
	[ -e /usr/libexec/chilli ] && rm /usr/libexec/chilli && echo -n "2, "
88
	[ -e /etc/chilli.conf.default ] && mv /etc/chilli.conf.default /etc/chilli.conf && echo -n "3, "
89
	[ -e /lib/systemd/system/chilli.service ] && rm /lib/systemd/system/chilli.service && echo -n "4"
90
}
91
 
92
dansguardian ()
93
{
94
	echo -en "(8) : "
95
	[ -d /var/dansguardian ] && rm -rf /var/dansguardian && echo -n "1, "
96
	[ -e /etc/dansguardian/dansguardian.conf.default ] && mv /etc/dansguardian/dansguardian.conf.default /etc/dansguardian/dansguardian.conf && echo -n "2, "
97
	[ -e /etc/dansguardian/lists/bannedphraselist.default ] && mv /etc/dansguardian/lists/bannedphraselist.default /etc/dansguardian/lists/bannedphraselist && echo -n "3, "
98
	[ -e /etc/dansguardian/dansguardianf1.conf.default ] && mv /etc/dansguardian/dansguardianf1.conf.default /etc/dansguardian/dansguardianf1.conf && echo -n "4, "
99
	[ -e /etc/dansguardian/lists/bannedextensionlist.default ] && mv /etc/dansguardian/lists/bannedextensionlist.default /etc/dansguardian/lists/bannedextensionlist && echo -n "5, "
100
	[ -e /etc/dansguardian/lists/bannedmimetypelist.default ] && mv /etc/dansguardian/lists/bannedmimetypelist.default /etc/dansguardian/lists/bannedmimetypelist && echo -n "6, "
101
	[ -e /etc/dansguardian/lists/exceptioniplist.default ] && mv /etc/dansguardian/lists/exceptioniplist.default /etc/dansguardian/lists/exceptioniplist && echo -n "7, "
102
	[ -e /etc/dansguardian/lists/bannedsitelist.default ] && mv /etc/dansguardian/lists/bannedsitelist.default /etc/dansguardian/lists/bannedsitelist && echo -n "8"
103
}
104
 
105
antivirus ()
106
{
107
	echo -en "(5) : "
108
	if [ -e /etc/init.d/havp ]
109
	then
110
		[ -e /etc/havp/havp.config.default ] && mv /etc/havp/havp.config.default /etc/havp/havp.config && echo -n "1, "
111
		userdel -r havp 2>/dev/null && echo -n "2, "
112
		[ -e /etc/init.d/havp.default ] && mv /etc/init.d/havp.default /etc/init.d/havp && echo -n "3, "
113
		[ -e /lib/systemd/system/havp.service.default ] && mv /lib/systemd/system/havp.service.default /lib/systemd/system/havp.service && echo -n "4, "
114
		[ -e /etc/freshclam.conf.default ] && mv /etc/freshclam.conf.default /etc/freshclam.conf && echo -n "5"
115
	else	echo -n "already uninstalled"
116
	fi
117
}
118
 
119
tinyproxy ()
120
{
121
	echo -en "(2) : "
122
	if [ -e /etc/init.d/tinyproxy ]
123
	then
124
		[ -e /etc/tinyproxy/tinyproxy.conf.default ] && mv /etc/tinyproxy/tinyproxy.conf.default /etc/tinyproxy/tinyproxy.conf && echo -n "1, "
125
		userdel -r tinyproxy 2>/dev/null && echo -n "2"
126
	else	echo -n "already uninstalled"
127
	fi
128
}
129
 
130
ulogd ()
131
{
132
	echo -en "(6) : "
133
	i=0
134
	for log_type in traceability ssh ext-access
135
	do
136
		i=`expr $i + 1`
137
		[ -e /etc/ulogd-$log_type.conf ] && rm -f /etc/ulogd-$log_type.conf && echo -n "$i, "
138
		i=`expr $i + 1`
139
		[ -e /lib/systemd/system/ulogd-$log_type.service ] && rm -f /lib/systemd/system/ulogd-$log_type.service && echo -n "$i, "
140
	done
141
}
142
 
143
nfsen ()
144
{
145
	echo -en "(1) : "
146
	[ -e /lib/systemd/system/nfsen.service ] && rm -f /lib/systemd/system/nfsen.service && echo -n "1"
147
}
148
 
149
vnstat ()
150
{
151
	echo -en "(1) : "
152
	[ -e /etc/vnstat.conf.default ] && mv /etc/vnstat.conf.default /etc/vnstat.conf && echo -n "1"
153
}
154
 
155
dnsmasq ()
156
{
157
	echo -en "(6 if update ; 8 if uninstall) : "
158
	i=0
159
	for list in blacklist whitelist blackhole
160
	do
161
		i=`expr $i + 1`
162
		[ -e /etc/dnsmasq-$list.conf ] && rm /etc/dnsmasq-$list.conf && echo -n "$i, "
163
		i=`expr $i + 1`
164
		[ -e /lib/systemd/system/dnsmasq-$list.service ] && rm /lib/systemd/system/dnsmasq-$list.service && echo -n "$i, "
165
	done
166
	if [ $mode == "full" ] # don't remove dnsmasq in update mode (DHCP + DNS !)
167
	then
168
		if [ -e /lib/systemd/system/dnsmasq.service ]
169
		then
170
			[ -e /etc/dnsmasq.conf.default ] && mv /etc/dnsmasq.conf.default /etc/dnsmasq.conf && echo -n "7, "
171
			[ -e /lib/systemd/system/dnsmasq.service.default ] && mv /lib/systemd/system/dnsmasq.service.default /lib/systemd/system/dnsmasq.service && echo -n "8"
172
		fi
173
	fi
174
}
175
 
176
cron ()
177
{
178
	echo -en "(11) : "
179
	i=1
180
	for cron in `ls /etc/cron.d/alcasar-* 2>/dev/null`
181
	do
182
		rm $cron && echo -n "$i, "
183
		i=`expr $i + 1`
184
	done
185
	[ -e /etc/crontab.default ] && mv /etc/crontab.default /etc/crontab && echo -n "10, "
186
	[ -e /etc/anacrontab.default ] && mv /etc/anacrontab.default /etc/anacrontab && echo -n "11"
187
}
188
 
189
fail2ban ()
190
{
191
	echo -en "(8) : "
192
	[ -e /etc/fail2ban/fail2ban.conf.default ] && mv /etc/fail2ban/fail2ban.conf.default /etc/fail2ban/fail2ban.conf && echo -n "1, "
193
	[ -e /etc/fail2ban/jail.conf.default ] && mv /etc/fail2ban/jail.conf.default /etc/fail2ban/jail.conf && echo -n "2, "
194
	[ -e /etc/fail2ban/action.d/iptables-allports.conf.default ] && mv /etc/fail2ban/action.d/iptables-allports.conf.default /etc/fail2ban/action.d/iptables-allports.conf && echo -n "3, "
195
	i=3
196
	for filter in `ls /etc/fail2ban/filter.d/alcasar_* 2>/dev/null`
197
	do
198
		i=`expr $i + 1`
199
		rm $filter && echo -n "$i, "
200
	done
201
	[ -e /lib/systemd/system/fail2ban.service.default ] && mv /lib/systemd/system/fail2ban.service.default /lib/systemd/system/fail2ban.service && echo -n "8"
202
}
203
 
204
gammu_smsd ()
205
{
206
	echo -en "(3) : "
207
	[ -e /etc/gammu_smsd_conf ] && rm -f /etc/gammu_smsd_conf && echo -n "1, "
208
	[ -e /lib/udev/rules.d/66-huawei.rules ] && rm -f /lib/udev/rules.d/66-huawei.rules && echo -n "2, "
209
	[ -e /var/log/gammu-smsd ] && rm -rf /var/log/gammu-smsd && echo -n "3"
210
}
211
 
212
msec ()
213
{
214
	echo -en "(2) : "
215
	if [ -e /etc/security/msec/security.conf ]
216
	then
217
		[ -e /etc/security/msec/security.conf.default ] && mv /etc/security/msec/security.conf.default /etc/security/msec/security.conf && echo -n "1, "
218
		[ -e /etc/security/msec/perm.local ] && rm -f /etc/security/msec/perm.local && echo -n "2"
219
	else	echo -n "uninstalled"
220
	fi
221
}
222
 
223
letsencrypt ()
224
{
225
	echo -en "(3) : "
226
	[ -e /usr/local/etc/letsencrypt ] && rm -rf /usr/local/etc/letsencrypt && echo -n "1, "
227
	[ -e /opt/acme.sh/acme.sh ] && /opt/acme.sh/acme.sh --uninstall --nocron 1>/dev/null && echo -n "2, "
228
	[ -e /opt/acme.sh ] && rm -rf /opt/acme.sh && echo -n "3"
229
}
230
 
231
post_install ()
232
{
233
echo -en "(7) : "
234
	[ -e /etc/mageia-release.default ] && mv -f /etc/mageia-release.default /etc/mageia-release && echo -n "1, "
235
	[ -e /etc/ssh/alcasar-banner-ssh ] && rm -f /etc/ssh/alcasar-banner-ssh && echo -n "2, "
236
	[ -e /etc/ssh/sshd_config.default ] && mv -f /etc/ssh/sshd_config.default /etc/ssh/sshd_config && echo -n "3, "
237
	[ -e /etc/bashrc.default ] && mv -f /etc/bashrc.default /etc/bashrc && echo -n "4, "
238
	[ -e /etc/sudoers.default ] && mv -f /etc/sudoers.default /etc/sudoers && echo -n "5, "
239
	[ -e /lib/systemd/system/alcasar-load_balancing.service ] && rm -f /lib/systemd/system/alcasar-load_balancing.service && echo -n "6, "
240
	[ -e /etc/default/grub.default ] && mv -f /etc/default/grub.default /etc/default/grub && echo -n "7"
241
}
242
 
243
 
244
usage="Usage: alcasar-uninstall.sh {-update or --update} | {-full or --full}"
245
 
2206 richard 246
nb_args=$#
247
args=$1
248
if [ $nb_args -eq 0 ]
249
then
250
	nb_args=1
251
	args="-h"
252
fi
253
case $args in
254
	-\? | -h* | --h*)
255
		echo "$usage"
256
		exit 0
257
		;;
258
	--update | -update)
259
		mode="update"
260
		;;
261
	--full | -full)
262
		mode="full"
263
		;;
264
	*)
265
		echo "Argument inconnu :$1";
266
		echo "$usage"
267
		exit 1
268
		;;
269
esac
1 root 270
clear
2206 richard 271
if [ $mode == "full" ]
272
then
273
	echo "----------------------------------------------------------------------------"
274
	echo "**                     Uninstall/Désinstallation d'ALCASAR		**"
275
	echo "----------------------------------------------------------------------------"
276
	services="alcasar-load_balancing vnstat havp freshclam ntpd httpd radiusd mysqld dnsmasq-blacklist dnsmasq-whitelist dnsmasq-blackhole tinyproxy nfsen fail2ban iptables ulogd-ext-access ulogd-ssh ulogd-traceability dansguardian dnsmasq sshd chilli"
277
	/usr/local/bin/alcasar-logout.sh all # logout everybody
278
else
2464 richard 279
	echo "--------------------------------------------------------------------------"
2206 richard 280
	echo "**                     update/mise à jour d'ALCASAR			**"
2464 richard 281
	echo "--------------------------------------------------------------------------"
2206 richard 282
	# dnsmasq & sshd should stay on to allow remote update
2212 richard 283
	services="alcasar-load_balancing vnstat havp freshclam ntpd httpd radiusd mysqld dnsmasq-blacklist dnsmasq-whitelist dnsmasq-blackhole tinyproxy nfsen fail2ban ulogd-ext-access ulogd-ssh ulogd-traceability dansguardian chilli"
2206 richard 284
	/usr/local/bin/alcasar-bypass.sh -on # to allow remote update
285
fi
1673 richard 286
echo "Stopping service : "
1800 richard 287
/usr/local/bin/alcasar-sms.sh --stop
2454 tom.houday 288
for i in $services
1211 crox53 289
do
2454 tom.houday 290
	if [ -e /lib/systemd/system/$i.service ]
1800 richard 291
	then
292
		/usr/bin/systemctl disable $i.service
2454 tom.houday 293
		/usr/bin/systemctl stop $i.service 1>/dev/null
1800 richard 294
		sleep 1
295
	else
296
		echo "The service $i.service doesn't exist !"
297
	fi
1211 crox53 298
done
1673 richard 299
echo "Check the service clearing"
2206 richard 300
for i in $services
1673 richard 301
do
302
	if [ `systemctl is-active $i.service` == "active" ]
303
	then
304
		echo "The service '$i' need to be killed"
305
		/usr/bin/systemctl stop $i.service
306
		killall $i
307
	fi
308
done
2426 richard 309
if [ $mode == "update" ] # reload sshd in case of remote update
2226 richard 310
then
2457 richard 311
	/usr/bin/systemctl reload sshd
2226 richard 312
fi
1502 richard 313
echo "Reset ALCASAR main functions : "
2464 richard 314
for func in init ACC CA time_server init_db freeradius chilli dansguardian antivirus tinyproxy ulogd nfsen vnstat dnsmasq cron fail2ban gammu_smsd msec letsencrypt post_install
2206 richard 315
do
2464 richard 316
	echo -en "\n- $func "
317
	$func
318
	sleep 1
2466 richard 319
	if [ $DEBUG_ALCASAR == "on" ]
320
	then
321
		echo -n " *** 'debug' : end of cleaning '$func' *** "
322
		read a
323
	fi
2206 richard 324
done
2426 richard 325
if [ $mode == "full" ]
2206 richard 326
then
327
	echo -en "\n- network(9) : "
2426 richard 328
	hostnamectl set-hostname localhost.localdomain
2464 richard 329
	chmod a-x /etc/sysconfig/network-scripts/default-*
2206 richard 330
	i=0
2464 richard 331
	for nic in `ls /etc/sysconfig/network-scripts/default-*|cut -d'-' -f4`
1362 richard 332
	do
2206 richard 333
		i=`expr $i + 1`
334
		/sbin/ifdown $nic
2464 richard 335
		[ -e /etc/sysconfig/network-scripts/default-ifcfg-$nic ] && mv -f /etc/sysconfig/network-scripts/default-ifcfg-$nic /etc/sysconfig/network-scripts/ifcfg-$nic && echo -n "$i ($nic), "
1362 richard 336
	done
2432 richard 337
	[ -e /etc/sysconfig/network.default ] && mv -f /etc/sysconfig/network.default /etc/sysconfig/network && echo -n "3, "
338
	[ -e /etc/hosts.default ] && mv -f /etc/hosts.default /etc/hosts && echo -n "4, "
339
	[ -e /etc/hosts.allow.default ] && mv -f /etc/hosts.allow.default /etc/hosts.allow && echo -n "5, "
340
	[ -e /etc/hosts.deny.default ] && mv -f /etc/hosts.deny.default /etc/hosts.deny && echo -n "6, "
341
	[ -e /etc/modprobe.preload.default ] && mv -f /etc/modprobe.preload.default /etc/modprobe.preload && echo -n "7, "
342
	[ -e /lib/systemd/system/iptables.service.default ] && mv -f /lib/systemd/system/iptables.service.default /lib/systemd/system/iptables.service && echo -n "8, "
343
	[ -e /usr/libexec/iptables.init.default ] && mv -f /usr/libexec/iptables.init.default /usr/libexec/iptables.init && echo -n "9"
2457 richard 344
	/usr/bin/systemctl restart network
2206 richard 345
	sleep 1
346
fi
790 richard 347
 
2226 richard 348
# Cleaning (remove all "old" alcasar scripts)
2243 tom.houday 349
echo -en "\n- End of cleaning ...\n"
1923 franck 350
for rm_fic in /usr/local/bin /usr/local/etc /usr/local/sbin
2206 richard 351
do
306 richard 352
	rm -rf $rm_fic/alcasar*
2206 richard 353
done
2457 richard 354
/usr/bin/update-grub2
2458 richard 355
 
356
if [ $mode == "full" ]
357
then
358
	echo -n "Waiting for Network to be up again : "
359
	i=0
360
	while [ $i -lt 10 ] # We wait 10 seconds max
361
	do
362
		echo -n "."
363
		DNS1=`grep ^nameserver /etc/resolv.conf|awk -F" " '{print $2}'|head -n 1`
364
		if [ "$DNS1" != "" ] && [ "$DNS1" != "127.0.0.1" ]
365
		then
366
			i=9
367
			echo -n "ok"
368
		fi
369
		i=`expr $i + 1`
370
		sleep 1
371
	done
372
fi
373
echo
2464 richard 374