35 lines
2.3 KiB
Python
35 lines
2.3 KiB
Python
#!/opt/pw/bin/python
|
|
"""share_setup.py — the household's „Hálózati megosztás" page: sharing on, the share password, a „Filmek" share on the
|
|
data disk (B4). Env PW = the share password. Prints the page's answer after each act; screenshots with fields blank."""
|
|
import os, re
|
|
from playwright.sync_api import sync_playwright
|
|
OUT = "/root/shots/b4-share"
|
|
def txt(pg): return re.sub(r"\s+", " ", pg.inner_text("main") if pg.locator("main").count() else pg.inner_text("body"))
|
|
with sync_playwright() as p:
|
|
b = p.chromium.launch(executable_path="/usr/bin/chromium", args=["--no-sandbox"])
|
|
pg = b.new_context(locale="hu-HU", ignore_https_errors=True, viewport={"width": 1366, "height": 900},
|
|
storage_state="/root/work/state-dash.json").new_page()
|
|
pg.goto("https://felhom.tester4.test/sharing", wait_until="networkidle")
|
|
cb = pg.get_by_label(re.compile("Megosztás engedélyezése"))
|
|
if not cb.is_checked():
|
|
cb.check()
|
|
pg.get_by_role("button", name="Mentés").first.click(); pg.wait_for_load_state("networkidle"); pg.wait_for_timeout(4000)
|
|
print("1 enabled:", re.search(r"Állapot: \S+", txt(pg)).group(0) if re.search(r"Állapot: \S+", txt(pg)) else txt(pg)[:200])
|
|
pw = pg.locator("input[type=password]")
|
|
for i in range(pw.count()):
|
|
pw.nth(i).fill(os.environ["PW"])
|
|
pg.get_by_role("button", name="Jelszó mentése").click(); pg.wait_for_load_state("networkidle"); pg.wait_for_timeout(3000)
|
|
print("2 password saved; page says:", [m for m in re.findall(r"(?:jelszó[^.]{0,80}\.)", txt(pg))][:2])
|
|
pg.get_by_label(re.compile("Megosztás neve")).fill("Filmek")
|
|
pg.get_by_label(re.compile("Tárhely")).select_option(label=re.compile("Családi adatlemez")) if False else None
|
|
sel = pg.locator("select").last
|
|
opts = sel.locator("option").evaluate_all("els => els.map(e => [e.value, e.textContent.trim()])")
|
|
val = [v for v, t in opts if "Családi" in t][0]
|
|
sel.select_option(val)
|
|
pg.get_by_role("button", name="Megosztás létrehozása").click(); pg.wait_for_load_state("networkidle"); pg.wait_for_timeout(4000)
|
|
t = txt(pg); i = t.find("Megosztott mappák")
|
|
print("3 shares:", t[i:i + 400])
|
|
pg.evaluate("document.querySelectorAll('input[type=password]').forEach(e => e.value = '')")
|
|
pg.screenshot(path=f"{OUT}-2-after-setup-desktop-hu.png", full_page=True)
|
|
b.close()
|