Esempio n. 1
0
        public string SharePackage(string sender, string[] recipients, string packageCode, string[] tokens, string subject, string message)
        {
            Console.WriteLine("Sharing package from " + sender + " for package " + packageCode + " containing " + tokens.Length + " files");
            log.InfoFormat("Sharing package from \"{0}\"", sender);

            Package package = new Package() {
                Code = packageCode,
                SenderMail = sender,
                Message = subject + "\n" + message,
                Status = (char)PackageStatus.Open,
                Scanned = false,
                ExpiresAt = DateTime.UtcNow.AddDays(14),
                CreatedAt = DateTime.UtcNow
            };

            using (DataClassesDataContext db = new DataClassesDataContext()) {
                foreach (string fileHash in tokens) {
                    File f = new File() {
                        CreatedAt = DateTime.UtcNow,
                        FileHash = fileHash,
                        FileSize = 0/*Storage.GetFileSize(package.Code, fileHash)*/,
                        Package = package,
                    };
                    db.Files.InsertOnSubmit(f);
                }

                db.SubmitChanges();
            }

            string response = TransmitSettings.Instance.Setting.OutlookInjectedHtml ?? "Download: [TransmitUrl]/receive.aspx?h=[Package.Code]";
            response = response.Replace("[Package.Code]", packageCode);
            response = response.Replace("[TransmitUrl]", TransmitSettings.Instance.Setting.ExternalUrl);
            return response;
        }
Esempio n. 2
0
        public void ProcessRequest(HttpContext context)
        {
            try {
                //log.DebugFormat("Start processing request from {0} with a content-length of {1}", HttpContext.Current.Request.UserHostAddress, context.Request.Headers["Content-Length"]);

                JumploaderWrapper.FileSystemFileSaver save = new JumploaderWrapper.FileSystemFileSaver(context, Commanigy.Transmit.Data.TransmitSettings.Instance.Setting.StorageLocation);
                JumploaderWrapper.MultUploadHandler handle = new JumploaderWrapper.MultUploadHandler(save);
                handle.FileSaved += new JumploaderWrapper.MFileEventHandler(delegate(object sender, JumploaderWrapper.FileSavedEventArgs args) {
                    log.DebugFormat("Client {0} successfully stored \"{3}\" ({1}kB) for token \"{2}\"", HttpContext.Current.Request.UserHostAddress, Math.Ceiling(int.Parse(context.Request.Headers["Content-Length"]) / 1024f), context.Request["token"], args.FileName);

                    using (DataClassesDataContext db = new DataClassesDataContext()) {
                        Package package = db.Packages.SingleOrDefault(p => p.Code == context.Request["token"]);
                        if (package == null) {
                            // create package if it doesn't already exists
                            package = new Package() {
                                Code = context.Request["token"],
                                SenderMail = "Unspecified",
                                Status = (char)PackageStatus.Open,
                                Scanned = false,
                                ExpiresAt = DateTime.Now.AddDays(14),
                                CreatedAt = DateTime.UtcNow
                            };
                        }

                        Commanigy.Transmit.Data.File file = package.Files.Where(f => f.FileHash == args.FileName).FirstOrDefault();
                        if (file == null) {
                            db.Files.InsertOnSubmit(new Commanigy.Transmit.Data.File() {
                                CreatedAt = DateTime.UtcNow,
                                FileHash = args.FileName,
                                FileSize = int.Parse(context.Request.Headers["Content-Length"]),
                                Package = package
                            });
                        }
                        else {
                            file.FileSize += int.Parse(context.Request.Headers["Content-Length"]);
                        }

                        db.SubmitChanges();
                    }
                });
                handle.ProcessRequest(context);
            }
            catch (Exception x) {
                log.Error("Failed to store received file", x);
                throw x;
            }
        }
Esempio n. 3
0
        public static bool Scan(Package package)
        {
            //Process si = new Process();
            ////si.StartInfo.WorkingDirectory = "c:\\";
            //si.StartInfo.UseShellExecute = false;
            //si.StartInfo.FileName = "cmd.exe";
            //si.StartInfo.Arguments = "/C dir";
            //si.StartInfo.CreateNoWindow = true;
            //si.StartInfo.RedirectStandardInput = true;
            //si.StartInfo.RedirectStandardOutput = true;
            //si.StartInfo.RedirectStandardError = true;
            //si.Start();
            //string output = si.StandardOutput.ReadToEnd();
            //si.Close();

            //return output;
            return true;
        }
Esempio n. 4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnShare_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request["Recipients[]"])) {
                ValidationError.Display(_("No recipients specified"));
            }

            if (string.IsNullOrEmpty(Request["Files[]"])) {
                ValidationError.Display(_("No files uploaded"));
            }

            if (!Page.IsValid) {
                ValidationSummary.HeaderText = _("Please correct the following:");
                return;
            }

            using (DataClassesDataContext db = new DataClassesDataContext()) {
                Package p = db.Packages.SingleOrDefault(pkg => pkg.Code == HfToken.Value);
                if (p == null) {
                    // FIXME: this "if" section should be removed once Flash code has been updated to files immediately as well
                    p = new Package() {
                        Code = HfToken.Value,
                        SenderMail = this.CurrentUser.Mail,
                        Message = TbxMessage.Text,
                        Status = (char)PackageStatus.Open,
                        Scanned = false,
                        ExpiresAt = DateTime.Now.AddDays(14),
                        CreatedAt = DateTime.UtcNow
                    };

                    string[] fileHashes = Request["Files[]"].Split(',');

                    foreach (string fileHash in fileHashes) {
                        db.Files.InsertOnSubmit(new File() {
                            CreatedAt = DateTime.UtcNow,
                            FileHash = fileHash,
                            FileSize = Storage.GetFileSize(p.Code, fileHash),
                            Package = p,
                        });
                    }
                }
                else {
                    p.SenderMail = this.CurrentUser.Mail;
                    p.Message = TbxMessage.Text;
                }

                db.SubmitChanges();
            }

            // get fresh copy of package
            Package package = Package.FindByCode(HfToken.Value);

            string[] recipients = Request["Recipients[]"].Split(',');

            log.DebugFormat("Packing files into ZIP archive {0} for faster (initial) downloads by clients", package.Code);
            new Thread(new ParameterizedThreadStart(delegate(object data) {
                Package uploadedPackage = data as Package;
                Storage.Pack(uploadedPackage.Code);

                ScanPackage(uploadedPackage);

                NotifyRecipients(uploadedPackage, recipients);
            })).Start(package);

            log.DebugFormat("User {0} completed sharing", this.CurrentUser);
            this.Response.Redirect("~/share.success.aspx", true);
        }
Esempio n. 5
0
 private void ScanPackage(Package package)
 {
     using (DataClassesDataContext db = new DataClassesDataContext()) {
         package.Scanned = PackageHelper.Scan(package);
         db.SubmitChanges();
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Notify all recipients about new, shared downloadable package.
        /// </summary>
        /// <param name="package">Recently uploaded package</param>
        /// <param name="recipients">An array of recipient emails</param>
        private void NotifyRecipients(Package package, string[] recipients)
        {
            log.DebugFormat("User {0} is dispatching share emails to {1} recipients", this.CurrentUser, recipients.Length);
            using (DataClassesDataContext db = new DataClassesDataContext()) {
                foreach (string recipientEmail in recipients) {
                    NotifyRecipient(package, this.CurrentUser.Mail, this.CurrentUser.DisplayName, recipientEmail, TbxMessage.Text);

                    Transfer t = new Transfer() {
                        CreatedAt = DateTime.UtcNow,
                        PackageID = package.ID,
                        RecipientMail = recipientEmail
                    };
                    db.Transfers.InsertOnSubmit(t);
                }
                db.SubmitChanges();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="fromAddress"></param>
        /// <param name="fromDisplayName"></param>
        /// <param name="toAddress"></param>
        private void NotifyRecipient(Package package, string fromAddress, string fromDisplayName, string toAddress, string message)
        {
            if (string.IsNullOrEmpty(message)) {
                message = string.Empty;
            }

            log.DebugFormat("Sending notification from {0} ({1}) to {2}", fromAddress, fromDisplayName, toAddress);

            // try to look up recipient in local store (LDAP server)
            AuthenticatedUser recipientUser = Locator.FindByMail(toAddress);

            Dictionary<string, string> tokens = new Dictionary<string, string>();
            tokens.Add("CompanyName", TransmitSettings.Instance.Setting.CompanyName);
            tokens.Add("Sender.Mail", fromAddress);
            tokens.Add("Sender.DisplayName", fromDisplayName);
            tokens.Add("Recipient.Mail", toAddress);
            tokens.Add("Recipient.DisplayName", (recipientUser != null) ? recipientUser.DisplayName : toAddress);
            tokens.Add("Package.Code", package.Code);
            tokens.Add("Package.Files", PackageHelper.FilesToMailHtml(package.Files.ToList()));
            tokens.Add("Package.Files.Count", package.Files.Count.ToString());
            tokens.Add("Mail.Message", message);
            tokens.Add("File.Location", string.Format("{0}/receive.aspx?h={1}", UserHelper.GetSiteUrl(recipientUser), package.Code));

            MailHelper.Send(TransmitSettings.Instance.Setting.ShareMailSubject, TransmitSettings.Instance.Setting.ShareMailBodyPlain, TransmitSettings.Instance.Setting.ShareMailBodyHtml, tokens);
        }
Esempio n. 8
0
        protected void BtnShare_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request["Files[]"])) {
                ValidationError.Display(_("No files uploaded"));
            }

            if (!Page.IsValid) {
                (this.Master as SiteMasterPage).Flash(_("You did not provide files to share"));
                return;
            }

            string[] fileHashes = Request["Files[]"].Split(',');

            using (DataClassesDataContext db = new DataClassesDataContext()) {
                Package p = db.Packages.SingleOrDefault(pkg => pkg.Code == HfToken.Value);
                if (p == null) {
                    // FIXME: this "if" section should be removed once Flash code has been updated to files immediately as well
                    p = new Package() {
                        Code = HfToken.Value,
                        SenderMail = this.Invitation.RecipientMail,
                        Message = TbxMessage.Text,
                        Status = (char)PackageStatus.Open,
                        Scanned = false,
                        ExpiresAt = DateTime.Now.AddDays(14),
                        CreatedAt = DateTime.UtcNow
                    };

                    foreach (string fileHash in fileHashes) {
                        Commanigy.Transmit.Data.File f = new Commanigy.Transmit.Data.File() {
                            CreatedAt = DateTime.UtcNow,
                            FileHash = fileHash,
                            FileSize = Storage.GetFileSize(p.Code, fileHash),
                            Package = p,
                        };
                        db.Files.InsertOnSubmit(f);
                    }
                }
                else {
                    p.SenderMail = this.Invitation.RecipientMail;
                    p.Message = TbxMessage.Text;
                }

                db.SubmitChanges();
            }

            // get fresh copy of package
            Package package = Package.FindByCode(HfToken.Value);

            log.Debug("Packing files into ZIP archive for faster (initial) downloads by clients");
            new Thread(new ParameterizedThreadStart(delegate(object data) {
                Package uploadedPackage = data as Package;
                Storage.Pack(uploadedPackage.Code);
            })).Start(package);

            // generate unique token allowing recipient (requester) to download file
            string uniqueHash = package.Code;

            // look up user requesting files (this should always resolve to a user) unless that
            // user has been disabled before file has been uploaded
            AuthenticatedUser recipientUser = Locator.FindByMail(this.Invitation.SenderMail);

            Dictionary<string, string> tokens = new Dictionary<string, string>();
            tokens.Add("CompanyName", TransmitSettings.Instance.Setting.CompanyName);
            tokens.Add("Sender.Mail", this.Invitation.RecipientMail);
            tokens.Add("Sender.DisplayName", this.Invitation.RecipientDisplayName);
            tokens.Add("Recipient.Mail", this.Invitation.SenderMail);
            tokens.Add("Recipient.DisplayName", (recipientUser != null) ? recipientUser.DisplayName : this.Invitation.SenderDisplayName);
            tokens.Add("Mail.Message", TbxMessage.Text ?? string.Empty);
            tokens.Add("Package.Code", package.Code);
            tokens.Add("Package.Files", PackageHelper.FilesToMailHtml(package.Files.ToList()));
            tokens.Add("File.Location", string.Format("{0}/receive.aspx?h={1}", UserHelper.GetSiteUrl(recipientUser), uniqueHash));

            MailHelper.Send(TransmitSettings.Instance.Setting.UploadMailSubject, TransmitSettings.Instance.Setting.UploadMailBodyPlain, TransmitSettings.Instance.Setting.UploadMailBodyHtml, tokens);

            this.Response.Redirect("~/upload.success.aspx", true);
        }
Esempio n. 9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            //log.DebugFormat("User {0} is requesting page '{1}' at {2}", this.CurrentUser, Page.Title, Page.Request.Path);

            string uniqueHash = Request["h"]; // package.code
            if (string.IsNullOrEmpty(uniqueHash)) {
                throw new HttpException(404, "Package hash not specified");
            }

            package = Package.FindByCode(uniqueHash);
            if (package == null) {
                throw new HttpException(404, "Package " + uniqueHash + " not found");
            }

            if (!Page.IsPostBack) {
                ImgSharedBy.Attributes["onerror"] = "null;this.src='images/no-user-picture.png'";
                ImgSharedBy.Attributes["onload"] = "this.style.backgroundImage='none'";

                AuthenticatedUser senderUser = Locator.FindByMail(package.SenderMail);
                if (senderUser != null) {
                    ImgSharedBy.ImageUrl = "Pictures.ashx?p=images/no-user-picture.png&u=" + Server.UrlEncode(senderUser.Url);
                    ImgSharedBy.ToolTip = string.Format("Avatar for {0}", senderUser.DisplayName);
                    LblSender.Text = senderUser.DisplayName;
                }
                else {
                    ImgSharedBy.ImageUrl = "images/no-user-picture.png";
                    ImgSharedBy.ToolTip = "";
                    LblSender.Text = package.SenderMail;
                }
                LblMessage.Text = package.Message.Replace("\n", "<br />");

                DlFiles.DataSource = package.Files;
                DlFiles.DataBind();
            }
        }
Esempio n. 10
0
 partial void DeletePackage(Package instance);
Esempio n. 11
0
 partial void UpdatePackage(Package instance);
Esempio n. 12
0
 partial void InsertPackage(Package instance);
Esempio n. 13
0
        private Package LoadPackage(string code)
        {
            Package package;

            using (DataClassesDataContext db = new DataClassesDataContext()) {
                package = db.Packages.SingleOrDefault(p => p.Code == code);
                if (package == null) {
                    return null;
                }

                package.Files.Load();
                package.Transfers.Load();
            }

            return package;
        }
Esempio n. 14
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            //log.DebugFormat("User {0} is requesting page '{1}' at {2}", this.CurrentUser, Page.Title, Page.Request.Path);

            string uniqueHash = Request["h"]; // package.code
            if (string.IsNullOrEmpty(uniqueHash)) {
                throw new HttpException(404, "Package hash not specified in request");
            }

            this.package = LoadPackage(uniqueHash);
            if (this.package == null || this.package.SenderMail != this.CurrentUser.Mail) {
                throw new HttpException(404, "Package '" + uniqueHash + "' not found or you do not have access to it.");
            }

            if (!Page.IsPostBack) {
                LblMessage.Text = package.Message.Replace("\n", "<br />");

            //				List<FileInfo> files = Storage.GetFiles(package.Code).ToList<FileInfo>();

                DlFiles.DataSource = package.Files;
                DlFiles.DataBind();

                SharedTo.DataSource = package.Transfers;
                SharedTo.DataBind();
            }
        }