added readme

This commit is contained in:
2026-03-28 18:26:38 +03:00
parent 52337e390d
commit 2664d63ead

187
README.md Normal file
View File

@@ -0,0 +1,187 @@
# 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` — полный ruleset
- `GET /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`
```bash
curl -s "$BASE/auth/login" \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"secret"}'
```
Ответ:
```json
{"token":"<jwt>","token_type":"Bearer","expires_in":3600}
```
`GET /api/ip/addr`
```bash
curl -s "$BASE/ip/addr" -H "Authorization: Bearer <token>"
```
Ответ:
```json
{"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`
```bash
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"}'
```
Ответ:
```json
{"status":"ok"}
```
`GET /api/ip/route`
```bash
curl -s "$BASE/ip/route" -H "Authorization: Bearer <token>"
```
Ответ:
```json
{"routes":[{"destination":"default","gateway":"192.168.1.1","device":"eth0","metric":100,"route_type":"unicast"}]}
```
`POST /api/ip/route`
```bash
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}'
```
Ответ:
```json
{"status":"ok"}
```
`GET /api/ip/link`
```bash
curl -s "$BASE/ip/link" -H "Authorization: Bearer <token>"
```
Ответ:
```json
{"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`
```bash
curl -s "$BASE/ip/link/eth0/up" -H "Authorization: Bearer <token>"
```
Ответ:
```json
{"status":"ok"}
```
`POST /api/ip/link/:ifname/down`
```bash
curl -s "$BASE/ip/link/eth0/down" -H "Authorization: Bearer <token>"
```
Ответ:
```json
{"status":"ok"}
```
`POST /api/ip/link/:ifname/mtu`
```bash
curl -s "$BASE/ip/link/eth0/mtu" -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"mtu":1500}'
```
Ответ:
```json
{"status":"ok"}
```
`GET /api/nft/ruleset`
```bash
curl -s "$BASE/nft/ruleset" -H "Authorization: Bearer <token>"
```
Ответ (сокращено):
```json
{"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`
```bash
curl -s "$BASE/nft/tables" -H "Authorization: Bearer <token>"
```
Ответ (сокращено):
```json
{"nftables":[{"table":{"family":"inet","name":"filter"}}]}
```
`GET /api/nft/chains`
```bash
curl -s "$BASE/nft/chains" -H "Authorization: Bearer <token>"
```
Ответ (сокращено):
```json
{"nftables":[{"chain":{"family":"inet","table":"filter","name":"input","type":"filter","hook":"input","prio":0,"policy":"accept"}}]}
```
`GET /api/nft/rules/:family/:table/:chain`
```bash
curl -s "$BASE/nft/rules/inet/filter/input" -H "Authorization: Bearer <token>"
```
Ответ (сокращено):
```json
{"nftables":[{"chain":{"family":"inet","table":"filter","name":"input"}},{"rule":{"family":"inet","table":"filter","chain":"input","handle":1,"expr":["..."]}}]}
```
`POST /api/nft/table`
```bash
curl -s "$BASE/nft/table" -H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"action":"add","family":"inet","table":"filter"}'
```
Ответ:
```json
{"status":"ok"}
```
`POST /api/nft/chain`
```bash
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"}'
```
Ответ:
```json
{"status":"ok"}
```
`POST /api/nft/rule`
```bash
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"}'
```
Ответ:
```json
{"status":"ok"}
```