-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 :)
- Loading branch information
Andre Bongon
authored
Aug 12, 2016
1 parent
e805fc6
commit eff5f1d
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |