/// <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 { } }
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 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; } }