55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
|
)
|
|
|
|
func main() {
|
|
bbbName := "bbbBot"
|
|
bbbURL, _ := url.Parse(os.Args[1])
|
|
|
|
res, err := http.Get(bbbURL.String())
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer res.Body.Close()
|
|
if res.StatusCode != 200 {
|
|
log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
|
|
}
|
|
|
|
doc, err := goquery.NewDocumentFromReader(res.Body)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
form := doc.Find("form")
|
|
authToken, ok := form.Find("input[name='authenticity_token']").Attr("value")
|
|
if !ok {
|
|
log.Fatalln("'authenticity_token' not found")
|
|
}
|
|
res.Body.Close()
|
|
// ----
|
|
res, err = http.PostForm(bbbURL.String(), url.Values{
|
|
"authenticity_token": {authToken},
|
|
fmt.Sprintf("%s[join_name]", bbbURL.Path): {bbbName},
|
|
})
|
|
//defer res.Body.Close()
|
|
if res.StatusCode != 200 {
|
|
log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
|
|
}
|
|
log.Printf("%v", res.Request.Header.Get("Referer"))
|
|
|
|
/* not needed ... websocket
|
|
doc, err = goquery.NewDocumentFromReader(res.Body)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
log.Println(doc.Html())
|
|
*/
|
|
}
|