-
Notifications
You must be signed in to change notification settings - Fork 0
/
cracksh.py
96 lines (79 loc) · 3.35 KB
/
cracksh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# -*- coding: utf -*-
from errbot import BotPlugin, arg_botcmd
import argparse
import requests
class CrackSh(BotPlugin):
""" Interface for https://crack.sh API """
def get_configuration_template(self):
""" Configuration entries """
config = {
'email': '',
'customer_id': '',
'api_url': 'https://crack.sh/api'
}
return config
def _check_config(self, option):
""" Check for option in config """
if self.config is None:
return None
else:
if option in self.config:
return self.config[option]
else:
return None
@arg_botcmd('token', type=str, help="Token to submit", template="cracksh_submit")
@arg_botcmd('format', type=str, help="Format of token", template="cracksh_submit")
@arg_botcmd('--customerid', dest='customer_id', type=str, default=None, help="Customer ID", template="cracksh_submit")
@arg_botcmd('--email', dest='email', type=str, default=None, help="Email for updates", template="cracksh_submit")
@arg_botcmd('--asap', dest='asap', type=int, default=0, help="Whether to rush a job", template="cracksh_submit")
def cracksh_submit(self, msg, format=None, token=None, customer_id=None, email=None, asap=None):
""" Submit a token to https://crack.sh
Examples:
!cracksh submit [format] [sometoken]
!cracksh submit --email someone@somewhere.net [format] [sometoken]
!cracksh submit --customerid lucas --asap 1 [format] [sometoken]
"""
sess = requests.Session()
head = {}
url = self._check_config('api_url')
payload = {'token': format + ':' + token, 'asap': asap}
# Check for customer_id override
if customer_id != None:
payload['customer_id'] = customer_id
elif self.config['customer_id'] != '':
payload['customer_id'] = self.config['customer_id']
# Check for email override
if email != None:
payload['email'] = email
elif self.config['email'] != '':
payload['email'] = self.config['email']
try:
response = sess.post(url, headers=head, data=payload, timeout=30)
self.log.debug('URL sent: {}'.format(url))
except Exception as e:
self.log.debug(e)
self.check_response(response)
return {'subresp': response.json()}
@arg_botcmd('reference', type=str, help="Reference ID", template="cracksh_status")
def cracksh_status(self, msg, reference=None):
""" Check the status of a submitted job
Examples:
!cracksh status [reference]
"""
sess = requests.Session()
head = {}
url = self._check_config('api_url')
payload = {'reference': reference}
try:
response = sess.get(url, headers=head, params=payload, timeout=30)
self.log.debug('URL sent: {}'.format(url))
except Exception as e:
self.log.debug(e)
self.check_response(response)
return {'statresp': response.json()}
@staticmethod
def check_response(response):
if response.status_code != 200:
raise ValueError(
'Request to API returned an error {0}, the response is: {1}'.format(response.status_code, response.text)
)