You need to sign in or sign up before continuing.
Commit 9b010a12 authored by Vitaly Lipatov's avatar Vitaly Lipatov

add mail check script, add broken web hosts to access list

parent f6c328f1
Команда et, выполняющая команды из /usr/lib/etersoft-admin-essentials
#!/bin/sh
grep "Connection refused" /var/log/mail/all | grep "reject: RCPT" | grep "Sender address rejected: unverified address" \
> $0.out
# sed "s!.*RCPT from \(.*\)\[.*from=<\(.*\)> to=<\(.*\)>.*!host=\1 from=\2 to=\3!g"
date
$(dirname $0)/parse_mail_log.py
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys, string, re, getopt, datetime, tempfile, time
from operator import truth
import datetime
import httplib2
def check_http(url):
h = httplib2.Http()
try:
resp = h.request(url, 'HEAD')
ec = int(resp[0]['status'])
print 'status code ', ec, ' for ', url
#return ec < 400
return True
except:
# TODO: странности с проверкой portal-credo.info
print 'exception with ', url
return False
def append_ip(host, ip, email):
today = datetime.datetime.now()
f = open('/etc/postfix/access-our', 'a')
f.write("\n# "+str(today)+": "+host+"\n"+ip+" OK\n#"+email+" OK\n");
f.close()
print ip
exists_ip = []
def read_exists_ip():
global exists_ip
f = open('/etc/postfix/access-our', 'r')
exists_ip = f.readlines()
#print exists_ip
f.close()
def check_if_already(ip):
global exists_ip
#for row in exists_ip:
# print row, ' --- ', (ip+" OK", ' ### ')
# if row == (ip+" OK\n"):
# print TRUE
# return True
return 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>"
tpl = re.compile(".*NOQUEUE: reject: RCPT from (.*?)\[(.*?)\].*from=<(.*?)>.*to=<(.*?)>.*")
#tpl = re.compile(".*RCPT from (.*?)\[(.*?)\].*")
def parse_row(row):
parsed = tpl.search(row)
if not truth(parsed):
return
res = {"host":parsed.group(1),
"ip":parsed.group(2),
"from":parsed.group(3),
"to":parsed.group(4),
}
return res
if __name__== "__main__":
#print test_string
#r1 = parse_row (test_string)
#print r1
read_exists_ip()
f = open('check_web_letters.sh.out', 'r')
result = []
for row in f.readlines():
#print row
line = parse_row(row)
if line == False:
continue
if line not in result:
result.append(line)
#print line
sp = string.split(line['from'],'@')
# если домен почты совпадает с хостом отправителя
if sp[1] == line['host']:
url = 'http://'+line['host']
print
print line
#print 'url=', url
if check_http(url):
if not check_if_already(line['ip']):
append_ip(line['host'], line['ip'], line['from'])
else:
print url, 'already exists'
else:
print 'Host ', url, 'are not accessed'
#exit()
f.close()
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