public async Task <string> WriteFile(CmsFile file, CmsType cmsType, Guid id, string fieldName, string?lang, string?currentUser) { string fileName = GenerateFileName(cmsType, id, fieldName, lang); var blob = await azureStorageService.StoreFileAsync(file.Bytes, fileName, file.ContentType).ConfigureAwait(false); return(fileName); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Get an instance of the CadesSignatureStarter class, responsible for receiving the signature elements and start the // signature process var signatureStarter = Util.GetRestPkiClient().GetCadesSignatureStarter(); // Set the signature policy signatureStarter.SetSignaturePolicy(StandardCadesSignaturePolicies.PkiBrazil.AdrBasica); // Optionally, set a SecurityContext to be used to determine trust in the certificate chain //signatureStarter.SetSecurityContext(StandardSecurityContexts.PkiBrazil); // Note: Depending on the signature policy chosen above, setting the security context may be mandatory (this is not // the case for ICP-Brasil policies, which will automatically use the PkiBrazil security context if none is passed) // Optionally, set whether the content should be encapsulated in the resulting CMS. If this parameter is ommitted, // the following rules apply: // - If no CmsToSign is given, the resulting CMS will include the content // - If a CmsToCoSign is given, the resulting CMS will include the content if and only if the CmsToCoSign also includes the content signatureStarter.SetEncapsulateContent(true); UserFile = Request.QueryString["userfile"]; CmsFile = Request.QueryString["cmsfile"]; if (!String.IsNullOrEmpty(UserFile)) { // If the user was redirected here by Upload (signature with file uploaded by user), the "userfile" URL argument // will contain the filename under the "App_Data" folder. signatureStarter.SetFileToSign(Server.MapPath("~/App_Data/" + UserFile.Replace("_", "."))); } else if (!String.IsNullOrEmpty(CmsFile)) { /* * If the URL argument "cmsfile" is filled, the user has asked to co-sign a previously signed CMS. We'll set the path to the CMS * to be co-signed, which was perviously saved in the App_Data folder by the POST action on this controller. Note two important things: * * 1. The CMS to be co-signed must be set using the method "SetCmsToCoSign", not the method "SetContentToSign" nor "SetFileToSign" * * 2. Since we're creating CMSs with encapsulated content (see call to SetEncapsulateContent above), we don't need to set the content * to be signed, REST PKI will get the content from the CMS being co-signed. */ signatureStarter.SetCmsToCoSign(Server.MapPath("~/App_Data/" + CmsFile.Replace("_", "."))); } else { // If both userfile and cmsfile are null, this is the "signature with server file" case. We'll set the path of the file to be signed signatureStarter.SetFileToSign(Util.GetSampleDocPath()); } // Call the StartWithWebPki() method, which initiates the signature. This yields the token, a 43-character // case-sensitive URL-safe string, which identifies this signature process. We'll use this value to call the // signWithRestPki() method on the Web PKI component (see javascript on the view) and also to complete the signature // on the POST action below (this should not be mistaken with the API access token). var token = signatureStarter.StartWithWebPki(); ViewState["Token"] = token; } }
public async Task <string> WriteFile(CmsFile file, CmsType cmsType, Guid id, string fieldName, string?lang, string?currentUser) { using (Stream stream = new MemoryStream(file.Bytes)) { var response = await _client.UploadFileAsync($"{fieldName}.{file.ContentType}", stream); return(response.Skylink); } }
public async Task <string> WriteFile(CmsFile file, CmsType cmsType, Guid id, string fieldName, string?lang, string?currentUser) { using (Stream stream = new MemoryStream(file.Bytes)) { var response = await _client.FileSystem.AddAsync(stream, fieldName); return(response.ToLink().Id.ToString()); } }
public void AddDownload(byte[] Bytes) { CmsFile kooboofile = new CmsFile(); kooboofile.Extension = UrlHelper.FileExtension(kooboofile.Name); kooboofile.Name = UrlHelper.FileName(this.DownloadTask.RelativeUrl); kooboofile.ContentBytes = Bytes; this.Manager.SiteDb.Routes.AddOrUpdate(this.DownloadTask.RelativeUrl, kooboofile, Manager.UserId); this.Manager.SiteDb.Files.AddOrUpdate(kooboofile, this.Manager.UserId); }
public TreeGridItem(CmsFile file) { this.ID = file.ID; this.Name = file.Name; this.IsActive = file.IsActive; this.Type = "Item"; this.Icon = file.ImageSrc; //"_img/icons/item_small.png"; this.IsLeaf = true; this.CreateDate = file.CreateDate; this.LastModifiedDate = file.ModifiedDate; this.FileType = file.FileType; //BUG #103 this.Volume = file.Volume; //BUG #103 }
public List <TreeGridItem> GetFiles(string folder, string sort) { BaseService.CheckLoginAndLicense(); folder = folder.Replace("/", "\\").Replace("\\\\", "\\"); folder = (getSiteRoot() + folder).Replace("/", "\\").Replace("\\\\", "\\");; CurrentFolder = folder; List <CmsFile> returnFileList = new List <CmsFile>(); List <CmsDirectory> returnDirectoryList = new List <CmsDirectory>(); List <TreeGridItem> returnList = new List <TreeGridItem>(); if (folder.ToLower().EndsWith("_files")) { if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } } string[] files = Directory.GetFiles(folder); string[] directories = Directory.GetDirectories(folder); foreach (string file in files) { FileInfo fileInfoObject = new FileInfo(file); CmsFile fileObject = new CmsFile(fileInfoObject, SessionObject.CurrentSite, SessionObject.CurrentBitplateUser.Theme); returnFileList.Add(fileObject); } foreach (string directory in directories) { DirectoryInfo directoryInfoObject = new DirectoryInfo(directory); CmsDirectory directoryObject = new CmsDirectory(directoryInfoObject); returnDirectoryList.Add(directoryObject); } string sortOrder = "ASC"; if (sort.Contains(" DESC")) { sortOrder = "DESC"; } string sortField = sort.Replace(" ASC", ""); sortField = sortField.Replace(" DESC", ""); Sort(sortField, sortOrder, returnFileList); SortFolders(sortField, sortOrder, returnDirectoryList); //Mappen sorteren. returnDirectoryList.ForEach(c => returnList.Add(new TreeGridItem(c))); returnFileList.ForEach(c => returnList.Add(new TreeGridItem(c))); return(returnList); }
public async Task <JsonResult> Upload([FromForm] IFormFile file, [FromRoute] string cmsType, [FromRoute] Guid id, [FromRoute] string?lang, [FromQuery] string fieldName) { if (file != null) { string fileName = GetFileName(file); string mimeType = file.ContentType.ToLowerInvariant(); //Get file bytes var outputStream = new MemoryStream(); var output = file.OpenReadStream(); output.CopyTo(outputStream); byte[] bytes = outputStream.ToArray(); //if (mimeType.StartsWith("image/")) //{ // // Only validate files that seem to be images. // //Image.Load(Configuration.Default, bytes); //} CmsFile cmsFile = new CmsFile { Bytes = bytes, ContentType = mimeType }; try { var result = await writeFileService.WriteFile(cmsFile, cmsType, id, fieldName, lang, this.User.Identity?.Name).ConfigureAwait(false); return(new JsonResult(result)); } catch (Exception ex) { logger.LogError(ex, "Error writing file."); throw; } } return(new JsonResult("No file submitted")); }
public static void FileRender(FrontContext context, string NameOrId, Dictionary <string, string> Parameters) { Guid FileId; CmsFile file = null; if (System.Guid.TryParse(NameOrId, out FileId)) { file = context.SiteDb.Files.Get(FileId) as CmsFile; } long logid = -1; if (long.TryParse(NameOrId, out logid)) { var logentry = context.SiteDb.Log.Get(logid); var repo = context.SiteDb.Images as IRepository; file = repo.GetByLog(logentry) as CmsFile; } if (file != null) { FileRenderer.RenderFile(context, file); } }
public async Task <string> WriteFile(CmsFile file, CmsType cmsType, Guid id, string fieldName, string?lang, string?currentUser) { var task = await Task.WhenAll(writeFileProviders.Select(x => x.WriteFile(file, cmsType, id, fieldName, lang, currentUser))).ConfigureAwait(false); return(task.First()); }
//file only contains column data. public static async Task RenderFile(FrontContext context, Models.CmsFile file) { var sitedb = context.WebSite.SiteDb(); string contentType = null; if (!string.IsNullOrEmpty(file.ContentType)) { contentType = file.ContentType; } else if (!string.IsNullOrWhiteSpace(file.Name)) { contentType = IOHelper.MimeType(file.Name); } if (string.IsNullOrWhiteSpace(contentType)) { if (context.Route != null) { contentType = IOHelper.MimeType(context.Route.Name); } } context.RenderContext.Response.ContentType = contentType; if (file.Size > BigSize) { var partinfo = sitedb.Files.Store.GetFieldPart(file.Id, nameof(file.ContentBytes)); context.RenderContext.Response.FilePart = partinfo; } else { // read whole content. CmsFile FileContent = null; if (file.ContentBytes == null) { FileContent = await sitedb.FilePool.GetAsync(file.Id); } else { FileContent = file; } if (FileContent.ContentBytes != null) { context.RenderContext.Response.Body = FileContent.ContentBytes; } else if (!string.IsNullOrEmpty(FileContent.ContentString)) { context.RenderContext.Response.Body = DataConstants.DefaultEncoding.GetBytes(FileContent.ContentString); } } // cache for font. if (contentType != null) { string lower = contentType.ToLower(); if (lower.Contains("font")) { VersionRenderer.FontVersion(context); } else if (lower.Contains("image")) { context.RenderContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); context.RenderContext.Response.Headers.Add("Access-Control-Allow-Headers", "*"); VersionRenderer.ImageVersion(context); } else if (lower.Contains("css")) { VersionRenderer.ScriptStyleVersion(context); } else if (lower.Contains("javascript")) { VersionRenderer.ScriptStyleVersion(context); } else if (lower.Contains("video")) { VersionRenderer.VideoVersion(context); } } }
public static SiteObject AddDownload(DownloadManager manager, DownloadContent download, string absoluteUrl, bool DefaultStartPage, bool AnalyzePage, string originalimporturl = "") { var sitedb = manager.SiteDb; bool issamehost = UrlHelper.isSameHost(originalimporturl, absoluteUrl); string relativeurl = UrlHelper.RelativePath(absoluteUrl, issamehost); byte consttype = 0; var FileType = Kooboo.Lib.Helper.UrlHelper.GetFileType(relativeurl, download.ContentType); switch (FileType) { case UrlHelper.UrlFileType.Image: { consttype = ConstObjectType.Image; } break; case UrlHelper.UrlFileType.JavaScript: { consttype = ConstObjectType.Script; } break; case UrlHelper.UrlFileType.Style: { consttype = ConstObjectType.Style; } break; case UrlHelper.UrlFileType.File: { consttype = ConstObjectType.File; } break; default: { string htmlsource = download.GetString(); if (string.IsNullOrEmpty(htmlsource) || Kooboo.HtmlUtility.HasHtmlOrBodyTag(htmlsource)) { consttype = ConstObjectType.Page; } else { consttype = ConstObjectType.View; } } break; } switch (consttype) { case ConstObjectType.Page: { Page page = new Page(); page.IsStatic = true; page.DefaultStart = DefaultStartPage; page.Name = Service.PageService.GetPageNameFromUrl(relativeurl); string htmlsource = UrlHelper.ReplaceMetaCharSet(download.GetString()); if (AnalyzePage) { var context = AnalyzerManager.Execute(htmlsource, absoluteUrl, page.Id, page.ConstType, manager, originalimporturl); htmlsource = context.HtmlSource; } page.Body = htmlsource; if (page.Name == "untitled") { var titleel = Service.DomService.GetTitleElement(page.Dom); if (titleel != null) { string title = titleel.InnerHtml; if (!string.IsNullOrEmpty(title)) { title = Lib.Helper.StringHelper.SementicSubString(title, 0, 30); page.Name = title.Trim(); } } } sitedb.Routes.AddOrUpdate(relativeurl, page, manager.UserId); sitedb.Pages.AddOrUpdate(page, manager.UserId); return(page); } case ConstObjectType.Style: { string csstext = download.GetString(); if (AnalyzePage) { CssManager.ProcessResource(ref csstext, absoluteUrl, manager, default(Guid)); } var style = new Style(); style.Body = csstext; sitedb.Routes.AddOrUpdate(relativeurl, style, manager.UserId); sitedb.Styles.AddOrUpdate(style, manager.UserId); return(style); } case ConstObjectType.Script: { Script script = new Script { ConstType = ConstObjectType.Script, Body = download.GetString() }; sitedb.Routes.AddOrUpdate(relativeurl, script, manager.UserId); sitedb.Scripts.AddOrUpdate(script, manager.UserId); return(script); } case ConstObjectType.Image: { Image koobooimage = new Image { ContentBytes = download.DataBytes, Extension = UrlHelper.FileExtension(relativeurl), Name = UrlHelper.FileName(relativeurl), }; sitedb.Routes.AddOrUpdate(relativeurl, koobooimage, manager.UserId); sitedb.Images.AddOrUpdate(koobooimage, manager.UserId); return(koobooimage); } case ConstObjectType.View: { var view = new View(); string name = System.IO.Path.GetFileNameWithoutExtension(absoluteUrl); if (string.IsNullOrEmpty(name)) { name = "untitlted"; } view.Name = name; string htmlsource = UrlHelper.ReplaceMetaCharSet(download.GetString()); if (AnalyzePage) { var context = AnalyzerManager.Execute(htmlsource, absoluteUrl, view.Id, view.ConstType, manager, originalimporturl); htmlsource = context.HtmlSource; } view.Body = htmlsource; sitedb.Routes.AddOrUpdate(relativeurl, view, manager.UserId); sitedb.Views.AddOrUpdate(view, manager.UserId); return(view); } default: { /// default treat it as file. var kooboofile = new CmsFile { ContentType = download.ContentType, ContentBytes = download.DataBytes, ContentString = download.ContentString, Extension = UrlHelper.FileExtension(relativeurl), Name = UrlHelper.FileName(relativeurl) }; sitedb.Routes.AddOrUpdate(relativeurl, kooboofile, manager.UserId); sitedb.Files.AddOrUpdate(kooboofile, manager.UserId); return(kooboofile); } } }