-
Notifications
You must be signed in to change notification settings - Fork 0
/
sxp-admin.py
89 lines (65 loc) · 2.86 KB
/
sxp-admin.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
import json
import sys
import urllib3
import requests
import datetime
from urllib3.exceptions import InsecureRequestWarning
from config import TOKEN, SERVER
urllib3.disable_warnings(InsecureRequestWarning) # disable insecure https warnings
# find_obj_in_acl find object id in access-list containing SGT
def find_acl_sgt(sgt, server, interface):
return_data = []
raw_data = get_acls(server, interface)
data = raw_data['items']
for i in data:
if 'srcSecurity' in i or 'dstSecurity' in i:
if sgt == (i['srcSecurity']['value'] or i['srcSecurity']['value']):
return_data.append(i['objectId'])
return return_data
# get_acls function returns access-lists on a interface. ObjectID is optional to get one specific ACL."""
def get_acls(server, interface, object_id=""):
header = {'content-type': 'application/json', 'User-agent': 'REST API Agent', 'X-Auth-Token': TOKEN}
url = server + "/api/access/in/" + interface + "/rules/" + object_id
response = requests.get(url, headers=header, verify=False)
json_data = response.json()
#print(json.dumps(json_data, indent=2))
return json_data
# Enables a line in the access-list, given obecjtId and interfacename.
def enable_acl(server, object_id, interface):
req = urllib3.PoolManager()
header = {'content-type': 'application/json', 'User-agent': 'REST API Agent', 'X-Auth-Token': TOKEN}
payload = {"active" : True}
url = server + "/api/access/in/" + interface + "/rules/" + object_id
requests.patch(url, headers=header, data=json.dumps(payload), verify=False)
# Disables a line in the access-list, given objectId and interface name.
def disable_acl(server, object_id, interface):
req = urllib3.PoolManager()
header = {'content-type': 'application/json', 'User-agent': 'REST API Agent', 'X-Auth-Token': TOKEN}
print(object_id)
payload = {"active": False}
url = server + "/api/access/in/" + interface + "/rules/" + object_id
requests.patch(url, headers=header, data=json.dumps(payload), verify=False)
# adds time in minutes to now and return ASA timerange command
def timeadder(time):
now = datetime.datetime.now()
then = now + datetime.timedelta(minutes=time)
when = then.strftime("%H:%M %B %d %Y")
return when
def update_timerange(server, timeobject, time):
header = {'content-type': 'application/json', 'User-agent': 'REST API Agent', 'X-Auth-Token': TOKEN}
payload = {"value": {"start": "now", "end": timeadder(time)}}
url = server + "/api/objects/timeranges/" + timeobject
requests.patch(url, headers=header, data=json.dumps(payload), verify=False)
def main():
print("Starting")
#getACLS(SERVER,"LAN","2605530362")
#enableACL(SERVER,"2605530362","LAN")
#disableACL(SERVER,"2605530362","LAN")
#getACLS(SERVER,"LAN","2605530362")
#get_acls(SERVER, "LAN")
#list = find_acl_sgt("Linda", SERVER, "LAN")
#for i in list:
# enable_acl(SERVER, i, "LAN")
update_timerange(SERVER, "Bo", 2)
if __name__ == '__main__':
main()