1+ using System ;
2+ using System . IO ;
3+ using System . Net ;
4+ using System . Linq ;
5+ using OpenQA . Selenium ;
6+ using System . Threading ;
7+ using SmorcIRL . TempMail ;
8+ using System . Diagnostics ;
9+ using Newtonsoft . Json . Linq ;
10+ using System . IO . Compression ;
11+ using System . Threading . Tasks ;
12+ using OpenQA . Selenium . Chrome ;
13+ using SmorcIRL . TempMail . Models ;
14+ using System . Collections . Generic ;
15+ using OpenQA . Selenium . Support . UI ;
16+ using System . Text . RegularExpressions ;
17+
18+ namespace MathGPTProGenerator
19+ {
20+ static class Chromium
21+ {
22+ public static string version ;
23+ private static ChromeDriver driver ;
24+
25+ public static void Initialization ( )
26+ {
27+ string temp_directory = Path . GetTempPath ( ) ;
28+ string current_directory = Directory . GetCurrentDirectory ( ) ;
29+ string chromium_directory = Path . Combine ( current_directory , "Chromium" ) ;
30+ string driver_path = Path . Combine ( current_directory , "chromedriver.exe" ) ;
31+
32+ string driver_endpoint = "https://storage.googleapis.com/chrome-for-testing-public/" ;
33+ string github_endpoint = "https://api.github.com/repos/ungoogled-software/ungoogled-chromium-windows/releases" ;
34+
35+ try
36+ {
37+ using ( WebClient client = new WebClient ( ) )
38+ {
39+ client . Headers . Add ( "User-Agent" , "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36" ) ;
40+
41+ if ( ! Directory . Exists ( chromium_directory ) )
42+ {
43+ Console . WriteLine ( "Fetching the latest Chromium release from GitHub..." ) ;
44+ string json = client . DownloadString ( github_endpoint ) ;
45+
46+ if ( ! string . IsNullOrEmpty ( json ) )
47+ {
48+ JArray array = JArray . Parse ( json ) ;
49+ JObject lasted = ( JObject ) array . FirstOrDefault ( ) ;
50+
51+ if ( lasted != null )
52+ {
53+ string tag = lasted [ "tag_name" ] . ToString ( ) ;
54+ version = Regex . Replace ( tag , @"-\d+\.\d+" , "" ) ;
55+ Console . WriteLine ( $ "Latest release: { tag } (driver version: { version } )") ;
56+
57+ string file_scheme = Environment . Is64BitOperatingSystem ? "x64.zip" : "x86.zip" ;
58+ IEnumerable < JToken > assets = lasted [ "assets" ] . Where ( a => a [ "name" ] . ToString ( ) . Contains ( file_scheme ) ) ;
59+
60+ if ( assets . Any ( ) )
61+ {
62+ string chromium_url = assets . First ( ) [ "browser_download_url" ] . ToString ( ) ;
63+ string chromium_zip = Path . Combine ( temp_directory , Path . GetFileName ( chromium_url ) ) ;
64+
65+ Console . WriteLine ( $ "Downloading: { Path . GetFileName ( chromium_url ) } ") ;
66+ client . DownloadFile ( chromium_url , chromium_zip ) ;
67+
68+ Console . WriteLine ( "Extracting Chromium..." ) ;
69+ ZipFile . ExtractToDirectory ( chromium_zip , current_directory ) ;
70+
71+ string chromium_extracted = Directory . GetDirectories ( current_directory ) . FirstOrDefault ( d => d . Contains ( "ungoogled-chromium" ) ) ;
72+ if ( ! string . IsNullOrEmpty ( chromium_extracted ) )
73+ {
74+ Directory . Move ( chromium_extracted , chromium_directory ) ;
75+ Console . WriteLine ( $ "Chromium extracted and renamed to: { chromium_directory } ") ;
76+ }
77+
78+ File . Delete ( chromium_zip ) ;
79+ }
80+ else
81+ {
82+ Console . WriteLine ( "No valid file found for download!" ) ;
83+ }
84+ }
85+ else
86+ {
87+ Console . WriteLine ( "Failed to find the latest release!" ) ;
88+ }
89+ }
90+ }
91+ else
92+ {
93+ version = GetChromiumVersion ( ) ;
94+
95+ if ( string . IsNullOrEmpty ( version ) )
96+ {
97+ Console . WriteLine ( "Could not determine Chromium version. Aborting driver download." ) ;
98+ return ;
99+ }
100+
101+ Console . WriteLine ( "Chromium is already installed. Skipping download." ) ;
102+ }
103+
104+ if ( ! File . Exists ( driver_path ) )
105+ {
106+ if ( string . IsNullOrEmpty ( version ) )
107+ {
108+ Console . WriteLine ( "Version is not set. Cannot download driver." ) ;
109+ return ;
110+ }
111+
112+ string driver_url = $ "{ driver_endpoint } { version } /win64/chromedriver-win64.zip";
113+ string driver_zip = Path . Combine ( temp_directory , $ "chromedriver_{ version } .zip") ;
114+
115+ Console . WriteLine ( $ "Downloading driver for version { version } ") ;
116+ client . DownloadFile ( driver_url , driver_zip ) ;
117+
118+ string driver_extracted = Path . Combine ( temp_directory , "chromedriver-temp" ) ;
119+ Console . WriteLine ( "Extracting driver..." ) ;
120+ ZipFile . ExtractToDirectory ( driver_zip , driver_extracted ) ;
121+
122+ string downloaded_driver_path = Directory . GetFiles ( driver_extracted , "chromedriver.exe" , SearchOption . AllDirectories ) . FirstOrDefault ( ) ;
123+ if ( File . Exists ( downloaded_driver_path ) )
124+ {
125+ File . Move ( downloaded_driver_path , driver_path ) ;
126+ Console . WriteLine ( $ "Driver extracted to: { driver_path } ") ;
127+ }
128+
129+ File . Delete ( driver_zip ) ;
130+ Directory . Delete ( driver_extracted , true ) ;
131+ }
132+ else
133+ {
134+ Console . WriteLine ( "Driver is already installed. Skipping download." ) ;
135+ }
136+ }
137+ }
138+ catch ( Exception ex )
139+ {
140+ Console . WriteLine ( $ "Error occurred: { ex . Message } ") ;
141+ }
142+ }
143+
144+ public static async Task Start ( )
145+ {
146+ Console . Write ( "Enter the number of accounts to generate: " ) ;
147+ int count = int . Parse ( Console . ReadLine ( ) ) ;
148+
149+ MailClient client = new MailClient ( ) ;
150+ driver = new ChromeDriver ( GetChromeDriverService ( ) , GetChromeOptions ( ) , TimeSpan . FromMinutes ( 2 ) ) ;
151+
152+ for ( int i = 0 ; i < count ; i ++ )
153+ {
154+ driver . Navigate ( ) . GoToUrl ( "https://mathgptpro.com/login/sign-up" ) ;
155+ driver . Manage ( ) . Timeouts ( ) . ImplicitWait = TimeSpan . FromSeconds ( 45 ) ;
156+ string domain = await client . GetFirstAvailableDomainName ( ) ;
157+
158+ string username = Utils . Random ( 10 ) ;
159+ string password = Utils . Random ( 16 ) ;
160+ string email = $ "{ username } @{ domain } ";
161+
162+ await client . Register ( email , password ) ;
163+
164+ Input ( driver , By . Id ( "input-email" ) , email ) ;
165+ Thread . Sleep ( 500 ) ;
166+ Click ( driver , By . XPath ( "//*[@id='root']/div/div[1]/div/div/div/div/div[4]/button" ) ) ;
167+
168+ MessageInfo [ ] messages = null ;
169+
170+ while ( messages == null || messages . Length == 0 )
171+ {
172+ messages = await client . GetAllMessages ( ) ;
173+ await Task . Delay ( 1000 ) ;
174+ }
175+
176+ MessageSource source = await client . GetMessageSource ( messages [ 0 ] . Id ) ;
177+
178+ string url = Utils . ExtractUrlFromHtml ( source . Data ) ;
179+
180+ if ( ! string . IsNullOrEmpty ( url ) )
181+ {
182+ driver . Navigate ( ) . GoToUrl ( url ) ;
183+
184+ Input ( driver , By . Id ( "input-firstName" ) , Utils . Random ( 5 ) ) ;
185+ Thread . Sleep ( 500 ) ;
186+ Input ( driver , By . Id ( "input-lastName" ) , Utils . Random ( 5 ) ) ;
187+ Thread . Sleep ( 500 ) ;
188+ Input ( driver , By . Id ( "input-password-new" ) , password ) ;
189+ Thread . Sleep ( 500 ) ;
190+ Input ( driver , By . Id ( "input-password-again" ) , password ) ;
191+ Thread . Sleep ( 500 ) ;
192+ Click ( driver , By . XPath ( "//*[@id='root']/div[1]/div[1]/div/div/div/div/div[7]/button" ) ) ;
193+ Thread . Sleep ( 500 ) ;
194+
195+ Console . WriteLine ( $ "{ email } :{ password } ") ;
196+ File . AppendAllText ( "Accounts.txt" , $ "{ email } :{ password } \n ") ;
197+
198+ await client . DeleteMessage ( messages [ 0 ] . Id ) ;
199+ await client . DeleteAccount ( ) ;
200+
201+ driver . Manage ( ) . Cookies . DeleteAllCookies ( ) ;
202+ Thread . Sleep ( 500 ) ;
203+ }
204+ }
205+
206+ driver . Quit ( ) ;
207+ }
208+
209+ private static string GetChromiumVersion ( )
210+ {
211+ string chromium_directory = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Chromium" ) ;
212+ string manifest_file = Directory . GetFiles ( chromium_directory , "*.manifest" ) . FirstOrDefault ( ) ;
213+
214+ if ( ! string . IsNullOrEmpty ( manifest_file ) )
215+ {
216+ string version = Path . GetFileNameWithoutExtension ( manifest_file ) ;
217+ Console . WriteLine ( $ "Chromium version from manifest: { version } ") ;
218+ return version ;
219+ }
220+
221+ string chromium_file = Path . Combine ( chromium_directory , "chrome.exe" ) ;
222+
223+ if ( File . Exists ( chromium_file ) )
224+ {
225+ try
226+ {
227+ string version = FileVersionInfo . GetVersionInfo ( chromium_file ) . FileVersion ;
228+ Console . WriteLine ( $ "Chromium version from chrome.exe: { version } ") ;
229+ return version ;
230+ }
231+ catch ( Exception ex )
232+ {
233+ Console . WriteLine ( $ "Failed to get version from chrome.exe: { ex . Message } ") ;
234+ }
235+ }
236+
237+ Console . WriteLine ( "Version not found!" ) ;
238+ return null ;
239+ }
240+
241+ private static ChromeDriverService GetChromeDriverService ( )
242+ {
243+ ChromeDriverService service = ChromeDriverService . CreateDefaultService ( ) ;
244+
245+ service . EnableVerboseLogging = false ;
246+ service . SuppressInitialDiagnosticInformation = true ;
247+
248+ return service ;
249+ }
250+
251+ private static ChromeOptions GetChromeOptions ( )
252+ {
253+ ChromeOptions options = new ChromeOptions ( ) ;
254+ options . BinaryLocation = Path . Combine ( Directory . GetCurrentDirectory ( ) , "Chromium" , "chrome.exe" ) ;
255+
256+ options . AddArgument ( "--start-maximized" ) ;
257+ options . AddExcludedArgument ( "--enable-automation" ) ;
258+ options . AddUserProfilePreference ( "credentials_enable_service" , false ) ;
259+ options . AddUserProfilePreference ( "profile.default_content_setting_values.images" , 2 ) ;
260+
261+ //options.AddArgument("--headless");
262+
263+ return options ;
264+ }
265+
266+ public static void Click ( ChromeDriver driver , By by )
267+ {
268+ WebDriverWait wait = new WebDriverWait ( driver , TimeSpan . FromSeconds ( 40 ) ) ;
269+
270+ bool element = wait . Until ( condition =>
271+ {
272+ try
273+ {
274+ IWebElement e = driver . FindElement ( by ) ;
275+
276+ if ( e != null && e . Displayed )
277+ {
278+ e . Click ( ) ;
279+ return true ;
280+ }
281+ else
282+ {
283+ return false ;
284+ }
285+ }
286+ catch ( StaleElementReferenceException )
287+ {
288+ return false ;
289+ }
290+ catch ( NoSuchElementException )
291+ {
292+ return false ;
293+ }
294+ } ) ;
295+ }
296+
297+ public static void Input ( ChromeDriver driver , By by , string text )
298+ {
299+ WebDriverWait wait = new WebDriverWait ( driver , TimeSpan . FromSeconds ( 20 ) ) ;
300+
301+ bool element = wait . Until ( condition =>
302+ {
303+ try
304+ {
305+ IWebElement e = driver . FindElements ( by ) . FirstOrDefault ( ) ;
306+
307+ if ( e != null && e . Displayed )
308+ {
309+ e . SendKeys ( text ) ;
310+ return true ;
311+ }
312+ else
313+ {
314+ return false ;
315+ }
316+ }
317+ catch ( StaleElementReferenceException )
318+ {
319+ return false ;
320+ }
321+ catch ( NoSuchElementException )
322+ {
323+ return false ;
324+ }
325+ } ) ;
326+ }
327+ }
328+ }
0 commit comments