-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcensorship-apply
executable file
·57 lines (50 loc) · 2.35 KB
/
censorship-apply
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
#!/bin/bash
# This master script runs the scripts which implement by-name and by-IP
# censorship.
# It must not fail even if one of the steps fail.
source config.sh
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Censorship APPLY started." >> $LOGFILE
./upload-bind-config || true
#./upload-unbound-config || true
#copying all the lists
TEMPFILE=$CONF_IP-tmp
echo -n "" > $TEMPFILE
for i in $LISTS ; do
if [ -e lists/$i-ip ] ; then
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - $i IPs: $(wc -w lists/$i-ip)" >> $LOGFILE
cat lists/$i-ip | sed 's/\r//g' >> $TEMPFILE
fi
done
cat $TEMPFILE | sort | uniq > $CONF_IP-new
rm $TEMPFILE
if [ $AGGREGATE_PREFIX == 'true' ] ; then
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - IP Aggregation enabled." >> $LOGFILE
# Subnets aggregation
if [ ! -e $AGGREGATION_TOOL ] ; then
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - ERROR: $AGGREGATION_TOOL not found. See README" >> $LOGFILE
exit
fi
python $AGGREGATION_TOOL --maxrange $AGGREGATION_MAXLEN $CONF_IP-new | sort | uniq > $AGGREGATE_LIST_FILE-new
if [ ! -e $AGGREGATE_LIST_FILE ] || ! diff $AGGREGATE_LIST_FILE $AGGREGATE_LIST_FILE-new &> /dev/null; then
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - New IPs detected." >> $LOGFILE
mv $CONF_IP-new $CONF_IP
mv $AGGREGATE_LIST_FILE-new $AGGREGATE_LIST_FILE
./install-routes-linux $AGGREGATE_LIST_FILE || true
else
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - No new IPs detected." >> $LOGFILE
fi
else
# no aggregation
if [ ! -e $CONF_IP ] || ! diff $CONF_IP $CONF_IP-new &> /dev/null; then
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - New IPs detected." >> $LOGFILE
mv $CONF_IP-new $CONF_IP
./install-routes-linux $CONF_IP || true
else
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - No new IPs detected." >> $LOGFILE
fi
fi
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Total IPs: $(wc -w $CONF_IP)" >> $LOGFILE
if [ $AGGREGATE_PREFIX == 'true' ] ; then
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Total CIDRs: $(wc -w $AGGREGATE_LIST_FILE)" >> $LOGFILE
fi
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Censorship APPLY ended." >> $LOGFILE