Example #1
0
func BasicAuth(umgr UserManager) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		authhdr := r.Header.Get("Authorization")
		if len(authhdr) == 0 {
			return
		}
		authhdrs := strings.Fields(authhdr)
		if len(authhdrs) != 2 || authhdrs[0] != "Basic" {
			http.NotFound(w, r)
			return
		}
		credential, err := base64.URLEncoding.DecodeString(authhdrs[1])
		if err != nil {
			http.NotFound(w, r)
			return
		}
		credentials := strings.Split(string(credential), ":")
		if len(credentials) != 2 {
			http.NotFound(w, r)
			return
		}
		apikey, err := gouuid.ParseString(credentials[0])
		if err != nil {
			http.NotFound(w, r)
			return
		}
		user, err := umgr.FindByAPIKey(&apikey)
		if err != nil {
			http.NotFound(w, r)
			return
		}
		context.Set(r, "uid", user.UID)
	})
}
Example #2
0
func containsValidCNAMERecord(uid *gouuid.UUID, rr []dns.RR) bool {
	for _, record := range rr {
		if cname, ok := record.(*dns.CNAME); ok {
			elems := strings.Split(cname.Target, ".")
			cnameuid, err := gouuid.ParseString(elems[0])
			if err != nil {
				continue
			}
			if cnameuid.Equal(*uid) {
				return true
			}
		}
	}
	return false
}
Example #3
0
func (api *APIv1) DeleteAlias(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	uid := context.Get(r, "uid").(*gouuid.UUID)

	aid, err := gouuid.ParseString(vars["aid"])
	if err != nil {
		log.Printf("Invalid id: %s", vars["aid"])
		http.Error(w, "Invalid id format", http.StatusNotFound)
		return
	}

	err = api.domainmgr.DeleteAlias(&aid, uid)
	if err != nil {
		log.Printf("Could not delete alias %s: %s", vars["aid"], err)
		http.Error(w, "Could not delete alias", http.StatusNotFound)
		return
	}
	http.Error(w, "", http.StatusNoContent)
}