Advertisement
Guest User

Untitled

a guest
Dec 1st, 2013
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.76 KB | None | 0 0
  1. unit AeriaAPI;
  2. interface uses Windows, uFunc, WININET, Jpeg, Graphics, SysUtils, Classes;
  3. const
  4. INVALID_CAPTCHA = 0;
  5. INVALID_PASSWORD = 1;
  6. INVALID_TOKEN = 2;
  7. INVALID_COOKIES = 3;
  8. INVALID_NONE = 4;
  9. INVALID_UNKNOWN = 5;
  10. INVALID_CREDENTIALS = 6;
  11. type
  12. TAeria = class
  13. private
  14. Cookies, EMail, AccID, PassWord, FormToken:String;
  15. LoggedIn:Boolean;
  16. LastErrorCode:Integer;
  17. ReCaptchaChallengeField, RecaptchaResponse:String;
  18. public
  19. function AeriaSetEmail(newemail:String):Boolean;
  20. function AeriaSetPass(newpass:String):Boolean;
  21. function GetData():Boolean;
  22. Procedure ReLogin(user, pass:String);
  23. Procedure SetCaptcha(response:String);
  24. function GetCaptchaImage(image:TPicture):Boolean;
  25. Property IsLoggedIn:Boolean read LoggedIn;
  26. Property GetCookies:String read Cookies;
  27. Property Error:Integer read LastErrorCode;
  28. Property GetEmail:String read EMail;
  29. Property AccountID:String read AccID;
  30. //constructor Create(user, pass:String);overload;
  31. published
  32. constructor Create(user, pass:String);
  33. //constructor Create(user, pass, CaptchaQuestion, CaptchaAnswer:String);overload;
  34. end;
  35. implementation
  36. function TAeria.AeriaSetPass(newpass:String):Boolean;
  37. var
  38. data, extraheaders, resul:string;
  39. const
  40. boundary:String = '-----------------------------7dd29641c076a'#13#10;
  41. rnrn:String = #13#10#13#10;
  42. begin
  43. Result := False;
  44. data := boundary + 'Content-Disposition: form-data; name="edit[mail]"' + rnrn + EMail + #13#10 +
  45. boundary + 'Content-Disposition: form-data; name="edit[pass_current_for_mail]"' + rnrn + '' + #13#10 +
  46. boundary + 'Content-Disposition: form-data; name="edit[pass_current]"' + rnrn + password + #13#10 +
  47. boundary + 'Content-Disposition: form-data; name="edit[pass][pass1]"' + rnrn + newpass +#13#10 +
  48. boundary + 'Content-Disposition: form-data; name="edit[pass][pass2]"' + rnrn + newpass + #13#10 +
  49. boundary + 'Content-Disposition: form-data; name="edit[change_email]"' + rnrn + '0' + #13#10 +
  50. boundary + 'Content-Disposition: form-data; name="edit[change_pass]"' + rnrn + '1' + #13#10 +
  51. boundary + 'Content-Disposition: form-data; name="edit[form_token]"' + rnrn + formtoken + #13#10 +
  52. boundary + 'Content-Disposition: form-data; name="edit[form_id]"' + rnrn + 'user_edit'#13#10 +
  53. boundary + 'Content-Disposition: form-data; name="recaptcha_challenge_field"' + rnrn + ReCaptchaChallengeField + #13#10 +
  54. boundary + 'Content-Disposition: form-data; name="recaptcha_response_field"' + rnrn + RecaptchaResponse + #13#10 +
  55. boundary + 'Content-Disposition: form-data; name="op"' + rnrn + 'Submit'#13#10 + Copy(boundary, 1, Length(boundary) - 2) + '--'#13#10;;
  56. extraheaders := 'Content-Type: multipart/form-data; boundary=' + boundary + #13#10 + 'Accept: text/html, application/xhtml+xml, */*'#13#10 + 'Cookie: ' + Cookies + #13#10;
  57. resul := PostHTTPRequest('www.aeriagames.com', '/user/' + accID + '/edit/account', data, extraheaders);
  58. if (Pos('Current password not recognized', resul) > 0) and (Pos('The confirmation code is not correct.', resul) > 0) then begin
  59. LastErrorCode := INVALID_CAPTCHA;
  60. Exit;
  61. end;
  62. if (Pos('Current password not recognized', resul) > 0) then begin
  63. LastErrorCode := INVALID_PASSWORD;
  64. Exit;
  65. end;
  66. if (Pos('The confirmation code is not correct.', Resul) > 0) then begin
  67. LastErrorCode := INVALID_CAPTCHA;
  68. Exit;
  69. end;
  70. //Validation error, please try again. If this error persists, please contact the site administrator.
  71. if (Pos('Validation error, please try again. If this error persists, please contact the site administrator.', resul) > 0) then begin
  72. LastErrorCode := INVALID_TOKEN;
  73. Exit;
  74. end;
  75. if Pos('You are not authorized to access this page.', resul) > 0 then begin
  76. LastErrorCode := INVALID_COOKIES;
  77. Exit;
  78. end;
  79. LastErrorCode := INVALID_NONE;
  80. end;
  81. function TAeria.GetData():Boolean;
  82. var
  83. d, e:string;
  84. begin
  85. Result := False;
  86. d := GETHTTPSRequest('www.aeriagames.com', '/privatemsg', 'Cookie: '+ Cookies);
  87. if Pos('href="//www.aeriagames.com/privatemsg" title="My Inbox">My Inbox', d) = 0 then Exit;
  88. Delete(d, 1, Pos('href="//www.aeriagames.com/privatemsg" title="My Inbox">My Inbox', d) + 70);
  89. Delete(d, 1, Pos('href="', d) + 5);
  90. d := copy(d, 1, Pos('"', d));
  91. Delete(d, 1, Pos('//www.aeriagames.com/user/', d) + 25);
  92. d := copy(d, 1, Pos('/', d) - 1);
  93. AccID := d;
  94. //http://www.aeriagames.com/user/92222799/edit/account
  95. d := GETHTTPSRequest('www.aeriagames.com', '/user/' + AccID + '/edit/account','Cookie: '+ Cookies + #13#10);
  96. e := d;
  97. if Pos('<span class="form-no-edit"><span id="edit-current_mail">', d) = 0 then Exit;
  98. Delete(d, 1, Pos('<span class="form-no-edit"><span id="edit-current_mail">', d) + 55);
  99. d := copy(d, 1, Pos('</span>', d) - 1);
  100. EMail := d;
  101. if Pos('<input type="hidden" name="edit[form_token]" id="edit-user-edit-form-token"', e) = 0 then Exit;
  102. Delete(e, 1, Pos('<input type="hidden" name="edit[form_token]" id="edit-user-edit-form-token" ', e));
  103. Delete(e, 1, Pos('value="', e) + 6);
  104. e := copy(e, 1, Pos('"', e) - 1);
  105. formtoken := e;
  106. Result := True;
  107. end;
  108.  
  109. function TAeria.AeriaSetEmail(newemail:String):Boolean;
  110. const
  111. boundary:string = '-----------------------------7dd29641c076a'#13#10;
  112. rnrn:String = #13#10#13#10;
  113. var
  114. data, extraheaders, resul:string;
  115. z:TStringList;
  116. begin
  117. Result := False;
  118. data := boundary + 'Content-Disposition: form-data; name="edit[mail]"' + rnrn + newemail + #13#10 +
  119. boundary + 'Content-Disposition: form-data; name="edit[pass_current_for_mail]"' + rnrn + PassWord + #13#10 +
  120. boundary + 'Content-Disposition: form-data; name="edit[pass_current]"' + rnrn + #13#10 +
  121. boundary + 'Content-Disposition: form-data; name="edit[pass][pass1]"' + rnrn +#13#10 +
  122. boundary + 'Content-Disposition: form-data; name="edit[pass][pass2]"' + rnrn + #13#10 +
  123. boundary + 'Content-Disposition: form-data; name="edit[change_email]"' + rnrn + '1' + #13#10 +
  124. boundary + 'Content-Disposition: form-data; name="edit[change_pass]"' + rnrn + '0' + #13#10 +
  125. boundary + 'Content-Disposition: form-data; name="edit[form_token]"' + rnrn + FormToken + #13#10 +
  126. boundary + 'Content-Disposition: form-data; name="edit[form_id]"' + rnrn + 'user_edit'#13#10 +
  127. boundary + 'Content-Disposition: form-data; name="recaptcha_challenge_field"' + rnrn + ReCaptchaChallengeField + #13#10 +
  128. boundary + 'Content-Disposition: form-data; name="recaptcha_response_field"' + rnrn + RecaptchaResponse + #13#10 +
  129. boundary + 'Content-Disposition: form-data; name="op"' + rnrn + 'Submit'#13#10 + Copy(boundary, 1, Length(boundary) - 2) + '--'#13#10;
  130. extraheaders := 'Content-Type: multipart/form-data; boundary=' + boundary + 'Cookie: ' + Cookies + #13#10 + 'Accept: text/html, application/xhtml+xml, */*'#13#10;
  131. resul := PostHTTPRequest('www.aeriagames.com', '/user/' + AccID + '/edit/account', data, extraheaders);
  132. z := TStringList.Create;
  133. z.Text := resul;
  134. z.SaveToFile(ExtractFilePath(paramstr(0)) + 'fk.html');
  135. z.Free;
  136. if (Pos('Current password not recognized', resul) > 0) and (Pos('The confirmation code is not correct.', resul) > 0) then begin
  137. LastErrorCode := INVALID_CAPTCHA;
  138. Exit;
  139. end;
  140. if (Pos('Current password not recognized', resul) > 0) then begin
  141. LastErrorCode := INVALID_PASSWORD;
  142. Exit;
  143. end;
  144. if (Pos('The confirmation code is not correct.', Resul) > 0) then begin
  145. LastErrorCode := INVALID_CAPTCHA;
  146. Exit;
  147. end;
  148. //Validation error, please try again. If this error persists, please contact the site administrator.
  149. if (Pos('Validation error, please try again. If this error persists, please contact the site administrator.', resul) > 0) then begin
  150. LastErrorCode := INVALID_TOKEN;
  151. Exit;
  152. end;
  153. if Pos('You are not authorized to access this page.', resul) > 0 then begin
  154. LastErrorCode := INVALID_COOKIES;
  155. Exit;
  156. end;
  157. if Pos('You will need to confirm the new email address. Further instructions have been sent to', resul) = 0 then begin
  158. LastErrorCode := 99;
  159. Exit;
  160. end;
  161. LastErrorCode := INVALID_NONE;
  162. Result := True;
  163. end;
  164. {Procedure TAeria.ReLogin(user, pass:String);
  165. var
  166. send, extraheaders, response:string;
  167. mycookie:PChar;
  168. mycookieLength:Cardinal;
  169. Begin
  170. password := '';
  171. LoggedIn := False;
  172. send := 'op=Log+in&edit%5Bmethod%5D=&edit%5Bform_id%5D=account_login' +
  173. '&' + url_encode('edit[id]') + '=' + url_encode(user) +
  174. '&' + url_encode('edit[pass]') + '=' + url_encode(pass) +
  175. '&recaptcha_challenge_field=' + ReCaptchaChallengeField +
  176. '&recaptcha_response_field=' + RecaptchaResponse;
  177. extraheaders := 'Content-Type: application/x-www-form-urlencoded' + #13#10;
  178. response := PostHTTPSRequest('www.aeriagames.com', '/account/login', send, extraheaders);
  179. if Pos('Sorry. Unrecognized username or password.', response) > 0 then begin
  180. if Pos('The confirmation code is not correct.', response) > 0 then
  181. LastErrorCode := INVALID_CAPTCHA
  182. else
  183. LastErrorCode := INVALID_CREDENTIALS;
  184. Exit;
  185. end;
  186. InternetGetCookie('https://www.aeriagames.com/', nil, nil, mycookieLength);
  187. if mycookieLength > 0 then begin
  188. mycookie := GetMemory(mycookieLength + 1);
  189. InternetGetCookie('https://www.aeriagames.com/', nil, mycookie, mycookieLength);
  190. Cookies := string(mycookie);
  191. end
  192. else
  193. Cookies := '';
  194. LoggedIn := True;
  195. password := pass;
  196. LastErrorCode := INVALID_NONE;
  197. end;}
  198. Procedure TAeria.ReLogin(user, pass:String);
  199. var
  200. send, extraheaders, response:string;
  201. mycookie:PChar;
  202. mycookieLength:Cardinal;
  203. Begin
  204. password := '';
  205. LastErrorCode := INVALID_NONE;
  206. LoggedIn := False;
  207. 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';
  208.  
  209. extraheaders := 'Content-Type: application/x-www-form-urlencoded' + #13#10 + 'Accept: text/html, application/xhtml+xml, */*';
  210. response := PostHTTPSRequest('www.aeriagames.com', '/account/login/ajax', send, extraheaders);
  211. if Pos('Sorry. Unrecognized username or password.', response) > 0 then begin
  212. if Pos('The confirmation code is not correct.', response) > 0 then
  213. LastErrorCode := INVALID_CAPTCHA
  214. else
  215. LastErrorCode := INVALID_CREDENTIALS;
  216. Exit;
  217. end;
  218. if Pos('Login successful. Redirecting to your home page.', response) = 0 then begin
  219. LastErrorCode := INVALID_UNKNOWN;
  220. Exit;
  221. end;
  222. InternetGetCookie('https://www.aeriagames.com/', nil, nil, mycookieLength);
  223. if mycookieLength > 0 then begin
  224. mycookie := GetMemory(mycookieLength + 1);
  225. InternetGetCookie('https://www.aeriagames.com/', nil, mycookie, mycookieLength);
  226. Cookies := string(mycookie);
  227. end
  228. else
  229. Cookies := '';
  230. LoggedIn := True;
  231. password := pass;
  232. LastErrorCode := INVALID_NONE;
  233. end;
  234. Procedure TAeria.SetCaptcha(response:String);
  235. begin
  236. RecaptchaResponse := response;
  237. end;
  238. function TAeria.GetCaptchaImage(image:TPicture):Boolean;
  239. var
  240. a:string;
  241. begin
  242. Result := False;
  243. a := GETHTTPSRequest('www.google.com', '/recaptcha/api/challenge?k=6LcR-MUSAAAAAODqgJEVRJl-lPlhEfZqxaEzRgRq', ''); ///recaptcha/api/noscript?k=6LcR-MUSAAAAAODqgJEVRJl-lPlhEfZqxaEzRgRq don't use!
  244. Delete(a, 1, Pos(' challenge : ''', a) + 13);
  245. a := Copy(a, 1, pos('''', a) - 1);
  246. ReCaptchaChallengeField := a;
  247. DeleteFileA( PChar(ExtractFilePath(ParamStr(0)) + 'captcha.jpg'));
  248. if not GetFile('https://www.google.com/recaptcha/api/image?c=' + a, ExtractFilePath(ParamStr(0)) + 'captcha.jpg') then Exit;
  249. image.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'captcha.jpg');
  250. Result := True;
  251. end;
  252. {
  253. function TAeria.GetCaptchaImage(image:TPicture):Boolean;
  254. var
  255. a ,b:string;
  256. begin
  257. Result := False;
  258. 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 :/
  259. b := a;
  260. Delete(b, 1, Pos('name="recaptcha_challenge_field" id="recaptcha_challenge_field" value="', b) + 70);
  261. b := Copy(b, 1, pos('"', b) - 1);
  262. ReCaptchaChallengeField := b;
  263. b := a;
  264. Delete(b, 1, Pos('<img width="300" height="57" alt="" src="', b) + 40);
  265. b := Copy(b, 1, pos('"', b) - 1);
  266. DeleteFileA( PChar(ExtractFilePath(ParamStr(0)) + 'captcha.jpg'));
  267. if not GetFile('https://www.google.com/recaptcha/api/' + b, ExtractFilePath(ParamStr(0)) + 'captcha.jpg') then Exit;
  268. image.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'captcha.jpg');
  269. Result := True;
  270. end;
  271. }
  272. {constructor TAeria.Create(user, pass, CaptchaQuestion, CaptchaAnswer:String);
  273. var
  274. send, extraheaders, response:string;
  275. mycookie:PChar;
  276. mycookieLength:Cardinal;
  277. Begin
  278. LoggedIn := False;
  279. send := 'op=Log+in&edit%5Bmethod%5D=&edit%5Bform_id%5D=account_login' +
  280. '&' + url_encode('edit[id]') + '=' + url_encode(user) +
  281. '&' + url_encode('edit[pass]') + '=' + url_encode(pass) +
  282. '&recaptcha_challenge_field=' + CaptchaQuestion +
  283. '&recaptcha_response_field=' + CaptchaAnswer;
  284. extraheaders := 'Content-Type: application/x-www-form-urlencoded' + #13#10;
  285. response := PostHTTPRequest('www.aeriagames.com', '/account/login', send, extraheaders);
  286. if Pos('Sorry. Unrecognized username or password.', response) > 0 then begin
  287. if Pos('The confirmation code is not correct.', response) > 0 then
  288. LastErrorCode := ERROR_INVALID_CAPTCHA
  289. else
  290. LastErrorCode := ERROR_INVALID_CREDENTIALS;
  291. Exit;
  292. end;
  293. InternetGetCookie('http://www.aeriagames.com/', nil, nil, mycookieLength);
  294. if mycookieLength = 0 then Exit;
  295. mycookie := GetMemory(mycookieLength + 1);
  296. InternetGetCookie('http://www.aeriagames.com/', nil, mycookie, mycookieLength);
  297. Cookies := string(mycookie);
  298. LoggedIn := True;
  299. End;
  300. Constructor TAeria.Create(user, pass:String);
  301. var
  302. send, extraheaders, response:string;
  303. mycookie:PChar;
  304. mycookieLength:Cardinal;
  305. Begin
  306. LoggedIn := False;
  307. send := 'op=Log+in&edit%5Bmethod%5D=&edit%5Bform_id%5D=account_login' +
  308. '&' + url_encode('edit[id]') + '=' + url_encode(user) +
  309. '&' + url_encode('edit[pass]') + '=' + url_encode(pass) +
  310. '&recaptcha_challenge_field=' + '' +
  311. '&recaptcha_response_field=' + '';
  312. extraheaders := 'Content-Type: application/x-www-form-urlencoded' + #13#10;
  313. response := PostHTTPRequest('www.aeriagames.com', '/account/login', send, extraheaders);
  314. if Pos('Sorry. Unrecognized username or password.', response) > 0 then begin
  315. if Pos('The confirmation code is not correct.', response) > 0 then
  316. LastErrorCode := ERROR_INVALID_CAPTCHA
  317. else
  318. LastErrorCode := ERROR_INVALID_CREDENTIALS;
  319. Exit;
  320. end;
  321. InternetGetCookie('http://www.aeriagames.com/', nil, nil, mycookieLength);
  322. if mycookieLength = 0 then Exit;
  323. mycookie := GetMemory(mycookieLength + 1);
  324. InternetGetCookie('http://www.aeriagames.com/', nil, mycookie, mycookieLength);
  325. Cookies := string(mycookie);
  326. LoggedIn := True;
  327. end;
  328. }
  329. Constructor TAeria.Create(user, pass:String);
  330. var
  331. send, extraheaders, response:string;
  332. mycookie:PChar;
  333. mycookieLength:Cardinal;
  334. Begin
  335. Cookies := '';
  336. EMail := '';
  337. AccID := '';
  338. PassWord := '';
  339. FormToken := '';
  340. ReCaptchaChallengeField := '';
  341. RecaptchaResponse := '';
  342. LastErrorCode := INVALID_NONE;
  343. LoggedIn := False;
  344. 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';
  345.  
  346. extraheaders := 'Content-Type: application/x-www-form-urlencoded' + #13#10 + 'Accept: text/html, application/xhtml+xml, */*';
  347. response := PostHTTPSRequest('www.aeriagames.com', '/account/login/ajax', send, extraheaders);
  348. {s := TStringList.Create;
  349. s.Text := response;
  350. s.SaveToFile(ExtractFilePath(paramstr(0)) + 'v.html');
  351. }
  352. if Pos('Sorry. Unrecognized username or password.', response) > 0 then begin
  353. if Pos('The confirmation code is not correct.', response) > 0 then
  354. LastErrorCode := INVALID_CAPTCHA
  355. else
  356. LastErrorCode := INVALID_CREDENTIALS;
  357. Exit;
  358. end;
  359. if Pos('Login successful. Redirecting to your home page.', response) = 0 then begin
  360. LastErrorCode := INVALID_UNKNOWN;
  361. Exit;
  362. end;
  363. InternetGetCookie('https://www.aeriagames.com/', nil, nil, mycookieLength);
  364. if mycookieLength > 0 then begin
  365. mycookie := GetMemory(mycookieLength + 1);//or I could do SetLength(Cookies, mycookielength) and then for the pchar put @cookies[1]
  366. InternetGetCookie('https://www.aeriagames.com/', nil, mycookie, mycookieLength);
  367. Cookies := string(mycookie);
  368. FreeMemory(mycookie);
  369. end;
  370.  
  371. LoggedIn := True;
  372. password := pass;
  373. LastErrorCode := INVALID_NONE;
  374. end;
  375.  
  376.  
  377.  
  378.  
  379. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement