Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 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}');"));
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }