diff --git a/app.py b/app.py index 3b692f5..2fe4968 100644 --- a/app.py +++ b/app.py @@ -334,21 +334,24 @@ def poll_provisioning(): 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 + pd = o.get("proxy_data") or {} + proxies = pd.get("proxies") or [] + ports = pd.get("ports") or {} + if proxies: + p = proxies[0] + host = p.get("ip") or "" + user = p.get("username") or "" + pw = p.get("password") or "" + socks_port = str(ports.get("socks5", "")) + http_port = str(ports.get("http|https", "")) + d = db.get_db() + d.execute("UPDATE dedicated_ips SET status='active', proxy_host=?, proxy_port=?," + "http_port=?, proxy_user=?, proxy_pass=?, expires_at=? WHERE id=?", + (host, socks_port, http_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"],)) diff --git a/db.py b/db.py index 277ff2a..07afab5 100644 --- a/db.py +++ b/db.py @@ -62,6 +62,7 @@ CREATE TABLE IF NOT EXISTS dedicated_ips ( status TEXT DEFAULT 'pending_payment', -- pending_payment/provisioning/active/expired/failed proxy_host TEXT, proxy_port TEXT, + http_port TEXT, proxy_user TEXT, proxy_pass TEXT, price_sats INTEGER, diff --git a/templates/dashboard.html b/templates/dashboard.html index 72f7906..4414519 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -62,14 +62,17 @@ {{ d.status }} {% if d.status == 'active' %} -
IP {{ d.proxy_host }} · expires in {{ d.plan_days }}d
{% elif d.status in ('provisioning','pending_payment') %}Provisioning — refresh shortly for your IP.
{% endif %} diff --git a/test_poll.py b/test_poll.py new file mode 100644 index 0000000..915fd43 --- /dev/null +++ b/test_poll.py @@ -0,0 +1,27 @@ +import db +import time +import app + +db.init_db() +d = db.get_db() +d.execute("DELETE FROM dedicated_ips WHERE iproyal_order_id=82970019") +d.execute("INSERT INTO dedicated_ips (user_id,product_id,product_name,plan_days,location_id," + "location_name,iproyal_order_id,status,price_sats,created_at) " + "VALUES (2,3,'Datacenter Dedicated',30,201,'United States - Ashburn (Virginia)'," + "82970019,'provisioning',10000,?)", (int(time.time()),)) +d.commit() +d.close() +print("inserted test row (order 82970019, status=provisioning)") + +ok, failed = app.poll_provisioning() +print(f"poll_provisioning -> provisioned={ok} failed={failed}") + +d = db.get_db() +r = d.execute("SELECT * FROM dedicated_ips WHERE iproyal_order_id=82970019").fetchone() +d.close() +print("RESULT ROW:") +for k in r.keys(): + v = r[k] + if k == "proxy_pass": + v = ("*" * len(v)) if v else "" + print(f" {k} = {v}")