예제 #1
0
 def _apply_conf(cls, conf):
     """ Applies nft configuration submitted from webUI """
     with open(cls.NEW_CONF, 'w') as f:
         f.write(conf.replace('\r\n', '\n'))
     _, ret_code = run_command(f'nft -f {cls.NEW_CONF}')
     if ret_code:
         raise NFTablesException
예제 #2
0
 def _restore_backup(cls):
     """ Restores previous nft configuration from a file """
     run_command(f'nft -f {cls.BACKUP_CONF_NAME}')
예제 #3
0
 def _backup_conf(cls):
     """ Backups current nft configuration to a file """
     run_command(f'nft list ruleset > {cls.BACKUP_CONF_NAME}')
예제 #4
0
 def _delete_rules():
     """ Delete all rules from nft configuration """
     run_command('nft flush ruleset')
예제 #5
0
 def get_current_configuration(cls) -> str:
     """ Returns current nft configuration """
     conf, ret_code = run_command('nft list ruleset')
     if ret_code:
         raise NFTablesException("Error during configuration access")
     return conf