예제 #1
0
파일: server.go 프로젝트: noscripter/ezgoo
func startServer(s *AppServ, addr string) {
	var proto = "https"
	var ezgoo = &ezgooServer{proto[:4+s.tlType]}
	if addr == NULL {
		addr = s.Listen
	}

	serv := &http.Server{
		Handler:        ezgoo,
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}
	ln, err := net.Listen("tcp", addr)
	abortIf(err)

	if s.cert != nil {
		tlsConfig := &tls.Config{Certificates: []tls.Certificate{*s.cert}}
		ln = tls.NewListener(ln, tlsConfig)
	}

	closeable = append(closeable, ln)
	defer ln.Close()

	log.Infoln("Listen at", ln.Addr())
	serv.Serve(&tcpKeepAliveListener{ln})
}
예제 #2
0
파일: server.go 프로젝트: noscripter/ezgoo
func waitSignal() {
	var sigChan = make(chan os.Signal)
	USR2 := syscall.Signal(12) // fake signal-USR2 for windows
	signal.Notify(sigChan, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM, USR2)

	for sig := range sigChan {
		switch sig {
		case syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM:
			log.Exitln("Terminated by", sig)
			for _, item := range closeable {
				item.Close()
			}
			return
		default:
			log.Infoln("Ingore signal", sig)
		}
	}
}
예제 #3
0
파일: prefdom.go 프로젝트: noscripter/ezgoo
func setPrefDom(xReq *PxReq, w http.ResponseWriter, host string) {
	var req *http.Request
	var resp *http.Response
	var body string

	// remove client old cookies
	xReq.header.Del("Cookie")
	xReq.header.Del("Accept-Encoding")

	baseUrl := default_protocol + default_host
	ncrUrl := baseUrl + "/?gfe_rd=cr&gws_rd=cr"
	req, _ = http.NewRequest("GET", ncrUrl, nil)
	req.Header = xReq.header // use client header
	resp, body = httpCallEx(req, false)

	matches := reSig.FindStringSubmatch(body)
	if matches == nil {
		log.Infoln(body)
		panic("sig not found")
	}

	sig := matches[0]
	setprefUrl := fmt.Sprintf("%s/setprefdomain?prefdom=US&prev=%s&%s", baseUrl, url.QueryEscape(ncrUrl), sig)
	req, _ = http.NewRequest("GET", setprefUrl, nil)
	req.Header = xReq.header

	nid, nidFound := extractNID(resp.Cookies())
	if nidFound {
		req.Header.Set("Cookie", cookieString(nid, nil, false))
	} // else panic ?
	resp, _ = httpCallEx(req, true)

	nid, nidFound = extractNID(resp.Cookies())
	if !nidFound {
		dumpHeader(fmt.Sprintf("resp[%s]->%s", resp.Status, req.URL), resp.Header)
		panic("nid not found")
	} else {
		nid.HttpOnly = true
		w.Header().Set("Set-Cookie", cookieString(nid, &host, true))
	}
	w.Header().Set("Location", "/")
	w.WriteHeader(302)
}