Exemplo n.º 1
0
        public ActionResult LicensePlugin(string systemName, LicensePluginModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedView());
            }

            var descriptor = _pluginFinder.GetPluginDescriptorBySystemName(systemName);

            if (descriptor == null || !descriptor.Installed)
            {
                return(HttpNotFound());
            }

            var isLicensable = LicenseChecker.IsLicensablePlugin(descriptor);

            if (!isLicensable)
            {
                return(HttpNotFound());
            }

            if (model.StoreLicenses != null)
            {
                foreach (var item in model.StoreLicenses)
                {
                    var result = LicenseChecker.Activate(item.LicenseKey, descriptor.SystemName, item.StoreUrl);

                    if (result == null)
                    {
                        // do nothing, skiped
                    }
                    else if (result.Success)
                    {
                        NotifySuccess(T("Admin.Configuration.Plugins.LicenseActivated"));
                    }
                    else
                    {
                        if (result.IsFailureWarning)
                        {
                            NotifyWarning(result.ToString());
                        }
                        else
                        {
                            NotifyError(result.ToString());
                        }

                        return(RedirectToAction("List"));
                    }
                }
            }

            return(RedirectToAction("List"));
        }
        private bool IsLicensable(PluginDescriptor pluginDescriptor)
        {
            var result = false;

            try
            {
                result = LicenseChecker.IsLicensablePlugin(pluginDescriptor);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            return(result);
        }
Exemplo n.º 3
0
        private LicensingData PrepareLicenseLabelModel(LicenseLabelModel model, PluginDescriptor pluginDescriptor, string url = null)
        {
            if (LicenseChecker.IsLicensablePlugin(pluginDescriptor))
            {
                // We always show license button to serve ability to delete a key.
                model.IsLicensable = true;
                model.LicenseUrl   = Url.Action("LicensePlugin", new { systemName = pluginDescriptor.SystemName });

                var license = LicenseChecker.GetLicense(pluginDescriptor.SystemName, url);
                if (license == null)
                {
                    // Licensed plugin has not been used yet -> Check state.
                    var unused = LicenseChecker.CheckState(pluginDescriptor.SystemName, url);

                    // And try to get license data again.
                    license = LicenseChecker.GetLicense(pluginDescriptor.SystemName, url);
                }

                if (license != null)
                {
                    // Licensed plugin has been used.
                    model.LicenseState           = license.State;
                    model.TruncatedLicenseKey    = license.TruncatedLicenseKey;
                    model.RemainingDemoUsageDays = license.RemainingDemoDays;
                }
                else
                {
                    // It's confusing to display a license state when there is no license data yet.
                    model.HideLabel = true;
                }

                return(license);
            }

            return(null);
        }
        public ActionResult LicensePlugin(string systemName, string licenseKey)
        {
            var descriptor = _pluginFinder.GetPluginDescriptorBySystemName(systemName);

            if (descriptor == null || !descriptor.Installed)
            {
                return(Content(T("Admin.Common.ResourceNotFound")));
            }

            var singleLicenseForAllStores = false;
            var isLicensable = LicenseChecker.IsLicensablePlugin(descriptor, out singleLicenseForAllStores);

            if (!isLicensable)
            {
                return(Content(T("Admin.Common.ResourceNotFound")));
            }

            var stores = Services.StoreService.GetAllStores();
            var model  = new LicensePluginModel
            {
                SystemName    = systemName,
                StoreLicenses = new List <LicensePluginModel.StoreLicenseModel>()
            };

            // Validate store url.
            foreach (var store in stores)
            {
                if (!Services.StoreService.IsStoreDataValid(store))
                {
                    model.InvalidDataStoreId = store.Id;
                    return(View(model));
                }
            }

            if (singleLicenseForAllStores)
            {
                var licenseModel = new LicensePluginModel.StoreLicenseModel();
                var license      = PrepareLicenseLabelModel(licenseModel.LicenseLabel, descriptor);
                if (license != null)
                {
                    licenseModel.LicenseKey = license.TruncatedLicenseKey;
                }

                model.StoreLicenses.Add(licenseModel);
            }
            else
            {
                foreach (var store in stores)
                {
                    var licenseModel = new LicensePluginModel.StoreLicenseModel
                    {
                        StoreId   = store.Id,
                        StoreName = store.Name,
                        StoreUrl  = store.Url
                    };

                    var license = PrepareLicenseLabelModel(licenseModel.LicenseLabel, descriptor, store.Url);
                    if (license != null)
                    {
                        licenseModel.LicenseKey = license.TruncatedLicenseKey;
                    }

                    model.StoreLicenses.Add(licenseModel);
                }
            }

            return(View(model));
        }
Exemplo n.º 5
0
        protected PluginModel PreparePluginModel(PluginDescriptor pluginDescriptor, bool forList = true)
        {
            var model = pluginDescriptor.ToModel();

            model.Group = T("Admin.Plugins.KnownGroup." + pluginDescriptor.Group);

            if (forList)
            {
                model.FriendlyName = pluginDescriptor.GetLocalizedValue(_services.Localization, "FriendlyName");
                model.Description  = pluginDescriptor.GetLocalizedValue(_services.Localization, "Description");
            }

            //locales
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
            {
                locale.FriendlyName = pluginDescriptor.GetLocalizedValue(_services.Localization, "FriendlyName", languageId, false);
                locale.Description  = pluginDescriptor.GetLocalizedValue(_services.Localization, "Description", languageId, false);
            });

            // Stores
            model.SelectedStoreIds = _services.Settings.GetSettingByKey <string>(pluginDescriptor.GetSettingKey("LimitedToStores")).ToIntArray();

            // Icon
            model.IconUrl = _pluginMediator.GetIconUrl(pluginDescriptor);

            if (pluginDescriptor.Installed)
            {
                // specify configuration URL only when a plugin is already installed
                if (pluginDescriptor.IsConfigurable)
                {
                    model.ConfigurationUrl = Url.Action("ConfigurePlugin", new { systemName = pluginDescriptor.SystemName });

                    if (!forList)
                    {
                        var configurable = pluginDescriptor.Instance() as IConfigurable;

                        string actionName;
                        string controllerName;
                        RouteValueDictionary routeValues;
                        configurable.GetConfigurationRoute(out actionName, out controllerName, out routeValues);

                        if (actionName.HasValue() && controllerName.HasValue())
                        {
                            model.ConfigurationRoute = new RouteInfo(actionName, controllerName, routeValues);
                        }
                    }
                }

                if (LicenseChecker.IsLicensablePlugin(pluginDescriptor))
                {
                    // we always show license button to serve ability to delete a key
                    model.IsLicensable = true;
                    model.LicenseUrl   = Url.Action("LicensePlugin", new { systemName = pluginDescriptor.SystemName });

                    var license = LicenseChecker.GetLicense(pluginDescriptor.SystemName);

                    if (license != null)                        // license\plugin has been used
                    {
                        model.LicenseState           = license.State;
                        model.TruncatedLicenseKey    = license.TruncatedLicenseKey;
                        model.RemainingDemoUsageDays = license.RemainingDemoDays;
                    }
                }
            }
            return(model);
        }
Exemplo n.º 6
0
        public ActionResult LicensePlugin(string systemName, string licenseKey)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedPartialView());
            }

            var descriptor = _pluginFinder.GetPluginDescriptorBySystemName(systemName);

            if (descriptor == null || !descriptor.Installed)
            {
                return(Content(T("Admin.Common.ResourceNotFound")));
            }

            bool singleLicenseForAllStores = false;
            bool isLicensable = LicenseChecker.IsLicensablePlugin(descriptor, out singleLicenseForAllStores);

            if (!isLicensable)
            {
                return(Content(T("Admin.Common.ResourceNotFound")));
            }

            var stores = _services.StoreService.GetAllStores();
            var model  = new LicensePluginModel
            {
                SystemName = systemName,
                Licenses   = new List <LicensePluginModel.LicenseModel>()
            };

            // validate store url
            foreach (var store in stores)
            {
                if (!_services.StoreService.IsStoreDataValid(store))
                {
                    model.InvalidDataStoreId = store.Id;
                    return(View(model));
                }
            }

            if (singleLicenseForAllStores)
            {
                var licenseModel = new LicensePluginModel.LicenseModel();
                var license      = LicenseChecker.GetLicense(systemName, "");

                if (license != null)
                {
                    licenseModel.LicenseKey = license.TruncatedLicenseKey;
                }

                model.Licenses.Add(licenseModel);
            }
            else
            {
                foreach (var store in stores)
                {
                    var licenseModel = new LicensePluginModel.LicenseModel
                    {
                        StoreId   = store.Id,
                        StoreName = store.Name,
                        StoreUrl  = store.Url
                    };

                    var license = LicenseChecker.GetLicense(systemName, store.Url);

                    if (license != null)
                    {
                        licenseModel.LicenseKey = license.TruncatedLicenseKey;
                    }

                    model.Licenses.Add(licenseModel);
                }
            }

            return(View(model));
        }