From eff5f1daa73c9ee507999e0a9dfc952f4e77c030 Mon Sep 17 00:00:00 2001 From: Andre Bongon Date: Fri, 12 Aug 2016 22:52:43 +0900 Subject: [PATCH 1/5] FreeFB Transport Untested code. Will "work" only on countries that has access to free.facebook.com I don't know if this works either. I need to test it but I don't have go runtime on my pc :) --- transport_freefb.go | 107 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 transport_freefb.go diff --git a/transport_freefb.go b/transport_freefb.go new file mode 100644 index 0000000..38a0ff9 --- /dev/null +++ b/transport_freefb.go @@ -0,0 +1,107 @@ +package transports + +import ( + "errors" + "fmt" + "github.com/headzoo/surf" + "github.com/headzoo/surf/browser" + "io/ioutil" + "net/http" +) + +type FreeFBTransport struct { + *Transport + Login string + Password string + Friend string + Browser *browser.Browser + Serializer DefaultSerializer + ChatUrl string +} + +func (t *FreeFBTransport) DoLogin() bool { + fmt.Println("FreeFBTransport, Login()") + err := t.Browser.Open("https://free.facebook.com/") + if err != nil { + panic(err) + } + + LoginForm := t.Browser.Forms()[1] + LoginForm.Input("email", t.Login) + LoginForm.Input("pass", t.Password) + if LoginForm.Submit() != nil { + panic(err) + } + + err = t.Browser.Open("https://free.facebook.com/profile.php") + + if err != nil { + panic(err) + } + + fmt.Println("Logged in as", t.Browser.Title(), "?") + + FriendUrl := fmt.Sprintf("https://free.facebook.com/%s", t.Friend) + err = t.Browser.Open(FriendUrl) + + if err != nil { + panic(err) + } + + t.Browser.Click("a[href*=\"/messages/thread/\"]") + + t.ChatUrl = t.Browser.Url().String() + + return true + +} + +func (t *FreeFBTransport) Prepare() { + fmt.Println("FreeFBTransport, Prepare()") + + t.Serializer = DefaultSerializer{} + + t.Browser = surf.NewBrowser() + + if !t.DoLogin() { + err := errors.New("Authentication error!") + panic(err) + } + + return +} + +func (t *FreeFBTransport) Handler(w http.ResponseWriter, originalRequest *http.Request) { + + t.Browser.Open(t.ChatUrl) + + client := &http.Client{} + + request, _ := http.NewRequest(originalRequest.Method, originalRequest.URL.String(), nil) + + serializedRequest := t.Serializer.Serialize(request, true).([]byte) + + fmt.Println("Got", originalRequest) + fmt.Println("Serialized", string(serializedRequest)) + + MessageForm, _ := t.Browser.Form("#composerInput") + MessageForm.Input("body", string(serializedRequest)) + MessageForm.Submit() + + resp, _ := client.Do(request) + b, _ := ioutil.ReadAll(resp.Body) + resp.Body.Close() + + w.Write(b) + + return +} + +func (t *FreeFBTransport) Listen() { + fmt.Println("FreeFBTransport, Listen()") + t.Prepare() + fmt.Println("Polling...") + for { + } + return +} From f2ff3f9c88c546baeba189f48cb9e25b95ce21d0 Mon Sep 17 00:00:00 2001 From: Andre Bongon Date: Tue, 23 Aug 2016 19:34:18 +0900 Subject: [PATCH 2/5] Create main_freefb_client.go Test out free fb client implementation --- examples/main_freefb_client.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/main_freefb_client.go diff --git a/examples/main_freefb_client.go b/examples/main_freefb_client.go new file mode 100644 index 0000000..9c47281 --- /dev/null +++ b/examples/main_freefb_client.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "github.com/joho/godotenv" + "github.com/matiasinsaurralde/transports" + "os" +) + +func main() { + godotenv.Load() + + fmt.Println("Transports test") + + freefbTransport := transports.FreeFBTransport{ + Login: os.Getenv("FB_LOGIN"), + Password: os.Getenv("FB_PASSWORD"), + Friend: os.Getenv("FB_FRIEND"), + } + + Proxy := transports.Proxy{ + Transport: freefbTransport, + Port: 8080, + } + + Proxy.Listen() +} From 755c2ddea6d0838d06a2c35faa88452c4c49bd7c Mon Sep 17 00:00:00 2001 From: Andre Bongon Date: Thu, 25 Aug 2016 19:22:50 +0800 Subject: [PATCH 3/5] Fix the github link to point to mine --- examples/main_freefb_client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/main_freefb_client.go b/examples/main_freefb_client.go index 9c47281..16b0a58 100644 --- a/examples/main_freefb_client.go +++ b/examples/main_freefb_client.go @@ -3,7 +3,7 @@ package main import ( "fmt" "github.com/joho/godotenv" - "github.com/matiasinsaurralde/transports" + "github.com/1Conan/transports" "os" ) From 5051cec8fcc9c2674d1f55da5d3b07a4f0503abe Mon Sep 17 00:00:00 2001 From: Andre Bongon Date: Thu, 1 Sep 2016 22:24:49 +0900 Subject: [PATCH 4/5] Fix panic It's really supposed to be composer_form --- transport_freefb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transport_freefb.go b/transport_freefb.go index 38a0ff9..f378c2d 100644 --- a/transport_freefb.go +++ b/transport_freefb.go @@ -84,7 +84,7 @@ func (t *FreeFBTransport) Handler(w http.ResponseWriter, originalRequest *http.R fmt.Println("Got", originalRequest) fmt.Println("Serialized", string(serializedRequest)) - MessageForm, _ := t.Browser.Form("#composerInput") + MessageForm, _ := t.Browser.Form("#composer_form") MessageForm.Input("body", string(serializedRequest)) MessageForm.Submit() From fc9e20858c44dd0e43cc10b7b9e03305ca4611cc Mon Sep 17 00:00:00 2001 From: Andre Bongon Date: Sun, 4 Sep 2016 13:10:50 +0900 Subject: [PATCH 5/5] Remove unused function. This will only work for clients so the listen function is useless. --- transport_freefb.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/transport_freefb.go b/transport_freefb.go index f378c2d..44a2563 100644 --- a/transport_freefb.go +++ b/transport_freefb.go @@ -96,12 +96,3 @@ func (t *FreeFBTransport) Handler(w http.ResponseWriter, originalRequest *http.R return } - -func (t *FreeFBTransport) Listen() { - fmt.Println("FreeFBTransport, Listen()") - t.Prepare() - fmt.Println("Polling...") - for { - } - return -}