public IHttpActionResult Get()
        {
            try
            {
                var request  = new AuthenticatedRequest();
                var redirect = request.AdminRedirectCheck(checkInstall: true, checkDatabaseVersion: true);
                if (redirect != null)
                {
                    return(Ok(redirect));
                }

                return(Ok(new
                {
                    Value = true,
                    SystemManager.ProductVersion
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Beispiel #2
0
        public IHttpActionResult GetConfig()
        {
            try
            {
                var request  = new AuthenticatedRequest();
                var redirect = request.AdminRedirectCheck(checkInstall: true, checkDatabaseVersion: true, checkLogin: true);
                if (redirect != null)
                {
                    return(Ok(redirect));
                }

                var siteId       = request.GetQueryInt("siteId");
                var siteInfo     = SiteManager.GetSiteInfo(siteId);
                var adminInfo    = request.AdminInfo;
                var permissions  = request.AdminPermissionsImpl;
                var isSuperAdmin = permissions.IsConsoleAdministrator;
                var siteIdListWithPermissions = permissions.GetSiteIdList();

                if (siteInfo == null || !siteIdListWithPermissions.Contains(siteInfo.Id))
                {
                    if (siteIdListWithPermissions.Contains(adminInfo.SiteId))
                    {
                        return(Ok(new
                        {
                            Value = false,
                            RedirectUrl = PageUtils.GetMainUrl(adminInfo.SiteId)
                        }));
                    }

                    if (siteIdListWithPermissions.Count > 0)
                    {
                        return(Ok(new
                        {
                            Value = false,
                            RedirectUrl = PageUtils.GetMainUrl(siteIdListWithPermissions[0])
                        }));
                    }

                    if (isSuperAdmin)
                    {
                        return(Ok(new
                        {
                            Value = false,
                            RedirectUrl = PageSiteAdd.GetRedirectUrl()
                        }));
                    }

                    return(Ok(new
                    {
                        Value = false,
                        RedirectUrl = $"pageError.html?message={HttpUtility.UrlEncode("您没有可以管理的站点,请联系超级管理员协助解决")}"
                    }));
                }

                var packageIds = new List <string>
                {
                    PackageUtils.PackageIdSsCms
                };
                var packageList = new List <object>();
                var dict        = PluginManager.GetPluginIdAndVersionDict();
                foreach (var id in dict.Keys)
                {
                    packageIds.Add(id);
                    var version = dict[id];
                    packageList.Add(new
                    {
                        id,
                        version
                    });
                }

                var siteIdListLatestAccessed = DataProvider.AdministratorDao.UpdateSiteId(adminInfo, siteInfo.Id);

                var permissionList = new List <string>(permissions.PermissionList);
                if (permissions.HasSitePermissions(siteInfo.Id))
                {
                    var websitePermissionList = permissions.GetSitePermissions(siteInfo.Id);
                    if (websitePermissionList != null)
                    {
                        permissionList.AddRange(websitePermissionList);
                    }
                }
                var channelPermissions = permissions.GetChannelPermissions(siteInfo.Id);
                if (channelPermissions.Count > 0)
                {
                    permissionList.AddRange(channelPermissions);
                }

                var topMenus  = GetTopMenus(siteInfo, isSuperAdmin, siteIdListLatestAccessed, siteIdListWithPermissions);
                var siteMenus =
                    GetLeftMenus(siteInfo, ConfigManager.TopMenu.IdSite, isSuperAdmin, permissionList);
                var pluginMenus = GetLeftMenus(siteInfo, string.Empty, isSuperAdmin, permissionList);

                return(Ok(new
                {
                    Value = true,
                    DefaultPageUrl = PluginMenuManager.GetSystemDefaultPageUrl(siteId) ?? "dashboard.cshtml",
                    IsNightly = WebConfigUtils.IsNightlyUpdate,
                    SystemManager.ProductVersion,
                    SystemManager.PluginVersion,
                    SystemManager.TargetFramework,
                    SystemManager.EnvironmentVersion,
                    IsSuperAdmin = isSuperAdmin,
                    PackageList = packageList,
                    PackageIds = packageIds,
                    TopMenus = topMenus,
                    SiteMenus = siteMenus,
                    PluginMenus = pluginMenus,
                    Local = new
                    {
                        UserId = adminInfo.Id,
                        adminInfo.UserName,
                        adminInfo.AvatarUrl,
                        Level = permissions.GetAdminLevel()
                    }
                }));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }