func main() {

	logger.Log("Started")

	// Check to test web server is running
	http.HandleFunc("/", test)

	// Deeper test stuff
	http.HandleFunc("/secure/", func(w http.ResponseWriter, r *http.Request) {

		key := strings.SplitN(r.URL.Path, "/", 3)[2]

		signature, unix := encode.HmacSha256Encode(key, "bq1Yl5thyhy6uQUvghh67j7ijG7HbcvrrKUMc3fDdNYn/+d=")

		signature = strings.Replace(signature, "-", "%2b", -1)

		signature = strings.Replace(signature, "_", "%2f", -1)

		signature = strings.Replace(signature, "=", "%3d", -1)

		secretKey := &Secret{Unix: unix, Sign: signature}

		address := strings.Split(r.RemoteAddr, ":")

		logger.Log("Request from IP " + address[0] + " on port " + address[1] + ".  Response is: " + key)

		jsonResult, _ := json.Marshal(secretKey)

		result := string(jsonResult)

		w.Write([]byte(result))
	})

	http.ListenAndServe(":8080", nil)
}
Example #2
0
func (this IndexCache) WriteToFile(file string) error {
	index_file, err := os.Create(file)
	if err != nil {
		logger.Log("生成临时索引文件失败")
		return err
	}
	defer func() {
		if err = index_file.Close(); err != nil {
			logger.Log("关闭临时索引文件:'" + file + "'失败")
		}
	}()
	this.writeToFile(this.root, index_file)
	return nil
}
Example #3
0
func main() {
	http.HandleFunc("/", MainPage)
	http.HandleFunc("/search", Search)

	if err := http.ListenAndServe(":80", nil); err != nil {
		logger.Log("服务器启动失败")
	}

}
Example #4
0
func AddSeed(uri string) (err error) {
	var (
		file *os.File
	)
	if file, err = os.OpenFile(seed_file, os.O_APPEND, os.ModePerm); err != nil {
		logger.Log("打开爬行种子文件失败")
		return err
	}
	defer func() {
		if err = file.Close(); err != nil {
			logger.Log("关闭爬行种子文件失败")
		}
	}()
	if _, err = file.WriteString(uri + "\r\n"); err != nil {
		logger.Log("向爬行种子文件中添加新种子失败")
		return err
	}
	return nil
}
Example #5
0
// 记录指定下载完的页面,用来防止以后再次下载它
func (this *DownloadFilter) AddFootPrint(uri string) error {
	u, err := url.Parse(uri)
	if err != nil {
		logger.Log("无法被解析的资源定位符:" + uri)
		return err
	}
	if u.Host != this.domain {
		// 下面这行日志,日过你打算跟踪一个网站的外链几率,可以开启它统计一下
		// logger.Log("添加的资源定位与过滤器中设置的指定域不同, 主域:" + this.domain + ", 添加域:" + u.Host)
		return errors.New("different domain")
	}
	this.footprintf[uri] = true
	return nil
}
Example #6
0
// 下载单个Internet资源
func Download(uri string) (data []byte, err error) {
	var (
		res  *http.Response
		buff bytes.Buffer
	)
	if res, err = http.Get(uri); err != nil {
		// logger.Log("无法下载资源:" + uri)
		return nil, err
	}
	defer func() {
		if err = res.Body.Close(); err != nil {
			logger.Log("下载资源:" + uri + "的HTTP响应关闭失败")
		}
	}()
	if res.StatusCode >= 300 || res.StatusCode < 200 {
		return nil, errors.New("页面响应了错误代码(非200-299的响应吗)")
	}
	if _, err = io.Copy(&buff, res.Body); err != nil {
		logger.Log("将资源数据写入缓冲区失败")
		return nil, err
	}
	return buff.Bytes(), nil
}
Example #7
0
func main() {
	flag.Parse()
	prime := big.NewInt(0)
	prime, _ = prime.SetString(*dhPrime, 0)

	g := big.NewInt(*dhGroup)
	logger.Log("DHGenStart:Prime", prime.String())
	logger.Log("DHGenStart:Group", g.String())
	var mydh *dh.DHData
	var err os.Error

	if *dhSecret == "" {
		mydh, err = dh.NewDH(rand.Reader, (*dhLen+7)/8, g, prime)
	} else {
		s, ok := big.NewInt(0).SetString(*dhSecret, 0)
		if !ok {
			logger.Log("Invalid secret", err.String())
			os.Exit(1)
		}
		mydh, err = dh.NewDHFull(g, prime, s)
	}
	if err != nil {
		logger.Log("DHGenFailure", err)
		os.Exit(1)
	}
	logger.Log("DHPublic", mydh.ComputePublic().String())
	if *dhLHS != "" {
		c, ok := big.NewInt(0).SetString(*dhLHS, 0)
		if !ok {
			logger.Log("Invalid LHS Key", nil)
			os.Exit(1)
		}
		shared, err := mydh.ComputeShared(c)
		if err != nil {
			logger.Log("Invalid LHS Computation", err)
			os.Exit(1)
		}
		logger.Log("DHShared", shared.String())
	}
}