Exemplo n.º 1
0
func StartServer() {
	config := Config{}

	fh, err := os.Open("config.json")
	if err != nil {
		log.Fatal(err)
	}
	dec := json.NewDecoder(fh)
	err = dec.Decode(&config)
	if err != nil {
		log.Println("Error parsing config.json")
		log.Fatal(err)
	}
	log.Println("Config okay, checking paths")

	// Check needed paths for existence, eg the CSV file, template and static folders
	toCheck := []string{config.Datafile, config.Templatedir, config.Staticdir}
	for _, e := range toCheck {
		if ok, err := utils.PathExistsErr(e); !ok {
			log.Fatal(err)
		}
	}

	// If the value is not given in the config, it's an empty string.
	if config.Keydir != "" {
		// If not an empty string, check if it's a folder.
		if ok, _ := utils.IsDirectory(config.Keydir); ok {
			repo.ScanPGPKeys(config.Keydir)
		} else {
			log.Println("config.Keydir is given, but not a valid path.")
		}
	}

	log.Println("Starting server on port", config.Port)

	r := repo.GetRepo()
	r.ReadDatafile(config.Datafile)
	log.Println("The following entities were read:")
	r.Print()

	web.Run(config.Port, config.Baseurl, config.Templatedir, config.Staticdir)
}
Exemplo n.º 2
0
// Handler for requests to "/check"
func CheckHandler(w http.ResponseWriter, r *http.Request) {
	inputFingerprint := r.FormValue("fingerprint")
	if inputFingerprint != "" {
		utils.Sanitizer(&inputFingerprint, ":", " ")

		data := newPD("Check result")
		data.addPayload("fp", inputFingerprint)

		r := repo.GetRepo()
		if ok, e := r.GetEntry(inputFingerprint); ok {
			data.addPayload("Entry", e)
		}

		t := parse("result.html")
		t.Execute(w, data)

		return
	}
	http.Redirect(w, r, _baseurl, http.StatusFound)
}