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(); } } }
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"; } }
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 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(); } }
private void EditSelectedDrive() { if (lbxOnlineDrives.SelectedIndex != -1) { string driveID = lbxOnlineDrives.SelectedValue.ToString(); if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return; } string drivePath = mysql.ExecuteScalar <string>("SELECT LocalPath FROM qd_drives WHERE ID = ?", driveID); string defaultName = mysql.ExecuteScalar <string>("SELECT DefaultName FROM qd_drives WHERE ID = ?", driveID); string defaultLetter = mysql.ExecuteScalar <string>("SELECT DefaultDriveLetter FROM qd_drives WHERE ID = ?", driveID); bool canBeDeployed = Convert.ToBoolean(mysql.ExecuteScalar <short>("SELECT IsDeployable FROM qd_drives WHERE ID = ?", driveID)); mysql.Close(); QDAddPublicDrive editDrive = new QDAddPublicDrive { EditMode = true, DrivePath = drivePath, DriveName = defaultName, DriveLetter = defaultLetter, CanBeDeployed = canBeDeployed }; if (editDrive.ShowDialog() == DialogResult.OK) { try { mysql.ExecuteNonQueryACon("UPDATE qd_drives SET DefaultName = ?, DefaultDriveLetter = ?, LocalPath = ?, IsDeployable = ? WHERE ID = ?", editDrive.DriveName, editDrive.DriveLetter, editDrive.DrivePath, editDrive.CanBeDeployed, driveID ); } catch { MessageBox.Show("Could not update drive data. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateOnlineDrives(); } } }
private void lbxDevices_SelectedIndexChanged(object sender, EventArgs e) { if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return; } txbDeviceMac.Text = mysql.ExecuteScalar <string>("SELECT MacAddress FROM qd_devices WHERE ID = ?", lbxDevices.SelectedValue); txbDeviceName.Text = mysql.ExecuteScalar <string>("SELECT DeviceName FROM qd_devices WHERE ID = ?", lbxDevices.SelectedValue); txbLogonName.Text = mysql.ExecuteScalar <string>("SELECT LogonName FROM qd_devices WHERE ID = ?", lbxDevices.SelectedValue); mysql.Close(); int userCount = QDLib.UserCountAtDevice(lbxDevices.SelectedValue.ToString(), dbData); if (userCount == 1) { lblDeviceUserCount.Text = $"{userCount} User logged into Q-Drive on this{Environment.NewLine}machine / account"; } else { lblDeviceUserCount.Text = $"{userCount} Users logged into Q-Drive on this{Environment.NewLine}machine / account"; } }
private void btnRemoveOnlineDrive_Click(object sender, EventArgs e) { if (lbxOnlineDrives.SelectedIndex != -1) { bool success = false; if (MessageBox.Show("Do you really want to remove the selected drive?", "Remove Drive", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (!QDLib.ManagedDBOpen(mysql)) { QDLib.DBOpenFailed(); return; } mysql.TransactionBegin(); try { mysql.ExecuteNonQuery("DELETE FROM qd_drives WHERE ID = ?", lbxOnlineDrives.SelectedValue.ToString()); mysql.ExecuteNonQuery("DELETE FROM qd_assigns WHERE DriveID = ?", lbxOnlineDrives.SelectedValue.ToString()); success = true; mysql.TransactionCommit(); } catch { mysql.TransactionRollback(); } mysql.Close(); if (!success) { MessageBox.Show("Could not remove drive. Please try again later.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } UpdateOnlineDrives(); } } }
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); }
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 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 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; } }
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 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"; } }