示例#1
0
		///<summary></summary>
		public static long Insert(CentralConnection centralConnection){
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){
				centralConnection.CentralConnectionNum=Meth.GetLong(MethodBase.GetCurrentMethod(),centralConnection);
				return centralConnection.CentralConnectionNum;
			}
			return Crud.CentralConnectionCrud.Insert(centralConnection);
		}
示例#2
0
		///<summary></summary>
		public static void Update(CentralConnection centralConnection){
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb){
				Meth.GetVoid(MethodBase.GetCurrentMethod(),centralConnection);
				return;
			}
			Crud.CentralConnectionCrud.Update(centralConnection);
		}
示例#3
0
        ///<summary>Initializes central connection store from a given xml file. Throws exceptions if file not found or init fails for any other reason.</summary>
        /// <typeparam name="FILETYPE">Must extend IConnectionFile. Instance will be created by deserializing the given xml file.</typeparam>
        /// <typeparam name="ITEMTYPE">The type of item defined by the given IConnectionFile type.</typeparam>
        /// <param name="fullPath">Full file path to the xml file.</param>
        /// <param name="fGetConnectionFromItem">Function that will take in an instance of ITEMTYPE and return an instance of CentralConnection.</param>
        private static Dictionary <ConnectionNames, OpenDentBusiness.CentralConnection> InitConnectionsFromXmlFile <FILETYPE, ITEMTYPE>(string fullPath, Func <ITEMTYPE, CentralConnection> fGetConnectionFromItem) where FILETYPE : IConnectionFile <ITEMTYPE>
        {
            if (HasAnyEntries)              //Prevent re-entry. Only want to run this once.
            {
                return(null);
            }
            if (!File.Exists(fullPath))
            {
                throw new Exception("ConnectionStore file not found: " + fullPath);
            }
            //Deserialize the file.
            FILETYPE fromFile;

            using (XmlReader reader = XmlReader.Create(fullPath)) {
                fromFile = (FILETYPE) new XmlSerializer(typeof(FILETYPE)).Deserialize(reader);
            }
            Dictionary <ConnectionNames, CentralConnection> ret = new Dictionary <ConnectionNames, CentralConnection>();

            //Loop through each item in the file and convert it to a CentralConnection.
            foreach (ITEMTYPE item in fromFile.Items)
            {
                CentralConnection centConnCur = fGetConnectionFromItem(item);
                ConnectionNames   connName;
                //Note field must deserialize to a ConnectionNames enum value.
                if (Enum.TryParse <ConnectionNames>(centConnCur.Note, out connName))
                {
                    ret[connName] = centConnCur;
                }
            }
            return(ret);
        }
		private void butAdd_Click(object sender,EventArgs e) {
			FormCentralConnectionEdit formC = new FormCentralConnectionEdit();
			CentralConnection cc=new CentralConnection();
			cc.IsNew=true;;
			formC.CentralConnectionCur=cc;
			formC.ShowDialog();
			FillGrid();
		}
示例#5
0
 ///<summary></summary>
 public static long Insert(CentralConnection centralConnection)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         centralConnection.CentralConnectionNum = Meth.GetLong(MethodBase.GetCurrentMethod(), centralConnection);
         return(centralConnection.CentralConnectionNum);
     }
     return(Crud.CentralConnectionCrud.Insert(centralConnection));
 }
示例#6
0
 ///<summary></summary>
 public static void Update(CentralConnection centralConnection)
 {
     if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
     {
         Meth.GetVoid(MethodBase.GetCurrentMethod(), centralConnection);
         return;
     }
     Crud.CentralConnectionCrud.Update(centralConnection);
 }
示例#7
0
		///<summary>Sets the connection of the current thread to the ConnectionName indicated. Connection details will be retrieved from ConnectionStore.xml.</summary>
		public static OpenDentBusiness.CentralConnection SetDb(ConnectionNames dbName) {
			CentralConnection conn=GetConnection(dbName);
			if(!string.IsNullOrEmpty(conn.ServiceURI)) {
				RemotingClient.ServerURI=conn.ServiceURI;
			}
			else {
				new DataConnection().SetDb(conn.ServerName,conn.DatabaseName,conn.MySqlUser,conn.MySqlPassword,"","",DatabaseType.MySql);
			}
			return conn;
		}
示例#8
0
 ///<summary>Overrides any current connection with the connection passed in.  This should rarely be used.  E.g. used in Unit Testing.</summary>
 public static void OverrideConnection(ConnectionNames name, CentralConnection centralConnection)
 {
     lock (_lock) {
         if (_dictCentConnUnsafe == null)
         {
             _dictCentConnUnsafe = new Dictionary <ConnectionNames, CentralConnection>();
         }
         _dictCentConnUnsafe[name] = centralConnection;
     }
 }
示例#9
0
		///<summary>Updates the current data connection settings of the central manager to the connection settings passed in.  Setting refreshCache to true will cause the entire local cache to get updated with the cache from the connection passed in if the new connection settings are successful.</summary>
		public static bool UpdateCentralConnection(CentralConnection centralConnection,bool refreshCache) {
			UTF8Encoding enc=new UTF8Encoding();
			byte[] EncryptionKey=enc.GetBytes("mQlEGebnokhGFEFV");//Gotten from FormCentralManager constructor. Only place that does anything like this.
			string webServiceURI="";
			string computerName="";
			string database="";
			string user="";
			string password="";
			string odPassword="";
			if(centralConnection.DatabaseName!="") {
				computerName=centralConnection.ServerName;
				database=centralConnection.DatabaseName;
				user=centralConnection.MySqlUser;
				if(centralConnection.MySqlPassword!="") {
					password=CentralConnections.Decrypt(centralConnection.MySqlPassword,EncryptionKey);
				}
				RemotingClient.ServerURI="";
			}
			else if(centralConnection.ServiceURI!="") {
				webServiceURI=centralConnection.ServiceURI;
				RemotingClient.ServerURI=webServiceURI;
				try {
					odPassword=CentralConnections.Decrypt(centralConnection.OdPassword,EncryptionKey);
					Security.CurUser=Security.LogInWeb(centralConnection.OdUser,odPassword,"",Application.ProductVersion,centralConnection.WebServiceIsEcw);
					Security.PasswordTyped=odPassword;
				}
				catch {
					return false;
				}
			}
			else {
				MessageBox.Show("Either a database or a Middle Tier URI must be specified in the connection.");
				return false;
			}
			try {
				if(RemotingClient.ServerURI!="") {
					RemotingClient.RemotingRole=RemotingRole.ClientWeb;
				}
				else {
					DataConnection.DBtype=DatabaseType.MySql;
					OpenDentBusiness.DataConnection dcon=new OpenDentBusiness.DataConnection();
					dcon.SetDb(computerName,database,user,password,"","",DataConnection.DBtype);
					RemotingClient.RemotingRole=RemotingRole.ClientDirect;
				}
				if(refreshCache) {
					Cache.RefreshCache(((int)InvalidType.AllLocal).ToString());
				}
			}
			catch {
				return false;
			}
			return true;
		}
示例#10
0
 ///<summary>Perform the given action in the context of the manual publisher db.
 ///Leave useConnectionStore false to use the ConnectionSettingsHQ preference or the sitelink override for ConnectionNames.ManualPublisher.</summary>
 public static void RunManualPublisherHQ(Action a, bool useConnectionStore = false)
 {
     if (useConnectionStore)
     {
         Run(a, ConnectionNames.ManualPublisher);
     }
     else
     {
         CentralConnection con = GetHqConnection(ConnectionNames.ManualPublisher);
         Run(a, con.ServerName, con.DatabaseName, con.MySqlUser, con.MySqlPassword, "", "");
     }
 }
示例#11
0
        ///<summary>Updates Status of the provided CentralConnection</summary>
        public static void UpdateStatus(CentralConnection centralConnection)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), centralConnection);
                return;
            }
            string command = "UPDATE centralconnection SET ConnectionStatus='" + POut.String(centralConnection.ConnectionStatus)
                             + "' WHERE CentralConnectionNum=" + POut.Long(centralConnection.CentralConnectionNum);

            Db.NonQ(command);
        }
示例#12
0
 ///<summary>Perform the given action in the context of the bugs db.
 ///Set useConnectionStore false to use the ConnectionSettingsHQ preference or the sitelink override for ConnectionNames.BugsHQ.</summary>
 public static void RunBugsHQ(Action a, bool useConnectionStore = true)
 {
     if (useConnectionStore)
     {
         Run(a, ConnectionNames.BugsHQ);
     }
     else
     {
         CentralConnection con = GetHqConnection(ConnectionNames.BugsHQ);
         Run(a, con.ServerName, con.DatabaseName, con.MySqlUser, con.MySqlPassword, "", "");
     }
 }
示例#13
0
        ///<summary>Supply a CentralConnection and this method will go through the logic to put together the connection string.</summary>
        public static string GetConnectionString(CentralConnection conn)
        {
            string connString = "";

            if (conn.DatabaseName != "")
            {
                connString  = conn.ServerName;
                connString += ", " + conn.DatabaseName;
            }
            else if (conn.ServiceURI != "")
            {
                connString = conn.ServiceURI;
            }
            return(connString);
        }
示例#14
0
 ///<summary></summary>
 public static string[] GetDatabases(CentralConnection centralConnection, DatabaseType dbType)
 {
     if (centralConnection.ServerName == "")
     {
         return(new string[0]);
     }
     if (dbType != DatabaseType.MySql)
     {
         return(new string[0]);               //because SHOW DATABASES won't work
     }
     try {
         DataConnection dcon;
         //use the one table that we know exists
         if (centralConnection.MySqlUser == "")
         {
             dcon = new DataConnection(centralConnection.ServerName, "mysql", "root", centralConnection.MySqlPassword, dbType);
         }
         else
         {
             dcon = new DataConnection(centralConnection.ServerName, "mysql", centralConnection.MySqlUser, centralConnection.MySqlPassword
                                       , dbType);
         }
         string command = "SHOW DATABASES";
         //if this next step fails, table will simply have 0 rows
         DataTable table   = dcon.GetTable(command, false);
         string[]  dbNames = new string[table.Rows.Count];
         for (int i = 0; i < table.Rows.Count; i++)
         {
             dbNames[i] = table.Rows[i][0].ToString();
         }
         return(dbNames);
     }
     catch (Exception) {
         return(new string[0]);
     }
 }
 ///<summary>Throws an exception to display to the user if anything goes wrong.</summary>
 public static void TryToConnect(CentralConnection centralConnection, DatabaseType dbType, string connectionString = "", bool noShowOnStartup = false,
                                 List <string> listAdminCompNames = null, bool isCommandLineArgs = false, bool useDynamicMode = false, bool allowAutoLogin = true)
 {
     if (!string.IsNullOrEmpty(centralConnection.ServiceURI))
     {
         LoadMiddleTierProxySettings();
         string originalURI = RemotingClient.ServerURI;
         RemotingClient.ServerURI = centralConnection.ServiceURI;
         bool         useEcwAlgorithm = centralConnection.WebServiceIsEcw;
         RemotingRole originalRole    = RemotingClient.RemotingRole;
         RemotingClient.RemotingRole = RemotingRole.ClientWeb;
         try {
             string password = centralConnection.OdPassword;
             if (useEcwAlgorithm)
             {
                 //It doesn't matter what Security.CurUser is when it is null because we are technically trying to set it for the first time.
                 //It cannot be null before invoking HashPassword for Middle Tier for creating credentials for DTOs.
                 if (Security.CurUser == null)
                 {
                     Security.CurUser = new Userod();
                 }
                 //Utilize the custom eCW MD5 hashing algorithm if no password hash was passed in via command line arguments.
                 if (string.IsNullOrEmpty(centralConnection.OdPassHash))
                 {
                     password = Authentication.HashPasswordMD5(password, true);
                 }
                 else                          //eCW gave us the password already hashed via command line arguments, simply use it.
                 {
                     password = centralConnection.OdPassHash;
                 }
             }
             string username = centralConnection.OdUser;
             //ecw requires hash, but non-ecw requires actual password
             Security.CurUser       = Security.LogInWeb(username, password, "", Application.ProductVersion, useEcwAlgorithm);
             Security.PasswordTyped = password;                  //for ecw, this is already encrypted.
             UserOdPrefs.SetThemeForUserIfNeeded();
         }
         catch (Exception ex) {
             RemotingClient.ServerURI    = originalURI;
             RemotingClient.RemotingRole = originalRole;
             throw ex;
         }
     }
     else
     {
         DataConnection.DBtype = dbType;
         DataConnection dcon = new DataConnection();
         if (connectionString.Length > 0)
         {
             dcon.SetDb(connectionString, "", DataConnection.DBtype);
         }
         else
         {
             //Password could be plain text password from the Password field of the config file, the decrypted password from the MySQLPassHash field
             //of the config file, or password entered by the user and can be blank (empty string) in all cases
             dcon.SetDb(centralConnection.ServerName, centralConnection.DatabaseName, centralConnection.MySqlUser
                        , centralConnection.MySqlPassword, "", "", DataConnection.DBtype);
         }
         //a direct connection does not utilize lower privileges.
         RemotingClient.RemotingRole = RemotingRole.ClientDirect;
     }
     //Only gets this far if we have successfully connected, thus, saving connection settings is appropriate.
     TrySaveConnectionSettings(centralConnection, dbType, connectionString, noShowOnStartup: noShowOnStartup, listAdminCompNames,
                               isCommandLineArgs: isCommandLineArgs, useDynamicMode: useDynamicMode, allowAutoLogin: allowAutoLogin);
 }
        ///<summary>Returns true if the connection settings were successfully saved to the FreeDentalConfig file and/or Windows PasswordVault.
        ///Otherwise, false.
        ///Set isCommandLineArgs to true in order to preserve settings within FreeDentalConfig.xml that are not command line args.
        ///E.g. the current value within the FreeDentalConfig.xml for NoShowOnStartup will be preserved instead of the value passed in.</summary>
        public static bool TrySaveConnectionSettings(CentralConnection centralConnection, DatabaseType dbType, string connectionString = ""
                                                     , bool noShowOnStartup = false, List <string> listAdminCompNames = null, bool isCommandLineArgs = false, bool useDynamicMode = false, bool allowAutoLogin = true)
        {
            try {
                //The parameters passed in might have misleading information (like noShowOnStartup) if they were comprised from command line arguments.
                //Non-command line settings within the FreeDentalConfig.xml need to be preserved when command line arguments are used.
                if (isCommandLineArgs)
                {
                    //Updating the freedentalconfig.xml file when connecting via command line arguments causes issues for users
                    //who prefer to have a desktop icon pointing to their main database and additional icons for other databases (popular amongst CEMT users).
                    return(false);

                    /**** The following code will be reintroduced in the near future.  Leaving as a comment on purpose. ****
                     * //Override all variables that are NOT valid command line arguments with their current values within the FreeDentalConfig.xml
                     * //This will preserve the values that should stay the same (e.g. noShowOnStartup is NOT a command line arg and will always be true).
                     * CentralConnection centralConnectionFile;
                     * string connectionStringFile;
                     * YN noShowFile;
                     * DatabaseType dbTypeFile;
                     * List<string> listAdminCompNamesFile;
                     * GetChooseDatabaseConnectionSettings(out centralConnectionFile,out connectionStringFile,out noShowFile,out dbTypeFile
                     *      ,out listAdminCompNamesFile,out useDynamicMode);
                     * //Since command line args are being used, override any variables that are NOT allowed to be passed in via the command line.
                     #region FreeDentalConfig Nodes That Do Not Have a Corresponding Command Line Arg
                     * switch(noShowFile) {//config node: <NoShowOnStartup>
                     *      case YN.Yes:
                     *              noShowOnStartup=true;
                     *              break;
                     *      case YN.No:
                     *      case YN.Unknown:
                     *              //Either NoShowOnStartup was not found or was explicitly set to no.
                     *              noShowOnStartup=false;
                     *              break;
                     * }
                     * listAdminCompNames=listAdminCompNamesFile;//config node: <AdminCompNames>
                     * connectionString=connectionStringFile;//config node: <ConnectionString>
                     * centralConnection.IsAutomaticLogin=centralConnectionFile.IsAutomaticLogin;//config node: <UsingAutoLogin>
                     #endregion
                     ********************************************************************************************************/
                }
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent      = true;
                settings.IndentChars = ("    ");
                using (XmlWriter writer = XmlWriter.Create(ODFileUtils.CombinePaths(Application.StartupPath, "FreeDentalConfig.xml"), settings)) {
                    writer.WriteStartElement("ConnectionSettings");
                    if (!allowAutoLogin)
                    {
                        //Only add if it was added before.
                        writer.WriteElementString("AllowAutoLogin", "False");
                    }
                    if (connectionString != "")
                    {
                        writer.WriteStartElement("ConnectionString");
                        writer.WriteString(connectionString);
                        writer.WriteEndElement();
                    }
                    else if (RemotingClient.RemotingRole == RemotingRole.ClientDirect)
                    {
                        writer.WriteStartElement("DatabaseConnection");
                        writer.WriteStartElement("ComputerName");
                        writer.WriteString(centralConnection.ServerName);
                        writer.WriteEndElement();
                        writer.WriteStartElement("Database");
                        writer.WriteString(centralConnection.DatabaseName);
                        writer.WriteEndElement();
                        writer.WriteStartElement("User");
                        writer.WriteString(centralConnection.MySqlUser);
                        writer.WriteEndElement();
                        string encryptedPwd;
                        CDT.Class1.Encrypt(centralConnection.MySqlPassword, out encryptedPwd);                       //sets encryptedPwd ot value or null
                        writer.WriteStartElement("Password");
                        //If encryption fails, write plain text password to xml file; maintains old behavior.
                        writer.WriteString(string.IsNullOrEmpty(encryptedPwd) ? centralConnection.MySqlPassword : "");
                        writer.WriteEndElement();
                        writer.WriteStartElement("MySQLPassHash");
                        writer.WriteString(encryptedPwd ?? "");
                        writer.WriteEndElement();
                        writer.WriteStartElement("NoShowOnStartup");
                        if (noShowOnStartup)
                        {
                            writer.WriteString("True");
                        }
                        else
                        {
                            writer.WriteString("False");
                        }
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }
                    else if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
                    {
                        writer.WriteStartElement("ServerConnection");
                        writer.WriteStartElement("URI");
                        writer.WriteString(centralConnection.ServiceURI);
                        writer.WriteEndElement();                        //end URI
                        if (centralConnection.IsAutomaticLogin)
                        {
                            writer.WriteStartElement("User");
                            writer.WriteString(centralConnection.OdUser);
                            writer.WriteEndElement();                            //end Username
                            writer.WriteStartElement("UsingAutoLogin");
                            writer.WriteString("True");
                            writer.WriteEndElement();                            //end UsingAutoLogin
                        }
                        writer.WriteStartElement("UsingEcw");
                        if (centralConnection.WebServiceIsEcw)
                        {
                            writer.WriteString("True");
                        }
                        else
                        {
                            writer.WriteString("False");
                        }
                        writer.WriteEndElement();                        //end UsingEcw
                        writer.WriteEndElement();                        //end ServerConnection
                    }
                    writer.WriteStartElement("DatabaseType");
                    if (dbType == DatabaseType.MySql)
                    {
                        writer.WriteString("MySql");
                    }
                    else
                    {
                        writer.WriteString("Oracle");
                    }
                    writer.WriteEndElement();
                    writer.WriteStartElement("UseDynamicMode");
                    writer.WriteString(useDynamicMode.ToString());
                    writer.WriteEndElement();
                    if (OpenDentBusiness.WebTypes.Shared.XWeb.XWebs.UseXWebTestGateway)
                    {
                        writer.WriteStartElement("UseXWebTestGateway");
                        writer.WriteString("True");
                        writer.WriteEndElement();
                    }
                    if (listAdminCompNames != null && listAdminCompNames.Count > 0)
                    {
                        writer.WriteStartElement("AdminCompNames");
                        foreach (string compName in listAdminCompNames)
                        {
                            writer.WriteStartElement("CompName");
                            writer.WriteString(compName);
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                    writer.Flush();
                }                //using writer
                //Input the user's credentials to WCM (Windows Credential Manager) if necessary.
                if (RemotingClient.RemotingRole == RemotingRole.ClientWeb &&
                    !string.IsNullOrWhiteSpace(centralConnection.ServiceURI) &&
                    centralConnection.IsAutomaticLogin)
                {
                    bool isCredentialSaveRequired = true;                                                            //Assume credentials are not saved yet.
                    if (PasswordVaultWrapper.TryRetrieveUserName(centralConnection.ServiceURI, out string userName)) //Found a saved OD MT UserName
                    //Update the credentials if the user or password is different.
                    {
                        if (centralConnection.OdUser != userName ||
                            PasswordVaultWrapper.RetrievePassword(centralConnection.ServiceURI, userName) != centralConnection.OdPassword)
                        {
                            //UserName or Password in the saved credentials does not match current password.  Delete the saved credentials and save the new
                            //credentials.  This will clear all the saved credentials from the PasswordVault for the currently logged in Windows User, which is
                            //desired behavior as each Windows User should only have one set of OpenDental Middle Tier credentials.
                            PasswordVaultWrapper.ClearCredentials(centralConnection.ServiceURI);
                        }
                        else
                        {
                            isCredentialSaveRequired = false;                          //Username and Password already saved and match current credentials.
                        }
                    }
                    if (isCredentialSaveRequired)
                    {
                        if (!string.IsNullOrWhiteSpace(centralConnection.OdUser) && !string.IsNullOrWhiteSpace(centralConnection.OdPassword))
                        {
                            //Save the new credentials.
                            PasswordVaultWrapper.WritePassword(centralConnection.ServiceURI, centralConnection.OdUser, centralConnection.OdPassword);
                        }
                        else
                        {
                            return(false);                           //Invalid username/password.
                        }
                    }
                }
            }
            catch (Exception ex) {
                ex.DoNothing();
                return(false);
            }
            return(true);
        }
示例#17
0
 ///<summary>Returns true if the connection settings were successfully saved to the FreeDentalConfig file.  Otherwise, false.</summary>
 public static bool TrySaveConnectionSettings(CentralConnection centralConnection, DatabaseType dbType, string connectionString = ""
                                              , bool noShowOnStartup = false, List <string> listAdminCompNames = null)
 {
     try {
         XmlWriterSettings settings = new XmlWriterSettings();
         settings.Indent      = true;
         settings.IndentChars = ("    ");
         using (XmlWriter writer = XmlWriter.Create(ODFileUtils.CombinePaths(Application.StartupPath, "FreeDentalConfig.xml"), settings)) {
             writer.WriteStartElement("ConnectionSettings");
             if (connectionString != "")
             {
                 writer.WriteStartElement("ConnectionString");
                 writer.WriteString(connectionString);
                 writer.WriteEndElement();
             }
             else if (RemotingClient.RemotingRole == RemotingRole.ClientDirect)
             {
                 writer.WriteStartElement("DatabaseConnection");
                 writer.WriteStartElement("ComputerName");
                 writer.WriteString(centralConnection.ServerName);
                 writer.WriteEndElement();
                 writer.WriteStartElement("Database");
                 writer.WriteString(centralConnection.DatabaseName);
                 writer.WriteEndElement();
                 writer.WriteStartElement("User");
                 writer.WriteString(centralConnection.MySqlUser);
                 writer.WriteEndElement();
                 string encryptedPwd;
                 CDT.Class1.Encrypt(centralConnection.MySqlPassword, out encryptedPwd);                       //sets encryptedPwd ot value or null
                 writer.WriteStartElement("Password");
                 //If encryption fails, write plain text password to xml file; maintains old behavior.
                 writer.WriteString(string.IsNullOrEmpty(encryptedPwd) ? centralConnection.MySqlPassword : "");
                 writer.WriteEndElement();
                 writer.WriteStartElement("MySQLPassHash");
                 writer.WriteString(encryptedPwd ?? "");
                 writer.WriteEndElement();
                 writer.WriteStartElement("NoShowOnStartup");
                 if (noShowOnStartup)
                 {
                     writer.WriteString("True");
                 }
                 else
                 {
                     writer.WriteString("False");
                 }
                 writer.WriteEndElement();
                 writer.WriteEndElement();
             }
             else if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
             {
                 writer.WriteStartElement("ServerConnection");
                 writer.WriteStartElement("URI");
                 writer.WriteString(centralConnection.ServiceURI);
                 writer.WriteEndElement();                        //end URI
                 if (centralConnection.IsAutomaticLogin)
                 {
                     writer.WriteStartElement("User");
                     writer.WriteString(centralConnection.OdUser);
                     writer.WriteEndElement();                            //end Username
                     writer.WriteStartElement("UsingAutoLogin");
                     writer.WriteString("True");
                     writer.WriteEndElement();                            //end UsingAutoLogin
                 }
                 writer.WriteStartElement("UsingEcw");
                 if (centralConnection.WebServiceIsEcw)
                 {
                     writer.WriteString("True");
                 }
                 else
                 {
                     writer.WriteString("False");
                 }
                 writer.WriteEndElement();                        //end UsingEcw
                 writer.WriteEndElement();                        //end ServerConnection
             }
             writer.WriteStartElement("DatabaseType");
             if (dbType == DatabaseType.MySql)
             {
                 writer.WriteString("MySql");
             }
             else
             {
                 writer.WriteString("Oracle");
             }
             writer.WriteEndElement();
             if (OpenDentBusiness.WebTypes.Shared.XWeb.XWebs.UseXWebTestGateway)
             {
                 writer.WriteStartElement("UseXWebTestGateway");
                 writer.WriteString("True");
                 writer.WriteEndElement();
             }
             if (listAdminCompNames != null && listAdminCompNames.Count > 0)
             {
                 writer.WriteStartElement("AdminCompNames");
                 foreach (string compName in listAdminCompNames)
                 {
                     writer.WriteStartElement("CompName");
                     writer.WriteString(compName);
                     writer.WriteEndElement();
                 }
                 writer.WriteEndElement();
             }
             writer.WriteEndElement();
             writer.Flush();
         }                                       //using writer
         if (centralConnection.IsAutomaticLogin) //Input the user's credentials to WCM (Windows Credential Manager)
         {
             PasswordVaultWrapper.WritePassword(centralConnection.ServiceURI, centralConnection.OdUser, centralConnection.OdPassword);
         }
     }
     catch (Exception) {
         return(false);
     }
     return(true);
 }
示例#18
0
        ///<summary>Gets all of the connection setting information from the FreeDentalConfig.xml
        ///Throws exceptions.</summary>
        public static void GetChooseDatabaseConnectionSettings(out CentralConnection centralConnection, out string connectionString, out YN noShow
                                                               , out DatabaseType dbType, out List <string> listAdminCompNames)
        {
            //No remoting role check; out parameters are used.
            centralConnection  = new CentralConnection();
            connectionString   = "";
            noShow             = YN.Unknown;
            dbType             = DatabaseType.MySql;
            listAdminCompNames = new List <string>();
            string xmlPath = ODFileUtils.CombinePaths(Application.StartupPath, "FreeDentalConfig.xml");

            #region Permission Check
            //Improvement should be made here to avoid requiring admin priv.
            //Search path should be something like this:
            //1. /home/username/.opendental/config.xml (or corresponding user path in Windows)
            //2. /etc/opendental/config.xml (or corresponding machine path in Windows) (should be default for new installs)
            //3. Application Directory/FreeDentalConfig.xml (read-only if user is not admin)
            if (!File.Exists(xmlPath))
            {
                FileStream fs;
                try {
                    fs = File.Create(xmlPath);
                }
                catch (Exception) {
                    //No translation right here because we typically do not have a database connection yet.
                    throw new ODException("The very first time that the program is run, it must be run as an Admin.  "
                                          + "If using Vista, right click, run as Admin.");
                }
                fs.Close();
            }
            #endregion
            XmlDocument document = new XmlDocument();
            try {
                document.Load(xmlPath);
                XPathNavigator Navigator = document.CreateNavigator();
                XPathNavigator nav;
                #region Nodes with No UI
                //Always look for these settings first in order to always preserve them correctly.
                nav = Navigator.SelectSingleNode("//AdminCompNames");
                if (nav != null)
                {
                    listAdminCompNames.Clear();                     //this method gets called more than once
                    XPathNodeIterator navIterator = nav.SelectChildren(XPathNodeType.All);
                    for (int i = 0; i < navIterator.Count; i++)
                    {
                        navIterator.MoveNext();
                        listAdminCompNames.Add(navIterator.Current.Value);                        //Add this computer name to the list.
                    }
                }
                //See if there's a UseXWebTestGateway
                nav = Navigator.SelectSingleNode("//UseXWebTestGateway");
                if (nav != null)
                {
                    OpenDentBusiness.WebTypes.Shared.XWeb.XWebs.UseXWebTestGateway = nav.Value.ToLower() == "true";
                }
                #endregion
                #region Nodes from Choose Database Window
                #region Nodes with No Group Box
                //Database Type
                nav    = Navigator.SelectSingleNode("//DatabaseType");
                dbType = DatabaseType.MySql;
                if (nav != null && nav.Value == "Oracle")
                {
                    dbType = DatabaseType.Oracle;
                }
                //ConnectionString
                nav = Navigator.SelectSingleNode("//ConnectionString");
                if (nav != null)
                {
                    //If there is a ConnectionString, then use it.
                    connectionString = nav.Value;
                }
                #endregion
                #region Connection Settings Group Box
                //See if there's a DatabaseConnection
                nav = Navigator.SelectSingleNode("//DatabaseConnection");
                if (nav != null)
                {
                    //If there is a DatabaseConnection, then use it.
                    centralConnection.ServerName    = nav.SelectSingleNode("ComputerName").Value;
                    centralConnection.DatabaseName  = nav.SelectSingleNode("Database").Value;
                    centralConnection.MySqlUser     = nav.SelectSingleNode("User").Value;
                    centralConnection.MySqlPassword = nav.SelectSingleNode("Password").Value;
                    XPathNavigator encryptedPwdNode = nav.SelectSingleNode("MySQLPassHash");
                    //If the Password node is empty, but there is a value in the MySQLPassHash node, decrypt the node value and use that instead
                    string _decryptedPwd;
                    if (centralConnection.MySqlPassword == "" &&
                        encryptedPwdNode != null &&
                        encryptedPwdNode.Value != "" &&
                        CDT.Class1.Decrypt(encryptedPwdNode.Value, out _decryptedPwd))
                    {
                        //decrypted value could be an empty string, which means they don't have a password set, so textPassword will be an empty string
                        centralConnection.MySqlPassword = _decryptedPwd;
                    }
                    XPathNavigator noshownav = nav.SelectSingleNode("NoShowOnStartup");
                    if (noshownav != null)
                    {
                        if (noshownav.Value == "True")
                        {
                            noShow = YN.Yes;
                        }
                        else
                        {
                            noShow = YN.No;
                        }
                    }
                }
                #endregion
                #region Connect to Middle Tier Group Box
                nav = Navigator.SelectSingleNode("//ServerConnection");

                /* example:
                 * <ServerConnection>
                 *      <URI>http://server/OpenDentalServer/ServiceMain.asmx</URI>
                 *      <UsingEcw>True</UsingEcw>
                 * </ServerConnection>
                 */
                if (nav != null)
                {
                    //If there is a ServerConnection, then use it.
                    centralConnection.ServiceURI = nav.SelectSingleNode("URI").Value;
                    XPathNavigator ecwnav = nav.SelectSingleNode("UsingEcw");
                    if (ecwnav != null && ecwnav.Value == "True")
                    {
                        noShow = YN.Yes;
                        centralConnection.WebServiceIsEcw = true;
                    }
                    XPathNavigator autoLoginNav = nav.SelectSingleNode("UsingAutoLogin");
                    //Auto login the user using their windows credentials
                    if (autoLoginNav != null && autoLoginNav.Value == "True")
                    {
                        centralConnection.OdUser = nav.SelectSingleNode("User").Value;
                        //Get the user's password from Windows Credential Manager
                        try {
                            centralConnection.OdPassword =
                                PasswordVaultWrapper.RetrievePassword(centralConnection.ServiceURI, centralConnection.OdUser);
                            //Must set this so FormChooseDatabase() does not launch
                            noShow = YN.Yes;
                            centralConnection.IsAutomaticLogin = true;
                        }
                        catch (Exception ex) {
                            ex.DoNothing();                            //We still want to display the server URI and the user name if getting the password fails.
                        }
                    }
                }
                #endregion
                #endregion
            }
            catch (Exception) {
                //Common error: root element is missing
                centralConnection.ServerName = "localhost";
#if (TRIALONLY)
                centralConnection.ServerName = "demo";
#else
                centralConnection.DatabaseName = "opendental";
#endif
                centralConnection.MySqlUser = "******";
            }
        }
示例#19
0
		private void butAdd_Click(object sender,EventArgs e) {
			CentralConnection conn=new CentralConnection();
			conn.IsNew=true;
			FormCentralConnectionEdit FormCCS=new FormCentralConnectionEdit();
			FormCCS.CentralConnectionCur=conn;
			FormCCS.ShowDialog();//Will insert conn on OK.
			FillGrid();//Refreshing the grid will show any new connections added.
		}
示例#20
0
        ///<summary>Perform the given action in the context of the webchat db.
        ///Uses the ConnectionSettingsHQ preference or the sitelink override for ConnectionNames.WebChat.</summary>
        public static void RunWebChat(Action a)
        {
            CentralConnection con = GetHqConnection(ConnectionNames.WebChat);

            Run(a, con.ServerName, con.DatabaseName, con.MySqlUser, con.MySqlPassword, "", "", DatabaseType.MySql);
        }
示例#21
0
		///<summary>Updates the current data connection settings of the central manager to the connection settings passed in.  Automatically refreshes the local cache to reflect the cache of the connection passed in.</summary>
		public static bool UpdateCentralConnection(CentralConnection centralConnection) {
			return UpdateCentralConnection(centralConnection,true);
		}
示例#22
0
        ///<summary>Returns true if the connection settings were successfully saved to the FreeDentalConfig file.  Otherwise, false.
        ///Set isCommandLineArgs to true in order to preserve settings within FreeDentalConfig.xml that are not command line args.
        ///E.g. the current value within the FreeDentalConfig.xml for NoShowOnStartup will be preserved instead of the value passed in.</summary>
        public static bool TrySaveConnectionSettings(CentralConnection centralConnection, DatabaseType dbType, string connectionString = ""
                                                     , bool noShowOnStartup = false, List <string> listAdminCompNames = null, bool isCommandLineArgs = false)
        {
            try {
                //The parameters passed in might have misleading information (like noShowOnStartup) if they were comprised from command line arguments.
                //Non-command line settings within the FreeDentalConfig.xml need to be preserved when command line arguments are used.
                if (isCommandLineArgs)
                {
                    //Override all variables that are NOT valid command line arguments with their current values within the FreeDentalConfig.xml
                    //This will preserve the values that should stay the same (e.g. noShowOnStartup is NOT a command line arg and will always be true).
                    CentralConnection centralConnectionFile;
                    string            connectionStringFile;
                    YN            noShowFile;
                    DatabaseType  dbTypeFile;
                    List <string> listAdminCompNamesFile;
                    GetChooseDatabaseConnectionSettings(out centralConnectionFile, out connectionStringFile, out noShowFile, out dbTypeFile
                                                        , out listAdminCompNamesFile);
                    //Since command line args are being used, override any variables that are NOT allowed to be passed in via the command line.
                    #region FreeDentalConfig Nodes That Do Not Have a Corresponding Command Line Arg
                    switch (noShowFile)                     //config node: <NoShowOnStartup>
                    {
                    case YN.Yes:
                        noShowOnStartup = true;
                        break;

                    case YN.No:
                    case YN.Unknown:
                        //Either NoShowOnStartup was not found or was explicitly set to no.
                        noShowOnStartup = false;
                        break;
                    }
                    listAdminCompNames = listAdminCompNamesFile;                                 //config node: <AdminCompNames>
                    connectionString   = connectionStringFile;                                   //config node: <ConnectionString>
                    centralConnection.IsAutomaticLogin = centralConnectionFile.IsAutomaticLogin; //config node: <UsingAutoLogin>
                    #endregion
                }
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent      = true;
                settings.IndentChars = ("    ");
                using (XmlWriter writer = XmlWriter.Create(ODFileUtils.CombinePaths(Application.StartupPath, "FreeDentalConfig.xml"), settings)) {
                    writer.WriteStartElement("ConnectionSettings");
                    if (connectionString != "")
                    {
                        writer.WriteStartElement("ConnectionString");
                        writer.WriteString(connectionString);
                        writer.WriteEndElement();
                    }
                    else if (RemotingClient.RemotingRole == RemotingRole.ClientDirect)
                    {
                        writer.WriteStartElement("DatabaseConnection");
                        writer.WriteStartElement("ComputerName");
                        writer.WriteString(centralConnection.ServerName);
                        writer.WriteEndElement();
                        writer.WriteStartElement("Database");
                        writer.WriteString(centralConnection.DatabaseName);
                        writer.WriteEndElement();
                        writer.WriteStartElement("User");
                        writer.WriteString(centralConnection.MySqlUser);
                        writer.WriteEndElement();
                        string encryptedPwd;
                        CDT.Class1.Encrypt(centralConnection.MySqlPassword, out encryptedPwd);                       //sets encryptedPwd ot value or null
                        writer.WriteStartElement("Password");
                        //If encryption fails, write plain text password to xml file; maintains old behavior.
                        writer.WriteString(string.IsNullOrEmpty(encryptedPwd) ? centralConnection.MySqlPassword : "");
                        writer.WriteEndElement();
                        writer.WriteStartElement("MySQLPassHash");
                        writer.WriteString(encryptedPwd ?? "");
                        writer.WriteEndElement();
                        writer.WriteStartElement("NoShowOnStartup");
                        if (noShowOnStartup)
                        {
                            writer.WriteString("True");
                        }
                        else
                        {
                            writer.WriteString("False");
                        }
                        writer.WriteEndElement();
                        writer.WriteEndElement();
                    }
                    else if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
                    {
                        writer.WriteStartElement("ServerConnection");
                        writer.WriteStartElement("URI");
                        writer.WriteString(centralConnection.ServiceURI);
                        writer.WriteEndElement();                        //end URI
                        if (centralConnection.IsAutomaticLogin)
                        {
                            writer.WriteStartElement("User");
                            writer.WriteString(centralConnection.OdUser);
                            writer.WriteEndElement();                            //end Username
                            writer.WriteStartElement("UsingAutoLogin");
                            writer.WriteString("True");
                            writer.WriteEndElement();                            //end UsingAutoLogin
                        }
                        writer.WriteStartElement("UsingEcw");
                        if (centralConnection.WebServiceIsEcw)
                        {
                            writer.WriteString("True");
                        }
                        else
                        {
                            writer.WriteString("False");
                        }
                        writer.WriteEndElement();                        //end UsingEcw
                        writer.WriteEndElement();                        //end ServerConnection
                    }
                    writer.WriteStartElement("DatabaseType");
                    if (dbType == DatabaseType.MySql)
                    {
                        writer.WriteString("MySql");
                    }
                    else
                    {
                        writer.WriteString("Oracle");
                    }
                    writer.WriteEndElement();
                    if (OpenDentBusiness.WebTypes.Shared.XWeb.XWebs.UseXWebTestGateway)
                    {
                        writer.WriteStartElement("UseXWebTestGateway");
                        writer.WriteString("True");
                        writer.WriteEndElement();
                    }
                    if (listAdminCompNames != null && listAdminCompNames.Count > 0)
                    {
                        writer.WriteStartElement("AdminCompNames");
                        foreach (string compName in listAdminCompNames)
                        {
                            writer.WriteStartElement("CompName");
                            writer.WriteString(compName);
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                    writer.Flush();
                }                                       //using writer
                if (centralConnection.IsAutomaticLogin) //Input the user's credentials to WCM (Windows Credential Manager)
                {
                    PasswordVaultWrapper.WritePassword(centralConnection.ServiceURI, centralConnection.OdUser, centralConnection.OdPassword);
                }
            }
            catch (Exception) {
                return(false);
            }
            return(true);
        }
示例#23
0
        ///<summary>Throws an exception to display to the user if anything goes wrong.</summary>
        public static void TryToConnect(CentralConnection centralConnection, DatabaseType dbType, string connectionString = "", bool noShowOnStartup = false
                                        , List <string> listAdminCompNames = null, bool isCommandLineArgs = false)
        {
            if (!string.IsNullOrEmpty(centralConnection.ServiceURI))
            {
                LoadMiddleTierProxySettings();
                string originalURI = RemotingClient.ServerURI;
                RemotingClient.ServerURI = centralConnection.ServiceURI;
                bool         useEcwAlgorithm = centralConnection.WebServiceIsEcw;
                RemotingRole originalRole    = RemotingClient.RemotingRole;
                RemotingClient.RemotingRole = RemotingRole.ClientWeb;
                try {
                    string password = centralConnection.OdPassword;
                    if (useEcwAlgorithm)
                    {
                        //Userods.HashPassword explicitly goes over to middle tier in order to use it's MD5 algorithm.
                        //It doesn't matter what Security.CurUser is when it is null because we are technically trying to set it for the first time.
                        //It cannot be null before invoking HashPassword because middle needs it to NOT be null when creating the credentials for DtoGetString.
                        if (Security.CurUser == null)
                        {
                            Security.CurUser = new Userod();
                        }
                        password = Userods.HashPassword(password, true);
                    }
                    string username = centralConnection.OdUser;
#if DEBUG
                    if (username == "")
                    {
                        username = "******";
                        password = "******";
                    }
#endif
                    //ecw requires hash, but non-ecw requires actual password
                    Security.CurUser       = Security.LogInWeb(username, password, "", Application.ProductVersion, useEcwAlgorithm);
                    Security.PasswordTyped = password;                  //for ecw, this is already encrypted.
                }
                catch (Exception ex) {
                    RemotingClient.ServerURI    = originalURI;
                    RemotingClient.RemotingRole = originalRole;
                    throw ex;
                }
            }
            else
            {
                DataConnection.DBtype = dbType;
                DataConnection dcon = new DataConnection();
                if (connectionString.Length > 0)
                {
                    dcon.SetDb(connectionString, "", DataConnection.DBtype);
                }
                else
                {
                    //Password could be plain text password from the Password field of the config file, the decrypted password from the MySQLPassHash field
                    //of the config file, or password entered by the user and can be blank (empty string) in all cases
                    dcon.SetDb(centralConnection.ServerName, centralConnection.DatabaseName, centralConnection.MySqlUser
                               , centralConnection.MySqlPassword, "", "", DataConnection.DBtype);
                }
                //a direct connection does not utilize lower privileges.
                RemotingClient.RemotingRole = RemotingRole.ClientDirect;
            }
            TrySaveConnectionSettings(centralConnection, dbType, connectionString, noShowOnStartup, listAdminCompNames, isCommandLineArgs);
        }