Added LDAP (AD) address book support
This commit is contained in:
parent
8088c7da0d
commit
97a8bbacb7
56
www/index.py
56
www/index.py
|
@ -1,5 +1,6 @@
|
||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
import os, sys, pymysql, re, time
|
import os, sys, pymysql, re, time
|
||||||
|
from ldap3 import Server, Connection, NTLM
|
||||||
|
|
||||||
def application(environ, start_response):
|
def application(environ, start_response):
|
||||||
#sys.stdout._encoding = 'utf-8'
|
#sys.stdout._encoding = 'utf-8'
|
||||||
|
@ -15,6 +16,8 @@ def application(environ, start_response):
|
||||||
output = bytes((header() + body() + getCOline() + footer()).encode('utf8'))
|
output = bytes((header() + body() + getCOline() + footer()).encode('utf8'))
|
||||||
elif paramDict.get('query_type') == 'report':
|
elif paramDict.get('query_type') == 'report':
|
||||||
output = bytes((header() + body() + ReportForm() + ReportData(environ) + footer()).encode('utf8'))
|
output = bytes((header() + body() + ReportForm() + ReportData(environ) + footer()).encode('utf8'))
|
||||||
|
elif paramDict.get('query_type') == 'ldap':
|
||||||
|
output = bytes((header() + body() + getLDAPusers() + footer()).encode('utf8'))
|
||||||
else:
|
else:
|
||||||
output = bytes((header() + body() + footer()).encode('utf8'))
|
output = bytes((header() + body() + footer()).encode('utf8'))
|
||||||
|
|
||||||
|
@ -46,12 +49,13 @@ def menu():
|
||||||
'<li><a class="hsubs" href="#">Справочник</a><ul class="subs">\n' \
|
'<li><a class="hsubs" href="#">Справочник</a><ul class="subs">\n' \
|
||||||
'<li><a href="?query_type=external">Городские телефоны</a></li>\n' \
|
'<li><a href="?query_type=external">Городские телефоны</a></li>\n' \
|
||||||
'<li><a href="?query_type=internal">Внутренние</a></li></ul></li>\n' \
|
'<li><a href="?query_type=internal">Внутренние</a></li></ul></li>\n' \
|
||||||
|
'<li><a href="?query_type=ldap">Внутренние (AD)</a></li></ul></li>\n' \
|
||||||
'<li><a class="hsubs" href="">Отчёты</a><ul class="subs">' \
|
'<li><a class="hsubs" href="">Отчёты</a><ul class="subs">' \
|
||||||
'<li><a href="?query_type=report&report_type=int">Список звонков по номеру</a></li>\n' \
|
'<li><a href="?query_type=report&report_type=int">Список звонков по номеру</a></li>\n' \
|
||||||
'<li><a href="?query_type=report&report_type=dep">Звонки по отделам</a></li>\n' \
|
'<li><a href="?query_type=report&report_type=dep">Звонки по отделам</a></li>\n' \
|
||||||
'</ul></div>\n'
|
'</ul></div>\n'
|
||||||
return txtMenu
|
return txtMenu
|
||||||
|
# Список внутренних номеров из СУБД
|
||||||
def getInternalNumbers():
|
def getInternalNumbers():
|
||||||
conn = connectDB()
|
conn = connectDB()
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
@ -68,6 +72,56 @@ def getInternalNumbers():
|
||||||
rowData = "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td><a href=\"mailto:%s\">%s</a></td></tr>\n" % (row[0], row[1], row[2], row[4], row[3], row[3])
|
rowData = "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td><a href=\"mailto:%s\">%s</a></td></tr>\n" % (row[0], row[1], row[2], row[4], row[3], row[3])
|
||||||
result = result + rowData
|
result = result + rowData
|
||||||
return (result + "</table>\n")
|
return (result + "</table>\n")
|
||||||
|
# Список пользователей (ФИО, телефон, почта, отдел) из LDAP (AD)
|
||||||
|
def getLDAPusers():
|
||||||
|
|
||||||
|
order = 'int_number'
|
||||||
|
result = '<h4 align=left>Список абонентов ЛТБ</h4>'
|
||||||
|
listHeader = '<table class="table_dark"><tr><th>№ п/п</th>\n' \
|
||||||
|
'<th><a href=index.py?query_type=internal&order=int_number>Телефон</a></th>\n' \
|
||||||
|
'<th><a href=index.py?query_type=internal&order=fio>ФИО</a></th>\n' \
|
||||||
|
'<th>Описание<th>Эл.почта</th></tr>\n'
|
||||||
|
result = result + listHeader
|
||||||
|
|
||||||
|
# define the server and the connection
|
||||||
|
s = Server('1.1.1.1')
|
||||||
|
c = Connection(s, user="DOMEN\\user", password="some-pass", authentication=NTLM)
|
||||||
|
# perform the Bind operation
|
||||||
|
if not c.bind():
|
||||||
|
print('error in bind', c.result)
|
||||||
|
|
||||||
|
c.search('OU=LTB_users,dc=dals,dc=local', '(objectclass=person)',
|
||||||
|
attributes=['cn', 'mail', 'telephoneNumber', 'department'])
|
||||||
|
# print(c.result)
|
||||||
|
for item in c.entries:
|
||||||
|
# print(item)
|
||||||
|
# item = re.sub('\n', '', str(item))
|
||||||
|
item = str(item)
|
||||||
|
name = re.search('(cn:)(.+?)(\n)', item)
|
||||||
|
if name:
|
||||||
|
name = name.groups()[1]
|
||||||
|
else:
|
||||||
|
name=name
|
||||||
|
#print(name.groups()[1])
|
||||||
|
department = re.search("(department:)(.+?)(\n)", item)
|
||||||
|
if department:
|
||||||
|
dep = department.groups()[1]
|
||||||
|
else:
|
||||||
|
dep = ""
|
||||||
|
mail = re.search("(mail:)(.+?)(\n)", item)
|
||||||
|
if mail:
|
||||||
|
mail = mail.groups()[1]
|
||||||
|
else:
|
||||||
|
mail = ""
|
||||||
|
telephone = re.search("(telephoneNumber:)(.+?)(\n)", item)
|
||||||
|
if telephone:
|
||||||
|
phone = telephone.groups()[1]
|
||||||
|
else:
|
||||||
|
phone = ""
|
||||||
|
rowData = "<tr><td></td><td>%s</td><td>%s</td><td>%s</td><td><a href=\"mailto:%s\">%s</a></td></tr>\n" % (name, phone, dep, mail, mail)
|
||||||
|
result = result + rowData
|
||||||
|
return (result + "</table>\n")
|
||||||
|
|
||||||
|
|
||||||
def getCOline():
|
def getCOline():
|
||||||
conn = connectDB()
|
conn = connectDB()
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
import sys
|
import sys
|
||||||
import cgitb
|
import cgitb
|
||||||
import cgi
|
import cgi
|
||||||
|
#import ldap
|
||||||
|
|
||||||
cgitb.enable()
|
cgitb.enable()
|
||||||
# Print necessary headers.
|
# Print necessary headers.
|
||||||
print("Content-Type: text/html; charset=UTF-8\n\n")
|
print("Content-Type: text/html; charset=UTF-8\n\n")
|
||||||
|
@ -66,6 +68,8 @@ if qwery_type == "internal":
|
||||||
for row in c.fetchall():
|
for row in c.fetchall():
|
||||||
print("<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % (row[0], row[1], row[2], row[3], row[4], row[5], row[5], row[7], row[9], row[9], row[10]))
|
print("<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>" % (row[0], row[1], row[2], row[3], row[4], row[5], row[5], row[7], row[9], row[9], row[10]))
|
||||||
print("</table>")
|
print("</table>")
|
||||||
|
elif qwery_type == 'ldap':
|
||||||
|
|
||||||
|
|
||||||
print("</td></tr></table>")
|
print("</td></tr></table>")
|
||||||
print("</body></html>")
|
print("</body></html>")
|
Loading…
Reference in New Issue
Block a user