Create or rotate a trusted-device token for (username, fp). Returns raw token.
(username: str, fp: str, approved_by: Optional[str]=None)
| 1420 | def _handle_unexpected_web_error(error): |
| 1421 | """Log full web exceptions to the file and the Termux error monitor.""" |
| 1422 | if isinstance(error, HTTPException): |
| 1423 | return error |
| 1424 | try: |
| 1425 | request_id = getattr(g, "request_id", "-") |
| 1426 | method = getattr(request, "method", "?") |
| 1427 | path = getattr(request, "path", "?") |
| 1428 | log.error( |
| 1429 | "Unhandled web exception request_id=%s method=%s path=%s error=%s", |
| 1430 | request_id, method, path, error, |
| 1431 | exc_info=(type(error), error, error.__traceback__), |
| 1432 | ) |
| 1433 | except Exception: |
| 1434 | traceback.print_exc() |
| 1435 | return Response( |
| 1436 | "Internal Server Error\n\nThe complete error was printed in Termux below the generated links and saved to the ButSystem log.", |
| 1437 | status=500, |
| 1438 | mimetype="text/plain", |
| 1439 | ) |
| 1440 | # Respect X-Forwarded-* headers when running behind Cloudflared / reverse proxies. |
| 1441 | # This helps correct URL generation (scheme/host) and client IP for security logs. |
| 1442 | # Only trust X-Forwarded-* when the direct peer is loopback (cloudflared/tor connect locally). |
| 1443 | class _LoopbackProxyFix: |
| 1444 | def __init__(self, wsgi_app): |
no test coverage detected