Пример #1
0
func getConfigDir() (string, error) {
	if runtime.GOOS == "windows" {
		appData := os.Getenv("LOCALAPPDATA")
		configPath := filepath.ToSlash(appData + path.Dir(baseCfgPath))
		return configPath, nil
	}
	usr, err := user.Current()
	if err != nil {
		return "", err
	}
	cfgLoc := usr.HomeDir + "/.config"
	configPath := filepath.ToSlash(cfgLoc + path.Dir(baseCfgPath))
	return configPath, nil
}
Пример #2
0
func getUserConfigLoc() string {
	cfgDir, err := getConfigDir()
	if err != nil {
		// If this isn't a real user we panic out
		panic(err)
	}
	cfgLoc := filepath.ToSlash(cfgDir + "/1Password.json")
	if _, err := os.Stat(cfgLoc); os.IsNotExist(err) {
		err := os.MkdirAll(cfgDir, 0775)
		if err != nil {
			panic("You do not have access to create configuration data as your user something is really wrong exiting...\n" + err.Error())
		}
		err = ioutil.WriteFile(cfgLoc, []byte(baseConfig), 0664)
		if err != nil {
			panic("Could not write default config as your user something is really wrong exiting...\n" + err.Error())
		}

	}
	return cfgLoc
}
Пример #3
0
func show1PData(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
	cfg := utils.GetConfig()
	dfs := http.FileServer(http.Dir(cfg.MainLocation))
	fp := p.ByName("filepath")
	if fp == "" {
		fp = "/"
	}
	if fp != "/" {
		w.Header().Set("Vary", "Accept-Encoding")
		w.Header().Set("Cache-Control", "public, max-age=60")
		w.Header().Set("Access-Control-Allow-Origin", "*")
		dfs.ServeHTTP(w, r)
		return
	}
	f, err := ioutil.ReadFile(filepath.ToSlash(cfg.MainLocation + "/1Password.html"))
	if err != nil {
		log.Printf("Error reading 1password file: %s", err.Error())
		fmt.Fprint(w, utils.HTMLErr)
		return
	}
	fmt.Fprint(w, string(f))
	return
}