5.3 KiB
5.3 KiB
dashcore API
Базовый префикс: /api
Аутентификация:
POST /api/auth/login— получить токен (ответ:token,token_type=Bearer,expires_in)- Все маршруты ниже требуют заголовок
Authorization: Bearer <token>
IP
GET /api/ip/addr— список адресовPOST /api/ip/addr— изменение адресовGET /api/ip/route— список маршрутовPOST /api/ip/route— изменение маршрутовGET /api/ip/link— список интерфейсовPOST /api/ip/link/:ifname/up— поднять интерфейсPOST /api/ip/link/:ifname/down— опустить интерфейсPOST /api/ip/link/:ifname/mtu— изменить MTU
nftables
GET /api/nft/ruleset— полный rulesetGET /api/nft/tables— список таблицGET /api/nft/chains— список цепочекGET /api/nft/rules/:family/:table/:chain— правила в цепочкеPOST /api/nft/table— изменить таблицуPOST /api/nft/chain— изменить цепочкуPOST /api/nft/rule— изменить правило
Примеры
BASE=http://<host>:<port>/api
POST /api/auth/login
curl -s "$BASE/auth/login" \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"secret"}'
Ответ:
{"token":"<jwt>","token_type":"Bearer","expires_in":3600}
GET /api/ip/addr
curl -s "$BASE/ip/addr" -H "Authorization: Bearer <token>"
Ответ:
{"interfaces":[{"name":"lo","index":1,"state":"UP","mac_address":null,"ipv4_addresses":[{"address":"127.0.0.1","prefix_len":8,"scope":"host"}],"ipv6_addresses":[{"address":"::1","prefix_len":128,"scope":"host"}]}]}
POST /api/ip/addr
curl -s "$BASE/ip/addr" -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"action":"add","dev":"eth0","address":"192.168.1.10","prefix_len":24,"family":"inet"}'
Ответ:
{"status":"ok"}
GET /api/ip/route
curl -s "$BASE/ip/route" -H "Authorization: Bearer <token>"
Ответ:
{"routes":[{"destination":"default","gateway":"192.168.1.1","device":"eth0","metric":100,"route_type":"unicast"}]}
POST /api/ip/route
curl -s "$BASE/ip/route" -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"action":"add","destination":"default","gateway":"192.168.1.1","dev":"eth0","metric":100}'
Ответ:
{"status":"ok"}
GET /api/ip/link
curl -s "$BASE/ip/link" -H "Authorization: Bearer <token>"
Ответ:
{"links":[{"index":2,"name":"eth0","state":"UP","mac_address":"aa:bb:cc:dd:ee:ff","mtu":1500,"qdisc":"fq_codel","link_type":"ether"}]}
POST /api/ip/link/:ifname/up
curl -s "$BASE/ip/link/eth0/up" -H "Authorization: Bearer <token>"
Ответ:
{"status":"ok"}
POST /api/ip/link/:ifname/down
curl -s "$BASE/ip/link/eth0/down" -H "Authorization: Bearer <token>"
Ответ:
{"status":"ok"}
POST /api/ip/link/:ifname/mtu
curl -s "$BASE/ip/link/eth0/mtu" -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"mtu":1500}'
Ответ:
{"status":"ok"}
GET /api/nft/ruleset
curl -s "$BASE/nft/ruleset" -H "Authorization: Bearer <token>"
Ответ (сокращено):
{"nftables":[{"metainfo":{"version":"..."}},{"table":{"family":"inet","name":"filter"}},{"chain":{"family":"inet","table":"filter","name":"input"}},{"rule":{"family":"inet","table":"filter","chain":"input","handle":1,"expr":["..."]}}]}
GET /api/nft/tables
curl -s "$BASE/nft/tables" -H "Authorization: Bearer <token>"
Ответ (сокращено):
{"nftables":[{"table":{"family":"inet","name":"filter"}}]}
GET /api/nft/chains
curl -s "$BASE/nft/chains" -H "Authorization: Bearer <token>"
Ответ (сокращено):
{"nftables":[{"chain":{"family":"inet","table":"filter","name":"input","type":"filter","hook":"input","prio":0,"policy":"accept"}}]}
GET /api/nft/rules/:family/:table/:chain
curl -s "$BASE/nft/rules/inet/filter/input" -H "Authorization: Bearer <token>"
Ответ (сокращено):
{"nftables":[{"chain":{"family":"inet","table":"filter","name":"input"}},{"rule":{"family":"inet","table":"filter","chain":"input","handle":1,"expr":["..."]}}]}
POST /api/nft/table
curl -s "$BASE/nft/table" -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"action":"add","family":"inet","table":"filter"}'
Ответ:
{"status":"ok"}
POST /api/nft/chain
curl -s "$BASE/nft/chain" -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"action":"add","family":"inet","table":"filter","chain":"input","type":"filter","hook":"input","priority":0,"policy":"accept"}'
Ответ:
{"status":"ok"}
POST /api/nft/rule
curl -s "$BASE/nft/rule" -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"action":"add","family":"inet","table":"filter","chain":"input","expr":"ip saddr 1.2.3.4 drop"}'
Ответ:
{"status":"ok"}