small cookie fix
This commit is contained in:
+13
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import re
|
import re
|
||||||
|
import urllib.error
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -86,6 +87,7 @@ def parseCookieFile(file: Path, domain: str) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def getSeedboxes(domain: str) -> tuple[list[dict], str]:
|
def getSeedboxes(domain: str) -> tuple[list[dict], str]:
|
||||||
|
global COOKIE_HEADER
|
||||||
try:
|
try:
|
||||||
req = urllib.request.Request(
|
req = urllib.request.Request(
|
||||||
f"https://{domain}/users/{parsed_args.username}/seedboxes",
|
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:
|
with urllib.request.urlopen(req) as resp:
|
||||||
html = resp.read().decode("utf-8")
|
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(
|
token_match = re.search(
|
||||||
r'<meta\s+name="csrf-token"\s+content="([^"]+)"', html, re.IGNORECASE
|
r'<meta\s+name="csrf-token"\s+content="([^"]+)"', html, re.IGNORECASE
|
||||||
)
|
)
|
||||||
@@ -187,7 +195,12 @@ def main():
|
|||||||
data=data,
|
data=data,
|
||||||
headers=generateHeaders(domain),
|
headers=generateHeaders(domain),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
urllib.request.urlopen(req)
|
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 parsed_args.ip:
|
||||||
if addSeedbox(domain, add_token):
|
if addSeedbox(domain, add_token):
|
||||||
|
|||||||
Reference in New Issue
Block a user