2223 |
tom.houday |
1 |
#!/bin/bash
|
64 |
franck |
2 |
# $Id: alcasar-conf.sh 2878 2020-11-01 21:48:35Z rexy $
|
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 |
|
2744 |
rexy |
8 |
# Ce script permet la mise à jour d'un ALCASAR
|
|
|
9 |
# - (alcasar-conf.sh -create) : création de l'archive des fichiers de configuration (/var/tmp/alcasar-conf.tar.gz)
|
|
|
10 |
# - (alcasar-conf.sh -load) : chargement de l'archive des fichiers de configuration. Le cas échéant, c'est ici qu'on met à jour les fichiers entre versions
|
|
|
11 |
# - (alcasar-conf.sh -apply) : application des directives du fichier de conf central "/usr/local/etc/alcasar.conf". Peut aussi être exploité à chaud après avoir changé des valeurs du fichier de conf.
|
2570 |
rexy |
12 |
# This script allows ALCASAR update
|
2744 |
rexy |
13 |
# - (alcasar-conf.sh -create) : create the configuration files backup (/var/tmp/alcasar-conf.tar.gz)
|
|
|
14 |
# - (alcasar-conf.sh -load) : load the backup of configuration files. If needed, it's here we update files between versions
|
|
|
15 |
# - (alcasar-conf.sh -load) : apply ALCASAR central configuration file "/usr/local/etc/alcasar.conf". Can be use after changes of conf file values.
|
672 |
richard |
16 |
|
2585 |
tom.houday |
17 |
DIR_UPDATE="/var/tmp/conf" # répertoire de stockage des fichier de conf pour une mise à jour
|
2247 |
tom.houday |
18 |
DIR_WEB="/var/www/html" # répertoire du centre de gestion
|
|
|
19 |
DIR_BIN="/usr/local/bin" # scripts directory
|
|
|
20 |
DIR_ETC="/usr/local/etc" # conf directory
|
2688 |
lucas.echa |
21 |
DIR_E2G="/etc/e2guardian/lists" # Toulouse BL directory
|
|
|
22 |
DIR_BLACKLIST="$DIR_E2G/blacklists" # Toulouse BL directory
|
2878 |
rexy |
23 |
CONF_FILE="$DIR_ETC/alcasar.conf" # main alcasar conf file
|
|
|
24 |
PASSWD_FILE="/root/ALCASAR-passwords.txt"
|
|
|
25 |
DB_USER=$(grep '^db_user=' $PASSWD_FILE | cut -d'=' -f 2-)
|
|
|
26 |
DB_PASS=$(grep '^db_password=' $PASSWD_FILE | cut -d'=' -f 2-)
|
2247 |
tom.houday |
27 |
EXTIF=`grep ^EXTIF= $CONF_FILE|cut -d"=" -f2` # EXTernal InterFace
|
|
|
28 |
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2` # INTernal InterFace
|
|
|
29 |
MTU=`grep ^PUBLIC_MTU= $CONF_FILE|cut -d"=" -f2`
|
1890 |
franck |
30 |
DHCP_mode=`grep ^DHCP= $CONF_FILE|cut -d"=" -f2`
|
|
|
31 |
INT_DNS_mode=`grep ^INT_DNS_ACTIVE= $CONF_FILE|cut -d"=" -f2`
|
2247 |
tom.houday |
32 |
HOSTNAME=`grep ^HOSTNAME= $CONF_FILE|cut -d"=" -f2`
|
|
|
33 |
DOMAIN=`grep ^DOMAIN= $CONF_FILE|cut -d"=" -f2`
|
384 |
richard |
34 |
SED="/bin/sed -i"
|
2474 |
tom.houday |
35 |
DNS1=`grep ^DNS1= $CONF_FILE | cut -d'=' -f2` # server DNS1 (for WL domain names)
|
923 |
franck |
36 |
DOMAIN=${DOMAIN:=localdomain}
|
2247 |
tom.houday |
37 |
|
628 |
richard |
38 |
private_network_calc ()
|
|
|
39 |
{
|
1060 |
richard |
40 |
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2` # prefixe du réseau (ex. 24)
|
2561 |
rexy |
41 |
PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2` # @ réseau de consultation (ex.: 192.168.182.0)
|
|
|
42 |
PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX # @ + masque du réseau de consult (192.168.182.0/24)
|
2688 |
lucas.echa |
43 |
classe=$((PRIVATE_PREFIX/8)); classe_sup=`expr $classe + 1`; # classes de réseau (ex.: 2=classe B, 3=classe C)
|
1060 |
richard |
44 |
PRIVATE_NETWORK_SHORT=`echo $PRIVATE_NETWORK | cut -d"." -f1-$classe`. # @ compatible hosts.allow et hosts.deny (ex.: 192.168.182.)
|
|
|
45 |
PRIVATE_BROADCAST=`/bin/ipcalc -b $PRIVATE_NETWORK_MASK | cut -d"=" -f2` # private network broadcast (ie.: 192.168.182.255)
|
2561 |
rexy |
46 |
private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup` # last octet of LAN broadcast
|
|
|
47 |
private_ip_ending=`echo $PRIVATE_IP | cut -d"." -f4` # last octet of LAN address
|
|
|
48 |
PRIVATE_SECOND_IP=`echo $PRIVATE_IP | cut -d"." -f1-3`"."`expr $private_ip_ending + 1` # second network address (ex.: 192.168.182.2)
|
1060 |
richard |
49 |
PRIVATE_LAST_IP=`echo $PRIVATE_BROADCAST | cut -d"." -f1-3`"."`expr $private_broadcast_ending - 1` # last network address (ex.: 192.168.182.254)
|
1581 |
richard |
50 |
PRIVATE_MAC=`/sbin/ip link show $INTIF | grep ether | cut -d" " -f6| sed 's/:/-/g'| awk '{print toupper($0)}'` # MAC address of INTIF
|
628 |
richard |
51 |
}
|
8 |
franck |
52 |
|
933 |
franck |
53 |
usage="Usage: alcasar-conf.sh {--create or -create} | {--load or -load} | {--apply or -apply}"
|
8 |
franck |
54 |
nb_args=$#
|
|
|
55 |
args=$1
|
|
|
56 |
if [ $nb_args -eq 0 ]
|
|
|
57 |
then
|
2430 |
tom.houday |
58 |
nb_args=1
|
8 |
franck |
59 |
args="-h"
|
|
|
60 |
fi
|
|
|
61 |
case $args in
|
|
|
62 |
-\? | -h* | --h*)
|
|
|
63 |
echo "$usage"
|
|
|
64 |
exit 0
|
|
|
65 |
;;
|
2874 |
rexy |
66 |
###################################################
|
|
|
67 |
## Create an archive conf file ##
|
|
|
68 |
###################################################
|
|
|
69 |
--create|-create)
|
8 |
franck |
70 |
[ -d $DIR_UPDATE ] && rm -rf $DIR_UPDATE
|
|
|
71 |
mkdir $DIR_UPDATE
|
1916 |
franck |
72 |
# backup the users database (test to delete in future version)
|
2664 |
tom.houday |
73 |
$DIR_BIN/alcasar-mysql.sh --dump
|
2688 |
lucas.echa |
74 |
cp /var/Save/base/"$(ls -1t /var/Save/base|head -1)" $DIR_UPDATE
|
2824 |
rexy |
75 |
# backup organism logo
|
8 |
franck |
76 |
cp -f $DIR_WEB/images/organisme.png $DIR_UPDATE
|
1912 |
richard |
77 |
# backup BL/WL custom files
|
1914 |
richard |
78 |
mkdir $DIR_UPDATE/custom_bl
|
2541 |
rexy |
79 |
for i in exceptioniplist urlregexplist exceptionsitelist bannedsitelist exceptionurllist bannedurllist
|
|
|
80 |
do
|
2570 |
rexy |
81 |
if [ -d /etc/dansguardian ]; then
|
|
|
82 |
cp /etc/dansguardian/lists/$i $DIR_UPDATE/custom_bl/ # before V3.3
|
2661 |
lucas.echa |
83 |
cp -rf /etc/dansguardian/lists/blacklists/ossi-* $DIR_UPDATE/custom_bl/ 2>/dev/null
|
2541 |
rexy |
84 |
else
|
2688 |
lucas.echa |
85 |
cp $DIR_E2G/$i $DIR_UPDATE/custom_bl/ # since V3.3
|
2661 |
lucas.echa |
86 |
cp -rf $DIR_BLACKLIST/ossi-* $DIR_UPDATE/custom_bl/ 2>/dev/null
|
2541 |
rexy |
87 |
fi
|
|
|
88 |
done
|
2824 |
rexy |
89 |
# backup conf files (main conf file, filtering, digest, etc.)
|
8 |
franck |
90 |
mkdir $DIR_UPDATE/etc/
|
346 |
richard |
91 |
cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
|
2825 |
rexy |
92 |
cp -f /etc/hosts $DIR_UPDATE/etc/
|
1758 |
richard |
93 |
# backup of the security certificates (server & CA)
|
2561 |
rexy |
94 |
cp -f /etc/pki/tls/certs/alcasar.crt* $DIR_UPDATE
|
|
|
95 |
cp -f /etc/pki/tls/private/alcasar.key* $DIR_UPDATE
|
2570 |
rexy |
96 |
[ -e /etc/pki/tls/private/alcasar.pem ] && cp -f /etc/pki/tls/private/alcasar.pem $DIR_UPDATE # since V3.3
|
1564 |
richard |
97 |
cp -f /etc/pki/CA/alcasar-ca.crt $DIR_UPDATE
|
|
|
98 |
cp -f /etc/pki/CA/private/alcasar-ca.key $DIR_UPDATE
|
2813 |
rexy |
99 |
if [ -e /etc/pki/tls/certs/server-chain.pem ]; then
|
|
|
100 |
cp -f /etc/pki/tls/certs/server-chain.pem $DIR_UPDATE # autosigned and official if exist
|
510 |
richard |
101 |
else
|
2813 |
rexy |
102 |
cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE/server-chain.pem
|
510 |
richard |
103 |
fi
|
2875 |
rexy |
104 |
# backup gammu conf file (if necessary)
|
|
|
105 |
SMS=`grep ^SMS= $CONF_FILE|cut -d"=" -f2`
|
|
|
106 |
if [ "$SMS" == "on" ]
|
|
|
107 |
then
|
|
|
108 |
cp -f /etc/gammurc $DIR_UPDATE
|
|
|
109 |
cp -f /etc/gammu_smsd_conf $DIR_UPDATE
|
|
|
110 |
fi
|
1758 |
richard |
111 |
# archive file creation
|
2688 |
lucas.echa |
112 |
cd /var/tmp || { echo "Unable to find /var/tmp directory"; }
|
8 |
franck |
113 |
tar -cf alcasar-conf.tar conf/
|
|
|
114 |
gzip -f alcasar-conf.tar
|
2835 |
rexy |
115 |
cp alcasar-conf.tar.gz /var/www/html/acc/backup/alcasar-conf.tar.gz
|
|
|
116 |
chown apache:apache /var/www/html/acc/backup/alcasar-conf.tar.gz
|
8 |
franck |
117 |
rm -rf $DIR_UPDATE
|
|
|
118 |
;;
|
2560 |
rexy |
119 |
|
2874 |
rexy |
120 |
###################################################
|
|
|
121 |
## Load an archive conf file ##
|
|
|
122 |
###################################################
|
389 |
franck |
123 |
--load|-load)
|
2688 |
lucas.echa |
124 |
cd /var/tmp || { echo "Unable to find /var/tmp directory"; }
|
2834 |
rexy |
125 |
tar -xf alcasar-conf.tar.gz
|
2824 |
rexy |
126 |
# copy alcasar.conf parameters
|
2561 |
rexy |
127 |
PREVIOUS_VERSION=`grep ^VERSION= $DIR_UPDATE/etc/alcasar.conf|cut -d"=" -f2`
|
|
|
128 |
MAJ_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f1`
|
|
|
129 |
MIN_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f2`
|
|
|
130 |
UPD_PREVIOUS_VERSION=`echo $PREVIOUS_VERSION|cut -d"." -f3|cut -c1`
|
2875 |
rexy |
131 |
for line in `cat $DIR_UPDATE/etc/alcasar.conf | grep "=" | grep -Ev "^#| |VERSION|INSTALL_DATE|PUBLIC|GW|EXTIF|INTIF"`
|
2824 |
rexy |
132 |
do
|
|
|
133 |
key=`echo $line | cut -d"=" -f1`
|
|
|
134 |
key=$key=
|
|
|
135 |
value=`echo $line|cut -d"=" -f2-`
|
|
|
136 |
if [ "$value" != "" ]
|
|
|
137 |
then
|
|
|
138 |
sed -i "s?^$key.*?$key$value?g" /usr/local/etc/alcasar.conf
|
|
|
139 |
fi
|
|
|
140 |
done
|
2874 |
rexy |
141 |
# lighttpd need a .pem certificate (aggregation with private key & server crt)
|
2665 |
tom.houday |
142 |
[ ! -f $DIR_UPDATE/alcasar.pem ] && (cat $DIR_UPDATE/alcasar.key; echo; cat $DIR_UPDATE/alcasar.crt) > $DIR_UPDATE/alcasar.pem
|
2824 |
rexy |
143 |
# Retrieve organism logo
|
510 |
richard |
144 |
[ -e $DIR_UPDATE/organisme.png ] && cp -f $DIR_UPDATE/organisme.png $DIR_WEB/images/
|
8 |
franck |
145 |
chown apache:apache $DIR_WEB/images/organisme.png $DIR_WEB/intercept.php
|
1060 |
richard |
146 |
# Retrieve the security certificates (CA and server)
|
2571 |
rexy |
147 |
cp -f $DIR_UPDATE/alcasar-ca.crt /etc/pki/CA/
|
|
|
148 |
cp -f $DIR_UPDATE/alcasar-ca.key /etc/pki/CA/private/
|
1758 |
richard |
149 |
cp -f $DIR_UPDATE/alcasar.crt /etc/pki/tls/certs/
|
|
|
150 |
cp -f $DIR_UPDATE/alcasar.key /etc/pki/tls/private/
|
2688 |
lucas.echa |
151 |
cp -f $DIR_UPDATE/alcasar.pem /etc/pki/tls/private/
|
2813 |
rexy |
152 |
[ -e $DIR_UPDATE/server-chain.pem ] && cp -f $DIR_UPDATE/server-chain.pem /etc/pki/tls/certs/ # autosigned and official if exist
|
2825 |
rexy |
153 |
chmod 755 /etc/pki/
|
2811 |
rexy |
154 |
chown root:apache /etc/pki/CA; chmod 750 /etc/pki/CA
|
2825 |
rexy |
155 |
chown root:apache /etc/pki/CA/alcasar-ca.crt; chmod 640 /etc/pki/CA/alcasar-ca.crt
|
2811 |
rexy |
156 |
chown root:root /etc/pki/CA/private; chmod 700 /etc/pki/CA/private
|
|
|
157 |
chmod 600 /etc/pki/CA/private/*
|
|
|
158 |
chown -R root:apache /etc/pki/tls/private; chmod 750 /etc/pki/tls/private
|
|
|
159 |
chmod 640 /etc/pki/tls/private/*
|
2825 |
rexy |
160 |
chmod 644 /etc/pki/tls/certs/* # "freshclam" need to access to that bundle
|
1060 |
richard |
161 |
# Import of the users database
|
2688 |
lucas.echa |
162 |
$DIR_BIN/alcasar-mysql.sh --import "$(ls $DIR_UPDATE/alcasar-users-database*)"
|
1914 |
richard |
163 |
# Retrieve local parameters
|
2825 |
rexy |
164 |
[ -d $DIR_UPDATE/etc/digest ] && cp -rf $DIR_UPDATE/etc/digest $DIR_ETC/ # ACC accounts
|
|
|
165 |
[ -e $DIR_UPDATE/etc/alcasar-iptables-local.sh ] && cp -f $DIR_UPDATE/etc/alcasar-iptables-local.sh $DIR_ETC/ # local FW rules
|
|
|
166 |
[ -e $DIR_UPDATE/etc/alcasar-iptables-local-mac-filtered ] && cp -f $DIR_UPDATE/etc/alcasar-iptables-local-mac-filtered $DIR_ETC/ # blocked MAC addresses
|
|
|
167 |
[ -e $DIR_UPDATE/etc/alcasar-uamdomain ] && cp -f $DIR_UPDATE/etc/alcasar-uamdomain $DIR_ETC/ # exception domain names
|
|
|
168 |
[ -e $DIR_UPDATE/etc/alcasar-uamallowed ] && cp -f $DIR_UPDATE/etc/alcasar-uamallowed $DIR_ETC/ # exception IP_addresses or network_IP_addresses
|
|
|
169 |
[ -e $DIR_UPDATE/etc/alcasar-ethers ] && cp -f $DIR_UPDATE/etc/alcasar-ethers $DIR_ETC/ # DHCP static hosts
|
|
|
170 |
[ -e $DIR_UPDATE/etc/alcasar-ethers-info ] && cp -f $DIR_UPDATE/etc/alcasar-ethers-info $DIR_ETC/ # DHCP static hosts information
|
2833 |
rexy |
171 |
[ -e $DIR_UPDATE/etc/hosts ] && cp -f $DIR_UPDATE/etc/hosts /etc/ # local host name resolution
|
2874 |
rexy |
172 |
[ -e $DIR_UPDATE/etc/alcasar-letsencrypt ] && cp -f $DIR_UPDATE/etc/alcasar-letsencrypt $DIR_ETC/ # Letsencrypt local conf
|
|
|
173 |
[ -d $DIR_UPDATE/etc/letsencrypt ] && cp -rf $DIR_UPDATE/etc/letsencrypt $DIR_ETC/ # Letsencrypt local conf files
|
2875 |
rexy |
174 |
[ -e $DIR_UPDATE/gammurc ] && cp -f $DIR_UPDATE/gammurc /etc/ # Gammu conf file
|
|
|
175 |
[ -e $DIR_UPDATE/gammu_smsd_conf ] && cp -f $DIR_UPDATE/gammu_smsd_conf /etc/ # Gammu_smsd conf file
|
1914 |
richard |
176 |
# Retrieve BL/WL custom files
|
2688 |
lucas.echa |
177 |
cp -f $DIR_UPDATE/custom_bl/exceptioniplist $DIR_E2G/
|
|
|
178 |
cp -f $DIR_UPDATE/custom_bl/exceptionsitelist $DIR_E2G/
|
|
|
179 |
cp -f $DIR_UPDATE/custom_bl/urlregexplist $DIR_E2G/
|
|
|
180 |
cp -f $DIR_UPDATE/custom_bl/bannedsitelist $DIR_E2G/
|
|
|
181 |
cp -f $DIR_UPDATE/custom_bl/exceptionurllist $DIR_E2G/
|
|
|
182 |
cp -f $DIR_UPDATE/custom_bl/bannedurllist $DIR_E2G/
|
1961 |
richard |
183 |
cp -rf $DIR_UPDATE/custom_bl/ossi-* $DIR_BLACKLIST/ 2>/dev/null
|
2688 |
lucas.echa |
184 |
chown -R e2guardian:apache $DIR_E2G
|
|
|
185 |
chmod -R g+rw $DIR_E2G
|
1060 |
richard |
186 |
# Adapt DNS/URL filtering
|
|
|
187 |
PARENT_SCRIPT=`basename $0`
|
637 |
richard |
188 |
export PARENT_SCRIPT
|
1946 |
richard |
189 |
$DIR_BIN/alcasar-bl.sh -cat_choice
|
1827 |
raphael.pi |
190 |
$DIR_BIN/alcasar-bl.sh -reload
|
1060 |
richard |
191 |
# admin profile update (admin + manager + backup)
|
1827 |
raphael.pi |
192 |
$DIR_BIN/alcasar-profil.sh --list
|
634 |
richard |
193 |
# Start / Stop SSH Daemon
|
2327 |
richard |
194 |
ssh_active=`grep "^SSH=" $CONF_FILE|cut -d"=" -f2`
|
634 |
richard |
195 |
if [ $ssh_active = "on" ]
|
|
|
196 |
then
|
1574 |
richard |
197 |
/usr/bin/systemctl -q enable sshd.service
|
634 |
richard |
198 |
else
|
1574 |
richard |
199 |
/usr/bin/systemctl -q disable sshd.service
|
634 |
richard |
200 |
fi
|
1060 |
richard |
201 |
# Remove the update folder
|
8 |
franck |
202 |
rm -rf $DIR_UPDATE
|
|
|
203 |
;;
|
2560 |
rexy |
204 |
|
2874 |
rexy |
205 |
####################################################
|
|
|
206 |
## Configure ALCASAR according to alcasar.conf ##
|
|
|
207 |
####################################################
|
628 |
richard |
208 |
--apply|-apply)
|
994 |
franck |
209 |
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"
|
2474 |
tom.houday |
210 |
PRIVATE_IP_MASK=`grep ^PRIVATE_IP= $CONF_FILE|cut -d"=" -f2`
|
2688 |
lucas.echa |
211 |
if ! echo $PRIVATE_IP_MASK | egrep -q $PTN
|
|
|
212 |
then
|
628 |
richard |
213 |
echo "Syntax error for PRIVATE_IP_MASK ($PRIVATE_IP_MASK)"
|
|
|
214 |
exit 0
|
|
|
215 |
fi
|
2474 |
tom.houday |
216 |
PUBLIC_IP_MASK=`grep ^PUBLIC_IP= $CONF_FILE|cut -d"=" -f2`
|
1590 |
richard |
217 |
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"
|
1585 |
richard |
218 |
if [[ "$PUBLIC_IP_MASK" == "dhcp" ]]
|
|
|
219 |
then
|
|
|
220 |
PUBLIC_GATEWAY="dhcp"
|
|
|
221 |
else
|
2688 |
lucas.echa |
222 |
if ! echo $PUBLIC_IP_MASK | egrep -q $PTN
|
|
|
223 |
then
|
1585 |
richard |
224 |
echo "Syntax error for PUBLIC_IP_MASK ($PUBLIC_IP_MASK)"
|
|
|
225 |
exit 0
|
|
|
226 |
fi
|
1590 |
richard |
227 |
PUBLIC_IP=`echo $PUBLIC_IP_MASK | cut -d"/" -f1`
|
|
|
228 |
PUBLIC_NETMASK=`/bin/ipcalc -m $PUBLIC_IP_MASK | cut -d"=" -f2`
|
2474 |
tom.houday |
229 |
PUBLIC_GATEWAY=`grep ^GW= $CONF_FILE|cut -d"=" -f2`
|
2688 |
lucas.echa |
230 |
if ! echo $PUBLIC_GATEWAY | egrep -q $PTN
|
|
|
231 |
then
|
1585 |
richard |
232 |
echo "Syntax error for the Gateway IP ($PUBLIC_GATEWAY)"
|
|
|
233 |
exit 0
|
|
|
234 |
fi
|
628 |
richard |
235 |
fi
|
2474 |
tom.houday |
236 |
DNS1=`grep ^DNS1= $CONF_FILE|cut -d"=" -f2`
|
2688 |
lucas.echa |
237 |
if ! echo $DNS1 | egrep -q $PTN
|
|
|
238 |
then
|
1590 |
richard |
239 |
echo "Syntax error for the IP address of the first DNS server ($DNS1)"
|
|
|
240 |
exit 0
|
|
|
241 |
fi
|
2474 |
tom.houday |
242 |
DNS2=`grep ^DNS2= $CONF_FILE|cut -d"=" -f2`
|
2688 |
lucas.echa |
243 |
if ! echo $DNS2 | egrep -q $PTN
|
|
|
244 |
then
|
1590 |
richard |
245 |
echo "Syntax error for the IP address of the second DNS server ($DNS2)"
|
|
|
246 |
exit 0
|
|
|
247 |
fi
|
631 |
richard |
248 |
PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
|
632 |
richard |
249 |
PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
|
628 |
richard |
250 |
private_network_calc
|
2474 |
tom.houday |
251 |
INSTALL_DATE=`grep ^INSTALL_DATE= $CONF_FILE|cut -d"=" -f2`
|
|
|
252 |
ORGANISME=`grep ^ORGANISM= $CONF_FILE|cut -d"=" -f2-`
|
2688 |
lucas.echa |
253 |
BL_SAFESEARCH=`grep ^BL_SAFESEARCH= $CONF_FILE|cut -d"=" -f2`
|
|
|
254 |
WL_SAFESEARCH=`grep ^WL_SAFESEARCH= $CONF_FILE|cut -d"=" -f2`
|
|
|
255 |
BL_PUREIP=`grep ^BL_PUREIP= $CONF_FILE|cut -d"=" -f2`
|
2474 |
tom.houday |
256 |
DHCP_mode=`grep ^DHCP= $CONF_FILE|cut -d"=" -f2`
|
1060 |
richard |
257 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
933 |
franck |
258 |
then
|
2688 |
lucas.echa |
259 |
if [ "$DHCP_mode" = "off" ] || [ "$DHCP_mode" = "Off" ] || [ "$DHCP_mode" = "OFF" ]
|
1060 |
richard |
260 |
then
|
1827 |
raphael.pi |
261 |
$DIR_BIN/alcasar-dhcp.sh --off
|
1890 |
franck |
262 |
else
|
2569 |
lucas.echa |
263 |
$DIR_BIN/alcasar-dhcp.sh --on
|
1060 |
richard |
264 |
fi
|
2568 |
rexy |
265 |
# Set the local DNS (or not)
|
2688 |
lucas.echa |
266 |
if [ "$INT_DNS_mode" = "on" ] || [ "$INT_DNS_mode" = "On" ] || [ "$INT_DNS_mode" = "ON" ]
|
1890 |
franck |
267 |
then
|
|
|
268 |
$DIR_BIN/alcasar-dns-local.sh --on
|
|
|
269 |
else
|
|
|
270 |
$DIR_BIN/alcasar-dns-local.sh --off
|
|
|
271 |
fi
|
2688 |
lucas.echa |
272 |
# Set the pure ip option (or not)
|
|
|
273 |
if [ "$BL_PUREIP" = "off" ] || [ "$BL_PUREIP" = "Off" ] || [ "$BL_PUREIP" = "OFF" ]
|
|
|
274 |
then
|
|
|
275 |
bl_filter_param+="--pureip_off"
|
|
|
276 |
else
|
|
|
277 |
bl_filter_param+="--pureip_on"
|
|
|
278 |
fi
|
|
|
279 |
# Set the safesearch options (or not)
|
|
|
280 |
bl_filter_param=""
|
|
|
281 |
if [ "$BL_SAFESEARCH" = "on" ] || [ "$BL_SAFESEARCH" = "On" ] || [ "$BL_SAFESEARCH" = "ON" ]
|
|
|
282 |
then
|
|
|
283 |
bl_filter_param+="--safesearch_on "
|
|
|
284 |
else
|
|
|
285 |
bl_filter_param+="--safesearch_off "
|
|
|
286 |
fi
|
|
|
287 |
$DIR_BIN/alcasar-url_filter_bl.sh $bl_filter_param
|
|
|
288 |
if [ "$WL_SAFESEARCH" = "on" ] || [ "$WL_SAFESEARCH" = "On" ] || [ "$WL_SAFESEARCH" = "ON" ]
|
|
|
289 |
then
|
|
|
290 |
$DIR_BIN/alcasar-url_filter_wl.sh --safesearch_on
|
|
|
291 |
else
|
|
|
292 |
$DIR_BIN/alcasar-url_filter_wl.sh --safesearch_off
|
|
|
293 |
fi
|
|
|
294 |
# Reload the local dns configuration
|
|
|
295 |
$DIR_BIN/alcasar-dns-local.sh --reload
|
1585 |
richard |
296 |
# Logout everybody
|
2688 |
lucas.echa |
297 |
$DIR_BIN/alcasar-logout.sh all
|
1585 |
richard |
298 |
# Services stop
|
1521 |
richard |
299 |
echo -n "Stop services : "
|
2840 |
rexy |
300 |
for i in ntpd e2guardian unbound unbound-whitelist dnsmasq-whitelist unbound-blacklist unbound-blackhole chilli network lighttpd
|
1060 |
richard |
301 |
do
|
1574 |
richard |
302 |
/usr/bin/systemctl stop $i && echo -n "$i, "
|
1060 |
richard |
303 |
done
|
1521 |
richard |
304 |
echo
|
1060 |
richard |
305 |
fi
|
1518 |
richard |
306 |
# EXTIF config
|
1585 |
richard |
307 |
if [ $PUBLIC_IP_MASK == "dhcp" ]
|
|
|
308 |
then
|
|
|
309 |
cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$EXTIF
|
|
|
310 |
DEVICE=$EXTIF
|
|
|
311 |
BOOTPROTO=dhcp
|
2870 |
rexy |
312 |
DNS1=127.0.0.1
|
1585 |
richard |
313 |
PEERDNS=no
|
|
|
314 |
RESOLV_MODS=yes
|
|
|
315 |
ONBOOT=yes
|
|
|
316 |
METRIC=10
|
|
|
317 |
MII_NOT_SUPPORTED=yes
|
|
|
318 |
IPV6INIT=no
|
|
|
319 |
IPV6TO4INIT=no
|
|
|
320 |
ACCOUNTING=no
|
|
|
321 |
USERCTL=no
|
|
|
322 |
MTU=$MTU
|
1850 |
franck |
323 |
NOZEROCONF=yes
|
1585 |
richard |
324 |
EOF
|
2688 |
lucas.echa |
325 |
else
|
1585 |
richard |
326 |
cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$EXTIF
|
|
|
327 |
DEVICE=$EXTIF
|
|
|
328 |
BOOTPROTO=static
|
|
|
329 |
IPADDR=$PUBLIC_IP
|
|
|
330 |
NETMASK=$PUBLIC_NETMASK
|
|
|
331 |
GATEWAY=$PUBLIC_GATEWAY
|
2870 |
rexy |
332 |
DNS1=127.0.0.1
|
1585 |
richard |
333 |
RESOLV_MODS=yes
|
|
|
334 |
ONBOOT=yes
|
|
|
335 |
METRIC=10
|
|
|
336 |
MII_NOT_SUPPORTED=yes
|
|
|
337 |
IPV6INIT=no
|
|
|
338 |
IPV6TO4INIT=no
|
|
|
339 |
ACCOUNTING=no
|
|
|
340 |
USERCTL=no
|
|
|
341 |
MTU=$MTU
|
1850 |
franck |
342 |
NOZEROCONF=yes
|
1585 |
richard |
343 |
EOF
|
|
|
344 |
fi
|
1518 |
richard |
345 |
# INTIF config (for bypass mode only)
|
1554 |
richard |
346 |
$SED "s?^IPADDR=.*?IPADDR=$PRIVATE_IP?" /etc/sysconfig/network-scripts/bypass-ifcfg-$INTIF
|
|
|
347 |
$SED "s?^NETMASK=.*?NETMASK=$PRIVATE_NETMASK?" /etc/sysconfig/network-scripts/bypass-ifcfg-$INTIF
|
628 |
richard |
348 |
# NTP server
|
632 |
richard |
349 |
$SED "/127.0.0.1/!s?^restrict.*?restrict $PRIVATE_NETWORK mask $PRIVATE_NETMASK nomodify notrap?g" /etc/ntp.conf
|
2688 |
lucas.echa |
350 |
# host.allow
|
628 |
richard |
351 |
cat <<EOF > /etc/hosts.allow
|
|
|
352 |
ALL: LOCAL, 127.0.0.1, localhost, $PRIVATE_IP
|
|
|
353 |
sshd: ALL
|
|
|
354 |
ntpd: $PRIVATE_NETWORK_SHORT
|
|
|
355 |
EOF
|
2309 |
tom.houday |
356 |
# Set hostname
|
|
|
357 |
hostnamectl set-hostname $HOSTNAME.$DOMAIN
|
2838 |
rexy |
358 |
# /etc/hosts (retriving local hostnames)
|
|
|
359 |
cp /etc/hosts /tmp/hosts
|
|
|
360 |
echo "127.0.0.1 localhost" > /etc/hosts
|
|
|
361 |
echo "$PRIVATE_IP $HOSTNAME $HOSTNAME.$DOMAIN" >> /etc/hosts
|
|
|
362 |
while read -r line
|
|
|
363 |
do
|
|
|
364 |
if ! echo $line | grep -E -q "^([0-9\.\t ]+alcasar( |$)|127\.0\.0)"
|
|
|
365 |
then
|
|
|
366 |
echo $line >> /etc/hosts
|
|
|
367 |
fi
|
|
|
368 |
done < /tmp/hosts
|
2861 |
rexy |
369 |
rm -f /tmp/hosts
|
2603 |
tom.houday |
370 |
# MOTD
|
|
|
371 |
$SED "s@'https://\(.\+\)/acc'@'https://$HOSTNAME.$DOMAIN/acc'@" /etc/mageia-release
|
2568 |
rexy |
372 |
# Lighttpd
|
2688 |
lucas.echa |
373 |
$SED "s?^server\.bind.*?server\.bind = \"$PRIVATE_IP\"?g" /etc/lighttpd/lighttpd.conf
|
|
|
374 |
$SED 's/^$SERVER\["socket"\] == ".*:443.*/$SERVER\["socket"\] == "'"$PRIVATE_IP"':443" {/g' /etc/lighttpd/vhosts.d/alcasar.conf
|
|
|
375 |
$SED "s/^\([\t ]*\)var.server_name.*/\1var.server_name = \"$PRIVATE_IP\"/g" /etc/lighttpd/vhosts.d/alcasar.conf
|
2744 |
rexy |
376 |
# FreeRADIUS
|
634 |
richard |
377 |
$SED "s?^nas1_name:.*?nas1_name: alcasar-$ORGANISME?g" /etc/freeradius-web/naslist.conf
|
|
|
378 |
$SED "s?^nas1_ip:.*?nas1_ip: $PRIVATE_IP?g" /etc/freeradius-web/naslist.conf
|
2707 |
tom.houday |
379 |
# CoovaChilli
|
2568 |
rexy |
380 |
$SED "s/^uamallowed.*/uamallowed\t$HOSTNAME,$HOSTNAME.$DOMAIN/g" /etc/chilli.conf
|
|
|
381 |
$SED "s/^locationname.*/locationname\t$HOSTNAME.$DOMAIN/g" /etc/chilli.conf
|
2707 |
tom.houday |
382 |
$SED "s/^domain.*/domain\t\t$DOMAIN/g" /etc/chilli.conf
|
2688 |
lucas.echa |
383 |
[ "`grep ^HTTPS_LOGIN= $CONF_FILE | cut -d'=' -f2`" == "on" ] && chilli_login_protocol="https" || chilli_login_protocol="http"
|
2568 |
rexy |
384 |
$SED "s/^uamserver.*/uamserver\t$chilli_login_protocol:\/\/$HOSTNAME.$DOMAIN\/intercept.php/" /etc/chilli.conf
|
|
|
385 |
$SED "s/^radiusnasid.*/radiusnasid\t$HOSTNAME.$DOMAIN/g" /etc/chilli.conf
|
634 |
richard |
386 |
$SED "s?^net.*?net\t\t$PRIVATE_NETWORK_MASK?g" /etc/chilli.conf
|
|
|
387 |
$SED "s?^dns1.*?dns1\t\t$PRIVATE_IP?g" /etc/chilli.conf
|
|
|
388 |
$SED "s?^dns2.*?dns2\t\t$PRIVATE_IP?g" /etc/chilli.conf
|
|
|
389 |
$SED "s?^uamlisten.*?uamlisten\t$PRIVATE_IP?g" /etc/chilli.conf
|
1581 |
richard |
390 |
# modify the DHCP static ip file. Reserve the second IP address for INTIF (the first one is for tun0). Keep previous entries
|
2274 |
richard |
391 |
$SED "s?^$PRIVATE_MAC.*?$PRIVATE_MAC $PRIVATE_SECOND_IP?" $DIR_ETC/alcasar-ethers $DIR_ETC/alcasar-ethers-info
|
2688 |
lucas.echa |
392 |
# dnsmasq-whitelist
|
|
|
393 |
$SED "/^server=/d" /etc/dnsmasq-whitelist.conf
|
|
|
394 |
echo "server=$DNS1" >> /etc/dnsmasq-whitelist.conf
|
|
|
395 |
echo "server=$DNS2" >> /etc/dnsmasq-whitelist.conf
|
|
|
396 |
# unbound
|
|
|
397 |
# removing unbound configuration files
|
|
|
398 |
rm -f /etc/unbound/conf.d/{forward,blacklist,whitelist,blackhole}/iface.*
|
|
|
399 |
rm -f /etc/unbound/conf.d/common/forward-zone.conf
|
|
|
400 |
# Configuration file for the dns servers forward-zone
|
|
|
401 |
cat << EOF > /etc/unbound/conf.d/common/forward-zone.conf
|
|
|
402 |
forward-zone:
|
|
|
403 |
name: "."
|
|
|
404 |
forward-addr: $DNS1
|
|
|
405 |
forward-addr: $DNS2
|
|
|
406 |
EOF
|
2813 |
rexy |
407 |
# Configuration file for lo of forward
|
2688 |
lucas.echa |
408 |
cat << EOF > /etc/unbound/conf.d/forward/iface.lo.conf
|
|
|
409 |
server:
|
|
|
410 |
interface: 127.0.0.1@53
|
|
|
411 |
access-control-view: 127.0.0.1/8 lo
|
|
|
412 |
view:
|
|
|
413 |
name: "lo"
|
2864 |
rexy |
414 |
local-data: "$HOSTNAME A 127.0.0.1"
|
2831 |
rexy |
415 |
local-data: "$HOSTNAME.$DOMAIN A 127.0.0.1"
|
2864 |
rexy |
416 |
local-data-ptr: "127.0.0.1 $HOSTNAME.$DOMAIN"
|
2688 |
lucas.echa |
417 |
view-first: yes
|
|
|
418 |
EOF
|
2813 |
rexy |
419 |
# Configuration file for $INTIF of forward
|
2688 |
lucas.echa |
420 |
cat << EOF > /etc/unbound/conf.d/forward/iface.${INTIF}.conf
|
|
|
421 |
server:
|
|
|
422 |
interface: ${PRIVATE_IP}@53
|
|
|
423 |
access-control-view: $PRIVATE_NETWORK_MASK $INTIF
|
|
|
424 |
view:
|
|
|
425 |
name: "$INTIF"
|
|
|
426 |
view-first: yes
|
|
|
427 |
EOF
|
2813 |
rexy |
428 |
# Configuration file for $INTIF of blacklist
|
2688 |
lucas.echa |
429 |
cat << EOF > /etc/unbound/conf.d/blacklist/iface.${INTIF}.conf
|
|
|
430 |
server:
|
|
|
431 |
interface: ${PRIVATE_IP}@54
|
|
|
432 |
access-control: $PRIVATE_IP_MASK allow
|
|
|
433 |
access-control-tag: $PRIVATE_IP_MASK "blacklist"
|
|
|
434 |
access-control-tag-action: $PRIVATE_IP_MASK "blacklist" redirect
|
|
|
435 |
access-control-tag-data: $PRIVATE_IP_MASK "blacklist" "A $PRIVATE_IP"
|
|
|
436 |
EOF
|
2813 |
rexy |
437 |
# Configuration file for $INTIF of whitelist
|
2688 |
lucas.echa |
438 |
cat << EOF > /etc/unbound/conf.d/whitelist/iface.${INTIF}.conf
|
|
|
439 |
server:
|
|
|
440 |
interface: ${PRIVATE_IP}@55
|
|
|
441 |
access-control: $PRIVATE_IP_MASK allow
|
|
|
442 |
access-control-tag: $PRIVATE_IP_MASK "whitelist"
|
|
|
443 |
access-control-tag-action: $PRIVATE_IP_MASK "whitelist" redirect
|
|
|
444 |
access-control-tag-data: $PRIVATE_IP_MASK "whitelist" "A $PRIVATE_IP"
|
|
|
445 |
EOF
|
2871 |
rexy |
446 |
# Configuration file for $INTIF of blackhole unbound
|
|
|
447 |
cat << EOF > /etc/unbound/conf.d/blackhole/iface.${INTIF}.conf
|
|
|
448 |
server:
|
|
|
449 |
interface: ${PRIVATE_IP}@56
|
|
|
450 |
access-control-view: $PRIVATE_NETWORK_MASK $INTIF
|
|
|
451 |
view:
|
|
|
452 |
name: "$INTIF"
|
|
|
453 |
local-zone: "." redirect
|
|
|
454 |
local-data: ". A $PRIVATE_IP"
|
|
|
455 |
EOF
|
|
|
456 |
|
2688 |
lucas.echa |
457 |
# dhcpd
|
|
|
458 |
cat <<EOF > /etc/dhcpd.conf
|
|
|
459 |
ddns-update-style none;
|
|
|
460 |
subnet $PRIVATE_NETWORK netmask $PRIVATE_NETMASK {
|
|
|
461 |
option routers $PRIVATE_IP;
|
|
|
462 |
option subnet-mask $PRIVATE_NETMASK;
|
|
|
463 |
option domain-name-servers $PRIVATE_IP;
|
|
|
464 |
range dynamic-bootp $PRIVATE_SECOND_IP $PRIVATE_LAST_IP;
|
|
|
465 |
default-lease-time 21600;
|
|
|
466 |
max-lease-time 43200;
|
|
|
467 |
}
|
|
|
468 |
EOF
|
2838 |
rexy |
469 |
$DIR_BIN/alcasar-dns-local.sh -hosts_to_unbound # add local name resolution to unbound (forward & blackhole)
|
2867 |
rexy |
470 |
# E2guardian
|
2521 |
armand.ito |
471 |
$SED "s?^filterip.*?filterip = $PRIVATE_IP?g" /etc/e2guardian/e2guardian.conf
|
2867 |
rexy |
472 |
$SED "s?\/\/[a-z.]*\/?\/\/$HOSTNAME.$DOMAIN\/?g" /usr/share/e2guardian/languages/french/alcasar-e2g.html
|
|
|
473 |
$SED "s?\/\/[a-z.]*\/?\/\/$HOSTNAME.$DOMAIN\/?g" /usr/share/e2guardian/languages/ukenglish/alcasar-e2g.html
|
634 |
richard |
474 |
# Watchdog
|
|
|
475 |
$SED "s?^PRIVATE_IP=.*?PRIVATE_IP=\"$PRIVATE_IP\"?g" $DIR_BIN/alcasar-watchdog.sh
|
|
|
476 |
# Prompts
|
|
|
477 |
$SED "s?^ORGANISME.*?ORGANISME=$ORGANISME?g" /etc/bashrc
|
|
|
478 |
# sudoers
|
|
|
479 |
$SED "s?^Host_Alias.*?Host_Alias LAN_ORG=$PRIVATE_NETWORK/$PRIVATE_NETMASK,localhost #réseau de l'organisme?g" /etc/sudoers
|
2878 |
rexy |
480 |
# gammu-smsd
|
|
|
481 |
$SED "s?^user =.*?user = $DB_USER?g" /etc/gammu_smsd_conf
|
|
|
482 |
$SED "s?^password =.*?password = $DB_PASS?g" /etc/gammu_smsd_conf
|
|
|
483 |
# Services start
|
1060 |
richard |
484 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
|
|
485 |
then
|
1574 |
richard |
486 |
/usr/bin/systemctl start network && echo -n "Start service : network" && sleep 1
|
2309 |
tom.houday |
487 |
$DIR_BIN/alcasar-dhcp.sh -$DHCP_mode && echo -n ", chilli" # apply DHCP mode and start CoovaChilli
|
2840 |
rexy |
488 |
for i in unbound unbound-blackhole ntpd
|
2309 |
tom.houday |
489 |
do
|
|
|
490 |
sleep 1
|
|
|
491 |
/usr/bin/systemctl start $i && echo -n ", $i"
|
|
|
492 |
done
|
2688 |
lucas.echa |
493 |
$DIR_BIN/alcasar-bl.sh -reload && echo -n ", unbound-blacklist, unbound-whitelist, dnsmasq-whitelist, e2guardian, iptables"
|
2488 |
lucas.echa |
494 |
/usr/bin/systemctl restart lighttpd && echo -n ", lighttpd"
|
1060 |
richard |
495 |
fi
|
628 |
richard |
496 |
# Start / Stop SSH Daemon
|
2474 |
tom.houday |
497 |
ssh_active=`grep ^SSH= $CONF_FILE|cut -d"=" -f2`
|
634 |
richard |
498 |
if [ $ssh_active = "on" ]
|
|
|
499 |
then
|
1574 |
richard |
500 |
/usr/bin/systemctl enable sshd.service
|
1060 |
richard |
501 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
|
|
502 |
then
|
1574 |
richard |
503 |
/usr/bin/systemctl start sshd.service
|
1060 |
richard |
504 |
fi
|
634 |
richard |
505 |
else
|
1574 |
richard |
506 |
/usr/bin/systemctl disable sshd.service
|
1060 |
richard |
507 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
|
|
508 |
then
|
1574 |
richard |
509 |
/usr/bin/systemctl stop sshd.service
|
1060 |
richard |
510 |
fi
|
634 |
richard |
511 |
fi
|
2568 |
rexy |
512 |
# Start / Stop LDAP authentification
|
2875 |
rexy |
513 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
2568 |
rexy |
514 |
then
|
2875 |
rexy |
515 |
LDAP_mode=`grep ^LDAP= $CONF_FILE|cut -d"=" -f2`
|
|
|
516 |
if [ $LDAP_mode = "on" ]
|
|
|
517 |
then
|
|
|
518 |
$DIR_BIN/alcasar-ldap.sh --on
|
|
|
519 |
else
|
|
|
520 |
$DIR_BIN/alcasar-ldap.sh --off
|
|
|
521 |
fi
|
2568 |
rexy |
522 |
fi
|
2875 |
rexy |
523 |
# Start / Stop Gammu-smsd (SMS)
|
|
|
524 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
|
|
525 |
then
|
|
|
526 |
SMS_mode=`grep ^SMS= $CONF_FILE|cut -d"=" -f2`
|
|
|
527 |
if [ $SMS_mode = "on" ]
|
|
|
528 |
then
|
|
|
529 |
$DIR_BIN/alcasar-sms.sh --start
|
|
|
530 |
fi
|
|
|
531 |
fi
|
2568 |
rexy |
532 |
echo
|
628 |
richard |
533 |
;;
|
8 |
franck |
534 |
*)
|
2688 |
lucas.echa |
535 |
echo "Argument inconnu : $1";
|
8 |
franck |
536 |
echo "$usage"
|
|
|
537 |
exit 1
|
|
|
538 |
;;
|
|
|
539 |
esac
|