def event_reload_config(self, widget, event, data=None): utils.get_user_config() self.vbox.remove(self.tree_view.get_parent()) self.create_list() Control.reload_notes = True self.event_switch_to_list_view(None, None)
def __init__(self): utils.get_user_config() Control.regex_patterns = History.load_history_from_file(utils.get_search_history_path()) Control.file_history = History.load_history_from_file(utils.get_file_history_path()) self.stored_items = NoteList() self.event_dict_commandline = dict({ gtk.keysyms.Escape: self.event_focus_list, gtk.keysyms.Return: self.event_execute_command, gtk.keysyms.Up: self.event_prev_search_regex, gtk.keysyms.Down: self.event_next_search_regex, gtk.keysyms.Home: self.event_commandline_home, }) self.event_dict_list = dict({ # List to commandline #gtk.keysyms.colon: self.event_focus_commandline_command_mode, gtk.keysyms.slash: self.event_focus_commandline_search_mode, gtk.keysyms.f: self.event_focus_commandline_search_mode, gtk.keysyms.numbersign: self.event_focus_commandline_search_mode, # List to editor gtk.keysyms.Escape: self.event_reset_search, #gtk.keysyms.Tab: self.event_toggle_view, gtk.keysyms.a: self.event_add_new_note, # List #gtk.keysyms.q: self.event_destroy, gtk.keysyms.j: self.event_select_next, gtk.keysyms.k: self.event_select_prev, gtk.keysyms.G: self.event_select_last, gtk.keysyms.M: self.event_select_middle_visible, gtk.keysyms.L: self.event_select_last_visible, gtk.keysyms.H: self.event_select_first_visible, gtk.keysyms.g: self.event_select_first, gtk.keysyms.n: self.event_next_tag_mode, gtk.keysyms.p: self.event_prev_tag_mode, gtk.keysyms.F3: self.event_edit_config, gtk.keysyms.F5: self.event_reload_config, }) self.event_dict_editor = dict({ gtk.keysyms.Escape: self.event_switch_to_list_view, gtk.keysyms.z: self.event_undo, gtk.keysyms.r: self.event_redo, gtk.keysyms.s: self.event_save, gtk.keysyms.d: self.event_insert_date, gtk.keysyms.F4: self.event_delete_note, #gtk.keysyms.b: self.event_bold, })
def ipa_wrapper(**validated_params): # This method is called by both Click as a callback and manually for the simple commands. # Using a defaultdict allows for handling these params in the same way regardless of # how this method is called. validated_params = defaultdict(lambda: None, validated_params) # Get argument if present; the other params are options. argument = validated_params.pop(argument_name) # At somepoint during processing of the options, seemingly in click.Option, the '-' in ip-address # is being replaced with an underscore # I couldn't work out why so this is a messy fix for the time being if 'ip_address' in validated_params: validated_params['ip-address'] = validated_params['ip_address'] del validated_params['ip_address'] options = validated_params args = _build_ipa_args( argument, options=options, transform_options_callback=transform_options_callback) # if the command is modify host & there's only one item in the args list it's neccesary not to call # the ipa command as a) the option to modify it wouldn't do anything anyway and b) it would result # in a spurious error message if the --ip-address option has been removed in transform_options_callback if not (ipa_command == "host-mod" and len(args) == 1): # want to check if attempting user-add with creation script but that script isn't usable # before completing the user-add if (ipa_command == "user-add" and utils.get_user_config('POST_CREATE_SCRIPT') \ and (not utils.detect_user_config \ or not os.access(utils.get_user_config('POST_CREATE_SCRIPT'), os.X_OK))\ ): raise click.ClickException( "User create script unavailable - you need permissions to execute '{}' or alter your user config." .format(utils.get_user_config('POST_CREATE_SCRIPT'))) result = ipa_utils.ipa_run(ipa_command, args) utils.display_success() handle_result_callback(argument, options, result)
def start(webserver_context): # Read from home directory the user_key. If non-existent, get one from # cloud. config_dict = utils.get_user_config() utils.log('[MAIN] Starting.') # Set up environment state = HostState() state.user_key = config_dict['user_key'] state.secret_salt = config_dict['secret_salt'] state.host_mac = utils.get_my_mac() state.gateway_ip, _, state.host_ip = utils.get_default_route() webserver_context['host_state'] = state assert utils.is_ipv4_addr(state.gateway_ip) assert utils.is_ipv4_addr(state.host_ip) state.packet_processor = PacketProcessor(state) utils.log('Initialized:', state.__dict__) # Continously discover devices arp_scan_thread = ArpScan(state) arp_scan_thread.start() # Continuously gather SSDP data netdisco_thread = NetdiscoWrapper(state) netdisco_thread.start() # Continuously capture packets packet_capture_thread = PacketCapture(state) packet_capture_thread.start() # Continously spoof ARP if '--no_spoofing' not in sys.argv: arp_spoof_thread = ArpSpoof(state) arp_spoof_thread.start() # Continuously upload data data_upload_thread = DataUploader(state) data_upload_thread.start()
def init_data(self): user_config_exist = get_user_config() if not user_config_exist: print("initial database") init_result = init_database() print("table not exist, initialing tables") init_all_data(filt_path, init_result) else: pno, left_top_pot, right_bottom_pot, auto_apply, left_top_ans, right_bottom_ans, \ ans_1, ans_2, ans_3, ans_4 = user_config_exist self.left_top = sg.Text(left_top_pot, size=ConstCode.TEXT_SIZE) self.right_bottom = sg.Text(right_bottom_pot, size=ConstCode.TEXT_SIZE) if auto_apply: self.auto_apply_Y = sg.Radio("是:", "1", default=True, change_submits=True) # 0 else: self.auto_apply_N = sg.Radio("否:", "1", default=True, change_submits=True) # 1 self.auto_apply = auto_apply self.left_top_ans = sg.Text(left_top_ans, size=ConstCode.TEXT_SIZE) self.right_bottom_ans = sg.Text(right_bottom_ans, size=ConstCode.TEXT_SIZE) self.ans_click_1 = sg.Text(ans_1, size=ConstCode.TEXT_SIZE) self.ans_click_2 = sg.Text(ans_2, size=ConstCode.TEXT_SIZE) self.ans_click_3 = sg.Text(ans_3, size=ConstCode.TEXT_SIZE) self.ans_click_4 = sg.Text(ans_4, size=ConstCode.TEXT_SIZE)
def main(): # Read from home directory the user_key. If non-existent, get one from # cloud. config_dict = utils.get_user_config() # Where user would see report url = server_config.REPORT_URL.format(user_key=config_dict['user_key']) # Open a web browser only if non-root if not is_root() and LAUNCH_WEB_BROWSER_UPON_START: if 'no_browser' not in sys.argv: webbrowser.open_new_tab(url) os_platform = sys.platform # Run as root if os_platform.startswith('linux'): elevate(graphical=False) else: elevate() assert is_root() utils.log('[MAIN] Starting.') # Set up environment state = HostState() state.user_key = config_dict['user_key'] state.secret_salt = config_dict['secret_salt'] state.host_mac = utils.get_my_mac() state.gateway_ip, _, state.host_ip = utils.get_default_route() assert utils.is_ipv4_addr(state.gateway_ip) assert utils.is_ipv4_addr(state.host_ip) state.packet_processor = PacketProcessor(state) utils.log('Initialized:', state.__dict__) # Enable kernal forwarding. if os_platform.startswith('darwin'): cmd = ['/usr/sbin/sysctl', '-w', 'net.inet.ip.forwarding=1'] elif os_platform.startswith('linux'): cmd = ['sysctl', '-w', 'net.ipv4.ip_forward=1'] else: raise RuntimeError('Unsupported platform.') assert subprocess.call(cmd) == 0 # Continously discover devices arp_scan_thread = ArpScan(state) arp_scan_thread.start() # Continuously capture packets packet_capture_thread = PacketCapture(state) packet_capture_thread.start() # Continously spoof ARP arp_spoof_thread = ArpSpoof(state) arp_spoof_thread.start() # Continuously upload data data_upload_thread = DataUploader(state) data_upload_thread.start() # UI try: ui.start_main_ui(url, state) except KeyboardInterrupt: pass # Disable kernal forwarding. if os_platform.startswith('darwin'): cmd = ['/usr/sbin/sysctl', '-w', 'net.inet.ip.forwarding=0'] elif os_platform.startswith('linux'): cmd = ['sysctl', '-w', 'net.ipv4.ip_forward=0'] assert subprocess.call(cmd) == 0 utils.log('[MAIN] Done.')
def start(webserver_context): # Read from home directory the user_key. If non-existent, get one from # cloud. config_dict = utils.get_user_config() utils.log('[MAIN] Starting.') # Set up environment state = HostState() state.user_key = config_dict['user_key'].replace('-', '') state.secret_salt = config_dict['secret_salt'] state.host_mac = utils.get_my_mac() state.gateway_ip, _, state.host_ip = utils.get_default_route() webserver_context['host_state'] = state assert utils.is_ipv4_addr(state.gateway_ip) assert utils.is_ipv4_addr(state.host_ip) state.packet_processor = PacketProcessor(state) utils.log('Initialized:', state.__dict__) # Continously discover devices arp_scan_thread = ArpScan(state) arp_scan_thread.start() # Continuously gather SSDP data netdisco_thread = NetdiscoWrapper(state) netdisco_thread.start() # Continuously capture packets packet_capture_thread = PacketCapture(state) packet_capture_thread.start() # Continously spoof ARP if '--no_spoofing' not in sys.argv: arp_spoof_thread = ArpSpoof(state) arp_spoof_thread.start() # Continuously upload data data_upload_thread = DataUploader(state) data_upload_thread.start() # Suppress scapy warnings try: logging.getLogger("scapy.runtime").setLevel(logging.ERROR) except Exception: pass # Suppress flask messages try: logging.getLogger('werkzeug').setLevel(logging.ERROR) except Exception: pass if state.persistent_mode: # Insert a dash every four characters to make user-key easier to type pretty_user_key = '' for (ix, char) in enumerate(state.user_key): if (ix > 0) and (ix % 4 == 0): pretty_user_key += '-' pretty_user_key += char path = 'persistent/' + pretty_user_key caution = 'This is your private link. Open it only on trusted computers.' # noqa else: path = '' caution = '' print('\n' * 100) print(""" =========================== Princeton IoT Inspector =========================== View the IoT Inspector report at: https://inspector.cs.princeton.edu/{0} {1} Hit Control + C to terminate this process and stop data collection. """.format(path, caution))
def start(): """ Initializes inspector by spawning a number of background threads. Returns the host state once all background threats are started. """ # Read from home directory the user_key. If non-existent, get one from # cloud. config_dict = utils.get_user_config() utils.log('[MAIN] Starting.') # Set up environment state = HostState() state.user_key = config_dict['user_key'].replace('-', '') state.secret_salt = config_dict['secret_salt'] state.host_mac = utils.get_my_mac() state.gateway_ip, _, state.host_ip = utils.get_default_route() # Read special command-line arguments if '--raspberry_pi_mode' in sys.argv: state.raspberry_pi_mode = True assert utils.is_ipv4_addr(state.gateway_ip) assert utils.is_ipv4_addr(state.host_ip) state.packet_processor = PacketProcessor(state) utils.log('Initialized:', state.__dict__) # Continously discover devices arp_scan_thread = ArpScan(state) arp_scan_thread.start() # Continously discover ports via SYN scans syn_scan_thread = SynScan(state) syn_scan_thread.start() # Continuously gather SSDP data netdisco_thread = NetdiscoWrapper(state) netdisco_thread.start() # Continuously capture packets packet_capture_thread = PacketCapture(state) packet_capture_thread.start() # Continously spoof ARP if '--no_spoofing' not in sys.argv: arp_spoof_thread = ArpSpoof(state) arp_spoof_thread.start() # Continuously upload data data_upload_thread = DataUploader(state) data_upload_thread.start() # Suppress scapy warnings try: logging.getLogger("scapy.runtime").setLevel(logging.ERROR) except Exception: pass # Suppress flask messages try: logging.getLogger('werkzeug').setLevel(logging.ERROR) except Exception: pass # Insert a dash every four characters to make user-key easier to type pretty_user_key = '' for (ix, char) in enumerate(state.user_key): if (ix > 0) and (ix % 4 == 0): pretty_user_key += '-' pretty_user_key += char print('\n' * 100) os_platform = utils.get_os() print(WINDOWS_STARTUP_TEXT.format(server_config.BASE_URL, pretty_user_key)) # Open a browser window on Windows 10. Note that a new webpage will be # opened in a non-privileged mode. TODO: Not sure how to do the same # for macOS, as the "open" call on macOS will open a browser window # in privileged mode. if os_platform == 'windows': utils.open_browser_on_windows('{0}/user/{1}'.format( server_config.BASE_URL, pretty_user_key)) return state
def main(self, stdscr, notes_root, recursive): utils.get_user_config() Control.regex_patterns = History.load_history_from_file(utils.get_search_history_path()) Control.file_history = History.load_history_from_file(utils.get_file_history_path()) if not os.path.exists(notes_root): curses_view.end_curses() print('No such directory "%s"' % notes_root) exit() self.stored_items = NoteList() self.recursive = recursive self.notes_root = notes_root Control.reload_notes = True self.is_searching = False # TODO convert this into a TixMode instead # {{{ funcs for key events def keypress_list_pageup(): Control.reload_notes = False if TixMode.current == TixMode.LIST: curses_view.list_scroll_top -= curses_view.get_list_capacity() Control.list_visible_index -= curses_view.get_list_capacity() curses_view.adjust_scroll(len(self.stored_items)) elif TixMode.current == TixMode.TAGS: curses_view.tags_scroll_top -= curses_view.get_list_capacity() Control.tags_visible_index -= curses_view.get_list_capacity() curses_view.adjust_scroll(len(self.stored_items.modes())) def keypress_list_pagedown(): Control.reload_notes = False if TixMode.current == TixMode.LIST: # TODO don't scroll if last item is in view curses_view.list_scroll_top += curses_view.get_list_capacity() Control.list_visible_index += curses_view.get_list_capacity() curses_view.adjust_scroll(len(self.stored_items)) elif TixMode.current == TixMode.TAGS: curses_view.tags_scroll_top += curses_view.get_list_capacity() Control.tags_visible_index += curses_view.get_list_capacity() curses_view.adjust_scroll(len(self.stored_items.modes())) def keypress_select_first_in_view(): Control.reload_notes = False if TixMode.current == TixMode.LIST: i = Control.list_visible_index Control.list_visible_index = curses_view.list_scroll_top if i != Control.list_visible_index: curses_view.adjust_scroll(len(self.stored_items)) elif TixMode.current == TixMode.TAGS: i = Control.tags_visible_index Control.tags_visible_index = curses_view.tags_scroll_top if i != Control.tags_visible_index: curses_view.adjust_scroll(len(self.stored_items.modes())) def keypress_select_last_in_view(): Control.reload_notes = False if TixMode.current == TixMode.LIST: i = Control.list_visible_index Control.list_visible_index = curses_view.list_scroll_top + curses_view.get_list_capacity() - 1 if i != Control.list_visible_index: curses_view.adjust_scroll(len(self.stored_items)) elif TixMode.current == TixMode.TAGS: i = Control.tags_visible_index Control.tags_visible_index = curses_view.tags_scroll_top + curses_view.get_list_capacity() - 1 if i != Control.tags_visible_index: curses_view.adjust_scroll(len(self.stored_items.modes())) def keypress_select_middle_in_view(): Control.reload_notes = False i_after = i_before = nbr_items = scroll_top = 0 max_items_in_screen = curses_view.get_list_capacity() - 1 if TixMode.current == TixMode.LIST: i_after = i_before = Control.list_visible_index scroll_top = curses_view.list_scroll_top nbr_items = len(self.stored_items) elif TixMode.current == TixMode.TAGS: i_after = i_before = Control.tags_visible_index scroll_top = curses_view.tags_scroll_top nbr_items = len(self.stored_items.modes()) nbr_items_visible = min(nbr_items, nbr_items - scroll_top, max_items_in_screen) i_after = scroll_top + nbr_items_visible / 2 if TixMode.current == TixMode.LIST: Control.list_visible_index = i_after elif TixMode.current == TixMode.TAGS: Control.tags_visible_index = i_after if i_before != i_after: curses_view.adjust_scroll(nbr_items) def keypress_select_next(): Control.reload_notes = False if TixMode.current == TixMode.LIST: Control.list_visible_index += 1 curses_view.adjust_scroll(len(self.stored_items)) elif TixMode.current == TixMode.TAGS: Control.tags_visible_index += 1 nbr_modes = len(self.stored_items.modes()) curses_view.adjust_scroll(nbr_modes) def keypress_select_prev(): Control.reload_notes = False if TixMode.current == TixMode.LIST: Control.list_visible_index -= 1 curses_view.adjust_scroll(len(self.stored_items)) elif TixMode.current == TixMode.TAGS: Control.tags_visible_index -= 1 curses_view.adjust_scroll(len(self.stored_items.modes())) def keypress_select_last(): Control.reload_notes = False if TixMode.current == TixMode.LIST: Control.list_visible_index = len(self.stored_items) - 1 curses_view.adjust_scroll(len(self.stored_items)) elif TixMode.current == TixMode.TAGS: Control.tags_visible_index = len(self.stored_items.modes()) - 1 curses_view.adjust_scroll(len(self.stored_items.modes())) def keypress_select_first(): Control.reload_notes = False if TixMode.current == TixMode.LIST: Control.list_visible_index = 0 curses_view.list_scroll_top = 0 elif TixMode.current == TixMode.TAGS: Control.tags_visible_index = 0 curses_view.tags_scroll_top = 0 def keypress_change_sorting_order(): Control.reload_notes = False if TixMode.current == TixMode.LIST: SortMode.current = (SortMode.current + 1) % len(SortMode.OPTIONS) if SortMode.current == SortMode.BY_SHUF: SortMode.current = (SortMode.current + 1) % len(SortMode.OPTIONS) item_id = self.stored_items.get_visible(Control.list_visible_index).id if SortMode.current == SortMode.BY_DATE: self.stored_items.sort_by_modification_date() #self.stored_items.group_todo() elif SortMode.current == SortMode.BY_FILENAME: self.stored_items.sort_by_filename() new_index = 0 for i, item in enumerate(self.stored_items): if item.id == item_id: new_index = i break Control.list_visible_index = new_index def keypress_shuf_order(): Control.reload_notes = False if TixMode.current == TixMode.LIST: SortMode.current = SortMode.BY_SHUF item_id = self.stored_items.get_visible(Control.list_visible_index).id random.shuffle(self.stored_items) #self.stored_items.group_todo() new_index = 0 for i, item in enumerate(self.stored_items): if item.id == item_id: new_index = i break Control.list_visible_index = new_index def keypress_insert(): Control.reload_notes = False if TixMode.current == TixMode.LIST: curses_view.end_curses() list_modes = self.stored_items.modes() current_mode = list_modes[UserMode.current] if current_mode in (UserMode.ALL, UserMode.NOTAG): current_mode = None else: current_mode = current_mode + "\n\n" n = utils.new_note(current_mode) curses_view.init_curses() if n: Control.list_visible_index = 0 curses_view.adjust_scroll(len(self.stored_items)) Control.reload_notes = True def keypress_toggle_filename_view(): Control.reload_notes = False if TixMode.current == TixMode.LIST: Control.list_view_mode += 1 Control.list_view_mode = Control.list_view_mode % len(Control.LIST_VIEWS) def keypress_cycle_modes_reverse(): keypress_cycle_modes(True) def keypress_cycle_modes(reverse=False): Control.reload_notes = False if TixMode.current == TixMode.LIST: list_modes = self.stored_items.modes() nbr_modes = len(list_modes) if nbr_modes == 0: return addition = 1 if not reverse else -1 UserMode.current = (UserMode.current + addition) % nbr_modes for note in self.stored_items: if list_modes[UserMode.current] == UserMode.ALL or list_modes[UserMode.current] in note.modes: note.visible(True) elif list_modes[UserMode.current] == UserMode.NOTAG and not note.modes: note.visible(True) else: note.visible(False) def keypress_read(): Control.reload_notes = False if TixMode.current == TixMode.LIST: curses_view.end_curses() filename = self.stored_items.get_visible(Control.list_visible_index).fullpath() utils.open_file_in_reader(filename) curses_view.init_curses() def keypress_enter(): if TixMode.current == TixMode.LIST and len(self.stored_items) > 0: curses_view.end_curses() note_before = self.stored_items.get_visible(Control.list_visible_index) note_after = note_before.edit() curses_view.init_curses() if note_before.text != note_after.text: Control.reload_notes = True Control.list_visible_index = 0 h = History(note_after.fullpath()) Control.file_history.append(h) h.append_to_file(utils.get_file_history_path()) else: Control.reload_notes = False elif TixMode.current == TixMode.TAGS: Control.reload_notes = False TixMode.current = TixMode.LIST if UserMode.current == Control.tags_visible_index: return else: UserMode.current = Control.tags_visible_index Control.list_visible_index = 0 list_modes = self.stored_items.modes() for note in self.stored_items: if list_modes[UserMode.current] == UserMode.ALL or list_modes[UserMode.current] in note.modes: note.visible(True) elif list_modes[UserMode.current] == UserMode.NOTAG and not note.modes: note.visible(True) else: note.visible(False) def keypress_cycle_tix_modes(): Control.reload_notes = False nbr_modes = len(TixMode.OPTIONS) if nbr_modes == 0: return reverse = False addition = 1 if not reverse else -1 TixMode.current = (TixMode.current + addition) % nbr_modes if TixMode.current == TixMode.EDIT: TixMode.current = (TixMode.current + addition) % nbr_modes def keypress_switch_to_list_mode(): Control.reload_notes = False TixMode.current = TixMode.LIST def keypress_switch_to_tags_mode(): Control.reload_notes = False if TixMode.current == TixMode.LIST: TixMode.current = TixMode.TAGS elif TixMode.current == TixMode.TAGS: keypress_enter() pass def pressed_slash(): Control.reload_notes = False if TixMode.current == TixMode.LIST: Control.reload_thread_lock.acquire() def validator(c): if c == 27: # ctrl A >then> ctrl K # regex = None return 7 elif c == 10: return 7 # RETURN key -- CTRL-g = 7 and CTRL-j = 10 else: curses_view.search_textbox.do_command(c) if c == curses.KEY_UP and Control.current_regex_index > 0: Control.current_regex_index -= 1 curses_view.footer_pad.clear() CursesView.add_str(curses_view.footer_pad, Control.regex_patterns[Control.current_regex_index].value) elif c == curses.KEY_DOWN and Control.current_regex_index < len(Control.regex_patterns) - 1: Control.current_regex_index += 1 curses_view.footer_pad.clear() CursesView.add_str(curses_view.footer_pad, Control.regex_patterns[Control.current_regex_index].value) elif c == curses.KEY_DOWN and Control.current_regex_index == len(Control.regex_patterns) - 1: Control.current_regex_index += 1 curses_view.footer_pad.clear() CursesView.add_str(curses_view.footer_pad, curses_view.search_prompt) if curses_view.search_textbox.gather() is '': return 7 regex = "" try: curses.curs_set(1) except curses.error: # iphone pass Control.current_regex_index = len(Control.regex_patterns) curses_view.footer_pad.clear() CursesView.add_str(curses_view.footer_pad, curses_view.search_prompt) self.is_searching = True regex = curses_view.search_textbox.edit(validator) self.is_searching = False try: curses.curs_set(0) except curses.error: # iphone pass if regex != None: regex = regex[len(curses_view.search_prompt):] if regex.strip(): h = History(curses_view.search_prompt + regex) h.append_to_file(utils.get_search_history_path()) Control.regex_patterns.append(h) Control.list_visible_index = 0 curses_view.adjust_scroll(len(self.stored_items)) list_modes = self.stored_items.modes() current_mode = list_modes[UserMode.current] for note in self.stored_items: if note.is_search_match(regex): if (current_mode == UserMode.ALL or current_mode in note.modes): note.visible(True) elif (current_mode == UserMode.NOTAG and not note.modes): note.visible(True) else: note.visible(False) Control.reload_thread_lock.release() key_to_action = dict({ ord('M'): keypress_select_middle_in_view, ord('H'): keypress_select_first_in_view, ord('L'): keypress_select_last_in_view, ord('j'): keypress_select_next, ord('k'): keypress_select_prev, #ord('h'): keypress_switch_to_list_mode, ord('h'): keypress_switch_to_tags_mode, ord('l'): keypress_switch_to_tags_mode, ord('g'): keypress_select_first, ord('G'): keypress_select_last, ord('a'): keypress_insert, ord('r'): keypress_read, ord('n'): keypress_cycle_modes, ord('p'): keypress_cycle_modes_reverse, ord('\t'): keypress_cycle_tix_modes, 9: keypress_cycle_tix_modes, # = TAB ord('#'): keypress_cycle_tix_modes, ord('@'): keypress_cycle_tix_modes, #353: keypress_cycle_modes_reverse, # = SHIFT + TAB ord('f'): keypress_toggle_filename_view, ord('s'): keypress_change_sorting_order, ord('S'): keypress_shuf_order, ord('/'): pressed_slash, 10: keypress_enter, curses.KEY_ENTER: keypress_enter, curses.KEY_DOWN: keypress_select_next, curses.KEY_UP: keypress_select_prev, curses.KEY_HOME: keypress_select_first, curses.KEY_END: keypress_select_last, curses.KEY_NPAGE: keypress_list_pagedown, curses.KEY_PPAGE: keypress_list_pageup, curses.KEY_LEFT: keypress_switch_to_list_mode, curses.KEY_RIGHT: keypress_switch_to_tags_mode, }) #}}} while True: curses_view.update_screen_size() curses_view.recalculate_widths() curses_view.create_footer_pad() if Control.reload_notes: if not Control.reload_thread_lock.locked(): t = self.Loader(self) t.start() elif not Control.reload_thread_lock.locked(): curses_view.complete_redraw(self.stored_items) Control.reload_notes = False c = curses_view.keyboard_pad.getch() if c == ord('q'): break f = key_to_action.get(c) if f: f() curses_view.end_curses()
def start(): """ Initializes inspector by spawning a number of background threads. Returns the host state once all background threats are started. """ # Read from home directory the user_key. If non-existent, get one from # cloud. config_dict = utils.get_user_config() utils.log('[MAIN] Starting.') # Set up environment state = HostState() state.user_key = config_dict['user_key'].replace('-', '') state.secret_salt = config_dict['secret_salt'] state.host_mac = utils.get_my_mac() state.gateway_ip, _, state.host_ip = utils.get_default_route() assert utils.is_ipv4_addr(state.gateway_ip) assert utils.is_ipv4_addr(state.host_ip) state.packet_processor = PacketProcessor(state) utils.log('Initialized:', state.__dict__) # Start web API webserver.start_thread(state) # Continously discover devices arp_scan_thread = ArpScan(state) arp_scan_thread.start() # Continously discover ports via SYN scans syn_scan_thread = SynScan(state) syn_scan_thread.start() # # Continuously gather SSDP data # netdisco_thread = NetdiscoWrapper(state) # netdisco_thread.start() # Continuously capture packets packet_capture_thread = PacketCapture(state) packet_capture_thread.start() # Continously spoof ARP if '--no_spoofing' not in sys.argv: arp_spoof_thread = ArpSpoof(state) arp_spoof_thread.start() # Suppress scapy warnings try: logging.getLogger("scapy.runtime").setLevel(logging.ERROR) except Exception: pass # Suppress flask messages try: logging.getLogger('werkzeug').setLevel(logging.ERROR) except Exception: pass # Insert a dash every four characters to make user-key easier to type pretty_user_key = '' for (ix, char) in enumerate(state.user_key): if (ix > 0) and (ix % 4 == 0): pretty_user_key += '-' pretty_user_key += char print( 'Ready. To test if the API works, visit http://127.0.0.1:46241/get_device_list' ) return state
def __init__(self): utils.get_user_config() Control.regex_patterns = History.load_history_from_file( utils.get_search_history_path()) Control.file_history = History.load_history_from_file( utils.get_file_history_path()) self.stored_items = NoteList() self.event_dict_commandline = dict({ gtk.keysyms.Escape: self.event_focus_list, gtk.keysyms.Return: self.event_execute_command, gtk.keysyms.Up: self.event_prev_search_regex, gtk.keysyms.Down: self.event_next_search_regex, gtk.keysyms.Home: self.event_commandline_home, }) self.event_dict_list = dict({ # List to commandline #gtk.keysyms.colon: self.event_focus_commandline_command_mode, gtk.keysyms.slash: self.event_focus_commandline_search_mode, gtk.keysyms.f: self.event_focus_commandline_search_mode, gtk.keysyms.numbersign: self.event_focus_commandline_search_mode, # List to editor gtk.keysyms.Escape: self.event_reset_search, #gtk.keysyms.Tab: self.event_toggle_view, gtk.keysyms.a: self.event_add_new_note, # List #gtk.keysyms.q: self.event_destroy, gtk.keysyms.j: self.event_select_next, gtk.keysyms.k: self.event_select_prev, gtk.keysyms.G: self.event_select_last, gtk.keysyms.M: self.event_select_middle_visible, gtk.keysyms.L: self.event_select_last_visible, gtk.keysyms.H: self.event_select_first_visible, gtk.keysyms.g: self.event_select_first, gtk.keysyms.n: self.event_next_tag_mode, gtk.keysyms.p: self.event_prev_tag_mode, gtk.keysyms.F3: self.event_edit_config, gtk.keysyms.F5: self.event_reload_config, }) self.event_dict_editor = dict({ gtk.keysyms.Escape: self.event_switch_to_list_view, gtk.keysyms.z: self.event_undo, gtk.keysyms.r: self.event_redo, gtk.keysyms.s: self.event_save, gtk.keysyms.d: self.event_insert_date, gtk.keysyms.F4: self.event_delete_note, #gtk.keysyms.b: self.event_bold, })