-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
76 lines (58 loc) · 2.32 KB
/
Program.cs
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
using OpenQA.Selenium;
using NordVpnAccountsChecker.Extensions;
using NordVpnAccountsChecker.Components;
var blacklist = new AccountsFileStorage(fileName: "_blacklist");
blacklist.ReadAccounts();
Console.WriteLine($"Found {blacklist.GetAccounts().Count} accounts in the blacklist");
var whitelist = new AccountsFileStorage(fileName: "_whitelist");
whitelist.ReadAccounts();
Console.WriteLine($"Found {whitelist.GetAccounts().Count} accounts in the whitelist");
var handledAccounts = blacklist.GetAccounts()
.Union(whitelist.GetAccounts())
.DistinctBy(s => s.Key)
.ToDictionary(s => s.Key, s => s.Value);
Console.WriteLine($"Found {handledAccounts.Count} handled accounts");
var accounts = AccountsFileParser.ParseDirectory(relativePath: "Files");
var accountsToParse = accounts
.ExceptBy(handledAccounts.Select(s => s.Key), account => account.Key)
.OrderBy(s => s.Key)
.ToDictionary(s => s.Key, s => s.Value);
Console.WriteLine($"Found {accountsToParse.Count} accounts to handle");
var prefs = new Dictionary<string, object>()
{
{ "credentials_enable_service", false } // disable auth popups after login
};
using (IWebDriver driver = ChromeDriverEx.CreateUndetectedChromeDriver(prefs))
{
var loginUrl = "https://my.nordaccount.com/oauth2/login";
var navigateToLoginPage = true;
foreach (var account in accountsToParse)
{
if (navigateToLoginPage)
{
driver.Navigate().GoToUrl(loginUrl);
}
driver.HandleTooManyRequests(loginUrl);
driver.EnterLoginAndSubmit(account.Key);
driver.EnterPasswordAndSignIn(account.Value);
try
{
var success = driver.HandleMessage();
if (success)
{
whitelist.AddAccount(account.Key, account.Value);
Console.WriteLine($"{account.Key} added to the whitelist");
}
else
{
blacklist.AddAccount(account.Key, account.Value);
Console.WriteLine($"{account.Key} added to the blacklist");
}
navigateToLoginPage = true;
}
catch
{
navigateToLoginPage = false;
}
}
}