Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit AeriaAPI;
- interface uses Windows, uFunc, WININET, Jpeg, Graphics, SysUtils, Classes;
- const
- INVALID_CAPTCHA = 0;
- INVALID_PASSWORD = 1;
- INVALID_TOKEN = 2;
- INVALID_COOKIES = 3;
- INVALID_NONE = 4;
- INVALID_UNKNOWN = 5;
- INVALID_CREDENTIALS = 6;
- type
- TAeria = class
- private
- Cookies, EMail, AccID, PassWord, FormToken:String;
- LoggedIn:Boolean;
- LastErrorCode:Integer;
- ReCaptchaChallengeField, RecaptchaResponse:String;
- public
- function AeriaSetEmail(newemail:String):Boolean;
- function AeriaSetPass(newpass:String):Boolean;
- function GetData():Boolean;
- Procedure ReLogin(user, pass:String);
- Procedure SetCaptcha(response:String);
- function GetCaptchaImage(image:TPicture):Boolean;
- Property IsLoggedIn:Boolean read LoggedIn;
- Property GetCookies:String read Cookies;
- Property Error:Integer read LastErrorCode;
- Property GetEmail:String read EMail;
- Property AccountID:String read AccID;
- //constructor Create(user, pass:String);overload;
- published
- constructor Create(user, pass:String);
- //constructor Create(user, pass, CaptchaQuestion, CaptchaAnswer:String);overload;
- end;
- implementation
- function TAeria.AeriaSetPass(newpass:String):Boolean;
- var
- data, extraheaders, resul:string;
- const
- boundary:String = '-----------------------------7dd29641c076a'#13#10;
- rnrn:String = #13#10#13#10;
- begin
- Result := False;
- data := boundary + 'Content-Disposition: form-data; name="edit[mail]"' + rnrn + EMail + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[pass_current_for_mail]"' + rnrn + '' + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[pass_current]"' + rnrn + password + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[pass][pass1]"' + rnrn + newpass +#13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[pass][pass2]"' + rnrn + newpass + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[change_email]"' + rnrn + '0' + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[change_pass]"' + rnrn + '1' + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[form_token]"' + rnrn + formtoken + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[form_id]"' + rnrn + 'user_edit'#13#10 +
- boundary + 'Content-Disposition: form-data; name="recaptcha_challenge_field"' + rnrn + ReCaptchaChallengeField + #13#10 +
- boundary + 'Content-Disposition: form-data; name="recaptcha_response_field"' + rnrn + RecaptchaResponse + #13#10 +
- boundary + 'Content-Disposition: form-data; name="op"' + rnrn + 'Submit'#13#10 + Copy(boundary, 1, Length(boundary) - 2) + '--'#13#10;;
- extraheaders := 'Content-Type: multipart/form-data; boundary=' + boundary + #13#10 + 'Accept: text/html, application/xhtml+xml, */*'#13#10 + 'Cookie: ' + Cookies + #13#10;
- resul := PostHTTPRequest('www.aeriagames.com', '/user/' + accID + '/edit/account', data, extraheaders);
- if (Pos('Current password not recognized', resul) > 0) and (Pos('The confirmation code is not correct.', resul) > 0) then begin
- LastErrorCode := INVALID_CAPTCHA;
- Exit;
- end;
- if (Pos('Current password not recognized', resul) > 0) then begin
- LastErrorCode := INVALID_PASSWORD;
- Exit;
- end;
- if (Pos('The confirmation code is not correct.', Resul) > 0) then begin
- LastErrorCode := INVALID_CAPTCHA;
- Exit;
- end;
- //Validation error, please try again. If this error persists, please contact the site administrator.
- if (Pos('Validation error, please try again. If this error persists, please contact the site administrator.', resul) > 0) then begin
- LastErrorCode := INVALID_TOKEN;
- Exit;
- end;
- if Pos('You are not authorized to access this page.', resul) > 0 then begin
- LastErrorCode := INVALID_COOKIES;
- Exit;
- end;
- LastErrorCode := INVALID_NONE;
- end;
- function TAeria.GetData():Boolean;
- var
- d, e:string;
- begin
- Result := False;
- d := GETHTTPSRequest('www.aeriagames.com', '/privatemsg', 'Cookie: '+ Cookies);
- if Pos('href="//www.aeriagames.com/privatemsg" title="My Inbox">My Inbox', d) = 0 then Exit;
- Delete(d, 1, Pos('href="//www.aeriagames.com/privatemsg" title="My Inbox">My Inbox', d) + 70);
- Delete(d, 1, Pos('href="', d) + 5);
- d := copy(d, 1, Pos('"', d));
- Delete(d, 1, Pos('//www.aeriagames.com/user/', d) + 25);
- d := copy(d, 1, Pos('/', d) - 1);
- AccID := d;
- //http://www.aeriagames.com/user/92222799/edit/account
- d := GETHTTPSRequest('www.aeriagames.com', '/user/' + AccID + '/edit/account','Cookie: '+ Cookies + #13#10);
- e := d;
- if Pos('<span class="form-no-edit"><span id="edit-current_mail">', d) = 0 then Exit;
- Delete(d, 1, Pos('<span class="form-no-edit"><span id="edit-current_mail">', d) + 55);
- d := copy(d, 1, Pos('</span>', d) - 1);
- EMail := d;
- if Pos('<input type="hidden" name="edit[form_token]" id="edit-user-edit-form-token"', e) = 0 then Exit;
- Delete(e, 1, Pos('<input type="hidden" name="edit[form_token]" id="edit-user-edit-form-token" ', e));
- Delete(e, 1, Pos('value="', e) + 6);
- e := copy(e, 1, Pos('"', e) - 1);
- formtoken := e;
- Result := True;
- end;
- function TAeria.AeriaSetEmail(newemail:String):Boolean;
- const
- boundary:string = '-----------------------------7dd29641c076a'#13#10;
- rnrn:String = #13#10#13#10;
- var
- data, extraheaders, resul:string;
- z:TStringList;
- begin
- Result := False;
- data := boundary + 'Content-Disposition: form-data; name="edit[mail]"' + rnrn + newemail + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[pass_current_for_mail]"' + rnrn + PassWord + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[pass_current]"' + rnrn + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[pass][pass1]"' + rnrn +#13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[pass][pass2]"' + rnrn + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[change_email]"' + rnrn + '1' + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[change_pass]"' + rnrn + '0' + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[form_token]"' + rnrn + FormToken + #13#10 +
- boundary + 'Content-Disposition: form-data; name="edit[form_id]"' + rnrn + 'user_edit'#13#10 +
- boundary + 'Content-Disposition: form-data; name="recaptcha_challenge_field"' + rnrn + ReCaptchaChallengeField + #13#10 +
- boundary + 'Content-Disposition: form-data; name="recaptcha_response_field"' + rnrn + RecaptchaResponse + #13#10 +
- boundary + 'Content-Disposition: form-data; name="op"' + rnrn + 'Submit'#13#10 + Copy(boundary, 1, Length(boundary) - 2) + '--'#13#10;
- extraheaders := 'Content-Type: multipart/form-data; boundary=' + boundary + 'Cookie: ' + Cookies + #13#10 + 'Accept: text/html, application/xhtml+xml, */*'#13#10;
- resul := PostHTTPRequest('www.aeriagames.com', '/user/' + AccID + '/edit/account', data, extraheaders);
- z := TStringList.Create;
- z.Text := resul;
- z.SaveToFile(ExtractFilePath(paramstr(0)) + 'fk.html');
- z.Free;
- if (Pos('Current password not recognized', resul) > 0) and (Pos('The confirmation code is not correct.', resul) > 0) then begin
- LastErrorCode := INVALID_CAPTCHA;
- Exit;
- end;
- if (Pos('Current password not recognized', resul) > 0) then begin
- LastErrorCode := INVALID_PASSWORD;
- Exit;
- end;
- if (Pos('The confirmation code is not correct.', Resul) > 0) then begin
- LastErrorCode := INVALID_CAPTCHA;
- Exit;
- end;
- //Validation error, please try again. If this error persists, please contact the site administrator.
- if (Pos('Validation error, please try again. If this error persists, please contact the site administrator.', resul) > 0) then begin
- LastErrorCode := INVALID_TOKEN;
- Exit;
- end;
- if Pos('You are not authorized to access this page.', resul) > 0 then begin
- LastErrorCode := INVALID_COOKIES;
- Exit;
- end;
- if Pos('You will need to confirm the new email address. Further instructions have been sent to', resul) = 0 then begin
- LastErrorCode := 99;
- Exit;
- end;
- LastErrorCode := INVALID_NONE;
- Result := True;
- end;
- {Procedure TAeria.ReLogin(user, pass:String);
- var
- send, extraheaders, response:string;
- mycookie:PChar;
- mycookieLength:Cardinal;
- Begin
- password := '';
- LoggedIn := False;
- send := 'op=Log+in&edit%5Bmethod%5D=&edit%5Bform_id%5D=account_login' +
- '&' + url_encode('edit[id]') + '=' + url_encode(user) +
- '&' + url_encode('edit[pass]') + '=' + url_encode(pass) +
- '&recaptcha_challenge_field=' + ReCaptchaChallengeField +
- '&recaptcha_response_field=' + RecaptchaResponse;
- extraheaders := 'Content-Type: application/x-www-form-urlencoded' + #13#10;
- response := PostHTTPSRequest('www.aeriagames.com', '/account/login', send, extraheaders);
- if Pos('Sorry. Unrecognized username or password.', response) > 0 then begin
- if Pos('The confirmation code is not correct.', response) > 0 then
- LastErrorCode := INVALID_CAPTCHA
- else
- LastErrorCode := INVALID_CREDENTIALS;
- Exit;
- end;
- InternetGetCookie('https://www.aeriagames.com/', nil, nil, mycookieLength);
- if mycookieLength > 0 then begin
- mycookie := GetMemory(mycookieLength + 1);
- InternetGetCookie('https://www.aeriagames.com/', nil, mycookie, mycookieLength);
- Cookies := string(mycookie);
- end
- else
- Cookies := '';
- LoggedIn := True;
- password := pass;
- LastErrorCode := INVALID_NONE;
- end;}
- Procedure TAeria.ReLogin(user, pass:String);
- var
- send, extraheaders, response:string;
- mycookie:PChar;
- mycookieLength:Cardinal;
- Begin
- password := '';
- LastErrorCode := INVALID_NONE;
- LoggedIn := False;
- send := 'edit[id]=' + url_encode(user) + '&edit[pass]=' + url_encode(pass) + '&ajax_close_button=Cancel&op=Log%20in&edit[method]=ajax&edit[form_id]=account_login&action=submit';
- extraheaders := 'Content-Type: application/x-www-form-urlencoded' + #13#10 + 'Accept: text/html, application/xhtml+xml, */*';
- response := PostHTTPSRequest('www.aeriagames.com', '/account/login/ajax', send, extraheaders);
- if Pos('Sorry. Unrecognized username or password.', response) > 0 then begin
- if Pos('The confirmation code is not correct.', response) > 0 then
- LastErrorCode := INVALID_CAPTCHA
- else
- LastErrorCode := INVALID_CREDENTIALS;
- Exit;
- end;
- if Pos('Login successful. Redirecting to your home page.', response) = 0 then begin
- LastErrorCode := INVALID_UNKNOWN;
- Exit;
- end;
- InternetGetCookie('https://www.aeriagames.com/', nil, nil, mycookieLength);
- if mycookieLength > 0 then begin
- mycookie := GetMemory(mycookieLength + 1);
- InternetGetCookie('https://www.aeriagames.com/', nil, mycookie, mycookieLength);
- Cookies := string(mycookie);
- end
- else
- Cookies := '';
- LoggedIn := True;
- password := pass;
- LastErrorCode := INVALID_NONE;
- end;
- Procedure TAeria.SetCaptcha(response:String);
- begin
- RecaptchaResponse := response;
- end;
- function TAeria.GetCaptchaImage(image:TPicture):Boolean;
- var
- a:string;
- begin
- Result := False;
- a := GETHTTPSRequest('www.google.com', '/recaptcha/api/challenge?k=6LcR-MUSAAAAAODqgJEVRJl-lPlhEfZqxaEzRgRq', ''); ///recaptcha/api/noscript?k=6LcR-MUSAAAAAODqgJEVRJl-lPlhEfZqxaEzRgRq don't use!
- Delete(a, 1, Pos(' challenge : ''', a) + 13);
- a := Copy(a, 1, pos('''', a) - 1);
- ReCaptchaChallengeField := a;
- DeleteFileA( PChar(ExtractFilePath(ParamStr(0)) + 'captcha.jpg'));
- if not GetFile('https://www.google.com/recaptcha/api/image?c=' + a, ExtractFilePath(ParamStr(0)) + 'captcha.jpg') then Exit;
- image.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'captcha.jpg');
- Result := True;
- end;
- {
- function TAeria.GetCaptchaImage(image:TPicture):Boolean;
- var
- a ,b:string;
- begin
- Result := False;
- a := GETHTTPSRequest('www.google.com', '/recaptcha/api/noscript?k=6LcR-MUSAAAAAODqgJEVRJl-lPlhEfZqxaEzRgRq', ''); // don't use! You gotta copy the text etc so more work needed :/
- b := a;
- Delete(b, 1, Pos('name="recaptcha_challenge_field" id="recaptcha_challenge_field" value="', b) + 70);
- b := Copy(b, 1, pos('"', b) - 1);
- ReCaptchaChallengeField := b;
- b := a;
- Delete(b, 1, Pos('<img width="300" height="57" alt="" src="', b) + 40);
- b := Copy(b, 1, pos('"', b) - 1);
- DeleteFileA( PChar(ExtractFilePath(ParamStr(0)) + 'captcha.jpg'));
- if not GetFile('https://www.google.com/recaptcha/api/' + b, ExtractFilePath(ParamStr(0)) + 'captcha.jpg') then Exit;
- image.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'captcha.jpg');
- Result := True;
- end;
- }
- {constructor TAeria.Create(user, pass, CaptchaQuestion, CaptchaAnswer:String);
- var
- send, extraheaders, response:string;
- mycookie:PChar;
- mycookieLength:Cardinal;
- Begin
- LoggedIn := False;
- send := 'op=Log+in&edit%5Bmethod%5D=&edit%5Bform_id%5D=account_login' +
- '&' + url_encode('edit[id]') + '=' + url_encode(user) +
- '&' + url_encode('edit[pass]') + '=' + url_encode(pass) +
- '&recaptcha_challenge_field=' + CaptchaQuestion +
- '&recaptcha_response_field=' + CaptchaAnswer;
- extraheaders := 'Content-Type: application/x-www-form-urlencoded' + #13#10;
- response := PostHTTPRequest('www.aeriagames.com', '/account/login', send, extraheaders);
- if Pos('Sorry. Unrecognized username or password.', response) > 0 then begin
- if Pos('The confirmation code is not correct.', response) > 0 then
- LastErrorCode := ERROR_INVALID_CAPTCHA
- else
- LastErrorCode := ERROR_INVALID_CREDENTIALS;
- Exit;
- end;
- InternetGetCookie('http://www.aeriagames.com/', nil, nil, mycookieLength);
- if mycookieLength = 0 then Exit;
- mycookie := GetMemory(mycookieLength + 1);
- InternetGetCookie('http://www.aeriagames.com/', nil, mycookie, mycookieLength);
- Cookies := string(mycookie);
- LoggedIn := True;
- End;
- Constructor TAeria.Create(user, pass:String);
- var
- send, extraheaders, response:string;
- mycookie:PChar;
- mycookieLength:Cardinal;
- Begin
- LoggedIn := False;
- send := 'op=Log+in&edit%5Bmethod%5D=&edit%5Bform_id%5D=account_login' +
- '&' + url_encode('edit[id]') + '=' + url_encode(user) +
- '&' + url_encode('edit[pass]') + '=' + url_encode(pass) +
- '&recaptcha_challenge_field=' + '' +
- '&recaptcha_response_field=' + '';
- extraheaders := 'Content-Type: application/x-www-form-urlencoded' + #13#10;
- response := PostHTTPRequest('www.aeriagames.com', '/account/login', send, extraheaders);
- if Pos('Sorry. Unrecognized username or password.', response) > 0 then begin
- if Pos('The confirmation code is not correct.', response) > 0 then
- LastErrorCode := ERROR_INVALID_CAPTCHA
- else
- LastErrorCode := ERROR_INVALID_CREDENTIALS;
- Exit;
- end;
- InternetGetCookie('http://www.aeriagames.com/', nil, nil, mycookieLength);
- if mycookieLength = 0 then Exit;
- mycookie := GetMemory(mycookieLength + 1);
- InternetGetCookie('http://www.aeriagames.com/', nil, mycookie, mycookieLength);
- Cookies := string(mycookie);
- LoggedIn := True;
- end;
- }
- Constructor TAeria.Create(user, pass:String);
- var
- send, extraheaders, response:string;
- mycookie:PChar;
- mycookieLength:Cardinal;
- Begin
- Cookies := '';
- EMail := '';
- AccID := '';
- PassWord := '';
- FormToken := '';
- ReCaptchaChallengeField := '';
- RecaptchaResponse := '';
- LastErrorCode := INVALID_NONE;
- LoggedIn := False;
- send := 'edit[id]=' + url_encode(user) + '&edit[pass]=' + url_encode(pass) + '&ajax_close_button=Cancel&op=Log%20in&edit[method]=ajax&edit[form_id]=account_login&action=submit';
- extraheaders := 'Content-Type: application/x-www-form-urlencoded' + #13#10 + 'Accept: text/html, application/xhtml+xml, */*';
- response := PostHTTPSRequest('www.aeriagames.com', '/account/login/ajax', send, extraheaders);
- {s := TStringList.Create;
- s.Text := response;
- s.SaveToFile(ExtractFilePath(paramstr(0)) + 'v.html');
- }
- if Pos('Sorry. Unrecognized username or password.', response) > 0 then begin
- if Pos('The confirmation code is not correct.', response) > 0 then
- LastErrorCode := INVALID_CAPTCHA
- else
- LastErrorCode := INVALID_CREDENTIALS;
- Exit;
- end;
- if Pos('Login successful. Redirecting to your home page.', response) = 0 then begin
- LastErrorCode := INVALID_UNKNOWN;
- Exit;
- end;
- InternetGetCookie('https://www.aeriagames.com/', nil, nil, mycookieLength);
- if mycookieLength > 0 then begin
- mycookie := GetMemory(mycookieLength + 1);//or I could do SetLength(Cookies, mycookielength) and then for the pchar put @cookies[1]
- InternetGetCookie('https://www.aeriagames.com/', nil, mycookie, mycookieLength);
- Cookies := string(mycookie);
- FreeMemory(mycookie);
- end;
- LoggedIn := True;
- password := pass;
- LastErrorCode := INVALID_NONE;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement