Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public override bool ValidateUser(string username, string password)
        {
            bool result = false;

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
            {
                return(false);
            }

            using (ExtranetDB dbContext = new ExtranetDB())
            {
                var user = (from us in dbContext.Users
                            where string.Compare(username, us.Username, StringComparison.OrdinalIgnoreCase) == 0 &&
                            string.Compare(password, us.Password, StringComparison.OrdinalIgnoreCase) == 0 &&
                            us.IsActive == true
                            select us).FirstOrDefault();

                result = (user != null) ? true : false;
            }

            if (!result)
            {
                using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "DELLORTO.IT"))
                {
                    // validate the credentials
                    result = pc.ValidateCredentials(username, password, ContextOptions.Negotiate);
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public ActionResult Report(string sEmail, string sOggetto, string sDescrizione)
        {
            var         iD   = "";
            MailMessage mail = new MailMessage("*****@*****.**", "*****@*****.**");

            //mail.To.Add("*****@*****.**");
            //mail.To.Add("*****@*****.**");
            using (ExtranetDB dbContext = new ExtranetDB())
            {
                TicketWB nt     = new TicketWB();
                int      dToday = Int32.Parse(DateTime.Now.ToString("yyyyMMdd"));
                nt.Data = dToday;
                dbContext.TicketWB.Add(nt);
                dbContext.SaveChanges();
                iD = dbContext.TicketWB.Max(a => a.ID_Ticket).ToString();
            }
            SmtpClient client = new SmtpClient();

            client.Port                  = 25;
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Host                  = "mail.dellorto.it";
            mail.Subject                 = "Nuova segnalazione (ID: " + iD + "): " + sOggetto;
            mail.Body = sDescrizione + Environment.NewLine + "(" + sEmail + ")";

            client.Send(mail);

            return(View());
        }
Ejemplo n.º 3
0
        [Route("api/file/load/{*folder?}")]//{username}")]
        public IHttpActionResult Load(string folder = "")

        {
            FTPabilitazioni utente = db.FTPabilitazioni.Where(e => e.ftpUser == User.Identity.Name).FirstOrDefault();
            Boolean         bCheck = false;

            if (utente == null)
            {
                return(Content(HttpStatusCode.NoContent, "Abilitazione non trovata"));
            }
            var    nodes = new List <FtpModel>();
            string sDir  = "C:\\inetpub\\wwwroot\\FTP";

            if (folder == "")
            {
                //FTPabilitazioni utente = db.FTPabilitazioni.Where(e => e.ftpUser == User.Identity.Name).FirstOrDefault();

                nodes.Add(new FtpModel()
                {
                    FileName = "FTP", Folder = "#", Type = "Folder", ReadWrite = "R"
                });
                var data = DirSearch(sDir, nodes);
            }
            else
            {
                folder = folder.Replace("#/", "");
                folder = folder.Replace('/', Path.DirectorySeparatorChar);
                string   cartella        = (sDir + "\\" + folder);
                string   cartellaAttuale = cartella.Substring(sDir.Length + 1);
                string[] percorso        = cartellaAttuale.Split(Path.DirectorySeparatorChar);
                string   sRight;
                using (ExtranetDB dbContext = new ExtranetDB())
                {
                    string     toCheck      = percorso[0];
                    UserShares abilitazioni = dbContext.UserShares.Where(e => e.username == User.Identity.Name && e.SharePath == toCheck).FirstOrDefault();
                    if (abilitazioni != null)
                    {
                        bCheck = true;
                    }
                    sRight = abilitazioni.abilitazione;
                }
                if (bCheck == false)
                {
                    return(Content(HttpStatusCode.NoContent, "404"));
                }
                DirectoryInfo nomeFolder = new DirectoryInfo(cartella);
                nodes.Add(new FtpModel()
                {
                    FileName = nomeFolder.Name, Folder = folder, Type = "Folder", Size = GetDirectorySize(nomeFolder.FullName).ToString(), ReadWrite = sRight
                });
                var data = DirSearch(cartella, nodes);
            }
            return(Ok(nodes));//, System.Web.Mvc.Jso.nRequestBehavior.AllowGet);
        }
Ejemplo n.º 4
0
 public override bool ChangePassword(string username, string oldPassword, string newPassword)
 {
     using (ExtranetDB dbContext = new ExtranetDB())
     {
         var userp = dbContext.Users.Where(x => x.Username == username).FirstOrDefault();
         userp.Password = newPassword;
         dbContext.Entry(userp).State = EntityState.Modified;
         dbContext.SaveChanges();
         return(true);
     }
 }
Ejemplo n.º 5
0
        public override string GetUserNameByEmail(string email)
        {
            using (ExtranetDB dbContext = new ExtranetDB())
            {
                string username = (from u in dbContext.Users
                                   where string.Compare(email, u.Email) == 0
                                   select u.Username).FirstOrDefault();

                return(!string.IsNullOrEmpty(username) ? username : string.Empty);
            }
        }
Ejemplo n.º 6
0
 //public ActionResult Download(string id)
 //{
 //    try
 //    {
 //        string filePath = id;
 //        filePath = filePath.Substring(5);
 //        filePath = filePath.Replace('/', '\\');
 //        // System.Diagnostics.Debugger.Break();
 //        //byte[] fileBytes = System.IO.File.ReadAllBytes(@"c:\folder\myfile.ext");
 //        byte[] fileBytes = System.IO.File.ReadAllBytes(@"C:\\inetpub\\wwwroot\\Condivisione\\" + filePath);
 //        string fileName = filePath.Substring(filePath.LastIndexOf('\\') + 1);
 //        return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
 //    }
 //    catch (System.Exception e)
 //    {
 //        Console.WriteLine(e.Message);
 //        return View();
 //    }
 //}
 public ActionResult FTPmain()
 {
     using (ExtranetDB dbContext = new ExtranetDB())
     {
         FTPabilitazioni utente = dbContext.FTPabilitazioni.Where(e => e.ftpUser == User.Identity.Name).FirstOrDefault();
         //ICollection<UserShares> test = dbContext.UserShares.Where(e => e.username == utente.ftpUser).ToList();
         //ICollection<UserShares> test2 = dbContext.UserShares.Where(e => e.username == User.Identity.Name).ToList();
         var bubu = utente.UserShares;
         var tt   = dbContext.Shares.Where(e => e.ShareID == 4).Select(e => e.UserShares).ToList();
         //var bubu7 = dbContext.UserShares.Where(e => e.username == "paolo.oliva").ToList();
         var yoghi = bubu.Select(e => e.Shares.SharePath).ToList();
     }
     return(View());
 }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <param name="userIsOnline"></param>
        /// <returns></returns>
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            CustomMembershipUser selectedUser = null;

            using (ExtranetDB dbContext = new ExtranetDB())
            {
                var user = (from us in dbContext.Users
                            where string.Compare(username, us.Username, StringComparison.OrdinalIgnoreCase) == 0
                            select us).FirstOrDefault();

                if (user != null)
                {
                    selectedUser = new CustomMembershipUser(user);
                }
            }
            if (selectedUser == null)
            {
                using (var context = new PrincipalContext(ContextType.Domain, "DELLORTO.IT"))
                {
                    var usr = UserPrincipal.FindByIdentity(context, username);
                    if (usr != null)
                    {
                        selectedUser = new CustomMembershipUser(usr);
                    }
                }
            }
            if (selectedUser == null)
            {
                using (var context = new PrincipalContext(ContextType.Domain, "INDIA"))
                {
                    var usr = UserPrincipal.FindByIdentity(context, username);
                    if (usr != null)
                    {
                        selectedUser = new CustomMembershipUser(usr);
                    }
                }
            }
            return(selectedUser);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public override string[] GetRolesForUser(string username)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(null);
            }

            var userRoles = new string[] { };

            using (ExtranetDB dbContext = new ExtranetDB())
            {
                var selectedUser = (from us in dbContext.Users.Include("Roles")
                                    where string.Compare(us.Username, username, StringComparison.OrdinalIgnoreCase) == 0
                                    select us).FirstOrDefault();


                if (selectedUser != null)
                {
                    userRoles = new[] { selectedUser.Roles.Select(r => r.RoleName).ToString() };
                }

                return(userRoles.ToArray());
            }
        }
Ejemplo n.º 9
0
        public object DirSearch(string sDir, List <FtpModel> nodes)
        {
            string ftpRoot         = "C:\\inetpub\\wwwroot\\FTP";
            string cartellaAttuale = "";

            if (ftpRoot != sDir)
            {
                cartellaAttuale = sDir.Substring(ftpRoot.Length + 1);
            }

            try
            {
                foreach (string d in Directory.GetDirectories(sDir))
                {
                    Boolean bCheck = true;

                    //string oldFolder = d;

                    DirectoryInfo nomeFolder = new DirectoryInfo(d);
                    if (sDir == ftpRoot)
                    {
                        bCheck = false;
                        //var user = (CustomMembershipUser)Membership.GetUser(LoginView.UserName, false);
                        var user = User.Identity.Name;
                        using (ExtranetDB dbContext = new ExtranetDB())
                        {
                            //var utente = dbContext.Users.Include("UserShares");
                            //FTPabilitazioni[] abilitazioni = dbContext.FTPabilitazioni.Include("UserShares").Where(e => e.ftpUser == User.Identity.Name && e.UserShares).FirstOrDefault();
                            UserShares abilitazioni = dbContext.UserShares.Where(e => e.username == User.Identity.Name && e.SharePath == nomeFolder.Name).FirstOrDefault();
                            if (abilitazioni != null)
                            {
                                bCheck = true;
                            }
                        }
                        if (bCheck == true)
                        {
                            nodes.Add(new FtpModel()
                            {
                                FileName = nomeFolder.Name, Folder = "#" /*nomeFolder.Parent.Name*/, Type = "Folder", LastEdit = nomeFolder.LastWriteTimeUtc.ToLocalTime().ToString(), Size = GetDirectorySize(nomeFolder.FullName).ToString() + "Kb"
                            });
                        }
                    }
                    else
                    {
                        nodes.Add(new FtpModel()
                        {
                            FileName = nomeFolder.Name, Folder = cartellaAttuale, Type = "Folder", LastEdit = nomeFolder.LastWriteTimeUtc.ToLocalTime().ToString(), Size = GetDirectorySize(nomeFolder.FullName).ToString() + "Kb"
                        });
                    }
                }
                if (cartellaAttuale != "")
                {
                    DirectoryInfo nomeFolder2 = new DirectoryInfo(sDir);
                    //var cartella = sDir.Substring(ftpRoot.Length+1);
                    foreach (var f in nomeFolder2.GetFiles())
                    {
                        nodes.Add(new FtpModel()
                        {
                            FileName = f.Name, Folder = cartellaAttuale, Type = f.Extension, LastEdit = f.LastWriteTimeUtc.ToLocalTime().ToString(), Size = f.Length.ToString() + "Kb"
                        });
                    }
                }
                return(Ok(""));
            }



            catch (System.Exception excpt)
            {
                Console.WriteLine(excpt.InnerException);
                return(InternalServerError(excpt.InnerException));
            }
        }
Ejemplo n.º 10
0
        [Route("api/file/upload/")]         //{username}")]
        public HttpResponseMessage Upload() //non più usata, ora è in FileController
        {
            HttpResponseMessage result = null;

            try
            {
                var httpRequest = HttpContext.Current.Request;
                var filecontent = httpRequest.Files[0];
                var sFolder     = httpRequest["PathToSave"].ToString().TrimEnd();

                string[] sDir   = sFolder.Split('\\');
                Boolean  bCheck = false;
                var      user   = User.Identity.Name;
                string   sRight = "R";
                using (ExtranetDB dbContext = new ExtranetDB())
                {
                    var sPathToCheck = sDir[0];
                    //var utente = dbContext.Users.Include("UserShares");
                    //FTPabilitazioni[] abilitazioni = dbContext.FTPabilitazioni.Include("UserShares").Where(e => e.ftpUser == User.Identity.Name && e.UserShares).FirstOrDefault();
                    UserShares abilitazioni = dbContext.UserShares.Where(e => e.username == User.Identity.Name && e.SharePath == sPathToCheck).FirstOrDefault();
                    if (abilitazioni != null)
                    {
                        sRight = abilitazioni.abilitazione;
                        bCheck = true;
                    }
                }

                if (bCheck == false || sRight == "R")
                {
                    result = Request.CreateResponse(HttpStatusCode.Forbidden, "Forbidden");
                    return(result);
                }

                // var a=httpRequest.Files["uFile"];
                if (httpRequest.Files.Count > 0)
                {
                    if (sFolder != "#" && sFolder != "FTP" && sFolder != "")
                    {
                        var docfiles = new List <string>();
                        foreach (string file in httpRequest.Files)
                        {
                            var postedFile = httpRequest.Files[file]; //FTPROOT
                            var filePath   = HostingEnvironment.MapPath("~/FTP") + '\\' + sFolder + '\\' + postedFile.FileName;
                            postedFile.SaveAs(filePath);
                            docfiles.Add(filePath);
                        }
                        result = Request.CreateResponse(HttpStatusCode.Created, docfiles);
                    }
                    else
                    {
                        result = Request.CreateResponse(HttpStatusCode.BadRequest, "Cannot upload in this folder");
                        return(result);
                    }
                }
                else
                {
                    result = Request.CreateResponse(HttpStatusCode.BadRequest, "File non allegato");
                }
                return(result);
            }

            catch (Exception e)
            {
                result = Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
            }
            return(result);
        }
Ejemplo n.º 11
0
        public HttpResponseMessage DownloadM(DownloadUrl t)
        {
            if (t == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            HttpResponseMessage result = null;

            try
            {
                var httpRequest = HttpContext.Current.Request;

                Boolean bCheck = false;
                var     user   = User.Identity.Name;
                string  sRight = "R";



                using (ZipFile zip = new ZipFile())
                {
                    zip.AlternateEncodingUsage = ZipOption.AsNecessary;
                    zip.AddDirectoryByName("Files");


                    foreach (var percorso in t.Urls)
                    {
                        bCheck = false;

                        //var user = User.Identity.Name;
                        using (ExtranetDB dbContext = new ExtranetDB())
                        {
                            var sPath        = percorso.Split('/');
                            var sPathToCheck = sPath[0];
                            //var utente = dbContext.Users.Include("UserShares");
                            //FTPabilitazioni[] abilitazioni = dbContext.FTPabilitazioni.Include("UserShares").Where(e => e.ftpUser == User.Identity.Name && e.UserShares).FirstOrDefault();
                            UserShares abilitazioni = dbContext.UserShares.Where(e => e.username == User.Identity.Name && e.SharePath == sPathToCheck).FirstOrDefault();
                            if (abilitazioni != null)
                            {
                                bCheck = true;
                            }
                        }
                        if (bCheck == false)
                        {
                            var resultB = new HttpResponseMessage(HttpStatusCode.BadRequest);
                            return(resultB);
                        }

                        var sPercorso = ftpRoot + "\\" + percorso;
                        sPercorso = sPercorso.Replace("/", "\\");
                        zip.AddFile(sPercorso.ToString(), "Files");
                    }
                    return(ZipContentResult(zip));
                }
            }

            catch (Exception e)
            {
                result = Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
            }
            return(result);
        }
Ejemplo n.º 12
0
        [Route("api/file/download/{sTipo}/{*sFile?}")]//{username}")]
        public HttpResponseMessage Download(string sTipo, string sFile)

        {
            try
            {
                sFile = sFile.Substring(0, sFile.Length - 1);
                string filePath = ftpRoot + "\\" + sFile + "." + sTipo;
                //filePath = filePath.Substring(5);
                filePath = filePath.Replace('/', '\\');

                string[] sFolder = sFile.Split('/');
                Boolean  bCheck  = false;
                var      user    = User.Identity.Name;
                using (ExtranetDB dbContext = new ExtranetDB())
                {
                    var sPathToCheck = sFolder[0];
                    //var utente = dbContext.Users.Include("UserShares");
                    //FTPabilitazioni[] abilitazioni = dbContext.FTPabilitazioni.Include("UserShares").Where(e => e.ftpUser == User.Identity.Name && e.UserShares).FirstOrDefault();
                    UserShares abilitazioni = dbContext.UserShares.Where(e => e.username == User.Identity.Name && e.SharePath == sPathToCheck).FirstOrDefault();
                    if (abilitazioni != null)
                    {
                        bCheck = true;
                    }
                }
                if (bCheck == false)
                {
                    //var resultB = new HttpResponseMessage(HttpStatusCode.BadRequest);
                    //resultB.ReasonPhrase = "Not permitted";
                    var resultB = Request.CreateResponse(HttpStatusCode.BadRequest, "Not allowed");

                    return(resultB);
                }
                var dataBytes = File.ReadAllBytes(filePath);
                var sName     = filePath.Split('\\').Last();
                HttpContext.Current.Response.BufferOutput = false;
                //adding bytes to memory stream
                var dataStream             = new MemoryStream(dataBytes);
                HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    //Content = new ByteArrayContent(dataStream.ToArray())
                    Content = new ByteArrayContent(dataStream.ToArray())
                };

                //.BufferOutput = false;

                result.Content.Headers.ContentDisposition =
                    new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
                {
                    FileName = sName
                };
                result.Content.Headers.ContentType =
                    new MediaTypeHeaderValue("application/octet-stream");


                return(result);
                // System.Diagnostics.Debugger.Break();
                //byte[] fileBytes = System.IO.File.ReadAllBytes(@"c:\folder\myfile.ext");
                //byte[] fileBytes = System.IO.File.ReadAllBytes(@"C:\\inetpub\\wwwroot\\Condivisione\\" + filePath);
                //string fileName = filePath.Substring(filePath.LastIndexOf('\\') + 1);
                //return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
                //var result = new HttpResponseMessage(HttpStatusCode.BadRequest);
                //result.ReasonPhrase = e.Message;
                var result = Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
                return(result);
            }
        }
Ejemplo n.º 13
0
        public object dirSearch(string sDir, int?idParent, List <JsTreeModel> nodes)
        {
            if (sDir.ToString() == null)
            {
                // sDir = "C:\\Users\\paolo.oliva\\source\\repos\\test root";
            }
            if (id.ToString() == "")
            {
                id = 1;
            }
            if (idParent.ToString() == "")
            {
                idParent = 0;
            }
            if (nodes.Count() == 0)
            {
                nodes = new List <JsTreeModel>();
            }
            try
            {
                foreach (string d in Directory.GetDirectories(sDir))
                {
                    Boolean       bCheck     = true;
                    string        oldFolder  = d;
                    DirectoryInfo nomeFolder = new DirectoryInfo(d);
                    if (idParent == 1)
                    {
                        bCheck = false;
                        //var user = (CustomMembershipUser)Membership.GetUser(LoginView.UserName, false);
                        var user = User.Identity.Name;
                        using (ExtranetDB dbContext = new ExtranetDB())
                        {
                            var selected = (from us in dbContext.Users.Include("Roles")
                                            where string.Compare(us.Username, user, StringComparison.OrdinalIgnoreCase) == 0
                                            select us).FirstOrDefault();
                            var yoghi = (from us in dbContext.Shares.Include("Roles") select us).FirstOrDefault();

                            var bubu = (from us in dbContext.Roles.Include("Shares") select us).FirstOrDefault();


                            var user2 = dbContext.Users.Include(us => us.Roles).Where(sh => sh.Username == user)
                                        .FirstOrDefault();
                            //.FirstOrDefault();
                            foreach (var ruolo in user2.Roles)
                            {
                                var condivisione = dbContext.Roles
                                                   .Include(sh => sh.Shares)
                                                   .Where(sh => sh.RoleId == ruolo.RoleId)
                                                   .FirstOrDefault();
                                //Console.WriteLine(condivisione.ToString());
                                foreach (var r in condivisione.Shares.Select(s => s.SharePath))
                                {
                                    if (r == nomeFolder.Name)
                                    {
                                        bCheck = true;
                                        break;
                                    }
                                }
                                //if(condivisione.Shares.Select( s => s.SharePath ).ToString() ==nomeFolder.Name)
                                //{
                                //    bCheck = true;
                                //}
                                //var condivisione2 = condivisione.Shares.Select(s => s.SharePath).Take(1);
                                if (bCheck == true)
                                {
                                    break;
                                }
                            }
                            // var test = User.IsInRole("India"); //  CustomRole.isShareForRoles(Membership.GetUser().ToString() , nomeFolder.ToString()).ToString();
                        }
                    }
                    int?oldId = idParent;
                    if (bCheck == true)
                    {
                        id++;
                        //if (idParent > 0) { idParent--; }
                        nodes.Add(new JsTreeModel()
                        {
                            id = id.ToString(), parent = idParent.ToString(), text = nomeFolder.Name
                        });
                        //int? oldId = idParent;
                        idParent = id;
                        //idParent++;
                        foreach (var f in nomeFolder.GetFiles())
                        {
                            string sIcon = "jstree-file";
                            id++;
                            nodes.Add(new JsTreeModel()
                            {
                                id = id.ToString(), parent = idParent.ToString(), text = f.Name, icon = sIcon
                            });
                        }
                    }
                    //}
                    dirSearch(d, idParent, nodes);
                    idParent = oldId;
                    //idParent-- ;
                    //id=oldId;
                }
            }
            catch (System.Exception excpt)
            {
                Console.WriteLine(excpt.Message);
            }
            //return Json(nodes, JsonRequestBehavior.AllowGet);
            return(nodes);
        }
Ejemplo n.º 14
0
        public ActionResult Download(string file)
        {
            var sFile = "";

            sFile = ftpRoot + "/" + System.Uri.UnescapeDataString(file);
            //string file = @"C:\inetpub\wwwroot\FTP\IDIADA\20190706 EPOLE ERIC GRANADO.mp4";
            //file = ftpRoot+"/" + System.Uri.UnescapeDataString(file);
            //var filePath = @"C:\inetpub\wwwroot\FTP\IDIADA\20190706 EPOLE ERIC GRANADO.mp4";
            //var filePath = ftpRoot + file;

            if (sFile == "")
            {
                Response.StatusCode        = 400;
                Response.StatusDescription = "File request error";
                Response.End();
                return(FTP());
            }


            sFile = file;
            //sFile = sFile.Substring(0, sFile.Length - 1);

            string filePath = sFile;

            //filePath = filePath.Substring(5);
            filePath = filePath.Replace('/', '\\');
            sFile    = sFile.Replace('/', '\\');
            string[] sFolder = sFile.Split('\\');


            Boolean bCheck = false;
            var     user   = User.Identity.Name;

            using (ExtranetDB dbContext = new ExtranetDB())
            {
                var sPathToCheck = sFolder[0];
                //var utente = dbContext.Users.Include("UserShares");
                //FTPabilitazioni[] abilitazioni = dbContext.FTPabilitazioni.Include("UserShares").Where(e => e.ftpUser == User.Identity.Name && e.UserShares).FirstOrDefault();
                UserShares abilitazioni = dbContext.UserShares.Where(e => e.username == User.Identity.Name && e.SharePath == sPathToCheck).FirstOrDefault();
                if (abilitazioni != null)
                {
                    bCheck = true;
                }
            }
            if (bCheck == false)
            {
                //var resultB = new HttpResponseMessage(HttpStatusCode.BadRequest);
                //resultB.ReasonPhrase = "Not permitted";
                Response.StatusCode        = 400;
                Response.StatusDescription = "File request error";
                Response.End();

                return(FTP());
                //return resultB;
            }

            filePath = ftpRoot + "\\" + filePath;

            FileInfo OutFile = new FileInfo(filePath);



            Response.Clear();
            Response.ContentType = "application/octet-stream";
            Response.Buffer      = false;

            Response.BufferOutput = false;
            //Response.AppendHeader("Content-Lenght", OutFile.Length.ToString());
            filePath = OutFile.FullName;
            string fileName = OutFile.Name;

            //filePath = @"C:\inetpub\wwwroot\FTP\IDIADA\20190706 EPOLE ERIC GRANADO.mp4";
            Response.AppendHeader("Content-Disposition", "filename=" + System.Uri.EscapeDataString(fileName));
            Response.TransmitFile(filePath, 0, OutFile.Length);


            Response.End();
            //return null;
            //return FTP();
            return(FTP());
        }
Ejemplo n.º 15
0
        [Route("/Files/MultiUpload/")]//{username}")]
        public string MultiUpload()
        {
            //HttpResponseMessage result = null;
            try
            {
                var httpRequest = HttpContext.Request;
                //var filecontent = httpRequest.Files[0];
                //var httpRequest = Request;
                //var filecontent = Request.Files[0];
                string filename = System.Uri.UnescapeDataString(Request.Headers["x-filename"].ToString().TrimEnd());

                var sFolder = System.Uri.UnescapeDataString(Request.Headers["PathToSave"].ToString().TrimEnd());

                string[] sDir   = sFolder.Split('\\');
                Boolean  bCheck = false;
                var      user   = User.Identity.Name;
                string   sRight = "R";
                using (ExtranetDB dbContext = new ExtranetDB())
                {
                    var        sPathToCheck = sDir[0];
                    UserShares abilitazioni = dbContext.UserShares.Where(e => e.username == User.Identity.Name && e.SharePath == sPathToCheck).FirstOrDefault();
                    if (abilitazioni != null)
                    {
                        sRight = abilitazioni.abilitazione;
                        bCheck = true;
                    }
                }

                if (bCheck == false || sRight == "R")
                {
                    //result = Request.CreateResponse(HttpStatusCode.Forbidden, "Forbidden");
                    return("Forbidden");
                }

                var chunks = Request.InputStream;

                string path = HostingEnvironment.MapPath("~/FTP/upload"); //test
                //var filePath = HostingEnvironment.MapPath("~/FTP")

                string nome = filename + ".tmp" + Request.Headers["completed"].ToString().TrimEnd().PadLeft(4, '0');

                //path = ftpRoot + '\\' + sFolder; //20190830: utilizzo cartella temp x upload
                path = ftpRoot + "\\UPLOAD";
                if (sFolder != "#" && sFolder != "FTP" && sFolder != "")
                {
                    string newpath = Path.Combine(path, nome);

                    using (System.IO.FileStream fs = System.IO.File.Create(newpath))
                    {
                        byte[] bytes = new byte[1024000];//[77570];

                        int bytesRead;
                        //var httpRequest = HttpContext.Request;
                        //var filecontent = httpRequest.Files[0];
                        while ((bytesRead = Request.InputStream.Read(bytes, 0, bytes.Length)) > 0)
                        {
                            fs.Write(bytes, 0, bytesRead);
                        }
                    }
                    return("test");
                }
                else
                {
                    return("Cannot upload in this folder");
                }
            }
            catch (Exception ex)
            {
                return("Error: " + ex.Message);
            }
        }