try: for f in logfiles: dh = DenyHosts(f, prefs, lock_file, ignore_offset, first_time, noemail, daemon) except SystemExit, e: pass except Exception, e: traceback.print_exc(file=sys.stdout) print "\nDenyHosts exited abnormally" if sync_mode and not daemon: if not prefs.get('SYNC_SERVER'): lock_file.remove() die("You have provided the --sync flag however your configuration file is missing a value for SYNC_SERVER.") sync_upload = is_true(prefs.get("SYNC_UPLOAD")) sync_download = is_true(prefs.get("SYNC_DOWNLOAD")) if not sync_upload and not sync_download: lock_file.remove() die("You have provided the --sync flag however your configuration file has SYNC_UPLOAD and SYNC_DOWNLOAD set to false.") try: sync = Sync(prefs) if sync_upload: timestamp = sync.send_new_hosts() if sync_download: new_hosts = sync.receive_new_hosts() if new_hosts: info("received new hosts: %s", str(new_hosts)) sync.get_denied_hosts() sync.update_hosts_deny(new_hosts) sync.xmlrpc_disconnect()
def test_is_true(self): for string in self.true_strings: self.assertTrue(is_true(string)) for string in self.false_strings: self.assertFalse(is_true(string))
def test_is_true(): for string in ['1', 't', 'true', 'y', 'yes']: assert is_true(string) for string in ['', 'false', 'ye', 'tr']: assert not is_true(string)
# On some operating systems the file /etc/hosts.deny (or # whatever HOSTS_DENY is set to, may not exist. We should # "touch" the file to make sure it is there to avoid errors later. try: host_filename = prefs.get("HOSTS_DENY") if host_filename: fp = open(prefs.get("HOSTS_DENY"), "a") fp.close() except Exception as e: print("Unable to create file specified by HOSTS_DENY variable.") setup_logging(prefs, enable_debug, verbose, daemon) # we will only sync to the server if the sync server is enabled and the sync_version is either true or commented out # config file has it set to sync the version by default if the sync server is enabled if prefs.get('SYNC_SERVER') and (prefs.get('SYNC_VERSION') is None or is_true(prefs.get('SYNC_VERSION'))): debug('Attempting to Sync Version: %s' % VERSION) try: sync = Sync(prefs) sync.send_release_used(VERSION) del sync except: # more than likely sync server doesn't have the option yet pass if not logfiles or daemon: logfiles = [prefs.get('SECURE_LOG')] elif len(logfiles) > 1: ignore_offset = 1 if not prefs.get('ADMIN_EMAIL'):