Line 1... |
Line 1... |
1 |
#/bin/bash
|
1 |
#/bin/bash
|
2 |
# $Id: alcasar-conf.sh 1554 2015-01-11 22:42:51Z richard $
|
2 |
# $Id: alcasar-conf.sh 1564 2015-02-09 23:18:36Z 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 |
|
Line 19... |
Line 19... |
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
|
21 |
DIR_BIN="/usr/local/bin" # répertoire des scripts d'admin
|
21 |
DIR_BIN="/usr/local/bin" # répertoire des scripts d'admin
|
22 |
DIR_SBIN="/usr/local/sbin" # répertoire des scripts d'admin
|
22 |
DIR_SBIN="/usr/local/sbin" # répertoire des scripts d'admin
|
23 |
DIR_ETC="/usr/local/etc" # répertoire des fichiers de conf
|
23 |
DIR_ETC="/usr/local/etc" # répertoire des fichiers de conf
|
24 |
DIR_SAVE="/var/Save/system_backup" # répertoire de sauvegarde
|
- |
|
25 |
CONF_FILE="$DIR_ETC/alcasar.conf" # main alcasar conf file
|
24 |
CONF_FILE="$DIR_ETC/alcasar.conf" # main alcasar conf file
|
26 |
VERSION="/var/www/html/VERSION" # contient la version en cours
|
25 |
VERSION="/var/www/html/VERSION" # contient la version en cours
|
27 |
EXTIF=`grep ^EXTIF= $CONF_FILE|cut -d"=" -f2` # EXTernal InterFace
|
26 |
EXTIF=`grep ^EXTIF= $CONF_FILE|cut -d"=" -f2` # EXTernal InterFace
|
28 |
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2` # INTernal InterFace
|
27 |
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2` # INTernal InterFace
|
29 |
HOSTNAME="alcasar"
|
28 |
HOSTNAME="alcasar"
|
Line 32... |
Line 31... |
32 |
SED="/bin/sed -i"
|
31 |
SED="/bin/sed -i"
|
33 |
RUNNING_VERSION=`cat $VERSION|cut -d" " -f1`
|
32 |
RUNNING_VERSION=`cat $VERSION|cut -d" " -f1`
|
34 |
MAJ_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f1`
|
33 |
MAJ_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f1`
|
35 |
MIN_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f2|cut -c1`
|
34 |
MIN_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f2|cut -c1`
|
36 |
UPD_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f3`
|
35 |
UPD_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f3`
|
37 |
DOMAIN=`grep DOMAIN $CONF_FILE|cut -d"=" -f2` 2>/dev/null # Error if (Version < 2.2) (no conf file)
|
36 |
DOMAIN=`grep DOMAIN $CONF_FILE|cut -d"=" -f2` 2>/dev/null
|
38 |
DOMAIN=${DOMAIN:=localdomain}
|
37 |
DOMAIN=${DOMAIN:=localdomain}
|
39 |
DATE=`date '+%d %B %Y - %Hh%M'`
|
38 |
DATE=`date '+%d %B %Y - %Hh%M'`
|
40 |
private_network_calc ()
|
39 |
private_network_calc ()
|
41 |
{
|
40 |
{
|
42 |
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2` # prefixe du réseau (ex. 24)
|
41 |
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2` # prefixe du réseau (ex. 24)
|
Line 83... |
Line 82... |
83 |
cp -f /etc/dansguardian/lists/bannedurllist $DIR_UPDATE
|
82 |
cp -f /etc/dansguardian/lists/bannedurllist $DIR_UPDATE
|
84 |
cp -rf /etc/dansguardian/lists/blacklists/ossi $DIR_UPDATE
|
83 |
cp -rf /etc/dansguardian/lists/blacklists/ossi $DIR_UPDATE
|
85 |
# sauvegarde des fichiers : de conf, de filtrage, d'exception, digest, etc.
|
84 |
# sauvegarde des fichiers : de conf, de filtrage, d'exception, digest, etc.
|
86 |
mkdir $DIR_UPDATE/etc/
|
85 |
mkdir $DIR_UPDATE/etc/
|
87 |
cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
|
86 |
cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
|
88 |
# particularité des versions
|
87 |
# sauvegarde des certificats (serveur et 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
|
- |
|
90 |
cp -f /etc/pki/tls/private/alcasar.key $DIR_UPDATE
|
89 |
# si version <= 2.8
|
91 |
cp -f /etc/pki/CA/alcasar-ca.crt $DIR_UPDATE
|
90 |
if [ $MAJ_RUNNING_VERSION -lt 2 ] || ([ $MAJ_RUNNING_VERSION -eq 2 ] && [ $MIN_RUNNING_VERSION -lt 8 ])
|
92 |
cp -f /etc/pki/CA/private/alcasar-ca.key $DIR_UPDATE
|
91 |
then
|
93 |
if [ -e /etc/pki/tls/certs/server-chain.crt ]; then
|
92 |
$SED "s?alcasar?alcasar.$DOMAIN?g" $DIR_UPDATE/etc/digest/* # add the domainname to the hostname
|
94 |
cp -f /etc/pki/tls/certs/server-chain.crt $DIR_UPDATE
|
93 |
else
|
95 |
else
|
94 |
# si version > 2.8 : sauvegarde des certificats (serveur et CA)
|
- |
|
95 |
cert_date=`/usr/bin/openssl x509 -noout -in /etc/pki/tls/certs/alcasar.crt -dates|grep After|cut -d"=" -f2`
|
- |
|
96 |
cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE
|
- |
|
97 |
cp -f /etc/pki/tls/private/alcasar.key $DIR_UPDATE
|
- |
|
98 |
cp -f /etc/pki/CA/alcasar-ca.crt $DIR_UPDATE
|
- |
|
99 |
cp -f /etc/pki/CA/private/alcasar-ca.key $DIR_UPDATE
|
- |
|
100 |
if [ -e /etc/pki/tls/certs/server-chain.crt ]; then
|
- |
|
101 |
cp -f /etc/pki/tls/certs/server-chain.crt $DIR_UPDATE
|
- |
|
102 |
else
|
- |
|
103 |
cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE/server-chain.crt
|
96 |
cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE/server-chain.crt
|
104 |
fi
|
- |
|
105 |
fi
|
97 |
fi
|
106 |
# Changes since V2.6
|
- |
|
107 |
# SSH_ADMIN_FROM is redefined
|
- |
|
108 |
$SED "s?^Admin_from_IP=.*?SSH_ADMIN_FROM=0.0.0.0/0.0.0.0?" $CONF_FILE
|
- |
|
109 |
# macallowed is replaced with macauth
|
- |
|
110 |
rm -f $DIR_UPDATE/etc/alcasar-macallowed
|
- |
|
111 |
# The option 'EXT_LAN_FILTERING' is deleted
|
- |
|
112 |
$SED "/^EXT_LAN/d" $CONF_FILE
|
- |
|
113 |
# The category "ip" no longer exist
|
- |
|
114 |
$SED "/\/ip\/urls/d" $DIR_UPDATE/bannedurllist; $SED "/\/ip\/domains/d" $DIR_UPDATE/bannedsitelist
|
- |
|
115 |
$SED "/blacklists\/ip/d" $DIR_UPDATE/etc/alcasar-bl-categories; $SED "/^ip/d" $DIR_UPDATE/etc/alcasar-bl-categories-enabled
|
- |
|
116 |
# BL and WL are now dynamically built in "/usr/local/share"
|
- |
|
117 |
rm -rf $DIR_UPDATE/etc/alcasar-dnsfilter-enabled $DIR_UPDATE/etc/alcasar-dnsfilter-available
|
- |
|
118 |
# Bing et Youtube are added to the safesearching system
|
- |
|
119 |
Bing=`grep bing $DIR_UPDATE/urlregexplist | wc -l`
|
- |
|
120 |
if [ $Bing -ne "1" ]; then
|
- |
|
121 |
SafeSearch=`grep ^\"\(\^http\:\/\/ $DIR_UPDATE/urlregexplist | wc -l`
|
- |
|
122 |
if [ $SafeSearch -eq "0" ]; then
|
- |
|
123 |
cat <<EOF >> $DIR_UPDATE/urlregexplist
|
- |
|
124 |
# Bing - add 'adlt=strict'
|
- |
|
125 |
#"(^http://[0-9a-z]+\.bing\.[a-z]+[-/%.0-9a-z]*\?)(.*)"->"\1\2&adlt=strict"
|
- |
|
126 |
# Youtube - add 'edufilter=your_ID'
|
- |
|
127 |
#"(^http://[0-9a-z]+\.youtube\.[a-z]+[-/%.0-9a-z]*\?)(.*)"->"\1\2&edufilter=ABCD1234567890abcdef"
|
- |
|
128 |
EOF
|
- |
|
129 |
else
|
- |
|
130 |
cat <<EOF >> $DIR_UPDATE/urlregexplist
|
- |
|
131 |
# Bing - add 'adlt=strict'
|
- |
|
132 |
"(^http://[0-9a-z]+\.bing\.[a-z]+[-/%.0-9a-z]*\?)(.*)"->"\1\2&adlt=strict"
|
- |
|
133 |
# Youtube - add 'edufilter=your_ID'
|
- |
|
134 |
"(^http://[0-9a-z]+\.youtube\.[a-z]+[-/%.0-9a-z]*\?)(.*)"->"\1\2&edufilter=ABCD1234567890abcdef"
|
- |
|
135 |
EOF
|
- |
|
136 |
fi
|
- |
|
137 |
fi
|
- |
|
138 |
# YOUTUBE_ID variable added in the conf file
|
- |
|
139 |
YOUTUBE_ID=`grep ^YOUTUBE_ID $CONF_FILE | cut -d"=" -f2`
|
- |
|
140 |
YOUTUBE_ID=${YOUTUBE_ID:="-1"}
|
- |
|
141 |
if [ $YOUTUBE_ID = "-1" ]; then
|
- |
|
142 |
echo "YOUTUBE_ID=ABCD1234567890abcdef" >> $CONF_FILE
|
- |
|
143 |
fi
|
- |
|
144 |
# DNSMASQ conf file
|
98 |
# DNSMASQ conf file
|
145 |
cp /etc/sysconfig/dnsmasq $DIR_UPDATE
|
99 |
cp /etc/sysconfig/dnsmasq $DIR_UPDATE
|
146 |
# ALCASAR conf file
|
100 |
# ALCASAR conf file
|
147 |
cp $CONF_FILE $DIR_UPDATE/etc/
|
101 |
cp $CONF_FILE $DIR_UPDATE/etc/
|
148 |
# création de l'archive et copie dans le répertoire WEB associé
|
102 |
# création de l'archive et copie dans le répertoire WEB associé
|
149 |
cd /tmp
|
103 |
cd /tmp
|
150 |
tar -cf alcasar-conf.tar conf/
|
104 |
tar -cf alcasar-conf.tar conf/
|
151 |
gzip -f alcasar-conf.tar
|
105 |
gzip -f alcasar-conf.tar
|
152 |
[ -d $DIR_SAVE ] && cp alcasar-conf.tar.gz $DIR_SAVE/$fichier
|
- |
|
153 |
rm -rf $DIR_UPDATE
|
106 |
rm -rf $DIR_UPDATE
|
154 |
;;
|
107 |
;;
|
155 |
--load|-load)
|
108 |
--load|-load)
|
156 |
cd /tmp
|
109 |
cd /tmp
|
157 |
tar -xf /tmp/alcasar-conf*.tar.gz
|
110 |
tar -xf /tmp/alcasar-conf*.tar.gz
|