Jump to content

chrishumphr1es

Member
  • Posts

    12
  • Joined

  • Last visited

Posts posted by chrishumphr1es

  1. I think I've confused everyone pretty well for all of this, haha. Thank you guys for what you've done. I'm just going to post my workflow so I'll can show you what I've got.

     

    My workflow: https://www.dropbox.com/s/ujyop86u2ohercu/LDAPSearch.alfredworkflow - I've removed my login info and just have generic data in place.

     

    My hope is that i could

    1. Search my company's ldap database

    2. output the data I need into a file alfred can read

    3. Be able to list the data similar to how alfred does with spotlighted contacts

    4. be able to create a new email message from the listing.

     

    Any feedback you guys have would be great.

  2. Ok, thanks so much. Does this go in my script filter? I know my responses are probably frustrating but I am new at this and just trying to figure it out. Please feel free to just not respond if you'd rather not, but you've been helpful so far and I really appreciate it. 

     

    Would my script filter be as follows: sys.stdout.write('/tmp/ldapres.xml'.encode('utf-8')) ?

  3. Ok great, I think I've fixed it.

     

    My xmlfile looks like this:

    <?xml version="1.0"?>
    <items>
    <items><item arg="email" uid="username" valid="YES"><title title="name" /><subtitle subtitle="telephoneNumber :+1 111 111 1111 mail : mail" /></item></items>
    </items>
    

    Will this work for the script filter? How do I tell the script filter to call the file? I've been reading all of the docs in the forums, and am still a bit stuck.

  4. Thank you for your comments, they have been very helpful.

     

    I actually found a ldap python library online and a few helpful scripts which helped me write a python script that returns the info I need, my only confusion now is reformatting the xml file into the correct alfred format.

     

    Here's my script:

    #!/usr/local/bin/python 
    
    import ldap, sys
    
    
    if __name__ == "__main__":
      	ldap_server="ldap_server"
    	username = "username"
    	password= "password"
    	# the following is the user_dn format provided by the ldap server
    	user_dn = "uid="+username+",ou=people,dc=ex,dc=com"
    	# adjust this to your base dn for searching
    	base_dn = "dc=ex,dc=com"
    	connect = ldap.open(ldap_server)
    	search_filter = "uid="+username
    	try:
    		#if authentication successful, get the full user data
    		connect.bind_s(user_dn,password)
    		retrieveAttributes = ["mail", "telephoneNumber", "cn"]
    		result = connect.search_s(base_dn,ldap.SCOPE_SUBTREE,search_filter,retrieveAttributes)
    		# return all user data results
    		connect.unbind_s()
    		sys.stdout = open('/tmp/ldapres.xml', 'r+')
    		print result
    		
    		
    	except ldap.LDAPError:
    		connect.unbind_s()
    		print "authentication error"
    
    

    and here is my xml file:

    [('uid=username, ou=people, dc=ex, dc=com', {'telephoneNumber': ['+1 111 111 1111'], 'mail': ['email'], 'cn': ['full name']})]
    

    Any ideas on how to get this into the format alfred needs to display it correctly would be super helpful.

     

    I've replaced my specific login info and output with generics

     

    Thanks! 

  5. I have, I'm just not sure how to go about connecting the dots..I'm pretty green at all of this. Here's my output from the terminal (using generic parameters instead of specific for privacy) : 

    command: ldapsearch -h ldap.server.com -x -b "dc=company,dc=com" "uid=*username*" "telephoneNumber" "mail" "uid"
    
    # extended LDIF 
    # 
    # LDAPv3 
    # base with scope subtree 
    # filter: uid=*username* 
    # requesting: telephoneNumber mail uid 
    # 
    
    # username, people, ex.com 
    dn: uid=username, ou=people, dc=company, dc=com 
    telephoneNumber: +1 111 111-1111 
    mail: email 
    uid: username 
    # search result 
    search: 2 
    result: 0 Success 
    # numResponses: 2 
    # numEntries: 1 

     I'd like to be able to return the telephonNumber, mail, and uid values back to alfred similar to the way it does for the built-in contacts. Is this possible? Even better would be to be able to trigger an email from the mail value.

  6. My goal for my workflow is to run a bash command that uses ldapsearch to search my university's directory and return a list of contacts that operates similar to Alfred's contact search. I've got my bash script running fine, but I'm just unclear on how to format the returned information in the best way. Any guidance on script filtering and bash script returning would be great! I am relatively new at this, so excuse my poor terminology.

×
×
  • Create New...