-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupdate_cncpo
executable file
·126 lines (96 loc) · 4.5 KB
/
update_cncpo
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
source config.sh
source curl_errors.sh
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - CNCPO PEC Checking Started" >> $LOGFILE
cd $CNCPO_WORKING_DIR
# generating new setting file
cp $CNCPO_SETTINGS_TMPL settings.yaml
VARS=$(set | grep CNCPO | cut -d= -f1)
for var in $VARS ; do
VALUE=$(echo ${!var} | sed 's/\//\\\//g' )
sed -i "s/${var}/$VALUE/g" settings.yaml
done
# Running the Fetcher
python $CNCPO_DOWNLOAD_HELPER &>> $LOGFILE
if [ $? != 0 ] ; then
SUBJECT="Error while fetching CNCPO lists"
TXT='Unable to check PEC Mailbox'
if [ $ALERT_ENABLE == true ] && [ "x$NOC_EMAIL" != 'x' ] ; 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') - CNCPO Error: $TXT" >> $LOGFILE
echo "Warning: $TXT" >&2
exit 255
else
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Successfully checked CNCPO lists" >> $LOGFILE
fi
# check if there is new list downloaded
if [ -e $CNCPO_DOWNLOAD_DIR/$CNCPO_FILE_NAME_CRYPT ] ; then
# import key
if [ $GPG_IMPORT_KEY == true ] ; then
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - CNCPO Key Import Started" >> $LOGFILE
$CNCPO_GPG_PATH $GPG_IMPORT_ARGS --import $GPG_PRIVATE_KEY &>> $LOGFILE
if [ $? != 0 ] ; then
SUBJECT="Error while importing GPG Keyfile $GPG_PRIVATE_KEY"
TXT='Unable to import GPG Keyfile $GPG_PRIVATE_KEY'
if [ $ALERT_ENABLE == true ] && [ "x$NOC_EMAIL" != 'x' ] ; 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') - CNCPO Error: $TXT" >> $LOGFILE
echo "Warning: $TXT" >&2
exit 255
fi
fi
# decrypt
$CNCPO_GPG_PATH $GPG_DECRYPT_ARGS -o $CNCPO_DOWNLOAD_DIR/$CNCPO_FILE_NAME_DECRYPT --decrypt $CNCPO_DOWNLOAD_DIR/$CNCPO_FILE_NAME_CRYPT
if [ $? != 0 ] && [ ! -e $CNCPO_DOWNLOAD_DIR/$CNCPO_FILE_NAME_DECRYPT ] ; then
NEWFILENAME="$CNCPO_DOWNLOAD_DIR/$CNCPO_FILE_NAME_CRYPT.undecifrable-$(date +%Y%m%d%H%M)"
SUBJECT="Error while decrypting list"
TXT="Unable to decrypt file $CNCPO_FILE_NAME_CRYPT with GPG Keyfile $GPG_PRIVATE_KEY. The file was moved to $NEWFILENAME"
if [ $ALERT_ENABLE == true ] && [ "x$NOC_EMAIL" != 'x' ] ; 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') - CNCPO Error: $TXT" >> $LOGFILE
echo "Warning: $TXT" >&2
mv $CNCPO_DOWNLOAD_DIR/$CNCPO_FILE_NAME_CRYPT $NEWFILENAME
exit 255
else
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Successfully decrypted CNCPO lists" >> $LOGFILE
fi
# copy files
mv $CNCPO_DOWNLOAD_DIR/$CNCPO_FILE_NAME_DECRYPT ../$FILE_cncpo
# delete encrypted copy
rm $CNCPO_DOWNLOAD_DIR/$CNCPO_FILE_NAME_CRYPT
# Parse header for answer
LISTAID=$(head -1 ../$FILE_cncpo | cut -d\; -f1)
LISTADATE=$(head -1 ../$FILE_cncpo | cut -d\; -f2)
# answer
if [ $CNCPO_REPLY_ENABLED == true ] ; then
echo "$CNCPO_REPLY_TEMPLATE" | sed "s/_LISTAID_/$LISTAID/g" | sed "s/_LISTADATE_/$LISTADATE/g" | sed "s/_DATE_/$(date)/g" | python $CNCPO_EMAIL_SENDER
if [ $? != 0 ] ; then
SUBJECT="Error while sending reply message to CNCPO"
TXT="Unable to send reply message to $CNCPO_REPLY_DESTINATION"
if [ $ALERT_ENABLE == true ] && [ "x$NOC_EMAIL" != 'x' ] ; 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') - CNCPO Error: $TXT" >> $LOGFILE
echo "Warning: $TXT" >&2
exit 255
else
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Successfully Sent CNCPO PEC Reply" >> $LOGFILE
fi
fi
else
# nothing new to do
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - No new lists found." >> $LOGFILE
fi
cd ..
## parsing ###################################################################
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - CNCPO Parsing Started" >> $LOGFILE
./parse_cncpo $FILE_cncpo lists/cncpo.new lists/cncpo-ip.new 2>&1 | tee -a $LOGFILE
if [ $? == 0 ] ; then
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - CNCPO Parsing Completed" >> $LOGFILE
else
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Error while Parsing CNCPO Lists" >> $LOGFILE
fi
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Successfully processed CNCPO lists" >> $LOGFILE