mailcnf_posttools.py
5.59 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/python3
# -*- coding: UTF-8 -*-# enable debugging
from mysql.connector import MySQLConnection, Error
from read_dbconfig import read_db_config
import tornado.ioloop
import tornado.web
import tornado.escape
import tornado
import os.path
import sys
from subprocess import Popen, PIPE
#from itertools import izip
#from baseclasses.htmltools import htmltools
from ncauth.ncauth_base import ncauth_base
class mailcnf_posttools(ncauth_base):
def get(self):
self.redirect("/")
@tornado.web.authenticated
def post(self):
nav=all
subnav=all
content=all
msglvl=""
msg=False
mainfnc="posttools"
#module= self.get_argument("module", None, False)
#mainfnc= self.get_argument("mainfnc", None, False)
#if module== False:
module="mailcnf"
#if mainfnc== False:
mainfnc="posttools"
id= self.get_argument("id", None, False)
mailname= self.get_argument("mailname", None, False)
action= self.get_argument("action", None, False)
fnc= self.get_argument("fnc", None, False)
if action == 'postersuper1':
msg = self.postsuperdel(id,mailname)
msglvl="alert-info"
if action == 'postersupersend1':
msg = self.postersupersend1(id,mailname)
msglvl="alert-info"
if action == 'postersupershow':
msg = '<h3>Inhalt der Mail</h3><pre>'+self.postersupershow(id,mailname)+'</pre><h3>Ende der Mail</h3>'
msglvl="alert-info"
loader =tornado. template.Loader(os.path.join(os.path.dirname(__file__), "../templates"))
navigation=loader.load("navigation.html").generate(nav=nav)
subnavigation=loader.load("subnav_"+module+"_"+mainfnc+".html").generate(subnav=subnav)
mailstuff=self.mailcheck()
mailstufflist=self.mailchecktuple()
number=10
checklogin=self.checklogin(number)
maincontent=loader.load("content_"+module+"_"+mainfnc+".html").generate(mailstuff=mailstuff,mailstufflist=mailstufflist,checklogin=checklogin)
self.render('base.html', navigation=navigation, subnavigation=subnavigation, maincontent=maincontent, msg=msg, msglvl=msglvl)
def mailcheck(self):
old_dir = os.getcwd()
os.chdir( os.path.join(os.path.dirname(__file__), "") )
os.chdir( '..')
p1 = str(Popen(['/usr/sbin/postqueue','-p'],stdout=PIPE) .communicate()[0])
thatLine = p1.replace('\\n', '<br />')
thatLine = thatLine.replace('b\'', '<br>')
thatLine = thatLine.replace('\'', '')
print(str(thatLine))
return thatLine
def mailchecktuple(self):
old_dir = os.getcwd()
os.chdir( os.path.join(os.path.dirname(__file__), "") )
os.chdir( '..')
# p1 = Popen(['/usr/sbin/postqueue','-p'],stdout=PIPE)
p1 = str(Popen("/usr/sbin/postqueue -p | awk 'NR % 4 == 2' | awk '{print $1 \"\\n\" $7 }' |egrep -v '^-' | egrep -v '^$' " , stdout=PIPE, shell=True).communicate()[0])
# p3 = Popen(['egrep', '-v','"\'-\'"'], stdin=p2.stdout, stdout=PIPE)
# p4 = Popen(['egrep', '-v','"^$"'], stdin=p3.stdout, stdout=PIPE)
# p5 = Popen(['egrep', '-v','"^\("'], stdin=p4.stdout, stdout=PIPE).communicate()[0]
thatLine = p1.replace('\\n', ';')
thatLine = thatLine.replace('b\'', '')
thatLine = thatLine.replace('\'', '')
#print(str(thatLine))
list = [item for item in thatLine.split(';') if item.strip()]
# tuple = (item for item in thatLine.split(';') if item.strip())
i = iter(list)
dict = (zip(i, i))
return dict
def postsuperdel(self,id,mailname=''):
#self.write("postsuper -d "+str(id)+" " )
old_dir = os.getcwd()
os.chdir( os.path.join(os.path.dirname(__file__), "") )
os.chdir( '..')
p1 = str(Popen("/usr/sbin/postsuper -d "+str(id) , stdout=PIPE, shell=True).communicate()[0])
return "Nachricht "+str(id)+" von "+str(mailname)+" gelöscht"
def postersupersend1(self,id,mailname=''):
#self.write("postsuper -d "+str(id)+" " )
old_dir = os.getcwd()
os.chdir( os.path.join(os.path.dirname(__file__), "") )
os.chdir( '..')
p1 = str(Popen("/usr/sbin/postqueue -i "+str(id) , stdout=PIPE, shell=True).communicate()[0])
return "Nachricht "+str(id)+" von "+str(mailname)+" wird erneut versucht zu senden"
def postersupershow(self,id,mailname=''):
#self.write("postsuper -d "+str(id)+" " )
old_dir = os.getcwd()
os.chdir( os.path.join(os.path.dirname(__file__), "") )
os.chdir( '..')
p1 = str(Popen("/usr/sbin/postcat -q "+str(id) , stdout=PIPE, shell=True).communicate()[0])
thatLine = p1.replace('\\n', '<br />')
thatLine = thatLine.replace('b\'', '<br>')
thatLine = thatLine.replace('\'', '')
print(str(thatLine))
return thatLine
#return "Nachricht "+str(id)+" von "+str(mailname)+" wird erneut versucht zu senden"
def checklogin(self,number):
#self.write("postsuper -d "+str(id)+" " )
old_dir = os.getcwd()
os.chdir( os.path.join(os.path.dirname(__file__), "") )
os.chdir( '..')
p1 = str(Popen("grep sasl_username /var/log/mail.log |awk {'print $NF'}|sort| uniq -c|sort -n| awk '$1 > "+str(number)+" { print $1 \" \" $2 }' " , stdout=PIPE, shell=True).communicate()[0])
thatLine = p1.replace('\\n', '<br>')
thatLine = thatLine.replace('b\'', '<br>')
thatLine = thatLine.replace('\'', '')
return thatLine