32 lines
975 B
Python
32 lines
975 B
Python
import requests
|
|
import urllib3
|
|
import json
|
|
|
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
|
|
s = requests.Session()
|
|
s.verify = False
|
|
|
|
r = s.post('https://14.44.4.1/api/auth/login', json={'username': 'snarf', 'password': 'Katzir476!!!'})
|
|
csrf = r.headers.get('x-csrf-token') or r.cookies.get('csrf_token')
|
|
headers = {'X-CSRF-Token': csrf} if csrf else {}
|
|
|
|
policy_id = "d92c8e87-d76e-4e69-9c19-ab0cdbe82080"
|
|
url = f'https://14.44.4.1/proxy/network/v2/api/site/default/firewall-policies/{policy_id}'
|
|
|
|
# Fetch current policy
|
|
p = s.get(url, headers=headers).json()
|
|
print("Current policy:", p.get('name'), p.get('source', {}).get('ips'))
|
|
|
|
# Add 14.4.4.44
|
|
p['source']['ips'] = ['14.4.4.20', '14.4.4.44']
|
|
|
|
# PUT update
|
|
put_res = s.put(url, json=p, headers=headers)
|
|
print("PUT status:", put_res.status_code)
|
|
if put_res.status_code == 200:
|
|
print("PUT success! New ips:", put_res.json().get('source', {}).get('ips'))
|
|
else:
|
|
print("PUT error:", put_res.text)
|
|
|