def list_blacklist_ip(self): bl_countries = self.list_blocked(to_print=False) if len(bl_countries) > 0: for country in bl_countries: print command('{} -L {}_set'.format(utils().ipset_bin(), country)).print_output() else: print 'No blacklisted country.Nothing to print'
def startup(self): command('{} create countries list:set'.format( utils().ipset_bin())).run() geoip_settings_folder = utils().settings['geoip_settings_folder'] for zone in listdir(geoip_settings_folder): if search('[a-z]-aggregated.zone.set$', zone): command('{} restore -f {}'.format( utils().ipset_bin(), geoip_settings_folder + zone)).run()
def del_countries_subnet(self, country): country = country.lower() geoip_settings_folder = utils().settings['geoip_settings_folder'] utils().del_json_country(country) try: remove('{}{}-aggregated.zone.set'.format(geoip_settings_folder, country)) except OSError as e: print e command('{} del countries {}_set'.format(utils().ipset_bin(), country)).run() command('{} destroy {}_set'.format(utils().ipset_bin(), country)).run()
def create_tar(files, cwd, target): cmd = 'tar zcf %s %s' % (target, ' '.join(files)) run.command(cmd.split(), cwd=cwd)