Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import xml.etree.ElementTree as ET
- import requests
- from yattag import indent
- url = 'https://mail.hovedkvarteret.no:7071/service/admin/soap'
- headers = { 'Content-Type': 'application/soap+xml' }
- # Get the credentials through zmlocalconfig
- # zmlocalconfig zimbra_user
- # zmlocalconfig -s zimbra_ldap_password
- zimbra_user = 'zimbra'
- zimbra_password = 'zimbra_ldap_password'
- token_xml = '<?xml version="1.0" ?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">\
- <soap:Header><context xmlns="urn:zimbra"><format type="xml"/></context></soap:Header><soap:Body><AuthRequest xmlns="urn:zimbraAdmin">\
- <name>%s</name><password>%s</password></AuthRequest></soap:Body></soap:Envelope>' % (zimbra_user, zimbra_password)
- r = requests.post(url, data=token_xml, headers=headers)
- # Got the admin token, now you can get the delegated token to act on behalf a specific account
- admin_token = ET.fromstring(r.content).find('.//{urn:zimbraAdmin}authToken').text
- username = 'user3@hovedkvarteret.no'
- delegated_token_xml = '<?xml version="1.0" ?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">\
- <soap:Header>\
- <context xmlns="urn:zimbra">\
- <authToken>%s</authToken>\
- </context>\
- </soap:Header>\
- <soap:Body>\
- <DelegateAuthRequest duration="86400" xmlns="urn:zimbraAdmin">\
- <account by="name">%s</account>\
- </DelegateAuthRequest>\
- </soap:Body>\
- </soap:Envelope>' % (admin_token, username)
- r = requests.post(url, data=delegated_token_xml, headers=headers)
- #print(r)
- delegated_token = ET.fromstring(r.content).find('.//{urn:zimbraAdmin}authToken').text
- info_request_xml = '<?xml version="1.0" ?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">\
- <soap:Header>\
- <context xmlns="urn:zimbra">\
- <authToken>%s</authToken>\
- <session/><account by="name">%s</account>\
- <userAgent name="zclient" version="8.0.7_GA_6020"/>\
- </context>\
- </soap:Header>\
- <soap:Body>\
- <GetAccountInfoRequest>\
- <account by="id">%s</account>\
- </GetAccountInfoRequest>\
- </soap:Body>\
- </soap:Envelope>' % (delegated_token, username, "uuid")
- # print (info_request_xml)
- # Now you can start using the main url
- main_url = 'https://mail.hovedkvarteret.no/service/soap'
- r = requests.post(main_url, data=info_request_xml, headers=headers)
- print(r.content)
- # print(getcontacts)
- pretty_string = indent(r.content)
- print(pretty_string)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement