1
German - Deutsch / Re: Route via Api erstellen
« on: May 19, 2018, 10:09:09 pm »
Danke! Problem gelöst, siehe https://forum.opnsense.org/index.php?topic=8718.msg38810#msg38810
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
import json
import requests
apikey = 'xxx'
apisecret = 'xxx'
url = 'https://10.0.0.254/api/routes/routes/addroute'
payload = '{"route":{"descr":"vlan40","disabled":"0","gateway":"VLAN_GW","network":"10.0.40.0/24"}}'
res = requests.post(url, data=payload, verify=None, auth=(apikey, apisecret))
print(res)
print(json.loads(res.text))
<Response [200]>
{'result': 'failed'}
# cat /tmp/gateway_list.json
{"WAN_DHCP":"WAN_DHCP - 192.168.107.2","VLAN_GW":"VLAN_GW - 10.0.0.253","Null4":"Null4 - 127.0.0.1","Null6":"Null6 - ::1"}
>>> json.loads(request.text)
{'result': 'failed'}
payload = '{"route": {"descr": "vlan40", "disabled": "0", "gateway" : "VLAN_GW", "network": "10.0.40.0/24"}}'
verwende, bekomme ich nur <Response [200]>
zurück. Nichts weiter. Route wird nicht angelegt.<Response [200]>
as feedback and the route does not show up in the ui. apikey = 'xxx'
apisecret = 'xxx'
url = 'https://10.0.0.254/api/routes/routes/addroute'
requests.post(url, data=payload, verify=None, auth=(apikey, apisecret))
{'route': {'network': '10.0.50.0/24', 'gateway': {'Null4': {'value': 'Null4 - 127.0.0.1', 'selected': 0}, 'Null6': {'value': 'Null6 - ::1', 'selected': 0}, 'VLAN_GW': {'value': 'VLAN_GW - 10.0.0.253', 'selected': 1}, 'WAN_DHCP': {'value': 'WAN_DHCP - 192.168.107.2', 'selected': 0}}, 'descr': 'vlan50', 'disabled': '0'}}
{"errorMessage":"Error at /usr/local/opnsense/mvc/app/models/OPNsense/Routes/Route.php:59 - Undefined index: (errno=8)"}
/api/routes/routes/setroute/<uuid>
mit dem identischen Payload eine existierende Route erfolgreich ändern./api/routes/routes/getroute
ohne uuid zurückliefert.apikey = 'xxx'
apisecret = 'xxx'
url = 'https://10.0.0.254/api/routes/routes/addroute'
requests.post(url, data=payload, verify=None, auth=(apikey, apisecret))
{'route': {'network': '10.0.50.0/24', 'gateway': {'Null4': {'value': 'Null4 - 127.0.0.1', 'selected': 0}, 'Null6': {'value': 'Null6 - ::1', 'selected': 0}, 'VLAN_GW': {'value': 'VLAN_GW - 10.0.0.253', 'selected': 1}, 'WAN_DHCP': {'value': 'WAN_DHCP - 192.168.107.2', 'selected': 0}}, 'descr': 'vlan50', 'disabled': '0'}}
{"errorMessage":"Error at /usr/local/opnsense/mvc/app/models/OPNsense/Routes/Route.php:59 - Undefined index: (errno=8)"}
/api/routes/routes/setroute/<uuid>
with the same payload.getroute
and was modified accordingly.