iFargle / headscale-webui

A simple Headscale web UI for small-scale deployments.
Other
635 stars 60 forks source link

Overview Page Route/Exit counts are incorrect #36

Closed iFargle closed 1 year ago

iFargle commented 1 year ago
#!/bin/python3
import requests

def get_routes(url, api_key):
    response = requests.get(
        str(url)+"/api/v1/routes",
        headers={
            'Accept': 'application/json',
            'Authorization': 'Bearer '+str(api_key)
        }
    )
    return response.json()
routes  = get_routes(url, api_key)

print("|----|----------------------|----------------------|-------|-------|")
print("| ## | HOST (ID)            | ROUTE                | ADV   | ENAB  |")
print("|----|----------------------|----------------------|-------|-------|")
# Just print a table

for route in routes["routes"]:
    id      = str(route["id"]).ljust(2, ' ')
    host    = str(route["machine"]["name"])
    hostid  = str(route["machine"]["id"])
    hosts   = str(host+" ("+hostid+")").ljust(20, ' ')
    rt      = str(route["prefix"]).ljust(20, ' ')
    advert  = str(route["advertised"]).ljust(5, ' ')
    enabled = str(route["enabled"]).ljust(5, ' ')
    print("| "+id+" | "+hosts+" | "+rt+" | "+advert+" | "+enabled+" |")

print("|----|----------------------|----------------------|-------|-------|")

Outputs:

|----|----------------------|----------------------|-------|-------|
| ## | HOST (ID)            | ROUTE                | ADV   | ENAB  |
|----|----------------------|----------------------|-------|-------|
| 1  | nuc-docker01 (1)     | 0.0.0.0/0            | True  | True  |
| 2  | sysctl (13)          | 10.2.0.0/24          | True  | True  |
| 3  | sysctl (13)          | 0.0.0.0/0            | True  | True  |
| 4  | sysctl (13)          | ::/0                 | True  | True  |
| 5  | nuc-docker01 (1)     | 192.168.1.14/32      | True  | True  |
| 6  | nuc-docker01 (1)     | ::/0                 | True  | True  |
| 7  | nuc-docker01 (1)     | 192.168.1.0/24       | True  | False |
| 8  | nuc-docker01 (1)     | 192.168.1.13/32      | True  | True  |
| 9  | japan-rpi4 (50)      | 0.0.0.0/0            | True  | True  |
| 10 | japan-rpi4 (50)      | ::/0                 | True  | True  |
| 11 | quitman-rpi4 (49)    | 0.0.0.0/0            | True  | True  |
| 12 | quitman-rpi4 (49)    | ::/0                 | True  | True  |
| 13 | quitman-rpi4 (49)    | 192.168.1.0/24       | True  | False |
| 14 | quitman-rpi4 (49)    | 192.168.68.0/24      | True  | True  |
| 15 | piaware-rpi4 (46)    | 0.0.0.0/0            | True  | True  |
| 16 | piaware-rpi4 (46)    | ::/0                 | True  | True  |
| 17 |  (0)                 | 0.0.0.0/0            | False | False |
| 18 |  (0)                 | ::/0                 | False | False |
| 19 |  (0)                 | 0.0.0.0/0            | True  | True  |
| 20 |  (0)                 | ::/0                 | True  | True  |
| 21 |  (0)                 | 0.0.0.0/0            | True  | False |
| 22 |  (0)                 | ::/0                 | True  | False |
|----|----------------------|----------------------|-------|-------|

I don't know why there are blank routes. Previously deleted machines still have active routes?

iFargle commented 1 year ago

lol, using Headscales CLI confirms this:

[root@sysctl ~]# de headscale headscale  routes list
ID | Machine      | Prefix          | Advertised | Enabled | Primary
1  | nuc-docker01 | 0.0.0.0/0       | true       | true    | -
2  | sysctl       | 10.2.0.0/24     | true       | true    | true
3  | sysctl       | 0.0.0.0/0       | true       | true    | -
4  | sysctl       | ::/0            | true       | true    | -
5  | nuc-docker01 | 192.168.1.14/32 | true       | true    | true
6  | nuc-docker01 | ::/0            | true       | true    | -
7  | nuc-docker01 | 192.168.1.0/24  | true       | false   | false
8  | nuc-docker01 | 192.168.1.13/32 | true       | true    | true
9  | japan-rpi4   | 0.0.0.0/0       | true       | true    | -
10 | japan-rpi4   | ::/0            | true       | true    | -
11 | quitman-rpi4 | 0.0.0.0/0       | true       | true    | -
12 | quitman-rpi4 | ::/0            | true       | true    | -
13 | quitman-rpi4 | 192.168.1.0/24  | true       | false   | false
14 | quitman-rpi4 | 192.168.68.0/24 | true       | true    | true
15 | piaware-rpi4 | 0.0.0.0/0       | true       | true    | -
16 | piaware-rpi4 | ::/0            | true       | true    | -
17 |              | 0.0.0.0/0       | false      | false   | -
18 |              | ::/0            | false      | false   | -
19 |              | 0.0.0.0/0       | true       | true    | -
20 |              | ::/0            | true       | true    | -
21 |              | 0.0.0.0/0       | true       | false   | -
22 |              | ::/0            | true       | false   | -
iFargle commented 1 year ago

https://github.com/juanfont/headscale/issues/1228