Skip to content

ui.about_view

ui.about_view

About view rendering for the TapMap UI.

Build the About modal content from application metadata and cached runtime information.

kv_table(rows)

Build a two column key/value table with tooltips.

Source code in ui/tables.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def kv_table(rows: Iterable[tuple[str, str]]) -> html.Table:
    """Build a two column key/value table with tooltips."""
    body: list[Any] = []
    for key, value in rows:
        v = "" if value is None else str(value)
        body.append(
            html.Tr(
                [
                    html.Td(key),
                    html.Td(html.Span(v, title=v if v else None)),
                ]
            )
        )

    colgroup = html.Colgroup(
        [
            html.Col(style={"width": "180px"}),
            html.Col(),
        ]
    )

    return html.Table(
        className="mx-table mx-info-table",
        children=[colgroup, html.Tbody(body)],
    )

render_about(*, app_name, app_version, app_author, snapshot=None, is_docker)

Render About view content.

Read snapshot["app_info"] only and avoid network calls.

Source code in ui/about_view.py
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
def render_about(
    *,
    app_name: str,
    app_version: str,
    app_author: str,
    snapshot: Any | None = None,
    is_docker: bool,
) -> list[Any]:
    """Render About view content.

    Read snapshot["app_info"] only and avoid network calls.
    """
    app_info: dict[str, Any] = {}
    if isinstance(snapshot, dict):
        info = snapshot.get("app_info")
        if isinstance(info, dict):
            app_info = info

    server_port = app_info.get("server_port")
    poll_ms = app_info.get("poll_interval_ms")
    coord_precision = app_info.get("coord_precision")
    near_km = app_info.get("zoom_near_km")

    geoinfo_enabled = bool(app_info.get("geoinfo_enabled", False))
    geo_data_dir_val = app_info.get("geo_data_dir")
    geo_data_dir = geo_data_dir_val if isinstance(geo_data_dir_val, str) else ""

    myloc_mode_val = app_info.get("myloc_mode")
    myloc_mode = myloc_mode_val if isinstance(myloc_mode_val, str) else "OFF"
    my_location = app_info.get("my_location")

    public_ip_cached = app_info.get("public_ip_cached")
    public_ip_cached = (
        public_ip_cached if isinstance(public_ip_cached, str) and public_ip_cached else None
    )

    auto_geo_cached = app_info.get("auto_geo_cached")
    auto_geo = auto_geo_cached if isinstance(auto_geo_cached, dict) else {}

    os_text = app_info.get("os") if isinstance(app_info.get("os"), str) else "-"
    py_text = app_info.get("python") if isinstance(app_info.get("python"), str) else "-"

    net_backend_val = app_info.get("net_backend")
    net_backend = net_backend_val if isinstance(net_backend_val, str) else "-"
    net_backend_version_val = app_info.get("net_backend_version")
    net_backend_version = (
        net_backend_version_val if isinstance(net_backend_version_val, str) else "-"
    )

    tapmap_rows: list[tuple[str, str]] = [
        ("Name", app_name),
        ("Version", app_version),
        ("Author", app_author),
        ("Server port", str(server_port) if isinstance(server_port, int) else "-"),
        ("Poll interval", f"{poll_ms} ms" if isinstance(poll_ms, int) else "-"),
        ("Coord precision", str(coord_precision) if coord_precision is not None else "-"),
        ("Near distance", f"{near_km} km" if isinstance(near_km, (int, float)) else "-"),
    ]

    geo_rows: list[tuple[str, str]] = [
        ("Geolocation", "Enabled" if geoinfo_enabled else "Disabled"),
        ("GeoIP data folder", geo_data_dir if geo_data_dir else "-"),
    ]

    location_rows = _build_location_rows(
        myloc_mode=myloc_mode,
        my_location=my_location,
        public_ip_cached=public_ip_cached,
        auto_geo=auto_geo,
    )

    runtime_rows: list[tuple[str, str]] = [
        ("OS", os_text),
        ("Python", py_text),
        ("Network backend", net_backend),
        ("Backend version", net_backend_version),
    ]

    return [
        html.H1(f"About {app_name}"),
        html.P(
            "TapMap inspects local socket data, enriches IP addresses "
            "with geolocation, and visualizes their locations on an interactive map."
        ),
        html.P(
            "It reads active socket data using a platform-specific backend, "
            "local MaxMind GeoLite2 databases for geolocation, "
            "and Dash with Plotly for visualization."
        ),
        html.P("All processing is local. TapMap does not inspect traffic contents."),
        kv_table(tapmap_rows),
        html.H2("Geolocation"),
        html.P(
            "Geolocation is based on local MaxMind GeoLite2 .mmdb databases. "
            "The databases are not included."
        ),
        kv_table(geo_rows),
        html.Div(
            className="mx-path-row",
            children=[
                html.Pre(geo_data_dir, className="mx-path-box") if geo_data_dir else None,
                *(
                    []
                    if is_docker
                    else [
                        html.Button(
                            "Open data folder",
                            id="btn_open_data",
                            n_clicks=0,
                            className="mx-btn mx-btn--primary mx-btn--nowrap",
                            type="button",
                        )
                    ]
                ),
                html.Button(
                    "Recheck GeoIP databases",
                    id="btn_check_databases",
                    n_clicks=0,
                    className="mx-btn mx-btn--primary mx-btn--nowrap",
                    type="button",
                ),
            ],
        ),
        *(
            [
                html.P(
                    "Running in Docker. Place the GeoLite2 .mmdb files in the "
                    "host folder mounted to this path.",
                    className="mx-note",
                )
            ]
            if is_docker
            else []
        ),
        html.H2("Location"),
        kv_table(location_rows),
        html.H2("Runtime"),
        kv_table(runtime_rows),
        html.H2("Project"),
        html.P("TapMap is free and open source."),
        html.Ul(
            [
                html.Li(
                    html.A(
                        "Project page on GitHub",
                        href="https://github.com/olalie/tapmap",
                        target="_blank",
                        rel="noopener noreferrer",
                    )
                ),
                html.Li(
                    html.A(
                        "MaxMind GeoLite2 project",
                        href="https://dev.maxmind.com/geoip/geolite2-free-geolocation-data",
                        target="_blank",
                        rel="noopener noreferrer",
                    )
                ),
                html.Li(
                    html.A(
                        "Buy Me a Coffee",
                        href="https://www.buymeacoffee.com/olalie",
                        target="_blank",
                        rel="noopener noreferrer",
                    )
                ),
            ]
        ),
    ]

_build_location_rows(*, myloc_mode, my_location, public_ip_cached, auto_geo)

Build Location section rows for MY_LOCATION mode.

Source code in ui/about_view.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def _build_location_rows(
    *,
    myloc_mode: str,
    my_location: Any,
    public_ip_cached: str | None,
    auto_geo: dict[str, Any],
) -> list[tuple[str, str]]:
    """Build Location section rows for MY_LOCATION mode."""
    if myloc_mode == "OFF":
        return [("MY_LOCATION", "none (local marker hidden)")]

    if myloc_mode == "FIXED":
        if isinstance(my_location, (list, tuple)) and len(my_location) == 2:
            lon, lat = my_location[0], my_location[1]
            return [("MY_LOCATION", _fmt_coord(lon, lat))]
        return [("MY_LOCATION", "fixed (invalid value)")]

    rows: list[tuple[str, str]] = [("MY_LOCATION", "auto")]
    rows.append(("Public IP", public_ip_cached or "-"))

    if myloc_mode == "AUTO":
        place = _fmt_place(auto_geo.get("city"), auto_geo.get("country"))
        coord = _fmt_coord(auto_geo.get("lon"), auto_geo.get("lat"))
        rows.append(("AUTO place", place))
        rows.append(("AUTO coordinate", coord))
        return rows

    rows.append(("AUTO geo", "not available"))
    return rows

_fmt_coord(lon, lat)

Format lon/lat coordinates for UI display.

Source code in ui/about_view.py
218
219
220
221
222
def _fmt_coord(lon: Any, lat: Any) -> str:
    """Format lon/lat coordinates for UI display."""
    if isinstance(lon, (int, float)) and isinstance(lat, (int, float)):
        return f"{float(lon)}, {float(lat)}"
    return "-"

_fmt_place(city, country)

Format city/country place for UI display.

Source code in ui/about_view.py
225
226
227
228
229
230
231
232
233
def _fmt_place(city: Any, country: Any) -> str:
    """Format city/country place for UI display."""
    c = city.strip() if isinstance(city, str) else ""
    k = country.strip() if isinstance(country, str) else ""
    if c and k:
        return f"{c}, {k}"
    if k:
        return k
    return "-"