public LocalPackageInstallModel Fetch(string packageGuid) { //Default path string path = Path.Combine("packages", packageGuid + ".umb"); if (File.Exists(IOHelper.MapPath(Path.Combine(SystemDirectories.Data, path))) == false) { path = Services.PackagingService.FetchPackageFile(Guid.Parse(packageGuid), UmbracoVersion.Current, Security.GetUserId()); } var model = new LocalPackageInstallModel { PackageGuid = Guid.Parse(packageGuid), RepositoryGuid = Guid.Parse("65194810-1f85-11dd-bd0b-0800200c9a66"), ZipFilePath = path }; //Populate the model from the metadata in the package file (zip file) PopulateFromPackageData(model); var validate = ValidateInstalledInternal(model.Name, model.Version); if (validate == false) { //this package is already installed throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse( Services.TextService.Localize("packager/packageAlreadyInstalled"))); } return(model); }
private void PopulateFromPackageData(LocalPackageInstallModel model) { var ins = new global::umbraco.cms.businesslogic.packager.Installer(Security.CurrentUser.Id); //this will load in all the metadata too var tempDir = ins.Import(model.ZipFilePath, false); model.TemporaryDirectoryPath = Path.Combine(SystemDirectories.Data, tempDir); model.Name = ins.Name; model.Author = ins.Author; model.AuthorUrl = ins.AuthorUrl; model.IconUrl = ins.IconUrl; model.License = ins.License; model.LicenseUrl = ins.LicenseUrl; model.ReadMe = ins.ReadMe; model.ConflictingMacroAliases = ins.ConflictingMacroAliases; model.ConflictingStyleSheetNames = ins.ConflictingStyleSheetNames; model.ConflictingTemplateAliases = ins.ConflictingTemplateAliases; model.ContainsBinaryFileErrors = ins.ContainsBinaryFileErrors; model.ContainsLegacyPropertyEditors = ins.ContainsLegacyPropertyEditors; model.ContainsMacroConflict = ins.ContainsMacroConflict; model.ContainsStyleSheetConflicts = ins.ContainsStyleSheeConflicts; model.ContainsTemplateConflicts = ins.ContainsTemplateConflicts; model.ContainsUnsecureFiles = ins.ContainsUnsecureFiles; model.Url = ins.Url; model.Version = ins.Version; model.UmbracoVersion = ins.RequirementsType == RequirementsType.Strict ? string.Format("{0}.{1}.{2}", ins.RequirementsMajor, ins.RequirementsMinor, ins.RequirementsPatch) : string.Empty; //now we need to check for version comparison model.IsCompatible = true; if (ins.RequirementsType == RequirementsType.Strict) { var packageMinVersion = new System.Version(ins.RequirementsMajor, ins.RequirementsMinor, ins.RequirementsPatch); if (UmbracoVersion.Current < packageMinVersion) { model.IsCompatible = false; } } }
private void PopulateFromPackageData(LocalPackageInstallModel model) { var zipFile = new FileInfo(Path.Combine(Current.IOHelper.MapPath(SystemDirectories.Packages), model.ZipFileName)); var ins = Services.PackagingService.GetCompiledPackageInfo(zipFile); model.Name = ins.Name; model.Author = ins.Author; model.AuthorUrl = ins.AuthorUrl; model.Contributors = ins.Contributors; model.IconUrl = ins.IconUrl; model.License = ins.License; model.LicenseUrl = ins.LicenseUrl; model.Readme = ins.Readme; model.ConflictingMacroAliases = ins.Warnings.ConflictingMacros.ToDictionary(x => x.Name, x => x.Alias); model.ConflictingStyleSheetNames = ins.Warnings.ConflictingStylesheets.ToDictionary(x => x.Name, x => x.Alias);; model.ConflictingTemplateAliases = ins.Warnings.ConflictingTemplates.ToDictionary(x => x.Name, x => x.Alias);; model.ContainsUnsecureFiles = ins.Warnings.UnsecureFiles.Any(); model.Url = ins.Url; model.Version = ins.Version; model.UmbracoVersion = ins.UmbracoVersionRequirementsType == RequirementsType.Strict ? ins.UmbracoVersion.ToString(3) : string.Empty; //now we need to check for version comparison model.IsCompatible = true; if (ins.UmbracoVersionRequirementsType == RequirementsType.Strict) { var packageMinVersion = ins.UmbracoVersion; if (UmbracoVersion.Current < packageMinVersion) { model.IsCompatible = false; } } }
public async Task <LocalPackageInstallModel> Fetch(string packageGuid) { //Default path string fileName = packageGuid + ".umb"; if (File.Exists(Path.Combine(Current.IOHelper.MapPath(SystemDirectories.Packages), fileName)) == false) { var packageFile = await Services.PackagingService.FetchPackageFileAsync( Guid.Parse(packageGuid), UmbracoVersion.Current, Security.GetUserId().ResultOr(0)); fileName = packageFile.Name; } var model = new LocalPackageInstallModel { PackageGuid = Guid.Parse(packageGuid), ZipFileName = fileName }; //Populate the model from the metadata in the package file (zip file) PopulateFromPackageData(model); var installType = Services.PackagingService.GetPackageInstallType(model.Name, SemVersion.Parse(model.Version), out var alreadyInstalled); if (installType == PackageInstallType.AlreadyInstalled) { throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse( Services.TextService.Localize("packager/packageAlreadyInstalled"))); } model.OriginalVersion = installType == PackageInstallType.Upgrade ? alreadyInstalled.Version : null; return(model); }
public async Task <LocalPackageInstallModel> UploadLocalPackage() { if (Request.Content.IsMimeMultipartContent() == false) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var root = IOHelper.MapPath("~/App_Data/TEMP/FileUploads"); //ensure it exists Directory.CreateDirectory(root); var provider = new MultipartFormDataStreamProvider(root); var result = await Request.Content.ReadAsMultipartAsync(provider); //must have a file if (result.FileData.Count == 0) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } //TODO: App/Tree Permissions? var model = new LocalPackageInstallModel { PackageGuid = Guid.NewGuid() }; //get the files foreach (var file in result.FileData) { var fileName = file.Headers.ContentDisposition.FileName.Trim(new[] { '\"' }); var ext = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower(); //TODO: Only allow .zip if (ext.InvariantEquals("zip") || ext.InvariantEquals("umb")) { //TODO: Currently it has to be here, it's not ideal but that's the way it is right now var packageTempDir = IOHelper.MapPath(SystemDirectories.Data); //ensure it's there Directory.CreateDirectory(packageTempDir); //copy it - must always be '.umb' for the installer thing to work //the file name must be a GUID - this is what the packager expects (strange yes) //because essentially this is creating a temporary package Id that will be used //for unpacking/installing/etc... model.ZipFilePath = model.PackageGuid + ".umb"; var packageTempFileLocation = Path.Combine(packageTempDir, model.ZipFilePath); File.Copy(file.LocalFileName, packageTempFileLocation, true); //Populate the model from the metadata in the package file (zip file) PopulateFromPackageData(model); var validate = ValidateInstalledInternal(model.Name, model.Version); if (validate == false) { //this package is already installed throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse( Services.TextService.Localize("packager/packageAlreadyInstalled"))); } } else { model.Notifications.Add(new Notification( Services.TextService.Localize("speechBubbles/operationFailedHeader"), Services.TextService.Localize("media/disallowedFileType"), SpeechBubbleIcon.Warning)); } } return(model); }
public async Task <LocalPackageInstallModel> UploadLocalPackage() { if (Request.Content.IsMimeMultipartContent() == false) { throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); } var root = Current.IOHelper.MapPath(SystemDirectories.TempFileUploads); //ensure it exists Directory.CreateDirectory(root); var provider = new MultipartFormDataStreamProvider(root); var result = await Request.Content.ReadAsMultipartAsync(provider); //must have a file if (result.FileData.Count == 0) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } var model = new LocalPackageInstallModel { //Generate a new package Id for this, we'll use this later for tracking, when persisting, saving the file, etc... PackageGuid = Guid.NewGuid() }; //get the files foreach (var file in result.FileData) { var fileName = file.Headers.ContentDisposition.FileName.Trim('\"'); var ext = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower(); if (ext.InvariantEquals("zip") || ext.InvariantEquals("umb")) { //we always save package files to /App_Data/packages/package-guid.umb for processing as a standard so lets copy. var packagesFolder = Current.IOHelper.MapPath(SystemDirectories.Packages); Directory.CreateDirectory(packagesFolder); var packageFile = Path.Combine(packagesFolder, model.PackageGuid + ".umb"); File.Copy(file.LocalFileName, packageFile); model.ZipFileName = Path.GetFileName(packageFile); //add to the outgoing model so that all temp files are cleaned up model.UploadedFiles.Add(new ContentPropertyFile { TempFilePath = file.LocalFileName }); //Populate the model from the metadata in the package file (zip file) PopulateFromPackageData(model); var installType = Services.PackagingService.GetPackageInstallType(model.Name, SemVersion.Parse(model.Version), out var alreadyInstalled); if (installType == PackageInstallType.AlreadyInstalled) { //this package is already installed throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse( Services.TextService.Localize("packager/packageAlreadyInstalled"))); } model.OriginalVersion = installType == PackageInstallType.Upgrade ? alreadyInstalled.Version : null; } else { model.Notifications.Add(new Notification( Services.TextService.Localize("speechBubbles/operationFailedHeader"), Services.TextService.Localize("media/disallowedFileType"), NotificationStyle.Warning)); } } return(model); }