Пример #1
0
func StaticServer(w http.ResponseWriter, r *http.Request) {
	// check permission
	if r.RequestURI == AproxyUrlPrefix ||
		r.RequestURI == AproxyUrlPrefix+"index.html" {
		ctx := rfweb.NewContext(w, r)
		user := auth.GetLoginedUser(ctx)
		errMsg := ""
		if user == nil {
			login.RedirectToLogin(w, r)
			return
		} else {
			authority, err := auth.GetAuthorityByEmail(user.Email)
			if err != nil {
				errMsg = "can't get authority, error: " + err.Error()
			} else if authority == nil || authority.AdminLevel < 10 {
				errMsg = "you don't has permission."
			}
		}
		if errMsg != "" {
			http.Error(ctx.W, errMsg, http.StatusForbidden)
			return
		}
	}

	http.StripPrefix(AproxyUrlPrefix,
		fileServer).ServeHTTP(w, r)
}
Пример #2
0
func Proxy(w http.ResponseWriter, r *http.Request) {
	if b, ok := getBackend(r); ok {
		ctx := rfweb.NewContext(w, r)
		status := auth.CheckPermission(b.Conf.AuthType, ctx)
		if status == constant.PERMISSION_STATUS_OK {
			b.Lb.ServeHTTP(w, r)
		} else if status == constant.PERMISSION_STATUS_NEED_LOGIN {
			login.RedirectToLogin(w, r)
		} else if status == constant.PERMISSION_STATUS_NO_PERMISSION {
			http.Error(w, "no permission", http.StatusForbidden)
		}

	} else {
		http.NotFound(w, r)
	}
}