diff --git a/www/index.py b/www/index.py index 6df33e0..e981d82 100755 --- a/www/index.py +++ b/www/index.py @@ -1,5 +1,6 @@ # coding=utf-8 import os, sys, pymysql, re, time +from ldap3 import Server, Connection, NTLM def application(environ, start_response): #sys.stdout._encoding = 'utf-8' @@ -15,6 +16,8 @@ def application(environ, start_response): output = bytes((header() + body() + getCOline() + footer()).encode('utf8')) elif paramDict.get('query_type') == 'report': 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: output = bytes((header() + body() + footer()).encode('utf8')) @@ -46,12 +49,13 @@ def menu(): '
  • Справочник
  • \n' \ + '
  • Внутренние (AD)
  • \n' \ '
  • Отчёты\n' return txtMenu - +# Список внутренних номеров из СУБД def getInternalNumbers(): conn = connectDB() c = conn.cursor() @@ -68,6 +72,56 @@ def getInternalNumbers(): rowData = "%s%s%s%s%s\n" % (row[0], row[1], row[2], row[4], row[3], row[3]) result = result + rowData return (result + "\n") +# Список пользователей (ФИО, телефон, почта, отдел) из LDAP (AD) +def getLDAPusers(): + + order = 'int_number' + result = '

    Список абонентов ЛТБ

    ' + listHeader = '\n' \ + '\n' \ + '\n' \ + '\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 = "\n" % (name, phone, dep, mail, mail) + result = result + rowData + return (result + "
    № п/пТелефонФИООписаниеЭл.почта
    %s%s%s%s
    \n") + def getCOline(): conn = connectDB() diff --git a/www/report.py b/www/report.py index 3cc696e..156c44a 100755 --- a/www/report.py +++ b/www/report.py @@ -3,6 +3,8 @@ import sys import cgitb import cgi +#import ldap + cgitb.enable() # Print necessary headers. print("Content-Type: text/html; charset=UTF-8\n\n") @@ -66,6 +68,8 @@ if qwery_type == "internal": for row in c.fetchall(): print("%s%s%s%s%s%s%s%s%s%s%s" % (row[0], row[1], row[2], row[3], row[4], row[5], row[5], row[7], row[9], row[9], row[10])) print("") +elif qwery_type == 'ldap': + print("") print("") \ No newline at end of file