protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetNoStore();

            userid = Convert.ToString(Session["userid"]);
            utype  = Convert.ToString(Session["utype"]);

            if (userid == "undefined" && utype != "user")
            {
                Response.Redirect("Invalid.aspx");
            }
        }
        catch (Exception ex) { }

        try
        {
            int docid = Convert.ToInt32(Request.QueryString["docid"]);


            GetDocumentDetails dtl = new GetDocumentDetails(docid);

            string docname  = dtl.DocFileName;
            string docowner = dtl.DocOwner;

            string filePath = Server.MapPath("UserDocs/") + docowner + "/";


            string newpath = "/UserDocs/" + docowner;

            BackupHost info       = new BackupHost();
            string     remotepath = "http://" + info.StorageHostName + ":" + info.StorageHostPort + newpath;
            string     backuppath = "http://" + info.BackupHostName + ":" + info.BackupHostPort + newpath;

            if (FileToDownload(remotepath, docname, filePath, docowner))
            {
                Global.DocDownloadPath = "UserDocs/" + docowner + "/" + docname;
                // Response.Write(Global.DocDownloadPath);
                Panel1.Visible = true;
                Panel2.Visible = false;

                string      userid = Convert.ToString(Session["userid"]);
                RecordUsage rec    = new RecordUsage();
                rec.record(userid, "download");
                rec.record(userid, "decryption");
            }
            else if (FileToDownload(backuppath, docname, filePath, docowner))
            {
                //Global.DocDownloadPath = filePath  + docname;
                Global.DocDownloadPath = "UserDocs/" + docowner + "/" + docname;
                // Response.Write(Global.DocDownloadPath);
                Panel1.Visible = true;
                Panel2.Visible = false;

                string      userid = Convert.ToString(Session["userid"]);
                RecordUsage rec    = new RecordUsage();
                rec.record(userid, "download");
                rec.record(userid, "decryption");
                rec.record(userid, "recovery");
            }
            else
            {
                Panel1.Visible = false;
                Panel2.Visible = true;
            }

            // else recover the file from backup server
            // calculate its hash after decryption and allow it to download
        }
        catch (Exception ex) { }
    }
    protected void Process(object source, DataListCommandEventArgs e)
    {
        int docid = 0;

        try
        {
            string commandname = e.CommandName.ToString();
            docid = Convert.ToInt32(Convert.ToString(e.CommandArgument));

            if (commandname == "download")
            {
                value = 2;
            }
            if (commandname == "askkey")
            {
                string           userid = Convert.ToString(Session["userid"]);
                GetClientDetails cdtl   = new GetClientDetails(userid);
                string           name   = cdtl.ClientName;
                string           email  = cdtl.ClientEmailId;

                DocKeysGenerator gen = new DocKeysGenerator();
                gen.GetDocUserKey(docid);
                string seckey = gen.DocUserKey;

                GetDocumentDetails dtl      = new GetDocumentDetails(docid);
                string             doctitle = dtl.DocTitle;
                string             docowner = dtl.DocOwner;
                string             size     = dtl.DocSize + " bytes";

                EmailService mail = new EmailService();
                mail.sendSecKey(email, seckey, name, doctitle, docowner, size);

                value = 1;

                RecordUsage rec = new RecordUsage();
                rec.record(userid, "askkey");
            }
        }
        catch (Exception ex)
        {
            value = 0;
        }

        if (value == 2)
        {
            Response.Redirect("SecKeyAuthentication.aspx?docid=" + docid);
        }

        else if (value == 1)
        {
            message = "Secrete key generated successfully. Key is sent on your registered emailid.";
            title   = "Success Report";
        }
        else if (value == 0)
        {
            message = "Sorry.!! Secrete key generation failed.. Try again..";
            title   = "Failure Report";
        }

        string script = "window.onload = function(){ alert('";

        script += message;
        script += "')};";
        ClientScript.RegisterStartupScript(this.GetType(), title, script, true);
    }
Exemple #3
0
    protected void Process(object source, DataListCommandEventArgs e)
    {
        int docid = 0;

        try
        {
            string commandname = e.CommandName.ToString();
            docid = Convert.ToInt32(Convert.ToString(e.CommandArgument));

            if (commandname == "download")
            {
                value = 2;
            }
            else if (commandname == "permission")
            {
                value = 3;
            }
            else if (commandname == "viewpermissions")
            {
                value = 4;
            }
            else if (commandname == "delete")
            {
                GetDocumentDetails dtl = new GetDocumentDetails(docid);

                // delete meta file
                string metafilePath = Server.MapPath("UserDocs/") + userid + "/" + dtl.DocHashFile;;

                try
                {
                    if (File.Exists(metafilePath))
                    {
                        FileStream fs = new FileStream(metafilePath, FileMode.Open, FileAccess.Read, FileShare.None);
                        fs.Close();
                        File.Delete(metafilePath);
                    }
                }
                catch (Exception ex) { }

                if (obj.DeleteDoc(docid))
                {
                    value = 1;
                }
                else
                {
                    value = 0;
                }
            }
        }
        catch (Exception ex)
        {
            value = 0;
        }


        if (value == 1)
        {
            message = "File removed successfully..";
            title   = "Success Report";

            string script = "window.onload = function(){ alert('";
            script += message;
            script += "')};";
            ClientScript.RegisterStartupScript(this.GetType(), title, script, true);
        }
        else if (value == 0)
        {
            message = "Sorry.!! File processing failed.. Try again..";
            title   = "Failure Report";

            string script = "window.onload = function(){ alert('";
            script += message;
            script += "')};";
            ClientScript.RegisterStartupScript(this.GetType(), title, script, true);
        }
        else if (value == 2)
        {
            Response.Redirect("SecKeyAuthentication.aspx?docid=" + docid);
        }
        else if (value == 3)
        {
            Response.Redirect("AllotFilePermissions.aspx?docid=" + docid);
        }
        else if (value == 4)
        {
            Response.Redirect("ViewPermissions.aspx?docid=" + docid);
        }
    }