Esempio n. 1
0
        public IActionResult Authorize()
        {
            string res = "";

            //this.Session.WebOSHandle = this["Handle"];
            //this.Session.WebOSGuid = this["Guid"];
            string key      = this["sn"];
            string redirect = HttpUtility.UrlDecode(this["redirect"], System.Text.Encoding.UTF8);

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                var row = dbc.GetOne("@{$[AosAuthorize].[*]&[Code=='" + key + "']}");
                if (row.IsEmpty)
                {
                    return(TextContent("授权失败:授权码不正确"));
                }
                string code = "";
                do
                {
                    code = Guid.NewGuid().ToString().Replace("-", "");
                } while (!dbc.GetOne("@{$[AosAuthorizeCode].[*]&[Code=='" + code + "']}").IsEmpty);
                dbc.Exec("+{$[AosAuthorizeCode].[AuthID='" + row["ID"] + "'].[SessionID='" + this.Session.SessionID + "'].[Code='" + code + "'].[Token=''].[EffectiveTime='" + dpz.Time.New(DateTime.Now.AddMinutes(30)).ToTimeStamp() + "'].[Status='0']}");
                res = redirect + "?code=" + code;
            }

            Response.Redirect(res);

            return(TextContent(res));
        }
Esempio n. 2
0
        //获取用户授权列表
        public IRequestResult GetList()
        {
            if (!this.Verification)
            {
                return(Error("空闲超时或交互标识无效", 0));
            }

            string ip = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
                        .Select(p => p.GetIPProperties())
                        .SelectMany(p => p.UnicastAddresses)
                        .Where(p => p.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && !System.Net.IPAddress.IsLoopback(p.Address))
                        .FirstOrDefault()?.Address.ToString();

            long uid       = Session["User_ID"].ToLong();
            long desktopId = ((string)JReqData.DesktopID).ToLong();

            if (desktopId <= 0)
            {
                return(Fail("未指定一个有效的云桌面信息"));
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                var list = dbc.GetGdmlList($"@{{$[AosUserAuthorize]$[AosDesktopAuthorizes]$[AosAuthorize].[*]&[AosUserAuthorize.UserID=='{uid}'&&AosUserAuthorize.AuthID==AosAuthorize.ID&&AosDesktopAuthorizes.AuthID==AosAuthorize.ID&&AosDesktopAuthorizes.DesktopID=='{desktopId}'&&AosDesktopAuthorizes.Compatibility=='1']}}");
                JData.List = new List <dpz.Dynamic>();
                List <dpz.Dynamic> jList = JData.List;
                foreach (var row in list)
                {
                    //进行数据过滤
                    row["UrlEntrance"] = row["UrlEntrance"].Replace("${IP}", ip);
                    long userCreate = row["CreateUserID"].ToLong();
                    //int active = row["Active"].ToInteger();
                    //row["InfoStatus"] = active > 0 ? "√" : "";

                    var jRow = new dpz.Dynamic();
                    foreach (var item in row)
                    {
                        switch (item.Key)
                        {
                        //case "DBType":
                        case "DBIP":
                        case "DBPort":
                        case "DBUser":
                        case "DBPwd":
                        case "DBPath":
                        //case "Code":
                        case "SecurityKey":
                            break;

                        default:
                            jRow[item.Key] = item.Value;
                            break;
                        }
                    }
                    jList.Add(jRow);
                }
            }

            return(Success());
        }
        public ActionResult CreateApp()
        {
            long authId = 0;

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                if (!dbc.CheckTable("AosAuthorize"))
                {
                    return(JsonContent(0, $"请先安装AosAuthorize表"));
                }

                var row = dbc.GetGdmlOne($"@{{$[AosAuthorize]&[DBSign=='Manage']}}");
                if (row.IsEmpty)
                {
                    return(JsonContent(0, "请先添加管理授权"));
                }
                authId = row["ID"].ToLong();
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                if (!dbc.CheckTable("AosApps"))
                {
                    return(JsonContent(0, $"请先安装AosApps表"));
                }

                //添加APP管理应用
                if (dbc.GetGdmlOne($"@{{$[AosApps]&[Name=='AosApps']}}").IsEmpty)
                {
                    dbc.ExecGdml($"+{{$[AosApps].[AuthID='{authId}'].[Name='AosApps'].[Text='应用管理'].[Path='{site.Config.Url.Manage}/App/AosApps/Index/'].[OnStore='0'].[IsDesktop='0'].[Description='管理所有的应用'].[CatalogID='0']}}");
                }

                //添加用户管理应用
                if (dbc.GetGdmlOne($"@{{$[AosApps]&[Name=='AosUsers']}}").IsEmpty)
                {
                    dbc.ExecGdml($"+{{$[AosApps].[AuthID='{authId}'].[Name='AosUsers'].[Text='用户管理'].[Path='{site.Config.Url.Manage}/App/AosUsers/Index/'].[OnStore='0'].[IsDesktop='0'].[Description='管理所有的平台用户'].[CatalogID='0']}}");
                }

                //添加授权管理应用
                if (dbc.GetGdmlOne($"@{{$[AosApps]&[Name=='AosAuthorize']}}").IsEmpty)
                {
                    dbc.ExecGdml($"+{{$[AosApps].[AuthID='{authId}'].[Name='AosAuthorize'].[Text='授权管理'].[Path='{site.Config.Url.Manage}/App/Authorize/Index/'].[OnStore='0'].[IsDesktop='0'].[Description='管理所有的平台授权'].[CatalogID='0']}}");
                }

                //添加用户APP管理应用
                if (dbc.GetGdmlOne($"@{{$[AosApps]&[Name=='AosUserApps']}}").IsEmpty)
                {
                    dbc.ExecGdml($"+{{$[AosApps].[AuthID='{authId}'].[Name='AosUserApps'].[Text='用户应用管理'].[Path='{site.Config.Url.Manage}/App/AosUserApps/Index/'].[OnStore='0'].[IsDesktop='0'].[Description='管理所有的平台用户关联应用'].[CatalogID='0']}}");
                }

                //添加用户APP管理应用
                if (dbc.GetGdmlOne($"@{{$[AosApps]&[Name=='AosUserAuthorize']}}").IsEmpty)
                {
                    dbc.ExecGdml($"+{{$[AosApps].[AuthID='{authId}'].[Name='AosUserAuthorize'].[Text='用户授权管理'].[Path='{site.Config.Url.Manage}/App/AosUserAuthorize/Index/'].[OnStore='0'].[IsDesktop='0'].[Description='管理所有的平台用户关联授权'].[CatalogID='0']}}");
                }
            }

            return(JsonContent(1));
        }
Esempio n. 4
0
        //激活授权
        public IRequestResult GetActive()
        {
            if (!this.Verification)
            {
                return(Error("空闲超时或交互标识无效", 0));
            }

            string ip = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
                        .Select(p => p.GetIPProperties())
                        .SelectMany(p => p.UnicastAddresses)
                        .Where(p => p.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && !System.Net.IPAddress.IsLoopback(p.Address))
                        .FirstOrDefault()?.Address.ToString();

            long uid = Session["User_ID"].ToLong();

            //string aid = JRequest.Data["AuthID"];
            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                var row = dbc.GetGdmlOne($"@{{$[AosUserAuthorize]$[AosAuthorize].[*]&[AosUserAuthorize.UserID=='{uid}'&&AosUserAuthorize.Active=='1'&&AosUserAuthorize.AuthID==AosAuthorize.ID]}}");
                if (row.IsEmpty)
                {
                    return(Fail($"无可操作对象,请先激活一个可操作的对象"));
                }

                //进行数据过滤
                row["UrlEntrance"] = row["UrlEntrance"].Replace("${IP}", ip);
                long userCreate = row["CreateUserID"].ToLong();
                if (userCreate != uid)
                {
                    row["Code"]        = "";
                    row["SecurityKey"] = "";
                }

                foreach (var item in row)
                {
                    switch (item.Key)
                    {
                    case "DBType":
                    case "DBIP":
                    case "DBPort":
                    case "DBUser":
                    case "DBPwd":
                    case "DBPath":
                        break;

                    default:
                        JData[item.Key] = item.Value;
                        break;
                    }
                }
            }

            return(Success());
        }
        public IActionResult CreateAos()
        {
            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Defend)) {
                //var row = dbc.GetOne("select * from sys.databases where [name] = 'Aos'");
                if (dbc.CheckDatabase("Aos"))
                {
                    return(JsonContent(0, "数据库已经存在"));
                }

                dbc.CreateDatabase("Aos");
            }

            return(JsonContent(1));
        }
Esempio n. 6
0
        //获取用户授权列表
        public IRequestResult GetList()
        {
            if (!this.Verification)
            {
                return(Error("空闲超时或交互标识无效", 0));
            }

            long aid = ((string)JRequest.Data["AuthID"]).ToLong();

            string ip = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
                        .Select(p => p.GetIPProperties())
                        .SelectMany(p => p.UnicastAddresses)
                        .Where(p => p.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && !System.Net.IPAddress.IsLoopback(p.Address))
                        .FirstOrDefault()?.Address.ToString();

            long uid = Session["User_ID"].ToLong();

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                var list = dbc.GetGdmlList($"@{{$[AosUserApps]$[AosApps].[*]&[AosUserApps.UserID=='{uid}'&&AosUserApps.AuthID=='{aid}'&&AosUserApps.AppID==AosApps.ID]+[AosApps.Index]}}");
                JData.List = new List <dpz.Dynamic>();
                List <dpz.Dynamic> jList = JData.List;
                foreach (var row in list)
                {
                    //进行数据过滤
                    row["Path"] = row["Path"].Replace("${IP}", ip);

                    var jRow = new dpz.Dynamic();
                    foreach (var item in row)
                    {
                        switch (item.Key)
                        {
                        case "DBType":
                        case "DBIP":
                        case "DBPort":
                        case "DBUser":
                        case "DBPwd":
                        case "DBPath":
                            break;

                        default:
                            jRow[item.Key] = item.Value;
                            break;
                        }
                    }
                    jList.Add(jRow);
                }
            }

            return(Success());
        }
Esempio n. 7
0
        //获取GUID
        public IRequestResult Login()
        {
            if (!base.Verification)
            {
                return(Fail("交互标识无效或已过期"));
            }

            string szName = JRequest.Data["Name"].Value;
            string szPwd  = JRequest.Data["Pwd"].Value;

            long timeSession = Session["Session_Time"].ToLong();
            long timeLogin   = Session["User_Login_Time"].ToLong();
            long timeNow     = dpz.Time.Now.ToTimeStamp();

            if (timeNow - timeSession < 2)
            {
                return(Fail("创建新的连接2秒内不允许进行用户登录"));
            }

            if (timeNow - timeLogin < 2)
            {
                return(Fail("操作过于频繁"));
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                var row = dbc.GetGdmlOne($"@{{$[AosUsers]&[Name=='{szName}']}}");
                if (row.IsEmpty)
                {
                    return(Fail("用户不存在"));
                }
                string szSuperPwd = site.Config.Security.GetEncryptionPasswordString(szName, szPwd);
                string szUserPwd  = row["Pwd"];
                if (szSuperPwd != szUserPwd)
                {
                    Session["User_Login_Time"] = "" + timeNow;
                    return(Fail("密码错误"));
                }

                Session["User_ID"] = row["ID"];
            }

            return(Success());
        }
Esempio n. 8
0
        //获取GUID
        public IRequestResult Repwd()
        {
            if (!base.Verification)
            {
                return(Fail("交互标识无效或已过期"));
            }

            long userId = Session["User_ID"].ToLong();
            //string szName = JRequest.Data["Name"].Value;
            string oldPwd = JRequest.Data["OldPwd"].Value;
            string newPwd = JRequest.Data["NewPwd"].Value;
            string rePwd  = JRequest.Data["RePwd"].Value;

            if (newPwd != rePwd)
            {
                return(Fail("两次输入的密码不一致"));
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                var row = dbc.GetGdmlOne($"@{{$[AosUsers]&[ID=='{userId}']}}");
                if (row.IsEmpty)
                {
                    return(Fail("用户不存在"));
                }

                //验证旧密码
                string oldSuperPwd = site.Config.Security.GetEncryptionPasswordString(row["Name"], oldPwd);
                string userPwd     = row["Pwd"];
                if (oldSuperPwd != userPwd)
                {
                    //Session["User_Login_Time"] = "" + timeNow;
                    return(Fail("密码错误"));
                }

                //更新新密码
                string newSuperPwd = site.Config.Security.GetEncryptionPasswordString(row["Name"], newPwd);
                dbc.ExecGdml($"!{{$[AosUsers].[Pwd='{newSuperPwd}']&[ID=='{userId}']}}");

                //Session["User_ID"] = row["ID"];
            }

            return(Success());
        }
Esempio n. 9
0
        public IRequestResult GetInfo()
        {
            long uid = Session["User_ID"].ToLong();

            if (uid <= 0)
            {
                return(Fail());
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                var row = dbc.GetGdmlOne($"@{{$[AosUsers]&[ID=='{uid}']}}");
                foreach (var item in row)
                {
                    if (item.Key != "Pwd")
                    {
                        JData[item.Key] = item.Value;
                    }
                }
            }

            return(Success());
        }
Esempio n. 10
0
        //激活授权
        public IRequestResult Active()
        {
            if (!this.Verification)
            {
                return(Error("空闲超时或交互标识无效", 0));
            }

            long   uid = Session["User_ID"].ToLong();
            string aid = JRequest.Data["AuthID"];

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                var row = dbc.GetGdmlOne($"@{{$[AosUserAuthorize]$[AosAuthorize].[*]&[UserID=='{uid}'&&AuthID=='{aid}']}}");
                if (row.IsEmpty)
                {
                    return(Fail($"无操作权限"));
                }
                dbc.ExecGdml($"!{{$[AosUserAuthorize].[Active='0']&[UserID=='{uid}']}}");
                dbc.ExecGdml($"!{{$[AosUserAuthorize].[Active='1']&[ID=='{row["ID"]}']}}");
            }

            return(Success());
        }
Esempio n. 11
0
        //获取GUID
        public IRequestResult Create()
        {
            if (!this.Verification)
            {
                return(Error("空闲超时或交互标识无效", 0));
            }

            long aid = (JReqData.AuthID as string).ToLong();

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                string code = "";
                do
                {
                    code = Guid.NewGuid().ToString().Replace("-", "");
                } while (!dbc.GetOne("@{$[AosAuthorizeCode].[*]&[Code=='" + code + "']}").IsEmpty);
                dbc.Exec("+{$[AosAuthorizeCode].[AuthID='" + aid + "'].[SessionID='" + this.Session.SessionID + "'].[Code='" + code + "'].[Token=''].[EffectiveTime='" + dpz.Time.New(DateTime.Now.AddMinutes(30)).ToTimeStamp() + "'].[Status='0']}");
                //res = redirect + "?code=" + code;
                JData.Code = code;
            }

            return(Success());
        }
Esempio n. 12
0
        public IRequestResult Get()
        {
            string host = "" + JReqData.Host;
            //string host = "" + JReqData.Host;
            string ip = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
                        .Select(p => p.GetIPProperties())
                        .SelectMany(p => p.UnicastAddresses)
                        .Where(p => p.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && !System.Net.IPAddress.IsLoopback(p.Address))
                        .FirstOrDefault()?.Address.ToString();

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                var row = dbc.GetGdmlOne($"@{{$[AosDesktops]&[Host=='{host}'||Host??'{host}|%'||Host??'%|{host}|%'||Host??'%|{host}']}}");
                if (row.IsEmpty)
                {
                    row = dbc.GetGdmlOne($"@{{$[AosDesktops]&[Host=='*']}}");
                }
                if (row.IsEmpty)
                {
                    return(Fail("未找到满足条件的云桌面设置"));
                }

                row["UrlEntrance"] = row["UrlEntrance"].Replace("${IP}", ip);
                JData.Row          = row;
                JData.Host         = host;

                //dpz.Jsons.Jttp jttp = new dpz.Jsons.Jttp();
                //jttp.Header.Status = "1";
                //jttp.Header.Type = "Console";
                //string entrance = row["UrlEntrance"] + row["ScriptEntrance"];

                //jttp.Data.Host = host;
                //jttp.Data.Command = $"load-js 'Aos_Desktop_Entrance' '{entrance}'";
                //RenderJttps.Add(jttp);
            }
            return(Success());
        }
Esempio n. 13
0
        public ActionResult CreateRootUserApp()
        {
            long authId = 0;
            long appId  = this["appid"].ToLong();
            long uid    = 0;

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                if (!dbc.CheckTable("AosAuthorize"))
                {
                    return(JsonContent(0, $"请先安装AosAuthorize表"));
                }

                if (!dbc.CheckTable("AosUsers"))
                {
                    return(JsonContent(0, $"请先安装AosUsers表"));
                }

                if (!dbc.CheckTable("AosApps"))
                {
                    return(JsonContent(0, $"请先安装AosApps表"));
                }

                if (!dbc.CheckTable("AosUserApps"))
                {
                    return(JsonContent(0, $"请先安装AosUserApps表"));
                }

                if (!dbc.CheckTable("AosUserAuthorize"))
                {
                    return(JsonContent(0, $"请先安装AosUserAuthorize表"));
                }

                var row = dbc.GetGdmlOne($"@{{$[AosAuthorize]&[DBSign=='Manage']}}");
                if (row.IsEmpty)
                {
                    return(JsonContent(0, "请先添加管理授权"));
                }

                authId = row["ID"].ToLong();

                var rowUser = dbc.GetGdmlOne($"@{{$[AosUsers]&[Name=='root']}}");
                if (rowUser.IsEmpty)
                {
                    return(JsonContent(0, "请先添加管理用户"));
                }

                uid = rowUser["ID"].ToLong();

                //添加根用户关联APP
                var rowApp = dbc.GetGdmlOne($"@{{$[AosApps]&[ID=='{appId}']}}");
                if (rowApp.IsEmpty)
                {
                    return(JsonContent(0, "应用不存在,请先添加应用"));
                }

                if (dbc.GetGdmlOne($"@{{$[AosUserApps]&[UserID=='{uid}'&&AuthID=='{authId}'&&AppID=='{appId}']}}").IsEmpty)
                {
                    dbc.ExecGdml($"+{{$[AosUserApps].[UserID='{uid}'].[AuthID='{authId}'].[AppID='{appId}'].[Limit='']}}");
                }
            }

            return(JsonContent(1));
        }
Esempio n. 14
0
        public ActionResult CreateManage()
        {
            long authId    = 0;
            long desktopId = 0;

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                if (!dbc.CheckTable("AosDesktops"))
                {
                    return(JsonContent(0, $"请先安装AosDesktops表"));
                }

                //添加默认桌面
                if (dbc.GetGdmlOne($"@{{$[AosDesktops]&[Host=='*']}}").IsEmpty)
                {
                    dbc.ExecGdml($"+{{$[AosDesktops].[Name='Ycp'].[Text='云谊通云平台'].[Path=''].[Host='*'].[ScriptEntrance='/js/load.js'].[UrlEntrance='{site.Config.Url.Desktop}'].[Description='专业云应用协作平台']}}");
                }

                desktopId = dbc.GetGdmlOne($"@{{$[AosDesktops]&[Host=='*']}}")["ID"].ToLong();
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                if (!dbc.CheckTable("AosAuthorize"))
                {
                    return(JsonContent(0, $"请先安装AosAuthorize表"));
                }

                //添加授权信息
                if (dbc.GetGdmlOne($"@{{$[AosAuthorize]&[DBSign=='Manage']}}").IsEmpty)
                {
                    string code        = "";
                    string securityKey = Guid.NewGuid().ToString().Replace("-", "");

                    do
                    {
                        code = Guid.NewGuid().ToString();
                    } while (!dbc.GetGdmlOne($"@{{$[AosAuthorize]&[Code=='{code}']}}").IsEmpty);

                    JResponse["Code"]        = code;
                    JResponse["SecurityKey"] = securityKey;

                    dbc.ExecGdml($"+{{$[AosAuthorize].[Name='系统管理'].[Code='{code}'].[SecurityKey='{securityKey}'].[Lv='0'].[DBType='SqlServer'].[DBSign='Manage'].[DBIP=''].[DBPort='0'].[DBUser=''].[DBPwd=''].[ScriptEntrance='/js/load.js'].[UrlEntrance='{site.Config.Url.Manage}']}}");
                }

                authId = dbc.GetGdmlOne($"@{{$[AosAuthorize]&[DBSign=='Manage']}}")["ID"].ToLong();
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                if (!dbc.CheckTable("AosDesktopAuthorizes"))
                {
                    return(JsonContent(0, $"请先安装AosDesktopAuthorizes表"));
                }

                //添加桌面授权兼容信息
                var row = dbc.GetGdmlOne($"@{{$[AosDesktopAuthorizes]&[DesktopID=='{desktopId}'&&AuthID=='{authId}']}}");
                if (row.IsEmpty)
                {
                    dbc.ExecGdml($"+{{$[AosDesktopAuthorizes].[AuthID='{authId}'].[DesktopID='{desktopId}'].[Compatibility='1']}}");
                }
                else
                {
                    if (row["Compatibility"].ToInteger() <= 0)
                    {
                        dbc.ExecGdml($"!{{$[AosDesktopAuthorizes].[Compatibility='1']&[ID=='{row["ID"]}']}}");
                    }
                }
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Defend)) {
                //检测数据库,不存在则创建
                if (!dbc.CheckDatabase("Aos_Manage"))
                {
                    dbc.CreateDatabase("Aos_Manage");
                }
            }

            return(JsonContent(1));
        }
Esempio n. 15
0
        private string GetInfoBySid(string sid, string randString, string md5)
        {
            dpz.Jsons.Jttp res = new dpz.Jsons.Jttp();

            if (sid.IsNone())
            {
                res.Header.Status = "0";
                res.Message       = "交互标识无效";
                return(res.ToJson());
            }

            if (randString.IsNone())
            {
                res.Header.Status = "0";
                res.Message       = "缺少身份授权所需的随机字符串";
                return(res.ToJson());
            }

            if (randString.Length < 32)
            {
                res.Header.Status = "0";
                res.Message       = "为保证通讯安全,身份授权所需的随机字符串最少长度为32位";
                return(res.ToJson());
            }

            if (md5.IsNone())
            {
                res.Header.Status = "0";
                res.Message       = "缺少身份授权所需的验证码";
                return(res.ToJson());
            }

            using (dpz.Mvc.Sessions.RedisSessionManager redis = new dpz.Mvc.Sessions.RedisSessionManager(site.Config.Redis.ConnectionString, false, sid)) {
                //redis.CreateSessionId();
                if (!redis.CheckSessionId(sid, false))
                {
                    res.Header.Status = "0";
                    res.Message       = "交互标识无效";
                    return(res.ToJson());
                }

                long   uid        = redis["User_ID"].ToLong();
                string sessionKey = redis["Session_Key"];

                if (uid <= 0)
                {
                    res.Header.Status = "0";
                    res.Message       = "用户尚未登录或登陆状态失效";
                    return(res.ToJson());
                }

                using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                    var row = dbc.GetGdmlOne($"@{{$[AosUsers]&[ID=='{uid}']}}");
                    if (row.IsEmpty)
                    {
                        res.Header.Status = "0";
                        res.Message       = "未找到用户信息";
                        return(res.ToJson());
                    }

                    string name    = row["Name"];
                    string userMD5 = ("name=" + name + "&str=" + randString + "&key=" + sessionKey).GetMD5();
                    if (md5 != userMD5)
                    {
                        res.Header.Status = "0";
                        res.Message       = "MD5验证失败";
                        return(res.ToJson());
                    }

                    foreach (var item in row)
                    {
                        if (item.Key != "Pwd")
                        {
                            res.Data[item.Key] = item.Value;
                        }
                    }
                }

                res.Header.Status = "1";
                return(res.ToJson());
            }
        }
Esempio n. 16
0
        public ActionResult CreateManageTable()
        {
            string plmName = this["platform"];
            string tabName = this["table"];

            if (tabName != "SystemObjects")
            {
                using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Manage)) {
                    if (!dbc.CheckTable("SystemObjects"))
                    {
                        return(JsonContent(0, $"请先安装SystemObjects表"));
                    }
                }
            }

            string tabVersion = "";
            string xmlSetting = dpz.Net.Http.GetUTF8($"{site.Config.Orm.XmlUrl}/Setting.xml");

            using (dpz.Data.Xml xml = new dpz.Data.Xml(xmlSetting)) {
                var xmlDB    = xml["database"];
                var xmlAos   = xmlDB.GetNodeByAttrValue("name", plmName, false);
                var xmlTable = xmlAos.GetNodeByAttrValue("name", tabName, false);
                tabVersion = xmlTable.Attr["version"];
            }

            string xmlString = dpz.Net.Http.GetUTF8($"{site.Config.Orm.XmlUrl}/{plmName}/{tabName}.xml");

            if (xmlString == "")
            {
                return(JsonContent(0, "配置获取失败,请检查表名称是否存在"));
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Manage)) {
                string sql = "";

                using (dpz.Data.Xml xml = new dpz.Data.Xml(xmlString)) {
                    var xmlTable = xml["table"];

                    //判断表是否存在
                    //if (!dbc.GetOne($"Select * From sysObjects Where Name ='{tabName}' And Type In ('S','U')").HasData) {
                    if (!dbc.CheckTable(tabName))
                    {
                        //添加表
                        List <dpz.Gdbc.TableFieldDefine> fields = new List <dpz.Gdbc.TableFieldDefine>();

                        foreach (var xmlField in xmlTable.Nodes)
                        {
                            if (xmlField.Name.ToLower() == "field")
                            {
                                string fieldName      = xmlField.Attr["name"];
                                var    xmlData        = xmlField["data"];
                                string fieldDataType  = xmlData.Attr["type"].ToLower();
                                int    fieldDataSize  = xmlData.Attr["size"].ToInteger();
                                int    fieldDataFloat = xmlData.Attr["float"].ToInteger();

                                var field = new dpz.Gdbc.TableFieldDefine();
                                field.Name  = fieldName;
                                field.Type  = fieldDataType;
                                field.Size  = fieldDataSize;
                                field.Float = fieldDataFloat;
                                fields.Add(field);
                            }
                        }

                        dbc.CreateTable(tabName, fields);
                    }
                    else
                    {
                        //更新字段
                        foreach (var xmlField in xmlTable.Nodes)
                        {
                            if (xmlField.Name.ToLower() == "field")
                            {
                                string fieldName      = xmlField.Attr["name"];
                                var    xmlData        = xmlField["data"];
                                string fieldDataType  = xmlData.Attr["type"].ToLower();
                                int    fieldDataSize  = xmlData.Attr["size"].ToInteger();
                                int    fieldDataFloat = xmlData.Attr["float"].ToInteger();

                                dpz.Gdbc.TableFieldDefine fieldDefine = new dpz.Gdbc.TableFieldDefine()
                                {
                                    Name  = fieldName,
                                    Type  = fieldDataType,
                                    Size  = fieldDataSize,
                                    Float = fieldDataFloat
                                };

                                if (!dbc.CheckTableFiled(tabName, fieldName))
                                {
                                    dbc.AddTableFiled(tabName, fieldDefine);
                                }
                                else
                                {
                                    dbc.UpdateTableFiled(tabName, fieldName, fieldDefine);
                                }
                            }
                        }
                    }

                    //更新表格结构信息
                    if (dbc.GetGdmlOne($"@{{$[SystemObjects]&[Name=='{tabName}'&&Type=='Table']}}").IsEmpty)
                    {
                        string guid = "";
                        do
                        {
                            guid = Guid.NewGuid().ToString();
                        } while (!dbc.GetGdmlOne($"@{{$[SystemObjects]&[Guid=='{guid}']}}").IsEmpty);

                        dbc.ExecGdml($"+{{$[SystemObjects].[Name='{tabName}'].[Type='Table'].[Version='{tabVersion}'].[Guid='{guid}']}}");
                    }
                    else
                    {
                        dbc.ExecGdml($"!{{$[SystemObjects].[Version='{tabVersion}']&[Name=='{tabName}'&&Type=='Table']}}");
                    }

                    JResponse["Version"] = tabVersion;
                }
            }

            return(JsonContent(1));
        }
Esempio n. 17
0
        public ActionResult CreateAosTable()
        {
            //string plmName = this["platform"];
            string tabName = this["table"];

            if (tabName != "AosObjects")
            {
                using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                    if (!dbc.CheckTable("AosObjects"))
                    {
                        return(JsonContent(0, $"请在安装{tabName}表前先安装AosObjects表"));
                    }
                }
            }

            string tabVersion = "";
            string xmlSetting = dpz.Net.Http.GetUTF8($"{site.Config.Orm.XmlUrl}/Setting.xml");

            using (dpz.Data.Xml xml = new dpz.Data.Xml(xmlSetting)) {
                var xmlDB    = xml["database"];
                var xmlAos   = xmlDB.GetNodeByAttrValue("name", "Aos", false);
                var xmlTable = xmlAos.GetNodeByAttrValue("name", tabName, false);
                tabVersion = xmlTable.Attr["version"];
            }

            string xmlString = dpz.Net.Http.GetUTF8($"{site.Config.Orm.XmlUrl}/Aos/{tabName}.xml");

            if (xmlString == "")
            {
                return(JsonContent(0, "配置获取失败,请检查表名称是否存在"));
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                //string sql = "";

                using (dpz.Data.Xml xml = new dpz.Data.Xml(xmlString)) {
                    var xmlTable = xml["table"];

                    //判断表是否存在
                    if (!dbc.CheckTable(tabName))
                    {
                        List <dpz.Gdbc.TableFieldDefine> fields = new List <dpz.Gdbc.TableFieldDefine>();

                        foreach (var xmlField in xmlTable.Nodes)
                        {
                            if (xmlField.Name.ToLower() == "field")
                            {
                                string fieldName      = xmlField.Attr["name"];
                                var    xmlData        = xmlField["data"];
                                string fieldDataType  = xmlData.Attr["type"].ToLower();
                                int    fieldDataSize  = xmlData.Attr["size"].ToInteger();
                                int    fieldDataFloat = xmlData.Attr["float"].ToInteger();

                                var field = new dpz.Gdbc.TableFieldDefine();
                                field.Name  = fieldName;
                                field.Type  = fieldDataType;
                                field.Size  = fieldDataSize;
                                field.Float = fieldDataFloat;
                                fields.Add(field);
                            }
                        }

                        dbc.CreateTable(tabName, fields);
                    }
                    else
                    {
                        //更新字段
                        foreach (var xmlField in xmlTable.Nodes)
                        {
                            if (xmlField.Name.ToLower() == "field")
                            {
                                string fieldName      = xmlField.Attr["name"];
                                var    xmlData        = xmlField["data"];
                                string fieldDataType  = xmlData.Attr["type"].ToLower();
                                int    fieldDataSize  = xmlData.Attr["size"].ToInteger();
                                int    fieldDataFloat = xmlData.Attr["float"].ToInteger();

                                dpz.Gdbc.TableFieldDefine fieldDefine = new dpz.Gdbc.TableFieldDefine()
                                {
                                    Name  = fieldName,
                                    Type  = fieldDataType,
                                    Size  = fieldDataSize,
                                    Float = fieldDataFloat
                                };

                                if (!dbc.CheckTableFiled(tabName, fieldName))
                                {
                                    dbc.AddTableFiled(tabName, fieldDefine);
                                }
                                else
                                {
                                    dbc.UpdateTableFiled(tabName, fieldName, fieldDefine);
                                }
                            }
                        }
                    }

                    //更新表格结构信息
                    if (dbc.GetGdmlOne($"@{{$[AosObjects]&[Name=='{tabName}']}}").IsEmpty)
                    {
                        dbc.ExecGdml($"+{{$[AosObjects].[Name='{tabName}'].[Version='{tabVersion}']}}");
                    }
                    else
                    {
                        dbc.ExecGdml($"!{{$[AosObjects].[Version='{tabVersion}']&[Name=='{tabName}']}}");
                    }

                    JResponse["Version"] = tabVersion;
                }
            }

            return(JsonContent(1));
        }
Esempio n. 18
0
        public ActionResult CreateRoot()
        {
            long authId = 0;

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                if (!dbc.CheckTable("AosAuthorize"))
                {
                    return(JsonContent(0, $"请先安装AosAuthorize表"));
                }

                if (!dbc.CheckTable("AosUsers"))
                {
                    return(JsonContent(0, $"请先安装AosUsers表"));
                }

                if (!dbc.CheckTable("AosApps"))
                {
                    return(JsonContent(0, $"请先安装AosApps表"));
                }

                if (!dbc.CheckTable("AosUserApps"))
                {
                    return(JsonContent(0, $"请先安装AosUserApps表"));
                }

                if (!dbc.CheckTable("AosUserAuthorize"))
                {
                    return(JsonContent(0, $"请先安装AosUserAuthorize表"));
                }

                var row = dbc.GetGdmlOne($"@{{$[AosAuthorize]&[DBSign=='Manage']}}");
                if (row.IsEmpty)
                {
                    return(JsonContent(0, "请先添加管理授权"));
                }

                authId = row["ID"].ToLong();
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                //添加根用户
                var rowUser = dbc.GetGdmlOne($"@{{$[AosUsers]&[Name=='root']}}");
                if (rowUser.IsEmpty)
                {
                    string pwd = site.Config.Security.GetEncryptionPasswordString("root", "123456");
                    // "$" + YString.New("000000root" + web.Config.Password_Key).MD5;
                    dbc.ExecGdml($"+{{$[AosUsers].[Name='root'].[Pwd='{pwd}'].[Nick='超级管理员'].[Image=''].[Desktop='/App/Ydm2Desktop'].[Background=''].[Limit=''].[AuthorizeID='{authId}']}}");
                    rowUser = dbc.GetGdmlOne($"@{{$[AosUsers]&[Name=='root']}}");
                }

                //添加根用户授权
                if (dbc.GetGdmlOne($"@{{$[AosUserAuthorize]&[UserID=='{rowUser["ID"]}'&&AuthID=='{authId}']}}").IsEmpty)
                {
                    dbc.ExecGdml($"+{{$[AosUserAuthorize].[UserID='{rowUser["ID"]}'].[AuthID='{authId}'].[Limit='']}}");
                }

                //添加根用户关联APP
                //string[] appNeeds = new string[] { "AosApps", "AosUserApps", "AosUserAuthorize", "AosUsers", "AosAuthorize" };
                //for (int i = 0; i < appNeeds.Length; i++) {
                //    var rowApp = dbc.GetGdmlOne($"@{{$[AosApps]&[Name=='{appNeeds[i]}']}}");
                //    if (!rowApp.IsEmpty) {
                //        if (dbc.GetGdmlOne($"@{{$[AosUserApps]&[UserID=='{rowUser["ID"]}'&&AppID=='{rowApp["ID"]}']}}").IsEmpty)
                //            dbc.ExecGdml($"+{{$[AosUserApps].[UserID='{rowUser["ID"]}'].[AuthID='0'].[AppID='{rowApp["ID"]}'].[Limit='']}}");
                //    }
                //}
            }

            return(JsonContent(1));
        }
Esempio n. 19
0
        public ActionResult CreateManageApp()
        {
            long   authId = 0;
            string sign   = this["sign"];

            string ip = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()
                        .Select(p => p.GetIPProperties())
                        .SelectMany(p => p.UnicastAddresses)
                        .Where(p => p.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork && !System.Net.IPAddress.IsLoopback(p.Address))
                        .FirstOrDefault()?.Address.ToString();

            string manageUrl    = site.Config.Url.Manage.Replace("${IP}", ip);
            string appConfigUrl = site.Config.Url.ManageConfig.Replace("${IP}", ip);
            string appXmlString = dpz.Net.Http.GetUTF8(appConfigUrl);

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                if (!dbc.CheckTable("AosAuthorize"))
                {
                    return(JsonContent(0, $"请先安装AosAuthorize表"));
                }

                var row = dbc.GetGdmlOne($"@{{$[AosAuthorize]&[DBSign=='Manage']}}");
                if (row.IsEmpty)
                {
                    return(JsonContent(0, "请先添加管理授权"));
                }
                authId = row["ID"].ToLong();
            }

            using (dpz.Gdbc.Connection dbc = new dpz.Gdbc.Connection(site.Config.Database.Aos)) {
                if (!dbc.CheckTable("AosApps"))
                {
                    return(JsonContent(0, $"请先安装AosApps表"));
                }

                using (dpz.Data.Xml xml = new dpz.Data.Xml(appXmlString)) {
                    var    xmlEntity = xml["entity"];
                    var    xmlApps   = xmlEntity["apps"];
                    string appsSign  = xmlApps.Attr["sign"];
                    if (appsSign != "")
                    {
                        appsSign += ".";
                    }
                    foreach (var xmlApp in xmlApps.Nodes)
                    {
                        if (xmlApp.Name == "app")
                        {
                            string appSign = appsSign + xmlApp.Attr["sign"];

                            if (appSign == sign)
                            {
                                string appTitle = xmlApp.Attr["title"];
                                string appVer   = xmlApp.Attr["version"];
                                string appPath  = xmlApp.Attr["path"];
                                var    rowVer   = "";

                                var rowApp = dbc.GetGdmlOne($"@{{$[AosApps]&[AuthID=='{authId}'&&Name=='{appSign}']}}");
                                if (!rowApp.IsEmpty)
                                {
                                    rowVer = rowApp["Version"];
                                }

                                if (rowVer == "")
                                {
                                    dbc.ExecGdml($"+{{$[AosApps].[AuthID='{authId}'].[Name='{appSign}'].[Text='{appTitle}'].[Path='{appPath}'].[Version='{appVer}'].[OnStore='0'].[IsDesktop='0'].[Description=''].[CatalogID='0']}}");
                                }
                                else if (appVer != rowVer)
                                {
                                    dbc.ExecGdml($"!{{$[AosApps].[Text='{appTitle}'].[Path='{appPath}'].[Version='{appVer}']&[ID=='{rowApp["ID"]}']}}");
                                }

                                return(JsonContent(1));
                            }
                        }
                    }
                }
            }

            return(JsonContent(0, $"未找到应用配置信息"));
        }