Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
etersoft-admin-essentials
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
etersoft-admin-essentials
Commits
9b010a12
Commit
9b010a12
authored
Sep 14, 2013
by
Vitaly Lipatov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add mail check script, add broken web hosts to access list
parent
f6c328f1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
0 deletions
+103
-0
TODO
TODO
+1
-0
check_web_letters.sh
mail/check_web_letters.sh
+8
-0
parse_mail_log.py
mail/parse_mail_log.py
+94
-0
No files found.
TODO
0 → 100644
View file @
9b010a12
Команда et, выполняющая команды из /usr/lib/etersoft-admin-essentials
mail/check_web_letters.sh
0 → 100755
View file @
9b010a12
#!/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
mail/parse_mail_log.py
0 → 100755
View file @
9b010a12
#!/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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment