init
Browse files- app.py +26 -0
- templates/index.html +7 -0
app.py
CHANGED
|
@@ -40,6 +40,32 @@ def get_ngrok_tunnels():
|
|
| 40 |
|
| 41 |
return endpoints
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
@app.get("/", response_class=HTMLResponse)
|
| 44 |
async def read_root(request: Request):
|
| 45 |
endpoints = get_ngrok_tunnels()
|
|
|
|
| 40 |
|
| 41 |
return endpoints
|
| 42 |
|
| 43 |
+
def get_ngrok_usage():
|
| 44 |
+
api_key = os.getenv("NGROK_API_KEY")
|
| 45 |
+
if not api_key:
|
| 46 |
+
raise HTTPException(status_code=500, detail="Ngrok API key not found.")
|
| 47 |
+
|
| 48 |
+
headers = {
|
| 49 |
+
"Authorization": f"Bearer {api_key}",
|
| 50 |
+
"Ngrok-Version": "2"
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
try:
|
| 54 |
+
response = requests.get("https://api.ngrok.com/account", headers=headers)
|
| 55 |
+
response.raise_for_status()
|
| 56 |
+
except requests.RequestException as e:
|
| 57 |
+
raise HTTPException(status_code=500, detail=str(e))
|
| 58 |
+
|
| 59 |
+
account_data = response.json()
|
| 60 |
+
usage = account_data.get("usage", {})
|
| 61 |
+
|
| 62 |
+
return {
|
| 63 |
+
"month_start": usage.get("month_start"),
|
| 64 |
+
"month_end": usage.get("month_end"),
|
| 65 |
+
"total": usage.get("total"),
|
| 66 |
+
"used": usage.get("used")
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
@app.get("/", response_class=HTMLResponse)
|
| 70 |
async def read_root(request: Request):
|
| 71 |
endpoints = get_ngrok_tunnels()
|
templates/index.html
CHANGED
|
@@ -92,6 +92,13 @@
|
|
| 92 |
</div>
|
| 93 |
</div>
|
| 94 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
<!-- Notification -->
|
| 97 |
<div id="notification"
|
|
|
|
| 92 |
</div>
|
| 93 |
</div>
|
| 94 |
</div>
|
| 95 |
+
|
| 96 |
+
<h2>Account Usage</h2>
|
| 97 |
+
<div class="usage">
|
| 98 |
+
<p>Used: {{ usage.used }} / Total: {{ usage.total }}</p>
|
| 99 |
+
<p>Remaining: {{ usage.total - usage.used }}</p>
|
| 100 |
+
<p>Percentage Used: {{ (usage.used / usage.total) * 100 }}%</p>
|
| 101 |
+
</div>
|
| 102 |
|
| 103 |
<!-- Notification -->
|
| 104 |
<div id="notification"
|