From 2664d63ead169ad1db1e1d687f7342eef49bafef Mon Sep 17 00:00:00 2001 From: FIFIFiSKA Date: Sat, 28 Mar 2026 18:26:38 +0300 Subject: [PATCH] added readme --- README.md | 187 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..16a1901 --- /dev/null +++ b/README.md @@ -0,0 +1,187 @@ +# dashcore API + +Базовый префикс: `/api` + +Аутентификация: +- `POST /api/auth/login` — получить токен (ответ: `token`, `token_type=Bearer`, `expires_in`) +- Все маршруты ниже требуют заголовок `Authorization: Bearer ` + +## 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://:/api` + +`POST /api/auth/login` +```bash +curl -s "$BASE/auth/login" \ + -H "Content-Type: application/json" \ + -d '{"username":"admin","password":"secret"}' +``` +Ответ: +```json +{"token":"","token_type":"Bearer","expires_in":3600} +``` + +`GET /api/ip/addr` +```bash +curl -s "$BASE/ip/addr" -H "Authorization: Bearer " +``` +Ответ: +```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 " \ + -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 " +``` +Ответ: +```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 " \ + -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 " +``` +Ответ: +```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 " +``` +Ответ: +```json +{"status":"ok"} +``` + +`POST /api/ip/link/:ifname/down` +```bash +curl -s "$BASE/ip/link/eth0/down" -H "Authorization: Bearer " +``` +Ответ: +```json +{"status":"ok"} +``` + +`POST /api/ip/link/:ifname/mtu` +```bash +curl -s "$BASE/ip/link/eth0/mtu" -H "Authorization: Bearer " \ + -H "Content-Type: application/json" \ + -d '{"mtu":1500}' +``` +Ответ: +```json +{"status":"ok"} +``` + +`GET /api/nft/ruleset` +```bash +curl -s "$BASE/nft/ruleset" -H "Authorization: Bearer " +``` +Ответ (сокращено): +```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 " +``` +Ответ (сокращено): +```json +{"nftables":[{"table":{"family":"inet","name":"filter"}}]} +``` + +`GET /api/nft/chains` +```bash +curl -s "$BASE/nft/chains" -H "Authorization: Bearer " +``` +Ответ (сокращено): +```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 " +``` +Ответ (сокращено): +```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 " \ + -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 " \ + -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 " \ + -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"} +```