2016-11-14 12:17:07 +01:00
|
|
|
|
|
2016-05-17 18:22:18 +02:00
|
|
|
|
using System.IO;
|
2016-11-14 12:17:07 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Security.Claims;
|
2016-05-17 18:22:18 +02:00
|
|
|
|
using Microsoft.AspNet.FileProviders;
|
2016-11-14 12:17:07 +01:00
|
|
|
|
using Yavsc.ViewModels.UserFiles;
|
2016-05-17 18:22:18 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Yavsc.Helpers
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class FileSystemHelpers {
|
2016-09-05 00:24:43 +02:00
|
|
|
|
|
2016-11-14 12:17:07 +01:00
|
|
|
|
public static UserDirectoryInfo GetUserFiles(this ClaimsPrincipal user,string subdir) {
|
|
|
|
|
|
|
|
|
|
|
|
UserDirectoryInfo di = new UserDirectoryInfo(user.Identity.Name,subdir);
|
|
|
|
|
|
|
|
|
|
|
|
return di;
|
|
|
|
|
|
}
|
|
|
|
|
|
static char [] ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~.".ToCharArray();
|
|
|
|
|
|
|
|
|
|
|
|
public static bool IsValidDirectoryName(this string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return !name.Any(c=> !ValidChars.Contains(c));
|
|
|
|
|
|
}
|
|
|
|
|
|
public static bool IsValidPath(this string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (path==null) return true;
|
|
|
|
|
|
foreach (var name in path.Split(Path.DirectorySeparatorChar))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (name!=null)
|
|
|
|
|
|
if (!IsValidDirectoryName(name)
|
|
|
|
|
|
|| name.Equals("..")) return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
2016-05-17 18:22:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|