Exemple #1
0
func NewClient() (client *http.Client) {
	client = new(http.Client)
	client.Transport = DefaultTransport
	DefaultTransport.CloseIdleConnections()
	client.Jar, _ = cookiejar.New(options)
	return
}
Exemple #2
0
// Used to create a new SuperAgent object.
func New() *SuperAgent {
	cookiejarOptions := cookiejar.Options{
		PublicSuffixList: publicsuffix.List,
	}
	jar, _ := cookiejar.New(&cookiejarOptions)
	s := &SuperAgent{
		TargetType:        "json",
		Data:              make(map[string]interface{}),
		Header:            make(map[string]string),
		RawString:         "",
		SliceData:         []interface{}{},
		FormData:          url.Values{},
		QueryData:         url.Values{},
		BounceToRawString: false,
		Client:            &http.Client{Jar: jar},
		Transport:         &http.Transport{},
		Cookies:           make([]*http.Cookie, 0),
		Errors:            nil,
		BasicAuth:         struct{ Username, Password string }{},
		Debug:             false,
		CurlCommand:       false,
		logger:            log.New(os.Stderr, "[gorequest]", log.LstdFlags),
	}
	// desable keep alives by default, see this issue https://github.com/parnurzeal/gorequest/issues/75
	s.Transport.DisableKeepAlives = true
	return s
}
Exemple #3
0
// Used to create a new SuperAgent object.
func New() *SuperAgent {
	cookiejarOptions := cookiejar.Options{
		PublicSuffixList: publicsuffix.List,
	}
	jar, _ := cookiejar.New(&cookiejarOptions)
	s := &SuperAgent{
		TargetType:        "json",
		Data:              make(map[string]interface{}),
		Header:            make(map[string]string),
		RawString:         "",
		SliceData:         []interface{}{},
		FormData:          url.Values{},
		QueryData:         url.Values{},
		BounceToRawString: false,
		Client:            &http.Client{Jar: jar},
		Transport:         &http.Transport{},
		Cookies:           make([]*http.Cookie, 0),
		Errors:            nil,
		BasicAuth:         struct{ Username, Password string }{},
		Debug:             false,
		CurlCommand:       false,
		logger:            log.New(os.Stderr, "[gorequest]", log.LstdFlags),
	}
	return s
}
Exemple #4
0
func New(opts map[string]interface{}) *Cli {
	homedir := homedir()
	cookieJar, _ := cookiejar.New(nil)
	endpoint, _ := opts["endpoint"].(string)
	url, _ := url.Parse(strings.TrimRight(endpoint, "/"))

	transport := &http.Transport{
		TLSClientConfig: &tls.Config{},
	}

	if project, ok := opts["project"].(string); ok {
		opts["project"] = strings.ToUpper(project)
	}

	if insecureSkipVerify, ok := opts["insecure"].(bool); ok {
		transport.TLSClientConfig.InsecureSkipVerify = insecureSkipVerify
	}

	cli := &Cli{
		endpoint:   url,
		opts:       opts,
		cookieFile: filepath.Join(homedir, ".jira.d", "cookies.js"),
		ua: &http.Client{
			Jar:       cookieJar,
			Transport: transport,
		},
	}

	cli.ua.Jar.SetCookies(url, cli.loadCookies())

	return cli
}
func (p *PTPSearch) Login() error {
	options := cookiejar.Options{
		PublicSuffixList: publicsuffix.List,
	}
	var err error
	p.Cookiejar, err = cookiejar.New(&options)
	if err != nil {
		return err
	}

	client := &http.Client{Jar: p.Cookiejar}
	postData := url.Values{"username": {p.username},
		"password": {p.password}, "passkey": {p.passkey}, "keeplogged": {"1"}}
	resp, err := client.PostForm(ptp_endpoint_tls+"/ajax.php?action=login",
		postData)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	contents, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}

	var result loginResult
	if err := json.Unmarshal(contents, &result); err != nil {
		return err
	}
	if result.Result != "Ok" {
		return errors.New("Could not login to PTP.")
	}
	return nil
}
Exemple #6
0
func GetLanIP_Openwrt(address, password string) string {
	// Login first
	jar, _ := cookiejar.New(nil)
	client := &http.Client{Jar: jar}
	res, err := client.PostForm("http://"+address+"/", url.Values{"luci_username": {"root"}, "luci_password": {password}})
	if err != nil {
		fmt.Println(err)
		return ""
	}
	bin, _ := ioutil.ReadAll(res.Body)
	res.Body.Close()
	str := string(bin)
	ex := regexp.MustCompile(`/cgi-bin/luci/;stok=([a-z0-9]{32})`) // /cgi-bin/luci/;stok=dfc41c0ba4035a36922a6df4e26f6dd7/
	li := ex.FindStringSubmatch(str)
	if len(li) > 1 {
		res, err = client.Get("http://" + address + li[0] + "?status=1")
		if err != nil {
			fmt.Println(err)
			return ""
		}
		bin, _ = ioutil.ReadAll(res.Body)
		res.Body.Close()
		str = string(bin)
		ex = regexp.MustCompile(`"ipaddr":"(10\.[\.0-9]+?)",`)
		li = ex.FindStringSubmatch(str)
		if len(li) > 1 {
			return li[1]
		}
	}
	return ""
}
Exemple #7
0
// TODO(tiborvass): remove authConfig param once registry client v2 is vendored
func NewSession(client *http.Client, authConfig *cliconfig.AuthConfig, endpoint *Endpoint) (r *Session, err error) {
	r = &Session{
		authConfig:    authConfig,
		client:        client,
		indexEndpoint: endpoint,
	}

	var alwaysSetBasicAuth bool

	// If we're working with a standalone private registry over HTTPS, send Basic Auth headers
	// alongside all our requests.
	if endpoint.VersionString(1) != IndexServerAddress() && endpoint.URL.Scheme == "https" {
		info, err := endpoint.Ping()
		if err != nil {
			return nil, err
		}

		if info.Standalone && authConfig != nil {
			logrus.Debugf("Endpoint %s is eligible for private registry. Enabling decorator.", endpoint.String())
			alwaysSetBasicAuth = true
		}
	}

	// Annotate the transport unconditionally so that v2 can
	// properly fallback on v1 when an image is not found.
	client.Transport = AuthTransport(client.Transport, authConfig, alwaysSetBasicAuth)

	jar, err := cookiejar.New(nil)
	if err != nil {
		return nil, errors.New("cookiejar.New is not supposed to return an error")
	}
	client.Jar = jar

	return r, nil
}
Exemple #8
0
func (cmd *Cancel) Run() {
	log.SetOutput(LogOutput())

	if *cmd.VisitID == "" {
		fmt.Println("Must specify visitid.")
		return
	}

	// Load session
	mboSession, err := LoadMBOSession()
	if err != nil {
		fmt.Println(err)
		return
	}
	cookieJar, _ := cookiejar.New(nil)
	client := &http.Client{Jar: cookieJar}
	mbo_url, _ := url.Parse(MBO_URL)
	client.Jar.SetCookies(mbo_url, mboSession.Cookies)

	resp, err := client.Get(fmt.Sprintf("%s/ASP/adm/adm_res_canc.asp?visitID=%s&cType=1", MBO_URL, *cmd.VisitID))
	if err != nil || resp.StatusCode != 200 {
		log.Println(err)
		log.Println(resp)
		fmt.Println("Error performing cancel.")
	}
	defer resp.Body.Close()

	fmt.Println("Cancelled visit.")
}
Exemple #9
0
// NewTestSuite returns an initialized TestSuite ready for use. It is invoked
// by the test harness to initialize the embedded field in application tests.
func NewTestSuite() TestSuite {
	jar, _ := cookiejar.New(nil)
	return TestSuite{
		Client:  &http.Client{Jar: jar},
		Session: make(Session),
	}
}
Exemple #10
0
func getJar() *cookiejar.Jar {
	jar, err := cookiejar.New(nil)
	if err != nil {
		// Log
	}
	return jar
}
Exemple #11
0
func NewClient(u *url.URL, insecure bool) *Client {
	c := Client{
		u: u,
		k: insecure,
		d: newDebug(),
	}

	// Initialize http.RoundTripper on client, so we can customize it below
	c.t = &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		Dial: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).Dial,
	}

	if c.u.Scheme == "https" {
		c.t.TLSClientConfig = &tls.Config{InsecureSkipVerify: c.k}
		c.t.TLSHandshakeTimeout = 10 * time.Second
	}

	c.Client.Transport = c.t
	c.Client.Jar, _ = cookiejar.New(nil)

	// Remove user information from a copy of the URL
	c.u = c.URL()
	c.u.User = nil

	return &c
}
Exemple #12
0
// 创建http.CookieJar类型的值
func NewCookiejar() http.CookieJar {
	options := &cookiejar.Options{PublicSuffixList: &mk_publicSuffixList{}}

	jar, _ := cookiejar.New(options)

	return jar
}
Exemple #13
0
// CreateDefaultHTTPClient creates default HTTP with cookie jar.
func CreateDefaultHTTPClient() (*http.Client, error) {
	jar, err := cookiejar.New(nil)
	if err != nil {
		return nil, err
	}
	return &http.Client{Jar: jar}, nil
}
Exemple #14
0
func NewSession() *Session {
	jar, err := cookiejar.New(nil)
	if err != nil {
		RaiseHttpError(err)
	}

	defaultTransport := &gohttp.Transport{
		Proxy: nil,
		// DisableKeepAlives   : true,
		Dial: (&gonet.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
		}).Dial,

		TLSHandshakeTimeout: 10 * time.Second,
	}

	client := &gohttp.Client{
		CheckRedirect: nil,
		Jar:           jar,
		Timeout:       30 * time.Second,
		Transport:     defaultTransport,
	}

	return &Session{
		cookie:           jar,
		client:           client,
		headers:          make(gohttp.Header),
		defaultTransport: defaultTransport,
	}
}
func ExampleNew() {
	jar, err := cookiejar.New(nil)
	if err != nil {
		log.Fatal(err)
	}
	client := http.DefaultClient
	client.Jar = jar

	// Wrap around the client's transport to add support for space cookies.
	client.Transport = New(client.Transport, jar)

	// Assuming example.com sets space cookies, they get added to the jar.
	resp, err := client.Get("https://example.com")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	// So that following requests carry these cookies.
	resp, err = client.Get("https://example.com")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
}
Exemple #16
0
func Api(url string, options ...interface{}) *Resource {
	if !strings.HasSuffix(url, "/") {
		url = url + "/"
	}
	apiInstance := &ApiStruct{Base: url, Methods: make(map[string]*Resource), BasicAuth: nil}

	if len(options) > 0 {
		if auth, ok := options[0].(*BasicAuth); ok {
			apiInstance.BasicAuth = auth
		}
		if oauthClient, ok := options[0].(*http.Client); ok {
			apiInstance.Client = oauthClient
		}
	}
	if apiInstance.Client == nil {
		apiInstance.Cookies, _ = cookiejar.New(nil)

		// Skip verify by default?
		tr := &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		}

		client := &http.Client{
			Transport: tr,
			Jar:       apiInstance.Cookies,
		}
		apiInstance.Client = client
	}
	return &Resource{Url: "", Api: apiInstance}
}
Exemple #17
0
func hakai(c http.Client, config *Config, offset map[string]int) {
	u, err := url.Parse(config.Domain)
	if err != nil {
		log.Fatal(err)
	}

	queryParams := map[string]string{}
	for k, v := range config.QueryParams {
		vv := ReplaceNames(v, offset)
		queryParams[k] = vv
	}

	cookieJar, _ := cookiejar.New(nil)
	c.Jar = cookieJar
	attacker := Attacker{
		Client:      &c,
		Url:         u,
		Gzip:        config.Gzip,
		UserAgent:   config.UserAgent,
		QueryParams: &queryParams,
		ExVarOffset: offset,
	}
	for offset, action := range config.Actions {
		attacker.Action = action
		attacker.Attack(offset)
	}
}
Exemple #18
0
func parseGitCookies(data string) *cookiejar.Jar {
	jar, _ := cookiejar.New(nil)
	for _, line := range strings.Split(data, "\n") {
		f := strings.Split(line, "\t")
		if len(f) < 7 {
			continue
		}
		expires, err := strconv.ParseInt(f[4], 10, 64)
		if err != nil {
			continue
		}
		c := http.Cookie{
			Domain:  f[0],
			Path:    f[2],
			Secure:  f[3] == "TRUE",
			Expires: time.Unix(expires, 0),
			Name:    f[5],
			Value:   f[6],
		}
		// Construct a fake URL to add c to the jar.
		url := url.URL{
			Scheme: "http",
			Host:   c.Domain,
			Path:   c.Path,
		}
		jar.SetCookies(&url, []*http.Cookie{&c})
	}
	return jar
}
Exemple #19
0
func NewRegistry(authConfig *auth.AuthConfig, factory *utils.HTTPRequestFactory, indexEndpoint string) (r *Registry, err error) {
	httpTransport := &http.Transport{
		DisableKeepAlives: true,
		Proxy:             http.ProxyFromEnvironment,
	}

	r = &Registry{
		authConfig: authConfig,
		client: &http.Client{
			Transport: httpTransport,
		},
		indexEndpoint: indexEndpoint,
	}
	r.client.Jar, err = cookiejar.New(nil)
	if err != nil {
		return nil, err
	}

	// If we're working with a standalone private registry over HTTPS, send Basic Auth headers
	// alongside our requests.
	if indexEndpoint != auth.IndexServerAddress() && strings.HasPrefix(indexEndpoint, "https://") {
		standalone, err := pingRegistryEndpoint(indexEndpoint)
		if err != nil {
			return nil, err
		}
		if standalone {
			utils.Debugf("Endpoint %s is eligible for private registry auth. Enabling decorator.", indexEndpoint)
			dec := utils.NewHTTPAuthDecorator(authConfig.Username, authConfig.Password)
			factory.AddDecorator(dec)
		}
	}

	r.reqFactory = factory
	return r, nil
}
func (c *Client) initClient() {
	jar, _ := cookiejar.New(&cookiejar.Options{})
	c.Transport = &http.Transport{}
	c.Client = &http.Client{
		Transport: c.Transport,
		Jar:       jar,
		CheckRedirect: func(req *http.Request, via []*http.Request) error {
			if len(via) >= 10 {
				return errors.New("stopped after 10 redirects")
			}
			if c.SleepAfterRedirect > 0 {
				time.Sleep(time.Duration(c.SleepAfterRedirect) * time.Second)
				c.SleepAfterRedirect = 0
			}
			req.Header.Add("User-Agent", UserAgent)
			return nil
		},
	}
	c.SleepAfterRedirect = 0
	reasons := make([]string, 0)
	c.Result = &Result{
		Reason: &reasons,
	}
	c.TotalMemos = 0
}
Exemple #21
0
// NewNicoClient makes new http.Client with usersession
func NewNicoClient(a *Account) (*http.Client, error) {
	if a.Usersession == "" {
		return nil, MakeError(ErrOther, "no usersession")
	}

	nicoURL, err := url.Parse("http://nicovideo.jp")
	if err != nil {
		return nil, ErrFromStdErr(err)
	}

	jar, err := cookiejar.New(nil)
	if err != nil {
		return nil, ErrFromStdErr(err)
	}
	c := http.Client{Jar: jar}
	c.Jar.SetCookies(nicoURL, []*http.Cookie{
		&http.Cookie{
			Domain: nicoURL.Host,
			Path:   "/",
			Name:   "user_session",
			Value:  a.Usersession,
			Secure: false,
		},
	})
	return &c, nil
}
Exemple #22
0
func HttpGetCookieJar(url string, callType string,
	config M) (*cookiejar.Jar, error) {

	var resp *http.Response
	var errCall error
	var client *http.Client

	jar, e := cookiejar.New(nil)
	if e != nil {
		return nil, fmt.Errorf("Unable to initialize cookie jar: %s", e.Error())
	}

	client = &http.Client{
		Jar: jar,
	}

	if callType == "POST" {
		if config.Has("loginvalues") {
			fvs := config["loginvalues"].(M)
			vs := httpurl.Values{}
			for k, v := range fvs {
				vs.Set(k, v.(string))
			}

			resp, errCall = client.PostForm(url, vs)
			if errCall == nil {
				resp.Body.Close()
			}
		}
	} else {
		_, errCall = client.Get(url)
	}

	return jar, errCall
}
Exemple #23
0
func main() {
	baseURL := "http://axe-level-1.herokuapp.com/lv3"
	firstPage := true

	jar, err := cookiejar.New(nil)
	if err != nil {
		fmt.Println("cannot create cookiejar!?")
		return
	}
	client := http.Client{Jar: jar}

	towns := make([]*AreaLeader, 0, 1024)
	for {
		var resp *http.Response
		if resp, err = client.Get(baseURL); err != nil {
			fmt.Println("cannot get page!?")
			return
		}
		if firstPage {
			firstPage = false
			baseURL = baseURL + "?page=next"
		}
		newTowns, hasNext := parsePage(resp)

		towns = append(towns, newTowns...)
		if !hasNext {
			break
		}
	}
	//fmt.Println("len(towns)", len(towns))

	if err := json.NewEncoder(os.Stdout).Encode(towns); err != nil {
		fmt.Println(err)
	}
}
Exemple #24
0
func NewSession(authConfig *AuthConfig, factory *utils.HTTPRequestFactory, endpoint *Endpoint, timeout bool) (r *Session, err error) {
	r = &Session{
		authConfig:    authConfig,
		indexEndpoint: endpoint,
	}

	if timeout {
		r.timeout = ReceiveTimeout
	}

	r.jar, err = cookiejar.New(nil)
	if err != nil {
		return nil, err
	}

	// If we're working with a standalone private registry over HTTPS, send Basic Auth headers
	// alongside our requests.
	if r.indexEndpoint.VersionString(1) != IndexServerAddress() && r.indexEndpoint.URL.Scheme == "https" {
		info, err := r.indexEndpoint.Ping()
		if err != nil {
			return nil, err
		}
		if info.Standalone {
			log.Debugf("Endpoint %s is eligible for private registry. Enabling decorator.", r.indexEndpoint.String())
			dec := utils.NewHTTPAuthDecorator(authConfig.Username, authConfig.Password)
			factory.AddDecorator(dec)
		}
	}

	r.reqFactory = factory
	return r, nil
}
Exemple #25
0
func Adfly(url string) (string, error) {
	cookie, _ := cookiejar.New(nil)

	HH.Host = "adf.ly"
	html := htmlDownload(url, cookie)

	if html.URL == "http://adf.ly/not-found.php" {
		return "", errors.New("The URL is not a ADFLY valid link...")
	}

	ysmmregex := regexp.MustCompile("var ysmm = '(.*)';")
	result := ysmmregex.FindAllStringSubmatch(html.Html, -1)[0:]

	if result == nil {
		return "", errors.New(url + " is not a adfly valid link...")
	}

	for i := 0; i < (len(result[0][1])); i++ {
		if i%2 == 0 {
			side1 += string(result[0][1][i])
		} else {
			side2 = string(result[0][1][i]) + side2
		}
	}

	data, err := Base64Decode(side1 + side2)
	if err != nil {
		panic(err)
	}

	return string(data[2:]), nil
}
Exemple #26
0
func (this *Crawler) assignHtml() {
	if this.rawHtml == "" {
		cookieJar, _ := cookiejar.New(nil)
		client := &http.Client{
			Jar:     cookieJar,
			Timeout: this.config.timeout,
		}
		req, err := http.NewRequest("GET", this.url, nil)
		if err == nil {
			req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.91 Safari/534.30")
			resp, err := client.Do(req)
			if err == nil {
				defer resp.Body.Close()
				contents, err := ioutil.ReadAll(resp.Body)
				if err == nil {
					this.rawHtml = string(contents)
				} else {
					log.Println(err.Error())
				}
			} else {
				log.Println(err.Error())
			}
		} else {
			log.Println(err.Error())
		}
	}
}
Exemple #27
0
func Imagep2p(url_ string) (string, error) {
	cookie, _ := cookiejar.New(nil)

	HH.Host = "imagep2p.com"

	var cookies []*http.Cookie

	ageVerificationData := &http.Cookie{
		Name:   "AgeVerification",
		Path:   "/",
		Domain: "imagep2p.com",
		Value:  "1",
	}

	cookieURL, _ := url.Parse(url_)

	cookies = append(cookies, ageVerificationData)

	cookie.SetCookies(cookieURL, cookies)

	html := htmlDownload(url_, cookie)

	urlregex := regexp.MustCompile(`src="(images/.*?)"`)
	resutl := urlregex.FindAllStringSubmatch(html.Html, -1)[0:]
	return "http://imagep2p.com/" + resutl[0][1], nil
}
Exemple #28
0
func main() {
	if len(os.Args) != 3 {
		log.Fatalln("./das_downloader email password")
	}

	email := os.Args[1]
	password := os.Args[2]

	cookieJar, _ := cookiejar.New(nil)
	client := http.Client{nil, nil, cookieJar}

	signIn(&client, email, password)

	screencastUrls := make(chan *url.URL, 5)

	numDownloadingRoutines := runtime.NumCPU()
	runtime.GOMAXPROCS(numDownloadingRoutines)
	wait := sync.WaitGroup{}

	for i := 0; i < numDownloadingRoutines; i++ {
		wait.Add(1)
		go func() {
			for screencastUrl := range screencastUrls {
				downloadScreencast(&client, screencastUrl)
			}
			wait.Done()
		}()
	}

	getScreencastUrls(&client, screencastUrls)
	close(screencastUrls)

	wait.Wait()
}
func NewWebwx() (wx *Webwx, err error) {
	currentDir, err := os.Getwd()
	if err != nil {
		return
	}

	jar, err := cookiejar.New(nil)
	if err != nil {
		return
	}

	transport := *(http.DefaultTransport.(*http.Transport))
	transport.ResponseHeaderTimeout = 1 * time.Minute
	transport.TLSClientConfig = &tls.Config{
		InsecureSkipVerify: true,
	}

	wx = &Webwx{
		Client: &http.Client{
			Transport: &transport,
			Jar:       jar,
			Timeout:   1 * time.Minute,
		},
		Request: new(BaseRequest),

		CurrentDir:  currentDir,
		QRImagePath: filepath.Join(currentDir, "qrcode.jpg"),
	}
	return
}
Exemple #30
0
func New() *Megashares {
	cj, _ := cookiejar.New(nil)
	return &Megashares{cj, &http.Client{Jar: cj}}
	// m := new()
	// m.cookieJar, _ := cookiejar.New(nil)
	// m.Client := &http.Client{Jar: cookieJar}
}