Line 1... |
Line 1... |
1 |
#!/bin/bash
|
1 |
#!/bin/bash
|
2 |
# $Id: alcasar-conf.sh 2569 2018-07-14 09:17:12Z lucas.echard $
|
2 |
# $Id: alcasar-conf.sh 2570 2018-07-16 22:22:12Z rexy $
|
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 de mettre à jour d'ALCASAR
|
9 |
# - création de l'archive des fichiers de configuration "/var/tmp/alcasar-conf.tar.gz" (alcasar-conf.sh -create)
|
9 |
# - création de l'archive des fichiers de configuration "/var/tmp/alcasar-conf.tar.gz" (alcasar-conf.sh -create)
|
10 |
# - chargement de l'archive de fichiers de configuration lors de la mise à jour d'un alcasar (alcasar-conf -load). Le cas échéant, c'est ici qu'on met à jour les fichiers entre versions
|
10 |
# - chargement de l'archive de fichiers de configuration lors de la mise à jour d'un alcasar (alcasar-conf -load). Le cas échéant, c'est ici qu'on met à jour les fichiers entre versions
|
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)
|
11 |
# - application des directives du fichier de conf central "/usr/local/etc/alcasar.conf" à chaud (alcasar-conf -apply)
|
12 |
# This script allows ALCASAR update
|
12 |
# This script allows ALCASAR update
|
13 |
# - create the configuration files backup "/var/tmp/alcasar-conf.tar.gz" (alcasar-conf.sh -create)
|
13 |
# - create the configuration files backup "/var/tmp/alcasar-conf.tar.gz" (alcasar-conf.sh -create)
|
14 |
# - load the backup of configuration files during the update process (alcasar-conf -load). If needed, it's here we update files between versions
|
14 |
# - load the backup of configuration files during the update process (alcasar-conf -load). If needed, it's here we update files between versions
|
15 |
# - apply ALCASAR central configuration file "/usr/local/etc/alcasar.conf" when hot modification is needed (alcasar-conf -apply)
|
15 |
# - apply ALCASAR central configuration file "/usr/local/etc/alcasar.conf" when hot modification are 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="/var/tmp/conf" # répertoire de stockage des fichier de conf pour une mise à jour
|
19 |
DIR_UPDATE="/var/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 83... |
Line 83... |
83 |
cp -f $DIR_WEB/images/organisme.png $DIR_UPDATE
|
83 |
cp -f $DIR_WEB/images/organisme.png $DIR_UPDATE
|
84 |
# backup BL/WL custom files
|
84 |
# backup BL/WL custom files
|
85 |
mkdir $DIR_UPDATE/custom_bl
|
85 |
mkdir $DIR_UPDATE/custom_bl
|
86 |
for i in exceptioniplist urlregexplist exceptionsitelist bannedsitelist exceptionurllist bannedurllist
|
86 |
for i in exceptioniplist urlregexplist exceptionsitelist bannedsitelist exceptionurllist bannedurllist
|
87 |
do
|
87 |
do
|
88 |
if [ -d /etc/dansguardian ]; then # before V3.3
|
88 |
if [ -d /etc/dansguardian ]; then
|
89 |
cp /etc/dansguardian/lists/$i $DIR_UPDATE/custom_bl/
|
89 |
cp /etc/dansguardian/lists/$i $DIR_UPDATE/custom_bl/ # before V3.3
|
90 |
else
|
90 |
else
|
91 |
cp /etc/e2guardian/lists/$i $DIR_UPDATE/custom_bl/ # since V3.3
|
91 |
cp /etc/e2guardian/lists/$i $DIR_UPDATE/custom_bl/ # since V3.3
|
92 |
fi
|
92 |
fi
|
93 |
done
|
93 |
done
|
94 |
cp -rf $DIR_BLACKLIST/ossi-* $DIR_UPDATE/custom_bl/ 2>/dev/null
|
94 |
cp -rf $DIR_BLACKLIST/ossi-* $DIR_UPDATE/custom_bl/ 2>/dev/null
|
Line 97... |
Line 97... |
97 |
cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
|
97 |
cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
|
98 |
cp /etc/hosts $DIR_UPDATE/etc/
|
98 |
cp /etc/hosts $DIR_UPDATE/etc/
|
99 |
# backup of the security certificates (server & CA)
|
99 |
# backup of the security certificates (server & CA)
|
100 |
cp -f /etc/pki/tls/certs/alcasar.crt* $DIR_UPDATE
|
100 |
cp -f /etc/pki/tls/certs/alcasar.crt* $DIR_UPDATE
|
101 |
cp -f /etc/pki/tls/private/alcasar.key* $DIR_UPDATE
|
101 |
cp -f /etc/pki/tls/private/alcasar.key* $DIR_UPDATE
|
102 |
cp -f /etc/pki/tls/private/alcasar.pem $DIR_UPDATE
|
102 |
[ -e /etc/pki/tls/private/alcasar.pem ] && cp -f /etc/pki/tls/private/alcasar.pem $DIR_UPDATE # since V3.3
|
103 |
cp -f /etc/pki/CA/alcasar-ca.crt $DIR_UPDATE
|
103 |
cp -f /etc/pki/CA/alcasar-ca.crt $DIR_UPDATE
|
104 |
cp -f /etc/pki/CA/private/alcasar-ca.key $DIR_UPDATE
|
104 |
cp -f /etc/pki/CA/private/alcasar-ca.key $DIR_UPDATE
|
105 |
if [ -e /etc/pki/tls/certs/server-chain.crt ]; then
|
105 |
if [ -e /etc/pki/tls/certs/server-chain.crt ]; then
|
106 |
cp -f /etc/pki/tls/certs/server-chain.crt* $DIR_UPDATE # autosigned and official if exist
|
106 |
cp -f /etc/pki/tls/certs/server-chain.crt* $DIR_UPDATE # autosigned and official if exist
|
107 |
else
|
107 |
else
|
Line 115... |
Line 115... |
115 |
;;
|
115 |
;;
|
116 |
|
116 |
|
117 |
--load|-load)
|
117 |
--load|-load)
|
118 |
cd /var/tmp
|
118 |
cd /var/tmp
|
119 |
tar -xf alcasar-conf*.tar.gz
|
119 |
tar -xf alcasar-conf*.tar.gz
|
- |
|
120 |
######################### modifications between versions #######################
|
120 |
# Extract the previous version
|
121 |
# Retrieve the previous version
|
121 |
PREVIOUS_VERSION=`grep ^VERSION= $DIR_UPDATE/etc/alcasar.conf|cut -d"=" -f2`
|
122 |
PREVIOUS_VERSION=`grep ^VERSION= $DIR_UPDATE/etc/alcasar.conf|cut -d"=" -f2`
|
122 |
MAJ_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f1`
|
123 |
MAJ_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f1`
|
123 |
MIN_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f2`
|
124 |
MIN_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f2`
|
124 |
UPD_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f3|cut -c1`
|
125 |
UPD_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f3|cut -c1`
|
- |
|
126 |
## From 3.2.0 & 3.2.1 ##
|
- |
|
127 |
if [ $MAJ_PREVIOUS_VERSION == "3" ] && [ $MIN_PREVIOUS_VERSION == "2" ]
|
- |
|
128 |
then
|
- |
|
129 |
## rewrite the file managing domain name resolution (local & remote). Hostnames resolutions are now in /etc/hosts
|
- |
|
130 |
cat << EOF > $DIR_UPDATE/etc/alcasar-dns-name
|
- |
|
131 |
# Vous pouvez définir ici votre nom de domain local ('localdomain' par défaut)
|
- |
|
132 |
# Here you can define your local domain name ('localdomain' by default)
|
- |
|
133 |
local=/$DOMAIN/
|
- |
|
134 |
domain=$DOMAIN
|
- |
|
135 |
|
- |
|
136 |
## Ajouter une ligne pour chaque nom de domaine géré par un autre seveur DNS
|
- |
|
137 |
## Add one line for each domain name managed by an other DNS server
|
- |
|
138 |
## server=/<your_domain>/<@IP_domain_server>
|
- |
|
139 |
## Exemple for an A.D. domain : server=/Your.Domain.AD/110.120.100.100
|
- |
|
140 |
## Exemple for an other domain : server=/an_other_domain/10.20.30.40
|
- |
|
141 |
|
- |
|
142 |
## INFO : local hostnames are resolved in /etc/hosts file
|
- |
|
143 |
EOF
|
- |
|
144 |
## rewrite /etc/hosts file managing hostname resolution
|
- |
|
145 |
PRIVATE_IP=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2|cut -d"/" -f1`
|
- |
|
146 |
HOSTNAME=`grep ^HOSTNAME= $CONF_FILE|cut -d"=" -f2`
|
- |
|
147 |
cat << EOF > $DIR_UPDATE/etc/hosts
|
- |
|
148 |
127.0.0.1 localhost
|
- |
|
149 |
$PRIVATE_IP $HOSTNAME
|
- |
|
150 |
EOF
|
- |
|
151 |
## apache & dansguardian are replaced with lighttpd & E²guardian
|
- |
|
152 |
rm_rpm="apache apache-mod_php apache-mod_ssl dansguardian"
|
- |
|
153 |
/usr/sbin/urpme --auto -a $rm_rpm
|
- |
|
154 |
/usr/sbin/urpme --auto --auto-orphans
|
- |
|
155 |
rm -rf /etc/httpd/ /var/log/httpd/ /var/dansguardian/ /etc/dansguardian/
|
- |
|
156 |
## lighttpd need a .pem certificate (aggregation with private key & server crt)
|
- |
|
157 |
(cat $DIR_UPDATE/alcasar-ca.key; echo; cat $DIR_UPDATE/alcasar.crt) > $DIR_UPDATE/alcasar.pem
|
- |
|
158 |
fi
|
- |
|
159 |
###################### End of modifications between versions #######################
|
125 |
# Retrieve the logo
|
160 |
# Retrieve the logo
|
126 |
[ -e $DIR_UPDATE/organisme.png ] && cp -f $DIR_UPDATE/organisme.png $DIR_WEB/images/
|
161 |
[ -e $DIR_UPDATE/organisme.png ] && cp -f $DIR_UPDATE/organisme.png $DIR_WEB/images/
|
127 |
chown apache:apache $DIR_WEB/images/organisme.png $DIR_WEB/intercept.php
|
162 |
chown apache:apache $DIR_WEB/images/organisme.png $DIR_WEB/intercept.php
|
128 |
# Retrieve the security certificates (CA and server)
|
163 |
# Retrieve the security certificates (CA and server)
|
129 |
cp -f $DIR_UPDATE/alcasar-ca.crt* /etc/pki/CA/
|
164 |
cp -f $DIR_UPDATE/alcasar-ca.crt* /etc/pki/CA/
|
Line 136... |
Line 171... |
136 |
chmod -R 750 /etc/pki
|
171 |
chmod -R 750 /etc/pki
|
137 |
# Import of the users database
|
172 |
# Import of the users database
|
138 |
gzip -dc < `ls $DIR_UPDATE/alcasar-users-database*` | mysql -u$DB_USER -p$DB_PASS
|
173 |
gzip -dc < `ls $DIR_UPDATE/alcasar-users-database*` | mysql -u$DB_USER -p$DB_PASS
|
139 |
# Retrieve local parameters
|
174 |
# Retrieve local parameters
|
140 |
cp -rf $DIR_UPDATE/etc/* $DIR_ETC/
|
175 |
cp -rf $DIR_UPDATE/etc/* $DIR_ETC/
|
141 |
mv -f $DIR_ETC/hosts /etc/hosts
|
176 |
mv -f $DIR_UPDATE/etc/hosts /etc/hosts
|
142 |
# Retrieve BL/WL custom files
|
177 |
# Retrieve BL/WL custom files
|
143 |
cp -f $DIR_UPDATE/custom_bl/exceptioniplist /etc/e2guardian/lists/
|
178 |
cp -f $DIR_UPDATE/custom_bl/exceptioniplist /etc/e2guardian/lists/
|
144 |
cp -f $DIR_UPDATE/custom_bl/exceptionsitelist /etc/e2guardian/lists/
|
179 |
cp -f $DIR_UPDATE/custom_bl/exceptionsitelist /etc/e2guardian/lists/
|
145 |
cp -f $DIR_UPDATE/custom_bl/urlregexplist /etc/e2guardian/lists/
|
180 |
cp -f $DIR_UPDATE/custom_bl/urlregexplist /etc/e2guardian/lists/
|
146 |
cp -f $DIR_UPDATE/custom_bl/bannedsitelist /etc/e2guardian/lists/
|
181 |
cp -f $DIR_UPDATE/custom_bl/bannedsitelist /etc/e2guardian/lists/
|
Line 164... |
Line 199... |
164 |
else
|
199 |
else
|
165 |
/usr/bin/systemctl -q disable sshd.service
|
200 |
/usr/bin/systemctl -q disable sshd.service
|
166 |
fi
|
201 |
fi
|
167 |
# Remove the update folder
|
202 |
# Remove the update folder
|
168 |
rm -rf $DIR_UPDATE
|
203 |
rm -rf $DIR_UPDATE
|
169 |
######################### modifications between versions #######################
|
- |
|
170 |
## From 3.2.0 & 3.2.1 ##
|
- |
|
171 |
if [ $MAJ_PREVIOUS_VERSION == "3" ] && [ $MIN_PREVIOUS_VERSION == "2" ]
|
- |
|
172 |
then
|
- |
|
173 |
## rewrite the file managing domain name resolution (local & remote). Hostnames resolutions are now in /etc/hosts
|
- |
|
174 |
cat << EOF > $DIR_ETC/alcasar-dns-name
|
- |
|
175 |
# Vous pouvez définir ici votre nom de domain local ('localdomain' par défaut)
|
- |
|
176 |
# Here you can define your local domain name ('localdomain' by default)
|
- |
|
177 |
local=/$DOMAIN/
|
- |
|
178 |
domain=$DOMAIN
|
- |
|
179 |
|
- |
|
180 |
## Ajouter une ligne pour chaque nom de domaine géré par un autre seveur DNS
|
- |
|
181 |
## Add one line for each domain name managed by an other DNS server
|
- |
|
182 |
## server=/<your_domain>/<@IP_domain_server>
|
- |
|
183 |
## Exemple for an A.D. domain : server=/Your.Domain.AD/110.120.100.100
|
- |
|
184 |
## Exemple for an other domain : server=/an_other_domain/10.20.30.40
|
- |
|
185 |
|
- |
|
186 |
## INFO : local hostnames are resolved in /etc/hosts file
|
- |
|
187 |
EOF
|
- |
|
188 |
## rewrite /etc/hosts file managing hostname resolution
|
- |
|
189 |
PRIVATE_IP=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2|cut -d"/" -f1`
|
- |
|
190 |
HOSTNAME=`grep ^HOSTNAME= $CONF_FILE|cut -d"=" -f2`
|
- |
|
191 |
cat << EOF > /etc/hosts
|
- |
|
192 |
127.0.0.1 localhost
|
- |
|
193 |
$PRIVATE_IP $HOSTNAME
|
- |
|
194 |
EOF
|
- |
|
195 |
# apache & dansguardian are replaced with lighttpd & E²guardian
|
- |
|
196 |
rm_rpm="apache apache-mod_php apache-mod_ssl dansguardian"
|
- |
|
197 |
/usr/sbin/urpme --auto -a $rm_rpm
|
- |
|
198 |
/usr/sbin/urpme --auto --auto-orphans
|
- |
|
199 |
rm -rf /etc/httpd/ /var/log/httpd/ /var/dansguardian/ /etc/dansguardian/
|
- |
|
200 |
# lighttpd need a .pem certificate (aggregation with server crt & private key)
|
- |
|
201 |
(cat /etc/pki/tls/private/alcasar.key; echo; cat /etc/pki/tls/certs/alcasar.crt) > /etc/pki/tls/private/alcasar.pem
|
- |
|
202 |
fi
|
- |
|
203 |
;;
|
204 |
;;
|
204 |
|
205 |
|
205 |
--apply|-apply)
|
206 |
--apply|-apply)
|
206 |
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"
|
207 |
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"
|
207 |
PRIVATE_IP_MASK=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
|
208 |
PRIVATE_IP_MASK=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
|