tools- collection of tools for supernets sysadmins |
git clone git://git.acid.vegas/tools.git |
Log | Files | Refs | Archive |
namecheap.py (1933B)
1 #!/usr/bin/env python 2 # supernets namecheap api tool - developed by acidvegas in python (https://git.acid.vegas/supertools) 3 4 import re 5 import requests 6 import xml.etree.ElementTree as et 7 8 # Config 9 username = 'changeme' 10 api_key = 'changeme' 11 ip_addr = 'changeme' 12 13 def api(cmd, extra=False): 14 payload = { 15 'ApiKey' : api_key, 16 'ApiUser' : username, 17 'UserName' : username, 18 'ClientIP' : ip_addr, 19 'Command' : cmd 20 } 21 if extra: 22 payload.update(extra) 23 r = requests.post('https://api.namecheap.com/xml.response', params=payload) 24 return r.content 25 26 class domains: 27 class dns: 28 def getHosts(): 29 data = api('namecheap.domains.dns.getHosts', extra={'TLD': 'supernets','SLD':'org'}) 30 for child in et.fromstring(data).findall('.//{http://api.namecheap.com/xml.response}host'): 31 print(child.attrib) 32 33 def setHosts(type, address): 34 payload = { 35 'SLD' : 'supernets', 36 'TLD' : 'org', 37 'HostName' : 'irc', 38 'RecordType' : type, 39 'Address' : address, 40 'TTL' : '60' 41 } 42 data = api('namecheap.domains.dns.setHosts', payload) 43 44 class ssl: 45 def getInfo(id): 46 '''https://www.namecheap.com/support/api/methods/ssl/get-info/''' 47 data = api('namecheap.ssl.getInfo', extra={'CertificateID':id}) 48 49 def getList(): 50 '''https://www.namecheap.com/support/api/methods/ssl/get-list/''' 51 data = api('namecheap.ssl.getList') 52 53 def activate(id, csr, mail): 54 '''https://www.namecheap.com/support/api/methods/ssl/activate/''' 55 payload = { 56 'CertificateID': id, 57 'CSR':csr, 58 'AdminEmailAddress':mail 59 } 60 data = api('namecheap.ssl.activate', payload) 61 62 def parseCSR(csr): 63 payload = { 64 'csr': csr, 65 'CertificateType': 'PositiveSSL' 66 } 67 data = api('namecheap.ssl.parseCSR', payload) 68 69 def renew(id): 70 '''https://www.namecheap.com/support/api/methods/ssl/renew/''' 71 payload = { 72 'CertificateID':id, 73 'SSLType': 'PositiveSSL', 74 'years': '1' # or 5 75 } 76 data = api('namecheap.ssl.renew')