Line 1... |
Line 1... |
1 |
#/bin/bash
|
1 |
#/bin/bash
|
2 |
# $Id: alcasar-conf.sh 1694 2015-09-08 07:36:44Z franck $
|
2 |
# $Id: alcasar-conf.sh 1758 2016-01-13 22:27:27Z richard $
|
3 |
|
3 |
|
4 |
# alcasar-conf.sh
|
4 |
# alcasar-conf.sh
|
5 |
# by REXY
|
5 |
# by REXY
|
6 |
# This script is distributed under the Gnu General Public License (GPL)
|
6 |
# This script is distributed under the Gnu General Public License (GPL)
|
7 |
|
7 |
|
8 |
# Ce script permet la mise à jour ALCASAR
|
8 |
# Ce script permet la mise à jour ALCASAR
|
9 |
# - création de l'archive des fichiers de configuration (/tmp/alcasar-conf.tar.gz)
|
9 |
# - création de l'archive des fichiers de configuration dans "/tmp/alcasar-conf.tar.gz" (alcasar-conf.sh -create)
|
10 |
# - chargement d'une archive (lors de la mise à jour d'un alcasar)
|
10 |
# - chargement de l'archive de fichiers de configuration lors de la mise à jour d'un alcasar (alcasar-conf -load)
|
11 |
# - application des directives du fichier de conf central "/usr/local/etc/alcasar.conf" (lors d'un changement de conf à chaud)
|
11 |
# - application des directives du fichier de conf central "/usr/local/etc/alcasar.conf" lors d'un changement de conf réseau à chaud (alcasar-conf -apply)
|
12 |
# This script allows ALCASAR update
|
12 |
# This script allows ALCASAR update
|
13 |
# - create the configuration files backup (/tmp/alcasar-conf.tar.gz)
|
13 |
# - create the configuration files backup "/tmp/alcasar-conf.tar.gz" (alcasar-conf.sh -create)
|
14 |
# - load the bachup of configuration files (during the update process)
|
14 |
# - load the bachup of configuration files during the update process (alcasar-conf -load)
|
15 |
# - apply ALCASAR central configuration file "/usr/local/etc/alcasar.conf" (when hot modification are needed)
|
15 |
# - apply ALCASAR central configuration file "/usr/local/etc/alcasar.conf" when hot modification is needed (alcasar-conf -apply)
|
16 |
|
16 |
|
17 |
new="$(date +%G%m%d-%Hh%M)" # date et heure des fichiers
|
17 |
new="$(date +%G%m%d-%Hh%M)" # date et heure des fichiers
|
18 |
fichier="alcasar-conf-$new.tar.gz" # nom du fichier de sauvegarde
|
18 |
fichier="alcasar-conf-$new.tar.gz" # nom du fichier de sauvegarde
|
19 |
DIR_UPDATE="/tmp/conf" # répertoire de stockage des fichier de conf pour une mise à jour
|
19 |
DIR_UPDATE="/tmp/conf" # répertoire de stockage des fichier de conf pour une mise à jour
|
20 |
DIR_WEB="/var/www/html" # répertoire du centre de gestion
|
20 |
DIR_WEB="/var/www/html" # répertoire du centre de gestion
|
Line 66... |
Line 66... |
66 |
exit 0
|
66 |
exit 0
|
67 |
;;
|
67 |
;;
|
68 |
--create|-create)
|
68 |
--create|-create)
|
69 |
[ -d $DIR_UPDATE ] && rm -rf $DIR_UPDATE
|
69 |
[ -d $DIR_UPDATE ] && rm -rf $DIR_UPDATE
|
70 |
mkdir $DIR_UPDATE
|
70 |
mkdir $DIR_UPDATE
|
71 |
# Sauvegarde de la base des usagers
|
71 |
# backup the users database
|
72 |
$DIR_SBIN/alcasar-mysql.sh -dump
|
72 |
$DIR_SBIN/alcasar-mysql.sh -dump
|
73 |
cp /var/Save/base/`ls /var/Save/base|tail -1` $DIR_UPDATE
|
73 |
cp /var/Save/base/`ls /var/Save/base|tail -1` $DIR_UPDATE
|
74 |
# Sauvegarde du logo
|
74 |
# backup the logo
|
75 |
cp -f $DIR_WEB/images/organisme.png $DIR_UPDATE
|
75 |
cp -f $DIR_WEB/images/organisme.png $DIR_UPDATE
|
76 |
# Sauvegarde des fichiers exploités par dansguardian
|
76 |
# backup Dansguardian files
|
77 |
cp -f /etc/dansguardian/lists/exceptioniplist $DIR_UPDATE
|
77 |
cp -f /etc/dansguardian/lists/exceptioniplist $DIR_UPDATE
|
78 |
cp -f /etc/dansguardian/lists/urlregexplist $DIR_UPDATE
|
78 |
cp -f /etc/dansguardian/lists/urlregexplist $DIR_UPDATE
|
79 |
cp -f /etc/dansguardian/lists/exceptionsitelist $DIR_UPDATE
|
79 |
cp -f /etc/dansguardian/lists/exceptionsitelist $DIR_UPDATE
|
80 |
cp -f /etc/dansguardian/lists/bannedsitelist $DIR_UPDATE
|
80 |
cp -f /etc/dansguardian/lists/bannedsitelist $DIR_UPDATE
|
81 |
cp -f /etc/dansguardian/lists/exceptionurllist $DIR_UPDATE
|
81 |
cp -f /etc/dansguardian/lists/exceptionurllist $DIR_UPDATE
|
82 |
cp -f /etc/dansguardian/lists/bannedurllist $DIR_UPDATE
|
82 |
cp -f /etc/dansguardian/lists/bannedurllist $DIR_UPDATE
|
83 |
cp -rf /etc/dansguardian/lists/blacklists/ossi $DIR_UPDATE
|
83 |
cp -rf /etc/dansguardian/lists/blacklists/ossi $DIR_UPDATE
|
84 |
# sauvegarde des fichiers : de conf, de filtrage, d'exception, digest, etc.
|
84 |
# backup of different conf files (main conf file, filtering, digest, etc)
|
85 |
mkdir $DIR_UPDATE/etc/
|
85 |
mkdir $DIR_UPDATE/etc/
|
86 |
cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
|
86 |
cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
|
87 |
# sauvegarde des certificats (serveur et CA)
|
87 |
# backup of the security certificates (server & CA)
|
88 |
cert_date=`/usr/bin/openssl x509 -noout -in /etc/pki/tls/certs/alcasar.crt -dates|grep After|cut -d"=" -f2`
|
- |
|
89 |
cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE
|
88 |
cp -f /etc/pki/tls/certs/alcasar.crt* $DIR_UPDATE # autosigned and official if exist
|
90 |
cp -f /etc/pki/tls/private/alcasar.key $DIR_UPDATE
|
89 |
cp -f /etc/pki/tls/private/alcasar.key* $DIR_UPDATE # autosigned & official if exist
|
91 |
cp -f /etc/pki/CA/alcasar-ca.crt $DIR_UPDATE
|
90 |
cp -f /etc/pki/CA/alcasar-ca.crt $DIR_UPDATE
|
92 |
cp -f /etc/pki/CA/private/alcasar-ca.key $DIR_UPDATE
|
91 |
cp -f /etc/pki/CA/private/alcasar-ca.key $DIR_UPDATE
|
93 |
if [ -e /etc/pki/tls/certs/server-chain.crt ]; then
|
92 |
if [ -e /etc/pki/tls/certs/server-chain.crt ]; then
|
94 |
cp -f /etc/pki/tls/certs/server-chain.crt $DIR_UPDATE
|
93 |
cp -f /etc/pki/tls/certs/server-chain.crt $DIR_UPDATE
|
95 |
else
|
94 |
else
|
96 |
cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE/server-chain.crt
|
95 |
cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE/server-chain.crt
|
97 |
fi
|
96 |
fi
|
98 |
# DNSMASQ conf file
|
97 |
# backup DNSMASQ conf file
|
99 |
cp /etc/sysconfig/dnsmasq $DIR_UPDATE
|
98 |
cp /etc/sysconfig/dnsmasq $DIR_UPDATE
|
100 |
# ALCASAR conf file
|
99 |
# archive file creation
|
101 |
cp $CONF_FILE $DIR_UPDATE/etc/
|
- |
|
102 |
# création de l'archive et copie dans le répertoire WEB associé
|
- |
|
103 |
cd /tmp
|
100 |
cd /tmp
|
104 |
tar -cf alcasar-conf.tar conf/
|
101 |
tar -cf alcasar-conf.tar conf/
|
105 |
gzip -f alcasar-conf.tar
|
102 |
gzip -f alcasar-conf.tar
|
106 |
rm -rf $DIR_UPDATE
|
103 |
rm -rf $DIR_UPDATE
|
107 |
;;
|
104 |
;;
|
Line 110... |
Line 107... |
110 |
tar -xf /tmp/alcasar-conf*.tar.gz
|
107 |
tar -xf /tmp/alcasar-conf*.tar.gz
|
111 |
# Retrieve the logo
|
108 |
# Retrieve the logo
|
112 |
[ -e $DIR_UPDATE/organisme.png ] && cp -f $DIR_UPDATE/organisme.png $DIR_WEB/images/
|
109 |
[ -e $DIR_UPDATE/organisme.png ] && cp -f $DIR_UPDATE/organisme.png $DIR_WEB/images/
|
113 |
chown apache:apache $DIR_WEB/images/organisme.png $DIR_WEB/intercept.php
|
110 |
chown apache:apache $DIR_WEB/images/organisme.png $DIR_WEB/intercept.php
|
114 |
# Retrieve the security certificates (CA and server)
|
111 |
# Retrieve the security certificates (CA and server)
|
115 |
[ -e $DIR_UPDATE/alcasar-ca.crt ] && cp -f $DIR_UPDATE/alcasar-ca.crt /etc/pki/CA/
|
112 |
cp -f $DIR_UPDATE/alcasar-ca.crt* /etc/pki/CA/ # autosigned & official
|
116 |
[ -e $DIR_UPDATE/alcasar-ca.key ] && cp -f $DIR_UPDATE/alcasar-ca.key /etc/pki/CA/private/
|
113 |
cp -f $DIR_UPDATE/alcasar-ca.key* /etc/pki/CA/private/ # autosigned & official
|
117 |
[ -e $DIR_UPDATE/alcasar.crt ] && cp -f $DIR_UPDATE/alcasar.crt /etc/pki/tls/certs/
|
114 |
cp -f $DIR_UPDATE/alcasar.crt /etc/pki/tls/certs/
|
118 |
[ -e $DIR_UPDATE/alcasar.key ] && cp -f $DIR_UPDATE/alcasar.key /etc/pki/tls/private/
|
115 |
cp -f $DIR_UPDATE/alcasar.key /etc/pki/tls/private/
|
119 |
[ -e $DIR_UPDATE/server-chain.crt ] && cp -f $DIR_UPDATE/server-chain.crt /etc/pki/tls/certs/
|
116 |
[ -e $DIR_UPDATE/server-chain.crt ] && cp -f $DIR_UPDATE/server-chain.crt /etc/pki/tls/certs/
|
120 |
chown -R root:apache /etc/pki
|
117 |
chown -R root:apache /etc/pki
|
121 |
chmod -R 750 /etc/pki
|
118 |
chmod -R 750 /etc/pki
|
122 |
# Import of the users database
|
119 |
# Import of the users database
|
123 |
gzip -dc < `ls $DIR_UPDATE/alcasar-users-database*` | mysql -u$DB_USER -p$radiuspwd
|
120 |
gzip -dc < `ls $DIR_UPDATE/alcasar-users-database*` | mysql -u$DB_USER -p$radiuspwd
|
124 |
# Retrieve local parameters & Remove blacklist files (now in /usr/local/share)
|
121 |
# Retrieve local parameters & Remove blacklist files (now in /usr/local/share)
|
125 |
[ -d $DIR_UPDATE/etc ] && rm -rf $DIR_UPDATE/etc/alcasar-dnsfilter* && cp -rf $DIR_UPDATE/etc/* $DIR_ETC/
|
122 |
[ -d $DIR_UPDATE/etc ] && rm -rf $DIR_UPDATE/etc/alcasar-dnsfilter* && cp -rf $DIR_UPDATE/etc/* $DIR_ETC/
|
126 |
# Retrieve Dansguardian files
|
123 |
# Retrieve Dansguardian files
|
127 |
[ -e $DIR_UPDATE/exceptioniplist ] && cp -f $DIR_UPDATE/exceptioniplist /etc/dansguardian/lists/
|
124 |
cp -f $DIR_UPDATE/exceptioniplist /etc/dansguardian/lists/
|
128 |
[ -e $DIR_UPDATE/exceptionsitelist ] && cp -f $DIR_UPDATE/exceptionsitelist /etc/dansguardian/lists/
|
125 |
cp -f $DIR_UPDATE/exceptionsitelist /etc/dansguardian/lists/
|
129 |
[ -e $DIR_UPDATE/urlregexplist ] && cp -f $DIR_UPDATE/urlregexplist /etc/dansguardian/lists/
|
126 |
cp -f $DIR_UPDATE/urlregexplist /etc/dansguardian/lists/
|
130 |
[ -e $DIR_UPDATE/bannedsitelist ] && cp -f $DIR_UPDATE/bannedsitelist /etc/dansguardian/lists/
|
127 |
cp -f $DIR_UPDATE/bannedsitelist /etc/dansguardian/lists/
|
131 |
[ -e $DIR_UPDATE/exceptionurllist ] && cp -f $DIR_UPDATE/exceptionurllist /etc/dansguardian/lists/
|
128 |
cp -f $DIR_UPDATE/exceptionurllist /etc/dansguardian/lists/
|
132 |
[ -e $DIR_UPDATE/bannedurllist ] && cp -f $DIR_UPDATE/bannedurllist /etc/dansguardian/lists/
|
129 |
cp -f $DIR_UPDATE/bannedurllist /etc/dansguardian/lists/
|
133 |
[ -d $DIR_UPDATE/ossi ] && cp -rf $DIR_UPDATE/ossi /etc/dansguardian/lists/blacklists/
|
130 |
cp -rf $DIR_UPDATE/ossi /etc/dansguardian/lists/blacklists/
|
134 |
chown -R dansguardian:apache /etc/dansguardian/lists
|
131 |
chown -R dansguardian:apache /etc/dansguardian/lists
|
135 |
chmod -R g+rw /etc/dansguardian/lists
|
132 |
chmod -R g+rw /etc/dansguardian/lists
|
136 |
# Adapt DNS/URL filtering
|
133 |
# Adapt DNS/URL filtering
|
137 |
PARENT_SCRIPT=`basename $0`
|
134 |
PARENT_SCRIPT=`basename $0`
|
138 |
export PARENT_SCRIPT
|
135 |
export PARENT_SCRIPT
|
Line 150... |
Line 147... |
150 |
then
|
147 |
then
|
151 |
/usr/bin/systemctl -q enable sshd.service
|
148 |
/usr/bin/systemctl -q enable sshd.service
|
152 |
else
|
149 |
else
|
153 |
/usr/bin/systemctl -q disable sshd.service
|
150 |
/usr/bin/systemctl -q disable sshd.service
|
154 |
fi
|
151 |
fi
|
- |
|
152 |
# modifications added with this version (2.9.2)
|
- |
|
153 |
# add "HOSTNAME=" in alcasar.conf
|
- |
|
154 |
hostname_defined=`grep ^HOSTNAME= $CONF_FILE|wc -l`
|
- |
|
155 |
if [ $hostname_define = "0" ]
|
- |
|
156 |
then
|
- |
|
157 |
$SED "/^DOMAIN=/iHOSTNAME=alcasar" $CONF_FILE
|
- |
|
158 |
fi
|
155 |
# Remove the update folder
|
159 |
# Remove the update folder
|
156 |
rm -rf $DIR_UPDATE
|
160 |
rm -rf $DIR_UPDATE
|
157 |
;;
|
161 |
;;
|
158 |
--apply|-apply)
|
162 |
--apply|-apply)
|
159 |
PTN="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/([012]?[0-9]|3[0-2])\b"
|
163 |
PTN="\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/([012]?[0-9]|3[0-2])\b"
|