-
Notifications
You must be signed in to change notification settings - Fork 0
/
webfox.py
executable file
·70 lines (56 loc) · 1.43 KB
/
webfox.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
from random import randint
import requests
from os import environ
logging.basicConfig()
LOG = logging.getLogger(__name__)
LOG.setLevel(logging.DEBUG)
API_KEY = environ['CTFTOKEN']
if not API_KEY:
raise ValueError("Error, env var: '{}' not set".format('CTFTOKEN'))
BASE_URL = environ.get('BASE_URL')
if not BASE_URL:
raise ValueError("Error, env var: '{}' not set".format('BASE_URL'))
URL_POST_ADD_FOX = '{}/add_fox'.format(BASE_URL)
URL_POST_UPDATE_FOX = '{}/update_fox'.format(BASE_URL)
URL_POST_UPDATE_FOX = '{}/update_fox'.format(BASE_URL)
URL_POST_DELETE_FOX = '{}/delete_fox'.format(BASE_URL)
URL_GET_FOXES = '{}/foxes'.format(BASE_URL)
HEADER = {
'CTFTOKEN': API_KEY,
'Content-Type': 'application/json',
}
def mod_fox(dval):
r = requests.post(
URL_POST_UPDATE_FOX,
json=dval,
headers=HEADER,
)
return r.json()
def add_fox(dval):
r = requests.post(
URL_POST_ADD_FOX,
json=dval,
headers=HEADER,
)
return r.json()
def get_foxes():
r = requests.get(
URL_GET_FOXES,
headers=HEADER,
)
return r.json()
def delete_fox(dval):
r = requests.post(
URL_POST_DELETE_FOX,
json=dval,
headers=HEADER,
)
return r.json()
def gen_mac_address():
return ":".join([
str('{:02x}'.format(randint(1, 254)))
for i in range(6)
])