コード例 #1
0
        /// <summary>
        /// 更新ConfigBean
        /// </summary>
        /// <param name="name"></param>
        /// <param name="request"></param>
        /// <param name="serializer"></param>
        /// <returns></returns>
        private IReader UpdateConfigBean(ConfigBeanBase configBean, HttpRequest request)
        {
            var msg = new CBMessage();
            if (!PermissionValidate.Instance.CheckChangePermission())
            {
                if (HostingEnvironment.IsHosted && HttpContext.Current != null)
                {
                    HttpContext.Current.Response.Redirect(HostingEnvironment.ApplicationVirtualPath);
                }
                else
                {
                    msg.Message = "Sorry,Your IP Address " + IPHelper.GetClientIP() + " Doesn't Have Write Permission.";
                    msg.IsSuccess = false;
                }
            }
            else if (configBean != null)
            {
                if (request.HttpMethod.ToLowerInvariant() == "get")
                {
                    foreach (var k in request.QueryString.AllKeys.Where(a => paramsField.IndexOf(a.ToLowerInvariant()) == -1).OfType<string>())
                    {
                        var oldVal = configBean.Get(k);
                        var newVal = HttpUtility.HtmlDecode(HttpUtility.UrlDecode(request.QueryString[k]));

                        ChangeLog.Write(ContextHelper.GetCategory(), string.Format("{0}的{1}值被更新 Old Value :{2} New Value :{3}", configBean.GetType().Name, k, oldVal, newVal));
                        configBean.Set(k, newVal);

                    }
                }
                else
                {
                    foreach (var k in request.Form.AllKeys.Where(a => paramsField.IndexOf(a.ToLowerInvariant()) == -1).OfType<string>())
                    {
                        var oldVal = configBean.Get(k);
                        var newVal = HttpUtility.HtmlDecode(request.Form[k]);
                        configBean.Set(k, newVal);
                        ChangeLog.Write(ContextHelper.GetCategory(), string.Format("{0}的{1}值被更新 Old Value :{2} New Value :{3}", configBean.GetType().Name, k, oldVal, newVal));
                    }
                }
                msg.Message = "Success";
                msg.IsSuccess = true;
            }
            return msg;
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {

            var targetIpStr = context.Request.QueryString[AppConst.QueryHostIP] ?? "";
            var serializer = GetSerializer(context.Request);
            var type = serializer.GetType();
            if (typeof(XMLSerializer) == type)
            {
                context.Response.ContentType = "application/xml";
            }
            else
            {
                context.Response.ContentType = "text/html";
            }

            try
            {
                var action = (context.Request[AppConst.QueryAction] ?? "").ToLower();
                if (!PermissionValidate.Instance.IsInnerIp(IPHelper.GetClientIP()))
                {
                    if (HostingEnvironment.IsHosted)
                    {
                        context.Response.Redirect(HostingEnvironment.ApplicationVirtualPath);
                    }
                    else
                    {
                        var msg = new CBMessage() { IsSuccess = false, Message = "Sorry,Your IP Address Doesn't Have " + action + " Permission." };
                        context.Response.Write(msg.Read(serializer));
                    }
                    return;
                }

                //判断是否点火操作
                string rawUrl = context.Request.RawUrl.ToLower();
                if (rawUrl.IndexOf(longinitializationpath) >= 0 || rawUrl.IndexOf(shortinitializationpath) >= 0)
                {
                    context.Response.Write(AppInernalsManager.Instance.GetContent(context.Request, serializer));
                }
                else
                {
                    //appinternals 登录退出
                    if (context.Request.RawUrl.ToLower().IndexOf("/appinternals/logout") >= 0)
                    {
                        Authorization.Instance.LogOut();
                        return;
                    }


                    if (!Regex.IsMatch(context.Request.Url.AbsoluteUri, patten, RegexOptions.IgnoreCase))
                    {
                        context.Response.Write(GetMessage(urlTemplate).Read(serializer));
                        return;
                    }

                    var isChange = action.Equals("change", StringComparison.Ordinal);
                    bool IsAuthorized = true;

                    if (!(PermissionValidate.Instance.CheckViewIPPermission() || PermissionValidate.Instance.CheckChangeIPPermission()))
                    {
                        IsAuthorized = Authorization.Instance.Authorizate();
                    }

                    if (IsAuthorized)
                    {
                        if (isChange && !PermissionValidate.Instance.CheckChangePermission())
                        {
                            if (HostingEnvironment.IsHosted)
                            {
                                context.Response.Redirect(HostingEnvironment.ApplicationVirtualPath);
                            }
                            else
                            {
                                var msg = new CBMessage() { IsSuccess = false, Message = "Sorry,Your  Doesn't Have " + action + " Permission." };
                                context.Response.Write(msg.Read(serializer));
                            }
                            return;
                        }

                        //判断是不是请求IP
                        if (context.Request.Url.Host == "localhost" || context.Request.Url.Host == "127.0.0.1" || targetIpStr.Equals("127.0.0.1") || IISHelper.CheckTargetIP(targetIpStr))
                        {
                            //是请求IP,执行AppInternals功能模块
                            context.Response.Write(AppInernalsManager.Instance.GetContent(context.Request, serializer));
                        }
                        else
                        {
                            context.Response.Write(NetAccess.Instance.GetProxyContent(targetIpStr, context.Request.Url));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                context.Response.Write(GetExceptionMessage(e).Read(serializer));
            }

        }