Восстанови старую схему автозаполнения VPN
This commit is contained in:
@@ -37,7 +37,88 @@ grep -q '"event":"waiting"' "$ROOT/bin/vpn-lemanapro.sh"
|
||||
grep -q -- '--patch-only' "$ROOT/bin/vpn-lemanapro.sh"
|
||||
grep -q -- '--manual-sso' "$ROOT/bin/vpn-lemanapro.sh"
|
||||
grep -q 'LEMANA_VPN_AUTOFILL_DISABLE' "$ROOT/bin/vpn-lemanapro.sh"
|
||||
grep -q '__lemanaVpnClicked' "$ROOT/bin/vpn-lemanapro.sh"
|
||||
|
||||
fake_webengine="$TMP_DIR/webengine_process.py"
|
||||
cat > "$fake_webengine" <<'PY'
|
||||
import json
|
||||
import sys
|
||||
|
||||
class Browser:
|
||||
def run(self, display_mode, credentials, url_pattern, rules):
|
||||
argv = sys.argv.copy()
|
||||
if display_mode == "hidden":
|
||||
argv += ["-platform", "minimal"]
|
||||
|
||||
if credentials:
|
||||
logger.info("Initiating autologin", cred=credentials)
|
||||
for url_pattern, rules in auto_fill_rules.items():
|
||||
script = QWebEngineScript()
|
||||
script.setInjectionPoint(QWebEngineScript.InjectionPoint.DocumentReady)
|
||||
script.setWorldId(QWebEngineScript.ScriptWorldId.ApplicationWorld)
|
||||
script.setSourceCode(
|
||||
f"""
|
||||
// ==UserScript==
|
||||
// @include {url_pattern}
|
||||
// ==/UserScript==
|
||||
|
||||
function autoFill() {{
|
||||
{get_selectors(rules, credentials)}
|
||||
setTimeout(autoFill, 1000);
|
||||
}}
|
||||
autoFill();
|
||||
"""
|
||||
)
|
||||
self.page().scripts().insert(script)
|
||||
|
||||
def get_selectors(rules, credentials):
|
||||
statements = []
|
||||
for rule in rules:
|
||||
selector = json.dumps(rule.selector)
|
||||
if rule.action == "stop":
|
||||
statements.append(
|
||||
f"""var elem = document.querySelector({selector}); if (elem) {{ return; }}"""
|
||||
)
|
||||
elif rule.fill:
|
||||
value = json.dumps(getattr(credentials, rule.fill, None))
|
||||
if value:
|
||||
statements.append(
|
||||
f"""var elem = document.querySelector({selector}); if (elem) {{ elem.dispatchEvent(new Event("focus")); elem.value = {value}; elem.dispatchEvent(new Event("blur")); }}"""
|
||||
)
|
||||
else:
|
||||
logger.warning(
|
||||
"Credential info not available",
|
||||
type=rule.fill,
|
||||
possibilities=dir(credentials),
|
||||
)
|
||||
elif rule.action == "click":
|
||||
statements.append(
|
||||
f"""var elem = document.querySelector({selector}); if (elem) {{ elem.dispatchEvent(new Event("focus")); elem.click(); }}"""
|
||||
)
|
||||
return "\n".join(statements)
|
||||
PY
|
||||
|
||||
LEMANA_VPN_WEBENGINE_PROCESS="$fake_webengine" \
|
||||
LEMANA_VPN_OC_PYTHON=python3 \
|
||||
LEMANA_VPN_PATCH_BACKUP_DIR="$TMP_DIR/patch-backups" \
|
||||
bash "$ROOT/bin/vpn-lemanapro.sh" --patch-only >/dev/null
|
||||
|
||||
grep -q '"offscreen"' "$fake_webengine"
|
||||
grep -q 'LEMANA_VPN_AUTOFILL_DISABLE' "$fake_webengine"
|
||||
grep -q 'new RegExp' "$fake_webengine"
|
||||
grep -q 'script.setWorldId(QWebEngineScript.ScriptWorldId.ApplicationWorld)' "$fake_webengine"
|
||||
grep -q 'new Event("input", {{bubbles: true}})' "$fake_webengine"
|
||||
if grep -q 'ScriptWorldId.MainWorld' "$fake_webengine"; then
|
||||
echo "patched auto-fill should keep the original ApplicationWorld behavior" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -q '__lemanaVpnClicked' "$fake_webengine"; then
|
||||
echo "patched auto-fill should stay stateless like the original working setup" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -q 'valueSetter' "$fake_webengine"; then
|
||||
echo "patched auto-fill should use the original direct value assignment with input/change events" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
status_text="$(bash "$ROOT/bin/vpn-lemanapro.sh" --status)"
|
||||
printf '%s\n' "$status_text" | grep -q 'Modules:'
|
||||
|
||||
Reference in New Issue
Block a user