Revision | 9 (tree) |
---|---|
Time | 2020-05-01 06:39:58 |
Author | ![]() |
O procedimento de logout foi removido. Em seu lugar foi implementada a exclusão de cookies, a qual é feita toda vez que se inicia a aplicação, antes da verificação do estado de logado (IsLoggedIn)
Utilizados métodos repaint para ver se resolve o problema da tela de status ficar preta
@@ -3,7 +3,8 @@ | ||
3 | 3 | interface |
4 | 4 | |
5 | 5 | uses |
6 | - System.SysUtils, System.Classes, ExtCtrls, UConfigurations, KRK.Vcl.Forms.FormBlender; | |
6 | + System.SysUtils, System.Classes, ExtCtrls, UConfigurations, | |
7 | + KRK.Vcl.Forms.FormBlender; | |
7 | 8 | |
8 | 9 | type |
9 | 10 | TUserInformation = record |
@@ -17,14 +18,6 @@ | ||
17 | 18 | lsd: String; |
18 | 19 | end; |
19 | 20 | |
20 | - TLogoutParameters = record | |
21 | - url: String; | |
22 | - jazoest: String; | |
23 | - fb_dtsg: String; | |
24 | - ref: String; | |
25 | - h: String; | |
26 | - end; | |
27 | - | |
28 | 21 | TPublicationType = (ptUnknown, ptTextOnly, ptTextAndAttachment, ptTextAndLink); |
29 | 22 | |
30 | 23 | TPublicationParameters = record |
@@ -48,15 +41,10 @@ | ||
48 | 41 | { Private declarations } |
49 | 42 | FUserInformation: TUserInformation; |
50 | 43 | FLoginParameters: TLoginParameters; |
51 | - FLogoutParameters: TLogoutParameters; | |
52 | 44 | FB: TKRKFormBlender; |
53 | 45 | procedure GetProfilePicture(AUserId: String; AImage: TImage); |
54 | 46 | function ParseUserInformation(APageContents: TStream): TUserInformation; |
55 | 47 | function ParseLoginParameters(APageContents: TStream): TLoginParameters; |
56 | - // Esta função obtém todos os parâmetros necessários para que seja possível | |
57 | - // se executar um logout, portanto essa função só deve ser executada para | |
58 | - // realizar parser em uma página logada | |
59 | - function ParseLogoutParameters(APageContents: TStream): TLogoutParameters; | |
60 | 48 | procedure ConfigToProgram; |
61 | 49 | procedure ProgramToConfig; |
62 | 50 | function GetGroupInfo(AGroupUrl: String; out AGroupInfo: TGroupInfo): Boolean; |
@@ -72,10 +60,13 @@ | ||
72 | 60 | // usuário não está logado, esta função vai preencher FLoginParameters com |
73 | 61 | // os parâmetros necessários utilizados dentro da função Login. Esta função |
74 | 62 | // PRECISA SER EXECUTADA SEMPRE, ANTES DE QUALQUER OUTRA, POR ISSO ELA ESTÁ |
75 | - // COLOCADA NO ONSHOW DO FORM | |
63 | + // COLOCADA NO ONSHOW DO FORM. | |
76 | 64 | function IsLoggedIn: Boolean; |
77 | 65 | function Login: Boolean; |
78 | - function Logout: Boolean; | |
66 | + // O algorítmo de logout é falho e faz com que o facebook detecte uma | |
67 | + // tentativa de burlar, bloqueando a conta. Agora, não mais haverá logout e | |
68 | + // antes de entrar no sistema, todos os cookies serão apagados, obrigando um | |
69 | + // login a cada sessão do programa que for iniciada | |
79 | 70 | // Obtém todas as informações necessárias a partir da página da publicação |
80 | 71 | // passada no primeiro parâmetro |
81 | 72 | function GetPublicationParameters(APublicationUrl: String; out APublicationParameters: TPublicationParameters): Boolean; |
@@ -82,6 +73,7 @@ | ||
82 | 73 | // Adiciona as informações de um grupo a lista de grupos da aba de pubç |
83 | 74 | procedure AddGroupToBatchSharing(AGroupUrl: TLabeledEdit); |
84 | 75 | procedure ShareToGroups(AMessage: String; AIncludeOriginalPublication: Boolean); |
76 | + procedure ClearCookies; | |
85 | 77 | end; |
86 | 78 | |
87 | 79 | implementation |
@@ -102,7 +94,6 @@ | ||
102 | 94 | const |
103 | 95 | USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36 OPR/64.0.3417.92'; |
104 | 96 | |
105 | - | |
106 | 97 | { TDAMOPrincipal } |
107 | 98 | |
108 | 99 | procedure TDAMOPrincipal.ConfigToProgram; |
@@ -288,6 +279,11 @@ | ||
288 | 279 | end; |
289 | 280 | end; |
290 | 281 | |
282 | +procedure TDAMOPrincipal.ClearCookies; | |
283 | +begin | |
284 | + DeleteCookie('@facebook.com'); | |
285 | +end; | |
286 | + | |
291 | 287 | procedure TDAMOPrincipal.Wait5Seconds; |
292 | 288 | var |
293 | 289 | TimeOut: Cardinal; |
@@ -330,8 +326,6 @@ | ||
330 | 326 | |
331 | 327 | if not Result then |
332 | 328 | FLoginParameters := ParseLoginParameters(RE.Content) |
333 | - else | |
334 | - FLogoutParameters := ParseLogoutParameters(RE.Content); | |
335 | 329 | finally |
336 | 330 | RE.Content.Free; |
337 | 331 | RO.HttpOpenRequestParams.AcceptTypes.Free; |
@@ -386,65 +380,6 @@ | ||
386 | 380 | end; |
387 | 381 | end; |
388 | 382 | |
389 | -function TDAMOPrincipal.Logout: Boolean; | |
390 | -var | |
391 | - RO: TRequestOptions; | |
392 | - RE: TResponse; | |
393 | -begin | |
394 | - ZeroMemory(@RO,SizeOf(RO)); | |
395 | - ZeroMemory(@RE,SizeOf(RE)); | |
396 | - | |
397 | - RO.AutoClearSSLState := True; | |
398 | - | |
399 | - { InternetOpen } | |
400 | - RO.InternetOpenParams.Agent := USER_AGENT; | |
401 | - RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG; | |
402 | - { InternetConnect } | |
403 | - RO.InternetConnectParams.Service := INTERNET_SERVICE_HTTP; | |
404 | - RO.InternetConnectParams.ServerName := PChar(FLogoutParameters.Url); | |
405 | - { HttpOpenRequest } | |
406 | - RO.HttpOpenRequestParams.AcceptTypes := TStringList.Create; | |
407 | - RO.HttpOpenRequestParams.AcceptTypes.Text := '*/*'; | |
408 | - RO.HttpOpenRequestParams.AutoDetectHTTPS := True; | |
409 | - RO.HttpOpenRequestParams.Flags := INTERNET_FLAG_NO_CACHE_WRITE or INTERNET_FLAG_PRAGMA_NOCACHE; | |
410 | - RO.HttpOpenRequestParams.Verb := 'POST'; | |
411 | - RO.HttpOpenRequestParams.Headers := TStringList.Create; | |
412 | - RO.HttpOpenRequestParams.Headers.Add('Content-Type: application/x-www-form-urlencoded'); | |
413 | - { HttpSendRequest } | |
414 | - RO.HttpSendRequestParams.IgnoreInvalidCertificateCA := True; | |
415 | - | |
416 | - with TStringList.Create do | |
417 | - try | |
418 | - StrictDelimiter := True; | |
419 | - Delimiter := '&'; | |
420 | - | |
421 | - Add('jazoest=' + FLogoutParameters.jazoest); | |
422 | - Add('fb_dtsg=' + TNetEncoding.URL.Encode(FLogoutParameters.fb_dtsg)); | |
423 | - Add('ref=' + FLogoutParameters.ref); | |
424 | - Add('h=' + TNetEncoding.URL.Encode(FLogoutParameters.h)); | |
425 | - | |
426 | - RO.Content := TStringStream.Create(DelimitedText); | |
427 | - finally | |
428 | - Free; | |
429 | - end; | |
430 | - | |
431 | - RE.Content := TStringStream.Create(''); | |
432 | - Screen.Cursor := crHourGlass; | |
433 | - try | |
434 | - Request(RO, RE); | |
435 | - | |
436 | - Result := not IsLoggedIn; // Também prepara o programa para um próximo login | |
437 | - | |
438 | - TStringStream(RE.Content).SaveToFile('D:\pagina.html'); | |
439 | - finally | |
440 | - RE.Content.Free; | |
441 | - RO.Content.Free; | |
442 | - RO.HttpOpenRequestParams.AcceptTypes.Free; | |
443 | - RO.HttpOpenRequestParams.Headers.Free; | |
444 | - Screen.Cursor := crDefault; | |
445 | - end; | |
446 | -end; | |
447 | - | |
448 | 383 | function TDAMOPrincipal.ParseLoginParameters(APageContents: TStream): TLoginParameters; |
449 | 384 | var |
450 | 385 | HD: OleVariant; |
@@ -482,207 +417,6 @@ | ||
482 | 417 | end; |
483 | 418 | end; |
484 | 419 | |
485 | -function TDAMOPrincipal.ParseLogoutParameters(APageContents: TStream): TLogoutParameters; | |
486 | -var | |
487 | - JS: String; | |
488 | - JO: TJSONObject; | |
489 | -begin | |
490 | - ZeroMemory(@Result,SizeOf(TLogoutParameters)); | |
491 | - | |
492 | - // Primeiramente faz um parser para obter os parâmetros necessários para | |
493 | - // realizar uma requisição (que originalmente seria XHR) e assim obter, | |
494 | - // finalmente, os parâmetros para realizar o logout. Serão estes parâmetros a | |
495 | - // serem persistidos | |
496 | - if RegExMatch(TStringStream(APageContents).DataString | |
497 | - ,'\{"server_revision":\d*,"client_revision":\d*,"tier":".*","push_phase":".*","pkg_cohort":".*","pr":\d*,"'+'haste_site":".*","be_one_ahead":.*,"ir_on":.*,"is_rtl":.*,"is_comet":.*,"hsi":".*","spin":\d*,"__spin_r":\d*,"__spin_b":".*","__spin_t":\d*,"vip":"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"\}' | |
498 | - ,0 | |
499 | - ,1 | |
500 | - ,True | |
501 | - ,[preCaseLess] | |
502 | - ,JS) then | |
503 | - begin | |
504 | - var hsi: String; | |
505 | - var pkg_cohort: String; | |
506 | - var client_revision: String; | |
507 | - var __spin_b: String; | |
508 | - var __spin_r: String; | |
509 | - var __spin_t: String; | |
510 | - | |
511 | - JO := TJSONObject.ParseJSONValue(JS) as TJSONObject; | |
512 | - try | |
513 | - hsi := JO.GetValue<String>('hsi'); | |
514 | - pkg_cohort := JO.GetValue<String>('pkg_cohort'); | |
515 | - client_revision := JO.GetValue<String>('client_revision'); | |
516 | - __spin_b := JO.GetValue<String>('__spin_b'); | |
517 | - __spin_r := JO.GetValue<String>('__spin_r'); | |
518 | - __spin_t := JO.GetValue<String>('__spin_t'); | |
519 | - finally | |
520 | - JO.Free; | |
521 | - end; | |
522 | - | |
523 | - var HD: OleVariant; | |
524 | - var EL: OleVariant; | |
525 | - var i: Cardinal; | |
526 | - | |
527 | - // O resto das informações está em um código comentado dentro da página. | |
528 | - // Abaixo estamos obtendo o código que está no comentário e refazemos o | |
529 | - // parser para obter o que precisamos | |
530 | - HD := coHTMLDocument.Create as IHTMLDocument2; | |
531 | - HD.Write(TStringStream(APageContents).DataString); | |
532 | - HD.close; | |
533 | - | |
534 | - var fb_dtsg: String; | |
535 | - var jazoest: String; | |
536 | - | |
537 | - for i := 0 to HD.getElementsByTagName('code').length - 1 do | |
538 | - begin | |
539 | - EL := HD.getElementsByTagName('code').item(i); | |
540 | - | |
541 | - if Pos('/ajax/updatestatus.php',EL.innerHtml) <> 0 then | |
542 | - begin | |
543 | - HD.Write(EL.children[0].nodeValue); | |
544 | - HD.close; | |
545 | - Break; | |
546 | - end; | |
547 | - end; | |
548 | - | |
549 | - jazoest := HD.getElementsByName('jazoest').item[0].value; | |
550 | - fb_dtsg := HD.getElementsByName('fb_dtsg').item[0].value; | |
551 | - | |
552 | - // A seguir vem o código que finalmente faz a requisição XHR para, | |
553 | - // finalmente, obter os parâmetros de logout | |
554 | - var RO: TRequestOptions; | |
555 | - var RE: TResponse; | |
556 | - | |
557 | - ZeroMemory(@RO,SizeOf(RO)); | |
558 | - ZeroMemory(@RE,SizeOf(RE)); | |
559 | - | |
560 | - RO.AutoClearSSLState := True; | |
561 | - { InternetOpen } | |
562 | - RO.InternetOpenParams.Agent := USER_AGENT; | |
563 | - RO.InternetOpenParams.AccessType := INTERNET_OPEN_TYPE_PRECONFIG; | |
564 | - { InternetConnect } | |
565 | - RO.InternetConnectParams.Service := INTERNET_SERVICE_HTTP; | |
566 | - RO.InternetConnectParams.ServerName := 'https://www.facebook.com/bluebar/modern_settings_menu/?help_type=364455653583099&show_contextual_help=1'; | |
567 | - { HttpOpenRequest } | |
568 | - RO.HttpOpenRequestParams.AcceptTypes := TStringList.Create; | |
569 | - RO.HttpOpenRequestParams.AcceptTypes.Text := '*/*'; | |
570 | - RO.HttpOpenRequestParams.AutoDetectHTTPS := True; | |
571 | - RO.HttpOpenRequestParams.Flags := INTERNET_FLAG_NO_CACHE_WRITE or INTERNET_FLAG_PRAGMA_NOCACHE; | |
572 | - RO.HttpOpenRequestParams.Verb := 'POST'; | |
573 | - RO.HttpOpenRequestParams.Headers := TStringList.Create; | |
574 | - RO.HttpOpenRequestParams.Headers.Add('Content-Type: application/x-www-form-urlencoded'); | |
575 | - { HttpSendRequest } | |
576 | - RO.HttpSendRequestParams.IgnoreInvalidCertificateCA := True; | |
577 | - | |
578 | -{ | |
579 | - __a: 1 | |
580 | - __beoa: 0 | |
581 | - __comet_req: 0 | |
582 | - __csr: | |
583 | - __dyn: 7AgNe-4amaxx2u6aJGeFxqewRyWzEpF4Wo8oeES2N6wAxu13wFw_x-EK6UnG2OUG4XzEeUG3yczobohx3wCxC78O5UlwkEkxa2m4o4O5E8U5SEd87Cuq1nwhEpKEtxy5UrwFwgEdoK7U2qxOfK786CEWu4EhwIXwABojU8UlzUOmVojwAw_xm3ibxG12Ah9ogUWV8y2G5ojyFE-17z8oxC2i3yeCzEmgK7o88vwEy8ix21RxWEb8bGwCxe1Ty9o9o-7Eoxmm0P8e8e85a1qw | |
584 | - __hsi: 6813849785570917662-0 | |
585 | - __pc: PHASED%3ADEFAULT | |
586 | - __req: 18 | |
587 | - __rev: 1001968261 | |
588 | - __s: z0h4t7%3Acmo2pq%3Apoluka | |
589 | - __spin_b: trunk | |
590 | - __spin_r: 1001968261 | |
591 | - __spin_t: 1586473031 | |
592 | - __user: 100005421272296 | |
593 | - dpr: 1 | |
594 | - fb_dtsg: AQHDY8TLj25X%3AAQGb1FuUpH-w | |
595 | - jazoest: 21930 | |
596 | - pmid: 1 | |
597 | -} | |
598 | - with TStringList.Create do | |
599 | - try | |
600 | - StrictDelimiter := True; | |
601 | - Delimiter := '&'; | |
602 | - | |
603 | - Add('__a=1'); | |
604 | - Add('__beoa=0'); | |
605 | - Add('__comet_req=0'); | |
606 | - Add('__csr='); | |
607 | - //Add('__dyn=7AgNe-4amaxx2u6aJGeFxqewRyWzEpF4Wo8oeES2N6wAxu13wFw_x-EK6Un'+'G2OUG4XzEeUG3yczobohx3wCxC78O5UlwkEkxa2m4o4O5E8U5SEd87Cuq1nwhEpKEtxy5UrwFwgEdoK7U2qxOfK786CEWu4EhwIXwABojU8UlzUOmVojwAw_xm3ibxG12Ah9ogUWV8y2G5ojyFE-17z8oxC2i3yeCzEmgK7o88vwEy8ix21RxWEb8bGwCxe1Ty9o9o-7Eoxmm0P8e8e85a1qw'); | |
608 | - Add('__hsi=' + hsi); | |
609 | - Add('__pc=' + TNetEncoding.URL.Encode(pkg_cohort)); | |
610 | - Add('__req=j'); | |
611 | - Add('__rev=' + client_revision); | |
612 | - //Add('__s=xwknqq%3A388obt%3A7ilsh0'); | |
613 | - Add('__spin_b=' + __spin_b); | |
614 | - Add('__spin_r=' + __spin_r); | |
615 | - Add('__spin_t=' + __spin_t); | |
616 | - Add('__user=' + FUserInformation.ID); | |
617 | - Add('dpr=1'); | |
618 | - Add('fb_dtsg=' + TNetEncoding.URL.Encode(fb_dtsg)); | |
619 | - Add('jazoest=' + jazoest); | |
620 | - Add('pmid=1'); | |
621 | - | |
622 | - RO.Content := TStringStream.Create(DelimitedText); | |
623 | - //SaveToFile('D:\pagina.html'); | |
624 | - finally | |
625 | - Free; | |
626 | - end; | |
627 | - RE.Content := TStringStream.Create(''); | |
628 | - Screen.Cursor := crHourGlass; | |
629 | - try | |
630 | - Request(RO, RE); | |
631 | -// TStringStream(RE.Content).SaveToFile('D:\pagina.html'); | |
632 | - | |
633 | - if RegExMatch(TStringStream(RE.Content).DataString | |
634 | - ,'\{.*\}' | |
635 | - ,0 | |
636 | - ,0 | |
637 | - ,False | |
638 | - ,[] | |
639 | - ,JS) then | |
640 | - begin | |
641 | -// with TStringList.Create do | |
642 | -// try | |
643 | -// Text := JS; | |
644 | -// SaveToFile('D:\pagina.html'); | |
645 | -// finally | |
646 | -// Free; | |
647 | -// end; | |
648 | - JO := TJSONObject.ParseJSONValue(JS) as TJSONObject; | |
649 | - try | |
650 | - var JA: TJSONArray := JO.GetValue<TJSONObject>('jsmods'). | |
651 | - GetValue<TJSONArray>('markup'); | |
652 | - | |
653 | - var JO2: TJSONObject; | |
654 | - | |
655 | - for var JV: TJSONValue in JA do | |
656 | - begin | |
657 | - JO2 := ((JV as TJSONArray).Items[1] as TJSONObject); | |
658 | - | |
659 | - if Pos('<form',JO2.GetValue('__html').Value) = 1 then | |
660 | - begin | |
661 | - HD.Write(JO2.GetValue('__html').Value); | |
662 | - HD.close; | |
663 | - Break; | |
664 | - end; | |
665 | - end; | |
666 | - | |
667 | - Result.Url := HD.getElementsByTagName('form').item[0].action; | |
668 | - Result.Jazoest := HD.getElementsByName('jazoest').item[0].value; | |
669 | - Result.fb_dtsg := HD.getElementsByName('fb_dtsg').item[0].value; | |
670 | - Result.ref := HD.getElementsByName('ref').item[0].value; | |
671 | - Result.h := HD.getElementsByName('h').item[0].value; | |
672 | - finally | |
673 | - JO.Free; | |
674 | - end; | |
675 | - end; | |
676 | - finally | |
677 | - RE.Content.Free; | |
678 | - RO.Content.Free; | |
679 | - RO.HttpOpenRequestParams.AcceptTypes.Free; | |
680 | - RO.HttpOpenRequestParams.Headers.Free; | |
681 | - Screen.Cursor := crDefault; | |
682 | - end; | |
683 | - end; | |
684 | -end; | |
685 | - | |
686 | 420 | function TDAMOPrincipal.ParseUserInformation(APageContents: TStream): TUserInformation; |
687 | 421 | var |
688 | 422 | JS: String; |
@@ -724,10 +458,8 @@ | ||
724 | 458 | end; |
725 | 459 | |
726 | 460 | TFORMPrincipal(Owner).FocusControl(nil); // garante que botões desabilitados não fiquem com o estilo focado (gambiarra!) |
727 | - TFORMPrincipal(Owner).PNBBLogout.Enabled := Result.ID <> ''; | |
728 | - TFORMPrincipal(Owner).PNBBLogin.Enabled := not TFORMPrincipal(Owner).PNBBLogout.Enabled; | |
729 | - // TFORMPrincipal(Owner).PNBBLogout.Enabled = usuário logado! | |
730 | - TFORMPrincipal(Owner).TASHBatchSharingToGroups.TabVisible := TFORMPrincipal(Owner).PNBBLogout.Enabled; | |
461 | + TFORMPrincipal(Owner).PNBBLogin.Enabled := not (Result.ID <> ''); | |
462 | + TFORMPrincipal(Owner).TASHBatchSharingToGroups.TabVisible := (Result.ID <> ''); | |
731 | 463 | TFORMPrincipal(Owner).LAEDEmail.Enabled := TFORMPrincipal(Owner).PNBBLogin.Enabled; |
732 | 464 | TFORMPrincipal(Owner).LAEDPassword.Enabled := TFORMPrincipal(Owner).LAEDEmail.Enabled; |
733 | 465 | end; |
@@ -42,7 +42,6 @@ | ||
42 | 42 | PNBBLogin: TPngBitBtn; |
43 | 43 | Image1: TImage; |
44 | 44 | TASHBatchSharingToGroups: TTabSheet; |
45 | - PNBBLogout: TPngBitBtn; | |
46 | 45 | LABENome: TLabel; |
47 | 46 | LABEID: TLabel; |
48 | 47 | CHLBGroups: TCheckListBox; |
@@ -57,9 +56,9 @@ | ||
57 | 56 | Label1: TLabel; |
58 | 57 | TASHAbout: TTabSheet; |
59 | 58 | Image2: TImage; |
59 | + Button1: TButton; | |
60 | 60 | procedure PNBBLoginClick(Sender: TObject); |
61 | 61 | procedure FormShow(Sender: TObject); |
62 | - procedure PNBBLogoutClick(Sender: TObject); | |
63 | 62 | procedure PNBBAddGroupToBatchClick(Sender: TObject); |
64 | 63 | procedure PNBBShareClick(Sender: TObject); |
65 | 64 | procedure LAEDPostURLChange(Sender: TObject); |
@@ -112,6 +111,7 @@ | ||
112 | 111 | |
113 | 112 | procedure TFORMPrincipal.FormShow(Sender: TObject); |
114 | 113 | begin |
114 | + FDAMOPrincipal.ClearCookies; | |
115 | 115 | FDAMOPrincipal.IsLoggedIn; |
116 | 116 | end; |
117 | 117 |
@@ -135,11 +135,6 @@ | ||
135 | 135 | FDAMOPrincipal.Login; |
136 | 136 | end; |
137 | 137 | |
138 | -procedure TFORMPrincipal.PNBBLogoutClick(Sender: TObject); | |
139 | -begin | |
140 | - FDAMOPrincipal.Logout; | |
141 | -end; | |
142 | - | |
143 | 138 | procedure TFORMPrincipal.PNBBShareClick(Sender: TObject); |
144 | 139 | begin |
145 | 140 | if (not MEMOPostMessage.IsClear) or (Application.MessageBox('Your publication has no message. Are you sure?','Hey Yo!',MB_ICONQUESTION or MB_YESNO) = IDYES) then |