2223 |
tom.houday |
1 |
#!/bin/bash
|
64 |
franck |
2 |
# $Id: alcasar-conf.sh 2430 2017-10-18 22:24:25Z tom.houdayer $
|
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
|
1758 |
richard |
9 |
# - création de l'archive des fichiers de configuration dans "/tmp/alcasar-conf.tar.gz" (alcasar-conf.sh -create)
|
2327 |
richard |
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
|
1758 |
richard |
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)
|
672 |
richard |
12 |
# This script allows ALCASAR update
|
1758 |
richard |
13 |
# - create the configuration files backup "/tmp/alcasar-conf.tar.gz" (alcasar-conf.sh -create)
|
2327 |
richard |
14 |
# - load the backup of configuration files during the update process (alcasar-conf -load). If needed, it's here we update files between versions
|
1758 |
richard |
15 |
# - apply ALCASAR central configuration file "/usr/local/etc/alcasar.conf" when hot modification is needed (alcasar-conf -apply)
|
672 |
richard |
16 |
|
2247 |
tom.houday |
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
|
|
|
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
|
|
|
21 |
DIR_BIN="/usr/local/bin" # scripts directory
|
|
|
22 |
DIR_ETC="/usr/local/etc" # conf directory
|
|
|
23 |
DIR_SHARE="/usr/local/share" # data directory
|
1969 |
richard |
24 |
DIR_BLACKLIST="/etc/dansguardian/lists/blacklists" # Toulouse BL directory
|
2247 |
tom.houday |
25 |
CONF_FILE="$DIR_ETC/alcasar.conf" # main alcasar conf file
|
|
|
26 |
EXTIF=`grep ^EXTIF= $CONF_FILE|cut -d"=" -f2` # EXTernal InterFace
|
|
|
27 |
INTIF=`grep ^INTIF= $CONF_FILE|cut -d"=" -f2` # INTernal InterFace
|
|
|
28 |
MTU=`grep ^PUBLIC_MTU= $CONF_FILE|cut -d"=" -f2`
|
1890 |
franck |
29 |
DHCP_mode=`grep ^DHCP= $CONF_FILE|cut -d"=" -f2`
|
|
|
30 |
INT_DNS_mode=`grep ^INT_DNS_ACTIVE= $CONF_FILE|cut -d"=" -f2`
|
|
|
31 |
LDAP_mode=`grep ^LDAP= $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`
|
2412 |
tom.houday |
34 |
PASSWD_FILE="/root/ALCASAR-passwords.txt"
|
|
|
35 |
DB_USER=$(grep '^db_user=' $PASSWD_FILE | cut -d'=' -f 2-)
|
|
|
36 |
DB_PASS=$(grep '^db_password=' $PASSWD_FILE | cut -d'=' -f 2-)
|
384 |
richard |
37 |
SED="/bin/sed -i"
|
2247 |
tom.houday |
38 |
RUNNING_VERSION=`grep ^VERSION= $CONF_FILE|cut -d'=' -f2`
|
510 |
richard |
39 |
MAJ_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f1`
|
|
|
40 |
MIN_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f2|cut -c1`
|
|
|
41 |
UPD_RUNNING_VERSION=`echo $RUNNING_VERSION|cut -d"." -f3`
|
1969 |
richard |
42 |
DNS1=`grep "DNS1" $CONF_FILE | cut -d '=' -f 2` # server DNS1 (for WL domain names)
|
923 |
franck |
43 |
DOMAIN=${DOMAIN:=localdomain}
|
628 |
richard |
44 |
DATE=`date '+%d %B %Y - %Hh%M'`
|
2247 |
tom.houday |
45 |
|
628 |
richard |
46 |
private_network_calc ()
|
|
|
47 |
{
|
1060 |
richard |
48 |
PRIVATE_PREFIX=`/bin/ipcalc -p $PRIVATE_IP $PRIVATE_NETMASK |cut -d"=" -f2` # prefixe du réseau (ex. 24)
|
|
|
49 |
PRIVATE_NETWORK=`/bin/ipcalc -n $PRIVATE_IP $PRIVATE_NETMASK| cut -d"=" -f2` # @ réseau de consultation (ex.: 192.168.182.0)
|
|
|
50 |
PRIVATE_NETWORK_MASK=$PRIVATE_NETWORK/$PRIVATE_PREFIX # @ + masque du réseau de consult (192.168.182.0/24)
|
628 |
richard |
51 |
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 |
52 |
PRIVATE_NETWORK_SHORT=`echo $PRIVATE_NETWORK | cut -d"." -f1-$classe`. # @ compatible hosts.allow et hosts.deny (ex.: 192.168.182.)
|
|
|
53 |
PRIVATE_BROADCAST=`/bin/ipcalc -b $PRIVATE_NETWORK_MASK | cut -d"=" -f2` # private network broadcast (ie.: 192.168.182.255)
|
|
|
54 |
private_network_ending=`echo $PRIVATE_NETWORK | cut -d"." -f$classe_sup` # last octet of LAN address
|
|
|
55 |
private_broadcast_ending=`echo $PRIVATE_BROADCAST | cut -d"." -f$classe_sup` # last octet of LAN broadcast
|
2324 |
tom.houday |
56 |
private_ip_ending=`echo $PRIVATE_IP | cut -d"." -f4` # last octet of LAN address
|
2117 |
franck |
57 |
PRIVATE_FIRST_IP=$PRIVATE_IP # First network address (ex.: 192.168.182.1)
|
|
|
58 |
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 |
59 |
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 |
60 |
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 |
61 |
}
|
8 |
franck |
62 |
|
933 |
franck |
63 |
usage="Usage: alcasar-conf.sh {--create or -create} | {--load or -load} | {--apply or -apply}"
|
8 |
franck |
64 |
nb_args=$#
|
|
|
65 |
args=$1
|
|
|
66 |
if [ $nb_args -eq 0 ]
|
|
|
67 |
then
|
2430 |
tom.houday |
68 |
nb_args=1
|
8 |
franck |
69 |
args="-h"
|
|
|
70 |
fi
|
|
|
71 |
case $args in
|
|
|
72 |
-\? | -h* | --h*)
|
|
|
73 |
echo "$usage"
|
|
|
74 |
exit 0
|
|
|
75 |
;;
|
389 |
franck |
76 |
--create|-create)
|
8 |
franck |
77 |
[ -d $DIR_UPDATE ] && rm -rf $DIR_UPDATE
|
|
|
78 |
mkdir $DIR_UPDATE
|
1916 |
franck |
79 |
# backup the users database (test to delete in future version)
|
1918 |
franck |
80 |
if [ -e $DIR_BIN/alcasar-mysql.sh ]; then
|
|
|
81 |
$DIR_BIN/alcasar-mysql.sh --dump
|
1916 |
franck |
82 |
else
|
|
|
83 |
/usr/local/sbin/alcasar-mysql.sh --dump
|
|
|
84 |
fi
|
1777 |
richard |
85 |
cp /var/Save/base/`ls -1t /var/Save/base|head -1` $DIR_UPDATE
|
1758 |
richard |
86 |
# backup the logo
|
8 |
franck |
87 |
cp -f $DIR_WEB/images/organisme.png $DIR_UPDATE
|
1912 |
richard |
88 |
# backup BL/WL custom files
|
1914 |
richard |
89 |
mkdir $DIR_UPDATE/custom_bl
|
|
|
90 |
cp -f /etc/dansguardian/lists/exceptioniplist $DIR_UPDATE/custom_bl/
|
|
|
91 |
cp -f /etc/dansguardian/lists/urlregexplist $DIR_UPDATE/custom_bl/
|
|
|
92 |
cp -f /etc/dansguardian/lists/exceptionsitelist $DIR_UPDATE/custom_bl/
|
|
|
93 |
cp -f /etc/dansguardian/lists/bannedsitelist $DIR_UPDATE/custom_bl/
|
|
|
94 |
cp -f /etc/dansguardian/lists/exceptionurllist $DIR_UPDATE/custom_bl/
|
|
|
95 |
cp -f /etc/dansguardian/lists/bannedurllist $DIR_UPDATE/custom_bl/
|
1961 |
richard |
96 |
cp -rf $DIR_BLACKLIST/ossi-* $DIR_UPDATE/custom_bl/ 2>/dev/null
|
1758 |
richard |
97 |
# backup of different conf files (main conf file, filtering, digest, etc)
|
8 |
franck |
98 |
mkdir $DIR_UPDATE/etc/
|
2275 |
richard |
99 |
[ -e $DIR_ETC/alcasar-ethers-info ] || cp $DIR_ETC/alcasar-ethers $DIR_ETC/alcasar-ethers-info # V3.1.2 new info file for dhcp static
|
346 |
richard |
100 |
cp -rf $DIR_ETC/* $DIR_UPDATE/etc/
|
1758 |
richard |
101 |
# backup of the security certificates (server & CA)
|
|
|
102 |
cp -f /etc/pki/tls/certs/alcasar.crt* $DIR_UPDATE # autosigned and official if exist
|
|
|
103 |
cp -f /etc/pki/tls/private/alcasar.key* $DIR_UPDATE # autosigned & official if exist
|
1564 |
richard |
104 |
cp -f /etc/pki/CA/alcasar-ca.crt $DIR_UPDATE
|
|
|
105 |
cp -f /etc/pki/CA/private/alcasar-ca.key $DIR_UPDATE
|
|
|
106 |
if [ -e /etc/pki/tls/certs/server-chain.crt ]; then
|
2244 |
tom.houday |
107 |
cp -f /etc/pki/tls/certs/server-chain.crt* $DIR_UPDATE # autosigned and official if exist
|
510 |
richard |
108 |
else
|
1564 |
richard |
109 |
cp -f /etc/pki/tls/certs/alcasar.crt $DIR_UPDATE/server-chain.crt
|
510 |
richard |
110 |
fi
|
1758 |
richard |
111 |
# backup DNSMASQ conf file
|
933 |
franck |
112 |
cp /etc/sysconfig/dnsmasq $DIR_UPDATE
|
1758 |
richard |
113 |
# archive file creation
|
8 |
franck |
114 |
cd /tmp
|
|
|
115 |
tar -cf alcasar-conf.tar conf/
|
|
|
116 |
gzip -f alcasar-conf.tar
|
|
|
117 |
rm -rf $DIR_UPDATE
|
|
|
118 |
;;
|
389 |
franck |
119 |
--load|-load)
|
8 |
franck |
120 |
cd /tmp
|
1057 |
richard |
121 |
tar -xf /tmp/alcasar-conf*.tar.gz
|
1060 |
richard |
122 |
# Retrieve the logo
|
510 |
richard |
123 |
[ -e $DIR_UPDATE/organisme.png ] && cp -f $DIR_UPDATE/organisme.png $DIR_WEB/images/
|
8 |
franck |
124 |
chown apache:apache $DIR_WEB/images/organisme.png $DIR_WEB/intercept.php
|
1060 |
richard |
125 |
# Retrieve the security certificates (CA and server)
|
1758 |
richard |
126 |
cp -f $DIR_UPDATE/alcasar-ca.crt* /etc/pki/CA/ # autosigned & official
|
|
|
127 |
cp -f $DIR_UPDATE/alcasar-ca.key* /etc/pki/CA/private/ # autosigned & official
|
|
|
128 |
cp -f $DIR_UPDATE/alcasar.crt /etc/pki/tls/certs/
|
|
|
129 |
cp -f $DIR_UPDATE/alcasar.key /etc/pki/tls/private/
|
2244 |
tom.houday |
130 |
[ -e $DIR_UPDATE/server-chain.crt ] && cp -f $DIR_UPDATE/server-chain.crt* /etc/pki/tls/certs/ # autosigned and official if exist
|
8 |
franck |
131 |
chown -R root:apache /etc/pki
|
|
|
132 |
chmod -R 750 /etc/pki
|
1060 |
richard |
133 |
# Import of the users database
|
2412 |
tom.houday |
134 |
gzip -dc < `ls $DIR_UPDATE/alcasar-users-database*` | mysql -u$DB_USER -p$DB_PASS
|
1914 |
richard |
135 |
# Retrieve local parameters
|
1760 |
richard |
136 |
[ -d $DIR_UPDATE/etc ] && cp -rf $DIR_UPDATE/etc/* $DIR_ETC/
|
1914 |
richard |
137 |
# Retrieve BL/WL custom files
|
|
|
138 |
cp -f $DIR_UPDATE/custom_bl/exceptioniplist /etc/dansguardian/lists/
|
|
|
139 |
cp -f $DIR_UPDATE/custom_bl/exceptionsitelist /etc/dansguardian/lists/
|
|
|
140 |
cp -f $DIR_UPDATE/custom_bl/urlregexplist /etc/dansguardian/lists/
|
|
|
141 |
cp -f $DIR_UPDATE/custom_bl/bannedsitelist /etc/dansguardian/lists/
|
|
|
142 |
cp -f $DIR_UPDATE/custom_bl/exceptionurllist /etc/dansguardian/lists/
|
|
|
143 |
cp -f $DIR_UPDATE/custom_bl/bannedurllist /etc/dansguardian/lists/
|
1961 |
richard |
144 |
cp -rf $DIR_UPDATE/custom_bl/ossi-* $DIR_BLACKLIST/ 2>/dev/null
|
8 |
franck |
145 |
chown -R dansguardian:apache /etc/dansguardian/lists
|
|
|
146 |
chmod -R g+rw /etc/dansguardian/lists
|
1060 |
richard |
147 |
# Adapt DNS/URL filtering
|
|
|
148 |
PARENT_SCRIPT=`basename $0`
|
637 |
richard |
149 |
export PARENT_SCRIPT
|
1946 |
richard |
150 |
$DIR_BIN/alcasar-bl.sh -cat_choice
|
1827 |
raphael.pi |
151 |
$DIR_BIN/alcasar-bl.sh -reload
|
1060 |
richard |
152 |
# retrieve dnsmasq general config file
|
|
|
153 |
[ -e $DIR_UPDATE/dnsmasq ] && cp -f $DIR_UPDATE/dnsmasq /etc/sysconfig/dnsmasq \
|
|
|
154 |
&& chown root.root /etc/sysconfig/dnsmasq \
|
|
|
155 |
&& chmod 644 /etc/sysconfig/dnsmasq
|
|
|
156 |
# admin profile update (admin + manager + backup)
|
1827 |
raphael.pi |
157 |
$DIR_BIN/alcasar-profil.sh --list
|
634 |
richard |
158 |
# Start / Stop SSH Daemon
|
2327 |
richard |
159 |
ssh_active=`grep "^SSH=" $CONF_FILE|cut -d"=" -f2`
|
634 |
richard |
160 |
if [ $ssh_active = "on" ]
|
|
|
161 |
then
|
1574 |
richard |
162 |
/usr/bin/systemctl -q enable sshd.service
|
634 |
richard |
163 |
else
|
1574 |
richard |
164 |
/usr/bin/systemctl -q disable sshd.service
|
634 |
richard |
165 |
fi
|
1060 |
richard |
166 |
# Remove the update folder
|
8 |
franck |
167 |
rm -rf $DIR_UPDATE
|
2327 |
richard |
168 |
# If needed : write modifications between version
|
|
|
169 |
# V3.1.3
|
|
|
170 |
# add "HTTPS_LOGIN=on" in conf file
|
|
|
171 |
HTTPS_LOGIN=`grep -c "^HTTPS_LOGIN=" $CONF_FILE`
|
2332 |
tom.houday |
172 |
if [ $HTTPS_LOGIN == "0" ]
|
2327 |
richard |
173 |
then
|
|
|
174 |
echo "HTTPS_LOGIN=on" >> $CONF_FILE
|
|
|
175 |
fi
|
2409 |
tom.houday |
176 |
# V3.2.0
|
|
|
177 |
# add "HTTPS_CHILLI=off" in conf file
|
|
|
178 |
if [ $(grep -c "^HTTPS_CHILLI=" $CONF_FILE) == "0" ]; then
|
|
|
179 |
echo "HTTPS_CHILLI=off" >> $CONF_FILE
|
|
|
180 |
fi
|
8 |
franck |
181 |
;;
|
628 |
richard |
182 |
--apply|-apply)
|
994 |
franck |
183 |
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 |
184 |
PRIVATE_IP_MASK=`grep ^PRIVATE_IP $CONF_FILE|cut -d"=" -f2`
|
628 |
richard |
185 |
check=$(echo $PRIVATE_IP_MASK | egrep $PTN)
|
|
|
186 |
if [[ "$?" -ne 0 ]]
|
|
|
187 |
then
|
|
|
188 |
echo "Syntax error for PRIVATE_IP_MASK ($PRIVATE_IP_MASK)"
|
|
|
189 |
exit 0
|
|
|
190 |
fi
|
1054 |
franck |
191 |
PUBLIC_IP_MASK=`grep ^PUBLIC_IP $CONF_FILE|cut -d"=" -f2`
|
1590 |
richard |
192 |
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 |
193 |
if [[ "$PUBLIC_IP_MASK" == "dhcp" ]]
|
|
|
194 |
then
|
|
|
195 |
PUBLIC_GATEWAY="dhcp"
|
1590 |
richard |
196 |
|
1585 |
richard |
197 |
else
|
|
|
198 |
check=$(echo $PUBLIC_IP_MASK | egrep $PTN)
|
|
|
199 |
if [[ "$?" -ne 0 ]]
|
628 |
richard |
200 |
then
|
1585 |
richard |
201 |
echo "Syntax error for PUBLIC_IP_MASK ($PUBLIC_IP_MASK)"
|
|
|
202 |
exit 0
|
|
|
203 |
fi
|
1590 |
richard |
204 |
PUBLIC_IP=`echo $PUBLIC_IP_MASK | cut -d"/" -f1`
|
|
|
205 |
PUBLIC_NETMASK=`/bin/ipcalc -m $PUBLIC_IP_MASK | cut -d"=" -f2`
|
1585 |
richard |
206 |
PUBLIC_GATEWAY=`grep ^GW $CONF_FILE|cut -d"=" -f2`
|
|
|
207 |
check=$(echo $PUBLIC_GATEWAY | egrep $PTN)
|
|
|
208 |
if [[ "$?" -ne 0 ]]
|
|
|
209 |
then
|
|
|
210 |
echo "Syntax error for the Gateway IP ($PUBLIC_GATEWAY)"
|
|
|
211 |
exit 0
|
|
|
212 |
fi
|
628 |
richard |
213 |
fi
|
1590 |
richard |
214 |
DNS1=`grep ^DNS1 $CONF_FILE|cut -d"=" -f2`
|
|
|
215 |
check=$(echo $DNS1 | egrep $PTN)
|
|
|
216 |
if [[ "$?" -ne 0 ]]
|
|
|
217 |
then
|
|
|
218 |
echo "Syntax error for the IP address of the first DNS server ($DNS1)"
|
|
|
219 |
exit 0
|
|
|
220 |
fi
|
|
|
221 |
DNS2=`grep ^DNS2 $CONF_FILE|cut -d"=" -f2`
|
|
|
222 |
check=$(echo $DNS2 | egrep $PTN)
|
|
|
223 |
if [[ "$?" -ne 0 ]]
|
|
|
224 |
then
|
|
|
225 |
echo "Syntax error for the IP address of the second DNS server ($DNS2)"
|
|
|
226 |
exit 0
|
|
|
227 |
fi
|
631 |
richard |
228 |
PRIVATE_IP=`echo $PRIVATE_IP_MASK | cut -d"/" -f1`
|
632 |
richard |
229 |
PRIVATE_NETMASK=`/bin/ipcalc -m $PRIVATE_IP_MASK | cut -d"=" -f2`
|
628 |
richard |
230 |
private_network_calc
|
632 |
richard |
231 |
INSTALL_DATE=`grep INSTALL_DATE $CONF_FILE|cut -d"=" -f2`
|
|
|
232 |
ORGANISME=`grep ORGANISM $CONF_FILE|cut -d"=" -f2`
|
862 |
richard |
233 |
DHCP_mode=`grep DHCP= $CONF_FILE|cut -d"=" -f2`
|
1060 |
richard |
234 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
933 |
franck |
235 |
then
|
1890 |
franck |
236 |
if [ $DHCP_mode = "off" ] || [ $DHCP_mode = "Off" ] || [ $DHCP_mode = "OFF" ]
|
1060 |
richard |
237 |
then
|
1827 |
raphael.pi |
238 |
$DIR_BIN/alcasar-dhcp.sh --off
|
1890 |
franck |
239 |
else
|
|
|
240 |
$DIR_BIN/alcasar-dhcp.sh --on
|
1060 |
richard |
241 |
fi
|
1806 |
franck |
242 |
|
|
|
243 |
# Implementation of the local DNS
|
1890 |
franck |
244 |
if [ $INT_DNS_mode = "on" ] || [ $INT_DNS_mode = "On" ] || [ $INT_DNS_mode = "ON" ]
|
|
|
245 |
then
|
|
|
246 |
$DIR_BIN/alcasar-dns-local.sh --on
|
|
|
247 |
else
|
|
|
248 |
$DIR_BIN/alcasar-dns-local.sh --off
|
|
|
249 |
fi
|
1806 |
franck |
250 |
|
1694 |
franck |
251 |
# Implementation of the authentification LDAP
|
1890 |
franck |
252 |
# if [ LDAP_mode = "on" ] || [ $LDAP_mode = "On" ] || [ $LDAP_mode = "ON" ]
|
|
|
253 |
# then
|
|
|
254 |
# $DIR_BIN/alcasar-ldap.sh
|
|
|
255 |
# fi
|
1611 |
franck |
256 |
|
1585 |
richard |
257 |
# Logout everybody
|
1827 |
raphael.pi |
258 |
$DIR_BIN/alcasar-logout.sh all
|
1585 |
richard |
259 |
# Services stop
|
1521 |
richard |
260 |
echo -n "Stop services : "
|
1850 |
franck |
261 |
for i in ntpd tinyproxy dnsmasq dnsmasq-whitelist dnsmasq-blacklist dnsmasq-blackhole chilli network
|
1060 |
richard |
262 |
do
|
1574 |
richard |
263 |
/usr/bin/systemctl stop $i && echo -n "$i, "
|
1060 |
richard |
264 |
done
|
1827 |
raphael.pi |
265 |
/usr/bin/kill -s SIGSTOP $(pidof httpd)
|
1521 |
richard |
266 |
echo
|
1060 |
richard |
267 |
fi
|
1518 |
richard |
268 |
# EXTIF config
|
1585 |
richard |
269 |
if [ $PUBLIC_IP_MASK == "dhcp" ]
|
|
|
270 |
then
|
|
|
271 |
cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$EXTIF
|
|
|
272 |
DEVICE=$EXTIF
|
|
|
273 |
BOOTPROTO=dhcp
|
|
|
274 |
DNS1=127.0.0.1
|
|
|
275 |
PEERDNS=no
|
|
|
276 |
RESOLV_MODS=yes
|
|
|
277 |
ONBOOT=yes
|
|
|
278 |
METRIC=10
|
|
|
279 |
MII_NOT_SUPPORTED=yes
|
|
|
280 |
IPV6INIT=no
|
|
|
281 |
IPV6TO4INIT=no
|
|
|
282 |
ACCOUNTING=no
|
|
|
283 |
USERCTL=no
|
|
|
284 |
MTU=$MTU
|
1850 |
franck |
285 |
NOZEROCONF=yes
|
1585 |
richard |
286 |
EOF
|
|
|
287 |
else
|
|
|
288 |
cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-$EXTIF
|
|
|
289 |
DEVICE=$EXTIF
|
|
|
290 |
BOOTPROTO=static
|
|
|
291 |
IPADDR=$PUBLIC_IP
|
|
|
292 |
NETMASK=$PUBLIC_NETMASK
|
|
|
293 |
GATEWAY=$PUBLIC_GATEWAY
|
|
|
294 |
DNS1=127.0.0.1
|
|
|
295 |
RESOLV_MODS=yes
|
|
|
296 |
ONBOOT=yes
|
|
|
297 |
METRIC=10
|
|
|
298 |
MII_NOT_SUPPORTED=yes
|
|
|
299 |
IPV6INIT=no
|
|
|
300 |
IPV6TO4INIT=no
|
|
|
301 |
ACCOUNTING=no
|
|
|
302 |
USERCTL=no
|
|
|
303 |
MTU=$MTU
|
1850 |
franck |
304 |
NOZEROCONF=yes
|
1585 |
richard |
305 |
EOF
|
|
|
306 |
fi
|
1518 |
richard |
307 |
# INTIF config (for bypass mode only)
|
1554 |
richard |
308 |
$SED "s?^IPADDR=.*?IPADDR=$PRIVATE_IP?" /etc/sysconfig/network-scripts/bypass-ifcfg-$INTIF
|
|
|
309 |
$SED "s?^NETMASK=.*?NETMASK=$PRIVATE_NETMASK?" /etc/sysconfig/network-scripts/bypass-ifcfg-$INTIF
|
628 |
richard |
310 |
# NTP server
|
632 |
richard |
311 |
$SED "/127.0.0.1/!s?^restrict.*?restrict $PRIVATE_NETWORK mask $PRIVATE_NETMASK nomodify notrap?g" /etc/ntp.conf
|
628 |
richard |
312 |
# host.allow
|
|
|
313 |
cat <<EOF > /etc/hosts.allow
|
|
|
314 |
ALL: LOCAL, 127.0.0.1, localhost, $PRIVATE_IP
|
|
|
315 |
sshd: ALL
|
|
|
316 |
ntpd: $PRIVATE_NETWORK_SHORT
|
|
|
317 |
EOF
|
2309 |
tom.houday |
318 |
# Set hostname
|
|
|
319 |
hostnamectl set-hostname $HOSTNAME.$DOMAIN
|
|
|
320 |
# /etc/hosts
|
|
|
321 |
domainNames="alcasar.localdomain $HOSTNAME $HOSTNAME.$DOMAIN"
|
|
|
322 |
if [ "$HOSTNAME" != "alcasar" ]; then domainNames="alcasar $domainNames"; fi
|
|
|
323 |
cat <<EOF > /etc/hosts
|
|
|
324 |
127.0.0.1 localhost
|
|
|
325 |
$PRIVATE_IP $domainNames
|
|
|
326 |
EOF
|
|
|
327 |
# Set hostname in CoovaChilli
|
|
|
328 |
$SED "s/^uamallowed.*/uamallowed\t${domainNames// /,}/g" /etc/chilli.conf
|
|
|
329 |
$SED "s/^locationname.*/locationname\t$HOSTNAME.$DOMAIN/g" /etc/chilli.conf
|
2324 |
tom.houday |
330 |
[ `grep ^HTTPS_LOGIN= $CONF_FILE | cut -d'=' -f2` == "on" ] && chilli_login_protocol="https" || chilli_login_protocol="http"
|
|
|
331 |
$SED "s/^uamserver.*/uamserver\t$chilli_login_protocol:\/\/$HOSTNAME.$DOMAIN\/intercept.php/" /etc/chilli.conf
|
2309 |
tom.houday |
332 |
$SED "s/^radiusnasid.*/radiusnasid\t$HOSTNAME.$DOMAIN/g" /etc/chilli.conf
|
|
|
333 |
# Set hostname in Apache
|
|
|
334 |
$SED "s/^ServerName.*/ServerName $HOSTNAME.$DOMAIN/g" /etc/httpd/conf/httpd.conf
|
|
|
335 |
$SED "s/^\tErrorDocument.*/\tErrorDocument 404 https:\/\/$HOSTNAME.$DOMAIN\//g" /etc/httpd/conf/webapps.d/alcasar.conf
|
|
|
336 |
$SED "s/^\tAuthDigestDomain.*/\tAuthDigestDomain $HOSTNAME.$DOMAIN/g" /etc/httpd/conf/webapps.d/alcasar.conf
|
|
|
337 |
$SED "s/^ ServerName.*/ ServerName $HOSTNAME.$DOMAIN/g" /etc/httpd/conf/sites.d/00_default_vhosts.conf /etc/httpd/conf/sites.d/00_default_ssl_vhost.conf /etc/httpd/conf/vhosts-ssl.default
|
|
|
338 |
# Alcasar Control Center (ACC)
|
634 |
richard |
339 |
$SED "s?^Listen.*?Listen $PRIVATE_IP:80?g" /etc/httpd/conf/httpd.conf
|
1419 |
richard |
340 |
FIC_MOD_SSL=`find /etc/httpd/conf/ -type f -name ssl.conf`
|
634 |
richard |
341 |
$SED "s?^Listen.*?Listen $PRIVATE_IP:443?g" $FIC_MOD_SSL
|
|
|
342 |
$SED "/127.0.0.1/!s?Allow from .*?Allow from $PRIVATE_NETWORK_MASK?g" /etc/httpd/conf/webapps.d/alcasar.conf
|
2309 |
tom.houday |
343 |
# FreeRADIUS Web
|
634 |
richard |
344 |
$SED "s?^nas1_name:.*?nas1_name: alcasar-$ORGANISME?g" /etc/freeradius-web/naslist.conf
|
|
|
345 |
$SED "s?^nas1_ip:.*?nas1_ip: $PRIVATE_IP?g" /etc/freeradius-web/naslist.conf
|
632 |
richard |
346 |
# coova
|
634 |
richard |
347 |
$SED "s?^net.*?net\t\t$PRIVATE_NETWORK_MASK?g" /etc/chilli.conf
|
|
|
348 |
$SED "s?^dns1.*?dns1\t\t$PRIVATE_IP?g" /etc/chilli.conf
|
|
|
349 |
$SED "s?^dns2.*?dns2\t\t$PRIVATE_IP?g" /etc/chilli.conf
|
|
|
350 |
$SED "s?^uamlisten.*?uamlisten\t$PRIVATE_IP?g" /etc/chilli.conf
|
1581 |
richard |
351 |
# modify the DHCP static ip file. Reserve the second IP address for INTIF (the first one is for tun0). Keep previous entries
|
2274 |
richard |
352 |
$SED "s?^$PRIVATE_MAC.*?$PRIVATE_MAC $PRIVATE_SECOND_IP?" $DIR_ETC/alcasar-ethers $DIR_ETC/alcasar-ethers-info
|
632 |
richard |
353 |
# dnsmasq
|
1795 |
franck |
354 |
$SED "/127.0.0.1/!s?^listen-address=.*?listen-address=$PRIVATE_IP?g" /etc/dnsmasq.conf /etc/dnsmasq-blacklist.conf /etc/dnsmasq-whitelist.conf /etc/dnsmasq-blackhole.conf
|
1377 |
richard |
355 |
for i in /etc/dnsmasq.conf /etc/dnsmasq-blacklist.conf
|
673 |
richard |
356 |
do
|
|
|
357 |
$SED "/^server=/d" $i
|
|
|
358 |
echo "server=$DNS1" >> $i
|
|
|
359 |
echo "server=$DNS2" >> $i
|
|
|
360 |
done
|
1969 |
richard |
361 |
$SED "s?^address=.*?address=/#/$PRIVATE_IP?g" /etc/dnsmasq-blackhole.conf
|
|
|
362 |
for i in `ls $DIR_SHARE/dnsmasq-wl`
|
|
|
363 |
do
|
|
|
364 |
cat $DIR_SHARE/dnsmasq-wl/$i|cut -d"/" -f1,2 > /tmp/tmp_file
|
|
|
365 |
$SED "s/$/\/$DNS1/" /tmp/tmp_file
|
|
|
366 |
mv -f /tmp/tmp_file $DIR_SHARE/dnsmasq-wl/$i
|
|
|
367 |
done
|
|
|
368 |
chown root:apache $DIR_SHARE/dnsmasq-wl/*
|
|
|
369 |
chmod 660 $DIR_SHARE/dnsmasq-wl/*
|
|
|
370 |
$SED "s?^dhcp-option=option:router.*?dhcp-option=option:router,$PRIVATE_IP?g" /etc/dnsmasq.conf
|
1060 |
richard |
371 |
$SED "s?^dhcp-range=.*?dhcp-range=$PRIVATE_SECOND_IP,$PRIVATE_LAST_IP,$PRIVATE_NETMASK,12h?g" /etc/dnsmasq.conf
|
1518 |
richard |
372 |
# tinyproxy
|
|
|
373 |
$SED "s?^Listen.*?Listen $PRIVATE_IP?g" /etc/tinyproxy/tinyproxy.conf
|
634 |
richard |
374 |
# DG + BL
|
|
|
375 |
$SED "s?^filterip.*?filterip = $PRIVATE_IP?g" /etc/dansguardian/dansguardian.conf
|
|
|
376 |
# Watchdog
|
|
|
377 |
$SED "s?^PRIVATE_IP=.*?PRIVATE_IP=\"$PRIVATE_IP\"?g" $DIR_BIN/alcasar-watchdog.sh
|
|
|
378 |
# Prompts
|
|
|
379 |
$SED "s?^ORGANISME.*?ORGANISME=$ORGANISME?g" /etc/bashrc
|
|
|
380 |
# sudoers
|
|
|
381 |
$SED "s?^Host_Alias.*?Host_Alias LAN_ORG=$PRIVATE_NETWORK/$PRIVATE_NETMASK,localhost #réseau de l'organisme?g" /etc/sudoers
|
1060 |
richard |
382 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
|
|
383 |
then
|
634 |
richard |
384 |
# Services start
|
1574 |
richard |
385 |
/usr/bin/systemctl start network && echo -n "Start service : network" && sleep 1
|
2309 |
tom.houday |
386 |
$DIR_BIN/alcasar-dhcp.sh -$DHCP_mode && echo -n ", chilli" # apply DHCP mode and start CoovaChilli
|
|
|
387 |
for i in dnsmasq dnsmasq-blackhole tinyproxy ntpd
|
|
|
388 |
do
|
|
|
389 |
sleep 1
|
|
|
390 |
/usr/bin/systemctl start $i && echo -n ", $i"
|
|
|
391 |
done
|
2247 |
tom.houday |
392 |
$DIR_BIN/alcasar-bl.sh -reload && echo -n ", dnsmasq-blacklist, dnsmasq-whitelist, iptables"
|
1827 |
raphael.pi |
393 |
/usr/bin/kill -s SIGCONT $(pidof httpd)
|
|
|
394 |
/usr/bin/systemctl reload httpd && echo -n ", httpd"
|
1060 |
richard |
395 |
fi
|
628 |
richard |
396 |
# Start / Stop SSH Daemon
|
1065 |
richard |
397 |
ssh_active=`grep SSH= $CONF_FILE|cut -d"=" -f2`
|
634 |
richard |
398 |
if [ $ssh_active = "on" ]
|
|
|
399 |
then
|
1574 |
richard |
400 |
/usr/bin/systemctl enable sshd.service
|
1060 |
richard |
401 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
|
|
402 |
then
|
1574 |
richard |
403 |
/usr/bin/systemctl start sshd.service
|
1060 |
richard |
404 |
fi
|
634 |
richard |
405 |
else
|
1574 |
richard |
406 |
/usr/bin/systemctl disable sshd.service
|
1060 |
richard |
407 |
if [ "$PARENT_SCRIPT" != "alcasar.sh" ] # don't launch on install stage
|
|
|
408 |
then
|
1574 |
richard |
409 |
/usr/bin/systemctl stop sshd.service
|
1060 |
richard |
410 |
fi
|
634 |
richard |
411 |
fi
|
2247 |
tom.houday |
412 |
echo
|
628 |
richard |
413 |
;;
|
8 |
franck |
414 |
*)
|
|
|
415 |
echo "Argument inconnu :$1";
|
|
|
416 |
echo "$usage"
|
|
|
417 |
exit 1
|
|
|
418 |
;;
|
|
|
419 |
esac
|