private void btnDeleteAccount_Click(object sender, EventArgs e) { if (lbxUserList.SelectedIndex != -1) { if (MessageBox.Show("Do you really want to delete the selected user?", "Delete User", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return; } mysql.TransactionBegin(); try { mysql.ExecuteNonQuery("DELETE FROM qd_users WHERE ID = ?", lbxUserList.SelectedValue.ToString()); mysql.ExecuteNonQuery("DELETE FROM qd_assigns WHERE UserID = ?", lbxUserList.SelectedValue.ToString()); mysql.TransactionCommit(); } catch { mysql.TransactionRollback(); } mysql.Close(); UpdateUsersSettings(); } } }
/// <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); }
/// <summary> /// Tests the DB-Connection /// </summary> /// <param name="pOnlineDBConDat">DB connection data</param> /// <param name="messageOnSuccess">Show a messagebox when the connection is successfull</param> /// <returns></returns> public static bool TestConnection(WrapMySQLData pOnlineDBConDat, bool messageOnSuccess = true) { bool success = false; using (WrapMySQL sql = new WrapMySQL(pOnlineDBConDat)) { try { sql.Open(); success = true; } catch { success = false; } finally { sql.Close(); } } if (success) { if (messageOnSuccess) { MessageBox.Show("Connection to the database established successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Could not connect to the database.", "Connection failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(success); }
private void QDAddUser_Load(object sender, EventArgs e) { if (EditID != null) { using (WrapMySQL mysql = new WrapMySQL(DBData)) { if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return; } Username = mysql.ExecuteScalar <string>("SELECT Username FROM qd_users WHERE ID = ?", EditID); DisplayName = mysql.ExecuteScalar <string>("SELECT Name FROM qd_users WHERE ID = ?", EditID); mysql.Close(); txbUsername.Text = Username; txbDisplayName.Text = DisplayName; } this.Text = "Edit User"; btnSubmit.Text = "Save Changes"; lblRegisterTitle.Text = "Update user-data"; lblPassword.Text = "New Password"; } }
public void WrapMySQL_ConnectionTest_ExpectSuccess() { using (WrapMySQL sql = new WrapMySQL(dbHost, sbName, dbUser, dbPass)) { sql.Open(); sql.Close(); } }
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(); } }
public void WrapMySQL_SQLScalarUntypedString_Success() { using (WrapMySQL sql = new WrapMySQL(dbHost, sbName, dbUser, dbPass)) { sql.Open(); object res = sql.ExecuteScalar("SELECT QDValue FROM qd_info WHERE QDKey = ?", "DefaultDomain"); sql.Close(); Assert.AreEqual("endevx", Convert.ToString(res)); } }
public void WrapMySQL_SQLScalarUntypedInt_Success() { using (WrapMySQL sql = new WrapMySQL(dbHost, sbName, dbUser, dbPass)) { sql.Open(); object res = sql.ExecuteScalar("SELECT COUNT(*) FROM qd_drives"); sql.Close(); Assert.AreEqual(10, Convert.ToInt32(res)); } }
public void WrapMySQL_SQLScalarTypedInt_Success() { using (WrapMySQL sql = new WrapMySQL(dbHost, sbName, dbUser, dbPass)) { sql.Open(); int res = sql.ExecuteScalar <int>("SELECT COUNT(*) FROM qd_drives"); sql.Close(); Assert.AreEqual(10, res); } }
private void UpdateInfoData() { if (dgvActionBrowser.Rows.Count <= 0) { return; } if (dgvActionBrowser.SelectedRows.Count <= 0) { return; } string conlogID = dgvActionBrowser.SelectedRows[0].Cells["ID"].Value.ToString(); string sqlQuery = $"SELECT *, " + $"(SELECT COUNT(*) FROM qd_assigns WHERE qd_assigns.UserID = qd_conlog.UserID) AS AssignedDriveCount, " + $"(SELECT COUNT(*) FROM (SELECT * FROM qd_conlog GROUP BY qd_conlog.UserID) AS TMP WHERE TMP.DeviceID = qd_devices.ID) AS UserCount " + $"FROM qd_conlog " + $"INNER JOIN qd_users ON qd_conlog.UserID = qd_users.ID " + $"INNER JOIN qd_devices ON qd_conlog.DeviceID = qd_devices.ID " + $"WHERE qd_conlog.ID = ?"; using (WrapMySQL mysql = new WrapMySQL(DBData)) { if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return; } using (MySqlDataReader reader = (MySqlDataReader)mysql.ExecuteQuery(sqlQuery, conlogID)) { while (reader.Read()) { lblDateTime.Text = Convert.ToString(reader["LogTime"]); lblActionType.Text = Convert.ToString((QDLogAction)Convert.ToInt32(reader["LogAction"])); lblActionDescription.Text = QDLib.GetLogDescriptionFromAction((QDLogAction)Convert.ToInt32(reader["LogAction"])); lblDisplayName.Text = Convert.ToString(reader["Name"]); lblUsername.Text = Convert.ToString(reader["Username"]); lblAssignedDrives.Text = Convert.ToString(reader["AssignedDriveCount"]); lblDeviceName.Text = Convert.ToString(reader["DeviceName"]); lblLogonName.Text = Convert.ToString(reader["LogonName"]); lblMacAddress.Text = Convert.ToString(reader["MacAddress"]); lblUserCount.Text = QDLib.UserCountAtDevice(Convert.ToString(reader["DeviceID"]), DBData).ToString(); } } mysql.Close(); } }
/// <summary> /// Loggs user-actions to the online log /// </summary> /// <param name="pUserID">User-ID</param> /// <param name="pLogAction">Log Action</param> /// <param name="pDBData">DB connection data</param> /// <param name="pLogUserActionAllowed">Global flag to allow or deny the logging of data</param> public static void LogUserConnection(string pUserID, QDLogAction pLogAction, WrapMySQLData pDBData, bool pLogUserActionAllowed) { if (string.IsNullOrEmpty(pUserID)) { return; } try { using (WrapMySQL mysql = new WrapMySQL(pDBData)) { string deviceID; string deviceMac = GetMACAddress(); if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return; } mysql.TransactionBegin(); try { // Add device to DB if it doesn't exist. Get device ID if (mysql.ExecuteScalar <int>("SELECT COUNT(*) FROM qd_devices WHERE MacAddress = ? AND LogonName = ? AND DeviceName = ?", deviceMac, Environment.UserName, Environment.MachineName) == 0) { deviceID = Guid.NewGuid().ToString(); mysql.ExecuteNonQuery("INSERT INTO qd_devices (ID, MacAddress, LogonName, DeviceName) VALUES (?,?,?,?)", deviceID, deviceMac, Environment.UserName, Environment.MachineName ); } else { deviceID = mysql.ExecuteScalar <string>("SELECT ID FROM qd_devices WHERE MacAddress = ? AND LogonName = ? AND DeviceName = ?", deviceMac, Environment.UserName, Environment.MachineName); } // Log device action. if (pLogUserActionAllowed) { mysql.ExecuteNonQuery("INSERT INTO qd_conlog (ID, UserID, DeviceID, LogTime, LogAction) VALUES (?,?,?, NOW() ,?)", Guid.NewGuid(), pUserID, deviceID, pLogAction ); } mysql.TransactionCommit(); } catch { mysql.TransactionRollback(); } mysql.Close(); } } catch { } }
/// <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); }
/// <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); }
private void CreateOnlineDB() { try { using (WrapMySQL sql = new WrapMySQL(onlineDBConDat)) { if (onlineConfigureAsNewDB) { 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`"); sql.ExecuteNonQuery("DROP TABLE IF EXISTS `qd_users`"); sql.ExecuteNonQuery("DROP TABLE IF EXISTS `qd_assigns`"); sql.ExecuteNonQuery("DROP TABLE IF EXISTS `qd_conlog`"); sql.ExecuteNonQuery("DROP TABLE IF EXISTS `qd_devices`"); // Create new tables sql.ExecuteNonQuery("CREATE TABLE `qd_info` ( `QDKey` VARCHAR(255) NOT NULL , `QDValue` VARCHAR(255) NOT NULL , PRIMARY KEY (`QDKey`))"); sql.ExecuteNonQuery("CREATE TABLE `qd_drives` ( `ID` VARCHAR(50) NOT NULL , `DefaultName` VARCHAR(50) NOT NULL , `DefaultDriveLetter` VARCHAR(1) NOT NULL , `LocalPath` VARCHAR(255) NOT NULL , `RemotePath` VARCHAR(255) NOT NULL , `IsPublic` BOOLEAN NOT NULL , `IsDeployable` BOOLEAN NOT NULL , PRIMARY KEY (`ID`))"); sql.ExecuteNonQuery("CREATE TABLE `qd_users` ( `ID` varchar(50) NOT NULL, `Name` varchar(100) NOT NULL, `Username` varchar(100) NOT NULL, `Password` varchar(100) NOT NULL, PRIMARY KEY(`ID`), UNIQUE KEY `Username` (`Username`))"); sql.ExecuteNonQuery("CREATE TABLE `qd_assigns` ( `ID` varchar(50) NOT NULL, `UserID` varchar(50) NOT NULL, `DriveID` varchar(50) NOT NULL, `CustomDriveName` varchar(50) NOT NULL, `CustomDriveLetter` varchar(1) NOT NULL, `DUsername` varchar(200) NOT NULL, `DPassword` varchar(200) NOT NULL, `DDomain` varchar(200) NOT NULL, PRIMARY KEY(`ID`))"); sql.ExecuteNonQuery("CREATE TABLE `qd_conlog` ( `ID` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `UserID` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `DeviceID` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `LogTime` datetime NOT NULL, `LogAction` int(11) NOT NULL, PRIMARY KEY(`ID`))"); sql.ExecuteNonQuery("CREATE TABLE `qd_devices` ( `ID` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `MacAddress` varchar(50) COLLATE utf8_unicode_ci NOT NULL, `LogonName` varchar(150) COLLATE utf8_unicode_ci NOT NULL, `DeviceName` varchar(150) COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY(`ID`)) "); // Create pre-defined settings sql.ExecuteNonQuery($"INSERT INTO `qd_info` (`QDKey`, `QDValue`) VALUES (?, ?)", QDInfo.DBO.UserCanToggleKeepLoggedIn, false); sql.ExecuteNonQuery($"INSERT INTO `qd_info` (`QDKey`, `QDValue`) VALUES (?, ?)", QDInfo.DBO.UserCanAddPrivateDrive, false); sql.ExecuteNonQuery($"INSERT INTO `qd_info` (`QDKey`, `QDValue`) VALUES (?, ?)", QDInfo.DBO.UserCanAddPublicDrive, true); sql.ExecuteNonQuery($"INSERT INTO `qd_info` (`QDKey`, `QDValue`) VALUES (?, ?)", QDInfo.DBO.UserCanSelfRegister, true); sql.ExecuteNonQuery($"INSERT INTO `qd_info` (`QDKey`, `QDValue`) VALUES (?, ?)", QDInfo.DBO.MasterPassword, QDLib.HashPassword(onlineMasterPassword)); sql.ExecuteNonQuery($"INSERT INTO `qd_info` (`QDKey`, `QDValue`) VALUES (?, ?)", QDInfo.DBO.DefaultDomain, ""); sql.ExecuteNonQuery($"INSERT INTO `qd_info` (`QDKey`, `QDValue`) VALUES (?, ?)", QDInfo.DBO.UseLoginAsDriveAuthentication, false); sql.ExecuteNonQuery($"INSERT INTO `qd_info` (`QDKey`, `QDValue`) VALUES (?, ?)", QDInfo.DBO.ForceLoginAsDriveAuthentication, false); sql.ExecuteNonQuery($"INSERT INTO `qd_info` (`QDKey`, `QDValue`) VALUES (?, ?)", QDInfo.DBO.DisconnectDrivesAtShutdown, false); sql.ExecuteNonQuery($"INSERT INTO `qd_info` (`QDKey`, `QDValue`) VALUES (?, ?)", QDInfo.DBO.LogUserActions, false); sql.ExecuteNonQuery($"INSERT INTO `qd_info` (`QDKey`, `QDValue`) VALUES (?, ?)", QDInfo.DBO.UserCanChangeManagerSettings, true); sql.TransactionCommit(); } catch (Exception ex) { sql.TransactionRollback(); errorEncountered = true; txbS3ErrorLog.Text = ex.Message + " " + ex.StackTrace; } sql.Close(); if (errorEncountered) { MessageBox.Show("Could not create online database. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { MessageBox.Show("Could not create online database. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); errorEncountered = true; txbS3ErrorLog.Text = ex.Message + " " + ex.StackTrace; } }
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); }
private void UpdateDatagrid() { QDLoader qdLoader = new QDLoader(); qdLoader.Show(); BrowserSort sort = BrowserSort.None; if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); qdLoader.Close(); return; } totalEntryCount = mysql.ExecuteScalar <int>("SELECT COUNT(*) FROM qd_conlog"); bool abort = false; if (string.IsNullOrEmpty(SelectedObjectID)) { sort = BrowserSort.AllEntries; } else if (SelectedObjectID.StartsWith("ACT=")) { sort = BrowserSort.SortedByActionType; } else if (mysql.ExecuteScalar <int>("SELECT COUNT(*) FROM qd_users WHERE ID = ?", SelectedObjectID) != 0) { sort = BrowserSort.SortedByUsers; } else if (mysql.ExecuteScalar <int>("SELECT COUNT(*) FROM qd_devices WHERE ID = ?", SelectedObjectID) != 0) { sort = BrowserSort.SortedByDevice; } else { abort = true; } mysql.Close(); if (abort) { qdLoader.Close(); return; } switch (cbxEntryLimit.SelectedIndex) { case 0: listLimitSize = 50; break; case 1: listLimitSize = 100; break; case 2: listLimitSize = 250; break; case 3: listLimitSize = 500; break; case 4: listLimitSize = 1000; break; case 5: listLimitSize = 5000; break; default: listLimitSize = -1; break; } if (listOffset <= 0 || listLimitSize == -1) { btnJumpToFirst.Enabled = false; btnJumpToFirst.BackColor = Color.DarkGray; } else { btnJumpToFirst.Enabled = true; btnJumpToFirst.BackColor = Color.Gainsboro; } if (listOffset <= 0 || listLimitSize == -1) { btnJumpBack.Enabled = false; btnJumpBack.BackColor = Color.DarkGray; } else { btnJumpBack.Enabled = true; btnJumpBack.BackColor = Color.Gainsboro; } if (listOffset + listLimitSize > totalEntryCount || listLimitSize == -1) { btnJumpToNext.Enabled = false; btnJumpToNext.BackColor = Color.DarkGray; } else { btnJumpToNext.Enabled = true; btnJumpToNext.BackColor = Color.Gainsboro; } maxOffset = 0; while (listLimitSize + maxOffset < totalEntryCount) { maxOffset += listLimitSize; } if (listOffset >= maxOffset) { btnJumpToLast.Enabled = false; btnJumpToLast.BackColor = Color.DarkGray; } else { btnJumpToLast.Enabled = true; btnJumpToLast.BackColor = Color.Gainsboro; } string limitString; if (listLimitSize == -1) { limitString = ""; } else { limitString = $"LIMIT {listOffset},{listLimitSize}"; } string sqlQuery = ""; switch (sort) { case BrowserSort.AllEntries: sqlQuery = $"SELECT " + $"*, " + $"qd_conlog.ID AS MainID, " + $"CONCAT(qd_users.Name, ' (', qd_users.Username, ')') AS UserDisplay, " + $"CONCAT(qd_devices.LogonName, ' @ ', qd_devices.DeviceName) AS DeviceDisplay " + $"FROM qd_conlog " + $"INNER JOIN qd_users ON qd_conlog.UserID = qd_users.ID " + $"INNER JOIN qd_devices ON qd_conlog.DeviceID = qd_devices.ID " + $"ORDER BY LogTime DESC " + limitString; lblActionDescriptor.Text = "Showing all recorded actions."; break; case BrowserSort.SortedByActionType: sqlQuery = $"SELECT " + $"*, " + $"qd_conlog.ID AS MainID, " + $"CONCAT(qd_users.Name, ' (', qd_users.Username, ')') AS UserDisplay, " + $"CONCAT(qd_devices.LogonName, ' @ ', qd_devices.DeviceName) AS DeviceDisplay " + $"FROM qd_conlog " + $"INNER JOIN qd_users ON qd_conlog.UserID = qd_users.ID " + $"INNER JOIN qd_devices ON qd_conlog.DeviceID = qd_devices.ID " + $"WHERE qd_conlog.LogAction = ? " + $"ORDER BY LogTime DESC " + limitString; lblActionDescriptor.Text = $"Showing all recorded actions of type \"{(QDLogAction)Convert.ToInt32(SelectedObjectID.Replace("ACT=", ""))}\"."; break; case BrowserSort.SortedByDevice: sqlQuery = $"SELECT " + $"*, " + $"qd_conlog.ID AS MainID, " + $"CONCAT(qd_users.Name, ' (', qd_users.Username, ')') AS UserDisplay, " + $"CONCAT(qd_devices.LogonName, ' @ ', qd_devices.DeviceName) AS DeviceDisplay " + $"FROM qd_conlog " + $"INNER JOIN qd_users ON qd_conlog.UserID = qd_users.ID " + $"INNER JOIN qd_devices ON qd_conlog.DeviceID = qd_devices.ID " + $"WHERE qd_devices.ID = ? " + $"ORDER BY LogTime DESC " + limitString; lblActionDescriptor.Text = $"Showing all recorded actions of device \"{mysql.ExecuteScalarACon<string>("SELECT CONCAT(LogonName, ' @ ', DeviceName) FROM qd_devices WHERE ID = ?", SelectedObjectID)}\"."; break; case BrowserSort.SortedByUsers: sqlQuery = $"SELECT " + $"*, " + $"qd_conlog.ID AS MainID, " + $"CONCAT(qd_users.Name, ' (', qd_users.Username, ')') AS UserDisplay, " + $"CONCAT(qd_devices.LogonName, ' @ ', qd_devices.DeviceName) AS DeviceDisplay " + $"FROM qd_conlog " + $"INNER JOIN qd_users ON qd_conlog.UserID = qd_users.ID " + $"INNER JOIN qd_devices ON qd_conlog.DeviceID = qd_devices.ID " + $"WHERE qd_users.ID = ? " + $"ORDER BY LogTime DESC " + limitString; lblActionDescriptor.Text = $"Showing all recorded actions of user \"{mysql.ExecuteScalarACon<string>("SELECT CONCAT(Name, ' (', Username, ')') FROM qd_users WHERE ID = ?", SelectedObjectID)}\"."; break; } dgvActionBrowser.Rows.Clear(); if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); qdLoader.Close(); return; } using (MySqlDataReader reader = (MySqlDataReader)mysql.ExecuteQuery(sqlQuery, SelectedObjectID.Replace("ACT=", ""))) { while (reader.Read()) { dgvActionBrowser.Rows.Add(new string[] { Convert.ToString(reader["MainID"]), Convert.ToString(reader["LogTime"]), Convert.ToString(reader["UserDisplay"]), Convert.ToString(reader["DeviceDisplay"]), Convert.ToString((QDLogAction)Convert.ToInt32(reader["LogAction"])), }); } } mysql.Close(); lblResultRange.Text = $"Showing entries {listOffset + 1} to {listOffset + dgvActionBrowser.Rows.Count} ({totalEntryCount} entries in total)"; qdLoader.Close(); }
private void QDAddPublicDrive_Load(object sender, EventArgs e) { ImageList imgList = new ImageList() { ImageSize = new Size(60, 60), ColorDepth = ColorDepth.Depth32Bit, }; imgList.Images.Add("PublicUp", Properties.Resources.QDriveOnlinePublicUp); grvPublicDrives.SmallImageList = imgList; grvPublicDrives.GroupViewItems.Clear(); using (WrapMySQL sql = new WrapMySQL(DBData)) { if (!QDLib.ManagedDBOpen(sql)) { QDLib.DBOpenFailed(); return; } using (MySqlDataReader reader = (MySqlDataReader)sql.ExecuteQuery("SELECT * FROM qd_drives WHERE IsPublic = 1 ORDER BY DefaultDriveLetter ASC")) { while (reader.Read()) { grvPublicDrives.GroupViewItems.Add( new GroupViewItemEx( $"({Convert.ToString(reader["DefaultDriveLetter"])}:\\) {Convert.ToString(reader["DefaultName"])}\r\n({Convert.ToString(reader["LocalPath"])})", new DriveViewItem( Convert.ToString(reader["ID"]), Convert.ToString(reader["DefaultName"]), Convert.ToString(reader["LocalPath"]), Convert.ToString(reader["DefaultDriveLetter"]), false, true, "", "", "" ), 0 ) ); } } sql.Close(); } if (grvPublicDrives.GroupViewItems.Count == 0) { pbxNoDrivesFound.Visible = true; btnSubmit.Enabled = false; } else { pbxNoDrivesFound.Visible = false; } if (!string.IsNullOrEmpty(Username)) { txbUsername.Text = Username; } if (!string.IsNullOrEmpty(Password)) { txbPassword.Text = Password; } if (!string.IsNullOrEmpty(Domain)) { txbDomainName.Text = Domain; } if (ForceAutofill && !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password) && !string.IsNullOrEmpty(Domain)) { txbUsername.ReadOnly = true; txbPassword.ReadOnly = true; txbDomainName.ReadOnly = true; txbUsername.Enabled = false; txbPassword.Enabled = false; txbDomainName.Enabled = false; } // Set values for edit mode if (DBEntryID != null) { txbDisplayName.Text = CustomDriveName; txbUsername.Text = Username; txbPassword.Text = Password; txbDomainName.Text = Domain; for (int i = 0; i < cbxDriveLetter.Items.Count; i++) { if (cbxDriveLetter.Items[i].ToString()[0].ToString() == CustomDriveLetter) { cbxDriveLetter.SelectedIndex = i; } } for (int i = 0; i < grvPublicDrives.GroupViewItems.Count; i++) { if ((grvPublicDrives.GroupViewItems[i] as GroupViewItemEx).Drive.ID == DriveID) { grvPublicDrives.SelectedItem = i; txbDrivePath.Text = (grvPublicDrives.GroupViewItems[i] as GroupViewItemEx).Drive.DrivePath; } } this.Text = "Edit public drive"; btnSubmit.Text = "Update Drive"; } }