mailcnf_domain.py
7.97 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/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
from ncauth.ncauth_base import ncauth_base
class mailcnf_domain(ncauth_base):
def get(self):
self.redirect("/")
@tornado.web.authenticated
def post(self):
nav=all
subnav=all
content=all
msglvl=""
msg=False
module= self.get_argument("module", None, False)
mainfnc= self.get_argument("mainfnc", None, False)
mainid= self.get_argument("id", None, False)
fnc= self.get_argument("fnc", None, False)
# table= self.get_argument("table", None, False)
group_id= self.get_argument("group_id", None, False)
name= self.get_argument("name", None, False)
active= self.get_argument("active", None, False)
#self.write("Hello, "+str(module )+" "+str(mainfnc)+" id: "+str(mainid)+" fnc: "+str(fnc)+" "+str(table)+"<br>")
uid=0
ugroup=10
msg=""
loader =tornado. template.Loader(os.path.join(os.path.dirname(__file__), "../templates"))
navigation=loader.load("navigation.html").generate(nav=nav)
if fnc=="delete" and mainid :
msg=self.update_virtual_domains_deleted(mainid);
msglvl="alert alert-danger"
if fnc=="undelete" and mainid :
msg=self.update_virtual_domains_undelete(mainid);
msglvl="alert alert-danger"
if fnc=="submitnewdomain" :
msg=self. insert_virtual_domain(name,active,group_id=0)
msg="Domain angelegt"
msglvl="alert alert-success"
if fnc=="submitedit" :
self.update_virtual_domains( mainid,name,active,group_id)
msg="Domain aktualisert"
msglvl="alert alert-danger"
if fnc=="edit" and mainid :
subnavigation=loader.load("subnav_"+module+"_"+mainfnc+".html").generate(subnav=subnav)
lists=self.edit_virtual_domains_by_id(mainid, uid)
print(lists)
maincontent=loader.load("content_"+module+"_"+mainfnc+"_"+fnc+".html").generate(content=content, lists=lists, uid=uid, ugroup=ugroup)
self.render('base.html', navigation=navigation, subnavigation=subnavigation, maincontent=maincontent, msg=msg, msglvl=msglvl)
elif fnc=="new":
subnavigation=loader.load("subnav_"+module+"_"+mainfnc+".html").generate(subnav=subnav)
maincontent=loader.load("content_"+module+"_"+mainfnc+"_"+fnc+".html").generate(content=content,uid=uid, ugroup=ugroup)
self.render('base.html', navigation=navigation, subnavigation=subnavigation, maincontent=maincontent, msg=msg, msglvl=msglvl)
else:
subnavigation=loader.load("subnav_"+module+"_"+mainfnc+".html").generate(subnav=subnav)
lists=self.print_virtual_domain_id('','',uid)
maincontent=loader.load("content_"+module+"_"+mainfnc+".html").generate(content=content, lists=lists)
self.render('base.html', navigation=navigation, subnavigation=subnavigation, maincontent=maincontent, msg=msg, msglvl=msglvl)
def getUsers(self):
self.write("Hello, ")
def update_virtual_domains_undelete(self, id):
query = "UPDATE virtual_domains SET deleted='0', active='1' WHERE id='"+str(id)+"'"
try:
db_config = read_db_config()
conn = MySQLConnection(**db_config)
cursor = conn.cursor()
cursor.execute(query)
conn.commit()
return "ID "+str(id)+" wiederhergestellt"
except Error as error:
print(error)
finally:
cursor.close()
conn.close()
def update_virtual_domains_deleted(self, id):
query = "UPDATE virtual_domains SET deleted='1', active='0' WHERE id='"+str(id)+"'"
try:
db_config = read_db_config()
conn = MySQLConnection(**db_config)
cursor = conn.cursor()
cursor.execute(query)
conn.commit()
return "ID "+str(id)+" deleted"
except Error as error:
print(error)
finally:
cursor.close()
conn.close()
def update_virtual_domains(self, id,name,active,group_id):
query = "UPDATE virtual_domains SET name='"+str(name)+"' ,active='"+str(active)+"' ,group_id='"+str(group_id)+"' WHERE id="+str(id)+" "
try:
self.write(query)
db_config = read_db_config()
conn = MySQLConnection(**db_config)
cursor = conn.cursor()
cursor.execute(query)
conn.commit()
self.write(query)
except Error as error:
print(error)
finally:
cursor.close()
conn.close()
def insert_virtual_domain(self,name,active,group_id=0):
query = "INSERT INTO virtual_domains(name,active,group_id) VALUE('"+name+"','"+str(active)+"','"+str(group_id)+"');"
self.write(query)
# args = (domain_id,password,email,sent_mail,active)
insert_id = ''
try:
db_config = read_db_config()
conn = MySQLConnection(**db_config)
cursor = conn.cursor()
cursor.execute(query)
if cursor.lastrowid:
insert_id=str(cursor.lastrowid)
else:
print('mailcnf_domain')
conn.commit()
except Error as error:
print(error)
finally:
cursor.close()
conn.close()
return insert_id
def print_virtual_domain_id(self, id='', gid='', uid='0'):
query = ''
delstring = ' '
dictdata =[]
if str(uid) !='0':
delstring = " and deleted='0' "
if id!='' and id != None:
query = " SELECT id,name,description,transport,modified,active,deleted,group_id FROM `virtual_domains` WHERE `id`="+id+" "+delstring
elif str(gid) !='':
query = " SELECT id,name,description,transport,modified,active,deleted,group_id FROM `virtual_domains` WHERE `group_id` in ("+gid+") "+delstring
else:
if str(uid) !='0':
query = " SELECT id,name,description,transport,modified,active,deleted,group_id FROM `virtual_domains` WHERE deleted='0'"
else:
query = " SELECT id,name,description,transport,modified,active,deleted,group_id FROM `virtual_domains`"
try:
print(query)
db_config = read_db_config()
conn = MySQLConnection(**db_config)
cursor = conn.cursor()
cursor.execute(query)
fields=cursor.fetchall()
counter = 0
for field in fields:
counter = counter + 1
field=field+(counter, )
dictdata.append(field)
except Error as error:
print(error)
finally:
conn.commit()
cursor.close()
conn.close()
return dictdata
def edit_virtual_domains_by_id(self, id,uid):
query = " SELECT * FROM `virtual_domains` WHERE `id`='"+str(id)+"'"
dictdata =[]
# self.write(query)
counter=0
try:
db_config = read_db_config()
conn = MySQLConnection(**db_config)
cursor = conn.cursor()
cursor.execute(query)
fields=cursor.fetchall()
for field in fields:
counter = counter + 1
field=field+(counter, )
dictdata.append(field)
conn.commit()
except Error as error:
print(error)
finally:
cursor.close()
conn.close()
return dictdata