64 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			64 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| """
 | |
| Bazowa klasa dla backendów firewall
 | |
| """
 | |
| 
 | |
| import logging
 | |
| 
 | |
| 
 | |
| class FirewallBackend:
 | |
|     """Bazowa klasa dla backendów firewall"""
 | |
|     
 | |
|     def __init__(self, config):
 | |
|         """
 | |
|         Args:
 | |
|             config: ConfigParser object z konfiguracją
 | |
|         """
 | |
|         self.config = config
 | |
|         self.logger = logging.getLogger(self.__class__.__name__)
 | |
|         
 | |
|     def ban_ip(self, ip, duration):
 | |
|         """
 | |
|         Banuje IP na określony czas
 | |
|         
 | |
|         Args:
 | |
|             ip: Adres IP do zbanowania
 | |
|             duration: Czas bana w sekundach
 | |
|             
 | |
|         Returns:
 | |
|             bool: True jeśli ban się powiódł
 | |
|         """
 | |
|         raise NotImplementedError("Subclasses must implement ban_ip()")
 | |
|         
 | |
|     def unban_ip(self, ip):
 | |
|         """
 | |
|         Usuwa ban dla IP
 | |
|         
 | |
|         Args:
 | |
|             ip: Adres IP do odbanowania
 | |
|             
 | |
|         Returns:
 | |
|             bool: True jeśli odbanowanie się powiodło
 | |
|         """
 | |
|         raise NotImplementedError("Subclasses must implement unban_ip()")
 | |
|         
 | |
|     def is_banned(self, ip):
 | |
|         """
 | |
|         Sprawdza czy IP jest zbanowany
 | |
|         
 | |
|         Args:
 | |
|             ip: Adres IP do sprawdzenia
 | |
|             
 | |
|         Returns:
 | |
|             bool: True jeśli IP jest zbanowany
 | |
|         """
 | |
|         raise NotImplementedError("Subclasses must implement is_banned()")
 | |
|         
 | |
|     def test_availability(self):
 | |
|         """
 | |
|         Sprawdza czy backend jest dostępny w systemie
 | |
|         
 | |
|         Returns:
 | |
|             bool: True jeśli backend jest dostępny
 | |
|         """
 | |
|         return True
 | 
