Skip to content

Instantly share code, notes, and snippets.

@framirez
Created August 25, 2016 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save framirez/f748054f79d900704e9026dd652911ce to your computer and use it in GitHub Desktop.
Save framirez/f748054f79d900704e9026dd652911ce to your computer and use it in GitHub Desktop.
# Class to report abuse incidents to Godaddy hosting
import requests
import json
class godaddy():
TYPE_ABUSE = ['A_RECORD', 'CHILD_ABUSE', 'CONTENT', 'FRAUD_WIRE',
'IP_BLOCK', 'MALWARE', 'NETWORK_ABUSE', 'PHISHING', 'SPAM']
URL = "https://api.ote-godaddy.com/v1/{}"
HEADERS = {
"Content-Type": "application/json",
"Accept": "application/json"
}
def __init__(self):
pass
def __checkString(self, var, min_len, max_len):
if type(var) is str and len(var) > min_len and len(var) < max_len:
return True
return False
def reportAbuse(self, a_type, source, target=None, proxy=None, intentional=None, info=None, infoUrl=None):
ret = {}
if a_type in self.TYPE_ABUSE:
ret["type"] = a_type
else:
raise Exception('Type not in {}'.format(str(self.TYPE_ABUSE)))
if self.__checkString(source, 1, 250):
ret["source"] = source
else:
raise Exception('Source len 1...250')
if target is not None:
if self.__checkString(target, 0, 250):
ret["target"] = target
else:
raise Exception('Target len 0...250')
if proxy is not None:
if self.__checkString(proxy, 0, 250):
ret["proxy"] = proxy
else:
raise Exception('Proxy len 0...250')
if intentional is not None:
if type(intentional) is bool:
ret["intentional"] = intentional
else:
raise Exception('Intentional len 0...250')
if info is not None:
if self.__checkString(info, 0, 250):
ret["info"] = info
else:
raise Exception('Info len 0...250')
if infoUrl is not None:
if self.__checkString(infoUrl, 0, 250):
ret["infoUrl"] = infoUrl
else:
raise Exception('InfoUrl len 0...250')
r = requests.post(self.URL.format("abuse/tickets"),
headers=self.HEADERS, data=json.dumps(ret))
if r.status_code is not 201:
print(""" Status Code erro {}
201 Success
401 Authentication info not sent or invalid
403 Authenticated user is not allowed access
422 Error
{}""".format(r.status_code, r.text))
print "Ticket number {}".format(json.loads(r.text)["u_number"])
def checkTicketId(self, ticket_id):
if self.__checkString(ticket_id, 1, 40):
r = requests.get(self.URL.format(
"abuse/tickets/{}".format(ticket_id)), headers=self.HEADERS)
print r.text
else:
raise Exception('Ticket_id len 1...40')
if __name__ == "__main__":
g = godaddy()
#g.checkTicketId("DCU000001912")
#g.reportAbuse("PHISHING", "http://www.xxx.com/prueba")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment