-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolConfig.cs
More file actions
110 lines (92 loc) · 5.53 KB
/
Copy pathToolConfig.cs
File metadata and controls
110 lines (92 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
namespace WebToolsDataMonitor
{
public class TargetScriptExecution
{
public string Name { get; set; }
public Dictionary<string, object> OptionsOverride { get; set; } = new Dictionary<string, object>();
}
public class ScrapPageConfig
{
public string DestinationUrl { get; set; }
public List<TargetScriptExecution> Scripts { get; set; } = new List<TargetScriptExecution>();
}
public class ToolConfig
{
public string ToolName { get; set; }
public string Addr { get; set; }
public string PageLogin { get; set; }
public int LoginRetryAttempts { get; set; } = 1;
public int LoginRetryDelaySeconds { get; set; } = 1;
public string PredefinedUser { get; set; }
public string PredefinedPass { get; set; }
public string ElementName { get; set; }
public string ElementPass { get; set; }
public string ElementSubmit { get; set; }
public List<string> PageFilePatterns { get; set; } = new List<string>();
public List<ScrapPageConfig> ScrapPages { get; set; } = new List<ScrapPageConfig>();
// "parallel" | "sequential" | null. Per-tool override for page run mode. Null/unrecognized means
// "no override" - falls back to the global "Execute Tool Pages in Parallel" checkbox.
public string ForcePageRunMode { get; set; }
// Per-tool override for whether this tool's CacheData/<ToolName> WebView2 profile folder gets
// wiped after every run (see ParallelScraperManager.ClearToolCacheAsync). Null means "no override"
// - falls back to AppConfig.Instance.Data.DefaultDisableCache. true = always clear (forces a fresh
// login next run); false = preserve the cache across runs (needed for slow/weak devices whose SPA
// can't fully cold-bootstrap within the login retry window without a warm HTTP cache).
public bool? DisableCache { get; set; }
// If true, skip the login page/handshake entirely for this tool and go straight to navigating and
// scripting its pages - for devices/dashboards that don't require authentication at all. Default
// false (login runs as normal) since predefinedUser/predefinedPass/element selectors are still
// required config for any tool that does need it.
public bool BypassLogin { get; set; }
// If true, this tool's device presents an untrusted/self-signed/expired TLS certificate (common on
// embedded device web UIs like the GXP1610) and the resulting Chromium errors (ERR_CERT_AUTHORITY_INVALID,
// ERR_CERT_DATE_INVALID, ERR_CERT_COMMON_NAME_INVALID, etc.) should be ignored instead of blocking
// navigation. Applied two ways (see ParallelScraperManager.CreateEnvironmentOnUiAsync /
// InstantiateBrowserContextOnUiAsync): a --ignore-certificate-errors browser launch argument on the
// environment, plus a CoreWebView2.ServerCertificateErrorDetected handler that always allows, as a
// second layer in case the launch argument alone doesn't cover a given error type. Default false -
// only opt in per-tool for devices actually known to have this problem.
public bool IgnoreSslCertError { get; set; }
public string BaseLoginUrl => $"{Addr.TrimEnd('/')}/{PageLogin.TrimStart('/')}";
// Resolves a page's destinationUrl (tools/pages/*.yaml) against this tool's base addr, the same way
// BaseLoginUrl already does for pageLogin - so page configs can write a relative path ("/status/acts")
// instead of repeating the device's full scheme+host in every entry, and picking up an addr change
// doesn't mean editing every page file too. A destinationUrl that's already a fully-qualified
// absolute URL (as older tool configs were written) is returned unchanged, so this is backward
// compatible with configs that predate this convention.
public string ResolveUrl(string destinationUrl)
{
if (string.IsNullOrWhiteSpace(destinationUrl)) return destinationUrl;
if (Uri.TryCreate(destinationUrl, UriKind.Absolute, out _)) return destinationUrl;
return $"{Addr.TrimEnd('/')}/{destinationUrl.TrimStart('/')}";
}
// Resolves ForcePageRunMode to an explicit override, or null if unset/unrecognized so the caller
// can fall back to the global toggle.
public bool? ResolvedForcePagesInParallel
{
get
{
if (string.Equals(ForcePageRunMode, "parallel", StringComparison.OrdinalIgnoreCase)) return true;
if (string.Equals(ForcePageRunMode, "sequential", StringComparison.OrdinalIgnoreCase)) return false;
return null;
}
}
public string GetLoginPageAssertionScript()
{
return $@"
(function() {{
var userField = document.getElementsByName('{ElementName}')[0];
var passField = document.getElementsByName('{ElementPass}')[0];
var submitBtn = document.getElementsByName('{ElementSubmit}')[0];
var isLogin = (userField !== undefined && passField !== undefined && submitBtn !== undefined);
window.chrome.webview.postMessage(JSON.stringify({{
Tool: '{ToolName}',
Action: 'assertIsLoginPage',
Result: isLogin
}}));
}})();";
}
}
}