Commit 4925c238 authored by Vitaly Lipatov's avatar Vitaly Lipatov

parse_mail: не добавляем IP, но добавляем почту. Улучшил проверки

parent a4e56278
#!/bin/sh #!/bin/sh
grep "Connection refused" /var/log/mail/all | grep "reject: RCPT" | grep "Sender address rejected: unverified address" \ # Не смогли проверить адрес
# Sep 14 22:42:20 server postfix/smtp[20843]: 2C6FD80098: to=<noreply@openlibrary.org>, relay=mail.archive.org[207.241.224.6]:25, delay=7.5, delays=0.06/0/0.89/6.5, dsn=5.1.1, status=undeliverable (host mail.archive.org[207.241.224.6] said: 550 5.1.1 <noreply@openlibrary.org>: Recipient address rejected: User unknown in virtual mailbox table (in reply to RCPT TO command))
# Не принимаем письмо
# Sep 14 04:11:10 server postfix/smtpd[22127]: NOQUEUE: reject: RCPT from mail.mtml.ru[95.131.27.100]: 450 4.1.7 <noreply@mirtesen.ru>: Sender address rejected: unverified address: connect to mirtesen.ru[95.131.27.20]:25: Connection refused; from=<noreply@mirtesen.ru> to=<lav@etersoft.ru> proto=ESMTP helo=<mailgate1.mtml.ru>
# Sep 14 22:46:17 server postfix/smtpd[20894]: NOQUEUE: reject: RCPT from mail.us.archive.org[207.241.224.6]: 450 4.1.7 <noreply@openlibrary.org>: Sender address rejected: unverified address: host mail.archive.org[207.241.224.6] said: 550 5.1.1 <noreply@openlibrary.org>: Recipient address rejected: User unknown in virtual mailbox table (in reply to RCPT TO command); from=<noreply@openlibrary.org> to=<lav@etersoft.ru> proto=ESMTP helo=<mail.archive.org>
cat /var/log/mail/all | grep "reject: RCPT" | grep "Sender address rejected: unverified address" \
> $0.out > $0.out
# sed "s!.*RCPT from \(.*\)\[.*from=<\(.*\)> to=<\(.*\)>.*!host=\1 from=\2 to=\3!g" # sed "s!.*RCPT from \(.*\)\[.*from=<\(.*\)> to=<\(.*\)>.*!host=\1 from=\2 to=\3!g"
......
...@@ -22,7 +22,8 @@ def check_http(url): ...@@ -22,7 +22,8 @@ def check_http(url):
def append_ip(host, ip, email): def append_ip(host, ip, email):
today = datetime.datetime.now() today = datetime.datetime.now()
f = open('/etc/postfix/access-our', 'a') f = open('/etc/postfix/access-our', 'a')
f.write("\n# "+str(today)+": "+host+"\n"+ip+" OK\n"+email+" OK\n"); # записываем и хост и e-mail, потому что настроено плохо, и access указан и для IP и для e-mail
f.write("\n# "+str(today)+": "+host+"\n#"+ip+" OK\n"+email+" OK\n");
f.close() f.close()
print ip print ip
...@@ -41,7 +42,8 @@ def check_if_already(ip): ...@@ -41,7 +42,8 @@ def check_if_already(ip):
# if row == (ip+" OK\n"): # if row == (ip+" OK\n"):
# print TRUE # print TRUE
# return True # return True
return ip+" OK\n" in exists_ip # FIXME: это хак, надо парсить строки что ли, или составлять список IP для поиска
return ("#"+ip+" OK\n" in exists_ip) or (ip+" OK\n" in exists_ip)
test_string = "Sep 14 18:23:28 server postfix/smtpd[20585]: NOQUEUE: reject: RCPT from wiki.openvz.org[199.115.105.169]: 450 4.1.7 <apache@wiki.openvz.org>: Sender address rejected: unverified address: connect to wiki.openvz.org[199.115.105.169]:25: Connection refused; from=<apache@wiki.openvz.org> to=<lav@etersoft.ru> proto=ESMTP helo=<wiki.openvz.org>" test_string = "Sep 14 18:23:28 server postfix/smtpd[20585]: NOQUEUE: reject: RCPT from wiki.openvz.org[199.115.105.169]: 450 4.1.7 <apache@wiki.openvz.org>: Sender address rejected: unverified address: connect to wiki.openvz.org[199.115.105.169]:25: Connection refused; from=<apache@wiki.openvz.org> to=<lav@etersoft.ru> proto=ESMTP helo=<wiki.openvz.org>"
...@@ -74,13 +76,15 @@ if __name__== "__main__": ...@@ -74,13 +76,15 @@ if __name__== "__main__":
f = open('check_web_letters.sh.out', 'r') f = open('check_web_letters.sh.out', 'r')
result = [] result = []
totip = []
for row in f.readlines(): for row in f.readlines():
#print row #print row
line = parse_row(row) line = parse_row(row)
if line == False: if line == False:
continue continue
if line not in result: if line['ip'] not in totip:
result.append(line) result.append(line)
totip.append(line['ip'])
if list_only: if list_only:
print line print line
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment