111 lines
2.7 KiB
Python
111 lines
2.7 KiB
Python
import json
|
|
import requests
|
|
|
|
def get_session():
|
|
login_data = {'username':"admin","password":"admin"}
|
|
inf_s = requests.Session()
|
|
inf_s.post('http://10.30.1.138:5000/login', login_data)
|
|
|
|
return inf_s
|
|
|
|
def req_edit_state(id, state):
|
|
inf_s = get_session()
|
|
|
|
if state == "false":
|
|
state = False
|
|
|
|
if state == "true":
|
|
state = True
|
|
|
|
req_val = {"id":id,"status":state}
|
|
req_val = json.dumps(req_val)
|
|
|
|
print("Req Val --> ", req_val)
|
|
|
|
req = inf_s.post('http://10.30.1.138:5000/client/set-status', req_val)
|
|
|
|
print(req)
|
|
|
|
def req_edit_user(id):
|
|
inf_s = get_session()
|
|
req_val = id
|
|
req_url = 'http://10.30.1.138:5000/api/client/'+req_val
|
|
|
|
req = inf_s.get(req_url)
|
|
|
|
print("-->")
|
|
print(req)
|
|
|
|
# req = json.loads(req)
|
|
|
|
return req.json()
|
|
|
|
def req_apply_sys():
|
|
inf_s = get_session()
|
|
# http://10.30.1.138:5000/api/apply-wg-config?_=1669872830286
|
|
req_url = 'http://10.30.1.138:5000/api/apply-wg-config'
|
|
|
|
req = inf_s.get(req_url)
|
|
|
|
print("-->")
|
|
print(req)
|
|
|
|
return req
|
|
|
|
#
|
|
# http://10.30.1.138:5000/api/client/caivc1vekn84im2m6ec0?_=1669623393468
|
|
|
|
def req_ip_recommendation():
|
|
# Write your own ip recommendation next time
|
|
# http://10.30.1.138:5000/api/suggest-client-ips
|
|
|
|
inf_s = get_session()
|
|
req_url = 'http://10.30.1.138:5000/api/suggest-client-ips'
|
|
|
|
req = inf_s.get(req_url)
|
|
req = req.json()
|
|
|
|
req_dump = {}
|
|
req_dump["allocated_ips"] = {}
|
|
req_dump["allowed_ips"] = {"OAM":"10.30.1.0/24", "NEW_OAM":"192.168.200.0/24", "WG Nodes":"192.168.100.0/24"}
|
|
|
|
i = 0
|
|
|
|
tmp_array = []
|
|
for x in req:
|
|
print(x)
|
|
tmp_array.append(x)
|
|
i = i+1
|
|
|
|
req_dump["allocated_ips"] = tmp_array
|
|
print(req)
|
|
print(req_dump)
|
|
|
|
return json.dumps(req_dump)
|
|
|
|
def reg_bulk(data):
|
|
|
|
inf_s = get_session()
|
|
req_url = 'http://10.30.1.138:5000/api/new-client'
|
|
|
|
# req = inf_s.post(req_url, req_val)
|
|
|
|
|
|
for x in data:
|
|
|
|
uname = x[0]
|
|
email = x[1]
|
|
code = x[2]
|
|
org = x[3]
|
|
|
|
data = {"name":uname,"email":email,"code":code,"org":org}
|
|
# data = {"name":uname,"email":email,"allocated_ips":suggest_ips,"allowed_ips":allowed_ips,"extra_allowed_ips":[],"use_server_dns":true,"enabled":true,"preshared_key":true}
|
|
|
|
print(data)
|
|
|
|
|
|
# ret_reg=$(curl -s --location --request POST 'http://10.30.1.138:5000/new-client' \
|
|
# --header 'Content-Type: application/json' \
|
|
# --cookie .tmp-cookie \
|
|
# --data-raw '{"name":"'$uname'","email":"'$email'","allocated_ips":'$suggest_ips',"allowed_ips":["10.0.0.0/8", "192.168.100.0/24"],"extra_allowed_ips":[],"use_server_dns":true,"enabled":true,"preshared_key":true}' )
|