func generatePACFromGFWList(url string) { time.Sleep(5 * time.Second) log.Printf("Generate PAC from gfwlist %s\n", url) load_gfwlist_rule() gfwlist_txt := common.Home + "spac/snova-gfwlist.txt" var file_ts time.Time if fi, err := os.Stat(gfwlist_txt); nil == err { file_ts = fi.ModTime() } hf := common.Home + "spac/snova-gfwlist.pac" body, last_mod_date, err := util.FetchLateastContent(url, common.ProxyPort, file_ts, false) if nil == err { content := []byte{} if len(body) > 0 { content, _ = base64.StdEncoding.DecodeString(string(body)) ioutil.WriteFile(gfwlist_txt, content, 0666) } else { content, _ = ioutil.ReadFile(gfwlist_txt) } file_content := generatePAC(url, last_mod_date, string(content)) ioutil.WriteFile(hf, []byte(file_content), 0666) load_gfwlist_rule() } if nil != err { log.Printf("[ERROR]Failed to fetch gfwlist for reason:%v\n", err) } }
func fetchCloudSpacScript(url string) { time.Sleep(5 * time.Second) log.Printf("Fetch remote clound spac rule:%s\n", url) var file_ts time.Time if fi, err := os.Stat(spac_script_path[1]); nil == err { file_ts = fi.ModTime() } body, _, err := util.FetchLateastContent(url, common.ProxyPort, file_ts, true) if nil == err && len(body) > 0 { ioutil.WriteFile(spac_script_path[1], body, 0666) } if nil != err { log.Printf("Failed to fetch spac cloud script for reason:%v\n", err) } }
func fetchCloudHosts(url string) { time.Sleep(5 * time.Second) log.Printf("Fetch remote clound hosts:%s\n", url) file := common.Home + "hosts/" + CLOUD_HOSTS_FILE var file_ts time.Time if fi, err := os.Stat(file); nil == err { file_ts = fi.ModTime() } body, _, err := util.FetchLateastContent(url, common.ProxyPort, file_ts, true) if nil == err && len(body) > 0 { ioutil.WriteFile(file, body, 0666) mapping = make(map[string]*util.ListSelector) loadLocalHostMappings() } if nil != err { log.Printf("Failed to fetch spac cloud hosts for reason:%v\n", err) } }
func loadIPRangeFile(ipRepo string) { if len(ipRepo) == 0 { return } time.Sleep(5 * time.Second) hf := common.Home + "spac/" + "iprange.txt" _, err := os.Stat(hf) if nil != err { var zero time.Time body, _, err := util.FetchLateastContent(ipRepo, common.ProxyPort, zero, true) if err != nil { log.Printf("[ERROR]Failed to fetch ip range file from %s for reason:%v\n", ipRepo, err) return } else { err = ioutil.WriteFile(hf, body, 0755) if nil != err { log.Printf("Failed to manipulate ip range file for reason:%v\n", err) return } } log.Printf("Fetch ip range file success.\n") } init_iprange_func(hf) }