bugs fix
This commit is contained in:
parent
f2c54df2b0
commit
41a540bd1e
13 changed files with 165 additions and 114 deletions
|
@ -6,6 +6,7 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections
|
|||
public class WebDavExplorerConfigurationSettingsSection : ConfigurationSection
|
||||
{
|
||||
private const string UserDomainKey = "userDomain";
|
||||
private const string WebdavRootKey = "webdavRoot";
|
||||
private const string AuthTimeoutCookieNameKey = "authTimeoutCookieName";
|
||||
private const string AppName = "applicationName";
|
||||
private const string WebsitePanelConstantUserKey = "websitePanelConstantUser";
|
||||
|
@ -25,6 +26,13 @@ namespace WebsitePanel.WebDavPortal.WebConfigSections
|
|||
set { this[AuthTimeoutCookieNameKey] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(WebdavRootKey, IsRequired = true)]
|
||||
public WebdavRootElement WebdavRoot
|
||||
{
|
||||
get { return (WebdavRootElement)this[WebdavRootKey]; }
|
||||
set { this[WebdavRootKey] = value; }
|
||||
}
|
||||
|
||||
[ConfigurationProperty(UserDomainKey, IsRequired = true)]
|
||||
public UserDomainElement UserDomain
|
||||
{
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WebsitePanel.WebDav.Core.Config.WebConfigSections
|
||||
{
|
||||
public class WebdavRootElement : ConfigurationElement
|
||||
{
|
||||
private const string ValueKey = "value";
|
||||
|
||||
[ConfigurationProperty(ValueKey, IsKey = true, IsRequired = true)]
|
||||
public string Value
|
||||
{
|
||||
get { return (string)this[ValueKey]; }
|
||||
set { this[ValueKey] = value; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,6 +30,11 @@ namespace WebsitePanel.WebDav.Core.Config
|
|||
get { return _configSection.UserDomain.Value; }
|
||||
}
|
||||
|
||||
public string WebdavRoot
|
||||
{
|
||||
get { return _configSection.WebdavRoot.Value; }
|
||||
}
|
||||
|
||||
public string ApplicationName
|
||||
{
|
||||
get { return _configSection.ApplicationName.Value; }
|
||||
|
|
|
@ -5,13 +5,11 @@ namespace WebsitePanel.WebDav.Core.Interfaces.Managers
|
|||
{
|
||||
public interface IWebDavManager
|
||||
{
|
||||
string RootPath { get; }
|
||||
void OpenFolder(string pathPart);
|
||||
IEnumerable<IHierarchyItem> GetChildren();
|
||||
bool IsFile(string fileName);
|
||||
byte[] GetFileBytes(string fileName);
|
||||
IResource GetResource( string fileName);
|
||||
string GetFileUrl(string fileName);
|
||||
IEnumerable<IHierarchyItem> OpenFolder(string path);
|
||||
bool IsFile(string path);
|
||||
byte[] GetFileBytes(string path);
|
||||
IResource GetResource(string path);
|
||||
string GetFileUrl(string path);
|
||||
|
||||
string CreateFileId(string path);
|
||||
string FilePathFromId(string id);
|
||||
|
|
|
@ -21,16 +21,8 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
|
||||
private readonly ILog Log;
|
||||
|
||||
private IFolder _currentFolder;
|
||||
private bool _isRoot = true;
|
||||
|
||||
private Lazy<IList<SystemFile>> _rootFolders;
|
||||
private Lazy<string> _webDavRootPath;
|
||||
|
||||
public string RootPath
|
||||
{
|
||||
get { return _webDavRootPath.Value; }
|
||||
}
|
||||
private IFolder _currentFolder;
|
||||
|
||||
public WebDavManager(ICryptography cryptography)
|
||||
{
|
||||
|
@ -38,49 +30,29 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
Log = LogManager.GetLogger(this.GetType());
|
||||
|
||||
_webDavSession = new WebDavSession();
|
||||
|
||||
_rootFolders = new Lazy<IList<SystemFile>>(ConnectToWebDavServer);
|
||||
_webDavRootPath = new Lazy<string>(() =>
|
||||
{
|
||||
if (_rootFolders.Value.Any())
|
||||
{
|
||||
var folder = _rootFolders.Value.First();
|
||||
var uri = new Uri(folder.Url);
|
||||
return uri.Scheme + "://" + uri.Host + uri.Segments[0] + uri.Segments[1];
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void OpenFolder(string pathPart)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(pathPart))
|
||||
{
|
||||
_isRoot = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_isRoot = false;
|
||||
|
||||
_webDavSession.Credentials = new NetworkCredential(WspContext.User.Login, _cryptography.Decrypt(WspContext.User.EncryptedPassword), WebDavAppConfigManager.Instance.UserDomain);
|
||||
|
||||
_currentFolder = _webDavSession.OpenFolder(_webDavRootPath.Value + pathPart);
|
||||
}
|
||||
|
||||
public IEnumerable<IHierarchyItem> GetChildren()
|
||||
public IEnumerable<IHierarchyItem> OpenFolder(string pathPart)
|
||||
{
|
||||
IHierarchyItem[] children;
|
||||
|
||||
if (_isRoot)
|
||||
if (string.IsNullOrWhiteSpace(pathPart))
|
||||
{
|
||||
children = _rootFolders.Value.Select(x => new WebDavHierarchyItem {Href = new Uri(x.Url), ItemType = ItemType.Folder}).ToArray();
|
||||
children = ConnectToWebDavServer().Select(x => new WebDavHierarchyItem { Href = new Uri(x.Url), ItemType = ItemType.Folder }).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
if (_currentFolder == null || _currentFolder.Path.ToString() != pathPart)
|
||||
{
|
||||
_webDavSession.Credentials = new NetworkCredential(WspContext.User.Login,
|
||||
_cryptography.Decrypt(WspContext.User.EncryptedPassword),
|
||||
WebDavAppConfigManager.Instance.UserDomain);
|
||||
|
||||
_currentFolder = _webDavSession.OpenFolder(string.Format("{0}{1}/{2}",WebDavAppConfigManager.Instance.WebdavRoot, WspContext.User.OrganizationId , pathPart));
|
||||
}
|
||||
|
||||
children = _currentFolder.GetChildren();
|
||||
}
|
||||
}
|
||||
|
||||
List<IHierarchyItem> sortedChildren = children.Where(x => x.ItemType == ItemType.Folder).OrderBy(x => x.DisplayName).ToList();
|
||||
sortedChildren.AddRange(children.Where(x => x.ItemType != ItemType.Folder).OrderBy(x => x.DisplayName));
|
||||
|
@ -88,30 +60,40 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
return sortedChildren;
|
||||
}
|
||||
|
||||
public bool IsFile(string fileName)
|
||||
public bool IsFile(string path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fileName) | _currentFolder == null)
|
||||
return false;
|
||||
string folder = GetFileFolder(path);
|
||||
|
||||
try
|
||||
if (string.IsNullOrWhiteSpace(folder))
|
||||
{
|
||||
IResource resource = _currentFolder.GetResource(fileName);
|
||||
//Stream stream = resource.GetReadStream();
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
}
|
||||
return false;
|
||||
|
||||
var resourceName = GetResourceName(path);
|
||||
|
||||
OpenFolder(folder);
|
||||
|
||||
IResource resource = _currentFolder.GetResource(resourceName);
|
||||
|
||||
return resource.ItemType == ItemType.Resource;
|
||||
}
|
||||
|
||||
public byte[] GetFileBytes(string fileName)
|
||||
|
||||
public byte[] GetFileBytes(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
IResource resource = _currentFolder.GetResource(fileName);
|
||||
string folder = GetFileFolder(path);
|
||||
|
||||
var resourceName = GetResourceName(path);
|
||||
|
||||
OpenFolder(folder);
|
||||
|
||||
IResource resource = _currentFolder.GetResource(resourceName);
|
||||
|
||||
Stream stream = resource.GetReadStream();
|
||||
byte[] fileBytes = ReadFully(stream);
|
||||
|
||||
return fileBytes;
|
||||
}
|
||||
catch (InvalidOperationException exception)
|
||||
|
@ -120,12 +102,17 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
}
|
||||
}
|
||||
|
||||
public IResource GetResource(string fileName)
|
||||
public IResource GetResource(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
IResource resource = _currentFolder.GetResource(fileName);
|
||||
return resource;
|
||||
string folder = GetFileFolder(path);
|
||||
|
||||
var resourceName = GetResourceName(path);
|
||||
|
||||
OpenFolder(folder);
|
||||
|
||||
return _currentFolder.GetResource(resourceName);
|
||||
}
|
||||
catch (InvalidOperationException exception)
|
||||
{
|
||||
|
@ -133,11 +120,17 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
}
|
||||
}
|
||||
|
||||
public string GetFileUrl(string fileName)
|
||||
public string GetFileUrl(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
IResource resource = _currentFolder.GetResource(fileName);
|
||||
string folder = GetFileFolder(path);
|
||||
|
||||
var resourceName = GetResourceName(path);
|
||||
|
||||
OpenFolder(folder);
|
||||
|
||||
IResource resource = _currentFolder.GetResource(resourceName);
|
||||
return resource.Href.ToString();
|
||||
}
|
||||
catch (InvalidOperationException exception)
|
||||
|
@ -171,19 +164,6 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
return rootFolders;
|
||||
}
|
||||
|
||||
private byte[] ReadFully(Stream input)
|
||||
{
|
||||
var buffer = new byte[16*1024];
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
int read;
|
||||
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
|
||||
ms.Write(buffer, 0, read);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string CreateFileId(string path)
|
||||
{
|
||||
return _cryptography.Encrypt(path).Replace("/", "AAAAA");
|
||||
|
@ -193,5 +173,45 @@ namespace WebsitePanel.WebDav.Core.Managers
|
|||
{
|
||||
return _cryptography.Decrypt(id.Replace("AAAAA", "/"));
|
||||
}
|
||||
|
||||
#region Helpers
|
||||
|
||||
private byte[] ReadFully(Stream input)
|
||||
{
|
||||
var buffer = new byte[16 * 1024];
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
int read;
|
||||
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
|
||||
ms.Write(buffer, 0, read);
|
||||
return ms.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetFileFolder(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path) || !path.Contains('/'))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
string fileName = path.Split('/').Last();
|
||||
int index = path.LastIndexOf(fileName, StringComparison.InvariantCultureIgnoreCase);
|
||||
string folder = path.Remove(index - 1, fileName.Length + 1);
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
private string GetResourceName(string path)
|
||||
{
|
||||
if (string.IsNullOrEmpty(path) || !path.Contains('/'))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
return path.Split('/').Last(); ;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -23,13 +23,7 @@ namespace WebsitePanel.WebDav.Core.Owa
|
|||
|
||||
public CheckFileInfo GetCheckFileInfo(string path)
|
||||
{
|
||||
string fileName = path.Split('/').Last();
|
||||
int index = path.LastIndexOf(fileName, StringComparison.InvariantCultureIgnoreCase);
|
||||
string folder = path.Remove(index - 1, fileName.Length + 1);
|
||||
|
||||
_webDavManager.OpenFolder(folder);
|
||||
|
||||
var resource = _webDavManager.GetResource(fileName);
|
||||
var resource = _webDavManager.GetResource(path);
|
||||
|
||||
var cFileInfo = new CheckFileInfo
|
||||
{
|
||||
|
@ -44,13 +38,7 @@ namespace WebsitePanel.WebDav.Core.Owa
|
|||
|
||||
public FileResult GetFile(string path)
|
||||
{
|
||||
string fileName = path.Split('/').Last();
|
||||
int index = path.LastIndexOf(fileName, StringComparison.InvariantCultureIgnoreCase);
|
||||
string folder = path.Remove(index - 1, fileName.Length + 1);
|
||||
|
||||
_webDavManager.OpenFolder(folder);
|
||||
|
||||
var fileBytes = _webDavManager.GetFileBytes(fileName);
|
||||
var fileBytes = _webDavManager.GetFileBytes(path);
|
||||
|
||||
return new FileContentResult(fileBytes, MediaTypeNames.Application.Octet);
|
||||
}
|
||||
|
|
|
@ -25,12 +25,17 @@ namespace WebsitePanel.WebDav.Core.Security.Authentication
|
|||
|
||||
public WspPrincipal LogIn(string login, string password)
|
||||
{
|
||||
if (_principalContext.ValidateCredentials(login, password) == false)
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
//var user = UserPrincipal.FindByIdentity(_principalContext, IdentityType.UserPrincipalName, login);
|
||||
var user = UserPrincipal.FindByIdentity(_principalContext, IdentityType.UserPrincipalName, login);
|
||||
|
||||
if (_principalContext.ValidateCredentials(login, password) == false && user != null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var principal = new WspPrincipal(login);
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.DirectoryServices.AccountManagement" />
|
||||
|
@ -83,9 +84,8 @@
|
|||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WebsitePanel.EnterpriseServer.Base, Version=2.1.0.1, Culture=neutral, PublicKeyToken=da8782a6fc4d0081, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\Scheduler Domains\WebsitePanel\Bin\WebsitePanel.EnterpriseServer.Base.dll</HintPath>
|
||||
<Reference Include="WebsitePanel.EnterpriseServer.Base">
|
||||
<HintPath>..\WebsitePanel.WebPortal\Bin\WebsitePanel.EnterpriseServer.Base.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WebsitePanel.EnterpriseServer.Client">
|
||||
<HintPath>..\WebsitePanel.WebPortal\Bin\WebsitePanel.EnterpriseServer.Client.dll</HintPath>
|
||||
|
@ -114,6 +114,7 @@
|
|||
<Compile Include="Config\WebConfigSections\SessionKeysElementCollection.cs" />
|
||||
<Compile Include="Config\WebConfigSections\UserDomainElement.cs" />
|
||||
<Compile Include="Config\WebConfigSections\WebDavExplorerConfigurationSettingsSection.cs" />
|
||||
<Compile Include="Config\WebConfigSections\WebdavRootElement.cs" />
|
||||
<Compile Include="Config\WebConfigSections\WebsitePanelConstantUserElement.cs" />
|
||||
<Compile Include="Config\WebDavAppConfigManager.cs" />
|
||||
<Compile Include="Entities\Owa\CheckFileInfo.cs" />
|
||||
|
@ -155,6 +156,7 @@
|
|||
<Folder Include="Interfaces\ActiveDirectory\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue