示例#1
0
        /// <summary>
        /// Preprocess security / context, then get the item based on an passed in method,
        /// ...then process/finish
        /// </summary>
        /// <returns></returns>
        internal Dictionary <string, object> GetOne(IInstanceContext context, IBlock ctxBlock, string contentType, Func <EntityApi, IEntity> getOne, string appPath)
        {
            Log.Add($"get and serialize after security check type:{contentType}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, ctxBlock);

            var entityApi = new EntityApi(appIdentity.AppId, true, Log);

            var itm       = getOne(entityApi);
            var permCheck = new MultiPermissionsItems().Init(context, GetApp(appIdentity.AppId, ctxBlock), itm, Log);

            if (!permCheck.EnsureAll(GrantSets.ReadSomething, out var error))
            {
                throw HttpException.PermissionDenied(error);
            }

            // in case draft wasn't allow, get again with more restricted permissions
            if (!permCheck.EnsureAny(GrantSets.ReadDraft))
            {
                entityApi = new EntityApi(appIdentity.AppId, false, Log);
                itm       = getOne(entityApi);
            }

            return(InitEavAndSerializer(appIdentity.AppId, ctxBlock?.EditAllowed ?? false).Convert(itm));
        }
示例#2
0
    // Set up and check availability
    public FetchContent(string type)
    {
        gameType = type;
        if (type.Equals("D2E"))
        {
            finder = new RtLFinder();
        }
        else if (type.Equals("MoM"))
        {
            finder = new MoMFinder();
        }
        else
        {
            return;
        }

        string appVersion = finder.RequiredFFGVersion();
        // Open up the assets to get the actual version number
        string ffgVersion = fetchAppVersion();

        // Add version found to log
        if (ffgVersion.Length != 0)
        {
            ValkyrieDebug.Log("FFG " + type + " Version Found: " + ffgVersion + System.Environment.NewLine);
        }
        else
        {
            ValkyrieDebug.Log("FFG " + type + " not found." + System.Environment.NewLine);
        }

        // Check if version is acceptable for import
        importAvailable = VersionNewerOrEqual(appVersion, ffgVersion);
    }
        /// <summary>
        /// Preprocess security / context, then get the item based on an passed in method,
        /// ...then process/finish
        /// </summary>
        /// <param name="contentType"></param>
        /// <param name="getOne"></param>
        /// <param name="appPath"></param>
        /// <returns></returns>
        private Dictionary <string, object> GetAndSerializeOneAfterSecurityChecks(string contentType, Func <EntityApi, IEntity> getOne, string appPath)
        {
            Log.Add($"get and serialie after security check type:{contentType}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, BlockBuilder);

            var entityApi = new EntityApi(appIdentity.AppId, true, Log);

            var itm       = getOne(entityApi);
            var permCheck = new MultiPermissionsItems(BlockBuilder, appIdentity.AppId, itm, Log);

            if (!permCheck.EnsureAll(GrantSets.ReadSomething, out var exception))
            {
                throw exception;
            }

            // in case draft wasn't allow, get again with more restricted permissions
            if (!permCheck.EnsureAny(GrantSets.ReadDraft))
            {
                entityApi = new EntityApi(appIdentity.AppId, false, Log);
                itm       = getOne(entityApi);
            }

            return(InitEavAndSerializer(appIdentity.AppId).Convert(itm));
        }
        [AllowAnonymous]   // will check security internally, so assume no requirements
        public IEnumerable <Dictionary <string, object> > GetEntities(string contentType, string appPath = null, string cultureCode = null)
        {
            var wraplog = Log.Call($"get entities type:{contentType}, path:{appPath}, culture:{cultureCode}");

            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, BlockBuilder);

            // verify that read-access to these content-types is permitted
            var permCheck = new MultiPermissionsTypes(BlockBuilder, appIdentity.AppId, contentType, Log);

            if (!permCheck.EnsureAll(GrantSets.ReadSomething, out var exp))
            {
                throw exp;
            }

            //2018-09-15 2dm replaced
            //var context = GetContext(SxcBlock, Log);
            //PerformSecurityCheck(appIdentity, contentType, Grants.Read, appPath == null ? context.Dnn.Module : null);
            var result = new EntityApi(appIdentity.AppId, permCheck.EnsureAny(GrantSets.ReadDraft), Log)
                         .GetEntities(contentType, cultureCode)
                         ?.ToList();

            wraplog("found: " + result?.Count);
            return(result);
        }
示例#5
0
    public FetchContent(string type)
    {
        gameType = type;
        if (type.Equals("D2E"))
        {
            finder = new RtLFinder();
        }
        else if (type.Equals("MoM"))
        {
            finder = new MoMFinder();
        }
        else
        {
            return;
        }

        string appVersion = finder.RequiredFFGVersion();
        string ffgVersion = fetchAppVersion();

        if (ffgVersion.Length != 0)
        {
            Debug.Log("FFG " + type + " Version Found: " + ffgVersion + System.Environment.NewLine);
        }
        else
        {
            Debug.Log("FFG " + type + " not found." + System.Environment.NewLine);
        }

        importAvailable = VersionNewerOrEqual(appVersion, ffgVersion);
    }
示例#6
0
        private static void revertOldInstallations()
        {
            string defaultInstallLocation = StringUtils.GetDefaultInstallLocation(
                Windows.ApplicationModel.Package.Current.PublisherDisplayName);

            AppFinder.AppInfo appInfo = AppFinder.GetApplicationInfo(new string[] { "mrHelper" });
            if (appInfo != null ||
                Directory.Exists(defaultInstallLocation) ||
                System.IO.File.Exists(StringUtils.GetShortcutFilePath()))
            {
                MessageBox.Show("mrHelper needs to uninstall an old version of itself on this launch. "
                                + "It takes a few seconds, please wait...", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                string           currentPackagePath     = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
                string           revertMsiProjectFolder = "mrHelper.RevertMSI";
                string           revertMsiProjectName   = "mrHelper.RevertMSI.exe";
                ProcessStartInfo startInfo = new ProcessStartInfo
                {
                    FileName         = System.IO.Path.Combine(currentPackagePath, revertMsiProjectFolder, revertMsiProjectName),
                    WorkingDirectory = System.IO.Path.Combine(currentPackagePath, revertMsiProjectFolder),
                    Verb             = "runas", // revert implies work with registry
                };
                Process p = Process.Start(startInfo);
                p.WaitForExit();
                Trace.TraceInformation(String.Format("{0} exited with code {1}", revertMsiProjectName, p.ExitCode));
            }
        }
示例#7
0
        internal IEnumerable <Dictionary <string, object> > GetItems(IInstanceContext context, string contentType, IBlock ctxBlock, string appPath = null)
        {
            var wrapLog = Log.Call($"get entities type:{contentType}, path:{appPath}");

            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, ctxBlock);

            // get the app - if we have the context from the request, use that, otherwise generate full app
            var app = ctxBlock == null
                ? Factory.Resolve <Apps.App>().Init(appIdentity, Log)
                : GetApp(appIdentity.AppId, ctxBlock);

            // verify that read-access to these content-types is permitted
            var permCheck = new MultiPermissionsTypes().Init(context, app, contentType, Log);

            if (!permCheck.EnsureAll(GrantSets.ReadSomething, out var error))
            {
                throw HttpException.PermissionDenied(error);
            }

            var result = new EntityApi(appIdentity.AppId, permCheck.EnsureAny(GrantSets.ReadDraft), Log)
                         .GetEntities(contentType)
                         ?.ToList();

            wrapLog("found: " + result?.Count);
            return(result);
        }
示例#8
0
        [AllowAnonymous]   // will check security internally, so assume no requirements
        public Dictionary <string, object> CreateOrUpdate([FromUri] string contentType, [FromBody] Dictionary <string, object> newContentItem, [FromUri] int?id = null, [FromUri] string appPath = null)
        {
            Log.Add($"create or update type:{contentType}, id:{id}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, SxcInstance);

            // Check that this ID is actually of this content-type,
            // this throws an error if it's not the correct type
            var itm = id == null
                ? null
                : new EntityApi(appIdentity.AppId, Log).GetOrThrow(contentType, id.Value);

            var ok = itm == null
                ? new MultiPermissionsTypes(SxcInstance, appIdentity.AppId, contentType, Log)
                     .EnsureAll(Grants.Create.AsSet(), out var exp)
                : new MultiPermissionsItems(SxcInstance, appIdentity.AppId, itm, Log)
                     .EnsureAll(Grants.Update.AsSet(), out exp);

            if (!ok)
            {
                throw exp;
            }

            //2018-09-15 2dm moved/disabled
            //var context = GetContext(SxcInstance, Log);
            //PerformSecurityCheck(appIdentity, contentType, perm, appPath == null ? context.Dnn.Module : null, itm);

            // Convert to case-insensitive dictionary just to be safe!
            newContentItem = new Dictionary <string, object>(newContentItem, StringComparer.OrdinalIgnoreCase);

            // Now create the cleaned up import-dictionary so we can create a new entity
            var cleanedNewItem = new AppContentEntityBuilder(Log)
                                 .CreateEntityDictionary(contentType, newContentItem, appIdentity.AppId);

            var userName = new DnnUser().IdentityToken;

            // try to create
            var publish = Factory.Resolve <IEnvironmentFactory>().PagePublisher(Log);
            // 2018-09-22 new
            // todo: something looks wrong here, I think create/update would fail if it doesn't have a moduleid
            var currentApp = new App(new DnnTenant(PortalSettings), appIdentity.ZoneId, appIdentity.AppId,
                                     ConfigurationProvider.Build(false, publish.IsEnabled(ActiveModule.ModuleID),
                                                                 SxcInstance.Data.ConfigurationProvider), true, Log);

            // 2018-09-22 old
            //currentApp.InitData(false,
            //    publish.IsEnabled(ActiveModule.ModuleID),
            //    SxcInstance.Data.ConfigurationProvider);
            if (id == null)
            {
                currentApp.Data.Create(contentType, cleanedNewItem, userName);
                // Todo: try to return the newly created object
                return(null);
            }

            currentApp.Data.Update(id.Value, cleanedNewItem, userName);
            return(InitEavAndSerializer(appIdentity.AppId).Prepare(currentApp.Data.List.One(id.Value)));
        }
示例#9
0
        internal Dictionary <string, object> CreateOrUpdate(IInstanceContext context, IBlock ctxBlock, string contentType, Dictionary <string, object> newContentItem, int?id = null, string appPath = null)
        {
            Log.Add($"create or update type:{contentType}, id:{id}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, ctxBlock);

            // Check that this ID is actually of this content-type,
            // this throws an error if it's not the correct type
            var itm = id == null
                ? null
                : new EntityApi(appIdentity.AppId, true, Log).GetOrThrow(contentType, id.Value);

            var ok = itm == null
                ? new MultiPermissionsTypes()
                     .Init(context, GetApp(appIdentity.AppId, ctxBlock), contentType, Log)
                     .EnsureAll(Grants.Create.AsSet(), out var error)
                : new MultiPermissionsItems().Init(context, GetApp(appIdentity.AppId, ctxBlock), itm, Log)
                     .EnsureAll(Grants.Update.AsSet(), out error);

            if (!ok)
            {
                throw HttpException.PermissionDenied(error);
            }

            // Convert to case-insensitive dictionary just to be safe!
            newContentItem = new Dictionary <string, object>(newContentItem, StringComparer.OrdinalIgnoreCase);

            // Now create the cleaned up import-dictionary so we can create a new entity
            var cleanedNewItem = new AppContentEntityBuilder(Log)
                                 .CreateEntityDictionary(contentType, newContentItem, appIdentity.AppId);

            var userName = context.User.IdentityToken;

            // try to create
            // 2020-08-21 disabled publish check, don't think it's relevant in API mode
            // var publish = Factory.Resolve<IPagePublishing>().Init(Log);
            // var enablePublish = publish.IsEnabled(context.Container.Id);
            var currentApp = GetApp(appIdentity.AppId, ctxBlock);

            //Factory.Resolve<Apps.App>().Init(appIdentity,
            //    ConfigurationProvider.Build(false, false,
            //        ctxBlockBuilder?.Block.Data.Configuration.LookUps), true, Log);

            if (id == null)
            {
                var entity = currentApp.Data.Create(contentType, cleanedNewItem, userName);
                id = entity.EntityId;
            }
            else
            {
                currentApp.Data.Update(id.Value, cleanedNewItem, userName);
            }

            return(InitEavAndSerializer(appIdentity.AppId, ctxBlock?.EditAllowed ?? false)
                   .Convert(currentApp.Data.List.One(id.Value)));
        }
示例#10
0
        [AllowAnonymous]   // will check security internally, so assume no requirements
        public Dictionary <string, IEnumerable <Dictionary <string, object> > > PublicQuery([FromUri] string appPath, [FromUri] string name, [FromUri] string stream = null)
        {
            var wrapLog     = Log.Call($"path:{appPath}, name:{name}");
            var appIdentity = AppFinder.GetCurrentAppIdFromPath(appPath);
            var queryApp    = new Apps.App(new DnnTenant(PortalSettings), appIdentity.ZoneId, appIdentity.AppId,
                                           ConfigurationProvider.Build(false, false), false, Log);

            // now just run the default query check and serializer
            var result = BuildQueryAndRun(queryApp, name, stream, false, null, Log, BlockBuilder);

            wrapLog(null);
            return(result);
        }
示例#11
0
        [AllowAnonymous]   // will check security internally, so assume no requirements
        public Dictionary <string, IEnumerable <Dictionary <string, object> > > PublicQuery([FromUri] string appPath, [FromUri] string name, [FromUri] string stream = null)
        {
            Log.Add($"public query path:{appPath}, name:{name}");
            // 2018-09-22 new
            var appIdentity = AppFinder.GetCurrentAppIdFromPath(appPath);
            var queryApp    = new App(new DnnTenant(PortalSettings), appIdentity.ZoneId, appIdentity.AppId,
                                      ConfigurationProvider.Build(false, false), false, Log);

            // 2018-09-22 old
            // ensure the queries can be executed (needs configuration provider, usually given in SxcInstance, but we don't hav that here)
            //var config = DataSources.ConfigurationProvider.GetConfigProviderForModule(0, queryApp, null);
            //queryApp.InitData(false, false, config);

            // now just run the default query check and serializer
            return(BuildQueryAndRun(queryApp, name, stream, false, null, Log, SxcInstance));
        }
示例#12
0
        private static void revert()
        {
            AppFinder.AppInfo appInfo = AppFinder.GetApplicationInfo(new string[] { "mrHelper" });
            if (appInfo != null)
            {
                uninstall(appInfo.ProductCode);
            }

            string defaultInstallLocation = StringUtils.GetDefaultInstallLocation(
                Windows.ApplicationModel.Package.Current.PublisherDisplayName);

            cleanupBinaries(appInfo == null ? defaultInstallLocation : appInfo.InstallPath);

            cleanupShortcut(StringUtils.GetShortcutFilePath());

            removeProtocolFromRegistry();
        }
示例#13
0
        /// <summary>
        /// Preprocess security / context, then get the item based on an passed in method,
        /// ...then process/finish
        /// </summary>
        /// <param name="contentType"></param>
        /// <param name="getOne"></param>
        /// <param name="appPath"></param>
        /// <returns></returns>
        private Dictionary <string, object> GetAndSerializeOneAfterSecurityChecks(string contentType, Func <int, IEntity> getOne, string appPath)
        {
            Log.Add($"get and serialie after security check type:{contentType}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, SxcInstance);

            var itm       = getOne(appIdentity.AppId);
            var permCheck = new MultiPermissionsItems(SxcInstance, appIdentity.AppId, itm, Log);

            if (!permCheck.EnsureAll(GrantSets.ReadSomething, out var exception))
            {
                throw exception;
            }
            //2018-09-15 2dm moved/disabled
            //var context = GetContext(SxcInstance, Log);
            //PerformSecurityCheck(appIdentity, contentType, Grants.Read, appPath == null ? context.Dnn.Module : null, itm);
            return(InitEavAndSerializer(appIdentity.AppId).Prepare(itm));
        }
示例#14
0
        PublicQuery(IInstanceContext context, string appPath, string name, string stream, IBlock block)
        {
            var wrapLog = Log.Call($"path:{appPath}, name:{name}");

            if (string.IsNullOrEmpty(name))
            {
                throw HttpException.MissingParam(nameof(name));
            }
            var appIdentity = AppFinder.GetAppIdFromPath(appPath);
            var queryApp    = Factory.Resolve <Apps.App>().Init(appIdentity,
                                                                ConfigurationProvider.Build(false, false), false, Log);

            // now just run the default query check and serializer
            var result = BuildQueryAndRun(queryApp, name, stream, false, context, Log, block?.EditAllowed ?? false);

            wrapLog(null);
            return(result);
        }
示例#15
0
        [AllowAnonymous]       // will check security internally, so assume no requirements
        public void Delete(string contentType, Guid guid, [FromUri] string appPath = null)
        {
            Log.Add($"delete guid:{guid}, type:{contentType}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, BlockBuilder);

            var entityApi = new EntityApi(appIdentity.AppId, true, Log);
            var itm       = entityApi.GetOrThrow(contentType == "any" ? null : contentType, guid);

            var permCheck = new MultiPermissionsItems(BlockBuilder, appIdentity.AppId, itm, Log);

            if (!permCheck.EnsureAll(Grants.Delete.AsSet(), out var exception))
            {
                throw exception;
            }

            entityApi.Delete(itm.Type.Name, guid);
        }
示例#16
0
        internal void Delete(IInstanceContext context, IBlock ctxBlock, string contentType, Guid guid, string appPath)
        {
            Log.Add($"delete guid:{guid}, type:{contentType}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, ctxBlock);

            var entityApi = new EntityApi(appIdentity.AppId, true, Log);
            var itm       = entityApi.GetOrThrow(contentType == "any" ? null : contentType, guid);

            var permCheck = new MultiPermissionsItems().Init(context, GetApp(appIdentity.AppId, ctxBlock), itm, Log);

            if (!permCheck.EnsureAll(Grants.Delete.AsSet(), out var error))
            {
                throw HttpException.PermissionDenied(error);
            }

            entityApi.Delete(itm.Type.Name, guid);
        }
示例#17
0
        private void TryToAttachAppFromUrlParams()
        {
            var wrapLog = Log.Call("TryToAttachAppFromUrlParams");
            var found   = false;

            try
            {
                var routeAppPath = Route.AppPathOrNull(Request.GetRouteData());
                var appId        = AppFinder.GetCurrentAppIdFromPath(routeAppPath).AppId;
                // Look up if page publishing is enabled - if module context is not available, always false
                var publish           = Factory.Resolve <IEnvironmentFactory>().PagePublisher(Log);
                var publishingEnabled = Dnn.Module != null && publish.IsEnabled(Dnn.Module.ModuleID);
                var app = (App)Environment.Dnn7.Factory.App(appId, publishingEnabled);
                DnnAppAndDataHelpers.LateAttachApp(app);
                found = true;
            } catch { /* ignore */ }

            wrapLog(found.ToString());
        }
示例#18
0
        private void TryToAttachAppFromUrlParams()
        {
            var wrapLog = Log.Call();
            var found   = false;

            try
            {
                var routeAppPath = Route.AppPathOrNull(Request.GetRouteData());
                var appId        = AppFinder.GetAppIdFromPath(routeAppPath).AppId;
                // Look up if page publishing is enabled - if module context is not available, always false
                var publish           = Factory.Resolve <IPagePublishing>().Init(Log);
                var publishingEnabled = Dnn.Module != null && publish.IsEnabled(Dnn.Module.ModuleID);
                Log.Add($"AppId: {appId}, publishing:{publishingEnabled}");
                var app = Sxc.Dnn.Factory.App(appId, publishingEnabled, parentLog: Log);
                DynCode.LateAttachApp(app);
                found = true;
            } catch { /* ignore */ }

            wrapLog(found.ToString());
        }
    public void FindLinuxApp()
    {
        var platformResolver = Substitute.For <PlatformResolver>();

        platformResolver.GetRuntimePlatform().Returns(RuntimePlatform.LinuxPlayer);

        // empty directory should be ignored
        Directory.CreateDirectory(Path.Combine(_tempDir, "directory"));

        // copy linux app
        string source = TestFixtures.GetFilePath("magicbytes-test/linux_app");
        string dest   = Path.Combine(_tempDir, "executable");

        File.Copy(source, dest);

        var    appFinder  = new AppFinder();
        string executable = appFinder.FindLinuxExecutable(_tempDir);

        Assert.AreEqual(dest, executable);
    }
示例#20
0
        [AllowAnonymous]       // will check security internally, so assume no requirements
        public void Delete(string contentType, Guid guid, [FromUri] string appPath = null)
        {
            Log.Add($"delete guid:{guid}, type:{contentType}, path:{appPath}");
            // if app-path specified, use that app, otherwise use from context
            var appIdentity = AppFinder.GetAppIdFromPathOrContext(appPath, SxcInstance);

            var entityApi = new EntityApi(appIdentity.AppId, Log);
            var itm       = entityApi.GetOrThrow(contentType == "any" ? null : contentType, guid);

            var permCheck = new MultiPermissionsItems(SxcInstance, appIdentity.AppId, itm, Log);

            if (!permCheck.EnsureAll(Grants.Delete.AsSet(), out var exception))
            {
                throw exception;
            }
            //2018-09-15 2dm moved/disabled
            //var context = GetContext(SxcInstance, Log);
            //PerformSecurityCheck(appIdentity, itm.Type.Name, Grants.Delete, appPath == null ? context.Dnn.Module : null, itm);

            entityApi.Delete(itm.Type.Name, guid);
        }
        /// <summary>
        /// Throws DiffToolNotInstalledException if diff tool is not installed
        /// Throws DiffToolIntegrationException if integration failed
        /// </summary>
        public void Integrate(IIntegratedDiffTool diffTool, string self)
        {
            AppFinder.AppInfo appInfo = AppFinder.GetApplicationInfo(diffTool.GetToolRegistryNames());
            if (appInfo == null || !isInstalled(appInfo.InstallPath))
            {
                throw new DiffToolNotInstalledException("Diff tool not installed");
            }

            string toolpath = appInfo.InstallPath;

            Trace.TraceInformation(String.Format("Diff Tool installed at: {0}", toolpath));

            registerInGit(diffTool, toolpath);

            try
            {
                registerInTool(diffTool, self);
            }
            catch (DiffToolIntegrationException)
            {
                Trace.TraceError(String.Format("Cannot register the application in \"{0}\"", Constants.GitDiffToolName));

                try
                {
                    string key = String.Format("difftool.{0}.cmd", Constants.GitDiffToolName);
                    GitTools.SetConfigKeyValue(GitTools.ConfigScope.Global, key, null, String.Empty);
                }
                catch (ExternalProcessSystemException)
                {
                    Trace.TraceError(String.Format("Cannot remove \"{0}\" from git config", Constants.GitDiffToolName));
                }
                catch (ExternalProcessFailureException)
                {
                    Trace.TraceError(String.Format("Cannot remove \"{0}\" from git config", Constants.GitDiffToolName));
                }

                throw;
            }
        }
示例#22
0
 private static string getBinaryFilePath()
 {
     AppFinder.AppInfo appInfo = AppFinder.GetApplicationInfo(new string[] { RegistryDisplayName });
     return(appInfo != null && !String.IsNullOrWhiteSpace(appInfo.InstallPath)
     ? Path.Combine(appInfo.InstallPath, BinaryFileName) : null);
 }