def whenPressed(self): form = self.parent module_name = self.parent.module.name submodule_name = self.parent.submodule.name copy_number = self.parent.copy_number formid = module_name+"_"+submodule_name+"_"+str(copy_number) #Need to remove from the submodule_forms_data list and _display_pages list form.parentApp._display_pages.remove(formid) copy_count = 0 for form_data in form.parentApp.submodule_forms_data: if (module_name == form_data["module_name"]) & (submodule_name == form_data["submodule_name"]) & (copy_number == form_data["copy_number"]): form.parentApp.submodule_forms_data.remove(form_data) elif (module_name == form_data["module_name"]) & (submodule_name == form_data["submodule_name"]): copy_count += 1 #If the last one is removed, we need to unselect the IntroForm widget if copy_count == 0: ModuleForm = form.parentApp.getForm("MODULE") for widget_info in ModuleForm._widget_list: if module_name == widget_info["module_name"]: for choice in widget_info["widget"].value: if widget_info["widget"].values[choice] == submodule_name: widget_info["widget"].value.remove(choice) nps.notify_wait("Deleted copy of submodule %s." % submodule_name, title="Submodule Removed", form_color='STANDOUT', wrap=True, wide=True) form.edit_return_value = True form.editing = False
def popup(original, orig_type, thr, title): """ Start the thread and display a popup of info until the thread is finished """ thr.start() info_str = '' while thr.is_alive(): if orig_type == 'containers': info = diff(Containers(), original) elif orig_type == 'images': info = diff(Images(), original) if info: info_str = '' for entry in info: info_str = entry[0] + ': ' + entry[1] + '\n' + info_str if self.action['action_name'] != 'configure': npyscreen.notify_wait(info_str, title=title) time.sleep(1) thr.join() try: result = self.api_action.queue.get(False) if isinstance(result, tuple) and isinstance(result[1], tuple): running, failed = result[1] r_str = '' for container in running: r_str += container + ': successful\n' for container in failed: r_str += container + ': failed\n' npyscreen.notify_confirm(r_str) except Exception as e: # pragma: no cover pass return
def on_ok(self): # Verify Smart Card Available if self.ms2.value: v = self.ms2.get_selected_objects()[0] if v == 'Register': if client.askForRegist(): if Smartcard.isSmartCardAvailable(): self.parentApp.getForm("PIN").destination = "Register" self.parentApp.switchForm("PIN") else: npyscreen.notify_wait("You have no Smartcard connected", title="Failure", form_color="WARNING") else: print "ERROR MESSAGE" elif v == 'Log In': if client.askForLogIn(): if Smartcard.isSmartCardAvailable(): self.parentApp.getForm("PIN").destination = "Log In" self.parentApp.switchForm("PIN") else: self.parentApp.switchForm("Log In") else: print "ERROR MESSAGE" else: npyscreen.notify_wait( "Project Safebox - Security UA\n\n-> José Sequeira 64645\n" + "-> Vasco Santos 64191", title='Project Info', form_color='CRITICAL')
def main(self): Form = npyscreen.Form(name="GNU/Linux Magazine") text = Form.add(MyTitleAutocomplete, name = "Texte :") Form.edit() npyscreen.notify_wait("Valeur saisie : " + text.value, title="Vérification")
def on_ok(self): v = self.chose.get_selected_objects()[0] filename = self.filename.value if v == "Download": self.parentApp.getForm("Download").filename.value = \ self.filename.value self.parentApp.switchForm("Download") elif v == "Delete": # DELETE FROM DB confirm = npyscreen.notify_yes_no( "Are you sure you want to delete file %s?" % filename, title="Confimation", form_color='STANDOUT', wrap=True, editw=1) if confirm: global LogUser client.removeFile(LogUser, filename) self.parentApp.getForm("List").update_list() self.parentApp.switchForm("List") elif v == "Share": global LogUser if client.getPermission(LogUser, filename): self.parentApp.getForm("WhoIsShared").filename.value = \ self.filename.value self.parentApp.switchForm("WhoIsShared") else: npyscreen.notify_wait("You have no Permission to Share the File", title='Failure', form_color='CRITICAL') elif v == "Diff": self.parentApp.getForm("Get").filename.value = \ self.filename.value self.parentApp.switchForm("Get")
def on_ok(self): v = self.list.get_selected_objects()[0] if v != None or v != []: filename = self.filename.value global LogUser client.unshare(LogUser, filename, v) npyscreen.notify_wait("Un-Share Successful", form_color="VERYGOOD") self.parentApp.switchForm("List")
def change_forms(self, *args, **keywords): npyscreen.notify_wait(self.name) if self.name == "MAIN": change_to = "Detailed" else: change_to = "MAIN" self.parentApp.change_form(change_to)
def on_ok(self): if not self.validateInput(): nps.notify_wait("Not all required input items for this module have been entered. Please check all fields.", title="Error", form_color='STANDOUT', wrap=True, wide=True) self.editing = True else: if self.parentApp.current_page <= (len(self.parentApp._display_pages) - 1): self.parentApp.current_page += 1 self.parentApp.setNextForm(self.determineNextForm())
def on_ok(self): filename = self.filename.value destination = self.wgDestination.value privpath = self.wgPrivDest.value global LogUser client.download(filename, destination, privpath, LogUser) npyscreen.notify_wait("Download Successful", title="Download", form_color="VERYGOOD") self.parentApp.switchForm("List")
def on_ok(self): if len(self.pin.value) == 4 and self.pin.value.isdigit(): if not Smartcard.pinCorrect(self.pin.value): npyscreen.notify_wait("WRONG PIN") else: self.parentApp.getForm(self.destination).pin.value = self.pin.value self.parentApp.switchForm(self.destination) else: npyscreen.notify_wait("WRONG PIN FORMAT")
def main(self): npyscreen.setTheme(BeautifulTheme) Form = npyscreen.Form(name="GNU/Linux Magazine") text = Form.add(npyscreen.FixedText, value="Exemple de formulaire minimal") user_text = Form.add(npyscreen.TitleText, name="Saisir texte:") Form.edit() npyscreen.notify_wait("Valeur saisie : " + user_text.value, title="Vérification")
def onStart(self): # Welcome message npyscreen.notify_wait(includes.welcome_message, title="Welcome", form_color='STANDOUT', wrap=True, wide=True) # Networking self.addForm('MAIN', networking.connInfo, name='Linux Generic Installer - Networking') # User management self.addForm('userman', userman.userInfo, name='Linux Generic Installer - User Management')
def main(self): Form = npyscreen.Form(name="GNU/Linux Magazine") cbox_values = ["Option 1", "Option 2", "Option 3"] cbox = Form.add(npyscreen.TitleMultiSelect, max_height=len(cbox_values), value = [1,], name="Choix :", values = cbox_values, scroll_exit=True) Form.edit() npyscreen.notify_wait("Valeur saisie : " + str(cbox.get_selected_objects()), title="Vérification")
def main(self): Form = npyscreen.Form(name="GNU/Linux Magazine") radio_values = ["Option 1", "Option 2", "Option 3"] radio = Form.add(npyscreen.TitleSelectOne, max_height=len(radio_values), value = [0], name="Choix:", values = radio_values, scroll_exit=True) Form.edit() npyscreen.notify_wait("Valeur saisie : " + radio.get_selected_objects()[0], title="Vérification")
def afterEditing(self): self._save_parameters() API.update_view_params(self._view_params) if self._view_params.get('function_name', None): self.parentApp.NEXT_ACTIVE_FORM = 'TemplateForm' else: npyscreen.notify_wait( "You have to set function_name", "Form Validation" )
def whenPressed(self): try: _val = self.parent.parentApp.application_logic.query_boxids()[self.parent.wg_in_box.value] except Exception as e: _val = None if _val: self.parent.parentApp.application_logic.label(_val) npyscreen.notify_wait("Printing box reference label. Please wait.") else: npyscreen.notify_wait("Sorry, but I cannot print you a box label if you don't have a box selected.")
def popup(thr, title): """ Start the thread and display a popup of the plugin being cloned until the thread is finished """ thr.start() tool_str = "Cloning repository..." npyscreen.notify_wait(tool_str, title=title) while thr.is_alive(): time.sleep(1) return
def on_ok(self): fp = self.file.value if os.path.isdir(fp): npyscreen.notify_wait( "We're sorry, you can't upload folders - Yet :)", title='Work In Progress', form_color='CRITICAL') else: global LogUser client.upload(fp, LogUser) npyscreen.notify_wait("Upload successful", title="Upload", form_color="VERYGOOD") self.parentApp.switchFormPrevious()
def receive(self): while True: data = sock.recv(1024) if err_list.get(data.strip(), 0) != 0: time.sleep(1) npyscreen.notify_wait(err_list[data.strip()], title='Warning') time.sleep(0.5) # print ps_error else: self.resp.value = self.resp.value + data.decode() self.resp.display()
def popup(thr, add_type, title): """ Start the thread and display a popup of the plugin being cloned until the thread is finished """ thr.start() tool_str = 'Cloning repository...' if add_type == 'image': tool_str = 'Pulling image...' npyscreen.notify_wait(tool_str, title=title) while thr.is_alive(): time.sleep(1) return
def key_error(self, what, value): message = "Can only press one key at a time!" if what is self.action_widgets.LT: self.left_trigger_widget.value = value[0] message = "Can only trigger from one character!" elif what is self.action_widgets.RT: self.right_trigger_widget.value = value[0] message = "Can only trigger from one character!" elif what is self.action_widgets.LK: self.left_key_widget.value = value[0] else: self.right_key_widget.value = value[0] npyscreen.notify_wait(message, title="Input too long!")
def change_dir(self, select_file): try: os.listdir(select_file) except OSError: npyscreen.notify_wait(title="Error", message="Cannot enter directory.") return False self.parent.parentApp.myPath = select_file self.parent.update_grid() self.edit_cell = [0, 0] self.begin_row_display_at = 0 self.begin_col_display_at = 0 return True
def afterEditing(self): selected_option = self.parentApp.SELECTED_RESULT try: selection = self.parentApp.RESULTS[selected_option] self.search = self.parentApp.SCRAPER_OBJ self.download_link = self.search.get_link(selection) npyscreen.notify("Please wait while Romulus downloads this ROM...", "Downloading") self.d = Download(self.search) self.d.download(self.download_link) npyscreen.notify("The ROM is now available on EmulationStation", "Success") self.parentApp.setNextForm('MAIN') except TypeError: npyscreen.notify_wait('Please hit ENTER on your selection to select it', 'Error')
def myFunction(*args): global file_path,num_workers,format_type,model_type,iplist,program_path F = ApatheticML(name = "Choices for model and data:") F.edit() npyscreen.notify_wait('Thank you!') file_path = str(F.file.value) num_workers = F.splits.value format_type = F.format.value model_type = F.m[F.model.value[0]] iplist = F.ips.value.split() program_path = str(F.ppath.value) return "\nDeploying " + F.splits.value + ' workers to run ' + F.m[(F.model.value[0])] + ' on dataset in ' + str(F.file.value)+ F.ips.value + '\n'
def validateInput(self): #Validate the input variables #Get the variables args = {} for input_item in self._value["input"]: name = input_item["name"] if self.get_widget(name).value: args[name] = self.get_widget(name).value if not(self.submodule._input.requirementsMet(args)): nps.notify_wait("Not all required input items for this module have been entered. Please check all fields.", title="Error", form_color='STANDOUT', wrap=True, wide=True) return False else: return True
def on_ok(self): """ Perform restoration on the backup file selected """ if self.dir_select.value: npyscreen.notify_wait('In the process of restoring', title='Restoring...') status = self.restore(self.dirs[self.dir_select.value[0]]) if status[0]: npyscreen.notify_confirm('Status of restore:\n' + status[1]) else: npyscreen.notify_confirm(status[1]) self.quit() else: npyscreen.notify_confirm('Choose a version to restore from')
def do_save(self): F = ConfirmCancelPopup(name="Memory to save settings to:", color="STANDOUT") F.preserve_selected_widget = True mlw = F.add(npyscreen.SelectOne,max_height=3, value = [0,], values = ["Memory 1","Memory 2","Memory 3"], scroll_exit=True) mlw_width = mlw.width-1 F.editw = 1 F.edit() if F.value: try: aaptos = self.parentApp.soapProxy aaptos.save(mlw.value[0]+1) except socket.error as e: npyscreen.notify_wait("[Errno %s] %s"%(e.errno,e.strerror), title="Error", form_color='STANDOUT', wrap=True, wide=False)
def on_ok(self): if not self.validateInput(): nps.notify_wait( "Not all required input items for this module have been entered. Please check all fields.", title="Error", form_color='STANDOUT', wrap=True, wide=True) self.editing = True else: if self.parentApp.current_page <= ( len(self.parentApp._display_pages) - 1): self.parentApp.current_page += 1 self.parentApp.setNextForm(self.determineNextForm())
def on_ok(self): #Connect global HOST, PORT, CLIENT, CLIENT_READY HOST = self.server1.value sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect((HOST, PORT)) except: npyscreen.notify_wait("Server is down or the setting are wrong, try again...") return 1 if self.ssl.value[0] == 0: try: context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) context.load_verify_locations('certs/cert.pem') sock = context.wrap_socket(sock,server_hostname="PChaty") except ConnectionError: npyscreen.notify_wait("SSL Connection Error:Are you sure the server use ssl") client = chat.Client(sock) client.setname(self.nick.value) try: chat.send_msg(sock,client.getname()) resp = chat.recv_msg(sock) if 'Error:duplicate' in resp: raise chat.ClientExsit() CLIENT = client self.parentApp.setNextForm('Message') except (BrokenPipeError, ConnectionError): sys.stdout.flush() npyscreen.notify_wait("Connection Error, Try again!") except chat.ClientExsit: npyscreen.notify_wait("User with this name already exist")
def on_ok(self): kafka_enabled = self.parentApp.filebeat_config.is_kafka_output_enabled( ) if not InstallManager.validate_targets( targets=[self.target_text.value]): npyscreen.notify_ok_cancel( 'Target must be given in the format: host:port (E.G 192.168.0.100:5044)', form_color='DANGER') return if kafka_enabled: kafka_config = self.parentApp.filebeat_config.get_kafka_target_config( ) original_targets = list(kafka_config.get('hosts', [])) else: original_targets = list( self.parentApp.filebeat_config.get_logstash_target_hosts()) if self.value: edit_target_index = original_targets.index(self.value) original_targets[edit_target_index] = self.target_text.value npyscreen.notify_wait(self.target_text.value + ' has been updated!', form_color='GOOD') else: original_targets.append(self.target_text.value) npyscreen.notify_wait(self.target_text.value + ' has been created!', form_color='GOOD') if kafka_enabled: username, password = self.username_text.value, self.password_text.value if self.username_text.value.strip() == '': username = None if self.password_text.value.strip() == '': password = None self.parentApp.filebeat_config.set_kafka_targets( original_targets, topic=self.topic_text.value, username=username, password=password) else: self.parentApp.filebeat_config.set_logstash_targets( original_targets) # Switch back to the main interface self.parentApp.filebeat_config.write_config() self.parentApp.removeForm('MAIN') self.parentApp.addForm('MAIN', FilebeatInstanceSettingsForm, name='FileBeat Configuration') self.parentApp.switchForm('MAIN')
def validate_and_transform_data(self): data = dict( LDEVS=self._form.LDEVS.value.upper().split(","), GB=self._form.GB.value.split(","), POOL_ID=self._form.POOL_ID_SEL.values[ self._form.POOL_ID_SEL.value[0]].split(":")[0], LDEV_PREFIX=self._form.LDEV_PREFIX_SEL.values[ self._form.LDEV_PREFIX_SEL.value[0]].rstrip("_"), IS_GAD=True if self._form.GAD_SEL.values[self._form.GAD_SEL.value[0]] == 'YES' else False, GAD_RES_NAME=self._form.GAD_RES_NAME.value, GAD_DEV_GRP=self._form.GAD_DEV_GRP_SEL.values[ self._form.GAD_DEV_GRP_SEL.value[0]], SER_PRI=self._form.SER_PRI_SEL.values[ self._form.SER_PRI_SEL.value[0]], ) if len(data['LDEVS']) != len(data['GB']): nps.notify_wait("PLEASE, DOUBLE CHECK LDEVS VS THEIR SIZE", title='WARNING') elif not all([len(i) == 4 for i in data['LDEVS']]): nps.notify_wait( "LDEV ID MUST BE OF EXACTLY _4 DIGITS_, HEX (ex: 012F)", title='WARNING') elif not all([ j for i in [[k in '0123456789abcdefABCDEF' for k in j] for j in data['LDEVS']] for j in i ]): nps.notify_wait( "LDEV ID MUST BE _HEXADECIMAL_, 4-DIGITS (ex: 012F)", title='WARNING') elif not len(data['LDEVS']) == len(set(data['LDEVS'])): nps.notify_wait("THERE ARE _REPEATED_ LDEV IDs IN YOUR LIST", title='WARNING') else: # ldevs = [i.replace(":", "") for i in ldevs] ldev_dict = dict(zip(data['LDEVS'], data['GB'])) clean_data = { 'ldevs': [{ "ldev_id": i, "ldev_gb": j } for i, j in ldev_dict.items()], 'ldevs_prefix': data['LDEV_PREFIX'], 'gad': { 'gad_grp': data['GAD_DEV_GRP'], 'gad_res_name': data['GAD_RES_NAME'], 'is_gad': data['IS_GAD'] }, 'plural': '' if len(ldev_dict) == 1 else 's', 'pool': { 'pool_id': data['POOL_ID'] }, 'ser_pri': data['SER_PRI'], } write_yaml(clean_data) write_output('create')
def on_ok(self): pw = self.wgPass1.value global LogUser card = Smartcard.Smartcard(self.pin.value) LogUser = client.logInUser(self.bi.value, pw, card) if LogUser is not False: npyscreen.notify_wait("Valid Login", title='Sucess', form_color='VERYGOOD') self.parentApp.switchForm("Logged") else: self.text.value = "TRY AGAIN THE LOGIN" self.text.hidden = False npyscreen.notify_wait("INVALID LOGIN", title='Failure', form_color='CRITICAL')
def whenPressed(self): try: _val = self.parent.parentApp.application_logic.query_boxids()[ self.parent.wg_in_box.value] except Exception as e: _val = None if _val: self.parent.parentApp.application_logic.label(_val) npyscreen.notify_wait("Printing box reference label. Please wait.") else: npyscreen.notify_wait( "Sorry, but I cannot print you a box label if you don't have a box selected." )
def on_ok(self): if len(self.new_name.value) == 0 or len( self.new_phone_number.value) == 0: npyscreen.notify_wait( "Some of values is empty, cannot create contact. Try again please.", title="Error occurred") else: new_contact = contacts.create_contact(self.new_name.value, self.new_phone_number.value) npyscreen.notify_wait( "Contact has been created! New contact: {}".format( new_contact)) self.parentApp.update_contacts_form() self.parentApp.switchForm("MAIN")
def get_my_articles(self): try: self.titles.clear() self.articles.clear() self.page_no.value = 0 for file in os.listdir('sites/my_articles'): article_file = open('sites/my_articles/' + file, encoding='utf-8') self.titles.append(article_file.readline()) self.articles.append(article_file.readlines()) self.page.values = self.articles[0] self.title.value = self.titles[0] self.page_no.out_of = len(self.articles) except IndexError: npyscreen.notify_wait("Unexpected error ocured, please check the link you set for the download", "ERROR!", form_color="DANGER")
def on_ok(self): try: self.parentApp.filebeat_config.set_agent_tag(self.agent_tag.value) self.parentApp.filebeat_config.write_config() except exceptions.InvalidAgentTag as e: res = npyscreen.notify_ok_cancel( e.message, form_color='DANGER', ) if not res: return npyscreen.notify_wait( 'Be sure to restart the agent for changes to take effect!', form_color='WARNING' ) self.parentApp.setNextForm(None)
def main(self): Form = npyscreen.Form(name="GNU/Linux Magazine") radio_values = ["Option 1", "Option 2", "Option 3"] radio = Form.add(npyscreen.TitleSelectOne, max_height=len(radio_values), value=[0], name="Choix:", values=radio_values, scroll_exit=True) Form.edit() npyscreen.notify_wait("Valeur saisie : " + radio.get_selected_objects()[0], title="Vérification")
def Waiting_msgs(self): global REST, CLIENT while True: time.sleep(0.5) if CLIENT: try: (msgs, REST) = chat.recv_msgs(CLIENT.getsock(), REST) for msg in msgs: self.widget_messages.values.append(self.parse_msg(msg)) self.display() except ConnectionError: npyscreen.notify_wait("Connection Error:Upon message receiving.") CLIEN.getsock().close() except AttributeError: pass
def update_config(self): sub, sen = get_email() nps.notify_wait("INFO: SCANNING INBOX FOR THE LAST STORCOM REQUEST.") nps.notify_wait(f"DATE: {sen} - SUBJECT: {sub}") cfg = read_config('config/defaults.yaml') data = read_config('./vars/params.yaml') values = [] mode = data['action_type'] if mode == 'create': for i in data['devices']: for j in range(int(i['qty'])): values.append(i['size_gb']) first_id = self._form.parentApp.getForm( 'ACTION SELECT').FIRST_ID.value nps.notify_wait(f"FIRST ID= {first_id}") a, b = (zip(*to_dev_list(values, first_id))) nps.notify_wait(f"A: {a} - B: {b}") cfg['LDEVS'] = ','.join(map(str, a)) cfg['GB'] = ','.join(map(str, b)) cfg['TIER_INDEX'] = data['tier_index'] cfg['LDEV_PREFIX_INDEX'] = data['prefix_index'] cfg['REPLICA_INDEX'] = data['replica_index'] with open('config/defaults.yaml', 'w', encoding='utf-8') as handle: safe_dump(cfg, handle) reset_ldev_provisioner_form( self._form.parentApp.getForm('LDEV PROVISIONER')) elif mode == 'terminate': nps.notify_wait(str(data['devices'])) cfg['LDEVS'] = ','.join([i['lun_id'] for i in data['devices']]) cfg['GB'] = ','.join([i['size_gb'] for i in data['devices']]) self._form.parentApp.getForm( 'LDEV TERMINATOR').LDEVS.value = cfg['LDEVS'] cfg['TIER_INDEX'] = data['tier_index'] cfg['REPLICA_INDEX'] = data['replica_index'] with open('config/defaults.yaml', 'w', encoding='utf-8') as handle: safe_dump(cfg, handle) reset_ldev_terminator_form( self._form.parentApp.getForm('LDEV TERMINATOR'))
def on_ok(self): pin_cpus = [] for cpu in self.cpus_text.value.split(','): try: pin_cpus.append(int(cpu.strip())) except ValueError: npyscreen.notify_ok_cancel( 'CPU Affinity must be given as a list of integers separated by commas.', form_color='DANGER') return try: int(self.threads_text.value) except ValueError: npyscreen.notify_ok_cancel( 'Worker Threads must be given as an integer.', form_color='DANGER') return if not self.net_interface_text.value: npyscreen.notify_ok_cancel('Network Interface cannot be blank.', form_color='DANGER') return if not self.worker_name_text.value: npyscreen.notify_ok_cancel('Worker name cannot be blank.', form_color='DANGER') return if not self.host_text.value: npyscreen.notify_ok_cancel('Host name cannot be blank.', form_color='DANGER') return if self.value: self.parentApp.zeek_config.remove_worker(self.value) self.parentApp.zeek_config.add_worker( name=self.worker_name_text.value, interface=self.net_interface_text.value, host=self.host_text.value, lb_procs=self.threads_text.value, pin_cpus=tuple(pin_cpus)) # Switch back to the main interface npyscreen.notify_wait(self.worker_name_text.value + ' has been updated!', form_color='GOOD') self.parentApp.zeek_config.write_config() self.parentApp.removeForm('MAIN') self.parentApp.addForm('MAIN', ZeekNodeSettingsForm, name='Zeek Node Configuration') self.parentApp.switchForm('MAIN')
def main(self, *args, **kwargs): form = npyscreen.Form(name="Agenda") contact = form.add(ContactAutocomplete, name="Contact:") mail = form.add(npyscreen.TitleText, name="Mail:") weather = form.add(npyscreen.TitleSelectOne, max_height=len(TextUI.weather_values), value=[0], name="Temps:", values=TextUI.weather_values, scroll_exit=True) form.edit() (base, cursor) = DB.create_db() person = Contact(contact.value, (base, cursor)) person.mail = mail.value npyscreen.notify_wait("Valeur saisie : " + contact.value, title="Vérification") DB.close_db(base, cursor)
def actionHighlighted(self, act_on_this, keypress): zeek_installed, suricata_installed, filebeat_installed = zeek_profile.ProcessProfiler().is_installed(), \ suricata_profile.ProcessProfiler().is_installed(), \ filebeat_profile.ProcessProfiler().is_installed() app_mapping = {} if filebeat_installed: if zeek_installed and suricata_installed: app_mapping = zeek_and_suricata_mapping elif zeek_installed: app_mapping = zeek_only_mapping elif suricata_installed: app_mapping = suricata_only_mapping npyscreen.notify_wait(act_on_this, form_color='GOODHL') app_mapping[act_on_this]().run() exit(0)
def on_ok(self): # Attempt to commit changes updated_set = set(self._values) old_set = set(self.value.get_cards()) to_add = updated_set - old_set to_remove = old_set - updated_set for card in to_remove: self.value.unregister_card(card) errors = [] for card in to_add: if not self.value.register_card(card): errors.append(card) if len(errors) > 0: npyscreen.notify_wait("Unexpected error registering {}".format( ", ".join([hex(x) for x in errors]))) self.parentApp.switchFormPrevious()
def popup(original_containers, thr, title): """ Start the thread and display a popup of the running containers until the thread is finished """ thr.start() container_str = "" while thr.is_alive(): containers = diff(Containers(), original_containers) if containers: container_str = "" for container in containers: # TODO limit length of container_str to fit box container_str += container[0] + ": " + container[1] + "\n" npyscreen.notify_wait(container_str, title=title) time.sleep(1) return
def on_ok(self): if len(self.my_choice.value) < 1 or len( self.choosen_contact.value) < 1: npyscreen.notify_wait( "Please, to submit the form you must choose the contact and the action!", title="Error occurred") elif self.my_choice.get_selected_objects()[0] == self.menu[0]: self.parentApp.getForm("EditCont").setContact( self.choosen_contact.get_selected_objects()[0]) self.parentApp.switchForm("EditCont") elif self.my_choice.get_selected_objects()[0] == self.menu[1]: answer = npyscreen.notify_yes_no("Are you sure?", title="Delete Contact", editw=1) if answer: contacts.delete_contact(self.choosen_contact.value[0]) self.upd()
def get_gov_articles(self): try: download = npyscreen.notify_yes_no("Do you want to view government articles", 'Confirm?', editw=1) if download: self.articles.clear() self.titles.clear() self.page_no.value = 0 for file in os.listdir('sites/gov_articles'): article_file = open('sites/gov_articles/' + file, encoding='utf-8') self.titles.append(article_file.readline()) self.articles.append(article_file.readlines()) self.page.values = self.articles[0] self.title.value = self.titles[0] self.page_no.out_of = len(self.articles) except IndexError: npyscreen.notify_wait("There is no articles to view, have you tried downloading them?","WARNING", form_color="WARNING")
def popup(original_containers, thr, title): """ Start the thread and display a popup of the running containers until the thread is finished """ thr.start() container_str = "" while thr.is_alive(): containers = diff(Containers(), original_containers) if containers: container_str = "" for container in containers: # TODO limit length of container_str to fit box container_str += container[0]+": "+container[1]+"\n" npyscreen.notify_wait(container_str, title=title) time.sleep(1) return
def afterEditing(self): selected_option = self.parentApp.SELECTED_RESULT try: selection = self.parentApp.RESULTS.get(selected_option) if not selection: npyscreen.notify_wait("Please select a ROM by hitting ENTER on your selection", "Selection error") self.search = self.parentApp.SCRAPER_OBJ download_thread = ThreadDownload(selection=selection) download_thread.start() # self.download_link = self.search.get_link(selection) while download_thread.is_alive(): npyscreen.notify("Please wait while Romulus downloads this ROM...", "Downloading") # self.d = Download() # self.d.download(self.download_link, platform=selection.system) npyscreen.notify("The ROM is now available on EmulationStation", "Success") self.parentApp.setNextForm('MAIN') except TypeError: npyscreen.notify_wait('Please hit ENTER on your selection to select it', 'Error')
def on_ok(self): if re.match(r'^Private_key_', self.fp.value.split('/')[-1]): fp = self.fp.value fp2 = self.fp2.value filename = self.filename.value npyscreen.notify("Loading") global LogUser diff = client.diff(LogUser, filename, fp, fp2) values = [] try: while 1: values.append(diff.next()) except: pass self.parentApp.getForm("FileDiffDisplay").values = values self.parentApp.switchForm("FileDiffDisplay") else: npyscreen.notify_wait('Invalid Private key location/format (Private_key_<username>)')
def validateInput(self): #Validate the input variables #Get the variables args = {} for input_item in self._value["input"]: name = input_item["name"] if self.get_widget(name).value: args[name] = self.get_widget(name).value if not (self.submodule._input.requirementsMet(args)): nps.notify_wait( "Not all required input items for this module have been entered. Please check all fields.", title="Error", form_color='STANDOUT', wrap=True, wide=True) return False else: return True
def popup(original_tools, branch, thr, title): """ Start the thread and display a popup of the tools being added until the thread is finished """ thr.start() tool_str = 'Adding tools...' npyscreen.notify_wait(tool_str, title=title) while thr.is_alive(): tools = diff(ManifestTools(), original_tools) if tools: tool_str = '' for tool in tools: pre_tool = 'Added: ' + branch + '/' + tool + '\n' tool_str = pre_tool + tool_str npyscreen.notify_wait(tool_str, title=title) time.sleep(1) return
def popup(original_tools, branch, thr, title): """ Start the thread and display a popup of the tools being added until the thread is finished """ thr.start() tool_str = "Adding tools..." npyscreen.notify_wait(tool_str, title=title) while thr.is_alive(): tools = diff(Tools(), original_tools) if tools: tool_str = "" for tool in tools: # TODO limit length of tool_str to fit box tool_str = "Added: "+branch+"/"+tool+"\n"+tool_str npyscreen.notify_wait(tool_str, title=title) time.sleep(1) return
def on_ok(self): if self.wgPass1.value is '' or self.wgPass2.value is '' or\ self.wgUsername is '': npyscreen.notify_wait("Please correctly fill in all fields", title='Error', form_color='WARNING') card = Smartcard.Smartcard(self.pin.value) if self.wgPass2.value != self.wgPass1.value: npyscreen.notify_wait("Not the same password", title='Password Error', form_color='WARNING') elif excludeFromDict(self.wgPass1.value) or len(self.wgPass1.value) < 5: npyscreen.notify_wait("Weak Password. You can do better. We believe in you") elif client.registUser(self.bi.value, self.wgPass1.value, self.mail.value, card): npyscreen.notify_wait("Register for user %s successful\nPrivate Key stored in PrivateKeys/Private_key_<username>" % self.wgUsername.value, title="Success", form_color="VERYGOOD") self.parentApp.switchForm("MAIN") else: npyscreen.notify_wait("There was a problem with your regist", title="Failure", form_color="WARNING")
def popup(original, orig_type, thr, title): """ Start the thread and display a popup of info until the thread is finished """ thr.start() info_str = "" while thr.is_alive(): if orig_type == 'containers': info = diff(Containers(), original) elif orig_type == 'images': info = diff(Images(), original) if info: info_str = "" for entry in info: # TODO limit length of info_str to fit box info_str += entry[0]+": "+entry[1]+"\n" npyscreen.notify_wait(info_str, title=title) time.sleep(1) return