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
def _restore_backup(cls): """ Restores previous nft configuration from a file """ run_command(f'nft -f {cls.BACKUP_CONF_NAME}')
def _backup_conf(cls): """ Backups current nft configuration to a file """ run_command(f'nft list ruleset > {cls.BACKUP_CONF_NAME}')
def _delete_rules(): """ Delete all rules from nft configuration """ run_command('nft flush ruleset')
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