Ejemplo n.º 1
0
        /// <summary>
        /// 保存配置类实例
        /// </summary>
        /// <returns></returns>
        public static bool SaveConfig(APIConfigInfo apiconfiginfo)
        {
            APIConfigFileManager acfm = new APIConfigFileManager();

            APIConfigFileManager.ConfigInfo = apiconfiginfo;
            return(acfm.SaveConfig());
        }
Ejemplo n.º 2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!base.IsPostBack)
     {
         APIConfigInfo config = APIConfigInfo.Current;
         this.allowpassport.SelectedValue = (config.Enable ? "1" : "0");
         this.passportbody.Attributes.Add("style", "display:" + (config.Enable ? "block" : "none"));
         this.allowpassport.Items[0].Attributes.Add("onclick", "setAllowPassport(1)");
         this.allowpassport.Items[1].Attributes.Add("onclick", "setAllowPassport(0)");
         var       appCollection = config.AppCollection;
         DataTable dataTable     = new DataTable();
         dataTable.Columns.Add("appname");
         dataTable.Columns.Add("apptype");
         dataTable.Columns.Add("callbackurl");
         dataTable.Columns.Add("apikey");
         dataTable.Columns.Add("secret");
         foreach (ApplicationInfo current in appCollection)
         {
             DataRow dataRow = dataTable.NewRow();
             dataRow["appname"]     = current.AppName;
             dataRow["apptype"]     = ((current.ApplicationType == 1) ? "Web" : "桌面");
             dataRow["callbackurl"] = current.CallbackUrl;
             dataRow["apikey"]      = current.APIKey;
             dataRow["secret"]      = current.Secret;
             dataTable.Rows.Add(dataRow);
         }
         this.DataGrid1.TableHeaderName = "整合程序列表";
         this.DataGrid1.DataKeyField    = "apikey";
         this.DataGrid1.DataSource      = dataTable;
         this.DataGrid1.DataBind();
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         APIConfigInfo aci = APIConfigs.GetConfig();
         allowpassport.SelectedValue = aci.Enable ? "1" : "0";
         passportbody.Attributes.Add("style", "display:" + (aci.Enable ? "block" : "none"));
         allowpassport.Items[0].Attributes.Add("onclick", "setAllowPassport(1)");
         allowpassport.Items[1].Attributes.Add("onclick", "setAllowPassport(0)");
         ApplicationInfoCollection appColl = aci.AppCollection;
         DataTable dt = new DataTable();
         dt.Columns.Add("appname");
         dt.Columns.Add("callbackurl");
         dt.Columns.Add("apikey");
         dt.Columns.Add("secret");
         foreach (ApplicationInfo ai in appColl)
         {
             DataRow dr = dt.NewRow();
             dr["appname"]     = ai.AppName;
             dr["callbackurl"] = ai.CallbackUrl;
             dr["apikey"]      = ai.APIKey;
             dr["secret"]      = ai.Secret;
             dt.Rows.Add(dr);
         }
         DataGrid1.TableHeaderName = "整合程序列表";
         DataGrid1.DataKeyField    = "apikey";
         DataGrid1.DataSource      = dt;
         DataGrid1.DataBind();
     }
 }
Ejemplo n.º 4
0
        void Status_Load(object sender, EventArgs e)
        {
            APIConfigInfo apiInfo = APIConfigs.GetConfig();

            if (!apiInfo.Enable)
            {
                return;
            }
            ApplicationInfo           appInfo       = null;
            ApplicationInfoCollection appcollection = apiInfo.AppCollection;

            foreach (ApplicationInfo newapp in appcollection)
            {
                if (newapp.APIKey == DNTRequest.GetString("api_key"))
                {
                    appInfo = newapp;
                }
            }
            if (appInfo == null)
            {
                return;
            }


            string next  = DNTRequest.GetString("next");
            string reurl = string.Format("{0}{1}user_status={2}{3}", appInfo.CallbackUrl, appInfo.CallbackUrl.IndexOf("?") > 0 ? "&" : "?", userid > 0 ? "1" : "0", next == string.Empty ? next : "next=" + next);

            Response.Redirect(reurl);
        }
Ejemplo n.º 5
0
        void RESTServer_Load(object sender, EventArgs e)
        {
            List <DNTParam> parameters = GetParamsFromRequest(HttpContext.Current.Request);
            APIConfigInfo   apiInfo    = APIConfigs.GetConfig();

            if (!apiInfo.Enable)
            {
                RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_SERVICE, parameters));
                return;
            }

            //查找匹配客户端配置信息
            ApplicationInfo           appInfo       = null;
            ApplicationInfoCollection appcollection = apiInfo.AppCollection;

            foreach (ApplicationInfo newapp in appcollection)
            {
                if (newapp.APIKey == DNTRequest.GetString("api_key"))
                {
                    appInfo = newapp;
                    break;
                }
            }

            if (appInfo == null)
            {
                RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_APPLICATION, parameters));
                return;
            }

            //check request ip
            string ip = DNTRequest.GetIP();

            if (appInfo.IPAddresses != null && appInfo.IPAddresses.Trim() != string.Empty && !Utils.InIPArray(ip, appInfo.IPAddresses.Split(',')))
            {
                RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_BAD_IP, parameters));
                return;
            }

            string sig = GetSignature(parameters, appInfo.Secret);

            if (sig != DNTRequest.GetString("sig"))
            {
                //输出签名错误
                RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_SIGNATURE, parameters));
                return;
            }

            string method = DNTRequest.GetString("method").Trim().ToLower();

            //如果客户端未指定方法名称
            if (string.IsNullOrEmpty(method))
            {
                RESTServerResponse(Util.CreateErrorMessage(ErrorType.API_EC_METHOD, parameters));
                return;
            }

            RESTServerResponse(CommandManager.Run(new CommandParameter(method, parameters, appInfo)));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            applicationtype.Items[0].Attributes.Add("onclick", "$('showurl').style.display='';");
            applicationtype.Items[1].Attributes.Add("onclick", "$('showurl').style.display='none';");

            asyncmode.Items[0].Attributes.Add("onclick", "$('tr_asyncurl').style.display='';$('tr_asynclist').style.display='none';");
            asyncmode.Items[1].Attributes.Add("onclick", "$('tr_asyncurl').style.display='none';$('tr_asynclist').style.display='none';");
            asyncmode.Items[2].Attributes.Add("onclick", "$('tr_asyncurl').style.display='';$('tr_asynclist').style.display='';");
            if (!IsPostBack)
            {
                string apikey = DNTRequest.GetString("apikey");
                if (apikey != "")
                {
                    APIConfigInfo aci = APIConfigs.GetConfig();
                    foreach (ApplicationInfo ai in aci.AppCollection)
                    {
                        if (ai.APIKey == apikey)
                        {
                            appname.Text = ai.AppName;
                            applicationtype.SelectedValue = ai.ApplicationType.ToString();
                            if (applicationtype.SelectedIndex == 1)
                            {
                                base.RegisterStartupScript("applicationtype", "<script>$('showurl').style.display='none';</script>");
                            }
                            appurl.Text      = ai.AppUrl;
                            callbackurl.Text = ai.CallbackUrl;
                            ipaddresses.Text = ai.IPAddresses;

                            asyncmode.SelectedValue = ai.SyncMode.ToString();
                            if (asyncmode.SelectedIndex == 1)
                            {
                                base.RegisterStartupScript("asyncmode", "<script>$('tr_asyncurl').style.display='none';$('tr_asynclist').style.display='none';</script>");
                            }
                            if (asyncmode.SelectedIndex == 2)
                            {
                                base.RegisterStartupScript("asyncmode", "<script>$('tr_asyncurl').style.display='';$('tr_asynclist').style.display='';</script>");
                            }
                            asyncurl.Text  = ai.SyncUrl;
                            asynclist.Text = ai.SyncList;
                            break;
                        }
                    }
                }
                apikeyhidd.Value = apikey;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 是否是来自应用程序的登出
        /// </summary>
        /// <returns></returns>
        private bool IsApplicationLogout()
        {
            APIConfigInfo apiconfig = APIConfigs.GetConfig();

            if (!apiconfig.Enable)
            {
                return(false);
            }

            int confirm = DNTRequest.GetFormInt("confirm", -1);

            if (confirm != 1)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 8
0
        private void APILogin(APIConfigInfo apiInfo)
        {
            ApplicationInfo           appInfo       = null;
            ApplicationInfoCollection appcollection = apiInfo.AppCollection;

            foreach (ApplicationInfo newapp in appcollection)
            {
                if (newapp.APIKey == DNTRequest.GetString("api_key"))
                {
                    appInfo = newapp;
                    break;
                }
            }
            if (appInfo == null)
            {
                return;
            }
            RedirectAPILogin(appInfo);
        }
Ejemplo n.º 9
0
        private void APILogin(APIConfigInfo apiInfo)
        {
            ApplicationInfo applicationInfo = null;
            var             appCollection   = apiInfo.AppCollection;

            foreach (var current in appCollection)
            {
                if (current.APIKey == DNTRequest.GetString("api_key"))
                {
                    applicationInfo = current;
                    break;
                }
            }
            if (applicationInfo == null)
            {
                return;
            }
            this.RedirectAPILogin(applicationInfo);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 获取需要数据同步的应用程序列表
        /// </summary>
        /// <param name="actionName"></param>
        /// <returns></returns>
        private static ApplicationInfoCollection GetAsyncTarget(string action)
        {
            ApplicationInfoCollection appCollection = new ApplicationInfoCollection();
            APIConfigInfo             apiInfo       = APIConfigs.GetConfig();

            if (!apiInfo.Enable)
            {
                return(appCollection);
            }
            foreach (ApplicationInfo appInfo in apiInfo.AppCollection)
            {
                if (appInfo.SyncMode == 1 || (appInfo.SyncMode == 2 && Utils.InArray(action, appInfo.SyncList)))
                {
                    if (appInfo.SyncUrl.Trim() == string.Empty)
                    {
                        continue;
                    }
                    appCollection.Add(appInfo);
                }
            }
            return(appCollection);
        }
Ejemplo n.º 11
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         string apikey = DNTRequest.GetString("apikey");
         if (apikey != "")
         {
             APIConfigInfo aci = APIConfigs.GetConfig();
             foreach (ApplicationInfo ai in aci.AppCollection)
             {
                 if (ai.APIKey == apikey)
                 {
                     appname.Text     = ai.AppName;
                     appurl.Text      = ai.AppUrl;
                     callbackurl.Text = ai.CallbackUrl;
                     ipaddresses.Text = ai.IPAddresses;
                     break;
                 }
             }
         }
         apikeyhidd.Value = apikey;
     }
 }
Ejemplo n.º 12
0
        protected void DelRec_Click(object sender, EventArgs e)
        {
            string apikeylist = DNTRequest.GetString("apikey");

            if (apikeylist == "")
            {
                return;
            }
            foreach (string apikey in apikeylist.Split(','))
            {
                APIConfigInfo             aci     = APIConfigs.GetConfig();
                ApplicationInfoCollection appColl = aci.AppCollection;
                foreach (ApplicationInfo ai in appColl)
                {
                    if (ai.APIKey == apikey)
                    {
                        aci.AppCollection.Remove(ai);
                        break;
                    }
                }
                APIConfigs.SaveConfig(aci);
            }
            Response.Redirect("global_passportmanage.aspx");
        }
Ejemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int    pertask       = DNTRequest.GetInt("pertask", 0);
                int    lastnumber    = DNTRequest.GetInt("lastnumber", 0);
                int    startvalue    = DNTRequest.GetInt("startvalue", 0);
                int    endvalue      = DNTRequest.GetInt("endvalue", 0);
                string resultmessage = "";
                switch (Request.Params["opname"])
                {
                case "ReSetFourmTopicAPost":
                    AdminForumStats.ReSetFourmTopicAPost(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetUserDigestPosts":
                    AdminForumStats.ReSetUserDigestPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetUserPosts":
                    AdminForumStats.ReSetUserPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetTopicPosts":
                    AdminForumStats.ReSetTopicPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetFourmTopicAPost_StartEnd":
                    AdminForumStats.ReSetFourmTopicAPost(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetUserDigestPosts_StartEnd":
                    AdminForumStats.ReSetUserDigestPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetUserPosts_StartEnd":
                    AdminForumStats.ReSetUserPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetTopicPosts_StartEnd":
                    AdminForumStats.ReSetTopicPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ftptest":
                    string serveraddress = DNTRequest.GetString("serveraddress");
                    string serverport    = DNTRequest.GetString("serverport");
                    string username      = DNTRequest.GetString("username");
                    string password      = DNTRequest.GetString("password");
                    string timeout       = DNTRequest.GetString("timeout");
                    string uploadpath    = DNTRequest.GetString("uploadpath");
                    FTPs   ftps          = new FTPs();
                    string message       = "";
                    bool   ok            = ftps.TestConnect(serveraddress, int.Parse(serverport), username, password, int.Parse(timeout), uploadpath, ref message);
                    if (ok)
                    {
                        resultmessage = "ok";
                    }
                    else
                    {
                        resultmessage = "远程附件设置测试出现错误!\n描述:" + message;
                    }
                    break;

                case "setapp":
                    string        allowpassport = DNTRequest.GetString("allowpassport");
                    APIConfigInfo aci           = APIConfigs.GetConfig();
                    aci.Enable = allowpassport == "1";
                    APIConfigs.SaveConfig(aci);
                    resultmessage = "ok";
                    break;
                }
                Response.Write(resultmessage);
                Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
                Response.Expires         = -1;
                Response.End();
            }
        }
Ejemplo n.º 14
0
        protected override void ShowPage()
        {
            pagetitle = "用户登录";

            postusername = Utils.UrlDecode(DNTRequest.GetString("postusername")).Trim();

            if (this.userid != -1)
            {
                //SetUrl("/Forum/");
                SetMetaRefresh();
                SetShowBackLink(false);
                AddMsgLine("您已经登录,无须重复登录");
                ispost = true;
                SetLeftMenuRefresh();

                APIConfigInfo apiInfo = APIConfigs.GetConfig();
                if (apiInfo.Enable)
                {
                    APILogin(apiInfo);
                }
            }

            /*
             * if (LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), false) >= 5)
             * {
             *  AddMsgLine("您已经多次输入密码错误, 请15分钟后再登录");
             *  loginsubmit = false;
             *  return;
             * }
             */

            //未提交或跨页提交时
            if (!DNTRequest.IsPost() || referer != "")
            {
                string r = "";
                if (referer != "")
                {
                    r = referer;
                }
                else
                {
                    if ((DNTRequest.GetUrlReferrer() == "") || (DNTRequest.GetUrlReferrer().IndexOf("login") > -1) ||
                        DNTRequest.GetUrlReferrer().IndexOf("logout") > -1)
                    {
                        r = "index.aspx";
                    }
                    else
                    {
                        r = DNTRequest.GetUrlReferrer();
                    }
                }
                Utils.WriteCookie("reurl", (DNTRequest.GetQueryString("reurl") == "" || DNTRequest.GetQueryString("reurl").IndexOf("login.aspx") > -1) ? r : DNTRequest.GetQueryString("reurl"));
            }

            //如果提交...
            if (DNTRequest.IsPost())
            {
                StringBuilder builder = new StringBuilder();
                foreach (string key in System.Web.HttpContext.Current.Request.QueryString.AllKeys)
                {
                    if (key != "postusername")
                    {
                        builder.Append("&");
                        builder.Append(key);
                        builder.Append("=");
                        builder.Append(DNTRequest.GetQueryString(key));
                    }
                }
                base.SetBackLink("login.aspx?postusername="******"username")) + builder.ToString());


                //如果没输入验证码就要求用户填写
                if (isseccode && DNTRequest.GetString("vcode") == "")
                {
                    postusername = DNTRequest.GetString("username");
                    loginauth    = DES.Encode(DNTRequest.GetString("password"), config.Passwordkey).Replace("+", "[");
                    loginsubmit  = true;
                    return;
                }

                bool isExistsUserByName = Discuz.Forum.Users.Exists(DNTRequest.GetString("username"));
                if (!isExistsUserByName)
                {
                    Discuz.Data.DatabaseProvider.GetInstance().ClubLoginLog(1, -1, System.Web.HttpContext.Current.Request.UserHostAddress, 7);
                    AddErrLine("用户不存在");
                }

                if (DNTRequest.GetString("password").Equals("") && DNTRequest.GetString("loginauth") == "")
                {
                    AddErrLine("密码不能为空");
                }

                if (IsErr())
                {
                    return;
                }

                if (!Utils.StrIsNullOrEmpty(loginauth))
                {
                    postpassword = DES.Decode(loginauth.Replace("[", "+"), config.Passwordkey);
                }
                else
                {
                    postpassword = DNTRequest.GetString("password");
                }

                if (postusername == "")
                {
                    postusername = DNTRequest.GetString("username");
                }

                int uid = -1;
                if (config.Passwordmode == 1)
                {
                    if (config.Secques == 1 && (!Utils.StrIsNullOrEmpty(loginauth) || !loginsubmit))
                    {
                        uid = Discuz.Forum.Users.CheckDvBbsPasswordAndSecques(postusername,
                                                                              postpassword,
                                                                              DNTRequest.GetInt("question", 0),
                                                                              DNTRequest.GetString("answer"));
                    }
                    else
                    {
                        uid = Discuz.Forum.Users.CheckDvBbsPassword(postusername, postpassword);
                    }
                }
                else
                {
                    if (config.Secques == 1 && (!Utils.StrIsNullOrEmpty(loginauth) || !loginsubmit))
                    {
                        uid = Discuz.Forum.Users.CheckPasswordAndSecques(postusername,
                                                                         postpassword,
                                                                         true,
                                                                         DNTRequest.GetInt("question", 0),
                                                                         DNTRequest.GetString("answer"));
                    }
                    else
                    {
                        uid = Discuz.Forum.Users.CheckPassword(postusername, postpassword, true);
                    }
                }


                if (uid != -1)
                {
                    ShortUserInfo userinfo = Discuz.Forum.Users.GetShortUserInfo(uid);
                    if (userinfo.Groupid == 8)
                    {
                        AddErrLine("抱歉, 您的用户身份尚未得到验证");
                        if (config.Regverify == 1)
                        {
                            AddMsgLine("请您到您的邮箱中点击激活链接来激活您的帐号");
                        }

                        if (config.Regverify == 2)
                        {
                            AddMsgLine("您需要等待一些时间, 待系统管理员审核您的帐户后才可登录使用");
                        }
                        loginsubmit = false;
                    }
                    else
                    {
                        if (!Utils.StrIsNullOrEmpty(userinfo.Secques) && loginsubmit && Utils.StrIsNullOrEmpty(DNTRequest.GetString("loginauth")))
                        {
                            loginauth = DES.Encode(DNTRequest.GetString("password"), config.Passwordkey).Replace("+", "[");
                        }
                        else
                        {
                            LoginLogs.DeleteLoginLog(DNTRequest.GetIP());
                            UserCredits.UpdateUserCredits(uid);
                            ForumUtils.WriteUserCookie(
                                uid,
                                Utils.StrToInt(DNTRequest.GetString("expires"), -1),
                                config.Passwordkey,
                                DNTRequest.GetInt("templateid", 0),
                                DNTRequest.GetInt("loginmode", -1));
                            OnlineUsers.UpdateAction(olid, UserAction.Login.ActionID, 0);
                            //无延迟更新在线信息
                            oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout);
                            olid       = oluserinfo.Olid;
                            Discuz.Forum.Users.UpdateUserLastvisit(uid, DNTRequest.GetIP());

                            string reurl = Utils.UrlDecode(ForumUtils.GetReUrl());
                            if (reurl.IndexOf("register.aspx") < 0)
                            {
                                SetUrl(reurl);
                            }
                            else
                            {
                                SetUrl("index.aspx");
                            }

                            APIConfigInfo apiInfo = APIConfigs.GetConfig();
                            if (apiInfo.Enable)
                            {
                                APILogin(apiInfo);
                            }

                            Discuz.Forum.Users.SaveUserIDToCookie(uid);

                            Discuz.Data.DatabaseProvider.GetInstance().ClubLoginLog(1, uid, System.Web.HttpContext.Current.Request.UserHostAddress, 5);
                            AddMsgLine("登录成功, 返回登录前页面");

                            userid        = uid;
                            usergroupinfo = UserGroups.GetUserGroupInfo(userinfo.Groupid);
                            // 根据用户组得到相关联的管理组id
                            useradminid = usergroupinfo.Radminid;

                            SetMetaRefresh();
                            SetShowBackLink(false);

                            SetLeftMenuRefresh();

                            loginsubmit = false;
                        }
                    }
                }
                else
                {
                    int errcount = LoginLogs.UpdateLoginLog(DNTRequest.GetIP(), true);
                    if (errcount > 5)
                    {
                        AddErrLine("您已经输入密码5次错误, 请15分钟后再试");
                    }
                    else
                    {
                        if (isExistsUserByName)
                        {
                            uid = Discuz.Data.DatabaseProvider.GetInstance().GetuidByusername(postusername);
                        }
                        Discuz.Data.DatabaseProvider.GetInstance().ClubLoginLog(1, uid, System.Web.HttpContext.Current.Request.UserHostAddress, 6);
                        AddErrLine(string.Format("密码或安全提问第{0}次错误, 您最多有5次机会重试", errcount.ToString()));
                    }
                }
            }
        }
Ejemplo n.º 15
0
        void RESTServer_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.ContentType = "text/xml";

            APIConfigInfo apiInfo = APIConfigs.GetConfig();
            if (!apiInfo.Enable)
            {
                ResponseErrorInfo((int)ErrorType.API_EC_SERVICE);
                return;
            }

            //check sig
            DNTParam[] parameters = GetParamsFromRequest(Request);


            //GetRequests

            /*---- optional ----*/

            //format
            string format = DNTRequest.GetString("format");
            //callback
            string callback = DNTRequest.GetString("callback");
           

            /*---- required ----*/

            //api_key
            string api_key = DNTRequest.GetString("api_key");
            //整合程序对象
            ApplicationInfo appInfo = null;
            ApplicationInfoCollection appcollection = apiInfo.AppCollection;
            foreach (ApplicationInfo newapp in appcollection)
            {
                if (newapp.APIKey == DNTRequest.GetString("api_key"))
                {
                    appInfo = newapp;
                }
            }

            if (appInfo == null)
            {
                //输出API Key错误
                ResponseErrorInfo((int)ErrorType.API_EC_APPLICATION);
                return;
            }
            //check request ip
            string ip = DNTRequest.GetIP();
            if (appInfo.IPAddresses != null && appInfo.IPAddresses.Trim() != string.Empty && !Utils.InIPArray(ip, appInfo.IPAddresses.Split(',')))
            {
                ResponseErrorInfo((int)ErrorType.API_EC_BAD_IP);
                return;
            }

            /*---- required by specific method----*/



            string sig = GetSignature(parameters, appInfo.Secret);
            //if (sig != DNTRequest.GetString("sig"))
            //{
            //    //输出签名错误
            //    ResponseErrorInfo((int)ErrorType.API_EC_SIGNATURE);
            //    return;
            //}

            //get session_key and check user
            string session_key = DNTRequest.GetString("session_key");
            int uid = GetUidFromSessionKey(session_key, appInfo.Secret);




            string method = DNTRequest.GetString("method");
            if (method == string.Empty)
            {
                ResponseErrorInfo((int)ErrorType.API_EC_METHOD);
                return;
            }
            string classname = method.Substring(0, method.LastIndexOf('.'));
            string methodname = method.Substring(method.LastIndexOf('.') + 1);

            string content;
            ActionBase action;
            double lastcallid = -1;
            double callid = -1;
            try
            {
                Type type = Type.GetType(string.Format("Discuz.Web.Services.API.Actions.{0}, Discuz.Web.Services", classname), false, true);
                action = (ActionBase)Activator.CreateInstance(type);
                action.ApiKey = api_key;
                action.Params = parameters;
                action.App = appInfo;
                action.Secret = appInfo.Secret;
                action.Uid = uid;
                action.Format = FormatType.XML;
                action.Signature = sig;

                //call_id    - milliseconds  record last callid
                double.TryParse(DNTRequest.GetString("call_id"), out callid);
                if (callid > -1)
                {
                    if (Session["call_id"] == null)
                        lastcallid = -1;
                    else
                        double.TryParse(Session["call_id"].ToString(), out lastcallid);
                }
                action.CallId = callid;
                action.LastCallId = lastcallid;

                if (format.Trim().ToLower() == "json")
                {
                    Response.ContentType = "text/html";
                    action.Format = FormatType.JSON;
                }

                content = type.InvokeMember(methodname, BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.IgnoreCase, null, action, new object[] { }).ToString();
            }
            catch
            {
                content = "";
                ResponseErrorInfo((int)ErrorType.API_EC_METHOD);
                return;
            }
            if (action.ErrorCode > 0)
            {
                ResponseErrorInfo(action.ErrorCode);
                return;
            }

            //update callid
            if (callid > lastcallid)
            {
                Session["call_id"] = callid;
            }

            //成功后适当的地方更新用户在线状态
            if (callback != string.Empty)
            {
                Response.ContentType = "text/html";
                if (action.Format == FormatType.JSON)
                {
                    content = callback + "(" + content + ");";
                }
                else
                {
                    content = callback + "(\"" + content.Replace("\"", "\\\"") + "\");";
                }
            }
            Response.Write(content);
            Response.End();

        }
Ejemplo n.º 16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                int    pertask       = DNTRequest.GetInt("pertask", 0);
                int    lastnumber    = DNTRequest.GetInt("lastnumber", 0);
                int    startvalue    = DNTRequest.GetInt("startvalue", 0);
                int    endvalue      = DNTRequest.GetInt("endvalue", 0);
                string resultmessage = "";
                switch (Request.Params["opname"])
                {
                case "UpdatePostSP":
                    AdminForumStats.UpdatePostSP(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "UpdateMyPost":
                    AdminForumStats.UpdateMyPost(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetFourmTopicAPost":
                    //AdminForumStats.ReSetFourmTopicAPost(pertask, ref lastnumber);
                    AdminForumStats.ReSetFourmTopicAPost();
                    resultmessage = "-1";
                    break;

                case "ReSetUserDigestPosts":
                    //AdminForumStats.ReSetUserDigestPosts(pertask, ref lastnumber);
                    //resultmessage = lastnumber.ToString();
                    AdminForumStats.ReSetUserDigestPosts();
                    resultmessage = "-1";
                    break;

                case "ReSetUserPosts":
                    AdminForumStats.ReSetUserPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetTopicPosts":
                    AdminForumStats.ReSetTopicPosts(pertask, ref lastnumber);
                    resultmessage = lastnumber.ToString();
                    break;

                case "ReSetFourmTopicAPost_StartEnd":
                    AdminForumStats.ReSetFourmTopicAPost(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetUserDigestPosts_StartEnd":
                    AdminForumStats.ReSetUserDigestPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetUserPosts_StartEnd":
                    AdminForumStats.ReSetUserPosts(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ReSetTopicPosts_StartEnd":
                    AdminForumStats.ResetLastRepliesInfoOfTopics(startvalue, endvalue);
                    resultmessage = "1";
                    break;

                case "ftptest":
                    FTPs   ftps    = new FTPs();
                    string message = "";
                    bool   ok      = ftps.TestConnect(DNTRequest.GetString("serveraddress"), DNTRequest.GetInt("serverport", 0), DNTRequest.GetString("username"),
                                                      DNTRequest.GetString("password"), DNTRequest.GetInt("timeout", 0), DNTRequest.GetString("uploadpath"), ref message);
                    resultmessage = ok ? "ok" : "远程附件设置测试出现错误!\n描述:" + message;
                    break;

                case "setapp":
                    APIConfigInfo aci = APIConfigs.GetConfig();
                    aci.Enable = DNTRequest.GetString("allowpassport") == "1";
                    APIConfigs.SaveConfig(aci);
                    resultmessage = "ok";
                    break;

                case "location":
                    string city = DNTRequest.GetString("city");
                    resultmessage = "ok";
                    DataTable dt = MallPluginProvider.GetInstance().GetLocationsTable();
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr["country"].ToString() == DNTRequest.GetString("country") && dr["state"].ToString() == DNTRequest.GetString("state") && dr["city"].ToString() == city)
                        {
                            resultmessage = "<img src='../images/false.gif' title='" + city + "已经存在!'>";
                            break;
                        }
                    }
                    break;

                case "goodsinfo":
                    int       goodsid   = DNTRequest.GetInt("goodsid", 0);
                    Goodsinfo goodsinfo = MallPluginProvider.GetInstance().GetGoodsInfo(goodsid);
                    if (goodsinfo == null)
                    {
                        resultmessage = "商品不存在!";
                        break;
                    }
                    //GoodsattachmentinfoCollection attachmentinfos = GoodsAttachments.GetGoodsAttachmentsByGoodsid(goodsinfo.Goodsid);
                    //string img = "";
                    //if (attachmentinfos != null)
                    //{
                    //    img = attachmentinfos[0].Filename;
                    //}
                    PostpramsInfo param = new PostpramsInfo();
                    param.Allowhtml  = 1;
                    param.Showimages = 1;
                    param.Sdetail    = goodsinfo.Message;
                    resultmessage    = "<table width='100%'><tr><td>" + UBB.UBBToHTML(param) + "</td></tr></table>";
                    break;

                case "downloadword":
                    dt = BanWords.GetBanWordList();
                    string words = "";
                    if (dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            words += dt.Rows[i][2].ToString() + "=" + dt.Rows[i][3].ToString() + "\r\n";
                        }
                    }

                    string filename = "words.txt";
                    HttpContext.Current.Response.Clear();
                    HttpContext.Current.Response.Buffer          = false;
                    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(filename));
                    HttpContext.Current.Response.ContentType = "text/plain";
                    HttpContext.Current.Response.Write(words);
                    HttpContext.Current.Response.End();
                    break;

                case "gettopicinfo":
                    StringBuilder sb   = new StringBuilder();
                    TopicInfo     info = Topics.GetTopicInfo(DNTRequest.GetInt("tid", 0));
                    sb.Append("[");
                    if (info != null)
                    {
                        sb.Append(string.Format("{{'tid':{0},'title':'{1}'}}", info.Tid, info.Title));
                    }

                    System.Web.HttpContext.Current.Response.Clear();
                    System.Web.HttpContext.Current.Response.ContentType = "application/json";
                    System.Web.HttpContext.Current.Response.Expires     = 0;
                    System.Web.HttpContext.Current.Response.Cache.SetNoStore();
                    System.Web.HttpContext.Current.Response.Write(sb.Append("]").ToString());
                    System.Web.HttpContext.Current.Response.End();
                    break;
                }
                Response.Write(resultmessage);
                Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
                Response.Expires         = -1;
                Response.End();
            }
        }
        protected void savepassportinfo_Click(object sender, EventArgs e)
        {
            if (appname.Text.Trim() == "")
            {
                base.RegisterStartupScript("PAGE", "alert('整合程序名称不能为空!');");
                return;
            }
            if (applicationtype.SelectedValue != "2")
            {
                if (appurl.Text.Trim() == "")
                {
                    base.RegisterStartupScript("PAGE", "alert('整合程序 Url 地址不能为空!');");
                    return;
                }
                if (applicationtype.SelectedValue == "1" && callbackurl.Text.Trim() == "")
                {
                    base.RegisterStartupScript("PAGE", "alert('登录完成后返回地址不能为空!');");
                    return;
                }
            }
            if (ipaddresses.Text.Trim() != "")
            {
                foreach (string ip in ipaddresses.Text.Replace("\r\n", "").Replace(" ", "").Split(','))
                {
                    if (!Utils.IsIP(ip))
                    {
                        base.RegisterStartupScript("PAGE", "alert('IP地址格式错误!');");
                        return;
                    }
                }
            }
            if (apikeyhidd.Value == "") //增加
            {
                ApplicationInfo ai = new ApplicationInfo();
                ai.AppName         = appname.Text;
                ai.AppUrl          = appurl.Text;
                ai.APIKey          = Utils.MD5(System.Guid.NewGuid().ToString());
                ai.Secret          = Utils.MD5(System.Guid.NewGuid().ToString());
                ai.ApplicationType = Convert.ToInt32(applicationtype.SelectedValue);
                if (ai.ApplicationType == 1)
                {
                    ai.CallbackUrl = callbackurl.Text;
                }
                else
                {
                    ai.CallbackUrl = "";
                }
                ai.CallbackUrl = callbackurl.Text;
                ai.IPAddresses = ipaddresses.Text.Replace("\r\n", "").Replace(" ", "");

                ai.SyncMode = Convert.ToInt32(asyncmode.SelectedValue);
                ai.SyncUrl  = asyncurl.Text;
                ai.SyncList = asynclist.Text;

                APIConfigInfo aci = APIConfigs.GetConfig();
                if (aci.AppCollection == null)
                {
                    aci.AppCollection = new ApplicationInfoCollection();
                }
                aci.AppCollection.Add(ai);
                APIConfigs.SaveConfig(aci);
            }
            else   //修改
            {
                APIConfigInfo aci = APIConfigs.GetConfig();
                foreach (ApplicationInfo ai in aci.AppCollection)
                {
                    if (ai.APIKey == apikeyhidd.Value)
                    {
                        ai.AppName         = appname.Text;
                        ai.AppUrl          = appurl.Text;
                        ai.ApplicationType = Convert.ToInt32(applicationtype.SelectedValue);
                        if (ai.ApplicationType == 1)
                        {
                            ai.CallbackUrl = callbackurl.Text;
                        }
                        else
                        {
                            ai.CallbackUrl = "";
                        }
                        ai.CallbackUrl = callbackurl.Text;
                        ai.IPAddresses = ipaddresses.Text.Replace("\r\n", "").Replace(" ", "");

                        ai.SyncMode = Convert.ToInt32(asyncmode.SelectedValue);
                        ai.SyncUrl  = asyncurl.Text;
                        ai.SyncList = asynclist.Text;
                        break;
                    }
                }
                APIConfigs.SaveConfig(aci);
            }
            Response.Redirect("global_passportmanage.aspx");
        }