diff --git a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Web.config b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Web.config index 599b81ba..3a721fdd 100644 --- a/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Web.config +++ b/WebsitePanel/Sources/WebsitePanel.EnterpriseServer/Web.config @@ -5,11 +5,11 @@ - + - + diff --git a/WebsitePanel/Sources/WebsitePanel.Server/Web.config b/WebsitePanel/Sources/WebsitePanel.Server/Web.config index 4197b288..d9d1bde5 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/Web.config +++ b/WebsitePanel/Sources/WebsitePanel.Server/Web.config @@ -1,46 +1,51 @@ - + -
-
-
+
+
+
+
+
+
+
+
- - - - - + + + + + - + - + - + - + - + @@ -48,85 +53,85 @@ - + - + - + - + - + - - - + + + - + - - - - + + + + - - + + - - - - + + + + - + - + - - + + - + - + - + - - + + - - + + - - + + - - + + @@ -135,40 +140,40 @@ - - + + - + - - + + - - - - - - - + + + + + + + - - + + - - + + - + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.Server/WebsitePanel.Server.csproj b/WebsitePanel/Sources/WebsitePanel.Server/WebsitePanel.Server.csproj index 4ba51d1d..8b1d2bb6 100644 --- a/WebsitePanel/Sources/WebsitePanel.Server/WebsitePanel.Server.csproj +++ b/WebsitePanel/Sources/WebsitePanel.Server/WebsitePanel.Server.csproj @@ -17,9 +17,9 @@ 4.0 - v4.0 + v3.5 - true + false @@ -79,7 +79,6 @@ - @@ -272,11 +271,12 @@ - True + False False 9004 / - http://localhost:9003/ + + False False diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Extensions/UriExtensions.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Extensions/UriExtensions.cs new file mode 100644 index 00000000..3f6bd4c6 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Extensions/UriExtensions.cs @@ -0,0 +1,13 @@ +using System; +using System.Linq; + +namespace WebsitePanel.WebDav.Core.Extensions +{ + static class UriExtensions + { + public static Uri Append(this Uri uri, params string[] paths) + { + return new Uri(paths.Aggregate(uri.AbsoluteUri, (current, path) => string.Format("{0}/{1}", current.TrimEnd('/'), path.TrimStart('/')))); + } + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IHierarchyItem.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IHierarchyItem.cs index 94f7348f..55369709 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IHierarchyItem.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IHierarchyItem.cs @@ -17,8 +17,9 @@ namespace WebsitePanel.WebDav.Core DateTime CreationDate { get; } string CreatorDisplayName { get; } string DisplayName { get; } + bool IsRootItem { get; set; } Uri Href { get; } - ItemType ItemType { get; } + ItemType ItemType { get;} DateTime LastModified { get; } Property[] Properties { get; } @@ -73,6 +74,8 @@ namespace WebsitePanel.WebDav.Core } } + public bool IsRootItem { get; set; } + public Uri Href { get { return _href; } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IItemContent.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IItemContent.cs index 1a2d8e84..399aeba0 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IItemContent.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IItemContent.cs @@ -7,6 +7,7 @@ namespace WebsitePanel.WebDav.Core public interface IItemContent { long ContentLength { get; } + long AllocatedSpace { get; set; } string ContentType { get; } void Download(string filename); diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IResource.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IResource.cs index be8d4db3..6766553b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IResource.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/IResource.cs @@ -64,6 +64,7 @@ namespace WebsitePanel.WebDav.Core public long ContentLength { get { return _contentLength; } + set { _contentLength = value; } } public string ContentType @@ -110,6 +111,23 @@ namespace WebsitePanel.WebDav.Core webClient.UploadFile(Href, "PUT", filename); } + /// + /// Uploads content of a file specified by filename to the server + /// + /// Posted file data to be uploaded + public void Upload(byte[] data) + { + var credentials = (NetworkCredential)_credentials; + string auth = "Basic " + + Convert.ToBase64String( + Encoding.Default.GetBytes(credentials.UserName + ":" + credentials.Password)); + var webClient = new WebClient(); + webClient.Credentials = credentials; + webClient.Headers.Add("Authorization", auth); + + webClient.UploadData(Href, "PUT", data); + } + /// /// Loads content of the resource from WebDAV server. /// @@ -233,14 +251,19 @@ namespace WebsitePanel.WebDav.Core } } + public long AllocatedSpace { get; set; } + public bool IsRootItem { get; set; } + public Uri Href { get { return _href; } + set { SetHref(value.ToString(), new Uri(value.Scheme + "://" + value.Host + value.Segments[0] + value.Segments[1])); } } public ItemType ItemType { get { return _itemType; } + set { _itemType = value; } } public DateTime LastModified diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Interfaces/Managers/IWebDavManager.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Interfaces/Managers/IWebDavManager.cs index 2b8f7514..2c62309f 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Interfaces/Managers/IWebDavManager.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Interfaces/Managers/IWebDavManager.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Web; using WebsitePanel.WebDav.Core.Client; namespace WebsitePanel.WebDav.Core.Interfaces.Managers @@ -8,6 +9,7 @@ namespace WebsitePanel.WebDav.Core.Interfaces.Managers IEnumerable OpenFolder(string path); bool IsFile(string path); byte[] GetFileBytes(string path); + void UploadFile(string path, HttpPostedFileBase file); IResource GetResource(string path); string GetFileUrl(string path); } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Interfaces/Security/IWebDavAuthorizationService.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Interfaces/Security/IWebDavAuthorizationService.cs new file mode 100644 index 00000000..a8c376d3 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Interfaces/Security/IWebDavAuthorizationService.cs @@ -0,0 +1,11 @@ +using WebsitePanel.WebDav.Core.Security.Authentication.Principals; +using WebsitePanel.WebDav.Core.Security.Authorization.Enums; + +namespace WebsitePanel.WebDav.Core.Interfaces.Security +{ + public interface IWebDavAuthorizationService + { + bool HasAccess(WspPrincipal principal, string path); + WebDavPermissions GetPermissions(WspPrincipal principal, string path); + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Managers/WebDavManager.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Managers/WebDavManager.cs index 0f76a99e..fc6ab6ff 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Managers/WebDavManager.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Managers/WebDavManager.cs @@ -3,11 +3,15 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; +using System.Text; +using System.Web; +using System.Xml.Serialization; using log4net; using WebsitePanel.Providers.OS; using WebsitePanel.WebDav.Core.Client; using WebsitePanel.WebDav.Core.Config; using WebsitePanel.WebDav.Core.Exceptions; +using WebsitePanel.WebDav.Core.Extensions; using WebsitePanel.WebDav.Core.Interfaces.Managers; using WebsitePanel.WebDav.Core.Security.Cryptography; using WebsitePanel.WebDav.Core.Wsp.Framework; @@ -38,7 +42,25 @@ namespace WebsitePanel.WebDav.Core.Managers if (string.IsNullOrWhiteSpace(pathPart)) { - children = ConnectToWebDavServer().Select(x => new WebDavHierarchyItem { Href = new Uri(x.Url), ItemType = ItemType.Folder }).ToArray(); + var resources = ConnectToWebDavServer().Select(x => new WebDavResource { Href = new Uri(x.Url), ItemType = ItemType.Folder }).ToArray(); + + var items = WSP.Services.EnterpriseStorage.GetEnterpriseFolders(WspContext.User.ItemId); + + foreach (var resource in resources) + { + var folder = items.FirstOrDefault(x => x.Name == resource.DisplayName); + + if (folder == null) + { + continue; + } + + resource.ContentLength = folder.Size; + resource.AllocatedSpace = folder.FRSMQuotaMB; + resource.IsRootItem = true; + } + + children = resources; } else { @@ -51,7 +73,7 @@ namespace WebsitePanel.WebDav.Core.Managers _currentFolder = _webDavSession.OpenFolder(string.Format("{0}{1}/{2}", WebDavAppConfigManager.Instance.WebdavRoot, WspContext.User.OrganizationId, pathPart)); } - children = _currentFolder.GetChildren(); + children = _currentFolder.GetChildren().Where(x => !WebDavAppConfigManager.Instance.ElementsRendering.ElementsToIgnore.Contains(x.DisplayName.Trim('/'))).ToArray(); } List sortedChildren = children.Where(x => x.ItemType == ItemType.Folder).OrderBy(x => x.DisplayName).ToList(); @@ -108,6 +130,24 @@ namespace WebsitePanel.WebDav.Core.Managers } } + public void UploadFile(string path, HttpPostedFileBase file) + { + var resource = new WebDavResource(); + + var fileUrl = new Uri(WebDavAppConfigManager.Instance.WebdavRoot) + .Append(WspContext.User.OrganizationId) + .Append(path) + .Append(Path.GetFileName(file.FileName)); + + resource.SetHref(fileUrl); + resource.SetCredentials(new NetworkCredential(WspContext.User.Login, _cryptography.Decrypt(WspContext.User.EncryptedPassword))); + + file.InputStream.Seek(0, SeekOrigin.Begin); + var bytes = ReadFully(file.InputStream); + + resource.Upload(bytes); + } + public IResource GetResource(string path) { try @@ -184,6 +224,14 @@ namespace WebsitePanel.WebDav.Core.Managers } } + public void WriteTo(Stream sourceStream, Stream targetStream) + { + byte[] buffer = new byte[16 * 1024]; + int n; + while ((n = sourceStream.Read(buffer, 0, buffer.Length)) != 0) + targetStream.Write(buffer, 0, n); + } + private string GetFileFolder(string path) { path = path.TrimEnd('/'); diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Security/Authorization/Enums/WebDavPermissions.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Security/Authorization/Enums/WebDavPermissions.cs new file mode 100644 index 00000000..b3c9a52e --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Security/Authorization/Enums/WebDavPermissions.cs @@ -0,0 +1,13 @@ +using System; + +namespace WebsitePanel.WebDav.Core.Security.Authorization.Enums +{ + [Flags] + public enum WebDavPermissions + { + Empty = 0, + None = 1, + Read = 2, + Write = 4 + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Security/Authorization/WebDavAuthorizationService.cs b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Security/Authorization/WebDavAuthorizationService.cs new file mode 100644 index 00000000..2bc4d767 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/Security/Authorization/WebDavAuthorizationService.cs @@ -0,0 +1,69 @@ +using System; +using System.Linq; +using WebsitePanel.WebDav.Core.Interfaces.Security; +using WebsitePanel.WebDav.Core.Security.Authentication.Principals; +using WebsitePanel.WebDav.Core.Security.Authorization.Enums; +using WebsitePanel.WebDav.Core.Wsp.Framework; + +namespace WebsitePanel.WebDav.Core.Security.Authorization +{ + public class WebDavAuthorizationService : IWebDavAuthorizationService + { + public bool HasAccess(WspPrincipal principal, string path) + { + var permissions = GetPermissions(principal, path); + + return permissions.HasFlag(WebDavPermissions.Read) || permissions.HasFlag(WebDavPermissions.Write); + } + + public WebDavPermissions GetPermissions(WspPrincipal principal, string path) + { + if (string.IsNullOrEmpty(path)) + { + return WebDavPermissions.Read; + } + + var resultPermissions = WebDavPermissions.Empty; + + var rootFolder = GetRootFolder(path); + + var userGroups = WSP.Services.Organizations.GetSecurityGroupsByMember(principal.ItemId, principal.AccountId); + + var rootFolders = WSP.Services.EnterpriseStorage.GetEnterpriseFolders(principal.ItemId); + + var esRootFolder = rootFolders.FirstOrDefault(x => x.Name == rootFolder); + + if (esRootFolder == null) + { + return WebDavPermissions.None; + } + + var permissions = WSP.Services.EnterpriseStorage.GetEnterpriseFolderPermissions(principal.ItemId, esRootFolder.Name); + + foreach (var permission in permissions) + { + if ((!permission.IsGroup + && (permission.DisplayName == principal.UserName || permission.DisplayName == principal.DisplayName)) + || (permission.IsGroup && userGroups.Any(x => x.DisplayName == permission.DisplayName))) + { + if (permission.Access.ToLowerInvariant().Contains("read")) + { + resultPermissions |= WebDavPermissions.Read; + } + + if (permission.Access.ToLowerInvariant().Contains("write")) + { + resultPermissions |= WebDavPermissions.Write; + } + } + } + + return resultPermissions; + } + + private string GetRootFolder(string path) + { + return path.Split(new[]{'/'}, StringSplitOptions.RemoveEmptyEntries)[0]; + } + } +} \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj index 466bf922..ff78a246 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/WebsitePanel.WebDav.Core.csproj @@ -41,7 +41,7 @@ False - ..\packages\Microsoft.Web.Services3.3.0.0.0\lib\net20\Microsoft.Web.Services3.dll + ..\..\..\..\Scheduler Domains\WebsitePanel\Bin\Microsoft.Web.Services3.dll True @@ -123,10 +123,12 @@ + + @@ -145,6 +147,8 @@ True HttpErrors.resx + + diff --git a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/packages.config b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/packages.config index 367f50f4..ad6a1af2 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDav.Core/packages.config +++ b/WebsitePanel/Sources/WebsitePanel.WebDav.Core/packages.config @@ -5,5 +5,4 @@ - \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Data/SiteSettings.config b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Data/SiteSettings.config index 2977e729..91a5447b 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Data/SiteSettings.config +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Data/SiteSettings.config @@ -3,7 +3,7 @@ WebsitePanel - http://localhost:9002 + http://127.0.0.1:9555 UserCulture UserTheme diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/BundleConfig.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/BundleConfig.cs index a2285f14..b9eef087 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/BundleConfig.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/BundleConfig.cs @@ -26,7 +26,8 @@ namespace WebsitePanel.WebDavPortal bundles.Add(new ScriptBundle("~/bundles/appScripts").Include( "~/Scripts/appScripts/recalculateResourseHeight.js", "~/Scripts/appScripts/uploadingData2.js", - "~/Scripts/appScripts/authentication.js")); + "~/Scripts/appScripts/authentication.js", + "~/Scripts/appScripts/dialogs.js")); bundles.Add(new ScriptBundle("~/bundles/authScripts").Include( "~/Scripts/appScripts/authentication.js")); diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs index 8a6a2d90..0abc4a09 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/App_Start/RouteConfig.cs @@ -43,7 +43,13 @@ namespace WebsitePanel.WebDavPortal #endregion routes.MapRoute( - name: "Office365DocumentRoute", + name: FileSystemRouteNames.UploadFile, + url: "upload-file/{org}/{*pathPart}", + defaults: new { controller = "FileSystem", action = "UploadFile" } + ); + + routes.MapRoute( + name: FileSystemRouteNames.ShowOfficeOnlinePath, url: "office365/{org}/{*pathPart}", defaults: new { controller = "FileSystem", action = "ShowOfficeDocument", pathPart = UrlParameter.Optional } ); @@ -55,7 +61,7 @@ namespace WebsitePanel.WebDavPortal ); routes.MapRoute( - name: FileSystemRouteNames.FilePath, + name: FileSystemRouteNames.ShowContentPath, url: "{org}/{*pathPart}", defaults: new { controller = "FileSystem", action = "ShowContent", pathPart = UrlParameter.Optional } ); diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Content/Site.css b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Content/Site.css index 2389aea4..88729f71 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Content/Site.css +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Content/Site.css @@ -45,4 +45,13 @@ textarea { #logout :hover { color: white; +} + + +.web-dav-folder-progress { + margin-bottom: 0px; +} + +.modal-vertical-centered { + margin-top: 25%; } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs index d26d43ee..268a0b96 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/AccountController.cs @@ -29,7 +29,7 @@ namespace WebsitePanel.WebDavPortal.Controllers { if (WspContext.User != null && WspContext.User.Identity.IsAuthenticated) { - return RedirectToRoute(FileSystemRouteNames.FilePath, new { org = WspContext.User.OrganizationId }); + return RedirectToRoute(FileSystemRouteNames.ShowContentPath, new { org = WspContext.User.OrganizationId }); } return View(); @@ -46,9 +46,7 @@ namespace WebsitePanel.WebDavPortal.Controllers { _authenticationService.CreateAuthenticationTicket(user); - Session[WebDavAppConfigManager.Instance.SessionKeys.WebDavManager] = null; - - return RedirectToRoute(FileSystemRouteNames.FilePath, new { org = WspContext.User.OrganizationId }); + return RedirectToRoute(FileSystemRouteNames.ShowContentPath, new { org = WspContext.User.OrganizationId }); } return View(new AccountModel { LdapError = "The user name or password is incorrect" }); @@ -59,8 +57,6 @@ namespace WebsitePanel.WebDavPortal.Controllers { _authenticationService.LogOut(); - Session[WebDavAppConfigManager.Instance.SessionKeys.WebDavManager] = null; - return RedirectToRoute(AccountRouteNames.Login); } } diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs index 70bdfe36..2ac65019 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Controllers/FileSystemController.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Net.Mime; using System.Web; using System.Web.Mvc; using System.Web.Routing; +using log4net; using WebsitePanel.WebDav.Core; using WebsitePanel.WebDav.Core.Client; using WebsitePanel.WebDav.Core.Config; @@ -30,13 +32,18 @@ namespace WebsitePanel.WebDavPortal.Controllers private readonly IWebDavManager _webdavManager; private readonly IAuthenticationService _authenticationService; private readonly IAccessTokenManager _tokenManager; + private readonly IWebDavAuthorizationService _webDavAuthorizationService; + private readonly ILog Log; - public FileSystemController(ICryptography cryptography, IWebDavManager webdavManager, IAuthenticationService authenticationService, IAccessTokenManager tokenManager) + public FileSystemController(ICryptography cryptography, IWebDavManager webdavManager, IAuthenticationService authenticationService, IAccessTokenManager tokenManager, IWebDavAuthorizationService webDavAuthorizationService) { _cryptography = cryptography; _webdavManager = webdavManager; _authenticationService = authenticationService; _tokenManager = tokenManager; + _webDavAuthorizationService = webDavAuthorizationService; + + Log = LogManager.GetLogger(this.GetType()); } [HttpGet] @@ -57,10 +64,11 @@ namespace WebsitePanel.WebDavPortal.Controllers try { - IEnumerable children = _webdavManager.OpenFolder(pathPart).Where(x => !WebDavAppConfigManager.Instance.ElementsRendering.ElementsToIgnore.Contains(x.DisplayName.Trim('/'))); + IEnumerable children = _webdavManager.OpenFolder(pathPart); - var model = new ModelForWebDav { Items = children.Take(WebDavAppConfigManager.Instance.ElementsRendering.DefaultCount), UrlSuffix = pathPart }; - Session[WebDavAppConfigManager.Instance.SessionKeys.ResourseRenderCount] = WebDavAppConfigManager.Instance.ElementsRendering.DefaultCount; + var permissions = _webDavAuthorizationService.GetPermissions(WspContext.User, pathPart); + + var model = new ModelForWebDav { Items = children.Take(WebDavAppConfigManager.Instance.ElementsRendering.DefaultCount), UrlSuffix = pathPart, Permissions = permissions}; return View(model); } @@ -95,5 +103,23 @@ namespace WebsitePanel.WebDavPortal.Controllers return PartialView("_ResourseCollectionPartial", result); } + + [HttpPost] + public ActionResult UploadFile(string org, string pathPart) + { + foreach (string fileName in Request.Files) + { + var file = Request.Files[fileName]; + + if (file == null || file.ContentLength == 0) + { + continue; + } + + _webdavManager.UploadFile(pathPart, file); + } + + return RedirectToRoute(FileSystemRouteNames.ShowContentPath); + } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/PortalDependencies.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/PortalDependencies.cs index b30572c9..5589c751 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/PortalDependencies.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/DependencyInjection/PortalDependencies.cs @@ -1,19 +1,14 @@ using Ninject; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; using System.Web.SessionState; using WebsitePanel.WebDav.Core.Interfaces.Managers; using WebsitePanel.WebDav.Core.Interfaces.Owa; using WebsitePanel.WebDav.Core.Interfaces.Security; using WebsitePanel.WebDav.Core.Managers; using WebsitePanel.WebDav.Core.Owa; -using WebsitePanel.WebDav.Core.Security; using WebsitePanel.WebDav.Core.Security.Authentication; +using WebsitePanel.WebDav.Core.Security.Authorization; using WebsitePanel.WebDav.Core.Security.Cryptography; using WebsitePanel.WebDavPortal.DependencyInjection.Providers; -using WebsitePanel.WebDavPortal.Models; namespace WebsitePanel.WebDavPortal.DependencyInjection { @@ -27,6 +22,7 @@ namespace WebsitePanel.WebDavPortal.DependencyInjection kernel.Bind().To(); kernel.Bind().To(); kernel.Bind().To(); + kernel.Bind().To(); } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/ModelForWebDav.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/ModelForWebDav.cs index c334134e..b5d74661 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/ModelForWebDav.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Models/ModelForWebDav.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using WebsitePanel.WebDav.Core.Client; +using WebsitePanel.WebDav.Core.Security.Authorization.Enums; namespace WebsitePanel.WebDavPortal.Models { @@ -8,5 +9,6 @@ namespace WebsitePanel.WebDavPortal.Models public IEnumerable Items { get; set; } public string UrlSuffix { get; set; } public string Error { get; set; } + public WebDavPermissions Permissions { get; set; } } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Scripts/appScripts/dialogs.js b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Scripts/appScripts/dialogs.js new file mode 100644 index 00000000..c385e81a --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Scripts/appScripts/dialogs.js @@ -0,0 +1,20 @@ +var processDialog; +processDialog = processDialog || (function () { + var processDialogDiv = $('#processDialog'); + return { + showPleaseWait: function () { + $('#processDialog').modal(); + }, + hidePleaseWait: function () { + $('#processDialog').modal('hide'); + }, + + }; +})(); + + +$(document).ready(function() { + $('.processing-dialog').click(function () { + processDialog.showPleaseWait(); + }); +}); \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.Designer.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.Designer.cs new file mode 100644 index 00000000..8c1b3158 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.Designer.cs @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.33440 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WebsitePanel.WebDavPortal.UI { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WebsitePanel.WebDavPortal.UI.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Actions. + /// + public static string Actions { + get { + return ResourceManager.GetString("Actions", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Close. + /// + public static string Close { + get { + return ResourceManager.GetString("Close", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to File Upload. + /// + public static string FileUpload { + get { + return ResourceManager.GetString("FileUpload", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Gb. + /// + public static string GigabyteShort { + get { + return ResourceManager.GetString("GigabyteShort", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Processing. + /// + public static string Processing { + get { + return ResourceManager.GetString("Processing", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Processing.... + /// + public static string ProcessingWithDots { + get { + return ResourceManager.GetString("ProcessingWithDots", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Upload. + /// + public static string Upload { + get { + return ResourceManager.GetString("Upload", resourceCulture); + } + } + } +} diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.resx b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.resx new file mode 100644 index 00000000..8329ece5 --- /dev/null +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Resources.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Actions + + + Close + + + File Upload + + + Gb + + + Processing + + + Processing... + + + Upload + + \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs index f011561a..8767815d 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/UI/Routes/FileSystemRouteNames.cs @@ -7,7 +7,10 @@ namespace WebsitePanel.WebDavPortal.UI.Routes { public class FileSystemRouteNames { - public const string FilePath = "FilePathRoute"; + public const string ShowContentPath = "ShowContentRoute"; + public const string ShowOfficeOnlinePath = "ShowOfficeOnlineRoute"; public const string ShowAdditionalContent = "ShowAdditionalContentRoute"; + + public const string UploadFile = "UplaodFIleRoute"; } } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/ShowContent.cshtml b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/ShowContent.cshtml index bc4222bd..2ffecc86 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/ShowContent.cshtml +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/ShowContent.cshtml @@ -3,6 +3,9 @@ @using Ninject @using WebsitePanel.WebDav.Core.Config @using WebsitePanel.WebDav.Core.Interfaces.Managers +@using WebsitePanel.WebDav.Core.Security.Authorization.Enums +@using WebsitePanel.WebDavPortal.UI +@using WebsitePanel.WebDavPortal.UI.Routes @model WebsitePanel.WebDavPortal.Models.ModelForWebDav @{ @@ -34,6 +37,21 @@ else @elements[i] } + + if (Model.Permissions.HasFlag(WebDavPermissions.Write)) + { + @*@Resources.FileUpload*@ + + + } }
@@ -48,4 +66,31 @@ else } +} + + +@section popups +{ + + + @Html.Partial("_ProcessDialog", null) } \ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml index 2565898b..674917d1 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/FileSystem/_ResoursePartial.cshtml @@ -1,7 +1,10 @@ -@using WebsitePanel.WebDav.Core.Client +@using WebsitePanel.WebDav.Core +@using WebsitePanel.WebDav.Core.Client @using WebsitePanel.WebDav.Core.Config @using WebsitePanel.WebDavPortal.FileOperations @using Ninject; +@using WebsitePanel.WebDavPortal.UI +@using WebsitePanel.WebDavPortal.UI.Routes @model IHierarchyItem @{ @@ -14,17 +17,39 @@ { case FileOpenerType.OfficeOnline: isTargetBlank = true; - href = string.Concat(Url.Action("ShowOfficeDocument", "FileSystem"), Model.DisplayName); + var pathPart = Model.Href.AbsolutePath.Replace("/" + WspContext.User.OrganizationId, ""); + href = string.Concat(Url.RouteUrl(FileSystemRouteNames.ShowOfficeOnlinePath, new { org = WspContext.User.OrganizationId, pathPart = "" }), pathPart); break; default: isTargetBlank = false; href = Model.Href.AbsolutePath; break; } + + var resource = Model as IResource; + + bool showStatistic = Model.ItemType == ItemType.Folder && Model.IsRootItem && resource != null; + + int percent = 0; + + if (showStatistic) + { + percent = (int)(resource.AllocatedSpace != 0 ? 100 * resource.ContentLength / resource.AllocatedSpace : 0); + } } +

@name

+ @if (showStatistic) + { +
+
+ @percent% +
+
+

@Math.Round(Convert.ToDecimal(resource.ContentLength) / 1024, 2) / @Math.Round(Convert.ToDecimal(resource.AllocatedSpace) / 1024, 2) @Resources.GigabyteShort

+ }
\ No newline at end of file diff --git a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml index 20c4112c..cd295597 100644 --- a/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml +++ b/WebsitePanel/Sources/WebsitePanel.WebDavPortal/Views/Shared/_Layout.cshtml @@ -23,7 +23,7 @@ - @Html.RouteLink(WebDavAppConfigManager.Instance.ApplicationName, FileSystemRouteNames.FilePath, new { pathPart = string.Empty }, new { @class = "navbar-brand" }) + @Html.RouteLink(WebDavAppConfigManager.Instance.ApplicationName, FileSystemRouteNames.ShowContentPath, new { pathPart = string.Empty }, new { @class = "navbar-brand" })