public IHttpHandler GetHttpHandler(RequestContext requestContext) { if (!UrlAuthorizationModule.CheckUrlAccessForPrincipal("~/Download/", requestContext.HttpContext.User, requestContext.HttpContext.Request.HttpMethod)) { requestContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized; requestContext.HttpContext.Response.End(); } hapConfig config = hapConfig.Current; string path = HttpUtility.UrlDecode(((string)requestContext.RouteData.Values["path"]).Replace('^', '&').Replace("|", "%")); DriveMapping unc = config.MyFiles.Mappings.FilteredMappings[((string)requestContext.RouteData.Values["drive"]).ToUpper().ToCharArray()[0]]; path = Converter.FormatMapping(unc.UNC, ADUser) + '\\' + path.Replace('/', '\\'); HAP.Data.SQL.WebEvents.Log(DateTime.Now, "MyFiles.Download", requestContext.HttpContext.User.Identity.Name, HttpContext.Current.Request.UserHostAddress, HttpContext.Current.Request.Browser.Platform, HttpContext.Current.Request.Browser.Browser + " " + HttpContext.Current.Request.Browser.Version, HttpContext.Current.Request.UserHostName, "Downloading: " + path); Downloader downloader = new Downloader(); if (requestContext.RouteData.Values.ContainsKey("path")) { downloader.RoutingPath = requestContext.RouteData.Values["path"] as string; } else { downloader.RoutingPath = string.Empty; } downloader.RoutingDrive = requestContext.RouteData.Values["drive"] as string; downloader.RoutingDrive = downloader.RoutingDrive.ToUpper(); return(downloader); }
public static string DriveToUNC(string RoutingPath, string RoutingDrive, out DriveMapping unc, User user) { hapConfig config = hapConfig.Current; unc = config.MyFiles.Mappings.FilteredMappings[RoutingDrive.ToCharArray()[0]]; return((Converter.FormatMapping(unc.UNC, user) + HttpUtility.UrlDecode(RoutingPath.Replace('|', '%'), System.Text.Encoding.Default)).TrimEnd(new char[] { '\\' }).Replace('^', '&').Replace('/', '\\')); }
public File(DirectoryInfo file, DriveMapping mapping, User user) { Extension = file.Extension; Type = "Directory"; Name = file.Name + (file.Name.Contains(file.Extension) ? "" : file.Extension); try { Permissions = UserFileAccessRights.Get(file.FullName).ToPerms(); } catch { } FileIcon fi; if (FileIcon.TryGet(Extension, out fi)) { Type = fi.Type; Name = Name.Remove(Name.LastIndexOf(file.Extension)); } Icon = "../images/icons/" + ParseForImage(file); if (Icon.EndsWith(".ico")) { Icon = "../api/mycomputer/" + ParseForImage(file); } if (file.Extension.ToLower().Equals(".png") || file.Extension.ToLower().Equals(".jpg") || file.Extension.ToLower().Equals(".jpeg") || file.Extension.ToLower().Equals(".gif") || file.Extension.ToLower().Equals(".bmp") || file.Extension.ToLower().Equals(".wmf")) { Icon = "../api/mycomputer/thumb/" + HttpUtility.UrlEncode(Converter.UNCtoDrive(file.FullName, mapping, user).Replace(":", "")).Replace('+', ' ').Replace("%", "|").Replace("|2f", "/"); } CreationTime = file.CreationTime.ToShortDateString() + " " + file.CreationTime.ToString("hh:mm"); UnderlyingCreation = file.CreationTime; ModifiedTime = file.LastWriteTime.ToShortDateString() + " " + file.LastWriteTime.ToString("hh:mm"); UnderlyingModified = file.LastWriteTime; UnderlyingSize = 0; Size = ""; Path = HttpUtility.UrlEncode(Converter.UNCtoDrive(file.FullName, mapping, user).Replace(":", "")).Replace('+', ' ').Replace("%", "|").Replace("|5c", "\\"); Permissions = UserFileAccessRights.Get(file.FullName).ToPerms(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack && !IsCallback && !IsAsync) { if (!string.IsNullOrEmpty(Request.QueryString["teacher"])) { HAP.MyFiles.Homework.Homework Homework = new HAP.MyFiles.Homework.Homeworks().Homework.Single(hw => hw.Teacher == Request.QueryString["teacher"] && hw.Name == Request.QueryString["name"] && hw.Start == Request.QueryString["start"].Replace('.', ':') && hw.End == Request.QueryString["end"].Replace('.', ':')); ADUser.Authenticate(Homework.Teacher, TokenGenerator.ConvertToPlain(Homework.Token)); } ADUser.Impersonate(); string path = Server.UrlDecode(Request.QueryString["path"].Remove(0, 1).Replace('^', '&').Replace("|", "%")); string p = Request.QueryString["path"].Substring(0, 1); DriveMapping unc = null; unc = config.MyFiles.Mappings.FilteredMappings[p.ToCharArray()[0]]; if (unc == null || !isWriteAuth(unc)) { Response.Redirect(Request.ApplicationPath + "/unauthorised.aspx", true); } else { path = Converter.FormatMapping(unc.UNC, ADUser) + path.Replace('/', '\\'); } ADUser.EndImpersonate(); } }
/// <summary> /// Helper method to convert a group policy preference to a drive mapping model entity /// </summary> /// <param name="xml"></param> /// <returns>List<DriveMappingModel></returns> public static List <DriveMapping> ConvertToDriveMappingList(Stream xml) { // create xmldoc XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(xml); //namespace manager & URI's needed in order to read GPP nodes XmlNamespaceManager nsmanager = new XmlNamespaceManager(xmldoc.NameTable); nsmanager.AddNamespace("q1", "http://www.microsoft.com/GroupPolicy/Settings"); nsmanager.AddNamespace("q2", "http://www.microsoft.com/GroupPolicy/Settings/DriveMaps"); XmlNodeList driveProperties = xmldoc.SelectNodes("q1:GPO/q1:User/q1:ExtensionData/q1:Extension/q2:DriveMapSettings/q2:Drive", nsmanager); //create list to store all entries List <DriveMapping> driveMappings = new List <DriveMapping>(); DriveMapping driveMapping; //helper index to assign id to our entries int i = 0; foreach (XmlNode property in driveProperties) { //the real drive mapping configuration is stored in the 2nd XML child-node --> index 1 driveMapping = new DriveMapping { Path = property.ChildNodes[1].Attributes["path"].InnerXml, DriveLetter = property.ChildNodes[1].Attributes["letter"].InnerXml, Label = property.ChildNodes[1].Attributes["label"].InnerXml, Id = (i + 1) }; //check if we have a filter applied as child node --> index 2 try { string groupFilter = property.ChildNodes[2].ChildNodes[0].Attributes["name"].InnerXml; String[] streamlinedGroupFilter = groupFilter.Split('\\'); driveMapping.GroupFilter = streamlinedGroupFilter[1]; } catch { //nothing we can do } driveMappings.Add(driveMapping); i++; } return(driveMappings); }
public static UNCPath ToUNCPath(DriveMapping unc) { UNCPath Unc = new UNCPath(); Unc.Drive = unc.Drive.ToString(); Unc.EnableReadTo = unc.EnableReadTo; Unc.EnableWriteTo = unc.EnableWriteTo; Unc.Name = unc.Name; Unc.UNC = unc.UNC; Unc.Usage = unc.UsageMode; return(Unc); }
public ActionResult Create(DriveMapping driveMapping) { if (ModelState.IsValid) { List <DriveMapping> driveMappings = _driveMappingStore.GetDriveMappings(); driveMapping.Id = driveMappings.Count + 1; driveMappings.Add(driveMapping); _driveMappingStore.SetDriveMappings(driveMappings); } return(PartialView("_Create", driveMapping)); }
public File(FileInfo file, DriveMapping mapping, User user) { Extension = file.Extension; Type = "File"; Name = file.Name + (file.Name.Contains(file.Extension) ? "" : file.Extension); CreationTime = file.CreationTime.ToShortDateString() + " " + file.CreationTime.ToString("hh:mm"); UnderlyingCreation = file.CreationTime; ModifiedTime = file.LastWriteTime.ToShortDateString() + " " + file.LastWriteTime.ToString("hh:mm"); UnderlyingModified = file.LastWriteTime; Size = parseLength(file.Length); UnderlyingSize = file.Length; FileIcon fi; if (FileIcon.TryGet(Extension, out fi)) { Type = fi.Type; Name = Name.Remove(Name.LastIndexOf(file.Extension)); } if (Type == "File") { try { RegistryKey rkRoot = Registry.ClassesRoot; string keyref = rkRoot.OpenSubKey(file.Extension).GetValue("").ToString(); Type = rkRoot.OpenSubKey(keyref).GetValue("").ToString(); Name = Name.Remove(Name.LastIndexOf(file.Extension)); } catch { Type = "File"; } } if (Type != "File") { Icon = "../images/icons/" + ParseForImage(file); if (Icon.EndsWith(".ico")) { Icon = "../api/mycomputer/" + ParseForImage(file); } } else { Icon = "../images/icons/file.png"; } string m = Converter.UNCtoDrive2(file.FullName, mapping, user); Path = "../Download/" + HttpUtility.UrlEncode(m.Replace(":", "")).Replace('+', ' ').Replace("%", "|").Replace("|2f", "/"); if (file.Extension.ToLower().Equals(".png") || file.Extension.ToLower().Equals(".jpg") || file.Extension.ToLower().Equals(".jpeg") || file.Extension.ToLower().Equals(".gif") || file.Extension.ToLower().Equals(".bmp") || file.Extension.ToLower().Equals(".wmf")) { Icon = "../api/mycomputer/thumb/" + HttpUtility.UrlEncode(m.Replace(":", "")).Replace('+', ' ').Replace("%", "|").Replace("|2f", "/"); } Permissions = UserFileAccessRights.Get(file.FullName).ToPerms(); }
public int UpdateMapping(string origdrive, string origunc, string drive, string name, string unc, string enablereadto, string enablewriteto, string usagemode) { hapConfig Config = HttpContext.Current.Cache["tempConfig"] as hapConfig; DriveMapping m = Config.MyFiles.Mappings.Single(ma => ma.Key.Drive == origdrive.ToCharArray()[0] && ma.Key.UNC == origunc.Replace('/', '\\')).Value; m.Drive = drive.ToCharArray()[0]; m.UsageMode = (MappingUsageMode)Enum.Parse(typeof(MappingUsageMode), usagemode); m.Name = name; m.UNC = unc.Replace('/', '\\'); m.EnableReadTo = enablereadto; m.EnableWriteTo = enablewriteto; Config.MyFiles.Mappings.Update(origdrive.ToCharArray()[0], origunc, m); return(0); }
public ActionResult Init() { List <DriveMapping> driveMappings = new List <DriveMapping>(); DriveMapping driveMappingModel = new DriveMapping { DriveLetter = "A", Label = "Example", Path = "\\\\path\\to\\your\\share", GroupFilter = "exampleGroupSamAccountName" }; driveMappings.Add(driveMappingModel); _driveMappingStore.SetDriveMappings(driveMappings); return(RedirectToAction(indexView)); }
public override FileInfo GetRequestedFileInfo(HttpContext context) { config = hapConfig.Current; string path = HttpUtility.UrlDecode(RoutingPath.Replace('^', '&').Replace("|", "%")); DriveMapping unc = config.MyFiles.Mappings.FilteredMappings[RoutingDrive.ToCharArray()[0]]; if (unc == null || !isAuth(unc)) { context.Response.Redirect(VirtualPathUtility.ToAbsolute("~/unauthorised.aspx"), true); } else { path = Converter.FormatMapping(unc.UNC, ADUser) + '\\' + path.Replace('/', '\\'); } return(new FileInfo(path)); }
public Properties(DirectoryInfo dir, DriveMapping mapping, User user, bool RunSize) { Name = dir.Name; DateCreated = dir.CreationTime.ToString(); DriveMapping m; Actions = isWriteAuth(mapping) ? HAP.MyFiles.AccessControlActions.Change : HAP.MyFiles.AccessControlActions.View; try { Permissions = UserFileAccessRights.Get(dir.FullName).ToPerms(); } catch { } if (dir.FullName == Converter.DriveToUNC("", mapping.Drive.ToString(), out m, user) + "\\") { Location = null; } else { Location = HttpUtility.UrlEncode(Converter.UNCtoDrive(dir.Parent.FullName, mapping, user).Replace(":", "")).Replace('+', ' ').Replace("%", "|").Replace("|5c", "\\"); Contents = dir.GetFiles().Length + " Files, "; Contents += dir.GetDirectories().Length + " Folders"; long s = 0; if (RunSize) { foreach (FileInfo f in dir.GetFiles("*.*", SearchOption.AllDirectories)) { s += f.Length; } } Size = File.parseLength(s); } Type = "File Folder"; if (Type != "File") { Icon = "../images/icons/" + File.ParseForImage(dir); if (Icon.EndsWith(".ico")) { Icon = "../api/mycomputer/" + File.ParseForImage(dir); } } else { Icon = "../images/icons/file.png"; } }
private bool isAuth(DriveMapping path) { if (path.EnableReadTo == "All") { return(true); } else if (path.EnableReadTo != "None") { bool vis = false; foreach (string s in path.EnableReadTo.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { if (!vis) { vis = HttpContext.Current.User.IsInRole(s.Trim()); } } return(vis); } return(false); }
public ActionResult Edit(DriveMapping driveMapping) { try { if (ModelState.IsValid) { List <DriveMapping> driveMappings = _driveMappingStore.GetDriveMappings(); DriveMapping selectedItem = driveMappings.Where(dm => dm.Id == driveMapping.Id).First(); driveMappings[driveMappings.IndexOf(selectedItem)] = driveMapping; _driveMappingStore.SetDriveMappings(driveMappings); } return(PartialView("_Edit", driveMapping)); } catch (Exception ex) { _driveMappingStore.SetErrorMessage(ex); return(RedirectToAction(indexView)); } }
/// <summary> /// Create Properties for quick use /// </summary> /// <param name="dir">Directory</param> /// <param name="user">User</param> /// <param name="mapping">Drive Mapping</param> public Properties(DirectoryInfo dir, User user, DriveMapping mapping) { DriveMapping m; Actions = isWriteAuth(mapping) ? HAP.MyFiles.AccessControlActions.Change : HAP.MyFiles.AccessControlActions.View; try { Permissions = UserFileAccessRights.Get(dir.FullName).ToPerms(); } catch { } if (dir.FullName.Contains(".zip")) { Actions = AccessControlActions.ZIP; } else { try { dir.GetDirectories(); } catch { Actions = HAP.MyFiles.AccessControlActions.None; } } Name = (dir.FullName == Converter.DriveToUNC("", mapping.Drive.ToString(), out m, user) + '\\') ? mapping.Name : dir.Name; Location = HttpUtility.UrlEncode(Converter.UNCtoDrive(dir.FullName, mapping, user).Replace(":", "")).Replace('+', ' ').Replace("%", "|").Replace("|5c", "\\"); try { Permissions = UserFileAccessRights.Get(dir.FullName).ToPerms(); } catch { } Type = "File Folder"; if (Type != "File") { Icon = "../images/icons/" + File.ParseForImage(dir); if (Icon.EndsWith(".ico")) { Icon = "../api/mycomputer/" + File.ParseForImage(dir); } } else { Icon = "../images/icons/file.png"; } }
public Properties(FileInfo file, DriveMapping mapping, User user) { Actions = isWriteAuth(mapping) ? HAP.MyFiles.AccessControlActions.Change : HAP.MyFiles.AccessControlActions.View; Name = file.Name + (file.Name.Contains(file.Extension) ? "" : file.Extension); Extension = file.Extension; DateCreated = file.CreationTime.ToString(); DateModified = file.LastWriteTime.ToString(); DateAccessed = file.LastAccessTime.ToString(); Location = HttpUtility.UrlEncode(Converter.UNCtoDrive(file.Directory.FullName, mapping, user).Replace(":", "")).Replace('+', ' ').Replace("%", "|").Replace("|5c", "\\"); Size = File.parseLength(file.Length); FileIcon fi; if (FileIcon.TryGet(Extension, out fi)) { Type = fi.Type; } if (Type == "File") { try { RegistryKey rkRoot = Registry.ClassesRoot; string keyref = rkRoot.OpenSubKey(file.Extension).GetValue("").ToString(); Type = rkRoot.OpenSubKey(keyref).GetValue("").ToString(); } catch { Type = "File"; } } if (Type != "File") { Icon = "../images/icons/" + File.ParseForImage(file); if (Icon.EndsWith(".ico")) { Icon = "../api/mycomputer/" + File.ParseForImage(file); } } else { Icon = "../images/icons/file.png"; } }
static bool isWriteAuth(DriveMapping path) { if (path == null) { return(true); } if (path.EnableWriteTo == "All") { return(true); } else if (path.EnableWriteTo != "None") { bool vis = false; foreach (string s in path.EnableWriteTo.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { if (!vis) { vis = Context.User.IsInRole(s.Trim()); } } return(vis); } return(false); }
static bool isWriteAuth(DriveMapping path, User user) { if (path == null) { return(true); } if (path.EnableWriteTo == "All") { return(true); } else if (path.EnableWriteTo != "None") { bool vis = false; foreach (string s in path.EnableWriteTo.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { if (!vis) { vis = user.IsMemberOf(GroupPrincipal.FindByIdentity(ADUtils.GetPContext(), s.Trim())); } } return(vis); } return(false); }
public static string DriveToUNC(string Path, out DriveMapping unc) { return(DriveToUNC(Path.Remove(0, 2), Path.Substring(0, 1), out unc)); }
public static string UNCtoDrive(string dirpath, DriveMapping unc, User user) { dirpath = dirpath.Replace(Converter.FormatMapping(unc.UNC, user), unc.Drive + ":"); dirpath = dirpath.Replace("\\\\", "\\"); return(dirpath); }
public Properties(DirectoryInfo dir, DriveMapping mapping, User user) : this(dir, mapping, user, true) { }
public static string UNCtoDrive2(string dirpath, DriveMapping unc, User user) { dirpath = dirpath.Replace(Converter.FormatMapping(unc.UNC, user), unc.Drive.ToString()); dirpath = dirpath.Replace('\\', '/').Replace("//", "/"); return(dirpath); }
public static string UNCtoDrive2(string dirpath, DriveMapping unc) { return(UNCtoDrive2(dirpath, unc, (User)Membership.GetUser())); }
public static string DriveToUNC(string RoutingPath, string RoutingDrive, out DriveMapping unc) { return(DriveToUNC(RoutingPath, RoutingDrive, out unc)); }
protected void uploadbtn_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(Request.QueryString["teacher"])) { HAP.MyFiles.Homework.Homework Homework = new HAP.MyFiles.Homework.Homeworks().Homework.Single(hw => hw.Teacher == Request.QueryString["teacher"] && hw.Name == Request.QueryString["name"] && hw.Start == Request.QueryString["start"].Replace('.', ':') && hw.End == Request.QueryString["end"].Replace('.', ':')); ADUser.Authenticate(Homework.Teacher, TokenGenerator.ConvertToPlain(Homework.Token)); } ADUser.Impersonate(); message.Text = ""; string path = Server.UrlDecode(Request.QueryString["path"].Remove(0, 1).Replace('^', '&').Replace("|", "%")); string p = Request.QueryString["path"].Substring(0, 1); DriveMapping unc = null; unc = config.MyFiles.Mappings.FilteredMappings[p.ToCharArray()[0]]; if (unc == null || !isWriteAuth(unc)) { Response.Redirect(Request.ApplicationPath + "/unauthorised.aspx", true); } else { path = Converter.FormatMapping(unc.UNC, ADUser) + path.Replace('/', '\\'); } if (FileUpload1.HasFile && isAuth(Path.GetExtension(FileUpload1.FileName))) { FileUpload1.SaveAs(Path.Combine(path, (string.IsNullOrEmpty(Request.QueryString["teacher"]) ? "" : User.Identity.Name + " - ") + FileUpload1.FileName)); message.Text += FileUpload1.FileName + " has been uploaded<br />"; } else if (FileUpload1.HasFile) { message.Text += "Error: " + FileUpload1.FileName + " is a restricted file type<br/>"; } if (FileUpload2.HasFile && isAuth(Path.GetExtension(FileUpload2.FileName))) { FileUpload2.SaveAs(Path.Combine(path, (string.IsNullOrEmpty(Request.QueryString["teacher"]) ? "" : User.Identity.Name + " - ") + FileUpload2.FileName)); message.Text += FileUpload2.FileName + " has been uploaded<br />"; } else if (FileUpload2.HasFile) { message.Text += "Error: " + FileUpload2.FileName + " is a restricted file type<br/>"; } if (FileUpload3.HasFile && isAuth(Path.GetExtension(FileUpload3.FileName))) { FileUpload3.SaveAs(Path.Combine(path, (string.IsNullOrEmpty(Request.QueryString["teacher"]) ? "" : User.Identity.Name + " - ") + FileUpload3.FileName)); message.Text += FileUpload3.FileName + " has been uploaded<br />"; } else if (FileUpload3.HasFile) { message.Text += "Error: " + FileUpload3.FileName + " is a restricted file type<br/>"; } if (FileUpload4.HasFile && isAuth(Path.GetExtension(FileUpload4.FileName))) { FileUpload4.SaveAs(Path.Combine(path, (string.IsNullOrEmpty(Request.QueryString["teacher"]) ? "" : User.Identity.Name + " - ") + FileUpload4.FileName)); message.Text += FileUpload4.FileName + " has been uploaded<br />"; } else if (FileUpload4.HasFile) { message.Text += "Error: " + FileUpload4.FileName + " is a restricted file type<br/>"; } if (FileUpload5.HasFile && isAuth(Path.GetExtension(FileUpload5.FileName))) { FileUpload5.SaveAs(Path.Combine(path, (string.IsNullOrEmpty(Request.QueryString["teacher"]) ? "" : User.Identity.Name + " - ") + FileUpload5.FileName)); message.Text += FileUpload5.FileName + " has been uploaded<br />"; } else if (FileUpload5.HasFile) { message.Text += "Error: " + FileUpload5.FileName + " is a restricted file type<br/>"; } if (!string.IsNullOrEmpty(message.Text)) { message.Text = "<div style=\"padding: 4px; color: red;\">" + message.Text + "</div>"; } closeb.Visible = (((Button)sender).ID == "uploadbtnClose"); ADUser.EndImpersonate(); }
public File(FileInfo file, DriveMapping mapping, User user, AccessControlActions actions) : this(file, mapping, user) { this.Actions = actions; }
public File(DirectoryInfo subdir, DriveMapping mapping, User user, AccessControlActions actions) : this(subdir, mapping, user) { this.Actions = actions; }