Harden dedicated-IP parser against real IPRoyal response (proxy_data.ip/ports/user/pass)
This commit is contained in:
33
app.py
33
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"],))
|
||||
|
||||
1
db.py
1
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,
|
||||
|
||||
@@ -62,14 +62,17 @@
|
||||
<span style="color:{{ {'active':'var(--ok)','provisioning':'var(--warn)','pending_payment':'var(--warn)','failed':'var(--danger)','expired':'var(--muted)'}.get(d.status,'var(--muted)') }}">{{ d.status }}</span>
|
||||
</div>
|
||||
{% if d.status == 'active' %}
|
||||
<div class="copy" style="margin-top:8px">
|
||||
<input type="text" readonly value="{{ d.proxy_host }}:{{ d.proxy_port }}" onclick="this.select()">
|
||||
<label style="font-size:11px;color:var(--muted)">SOCKS5</label>
|
||||
<div class="copy">
|
||||
<input type="text" readonly value="socks5://{{ d.proxy_user }}:{{ d.proxy_pass }}@{{ d.proxy_host }}:{{ d.proxy_port }}" onclick="this.select()">
|
||||
<button onclick="copy(this.previousElementSibling)">Copy</button>
|
||||
</div>
|
||||
<label style="font-size:11px;color:var(--muted)">HTTP</label>
|
||||
<div class="copy" style="margin-top:6px">
|
||||
<input type="text" readonly value="{{ d.proxy_user }}:{{ d.proxy_pass }}" onclick="this.select()">
|
||||
<input type="text" readonly value="http://{{ d.proxy_user }}:{{ d.proxy_pass }}@{{ d.proxy_host }}:{{ d.http_port }}" onclick="this.select()">
|
||||
<button onclick="copy(this.previousElementSibling)">Copy</button>
|
||||
</div>
|
||||
<p class="muted" style="font-size:11px;margin:6px 0 0">IP {{ d.proxy_host }} · expires in {{ d.plan_days }}d</p>
|
||||
{% elif d.status in ('provisioning','pending_payment') %}
|
||||
<p class="muted" style="font-size:12px;margin:6px 0 0">Provisioning — refresh shortly for your IP.</p>
|
||||
{% endif %}
|
||||
|
||||
27
test_poll.py
Normal file
27
test_poll.py
Normal file
@@ -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}")
|
||||
Reference in New Issue
Block a user