672 |
richard |
1 |
#/bin/bash
|
64 |
franck |
2 |
# $Id: alcasar-conf.sh 1521 2014-12-17 22:57:44Z richard $
|
672 |
richard |
3 |
|
|
|
4 |
# alcasar-conf.sh
|
865 |
richard |
5 |
# by REXY
|
672 |
richard |
6 |
# This script is distributed under the Gnu General Public License (GPL)
|
|
|
7 |
|
|
|
8 |
# Ce script permet la mise à jour ALCASAR
|
1060 |
richard |
9 |
# - création de l'archive des fichiers de configuration (/tmp/alcasar-conf.tar.gz)
|
|
|
10 |
# - chargement d'une archive (lors de la mise à jour d'un alcasar)
|
|
|
11 |
# - application des directives du fichier de conf central "/usr/local/etc/alcasar.conf" (lors d'un changement de conf à chaud)
|
672 |
richard |
12 |
# This script allows ALCASAR update
|
1060 |
richard |
13 |
# - create the configuration files backup (/tmp/alcasar-conf.tar.gz)
|
|
|
14 |
# - load the bachup of configuration files (during the update process)
|
|
|
15 |
# - apply ALCASAR central configuration file "/usr/local/etc/alcasar.conf" (when hot modification are needed)
|
672 |
richard |
16 |
|
865 |
richard |
17 |
new="$(date +%G%m%d-%Hh%M)" # date et heure des fichiers
|
806 |
richard |
18 |
fichier="alcasar-conf-$new.tar.gz" # nom du fichier de sauvegarde
|
8 |
franck |
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
|
478 |
richard |
21 |
DIR_BIN="/usr/local/bin" # répertoire des scripts d'admin
|
346 |
richard |
22 |
DIR_SBIN="/usr/local/sbin" # répertoire des scripts d'admin
|
|
|
23 |
DIR_ETC="/usr/local/etc" # répertoire des fichiers de conf
|
811 |
richard |
24 |
DIR_SAVE="/var/Save/system_backup" # répertoire de sauvegarde
|
628 |
richard |
25 |
CONF_FILE="$DIR_ETC/alcasar.conf" # main alcasar conf file
|
510 |
richard |
26 |
VERSION="/var/www/html/VERSION" # contient la version en cours
|
1469 |
richard |
27 |
EXTIF=`grep ^EXTIF= $CONF_FILE|cut -d"=" -f2` # EXTernal InterFace
|
|
|
28 |
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2` # INTernal InterFace
|
628 |
richard |
29 |
HOSTNAME="alcasar"
|
369 |
richard |
30 |
DB_USER="radius"
|
504 |
richard |
31 |
radiuspwd=""
|
384 |
richard |
32 |
SED="/bin/sed -i"
|
510 |
richard |
33 |
RUNNING_VERSION=`cat $VERSION|cut -d" " -f1`
|
|
|
34 |
MAJ_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f1`
|
|
|
35 |
MIN_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f2|cut -c1`
|
|
|
36 |
UPD_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f3`
|
1062 |
richard |
37 |
DOMAIN=`grep DOMAIN $CONF_FILE|cut -d"=" -f2` 2>/dev/null # Error if (Version < 2.2) (no conf file)
|
923 |
franck |
38 |
DOMAIN=${DOMAIN:=localdomain}
|
628 |
richard |
39 |
DATE=`date '+%d %B %Y - %Hh%M'`
|
|
|
40 |
private_network_calc ()
|
|
|
41 |
{
|
1060 |
richard |
42 |
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2` # prefixe du réseau (ex. 24)
|
|
|
43 |
PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2` # @ réseau de consultation (ex.: 192.168.182.0)
|
|
|
44 |
PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX # @ + masque du réseau de consult (192.168.182.0/24)
|
628 |
richard |
45 |
classe=$((PRIVATE_PREFIX/8)); classe_sup=`expr $classe + 1`; classe_sup_sup=`expr $classe + 2` # classes de réseau (ex.: 2=classe B, 3=classe C)
|
1060 |
richard |
46 |
PRIVATE_NETWORK_SHORT=`echo $PRIVATE_NETWORK | cut -d"." -f1-$classe`. # @ compatible hosts.allow et hosts.deny (ex.: 192.168.182.)
|
|
|
47 |
PRIVATE_BROADCAST=`/bin/ipcalc -b $PRIVATE_NETWORK_MASK | cut -d"=" -f2` # private network broadcast (ie.: 192.168.182.255)
|
|
|
48 |
private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup` # last octet of LAN address
|
|
|
49 |
private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup` # last octet of LAN broadcast
|
|
|
50 |
PRIVATE_FIRST_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 1` # First network address (ex.: 192.168.182.1)
|
|
|
51 |
PRIVATE_SECOND_IP=`echo $PRIVATE_NETWORK | cut -d"." -f1-3`"."`expr $private_network_ending + 2` # second network address (ex.: 192.168.182.2)
|
|
|
52 |
PRIVATE_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1` # last network address (ex.: 192.168.182.254)
|
1460 |
franck |
53 |
PRIVATE_MAC=`/sbin/ip link show $INTIF | grep ether | cut -d" " -f6` # MAC address of INTIF
|
628 |
richard |
54 |
}
|
8 |
franck |
55 |
|
933 |
franck |
56 |
usage="Usage: alcasar-conf.sh {--create or -create} | {--load or -load} | {--apply or -apply}"
|
8 |
franck |
57 |
nb_args=$#
|
|
|
58 |
args=$1
|
|
|
59 |
if [ $nb_args -eq 0 ]
|
|
|
60 |
then
|
|
|
61 |
nb_args=1
|
|
|
62 |
args="-h"
|
|
|
63 |
fi
|
|
|
64 |
case $args in
|
|
|
65 |
-\? | -h* | --h*)
|
|
|
66 |
echo "$usage"
|
|
|
67 |
exit 0
|
|
|
68 |
;;
|
389 |
franck |
69 |
--create|-create)
|
8 |
franck |
70 |
[ -d $DIR_UPDATE ] && rm -rf $DIR_UPDATE
|
|
|
71 |
mkdir $DIR_UPDATE
|
|
|
72 |
# Sauvegarde de la base des usagers
|
1062 |
richard |
73 |
$DIR_SBIN/alcasar-mysql.sh -dump
|
8 |
franck |
74 |
cp /var/Save/base/`ls /var/Save/base|tail -1` $DIR_UPDATE
|
|
|
75 |
# Sauvegarde du logo
|
|
|
76 |
cp -f $DIR_WEB/images/organisme.png $DIR_UPDATE
|
310 |
richard |
77 |
# Sauvegarde des fichiers exploités par dansguardian
|
|
|
78 |
cp -f /etc/dansguardian/lists/exceptioniplist $DIR_UPDATE
|
879 |
richard |
79 |
cp -f /etc/dansguardian/lists/urlregexplist $DIR_UPDATE
|
310 |
richard |
80 |
cp -f /etc/dansguardian/lists/exceptionsitelist $DIR_UPDATE
|
|
|
81 |
cp -f /etc/dansguardian/lists/bannedsitelist $DIR_UPDATE
|
|
|
82 |
cp -f /etc/dansguardian/lists/exceptionurllist $DIR_UPDATE
|
|
|
83 |
cp -f /etc/dansguardian/lists/bannedurllist $DIR_UPDATE
|
|
|
84 |
cp -rf /etc/dansguardian/lists/blacklists/ossi $DIR_UPDATE
|
612 |
richard |
85 |
# sauvegarde des fichiers : de conf, de filtrage, d'exception, digest, etc.
|
8 |
franck |
86 |
mkdir $DIR_UPDATE/etc/
|
346 |
richard |
87 |
cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
|
510 |
richard |
88 |
# particularité des versions
|
1249 |
richard |
89 |
# si version <= 2.8
|
|
|
90 |
if [ $MAJ_RUNNING_VERSION -lt 2 ] || ([ $MAJ_RUNNING_VERSION -eq 2 ] && [ $MIN_RUNNING_VERSION -lt 8 ])
|
510 |
richard |
91 |
then
|
1252 |
richard |
92 |
$SED "s?alcasar?alcasar.$DOMAIN?g" $DIR_UPDATE/etc/digest/* # add the domainname to the hostname
|
510 |
richard |
93 |
else
|
1249 |
richard |
94 |
# si version > 2.8 : sauvegarde des certificats (serveur et CA)
|
510 |
richard |
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
|
675 |
richard |
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
|
|
|
104 |
fi
|
510 |
richard |
105 |
fi
|
1249 |
richard |
106 |
# Changes since V2.6
|
1062 |
richard |
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
|
1050 |
richard |
109 |
# macallowed is replaced with macauth
|
977 |
richard |
110 |
rm -f $DIR_UPDATE/etc/alcasar-macallowed
|
1050 |
richard |
111 |
# The option 'EXT_LAN_FILTERING' is deleted
|
885 |
richard |
112 |
$SED "/^EXT_LAN/d" $CONF_FILE
|
1050 |
richard |
113 |
# The category "ip" no longer exist
|
878 |
richard |
114 |
$SED "/\/ip\/urls/d" $DIR_UPDATE/bannedurllist; $SED "/\/ip\/domains/d" $DIR_UPDATE/bannedsitelist
|
885 |
richard |
115 |
$SED "/blacklists\/ip/d" $DIR_UPDATE/etc/alcasar-bl-categories; $SED "/^ip/d" $DIR_UPDATE/etc/alcasar-bl-categories-enabled
|
1050 |
richard |
116 |
# BL and WL are now dynamically built in "/usr/local/share"
|
1015 |
richard |
117 |
rm -rf $DIR_UPDATE/etc/alcasar-dnsfilter-enabled $DIR_UPDATE/etc/alcasar-dnsfilter-available
|
1050 |
richard |
118 |
# Bing et Youtube are addes to the safesearching system
|
885 |
richard |
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
|
977 |
richard |
138 |
# la variable YOUTUBE_ID est déclarée dans le fichier de conf
|
885 |
richard |
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
|
1492 |
franck |
144 |
# copie du fichier de config de dnsmasq
|
933 |
franck |
145 |
cp /etc/sysconfig/dnsmasq $DIR_UPDATE
|
885 |
richard |
146 |
# copie du fichier de conf modifié
|
|
|
147 |
cp $CONF_FILE $DIR_UPDATE/etc/
|
806 |
richard |
148 |
# le répertoire "ISO" est remplacé par "system_backup" suite à la suppression de "mondoarchive" (V2.5)
|
|
|
149 |
rm -rf /var/Save/ISO
|
|
|
150 |
# création de l'archive et copie dans le répertoire WEB associé
|
8 |
franck |
151 |
cd /tmp
|
|
|
152 |
tar -cf alcasar-conf.tar conf/
|
|
|
153 |
gzip -f alcasar-conf.tar
|
811 |
richard |
154 |
[ -d $DIR_SAVE ] && cp alcasar-conf.tar.gz $DIR_SAVE/$fichier
|
8 |
franck |
155 |
rm -rf $DIR_UPDATE
|
|
|
156 |
;;
|
389 |
franck |
157 |
--load|-load)
|
8 |
franck |
158 |
cd /tmp
|
1057 |
richard |
159 |
tar -xf /tmp/alcasar-conf*.tar.gz
|
1060 |
richard |
160 |
# Retrieve the logo
|
510 |
richard |
161 |
[ -e $DIR_UPDATE/organisme.png ] && cp -f $DIR_UPDATE/organisme.png $DIR_WEB/images/
|
8 |
franck |
162 |
chown apache:apache $DIR_WEB/images/organisme.png $DIR_WEB/intercept.php
|
1060 |
richard |
163 |
# Retrieve the security certificates (CA and server)
|
510 |
richard |
164 |
[ -e $DIR_UPDATE/alcasar-ca.crt ] && cp -f $DIR_UPDATE/alcasar-ca.crt /etc/pki/CA/
|
|
|
165 |
[ -e $DIR_UPDATE/alcasar-ca.key ] && cp -f $DIR_UPDATE/alcasar-ca.key /etc/pki/CA/private/
|
|
|
166 |
[ -e $DIR_UPDATE/alcasar.crt ] && cp -f $DIR_UPDATE/alcasar.crt /etc/pki/tls/certs/
|
|
|
167 |
[ -e $DIR_UPDATE/alcasar.key ] && cp -f $DIR_UPDATE/alcasar.key /etc/pki/tls/private/
|
675 |
richard |
168 |
[ -e $DIR_UPDATE/server-chain.crt ] && cp -f $DIR_UPDATE/server-chain.crt /etc/pki/tls/certs/
|
8 |
franck |
169 |
chown -R root:apache /etc/pki
|
|
|
170 |
chmod -R 750 /etc/pki
|
1060 |
richard |
171 |
# Import of the users database
|
8 |
franck |
172 |
mysql -u$DB_USER -p$radiuspwd < `ls $DIR_UPDATE/radius*`
|
1060 |
richard |
173 |
# Retrieve lacal parameters & Remove blacklist files (now in /usr/local/share)
|
1053 |
richard |
174 |
[ -d $DIR_UPDATE/etc ] && rm -rf $DIR_UPDATE/etc/alcasar-dnsfilter* && cp -rf $DIR_UPDATE/etc/* $DIR_ETC/
|
1060 |
richard |
175 |
# Retrieve Dansguardian files
|
510 |
richard |
176 |
[ -e $DIR_UPDATE/exceptioniplist ] && cp -f $DIR_UPDATE/exceptioniplist /etc/dansguardian/lists/
|
|
|
177 |
[ -e $DIR_UPDATE/exceptionsitelist ] && cp -f $DIR_UPDATE/exceptionsitelist /etc/dansguardian/lists/
|
879 |
richard |
178 |
[ -e $DIR_UPDATE/urlregexplist ] && cp -f $DIR_UPDATE/urlregexplist /etc/dansguardian/lists/
|
510 |
richard |
179 |
[ -e $DIR_UPDATE/bannedsitelist ] && cp -f $DIR_UPDATE/bannedsitelist /etc/dansguardian/lists/
|
|
|
180 |
[ -e $DIR_UPDATE/exceptionurllist ] && cp -f $DIR_UPDATE/exceptionurllist /etc/dansguardian/lists/
|
|
|
181 |
[ -e $DIR_UPDATE/bannedurllist ] && cp -f $DIR_UPDATE/bannedurllist /etc/dansguardian/lists/
|
|
|
182 |
[ -d $DIR_UPDATE/ossi ] && cp -rf $DIR_UPDATE/ossi /etc/dansguardian/lists/blacklists/
|
8 |
franck |
183 |
chown -R dansguardian:apache /etc/dansguardian/lists
|
|
|
184 |
chmod -R g+rw /etc/dansguardian/lists
|
1060 |
richard |
185 |
# Adapt DNS/URL filtering
|
|
|
186 |
PARENT_SCRIPT=`basename $0`
|
637 |
richard |
187 |
export PARENT_SCRIPT
|
1053 |
richard |
188 |
$DIR_SBIN/alcasar-bl.sh -adapt
|
654 |
richard |
189 |
$DIR_SBIN/alcasar-bl.sh -reload
|
1060 |
richard |
190 |
# retrieve dnsmasq general config file
|
|
|
191 |
[ -e $DIR_UPDATE/dnsmasq ] && cp -f $DIR_UPDATE/dnsmasq /etc/sysconfig/dnsmasq \
|
|
|
192 |
&& chown root.root /etc/sysconfig/dnsmasq \
|
|
|
193 |
&& chmod 644 /etc/sysconfig/dnsmasq
|
|
|
194 |
# admin profile update (admin + manager + backup)
|
395 |
franck |
195 |
$DIR_SBIN/alcasar-profil.sh --list
|
634 |
richard |
196 |
# Start / Stop SSH Daemon
|
1065 |
richard |
197 |
ssh_active=`grep SSH= $CONF_FILE|cut -d"=" -f2`
|
634 |
richard |
198 |
if [ $ssh_active = "on" ]
|
|
|
199 |
then
|
|
|
200 |
/sbin/chkconfig --add sshd
|
|
|
201 |
else
|
|
|
202 |
/sbin/chkconfig --del sshd
|
|
|
203 |
fi
|
1060 |
richard |
204 |
# Remove the update folder
|
8 |
franck |
205 |
rm -rf $DIR_UPDATE
|
|
|
206 |
;;
|
628 |
richard |
207 |
--apply|-apply)
|
994 |
franck |
208 |
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"
|
1054 |
franck |
209 |
PRIVATE_IP_MASK=`grep ^PRIVATE_IP $CONF_FILE|cut -d"=" -f2`
|
628 |
richard |
210 |
check=$(echo $PRIVATE_IP_MASK | egrep $PTN)
|
|
|
211 |
if [[ "$?" -ne 0 ]]
|
|
|
212 |
then
|
|
|
213 |
echo "Syntax error for PRIVATE_IP_MASK ($PRIVATE_IP_MASK)"
|
|
|
214 |
exit 0
|
|
|
215 |
fi
|
1054 |
franck |
216 |
PUBLIC_IP_MASK=`grep ^PUBLIC_IP $CONF_FILE|cut -d"=" -f2`
|
628 |
richard |
217 |
check=$(echo $PUBLIC_IP_MASK | egrep $PTN)
|
|
|
218 |
if [[ "$?" -ne 0 ]]
|
|
|
219 |
then
|
|
|
220 |
echo "Syntax error for PUBLIC_IP_MASK ($PUBLIC_IP_MASK)"
|
|
|
221 |
exit 0
|
|
|
222 |
fi
|
|
|
223 |
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]?)\b"
|
1054 |
franck |
224 |
PUBLIC_GATEWAY=`grep ^GW $CONF_FILE|cut -d"=" -f2`
|
628 |
richard |
225 |
check=$(echo $PUBLIC_GATEWAY | egrep $PTN)
|
|
|
226 |
if [[ "$?" -ne 0 ]]
|
|
|
227 |
then
|
|
|
228 |
echo "Syntax error for the Gateway IP ($PUBLIC_GATEWAY)"
|
|
|
229 |
exit 0
|
|
|
230 |
fi
|
1054 |
franck |
231 |
DNS1=`grep ^DNS1 $CONF_FILE|cut -d"=" -f2`
|
673 |
richard |
232 |
check=$(echo $DNS1 | egrep $PTN)
|
628 |
richard |
233 |
if [[ "$?" -ne 0 ]]
|
|
|
234 |
then
|
|
|
235 |
echo "Syntax error for the IP address of the first DNS server ($DNS1)"
|
|
|
236 |
exit 0
|
|
|
237 |
fi
|
1054 |
franck |
238 |
DNS2=`grep ^DNS2 $CONF_FILE|cut -d"=" -f2`
|
673 |
richard |
239 |
check=$(echo $DNS2 | egrep $PTN)
|
628 |
richard |
240 |
if [[ "$?" -ne 0 ]]
|
|
|
241 |
then
|
|
|
242 |
echo "Syntax error for the IP address of the second DNS server ($DNS2)"
|
|
|
243 |
exit 0
|
|
|
244 |
fi
|
632 |
richard |
245 |
PUBLIC_IP=`echo $PUBLIC_IP_MASK | cut -d"/" -f1`
|
|
|
246 |
PUBLIC_NETMASK=`/bin/ipcalc -m $PUBLIC_IP_MASK | cut -d"=" -f2`
|
631 |
richard |
247 |
PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
|
632 |
richard |
248 |
PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
|
628 |
richard |
249 |
private_network_calc
|
632 |
richard |
250 |
INSTALL_DATE=`grep INSTALL_DATE $CONF_FILE|cut -d"=" -f2`
|
|
|
251 |
ORGANISME=`grep ORGANISM $CONF_FILE|cut -d"=" -f2`
|
923 |
franck |
252 |
DOMAIN=`grep DOMAIN $CONF_FILE|cut -d"=" -f2`
|
862 |
richard |
253 |
DHCP_mode=`grep DHCP= $CONF_FILE|cut -d"=" -f2`
|
1460 |
franck |
254 |
# create file for DHCP static ip. Reserve the second IP address for INTIF (the first one is for tun0)
|
|
|
255 |
echo "$PRIVATE_MAC $PRIVATE_SECOND_IP" > $DIR_ETC/alcasar-ethers
|
1060 |
richard |
256 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
933 |
franck |
257 |
then
|
1060 |
richard |
258 |
if [ $DHCP_mode = "off" ]
|
|
|
259 |
then
|
|
|
260 |
$DIR_SBIN/alcasar-dhcp.sh --off
|
|
|
261 |
fi
|
634 |
richard |
262 |
# Logout everybody
|
1060 |
richard |
263 |
$DIR_SBIN/alcasar-logout.sh all
|
634 |
richard |
264 |
# Services stop
|
1521 |
richard |
265 |
echo -n "Stop services : "
|
1518 |
richard |
266 |
for i in ntpd httpd tinyproxy dnsmasq dnsmasq-whitelist dnsmasq-blacklist chilli network
|
1060 |
richard |
267 |
do
|
1521 |
richard |
268 |
systemctl stop $i && echo -n "$i, "
|
1060 |
richard |
269 |
done
|
1521 |
richard |
270 |
echo
|
1060 |
richard |
271 |
fi
|
628 |
richard |
272 |
|
|
|
273 |
# /etc/hosts
|
|
|
274 |
cat <<EOF > /etc/hosts
|
|
|
275 |
127.0.0.1 localhost
|
923 |
franck |
276 |
$PRIVATE_IP $HOSTNAME $HOSTNAME.$DOMAIN
|
628 |
richard |
277 |
EOF
|
|
|
278 |
|
1518 |
richard |
279 |
# EXTIF config
|
628 |
richard |
280 |
$SED "s?^IPADDR=.*?IPADDR=$PUBLIC_IP?" /etc/sysconfig/network-scripts/ifcfg-$EXTIF
|
|
|
281 |
$SED "s?^NETMASK=.*?NETMASK=$PUBLIC_NETMASK?" /etc/sysconfig/network-scripts/ifcfg-$EXTIF
|
|
|
282 |
$SED "s?^GATEWAY=.*?GATEWAY=$PUBLIC_GATEWAY?" /etc/sysconfig/network-scripts/ifcfg-$EXTIF
|
1518 |
richard |
283 |
# INTIF config (for bypass mode only)
|
1521 |
richard |
284 |
$SED "s?^IPADDR=.*?IPADDR=$PRIVATE_IP?" /etc/sysconfig/network-scripts/default-ifcfg-$INTIF
|
|
|
285 |
$SED "s?^NETMASK=.*?NETMASK=$PRIVATE_NETMASK?" /etc/sysconfig/network-scripts/default-ifcfg-$INTIF
|
628 |
richard |
286 |
# NTP server
|
632 |
richard |
287 |
$SED "/127.0.0.1/!s?^restrict.*?restrict $PRIVATE_NETWORK mask $PRIVATE_NETMASK nomodify notrap?g" /etc/ntp.conf
|
628 |
richard |
288 |
# host.allow
|
|
|
289 |
cat <<EOF > /etc/hosts.allow
|
|
|
290 |
ALL: LOCAL, 127.0.0.1, localhost, $PRIVATE_IP
|
|
|
291 |
sshd: ALL
|
|
|
292 |
ntpd: $PRIVATE_NETWORK_SHORT
|
|
|
293 |
EOF
|
632 |
richard |
294 |
# Alcasar Control Center
|
634 |
richard |
295 |
$SED "s?^Listen.*?Listen $PRIVATE_IP:80?g" /etc/httpd/conf/httpd.conf
|
1419 |
richard |
296 |
FIC_MOD_SSL=`find /etc/httpd/conf/ -type f -name ssl.conf`
|
634 |
richard |
297 |
$SED "s?^Listen.*?Listen $PRIVATE_IP:443?g" $FIC_MOD_SSL
|
|
|
298 |
$SED "/127.0.0.1/!s?Allow from .*?Allow from $PRIVATE_NETWORK_MASK?g" /etc/httpd/conf/webapps.d/alcasar.conf
|
632 |
richard |
299 |
# Dialup_Admin
|
634 |
richard |
300 |
$SED "s?^nas1_name:.*?nas1_name: alcasar-$ORGANISME?g" /etc/freeradius-web/naslist.conf
|
|
|
301 |
$SED "s?^nas1_ip:.*?nas1_ip: $PRIVATE_IP?g" /etc/freeradius-web/naslist.conf
|
632 |
richard |
302 |
# coova
|
634 |
richard |
303 |
$SED "s?^net.*?net\t\t$PRIVATE_NETWORK_MASK?g" /etc/chilli.conf
|
|
|
304 |
$SED "s?^dns1.*?dns1\t\t$PRIVATE_IP?g" /etc/chilli.conf
|
|
|
305 |
$SED "s?^dns2.*?dns2\t\t$PRIVATE_IP?g" /etc/chilli.conf
|
|
|
306 |
$SED "s?^uamlisten.*?uamlisten\t$PRIVATE_IP?g" /etc/chilli.conf
|
632 |
richard |
307 |
# dnsmasq
|
1419 |
richard |
308 |
$SED "/127.0.0.1/!s?^listen-address=.*?listen-address=$PRIVATE_IP?g" /etc/dnsmasq.conf /etc/dnsmasq-blacklist.conf /etc/dnsmasq-whitelist.conf
|
1377 |
richard |
309 |
for i in /etc/dnsmasq.conf /etc/dnsmasq-blacklist.conf
|
673 |
richard |
310 |
do
|
|
|
311 |
$SED "/^server=/d" $i
|
|
|
312 |
echo "server=$DNS1" >> $i
|
|
|
313 |
echo "server=$DNS2" >> $i
|
|
|
314 |
done
|
1060 |
richard |
315 |
$SED "s?^dhcp-range=.*?dhcp-range=$PRIVATE_SECOND_IP,$PRIVATE_LAST_IP,$PRIVATE_NETMASK,12h?g" /etc/dnsmasq.conf
|
634 |
richard |
316 |
$SED "s?^dhcp-option=option:router.*?dhcp-option=option:router,$PRIVATE_IP?g" /etc/dnsmasq.conf
|
1518 |
richard |
317 |
# tinyproxy
|
|
|
318 |
$SED "s?^Listen.*?Listen $PRIVATE_IP?g" /etc/tinyproxy/tinyproxy.conf
|
634 |
richard |
319 |
# DG + BL
|
|
|
320 |
$SED "s?^filterip.*?filterip = $PRIVATE_IP?g" /etc/dansguardian/dansguardian.conf
|
|
|
321 |
# Watchdog
|
|
|
322 |
$SED "s?^PRIVATE_IP=.*?PRIVATE_IP=\"$PRIVATE_IP\"?g" $DIR_BIN/alcasar-watchdog.sh
|
|
|
323 |
# SSHD
|
1024 |
franck |
324 |
$SED "/^ListenAddress/d" /etc/ssh/sshd_config
|
|
|
325 |
$SED "/ListenAddress 0.0.0.0.*/a\ListenAddress $PUBLIC_IP" /etc/ssh/sshd_config
|
1020 |
franck |
326 |
$SED "/ListenAddress $PUBLIC_IP/a\ListenAddress $PRIVATE_IP" /etc/ssh/sshd_config
|
634 |
richard |
327 |
# Prompts
|
|
|
328 |
$SED "s?^ORGANISME.*?ORGANISME=$ORGANISME?g" /etc/bashrc
|
|
|
329 |
# sudoers
|
|
|
330 |
$SED "s?^Host_Alias.*?Host_Alias LAN_ORG=$PRIVATE_NETWORK/$PRIVATE_NETMASK,localhost #réseau de l'organisme?g" /etc/sudoers
|
1060 |
richard |
331 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
|
|
332 |
then
|
634 |
richard |
333 |
# Services start
|
1521 |
richard |
334 |
systemctl start network && echo -n "Start service : network" && sleep 1
|
|
|
335 |
$DIR_SBIN/alcasar-dhcp.sh -$DHCP_mode && echo -n ", coova" # apply DHCP mode and start coova
|
|
|
336 |
for i in dnsmasq httpd tinyproxy ntpd
|
|
|
337 |
do
|
|
|
338 |
sleep 1
|
|
|
339 |
systemctl start $i && echo -n ", $i"
|
|
|
340 |
done
|
|
|
341 |
$DIR_SBIN/alcasar-bl.sh -reload && echo ", dnsmasq-blacklist, dnsmasq-whitelist, iptables"
|
1060 |
richard |
342 |
fi
|
628 |
richard |
343 |
# Start / Stop SSH Daemon
|
1065 |
richard |
344 |
ssh_active=`grep SSH= $CONF_FILE|cut -d"=" -f2`
|
634 |
richard |
345 |
if [ $ssh_active = "on" ]
|
|
|
346 |
then
|
1060 |
richard |
347 |
/bin/systemctl enable sshd.service
|
|
|
348 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
|
|
349 |
then
|
|
|
350 |
/bin/systemctl start sshd.service
|
|
|
351 |
fi
|
634 |
richard |
352 |
else
|
1060 |
richard |
353 |
/bin/systemctl disable sshd.service
|
|
|
354 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
|
|
355 |
then
|
|
|
356 |
/bin/systemctl stop sshd.service
|
|
|
357 |
fi
|
634 |
richard |
358 |
fi
|
628 |
richard |
359 |
;;
|
8 |
franck |
360 |
*)
|
|
|
361 |
echo "Argument inconnu :$1";
|
|
|
362 |
echo "$usage"
|
|
|
363 |
exit 1
|
|
|
364 |
;;
|
|
|
365 |
esac
|
|
|
366 |
|