def save_profile(self, profile_path): """ Save current profile to a json file """ # Convert peer objects into dictionary format profile = {} profile['peers'] = {} for peer in pm.peers: profile['peers'][peer.address] = {} profile['peers'][peer.address]['address'] = peer.address profile['peers'][ peer.address]['public_address'] = peer.public_address profile['peers'][peer.address]['listen_port'] = peer.listen_port profile['peers'][peer.address]['private_key'] = peer.private_key profile['peers'][peer.address]['keep_alive'] = peer.keep_alive if os.path.isfile(profile_path) or os.path.islink(profile_path): if not avalon.ask('File already exists. Overwrite?', True): avalon.warning('Aborted saving profile') return 1 if os.path.isdir(profile_path): avalon.warning('Destination path is a directory') avalon.warning('Aborted saving profile') return 1 avalon.dbgInfo('Writing profile to: {}'.format(profile_path)) with open(profile_path, 'w') as wgc_config: json.dump(profile, wgc_config, indent=2) wgc_config.close()
def display_options(kona, load_progress): """ Display konadl crawling options Prints the options of konadl before start crawling. Warns user if questionable images or explicit images are to be downloaded. Also shows other supplement information if any. More to be added in the future. """ avalon.dbgInfo('Program Started') avalon.info('Using storage directory: {}{}'.format(avalon.FG.W, kona.storage)) if load_progress: avalon.info('Sourcing configuration defined in the progress file') else: if kona.safe: avalon.info('Including {}{}SAFE{}{} rated images'.format( avalon.FG.W, avalon.FM.BD, avalon.FM.RST, avalon.FG.G)) if kona.questionable: avalon.warning('Including {}QUESTIONABLE{} rated images'.format( avalon.FG.W, avalon.FG.Y)) if kona.explicit: avalon.warning('Including {}EXPLICIT{} rated images'.format( avalon.FG.R, avalon.FG.Y)) if kona.yandere: avalon.info('Crawling yande.re') if args.pages: if args.pages == 1: avalon.info('Crawling {}{}{}{}{} Page\n'.format( avalon.FG.W, avalon.FM.BD, args.pages, avalon.FM.RST, avalon.FG.G)) else: avalon.info('Crawling {}{}{}{}{} Pages\n'.format( avalon.FG.W, avalon.FM.BD, args.pages, avalon.FM.RST, avalon.FG.G)) elif args.all: avalon.warning('Crawling {}ALL{} Pages\n'.format( avalon.FG.W, avalon.FG.Y)) elif args.page: avalon.info('Crawling Page #{}'.format(args.page)) avalon.info('Opening {}{}{}{}{} crawler threads'.format( avalon.FG.W, avalon.FM.BD, args.crawlers, avalon.FM.RST, avalon.FG.G)) avalon.info('Opening {}{}{}{}{} downloader threads\n'.format( avalon.FG.W, avalon.FM.BD, args.downloaders, avalon.FM.RST, avalon.FG.G))
def load_profile(self, profile_path): """ Load profile from a json file """ avalon.dbgInfo('Loading profile from: {}'.format(profile_path)) with open(profile_path, 'r') as wgc_config: profile = json.load(wgc_config) wgc_config.close() for peer in profile['peers']: address = profile['peers'][peer]['address'] public_address = profile['peers'][peer]['public_address'] listen_port = profile['peers'][peer]['listen_port'] private_key = profile['peers'][peer]['private_key'] keep_alive = profile['peers'][peer]['keep_alive'] pm.peers.append( Peer(address, public_address, listen_port, private_key, keep_alive))
def generate_configs(output_path): """ Generate configuration file for every peer This function reads the PEERS list, generates a configuration file for every peer, and export into the CONFIG_OUTPUT directory. """ if len(pm.peers) == 0: avalon.warning('No peers configured, exiting') exit(0) if len(pm.peers) == 1: avalon.warning('Only one peer configured') avalon.info('Generating configuration files') # Abort is destination is a file / link if os.path.isfile(output_path) or os.path.islink(output_path): avalon.warning('Destination path is a file / link') avalon.warning('Aborting configuration generation') return 1 # Ask if user wants to create the output directory if it doesn't exist if not os.path.isdir(output_path): if avalon.ask( 'Output directory doesn\'t exist. Create output directory?', True): os.mkdir(output_path) else: avalon('Aborting configuration generation') return 1 # Iterate through all peers and generate configuration for each peer for peer in pm.peers: avalon.dbgInfo('Generating configuration file for {}'.format( peer.address)) with open('{}/{}.conf'.format(output_path, peer.address.split('/')[0]), 'w') as config: # Write Interface configuration config.write('[Interface]\n') config.write('PrivateKey = {}\n'.format(peer.private_key)) if peer.address != '': config.write('Address = {}\n'.format(peer.address)) if peer.listen_port != '': config.write('ListenPort = {}\n'.format(peer.listen_port)) # Write peers' information for p in pm.peers: if p.address == peer.address: # Skip if peer is self continue config.write('\n[Peer]\n') print(p.private_key) config.write('PublicKey = {}\n'.format(wg.pubkey( p.private_key))) config.write('AllowedIPs = {}\n'.format(p.address)) if p.public_address != '': config.write('Endpoint = {}:{}\n'.format( p.public_address, p.listen_port)) if peer.keep_alive: config.write('PersistentKeepalive = 25\n') if p.preshared_key: config.write('PresharedKey = {}\n'.format(p.preshared_key))
def print_thread_exit(self, name): avalon.dbgInfo('[libkonadl] {} thread exiting'.format(name))
def print_retrieval(self, url, page): avalon.dbgInfo("[Page={}] Retrieving: {}".format(page, url))
def write_config(self): """ Write memory into trojan configuration""" avalon.dbgInfo('Writing config to: {}'.format(self.config_path)) with open(self.config_path, 'w') as conf: json.dump(self.config, conf, indent=2) conf.close()
def read_config(self): """ Read trojan configuration into memory""" avalon.dbgInfo('Reading config from: {}'.format(self.config_path)) with open(self.config_path, 'r') as conf: self.config = json.load(conf) conf.close()
def wrapper(*args, **kwargs): function(*args, **kwargs) avalon.dbgInfo('{} row(s) affected'.format(args[0].cursor.rowcount))