/// <summary> /// Bind the Data to the Page. /// </summary> private void BindData() { try { ChangeEntryType changeEntryType = (ChangeEntryType)Enum.Parse(typeof(ChangeEntryType), type); switch (changeEntryType) { case ChangeEntryType.File: case ChangeEntryType.Directory: // entry iFolderEntry entry = web.GetEntry(ifolderID, itemID); ItemName.Text = entry.Path; break; case ChangeEntryType.Member: iFolderUser member = web.GetUser(itemID); ItemName.Text = member.FullName; break; } } catch (SoapException ex) { if (!HandleException(ex)) { throw; } } BindHistoryData(); }
/// <summary> /// Create Button Click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CreateButton_Click(object sender, EventArgs e) { string name = NewFolderName.Text.Trim(); // check for folder name if (name.Length == 0) { // no name Message.Text = GetString("ENTRY.NOFOLDERNAME"); return; } // create iFolderEntry entry = null; try { entry = web.CreateEntry(ifolderID, entryID, iFolderEntryType.Directory, name); // redirect Response.Redirect(String.Format("Browse.aspx?iFolder={0}&Entry={1}", entry.iFolderID, entry.ParentID)); } catch (SoapException ex) { if (!HandleException(ex)) { throw; } } }
/// <summary> /// Entry Path List Item Command Handler /// </summary> /// <param name="source"></param> /// <param name="e"></param> private void EntryPathList_ItemCommand(object source, RepeaterCommandEventArgs e) { string path = (e.CommandSource as LinkButton).CommandName; try { iFolderEntry entry = web.GetEntryByPath(ifolderID, path); Response.Redirect(String.Format("Browse.aspx?iFolder={0}&Entry={1}", ifolderID, entry.ID)); } catch (SoapException ex) { if (!HandleException(ex)) { throw; } } }
/// <summary> /// Process the Request /// </summary> /// <param name="context">The HttpContext object</param> public void ProcessRequest(HttpContext context) { Blowfish bf = null; int boundary = 0; int count = 0; long bytesWritten = 0; // query string ifolderID = context.Request.QueryString["iFolder"]; string entryID = context.Request.QueryString["Entry"]; try { // connection iFolderWeb web = (iFolderWeb)context.Session["Connection"]; if (web == null) { context.Response.Redirect("Login.aspx"); } iFolder ifolder = web.GetiFolder(ifolderID); // Check if the passphrase is valid or not... if (ifolder.EncryptionAlgorithm != null && ifolder.EncryptionAlgorithm != "") { //string PassPhrase = context.Request.QueryString["PassPhrase"]; string PassPhraseStr = (string)context.Session["SessionPassPhrase"]; Status ObjValidate = web.ValidatePassPhrase(PassPhraseStr); if (ObjValidate.statusCode != StatusCodes.Success) { String MessageString = GetString("PASSPHRASE_INCORRECT"); context.Session["SessionPassPhrase"] = null; context.Response.Redirect(String.Format("Browse.aspx?iFolder={0}&Message={1}", ifolderID, MessageString)); return; } } // request UriBuilder uri = new UriBuilder(web.Url); // Location of ifolder. string ifolderLocation = web.GetiFolderLocation(ifolderID); UriBuilder remoteurl = new UriBuilder(ifolderLocation); remoteurl.Path = (new Uri(web.Url)).PathAndQuery; web.Url = remoteurl.Uri.ToString(); uri.Path = String.Format("/simias10/Download.ashx?iFolder={0}&Entry={1}", ifolderID, entryID); WebRequest webRequest = (WebRequest)WebRequest.Create(uri.Uri); webRequest.Method = "GET"; webRequest.PreAuthenticate = true; webRequest.Credentials = web.Credentials; //webRequest.CookieContainer = web.CookieContainer; WebResponse webResponse = (WebResponse)webRequest.GetResponse(); Stream webStream = webResponse.GetResponseStream(); // filename string filename = webResponse.Headers["Content-Disposition"]; filename = filename.Substring(filename.IndexOf('=') + 1); // filename fix-up for Firefox and Safari if ((context.Request.UserAgent.IndexOf("Firefox") != -1) || (context.Request.UserAgent.IndexOf("Safari") != -1)) { filename = HttpUtility.UrlDecode(filename, System.Text.Encoding.UTF8); } // response // iFolder ifolder = web.GetiFolder(ifolderID); iFolderEntry nodeEntry = web.GetEntry(ifolderID, entryID); context.Response.Clear(); context.Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", filename)); //context.Response.AddHeader("Content-Length", webResponse.ContentLength.ToString()); context.Response.AddHeader("Content-Length", nodeEntry.Size.ToString()); //actual size (padd bytes discarded below) context.Response.ContentType = "application/octet-stream"; context.Response.BufferOutput = false; if (ifolder.EncryptionAlgorithm != null && ifolder.EncryptionAlgorithm != "") { //string PassPhrase = context.Request.QueryString["PassPhrase"]; string PassPhrase = (string)context.Session["SessionPassPhrase"]; // UTF8Encoding utf8 = new UTF8Encoding(); string DecryptedCryptoKey; //Hash the passphrase and use it for encryption and decryption PassphraseHash hash = new PassphraseHash(); byte[] passphrase = hash.HashPassPhrase(PassPhrase); Key key = new Key(ifolder.EncryptionKey); key.DecrypytKey(passphrase, out DecryptedCryptoKey); //Decrypt the key using passphrase and use it bf = new Blowfish(Convert.FromBase64String(DecryptedCryptoKey)); boundary = 8; } try { Stream output = context.Response.OutputStream; byte[] buffer = new byte[BUFFERSIZE]; while ((count = webStream.Read(buffer, 0, BUFFERSIZE)) > 0) { if (ifolder.EncryptionAlgorithm != null && ifolder.EncryptionAlgorithm != "") { bf.Decipher(buffer, count); if ((bytesWritten + count) > nodeEntry.Size) { count = count - (boundary - (int)(nodeEntry.Size % boundary)); } } output.Write(buffer, 0, count); bytesWritten += count; output.Flush(); } } finally { webStream.Close(); } } catch { throw; try{ ResourceManager rm = (ResourceManager)context.Application["RM"]; context.Server.Transfer(String.Format( "{0}&Message={1}", context.Request.UrlReferrer, context.Server.UrlEncode(WebUtility.GetString("ENTRY.FAILEDDOWNLOAD", rm)))); } catch { string RedirectToUrl = string.Format("Browse.aspx?iFolder={0}", ifolderID); context.Response.Redirect(RedirectToUrl); } } }