private static void DeleteSyncRow(WhitelistType whitelistType, string Ip, BatchQueryBuilder batchQueryBuilder) { var command = new MySqlCommand($"DELETE FROM FamilyRpServerAccess.{schemaTable[whitelistType]} WHERE IP = @IP;"); command.Parameters.AddWithValue("IP", Ip); batchQueryBuilder.AppendSqlCommand(command); }
public static Task UpdateWhitelists() { using (BatchQueryBuilder batchQueryBuilder = new BatchQueryBuilder(config.ConnString)) { foreach (WhitelistType type in Enum.GetValues(typeof(WhitelistType))) { Dictionary <string, string> Ips = FetchIps(type, WhitelistActionFilter.Add); foreach (KeyValuePair <string, string> Ip in Ips) { AddUserToFirewall(type, Ip.Key, batchQueryBuilder); } Ips = FetchIps(type, WhitelistActionFilter.Remove); foreach (KeyValuePair <string, string> Ip in Ips) { RemoveUserFromFirewall(type, Ip.Key, batchQueryBuilder); } } } return(Task.CompletedTask); }
private static void AuditLog(string WhitelistType, string Ip, string ActionType, BatchQueryBuilder batchQueryBuilder) { batchQueryBuilder.AppendSqlCommand(new MySqlCommand($@"INSERT INTO FamilyRpServerAccess.ServerWhitelistLog (Date, ActionType, Ip, WhitelistType) VALUES (NOW(), '{ActionType}', '{Ip}', '{WhitelistType}');")); }
private static void UpdateSyncStatus(WhitelistType whitelistType, string Ip, string targetState, BatchQueryBuilder batchQueryBuilder) { var command = new MySqlCommand($"UPDATE FamilyRpServerAccess.{schemaTable[whitelistType]} SET State = @State WHERE IP = @IP;"); command.Parameters.AddWithValue("State", targetState); command.Parameters.AddWithValue("IP", Ip); batchQueryBuilder.AppendSqlCommand(command); }
private static void RemoveUserFromFirewall(WhitelistType whitelistType, string Ip, BatchQueryBuilder batchQueryBuilder) { Console.WriteLine($"Removing IP {Ip} as {whitelistType}"); // TODO: Delete IP from server here // Use Config.MasterIps and whitelistType to map to correct server // If success: DeleteSyncRow(whitelistType, Ip, batchQueryBuilder); }
private static void AddUserToFirewall(WhitelistType whitelistType, string Ip, BatchQueryBuilder batchQueryBuilder) { Console.WriteLine($"Adding IP {Ip} as {whitelistType}"); // TODO: Delete IP from server here // Example: // var ci = new CsfInterface.Client(); // await ci.LoginToCsf("username", "password", "baseUrl"); // await ci.AddTempWhiteListIp(Ip, "", "30124", 200); // Use Config.MasterIps and whitelistType to map to correct server // If success: UpdateSyncStatus(whitelistType, Ip, "Keep", batchQueryBuilder); }