Add dedicated-IP tier: IPRoyal DC/ISP reseller API, location picker, auto-provisioning

This commit is contained in:
drjones
2026-09-19 18:26:21 -07:00
parent 9d084373dc
commit 739921955e
9 changed files with 377 additions and 4 deletions

139
app.py
View File

@@ -12,6 +12,7 @@ from flask import (Flask, abort, flash, jsonify, redirect, render_template,
request, session, url_for)
import db
import iproyal
CFG = db.CFG
app = Flask(__name__)
@@ -23,6 +24,14 @@ SITE_HOST = CFG.get("site_host", "clean-proxys.thetempleofdoom.com")
PRICE_USD_PER_GB = CFG.get("price_usd_per_gb", 8.0) # display only
# Dedicated IP catalog: product_id -> {name, plans: {days: (iproyal_plan_id, price_sats)}}
DEDICATED_PRODUCTS = {
3: {"name": "Datacenter Dedicated", "desc": "Static datacenter IP — budget tier",
"plans": {30: (5, 10000), 60: (26, 20000), 90: (27, 30000)}},
9: {"name": "ISP Dedicated", "desc": "Clean residential-ISP IP — premium tier",
"plans": {30: (22, 22000), 60: (24, 44000), 90: (25, 66000)}},
}
# ---------- auth ----------
def current_user():
@@ -46,7 +55,7 @@ def login_required(f):
# ---------- BTCPay ----------
def create_invoice(amount_sats, order_id):
def create_invoice(amount_sats, order_id, meta=None):
data = {
"amount": amount_sats / 1e8,
"currency": "BTC",
@@ -56,6 +65,8 @@ def create_invoice(amount_sats, order_id):
},
"metadata": {"orderId": order_id},
}
if meta:
data["metadata"].update(meta)
r = requests.post(
f"{BTCPAY['url']}/api/v1/stores/{BTCPAY['store_id']}/invoices",
headers={"Authorization": f"token {BTCPAY['api_key']}"},
@@ -178,9 +189,28 @@ def webhook_btcpay():
if payload.get("type") not in ("InvoiceSettled", "InvoiceProcessing"):
return "ok"
order_id = (payload.get("metadata") or {}).get("orderId")
kind = (payload.get("metadata") or {}).get("kind")
if not order_id:
return "ok"
d = db.get_db()
if kind == "dedicated":
row = d.execute("SELECT * FROM dedicated_ips WHERE invoice_id=? AND status='pending_payment'",
(order_id,)).fetchone()
if row:
try:
plan_id = DEDICATED_PRODUCTS[row["product_id"]]["plans"][row["plan_days"]][0]
o = iproyal.create_order(row["product_id"], plan_id, row["location_id"], 1)
oid = o.get("id") or o.get("order_id") or (o.get("data") or {}).get("id")
d.execute("UPDATE dedicated_ips SET status='provisioning', iproyal_order_id=? WHERE id=?",
(oid, row["id"]))
d.commit()
app.logger.info("dedicated IPRoyal order %s created for dedicated_ips #%s", oid, row["id"])
except Exception as e:
app.logger.error("dedicated order failed: %s", e)
d.execute("UPDATE dedicated_ips SET status='failed' WHERE id=?", (row["id"],))
d.commit()
d.close()
return "ok"
o = d.execute("SELECT * FROM orders WHERE invoice_id=?", (order_id,)).fetchone()
if o and o["status"] != "paid":
plan = d.execute("SELECT * FROM plans WHERE id=?", (o["plan_id"],)).fetchone()
@@ -198,11 +228,12 @@ def dashboard():
u = current_user()
d = db.get_db()
used = d.execute("SELECT COALESCE(SUM(bytes),0) s FROM usage_log WHERE user_id=?", (u["id"],)).fetchone()["s"]
deds = [dict(r) for r in d.execute("SELECT * FROM dedicated_ips WHERE user_id=? ORDER BY id DESC", (u["id"],)).fetchall()]
d.close()
socks = f"socks5://{u['username']}:{u['proxy_password_plain']}@{PROXY['host']}:{PROXY['socks_port']}"
http = f"http://{u['username']}:{u['proxy_password_plain']}@{PROXY['host']}:{PROXY['http_port']}"
return render_template("dashboard.html", user=u, used_gb=used / 1e9,
socks=socks, http=http)
socks=socks, http=http, dedicated=deds)
@app.route("/dashboard/location", methods=["POST"])
@@ -236,6 +267,99 @@ def rotate():
return redirect(url_for("dashboard"))
# ---------- dedicated IPs ----------
@app.route("/dedicated")
def dedicated():
dc_locs = isp_locs = []
try:
dc_locs = iproyal.list_locations(3)
isp_locs = iproyal.list_locations(9)
except Exception as e:
flash(f"Location catalog unavailable: {e}", "warn")
return render_template("dedicated.html", products=DEDICATED_PRODUCTS,
dc_locs=dc_locs, isp_locs=isp_locs, user=current_user())
@app.route("/dedicated/locations")
def dedicated_locations():
pid = request.args.get("product", 3, type=int)
try:
return jsonify({"locations": [{"id": i, "name": n, "in_stock": s}
for i, n, s in iproyal.list_locations(pid)]})
except Exception as e:
return jsonify({"error": str(e)}), 502
@app.route("/dedicated/buy", methods=["POST"])
@login_required
def dedicated_buy():
pid = int(request.form.get("product", 3))
days = int(request.form.get("days", 30))
loc_id = int(request.form.get("location_id", 0))
loc_name = request.form.get("location_name", "")
if pid not in DEDICATED_PRODUCTS or days not in DEDICATED_PRODUCTS[pid]["plans"]:
flash("Bad product or duration.", "warn")
return redirect(url_for("dedicated"))
if not loc_id or not loc_name:
flash("Pick a location.", "warn")
return redirect(url_for("dedicated"))
_, price = DEDICATED_PRODUCTS[pid]["plans"][days]
oid = db.random_token(12)
d = db.get_db()
d.execute("INSERT INTO dedicated_ips (user_id,product_id,product_name,plan_days,location_id,"
"location_name,invoice_id,price_sats,status,created_at) VALUES (?,?,?,?,?,?,?,?,?,?)",
(current_user()["id"], pid, DEDICATED_PRODUCTS[pid]["name"], days, loc_id, loc_name,
oid, price, "pending_payment", int(time.time())))
d.commit()
d.close()
inv = create_invoice(price, oid, meta={"kind": "dedicated"})
return redirect(inv["checkoutLink"])
@app.route("/dedicated/poll", methods=["POST"])
def dedicated_poll():
"""Admin/agent hook: poll provisioning for pending dedicated orders."""
ok, failed = poll_provisioning()
return jsonify({"provisioned": ok, "failed": failed})
def poll_provisioning():
"""Check pending IPRoyal orders, move confirmed ones to active. Returns (ok, failed)."""
d = db.get_db()
pending = d.execute("SELECT * FROM dedicated_ips WHERE status IN ('provisioning')").fetchall()
d.close()
ok = failed = 0
for row in pending:
try:
o = iproyal.get_order(row["iproyal_order_id"])
status = o.get("status")
if status == "confirmed":
creds = o.get("proxies") or o.get("proxy") or o.get("data") or {}
# creds may be a list of {host,port,username,password} or {ip,...}
if isinstance(creds, list) and creds:
creds = creds[0]
host = creds.get("host") or creds.get("ip") or ""
port = str(creds.get("port", ""))
user = creds.get("username") or ""
pw = creds.get("password") or ""
d = db.get_db()
d.execute("UPDATE dedicated_ips SET status='active', proxy_host=?, proxy_port=?,"
"proxy_user=?, proxy_pass=?, expires_at=? WHERE id=?",
(host, port, user, pw, int(time.time()) + row["plan_days"] * 86400, row["id"]))
d.commit()
d.close()
ok += 1
elif status in ("refunded", "expired"):
d = db.get_db()
d.execute("UPDATE dedicated_ips SET status='failed' WHERE id=?", (row["id"],))
d.commit()
d.close()
failed += 1
except Exception as e:
app.logger.warning("poll order %s failed: %s", row["iproyal_order_id"], e)
return ok, failed
# ---------- agent discovery ----------
@app.route("/llms.txt")
def llms_txt():
@@ -257,8 +381,11 @@ Sells residential SOCKS5 and HTTP CONNECT proxies with global geo-targeting
## API
- GET /api/v1/info -> service info (JSON)
- GET /api/v1/plans -> available plans (JSON)
- GET /api/v1/plans -> residential GB plans (JSON)
- GET /api/v1/dedicated/locations?product=9 -> ISP dedicated locations (JSON)
- GET /api/v1/dedicated/locations?product=3 -> datacenter dedicated locations (JSON)
- Human signup: {SITE_HOST}/signup
- Dedicated IPs: {SITE_HOST}/dedicated (datacenter $1.80/30d + ISP $4/30d resold at markup)
## Connect (after signup + top-up)
socks5://USER:PASS@{PROXY['host']}:{PROXY['socks_port']}
@@ -286,6 +413,12 @@ def api_info():
"kyc": False,
"signup": f"https://{SITE_HOST}/signup",
"docs": f"https://{SITE_HOST}/llms.txt",
"dedicated_ips": {
"products": ["datacenter", "isp"],
"isp_locations": f"https://{SITE_HOST}/dedicated/locations?product=9",
"dc_locations": f"https://{SITE_HOST}/dedicated/locations?product=3",
"browse": f"https://{SITE_HOST}/dedicated",
},
})