Инструменты пользователя

Инструменты сайта


интеграция_с_ad

**Это старая версия документа!**

Нужны библиотеки pymysql (таблица в которую пишем должна быть в myisam), библиотека ldap3 и re

import re import pymysql

Описываем коннект к ДБ

db = pymysql.connect(«10.1.6.171»,«ldap»,«123456»,«asterisk» ) cursor = db.cursor()

from ldap3 import Server, Connection, SASL, DIGEST_MD5,SUBTREE

import ldap3 as ldap

from ldap3 import Connection, Server, SIMPLE, SYNC, SUBTREE, ALL

server = Server(host = '10.1.6.180', port = 389) conn = Connection(server, autobind = True, version = 3, clientstrategy = 'SYNC', authentication = SASL,

                       sasl_mechanism = DIGEST_MD5, sasl_credentials = (None, 'admin', 'Z12345xcvb', None))

#print('test')

print(conn.bind())

print('test2')

userdn = «cn=admin,ou=users,ou=data,ou=prod,ou=authserver,dc=asterisk,dc=AAA» basedn = «dc=asterisk,dc=AAA» filter = «uid=admin» totalentries = 0 conn.search(searchbase = 'dc=asterisk,dc=AAA',

       ##search_filter = '(objectClass=inetOrgPerson)',
       search_filter = '(objectCategory=Person)',            
       search_scope = SUBTREE,
       attributes = ['title','homePhone'],
       paged_size = 1000)

totalentries += len(conn.response) #result = conn.search(searchbase=basedn, searchfilter=filter, search_scope=SUBTREE)

logger.info('SEARCHING COMPLETE') #does not appear in the log

return all user data results

try:

  for entry in conn.response:

      str1 = entry['attributes']
      cont=(str1.get('title'))
      phone=(str1.get('homePhone'))
      if cont != [] and phone != [] : 
          ##print('ok')
          print(f"{cont} {phone}")
          ins=f"insert into sip(name,host,type,secret,qualify,context) values('{phone}','dynamic','friend','123456','yes','{cont}');"
          #ins =f"{phone} dsdsds {title}")
          print(ins)
          
          try:
              cursor.execute(ins)
          except:
              print('уже в базе')
      
          ##ins=f"insert into tab(p1,p2,p3,p4,p5) values('{str(mass[0])[9:18]}','{extdb}','{caldb}','{td}','{acode}');"
       
     
     

except:

  print("govno")
 
      ##print("ERR")

conn.unbind()

интеграция_с_ad.1521403221.txt.gz · Последнее изменение: 2018/03/18 23:00 (внешнее изменение)

DokuWiki Appliance - Powered by TurnKey Linux