-
Notifications
You must be signed in to change notification settings - Fork 5
/
update_pscaiip
executable file
·83 lines (67 loc) · 3.82 KB
/
update_pscaiip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
source config.sh
cd $PATH_pscaiip
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Invoking AAIP Privacy Shield Client" >> $LOGFILE
iptables -t nat -D POSTROUTING -d 10.253.254.20 -j SNAT --to 10.255.0.6 &> /dev/null
iptables -t nat -I POSTROUTING 1 -d 10.253.254.20 -j SNAT --to 10.255.0.6 &> /dev/null
iptables -t nat -D POSTROUTING -d 10.252.4.20 -j SNAT --to 10.255.0.6 &> /dev/null
iptables -t nat -I POSTROUTING 1 -d 10.252.4.20 -j SNAT --to 10.255.0.6 &> /dev/null
if [ $PSCAIIP_RANDOM_SLEEP == 'true' ] ; then
SLEEP=$((RANDOM % $PSCAIIP_MAXWAIT))
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Random wait enabled: waiting for $SLEEP seconds" >> $LOGFILE
sleep $SLEEP;
fi
echo "$(date '+%d/%m/%y %H:%M:%S') - docker-compose exec app bash -c \"php application psc:run\"" >> $LOGFILE
# too verbose for logfile
docker-compose exec app bash -c "php application psc:run" &> /dev/null
DOCKER_RETURN=$?
if [ $DOCKER_RETURN != 0 ] ; then
SUBJECT="Error while running Privacy Shield Client"
TXT="Privacy Shield Client on $(hostname --fqdn) psc:run have failed and returned $DOCKER_RETURN"
if [ $ALERT_ENABLE == true ] && [ "x$NOC_EMAIL" != 'x' ] && [ $ALERT_PSCAIIP_ENABLE == true ] ; then
echo -e "Subject: $SUBJECT\nFrom:$FROM_EMAIL\n$TXT" | sendmail $NOC_EMAIL
fi
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - AAIP Privacy Shield Client Run returned Error: $TXT" >> $LOGFILE
echo "Warning: $TXT" >&2
else
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - AAIP Privacy Shield Client Run Ended" >> $LOGFILE
fi
echo "$(date '+%d/%m/%y %H:%M:%S') - docker-compose exec app bash -c \"php application psc:process-queue\"" >> $LOGFILE
docker-compose exec app bash -c "php application psc:process-queue" >> $LOGFILE
DOCKER_RETURN_QUEUE=$?
if [ $DOCKER_RETURN_QUEUE != 0 ] ; then
SUBJECT="Error while running Privacy Shield Client"
TXT="Privacy Shield Client on $(hostname --fqdn) process-queue have failed and returned $DOCKER_RETURN_QUEUE"
if [ $ALERT_ENABLE == true ] && [ "x$NOC_EMAIL" != 'x' ] && [ $ALERT_PSCAIIP_ENABLE == true ] ; then
echo -e "Subject: $SUBJECT\nFrom:$FROM_EMAIL\n$TXT" | sendmail $NOC_EMAIL
fi
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - AAIP Privacy Shield Client returned Error during Process-Queue: $TXT" >> $LOGFILE
echo "Warning: $TXT" >&2
else
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - AAIP Privacy Shield Client Process-Queue Ended" >> $LOGFILE
fi
cd /root/kit-censura
#copying files from AAIP Privacy Shield Client
test -e "$PATH_pscaiip_fqdn" && cp $PATH_pscaiip_fqdn $FILE_pscaiip
if [ -e "$PATH_pscaiip_ipv4" ] ; then
cat $PATH_pscaiip_ipv4 > $FILE_pscaiip-ip
echo "" >> $FILE_pscaiip-ip
test -e "$PATH_pscaiip_ipv6" && cat $PATH_pscaiip_ipv6 >> $FILE_pscaiip-ip
else
test -e "$PATH_pscaiip_ipv6" && cat $PATH_pscaiip_ipv6 > $FILE_pscaiip-ip
fi
if [ -e "$FILE_pscaiip" ]; then
egrep '^[^#]' $FILE_pscaiip | sed 's~http[s]*://~~g' | sed -e "s/\r//g" | sort | uniq > lists/pscaiip.new.tmp
#cp $FILE_pscaiip lists/pscaiip.new.tmp
#egrep '^[^#]' $FILE_pscaiip | sort | uniq > lists/pscaiip.new.tmp
mv lists/pscaiip.new.tmp lists/pscaiip.new
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Imported list of FQDN $FILE_pscaiip" >> $LOGFILE
elif [ ! -e lists/pscaiip.new ]; then
: > lists/pscaiip.new
fi
# allow manual add of specific IPs if file exists (ex lista.pscaiip-ip)
if [ -e $FILE_pscaiip-ip ]; then
egrep '^[^#]' $FILE_pscaiip-ip | sort | uniq > lists/pscaiip-ip
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Imported list of IP $FILE_pscaiip-ip" >> $LOGFILE
fi
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Import pscaiip Completed" >> $LOGFILE