Harden dedicated-IP parser against real IPRoyal response (proxy_data.ip/ports/user/pass)
This commit is contained in:
23
app.py
23
app.py
@@ -334,18 +334,21 @@ def poll_provisioning():
|
|||||||
o = iproyal.get_order(row["iproyal_order_id"])
|
o = iproyal.get_order(row["iproyal_order_id"])
|
||||||
status = o.get("status")
|
status = o.get("status")
|
||||||
if status == "confirmed":
|
if status == "confirmed":
|
||||||
creds = o.get("proxies") or o.get("proxy") or o.get("data") or {}
|
pd = o.get("proxy_data") or {}
|
||||||
# creds may be a list of {host,port,username,password} or {ip,...}
|
proxies = pd.get("proxies") or []
|
||||||
if isinstance(creds, list) and creds:
|
ports = pd.get("ports") or {}
|
||||||
creds = creds[0]
|
if proxies:
|
||||||
host = creds.get("host") or creds.get("ip") or ""
|
p = proxies[0]
|
||||||
port = str(creds.get("port", ""))
|
host = p.get("ip") or ""
|
||||||
user = creds.get("username") or ""
|
user = p.get("username") or ""
|
||||||
pw = creds.get("password") or ""
|
pw = p.get("password") or ""
|
||||||
|
socks_port = str(ports.get("socks5", ""))
|
||||||
|
http_port = str(ports.get("http|https", ""))
|
||||||
d = db.get_db()
|
d = db.get_db()
|
||||||
d.execute("UPDATE dedicated_ips SET status='active', proxy_host=?, proxy_port=?,"
|
d.execute("UPDATE dedicated_ips SET status='active', proxy_host=?, proxy_port=?,"
|
||||||
"proxy_user=?, proxy_pass=?, expires_at=? WHERE id=?",
|
"http_port=?, proxy_user=?, proxy_pass=?, expires_at=? WHERE id=?",
|
||||||
(host, port, user, pw, int(time.time()) + row["plan_days"] * 86400, row["id"]))
|
(host, socks_port, http_port, user, pw,
|
||||||
|
int(time.time()) + row["plan_days"] * 86400, row["id"]))
|
||||||
d.commit()
|
d.commit()
|
||||||
d.close()
|
d.close()
|
||||||
ok += 1
|
ok += 1
|
||||||
|
|||||||
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
|
status TEXT DEFAULT 'pending_payment', -- pending_payment/provisioning/active/expired/failed
|
||||||
proxy_host TEXT,
|
proxy_host TEXT,
|
||||||
proxy_port TEXT,
|
proxy_port TEXT,
|
||||||
|
http_port TEXT,
|
||||||
proxy_user TEXT,
|
proxy_user TEXT,
|
||||||
proxy_pass TEXT,
|
proxy_pass TEXT,
|
||||||
price_sats INTEGER,
|
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>
|
<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>
|
</div>
|
||||||
{% if d.status == 'active' %}
|
{% if d.status == 'active' %}
|
||||||
<div class="copy" style="margin-top:8px">
|
<label style="font-size:11px;color:var(--muted)">SOCKS5</label>
|
||||||
<input type="text" readonly value="{{ d.proxy_host }}:{{ d.proxy_port }}" onclick="this.select()">
|
<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>
|
<button onclick="copy(this.previousElementSibling)">Copy</button>
|
||||||
</div>
|
</div>
|
||||||
|
<label style="font-size:11px;color:var(--muted)">HTTP</label>
|
||||||
<div class="copy" style="margin-top:6px">
|
<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>
|
<button onclick="copy(this.previousElementSibling)">Copy</button>
|
||||||
</div>
|
</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') %}
|
{% 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>
|
<p class="muted" style="font-size:12px;margin:6px 0 0">Provisioning — refresh shortly for your IP.</p>
|
||||||
{% endif %}
|
{% 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