Пример #1
0
        string SavePostedFile(UploadedFile uploadedFile)
        {
            string logPath = "";

            //Mukund VSPLUS-1035, Changed path to save CSV from Settings default to VSWeb- LogFiles
            //if (!uploadedFile.IsValid)
            //   logPath = VSWebBL.SettingBL.SettingsBL.Ins.Getvalue("Log Files Path");
            //if (logPath == "")
            //{
            //    logPath = AppDomain.CurrentDomain.BaseDirectory.ToString();
            //}
            fileupld.SaveAs(Server.MapPath("~/LogFiles/" + uploadedFile.FileName));
            // fileupld.SaveAs(logPath + uploadedFile.FileName);
            //string fileName1 = Path.Combine(MapPath("~/log_files/") + uploadedFile.FileName);
            string fileName1 = Server.MapPath("~/LogFiles/" + uploadedFile.FileName);// Path.Combine(logPath + uploadedFile.FileName);
            //string filename2 = Path.GetFileName(uploadedFile.FileName);
            string fileExtension = Path.GetExtension(uploadedFile.FileName);

            //uploadedFile.SaveAs(Server.MapPath("~/log_files/" + filename2));
            //using (Image original = Image.FromStream(uploadedFile.FileContent))
            //using (Image thumbnail = PhotoUtils.Inscribe(original, 100))
            //{
            //    PhotoUtils.SaveToJpeg(thumbnail, fileName);
            //}
            if (fileExtension == ".csv")
            {
                // oledbcon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
                oledbcon.ConnectionString = ("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + System.IO.Path.GetDirectoryName(filename) + "; Extended Properties = \"Text;HDR=YES;FMT=Delimited\"");


                string     fileName = fileName1;
                DataTable  dt       = new DataTable();
                DataRow    dr;
                DataColumn column;
                string     s;
                column            = new DataColumn();
                column.DataType   = System.Type.GetType("System.String");
                column.ColumnName = "ServerName";
                dt.Columns.Add(column);
                column            = new DataColumn();
                column.DataType   = System.Type.GetType("System.String");
                column.ColumnName = "IPAddress";
                dt.Columns.Add(column);
                logPath = fileName;
                //ASPxLabel6.Text = "File uploaded successfully.";
                try
                {
                    DataTable LocationsDataTable = new DataTable();
                    LocationsDataTable = VSWebBL.SecurityBL.LocationsBL.Ins.GetAllData();
                    if (LocationsDataTable.Rows.Count > 0)
                    {
                        LocComboBox.DataSource = LocationsDataTable;
                        LocComboBox.TextField  = "Location";
                        LocComboBox.ValueField = "Location";
                        LocComboBox.DataBind();
                        LocIDComboBox.DataSource = LocationsDataTable;
                        LocIDComboBox.TextField  = "ID";
                        LocIDComboBox.ValueField = "ID";
                        LocIDComboBox.DataBind();
                    }
                    using (StreamReader sr = new StreamReader(logPath))
                    {
                        while (!sr.EndOfStream)
                        {
                            s  = sr.ReadLine();
                            dr = dt.NewRow();
                            //2/11/2016 Durga Added for VSPLUS 2432
                            DataTable serversdt = VSWebBL.SecurityBL.ServersBL.Ins.GetServerDetailsByName(s.ToString());
                            if (serversdt.Rows.Count == 0)
                            {
                                dr["IPAddress"]  = "dummyaddress.yourdomain.com";
                                dr["ServerName"] = s.ToString();
                                dt.Rows.Add(dr);
                            }
                        }

                        if (dt.Rows.Count > 0)
                        {
                            infoDiv.Style.Value        = "display: block";
                            SrvCheckBoxList.DataSource = dt;
                            SrvCheckBoxList.TextField  = "ServerName";
                            SrvCheckBoxList.ValueField = "ServerName";
                            SrvCheckBoxList.DataBind();
                            IPCheckBoxList.DataSource = dt;
                            IPCheckBoxList.TextField  = "IPAddress";
                            IPCheckBoxList.ValueField = "IPAddress";
                            IPCheckBoxList.DataBind();
                            //12/20/2013 NS added
                            ASPxRoundPanel1.Visible = true;
                        }
                        else
                        {
                            //10/6/2014 NS modified for VSPLUS-990
                            errorDiv.InnerHtml = "There are no new servers in the address book that have not already been imported into VitalSigns." +
                                                 "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>";
                            errorDiv.Style.Value = "display: block";
                        }
                        sr.Close();
                    }
                }
                catch (Exception ex)
                {
                    logPath  = System.Web.HttpContext.Current.Server.MapPath("~");
                    logPath += "\\" + fileName;
                    try
                    {
                        using (StreamReader sr = new StreamReader(logPath))
                        {
                            while (!sr.EndOfStream)
                            {
                                s  = sr.ReadLine();
                                dr = dt.NewRow();
                                dr["ServerName"] = s.ToString();
                                dr["IPAddress"]  = "dummyaddress.yourdomain.com";
                                dt.Rows.Add(dr);
                            }
                            if (dt.Rows.Count > 0)
                            {
                                infoDiv.Style.Value        = "display: block";
                                SrvCheckBoxList.DataSource = dt;
                                SrvCheckBoxList.TextField  = "ServerName";
                                SrvCheckBoxList.ValueField = "ServerName";
                                SrvCheckBoxList.DataBind();
                                IPCheckBoxList.DataSource = dt;
                                IPCheckBoxList.TextField  = "IPAddress";
                                IPCheckBoxList.ValueField = "IPAddress";
                                IPCheckBoxList.DataBind();
                                //12/20/2013 NS added
                                ASPxRoundPanel1.Visible = true;
                            }
                            else
                            {
                                //10/6/2014 NS modified for VSPLUS-990
                                errorDiv.InnerHtml = "There are no new servers in the address book that have not already been imported into VitalSigns." +
                                                     "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>";
                                errorDiv.Style.Value = "display: block";
                            }
                            sr.Close();
                        }
                    }
                    catch
                    {
                        //6/27/2014 NS added for VSPLUS-634
                        Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex);
                    }
                }
            }

            return(fileName1);
        }
Пример #2
0
        public void LoadDominoServers()
        {
            Domino.NotesDbDirectory dir;
            Domino.NotesDatabase    db;
            Domino.NotesView        view;
            Domino.NotesDocument    doc;
            Domino.NotesName        sname;
            Domino.NotesItem        item;
            Domino.NotesItem        item2;
            byte[] MyPass;
            string MyDominoPassword; //should be string
            string MyObjPwd;

            string[] MyObjPwdArr;
            //1/8/2014 NS added
            DataTable importedDT;
            //12/24/2013 NS added - store the value of the Domino Server field in the Settings table Primary Server column
            bool updatedsrv = false;

            updatedsrv = VSWebBL.SettingBL.SettingsBL.Ins.UpdateSvalue("Primary Server", DomServerTextBox.Text, VSWeb.Constants.Constants.SysString);
            //object MyObjPwd;
            //12/20/2013 NS added
            errorDiv.Style.Value = "display: none;";
            //8/12/2014 NS added for VSPLUS-861
            errorinfoDiv.Style.Value = "display: none";
            DataTable LocationsDataTable = new DataTable();

            LocationsDataTable = VSWebBL.SecurityBL.LocationsBL.Ins.GetAllData();
            if (LocationsDataTable.Rows.Count > 0)
            {
                LocComboBox.DataSource = LocationsDataTable;
                LocComboBox.TextField  = "Location";
                LocComboBox.ValueField = "Location";
                LocComboBox.DataBind();
                LocIDComboBox.DataSource = LocationsDataTable;
                LocIDComboBox.TextField  = "ID";
                LocIDComboBox.ValueField = "ID";
                LocIDComboBox.DataBind();
                VSFramework.TripleDES mySecrets = new VSFramework.TripleDES();
                try
                {
                    MyObjPwd = VSWebBL.SettingBL.SettingsBL.Ins.Getvalue("Password");
                    //3/25/2014 NS modified for VSPLUS-494
                    if (MyObjPwd != "")
                    {
                        MyObjPwdArr = MyObjPwd.Split(',');
                        MyPass      = new byte[MyObjPwdArr.Length];
                        for (int i = 0; i < MyObjPwdArr.Length; i++)
                        {
                            MyPass[i] = Byte.Parse(MyObjPwdArr[i]);
                        }
                    }
                    else
                    {
                        //10/6/2014 NS modified for VSPLUS-990
                        errorDiv.InnerHtml = "The following error has occurred: Notes password may not be empty. Please update the password under Stored Passwords & Options\\IBM Domino Settings." +
                                             "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>";
                        errorDiv.Style.Value = "display: block";
                        MyPass = null;
                    }
                }
                catch (Exception ex)
                {
                    //12/20/2013 NS added
                    //10/6/2014 NS modified for VSPLUS-990
                    errorDiv.InnerHtml = "The following error has occurred: " + ex.Message +
                                         "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>";
                    errorDiv.Style.Value = "display: block";
                    //8/12/2014 NS added for VSPLUS-861
                    errorinfoDiv.Style.Value = "display: block";
                    MyPass = null;
                    //5/15/2014 NS added for VSPLUS-634
                    Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex);
                    throw ex;
                }

                try
                {
                    if (MyPass != null)
                    {
                        MyDominoPassword = mySecrets.Decrypt(MyPass);
                    }
                    else
                    {
                        MyDominoPassword = null;
                    }
                }
                catch (Exception ex)
                {
                    //12/20/2013 NS added
                    //10/6/2014 NS modified for VSPLUS-990
                    errorDiv.InnerHtml = "The following error has occurred: " + ex.Message +
                                         "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>";
                    errorDiv.Style.Value = "display: block";
                    //8/12/2014 NS added for VSPLUS-861
                    errorinfoDiv.Style.Value = "display: block";
                    MyDominoPassword         = "";
                    //5/15/2014 NS added for VSPLUS-634
                    Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex);
                    throw ex;
                }
                //3/25/2014 NS modified for VSPLUS-494
                if (MyDominoPassword != null)
                {
                    try
                    {
                        Domino.NotesSession NotesSessionObject = new Domino.NotesSession();
                        NotesSessionObject.Initialize(MyDominoPassword);
                        dir = NotesSessionObject.GetDbDirectory(DomServerTextBox.Text);
                        //db = dir.GetFirstDatabase(Domino.DB_TYPES.NOTES_DATABASE);
                        db   = dir.OpenDatabase("names.nsf");
                        view = db.GetView("($Servers)");
                        doc  = view.GetFirstDocument();
                        DataTable dt = new DataTable();
                        DataRow   dr = dt.NewRow();
                        //1/8/2014 NS added
                        DataRow[] foundRows;
                        dt.Columns.Add("ServerName", typeof(string));
                        dt.Columns.Add("IPAddress", typeof(string));
                        //1/8/2014 NS added - get a list of all servers already imported. Display only the ones that have not yet been imported.
                        importedDT = VSWebBL.ConfiguratorBL.AlertsBL.Ins.GetServer();
                        while (doc != null)
                        {
                            item             = doc.GetFirstItem("ServerName");
                            sname            = NotesSessionObject.CreateName(item.Text);
                            dr["ServerName"] = sname.Abbreviated;
                            //1/8/2014 NS added
                            foundRows = importedDT.Select("ServerName = '" + sname.Abbreviated + "'");
                            if (foundRows.Length == 0)
                            {
                                //5/16/2013 NS modified
                                //item = doc.GetFirstItem("NetAddresses");
                                item            = doc.GetFirstItem("SMTPFullHostDomain");
                                dr["IPAddress"] = item.Text;
                                //2/5/2016 NS modified for VSPLUS-2068
                                if (item == null || item.Text == null || item.Text == "")
                                {
                                    //1/26/2016 NS modified for VSPLUS-2068
                                    item2           = doc.GetFirstItem("NetAddresses");
                                    dr["IPAddress"] = item2.Text;
                                    if (item2 == null || item2.Text == null || item2.Text == "")
                                    {
                                        dr["IPAddress"] = "dummyaddress.yourdomain.com";
                                    }
                                }
                                dt.Rows.Add(dr);
                                dr = dt.NewRow();
                            }
                            doc = view.GetNextDocument(doc);
                        }
                        //1/8/2014 NS modified
                        if (dt.Rows.Count > 0)
                        {
                            //1/8/2014 NS added
                            infoDiv.Style.Value        = "display: block";
                            SrvCheckBoxList.DataSource = dt;
                            SrvCheckBoxList.TextField  = "ServerName";
                            SrvCheckBoxList.ValueField = "ServerName";
                            SrvCheckBoxList.DataBind();
                            IPCheckBoxList.DataSource = dt;
                            IPCheckBoxList.TextField  = "IPAddress";
                            IPCheckBoxList.ValueField = "IPAddress";
                            IPCheckBoxList.DataBind();
                            //12/20/2013 NS added
                            ASPxRoundPanel1.Visible = true;
                        }
                        else
                        {
                            //10/6/2014 NS modified for VSPLUS-990
                            errorDiv.InnerHtml = "There are no new servers in the address book that have not already been imported into VitalSigns." +
                                                 "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>";
                            errorDiv.Style.Value = "display: block";
                        }
                    }
                    catch (Exception ex)
                    {
                        //12/20/2013 NS added
                        //10/6/2014 NS modified for VSPLUS-990
                        errorDiv.InnerHtml = "The following error has occurred: " + ex.Message +
                                             "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>";
                        errorDiv.Style.Value = "display: block";
                        //8/12/2014 NS added for VSPLUS-861
                        errorinfoDiv.Style.Value = "display: block";
                        db   = null;
                        dir  = null;
                        view = null;
                        doc  = null;
                        //5/15/2014 NS added for VSPLUS-634
                        Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex);
                    }
                }
            }
            //5/13/2014 NS added for VSPLUS-183
            else
            {
                //10/6/2014 NS modified for VSPLUS-990
                errorDiv.InnerHtml = "All imported servers must be assigned to a location. There were no locations found. Please create at least one location entry using the 'Setup & Security - Maintain Server Locations' menu option." +
                                     "<button type=\"button\" class=\"close\" data-dismiss=\"alert\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>";
                errorDiv.Style.Value = "display: block";
            }
        }
Пример #3
0
        public void LoadExchangeDAG()
        {
            if (ExchangeServerTextBox.Text.ToLower().Contains("http://") == false && ExchangeServerTextBox.Text.ToLower().Contains("https://") == false)
            {
                errorDiv.InnerHtml   = "Not a Valid Exchange Server Address!. Server Address shoud be in the form of 'https://myexchange.com'";
                errorDiv.Style.Value = "display: block";
                return;
            }

            DataTable dt       = new DataTable();
            string    strError = "";
            string    UserName = "";
            string    Password = "";

            if (CredentialsComboBox.Text != "")
            {
                ArrayList Cred = getCredentials();
                if (Cred.Count > 1)
                {
                    UserName = Cred[0].ToString();
                    Password = Cred[1].ToString();

                    if (UserName == "" || Password == "")
                    {
                        errorDiv.InnerHtml   = "User Id or Password not set for the selected Credentials";
                        errorDiv.Style.Value = "display: block";
                        return;
                    }
                }
            }
            else
            {
                UserName = UserIdtextBox.Text;                // "jnittech\\administrator";
                Password = PasswordTextbox.Text;              // "Pa$$w0rd";
                if (UserName == "" || Password == "")
                {
                    errorDiv.InnerHtml   = "Please Enter the User Id and Password.";
                    errorDiv.Style.Value = "display: block";
                    return;
                }
            }
            Uid = UserName;
            Pwd = Password;


            string IPAddress = ExchangeServerTextBox.Text;            // "https://jnittech-exchg1.jnittech.com";
            //ViewState["Pwd"] = Password;
            //ViewState.Add("Pwd", Password);
            bool updatedsrv = VSWebBL.SettingBL.SettingsBL.Ins.UpdateSvalue("Primary Exchange Server", ExchangeServerTextBox.Text, VSWeb.Constants.Constants.SysString);

            System.Uri uri = new Uri(IPAddress + "/powershell?serializationLevel=Full");
            System.Security.SecureString securePassword = String2SecureString(Password);
            PSCredential creds      = new PSCredential(UserName, securePassword);
            Runspace     runspace   = RunspaceFactory.CreateRunspace();
            PowerShell   powershell = PowerShell.Create();

            PSCommand command = new PSCommand();

            command.AddCommand("New-PSSession");
            command.AddParameter("ConfigurationName", "Microsoft.Exchange");
            command.AddParameter("ConnectionUri", uri);
            command.AddParameter("Credential", creds);
            command.AddParameter("Authentication", "Default");
            System.Collections.ObjectModel.Collection <PSObject> results = new System.Collections.ObjectModel.Collection <PSObject>();

            PSSessionOption sessionOption = new PSSessionOption();

            sessionOption.SkipCACheck         = true;
            sessionOption.SkipCNCheck         = true;
            sessionOption.SkipRevocationCheck = true;

            command.AddParameter("SessionOption", sessionOption);
            powershell.AddScript(@"set-executionpolicy unrestricted");
            powershell.Commands = command;

            try
            {
                using (runspace)
                {
                    runspace.Open();
                    powershell.Runspace = runspace;
                    System.Collections.ObjectModel.Collection <PSSession> result = powershell.Invoke <PSSession>();

                    //foreach (ErrorRecord current in powershell.Streams.Error)
                    //{
                    //    strError += "Exception Importing Servers: " + current.Exception.ToString() + ",\r\nInner Exception: " + current.Exception.InnerException;
                    //    errorDiv.InnerHtml = strError;
                    //    errorDiv.Style.Value = "display: block";
                    //    return;
                    //}

                    if (result.Count == 0)
                    {
                        //errorDiv.InnerHtml = "Unexpected number of Remote Runspace connections returned.";
                        //errorDiv.Style.Value = "display: block";
                        //return;
                        foreach (ErrorRecord current in powershell.Streams.Error)
                        {
                            strError            += "Exception Importing Servers: " + current.Exception.ToString() + ",\r\nInner Exception: " + current.Exception.InnerException;
                            errorDiv.InnerHtml   = strError;
                            errorDiv.Style.Value = "display: block";
                            return;
                        }
                    }
                    PSSession pssession = (PSSession)result[0];
                    command = new PSCommand();
                    command.AddCommand("Set-Variable");
                    command.AddParameter("Name", "ra");
                    command.AddParameter("Value", result[0]);
                    powershell.Commands = command;;
                    powershell.Invoke();


                    command = new PSCommand();
                    command.AddScript("Import-PSSession -Session $ra -CommandName Get-DatabaseAvailabilityGroup, Test-ReplicationHealth, Get-MailboxDatabase, Get-MailboxDatabaseCopyStatus");
                    powershell.Commands = command;
                    powershell.Invoke();

                    powershell.Streams.Error.Clear();

                    String str = "Get-DatabaseAvailabilityGroup | Select-Object -Property Name,WitnessServer";
                    powershell.AddScript(str);

                    results = powershell.Invoke();

                    dt.Columns.Add("DAGName", typeof(string));
                    dt.Columns.Add("WitnessServer", typeof(string));
                    if (results.Count > 0)
                    {
                        foreach (PSObject ps in results)
                        {
                            string Fqdn = ps.Properties["Name"].Value.ToString();
                            string name = ps.Properties["Name"].Value.ToString();
                            //load exchange servers
                            errorDiv.Style.Value     = "display: none;";
                            errorinfoDiv.Style.Value = "display: none";
                            DataTable LocationsDataTable = new DataTable();
                            LocationsDataTable = VSWebBL.SecurityBL.LocationsBL.Ins.GetAllData();
                            if (LocationsDataTable.Rows.Count > 0)
                            {
                                LocComboBox.DataSource = LocationsDataTable;
                                LocComboBox.TextField  = "Location";
                                LocComboBox.ValueField = "Location";
                                LocComboBox.DataBind();
                                LocIDComboBox.DataSource = LocationsDataTable;
                                LocIDComboBox.TextField  = "ID";
                                LocIDComboBox.ValueField = "ID";
                                LocIDComboBox.DataBind();

                                try
                                {
                                    DataRow[] foundRows;

                                    DataTable importedDT;
                                    importedDT = VSWebBL.ConfiguratorBL.AlertsBL.Ins.GetServer();
                                    foundRows  = importedDT.Select("ServerName = '" + name + "'");
                                    if (foundRows.Length == 0)
                                    {
                                        DataRow dr = dt.NewRow();
                                        dr["DAGName"]       = name;
                                        dr["WitnessServer"] = name;
                                        dt.Rows.Add(dr);
                                        dr = dt.NewRow();
                                    }
                                }
                                catch (Exception ex)
                                {
                                    errorDiv.InnerHtml       = "The following error has occurred: " + ex.Message;
                                    errorDiv.Style.Value     = "display: block";
                                    errorinfoDiv.Style.Value = "display: block";
                                    Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Exception - " + ex);
                                    return;
                                }
                            }
                            else
                            {
                                errorDiv.InnerHtml   = "All imported servers must be assigned to a location. There were no locations found. Please create at least one location entry using the 'Setup & Security - Maintain Server Locations' menu option.";
                                errorDiv.Style.Value = "display: block";
                                return;
                            }
                        }
                        results.Clear();
                        result.Clear();
                        if (dt.Rows.Count > 0)
                        {
                            infoDiv.Style.Value        = "display: block";
                            SrvCheckBoxList.DataSource = dt;
                            SrvCheckBoxList.TextField  = "DAGName";
                            SrvCheckBoxList.ValueField = "DAGName";
                            SrvCheckBoxList.DataBind();
                            IPCheckBoxList.DataSource = dt;
                            IPCheckBoxList.TextField  = "DAGName";
                            IPCheckBoxList.ValueField = "DAGName";
                            IPCheckBoxList.DataBind();
                            ASPxRoundPanel1.Visible = true;
                        }
                        else
                        {
                            errorDiv.InnerHtml   = "There are no new servers in the address book that have not already been imported into VitalSigns.";
                            errorDiv.Style.Value = "display: block";
                            return;
                        }
                        if (pssession != null)
                        {
                            Command cmd = new Command("remove-pssession");
                            cmd.Parameters.Add("id", pssession.Id);
                            powershell.Commands.Clear();
                            powershell.Commands.AddCommand(cmd);
                            powershell.Invoke();
                        }
                        if (runspace != null)
                        {
                            if (runspace.RunspaceStateInfo.State == RunspaceState.Opened)
                            {
                                runspace.Close();
                                runspace.Dispose();
                                powershell.Dispose();
                            }
                        }
                    }
                    else
                    {
                        errorDiv.InnerHtml   = "No Servers Found!.";
                        errorDiv.Style.Value = "display: block";
                        return;
                    }
                }
                GC.Collect();
            }
            catch (Exception ex)
            {
                errorDiv.InnerHtml   = ex.Message.ToString();
                errorDiv.Style.Value = "display: block";
                return;
            }
        }