Ejemplo n.º 1
0
        /// <summary>
        /// Verifies if the password entered is correct
        /// </summary>
        /// <param name="pIsLocalConnection">Local connection flag</param>
        /// <param name="pUsername">Username</param>
        /// <param name="pPassword">Password</param>
        /// <param name="pUserID">Returns the user-ID</param>
        /// <param name="pDBData">DB connection data</param>
        /// <returns>True if the authentication was successfull</returns>
        public static bool VerifyPassword(bool pIsLocalConnection, string pUsername, string pPassword, out string pUserID, WrapMySQLData pDBData)
        {
            pUserID = "";

            bool passwordValid = false;

            if (pIsLocalConnection)
            {
                bool errorEncountered = false;
                using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile))
                {
                    try
                    {
                        if (!QDLib.ManagedDBOpen(sqlite))
                        {
                            QDLib.DBOpenFailed(); return(false);
                        }
                        string dbUsername = sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DefaultUsername);
                        string dbCipher   = sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DefaultPassword);
                        sqlite.Close();

                        string pwDecrypt = Cipher.Decrypt(dbCipher, QDInfo.LocalCipherKey);
                        if (dbUsername == pUsername && pwDecrypt == pPassword)
                        {
                            passwordValid = true;
                        }
                    }
                    catch
                    {
                        errorEncountered = true;
                    }
                }

                if (errorEncountered)
                {
                    MessageBox.Show("An error occured whilst trying to authenticate the user.", "Authentication error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                using (WrapMySQL mysql = new WrapMySQL(pDBData))
                {
                    if (!QDLib.ManagedDBOpen(mysql))
                    {
                        QDLib.DBOpenFailed(); return(false);
                    }
                    using (MySqlDataReader reader = (MySqlDataReader)mysql.ExecuteQuery("SELECT * FROM qd_users WHERE Username = ? AND Password = ?", pUsername, QDLib.HashPassword(pPassword)))
                    {
                        while (reader.Read())
                        {
                            pUserID       = Convert.ToString(reader["ID"]);
                            passwordValid = true;
                        }
                    }
                    mysql.Close();
                }
            }

            return(passwordValid);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if the database has already been configured by Q-Drive
        /// </summary>
        /// <returns>True if the DB is already configured</returns>
        public static bool IsQDConfigured()
        {
            if (File.Exists(QDInfo.ConfigFile))
            {
                try
                {
                    using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile))
                    {
                        object result = sqlite.ExecuteScalarACon("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.SetupSuccess);

                        if (result != null && Convert.ToBoolean(Convert.ToInt16(result)))
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                catch
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        private void LoadAllData()
        {
            try
            {
                using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile))
                {
                    if (!QDLib.ManagedDBOpen(sqlite))
                    {
                        QDLib.DBOpenFailed(); return;
                    }

                    bool localConnection = !Convert.ToBoolean(sqlite.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.IsOnlineLinked));

                    sqlite.Close();

                    if (localConnection)
                    {
                        pnlLocal.BringToFront();
                        return;
                    }

                    if (!QDLib.ManagedDBOpen(sqlite))
                    {
                        QDLib.DBOpenFailed(); return;
                    }
                    dbData.Hostname = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBHost), QDInfo.LocalCipherKey);
                    dbData.Username = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBUsername), QDInfo.LocalCipherKey);
                    dbData.Password = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBPassword), QDInfo.LocalCipherKey);
                    dbData.Database = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBName), QDInfo.LocalCipherKey);
                    sqlite.Close();
                }

                mysql = new WrapMySQL(dbData);

                if (!QDLib.ManagedDBOpen(mysql))
                {
                    QDLib.DBOpenFailed(); return;
                }
                userCanToggleKeepLoggedIn    = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UserCanToggleKeepLoggedIn));
                userCanAddPrivateDrive       = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UserCanAddPrivateDrive));
                userCanAddPublicDrive        = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UserCanAddPublicDrive));
                userCanSelfRegister          = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UserCanSelfRegister));
                useLoginAsDriveAuth          = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UseLoginAsDriveAuthentication));
                forceLoginDriveAuth          = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.ForceLoginAsDriveAuthentication));
                disconnectDrivesAtShutdown   = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.DisconnectDrivesAtShutdown));
                logUserActions               = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.LogUserActions));
                userCanChangeManagerSettings = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.UserCanChangeManagerSettings));
                defaultDomain  = mysql.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.DefaultDomain);
                masterPassword = mysql.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.MasterPassword);
                mysql.Close();
            }
            catch
            {
                MessageBox.Show("An error occured whilst trying to connect to the online-database.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }
        private void UpdateEntries_Load(object sender, EventArgs e)
        {
            sql = new WrapSQLite(SurgitManager.SurgitDatabaseLocation, true);

            // Ping all devices in Network Range
            ipStartParts = IPStartRange.Split('.');
            ipEndParts   = IPEndRange.Split('.');

            pgbProgress.Minimum = Convert.ToInt32(ipStartParts[3]);
            pgbProgress.Maximum = Convert.ToInt32(ipEndParts[3]);

            pgbProgress.Value = pgbProgress.Minimum;

            if (!bgwUpdateEntries.IsBusy)
            {
                bgwUpdateEntries.RunWorkerAsync();
            }
        }
Ejemplo n.º 5
0
        private bool SaveChanges()
        {
            QDLoader qdLoader = new QDLoader();

            qdLoader.Show();

            bool successOnline = false;
            bool successLocal  = false;

            if (!QDLib.ManagedDBOpen(mysql))
            {
                QDLib.DBOpenFailed(); return(false);
            }
            mysql.TransactionBegin();
            try
            {
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUserCanToggleKeepLoggedIn.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UserCanToggleKeepLoggedIn);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUserCanSelfRegister.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UserCanSelfRegister);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUserCanAddPublicDrives.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UserCanAddPublicDrive);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUserCanAddPrivateDrives.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UserCanAddPrivateDrive);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUseLoginAsDriveAuthentication.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UseLoginAsDriveAuthentication);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglForceLoginAsDriveAuthentication.ToggleState == ToggleButtonState.Active, QDInfo.DBO.ForceLoginAsDriveAuthentication);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglDisconnectDrivesAtShutdown.ToggleState == ToggleButtonState.Active, QDInfo.DBO.DisconnectDrivesAtShutdown);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglLogUserActions.ToggleState == ToggleButtonState.Active, QDInfo.DBO.LogUserActions);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", tglUserCanChangeManagerSettings.ToggleState == ToggleButtonState.Active, QDInfo.DBO.UserCanChangeManagerSettings);
                mysql.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", txbDefaultDomain.Text, QDInfo.DBO.DefaultDomain);

                mysql.TransactionCommit();
                successOnline = true;
            }
            catch
            {
                mysql.TransactionRollback();
            }

            mysql.Close();

            WrapMySQLData newDBConnection = new WrapMySQLData()
            {
                Hostname = txbDBHostname.Text,
                Database = txbDBDatabase.Text,
                Username = txbDBUsername.Text,
                Password = txbDBPassword.Text,
                Pooling  = false
            };

            using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile))
            {
                if (QDLib.TestConnection(newDBConnection, false))
                {
                    if (!QDLib.ManagedDBOpen(sqlite))
                    {
                        QDLib.DBOpenFailed(); return(false);
                    }
                    sqlite.TransactionBegin();

                    try
                    {
                        sqlite.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", Cipher.Encrypt(newDBConnection.Hostname, QDInfo.LocalCipherKey), QDInfo.DBL.DBHost);
                        sqlite.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", Cipher.Encrypt(newDBConnection.Database, QDInfo.LocalCipherKey), QDInfo.DBL.DBName);
                        sqlite.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", Cipher.Encrypt(newDBConnection.Username, QDInfo.LocalCipherKey), QDInfo.DBL.DBUsername);
                        sqlite.ExecuteNonQuery("UPDATE qd_info SET QDValue = ? WHERE QDKey = ?", Cipher.Encrypt(newDBConnection.Password, QDInfo.LocalCipherKey), QDInfo.DBL.DBPassword);

                        sqlite.TransactionCommit();
                        successLocal = true;
                    }
                    catch
                    {
                        sqlite.TransactionRollback();
                    }

                    sqlite.Close();
                }
            }

            if (!successOnline || !successLocal)
            {
                if (MessageBox.Show("Could not save the changes made. Please check your MySQL-Connection and try again. \r\n\r\nDo you want to close the admin-console anyway?", "Could not save settins", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    successOnline = true;
                }
            }

            qdLoader.Close();

            return(successOnline && successLocal);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Connect to all Network drives of a specified QD-User
        /// </summary>
        /// <param name="pUserID">User-ID of the user</param>
        /// <param name="pUserPassword">User-password</param>
        /// <param name="pDBData">DB connection data</param>
        /// <param name="pLogUserData">Log user data</param>
        /// <param name="pDisconnectFirst">Disconnect all drives before reconecting</param>
        /// <param name="drives">Drive-List</param>
        /// <param name="ConnectOnlyIfNotAvailable">Only reconnect to a drive if it isn't already connected</param>
        /// <returns></returns>
        public static int ConnectQDDrives(string pUserID, string pUserPassword, WrapMySQLData pDBData, bool pLogUserData, bool pDisconnectFirst = true, List <DriveViewItem> drives = null, bool ConnectOnlyIfNotAvailable = false)
        {
            int connectCtr = 0;

            // Disconnect all current drives
            if (pDisconnectFirst)
            {
                DisconnectAllDrives(drives);
                if (!string.IsNullOrEmpty(pUserID))
                {
                    LogUserConnection(pUserID, QDLogAction.QDDrivesDisconnect, pDBData, pLogUserData);
                }
            }

            // Connect online-drives (online-synced)
            if (!string.IsNullOrEmpty(pUserID))
            {
                try
                {
                    using (WrapMySQL sql = new WrapMySQL(pDBData))
                    {
                        if (!QDLib.ManagedDBOpen(sql))
                        {
                            QDLib.DBOpenFailed(); return(-1);
                        }
                        // Connect local network drives
                        using (MySqlDataReader reader = (MySqlDataReader)sql.ExecuteQuery("SELECT * FROM qd_drives INNER JOIN qd_assigns ON qd_drives.ID = qd_assigns.DriveID INNER JOIN qd_users ON qd_assigns.UserID = qd_users.ID WHERE qd_assigns.UserID = ?", pUserID))
                        {
                            while (reader.Read())
                            {
                                try
                                {
                                    if (!ConnectOnlyIfNotAvailable || (ConnectOnlyIfNotAvailable && !Directory.Exists($@"{Convert.ToChar(reader["CustomDriveLetter"])}:\")))
                                    {
                                        //MessageBox.Show("Try to connect " + Convert.ToString(reader["CustomDriveName"]));

                                        ConnectDrive(
                                            Convert.ToChar(reader["CustomDriveLetter"]),
                                            Convert.ToString(reader["LocalPath"]),
                                            Cipher.Decrypt(Convert.ToString(reader["DUsername"]), pUserPassword),
                                            Cipher.Decrypt(Convert.ToString(reader["DPassword"]), pUserPassword),
                                            Convert.ToString(reader["CustomDriveName"]),
                                            Cipher.Decrypt(Convert.ToString(reader["DDomain"]), pUserPassword)
                                            );

                                        connectCtr++;
                                    }
                                }
                                catch
                                {
                                    return(5);
                                }
                            }
                        }

                        sql.Close();

                        // Conenct remote network drives
                        // TODO
                    }
                }
                catch
                {
                    return(4);
                }
            }


            // Connect Private drives (not online-synced)
            try
            {
                if (!File.Exists(QDInfo.ConfigFile))
                {
                    return(1);
                }

                using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile))
                {
                    if (!QDLib.ManagedDBOpen(sqlite))
                    {
                        QDLib.DBOpenFailed(); return(-1);
                    }
                    // Connect local network drives
                    using (SQLiteDataReader reader = (SQLiteDataReader)sqlite.ExecuteQuery("SELECT * FROM qd_drives"))
                    {
                        while (reader.Read())
                        {
                            try
                            {
                                if (!ConnectOnlyIfNotAvailable || (ConnectOnlyIfNotAvailable && Directory.Exists($@"{Convert.ToChar(reader["CustomDriveLetter"])}:\")))
                                {
                                    //MessageBox.Show("Try to connect " + Convert.ToString(reader["CustomDriveName"]));

                                    ConnectDrive(
                                        Convert.ToChar(reader["DriveLetter"]),
                                        Convert.ToString(reader["LocalPath"]),
                                        Cipher.Decrypt(Convert.ToString(reader["Username"]), QDInfo.LocalCipherKey),
                                        Cipher.Decrypt(Convert.ToString(reader["Password"]), QDInfo.LocalCipherKey),
                                        Convert.ToString(reader["DriveName"]),
                                        Cipher.Decrypt(Convert.ToString(reader["Domain"]), QDInfo.LocalCipherKey)
                                        );

                                    connectCtr++;
                                }
                            }
                            catch
                            {
                                return(3);
                            }
                        }
                    }
                    sqlite.Close();

                    // Conenct remote network drives
                    // TODO
                }
            }
            catch
            {
                return(2);
            }

            // Log only if not local. Do not log if no drives connected
            if (!string.IsNullOrEmpty(pUserID) && connectCtr > 0)
            {
                LogUserConnection(pUserID, QDLogAction.QDDrivesConnect, pDBData, pLogUserData);
            }

            return(0);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a list with all drives of a specified user
        /// </summary>
        /// <param name="pIsLocalConnection">Determines if the connection is a local connection</param>
        /// <param name="pUserID">User-ID of the target user. Blank if local connection</param>
        /// <param name="pUserPassword">Password of the user</param>
        /// <param name="pDBConDat">DB connection data</param>
        /// <returns>Drive-List</returns>
        public static List <DriveViewItem> CreateDriveList(bool pIsLocalConnection, string pUserID, string pUserPassword, WrapMySQLData pDBConDat)
        {
            List <DriveViewItem> driveList = new List <DriveViewItem>();

            using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile))
            {
                if (!QDLib.ManagedDBOpen(sqlite))
                {
                    QDLib.DBOpenFailed(); return(null);
                }
                using (SQLiteDataReader reader = (SQLiteDataReader)sqlite.ExecuteQuery("SELECT * FROM qd_drives"))
                {
                    while (reader.Read())
                    {
                        driveList.Add(new DriveViewItem(
                                          Convert.ToString(reader["ID"]),
                                          Convert.ToString(reader["DriveName"]),
                                          Convert.ToString(reader["LocalPath"]),
                                          Convert.ToString(reader["DriveLetter"]),
                                          true,
                                          false,
                                          Cipher.Decrypt(Convert.ToString(reader["Username"]), QDInfo.LocalCipherKey),
                                          Cipher.Decrypt(Convert.ToString(reader["Password"]), QDInfo.LocalCipherKey),
                                          Cipher.Decrypt(Convert.ToString(reader["Domain"]), QDInfo.LocalCipherKey)
                                          ));
                    }
                }
                sqlite.Close();
            }

            if (!pIsLocalConnection)
            {
                try
                {
                    using (WrapMySQL mysql = new WrapMySQL(pDBConDat))
                    {
                        if (!QDLib.ManagedDBOpen(mysql))
                        {
                            QDLib.DBOpenFailed(); return(null);
                        }
                        using (MySqlDataReader reader = (MySqlDataReader)mysql.ExecuteQuery("SELECT *, qd_assigns.ID as AID, qd_drives.ID AS DID FROM qd_drives INNER JOIN qd_assigns ON qd_drives.ID = qd_assigns.DriveID WHERE qd_assigns.UserID = ?", pUserID))
                        {
                            while (reader.Read())
                            {
                                driveList.Add(new DriveViewItem(
                                                  Convert.ToString(reader["AID"]),
                                                  Convert.ToString(reader["CustomDriveName"]),
                                                  Convert.ToString(reader["LocalPath"]),
                                                  Convert.ToString(reader["CustomDriveLetter"]),
                                                  false,
                                                  Convert.ToBoolean(Convert.ToInt16(reader["IsPublic"])),
                                                  Cipher.Decrypt(Convert.ToString(reader["DUsername"]), pUserPassword),
                                                  Cipher.Decrypt(Convert.ToString(reader["DPassword"]), pUserPassword),
                                                  Cipher.Decrypt(Convert.ToString(reader["DDomain"]), pUserPassword),
                                                  Convert.ToString(reader["DID"])
                                                  ));
                            }
                        }
                        mysql.Close();
                    }
                }
                catch { }
            }

            driveList.Sort();

            return(driveList);
        }
Ejemplo n.º 8
0
        private int LoadQDData()
        {
            // Load local Data

            using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile))
            {
                if (!QDLib.ManagedDBOpen(sqlite))
                {
                    QDLib.DBOpenFailed(); return(-1);
                }

                localConnection = !Convert.ToBoolean(sqlite.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.IsOnlineLinked));
                promptPassword  = Convert.ToBoolean(sqlite.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.AlwaysPromptPassword));

                Username = sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DefaultUsername);
                Password = sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DefaultPassword);

                dbData.Hostname = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBHost), QDInfo.LocalCipherKey);
                dbData.Username = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBUsername), QDInfo.LocalCipherKey);
                dbData.Password = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBPassword), QDInfo.LocalCipherKey);
                dbData.Database = Cipher.Decrypt(sqlite.ExecuteScalar <string>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBL.DBName), QDInfo.LocalCipherKey);

                sqlite.Close();

                if (!string.IsNullOrEmpty(Password))
                {
                    Password = Cipher.Decrypt(Password, QDInfo.LocalCipherKey);
                }
            }

            try
            {
                using (WrapSQLite sqlite = new WrapSQLite(QDInfo.ConfigFile))
                {
                    sqlite.Open();

                    sqlite.Close();
                }
            }
            catch { return(3); }

            // Load Online Data
            if (!localConnection)
            {
                try
                {
                    using (WrapMySQL mysql = new WrapMySQL(dbData))
                    {
                        if (!QDLib.ManagedDBOpen(mysql))
                        {
                            QDLib.DBOpenFailed(); return(-1);
                        }

                        disconnectAtShutdown = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.DisconnectDrivesAtShutdown));
                        logUserActions       = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT QDValue FROM qd_info WHERE QDKey = ?", QDInfo.DBO.LogUserActions));

                        mysql.Close();
                    }
                }
                catch { return(2); }
            }

            if (!promptPassword)
            {
                QDLib.VerifyPassword(localConnection, Username, Password, out UserID, dbData);
            }

            return(0);
        }
Ejemplo n.º 9
0
        public static void PowerStateCheck(string pIPRangeStart, string pIPRangeEnd, BackgroundWorker pProgressReplyBGW = null)
        {
            using (WrapSQLite tsql = new WrapSQLite(SurgitManager.SurgitDatabaseLocation, true))
            {
                Dictionary <string, bool> DevicePowerState = new Dictionary <string, bool>();

                // Get all devices, set powerstate to false
                DevicePowerState.Clear();
                tsql.Open();
                using (SQLiteDataReader reader = tsql.ExecuteQuery("SELECT * FROM Devices"))
                    while (reader.Read())
                    {
                        DevicePowerState.Add(Convert.ToString(reader["MACAddress"]), false);
                    }
                tsql.Close();


                // Ping all devices in Network Range
                Ping          ping  = new Ping();
                StringBuilder sqlSB = new StringBuilder();

                if (CheckIPClassCValidity(pIPRangeStart, pIPRangeEnd))
                {
                    string[] ipStartParts = pIPRangeStart.Split('.');
                    string[] ipEndParts   = pIPRangeEnd.Split('.');

                    for (int i = Convert.ToInt32(ipStartParts[3]); i <= Convert.ToInt32(ipEndParts[3]); i++)
                    {
                        if (pProgressReplyBGW.CancellationPending)
                        {
                            return;
                        }

                        if (pProgressReplyBGW != null)
                        {
                            pProgressReplyBGW.ReportProgress(i);
                        }

                        string    currentIP = ipStartParts[0] + "." + ipStartParts[1] + "." + ipStartParts[2] + "." + i.ToString();
                        PingReply reply     = ping.Send(currentIP, 100);

                        if (reply.Status == IPStatus.Success)
                        {
                            string currentMAC = NetExplore.GetMacAddress(currentIP);

                            if (!string.IsNullOrEmpty(currentMAC))
                            {
                                // Update the power-state of the device
                                if (DevicePowerState.ContainsKey(currentMAC))
                                {
                                    // Known device, only update values
                                    DevicePowerState[currentMAC] = true;
                                    sqlSB.Append($"UPDATE Devices SET IP4Address = '{currentIP}', LastSeen = '{DateTime.Now:yyyy-MM-dd H:mm:ss}' WHERE MACAddress = '{currentMAC}';");
                                }
                                else
                                {
                                    // New, unknown device, add to DB
                                    DevicePowerState.Add(currentMAC, true);
                                    sqlSB.Append($"INSERT INTO Devices (MACAddress, DeviceType, Name, IP4Address, LastSeen) VALUES ('{currentMAC}','{DeviceType.UnknownDevice}','Device-{currentMAC}','{currentIP}','{DateTime.Now:yyyy-MM-dd H:mm:ss}')");
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }

                    // Update IP and LastSeen, add new entries
                    tsql.ExecuteNonQueryACon(sqlSB.ToString());

                    // Update last power-state
                    StringBuilder sb = new StringBuilder();
                    foreach (KeyValuePair <string, bool> entry in DevicePowerState)
                    {
                        sb.Append($"UPDATE Devices SET LastPowerState = '{(entry.Value ? 1 : 0)}' WHERE MACAddress = '{entry.Key}';");
                    }
                    tsql.ExecuteNonQueryACon(sb.ToString());
                }
                else
                {
                    if (pProgressReplyBGW.CancellationPending)
                    {
                        return;
                    }
                    MessageBox.Show("The given range is not valid. Make sure the IPs are in the same subnet. Note: Only C-Class IP-Adresses are currently supported", "Invalid Range", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
        }
Ejemplo n.º 10
0
        private void CreateLocalDB(bool onlineLinked)
        {
            try
            {
                using (WrapSQLite sql = new WrapSQLite(QDInfo.ConfigFile))
                {
                    if (!QDLib.ManagedDBOpen(sql))
                    {
                        QDLib.DBOpenFailed(); return;
                    }
                    sql.TransactionBegin();
                    try
                    {
                        // Delete old tables
                        sql.ExecuteNonQuery("DROP TABLE IF EXISTS qd_info");
                        sql.ExecuteNonQuery("DROP TABLE IF EXISTS qd_drives");

                        // Create new tables
                        sql.ExecuteNonQuery(@"CREATE TABLE ""qd_info"" ( ""QDKey"" TEXT, ""QDValue"" TEXT, PRIMARY KEY(""QDKey""));");
                        sql.ExecuteNonQuery(@"CREATE TABLE ""qd_drives"" (""ID"" TEXT, ""LocalPath"" TEXT, ""RemotePath"" TEXT, ""Username"" TEXT, ""Password"" TEXT, ""Domain"" TEXT, ""DriveLetter"" TEXT, ""DriveName"" TEXT, PRIMARY KEY(""ID""));");

                        // Create pre-defined settings
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.IsOnlineLinked, onlineLinked);
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.AlwaysPromptPassword, alwaysPromptPassword);
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.SetupSuccess, true);

                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DBHost, Cipher.Encrypt(onlineDBConDat.Hostname, QDInfo.LocalCipherKey));
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DBName, Cipher.Encrypt(onlineDBConDat.Database, QDInfo.LocalCipherKey));
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DBUsername, Cipher.Encrypt(onlineDBConDat.Username, QDInfo.LocalCipherKey));
                        sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DBPassword, Cipher.Encrypt(onlineDBConDat.Password, QDInfo.LocalCipherKey));

                        if (onlineLinked)
                        {
                            sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DefaultUsername, DBNull.Value);
                            sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DefaultPassword, DBNull.Value);
                        }
                        else
                        {
                            sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DefaultUsername, "local");
                            sql.ExecuteNonQuery($@"INSERT INTO qd_info (QDKey, QDValue) VALUES (?, ?)", QDInfo.DBL.DefaultPassword, Cipher.Encrypt(localPassword, QDInfo.LocalCipherKey));
                        }


                        sql.TransactionCommit();
                    }
                    catch (Exception ex)
                    {
                        sql.TransactionRollback();
                        errorEncountered   = true;
                        txbS3ErrorLog.Text = ex.Message + " " + ex.StackTrace;
                    }
                    sql.Close();

                    if (errorEncountered)
                    {
                        MessageBox.Show("Could not create local database. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not create local database. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                errorEncountered   = true;
                txbS3ErrorLog.Text = ex.Message + " " + ex.StackTrace;
            }
        }