func ConfigGet(u utils.Utils, w http.ResponseWriter, r *http.Request) { specifiedSecret := parseSecret(r) configSecret := os.Getenv("CONFIG_SECRET") if configSecret == "" || specifiedSecret != configSecret { w.WriteHeader(http.StatusForbidden) writeJson(u, w, r, "{}") u.Errorf("admin.ConfigGet: wrong secret %s", specifiedSecret) return } keys := parseKeys(r) values := make(map[string]string) for _, key := range keys { values[key] = u.ConfigGet(key) } valuesJson, err := json.Marshal(values) if err != nil { w.WriteHeader(http.StatusInternalServerError) writeJson(u, w, r, "{}") u.Errorf("admin.ConfigGet: json.Marshal(values) error %v", err) return } writeJson(u, w, r, string(valuesJson)) }
func getAdsAsJson(u utils.Utils) string { json, err := json.Marshal(u.ConfigGet("ADS")) if err != nil { return "''" } return string(json) }
func prepareFbGraphUrl(u utils.Utils, ids string) string { scheme := "http" accessToken := "" if appId := u.ConfigGet("FACEBOOK_APP_ID"); appId != "" { if appSecret := u.ConfigGet("FACEBOOK_APP_SECRET"); appSecret != "" { scheme = "https" accessToken = fmt.Sprintf("&access_token=%s|%s", appId, appSecret) } } return fmt.Sprintf("%s://graph.facebook.com/?ids=%s&fields=share%s", scheme, neturl.QueryEscape(ids), accessToken) }
func getBlacklist(u utils.Utils, refresh bool) *regexp.Regexp { if !blacklistPrepared || refresh { if value := u.ConfigGet("BLACKLIST"); value != "" { compiled, err := regexp.Compile(value) if err != nil { u.Errorf("web.getBlacklist error on %s: %v", value, err) } blacklist = compiled } blacklistPrepared = true } return blacklist }
func getWhitelist(u utils.Utils, refresh bool) *regexp.Regexp { if !whitelistPrepared || refresh { if value := u.ConfigGet("WHITELIST"); value != "" { compiled, err := regexp.Compile(value) if err != nil { u.Errorf("web.getWhitelist error on %s: %v", value, err) } whitelist = compiled } whitelistPrepared = true } return whitelist }