def parse_args(args): project = CanariProject(args.out_path) if project.is_valid: args.out_path = project.common_dir args.out_file = project.entities_py else: args.out_path = project.root_dir args.out_file = os.path.join(args.out_path, 'entities.py') if os.path.exists(args.out_file) and not args.append and not \ parse_bool('%r already exists. Are you sure you want to overwrite it?' % args.out_file, default=False): exit(-1) if not args.mtz_file: if not project.is_valid or not os.path.lexists(project.entities_mtz): print("Please specify a valid MTZ file.", file=sys.stderr) exit(-1) args.mtz_file = project.entities_mtz if args.maltego_entities: args.namespace.extend(args.exclude_namespace) args.exclude_namespace = [] args.project = project return args
def _install_transforms(self, prefix, distribution, in_project=False): if in_project: prefix = CanariProject().src_dir for transform in self.transforms: distribution.add_transform(prefix, 'Local', transform, server='Local')
def list_transforms(opts): try: with PushDir(opts.working_dir or CanariProject().src_dir): transform_package = TransformDistribution(opts.package) for transform_class in transform_package.transforms: transform = transform_class() print('`- %s: %s' % (highlight(transform.name, 'green', True), transform.description)) print(highlight(' `- Maltego identifiers:', 'black', True)) print(' `- %s applies to %s in set %s' % ( highlight(transform.name, 'red', False), highlight(transform.input_type._type_, 'red', False), highlight(transform.transform_set, 'red', False) )) print('') except ValueError, e: print(e) exit(-1)
def create_transform(args): opts = parse_args(args) project = CanariProject() transform_module = (opts.transform if not opts.transform.endswith('.py') else opts.transform[:-3]) transform_name = ''.join( [i[0].upper() + i[1:] for i in transform_module.split('_')]) transform_module = transform_module.lower() if '.' in transform_module: print("Transform name (%r) cannot have a dot ('.')." % transform_name) exit(-1) elif not transform_module: print("You must specify a valid transform name.") exit(-1) target = project.root_dir transform_directory = project.transforms_dir if os.path.exists( os.path.join(transform_directory, '%s.py' % transform_module)): print('Transform %r already exists... quitting' % transform_module) exit(-1) variables = parse_config(os.path.join(target, '.mrbob.ini'))['variables'] variables.update({ 'transform.module': transform_module, 'transform.name': transform_name }) configurator = Configurator(u'canari.resources.templates:create_transform', target, {'non_interactive': True}, variables=variables) configurator.ask_questions() print('Creating transform %r...' % transform_module) configurator.render() print('done!')
def debug_transform(opts): set_canari_mode(CanariMode.LocalDebug) with PushDir(CanariProject().src_dir): local_transform_runner(opts.transform, opts.value, opts.fields, opts.params, load_config(), console_writer)
def run_transform(opts): set_canari_mode(CanariMode.LocalDispatch) with PushDir(CanariProject().src_dir): local_transform_runner(opts.transform, opts.value, opts.fields, opts.params, load_config(), message)
def project(self): if not self._project: self._project = CanariProject() return self._project
def parse_args(args): project = CanariProject(args.out_path) args.out_path = project.root_dir sys.path.insert(0, project.src_dir) return args
def dockerize_package(args): project = CanariProject() print('Dockerizing %s transform package...' % project.name) configurator = Configurator('canari.resources.templates:dockerize_package', project.root_dir, {'non_interactive': True}, variables={ 'project.name': project.name, 'canari.version': version }) print('Creating Dockerfile for %s...' % project.name) configurator.render() print('done!') if not find_executable('docker'): print """Could not find 'docker' in your system path. Please download and install Docker from http://docker.com and rerun this command again. """ exit(-1) if not args.host and os.path.exists('/var/run/docker.sock'): args.host = ['unix:///var/run/docker.sock'] docker_hosts = [ j for sublist in [('-H', i) for i in args.host] for j in sublist ] container = '%s/%s:%s' % (project.name, project.name, args.os) if not args.host: if not find_executable('docker-machine'): print """Could not find 'docker-machine' in your system path. Please download and install Docker Machine from http://docker.com and rerun this command again or manually specify a Docker host using the '-H' parameter, instead. """ exit(-1) print 'Attempting to discover available Docker machines.' machines = run_command( ['docker-machine', 'ls', '-q'], stdout=subprocess.PIPE).communicate()[0].split('\n') machines.remove('') machine = question.parse_int( 'More than one Docker machine was detected. Which one would you like to use to' 'build and run this container?', machines) if len(machines) != 1 else 0 print 'Setting up environment for Docker machine %s' % machines[machine] # Inject docker environment variables env = run_command(['docker-machine', 'env', machines[machine]], stdout=subprocess.PIPE).communicate()[0] os.environ.update(re.findall(r'export ([^=]+)="([^"]+)', env)) with PushDir(project.root_dir): p = run_command( ['docker'] + docker_hosts + ['build', '-t', container, '-f', 'Dockerfile-%s' % args.os, '.']) p.communicate() if p.returncode: print 'An error occurred while building the Docker container.' exit(-1) if question.parse_bool('Would you like to run this container now?'): port = question.parse_int_range( 'Which port would you like Plume to listen on externally?', 0, 65535, 8080) print 'Plume will be listening on http://%s:%s' % (re.findall( '://([^:]+)', os.environ.get('DOCKER_HOST', 'http://0.0.0.0'))[0], port) run_command(['docker'] + docker_hosts + ['run', '-it', '-p', '8080:%s' % port, container]).communicate() print 'done!'