small cookie fix
This commit is contained in:
+14
-1
@@ -2,6 +2,7 @@
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
@@ -86,6 +87,7 @@ def parseCookieFile(file: Path, domain: str) -> None:
|
||||
|
||||
|
||||
def getSeedboxes(domain: str) -> tuple[list[dict], str]:
|
||||
global COOKIE_HEADER
|
||||
try:
|
||||
req = urllib.request.Request(
|
||||
f"https://{domain}/users/{parsed_args.username}/seedboxes",
|
||||
@@ -94,6 +96,12 @@ def getSeedboxes(domain: str) -> tuple[list[dict], str]:
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
html = resp.read().decode("utf-8")
|
||||
|
||||
for header, value in resp.getheaders():
|
||||
if header.lower() == "set-cookie":
|
||||
cookie_val = value.split(";")[0]
|
||||
if cookie_val not in COOKIE_HEADER:
|
||||
COOKIE_HEADER += f"; {cookie_val}"
|
||||
|
||||
token_match = re.search(
|
||||
r'<meta\s+name="csrf-token"\s+content="([^"]+)"', html, re.IGNORECASE
|
||||
)
|
||||
@@ -187,7 +195,12 @@ def main():
|
||||
data=data,
|
||||
headers=generateHeaders(domain),
|
||||
)
|
||||
urllib.request.urlopen(req)
|
||||
|
||||
try:
|
||||
urllib.request.urlopen(req)
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code != 302:
|
||||
print(f"Failed to delete {sbox['name']}: HTTP {e.code}", flush=True)
|
||||
|
||||
if parsed_args.ip:
|
||||
if addSeedbox(domain, add_token):
|
||||
|
||||
Reference in New Issue
Block a user