def signal_assistant_apply(self, _): self._close_ready = False # have to do it this way because the next page will be selected when the apply signal is complete set_current_page = lambda page_name: self.assistant.set_current_page(max(0, self._page_titles[page_name] - 1)) # get and validate the campaign name campaign_name = self.gobjects['entry_campaign_name'].get_text() campaign_name = campaign_name.strip() if not campaign_name: gui_utilities.show_dialog_error('Invalid Campaign Name', self.parent, 'A unique and valid campaign name must be specified.') set_current_page('Basic Settings') return True properties = {} # validate the credential validation regular expressions for field in ('username', 'password', 'mfa_token'): regex = self.gobjects['entry_validation_regex_' + field].get_text() if regex: try: re.compile(regex) except re.error: label = self.gobjects['label_validation_regex_' + field].get_text() gui_utilities.show_dialog_error('Invalid Regex', self.parent, "The '{0}' regular expression is invalid.".format(label)) return True else: regex = None # keep empty strings out of the database properties['credential_regex_' + field] = regex # validate the company company_id = None if self.gobjects['radiobutton_company_existing'].get_active(): company_id = self._get_company_existing_id() if company_id is None: gui_utilities.show_dialog_error('Invalid Company', self.parent, 'A valid existing company must be specified.') set_current_page('Company') return True elif self.gobjects['radiobutton_company_new'].get_active(): company_id = self._get_company_new_id() if company_id is None: gui_utilities.show_dialog_error('Invalid Company', self.parent, 'The new company settings are invalid.') set_current_page('Company') return True # get and validate the campaign expiration expiration = None if self.gobjects['checkbutton_expire_campaign'].get_property('active'): expiration = datetime.datetime.combine( gui_utilities.gtk_calendar_get_pydate(self.gobjects['calendar_campaign_expiration']), self._expiration_time.time ) expiration = utilities.datetime_local_to_utc(expiration) if self.is_new_campaign and expiration <= datetime.datetime.now(): gui_utilities.show_dialog_error('Invalid Campaign Expiration', self.parent, 'The expiration date is set in the past.') set_current_page('Expiration') return True # point of no return campaign_description = self.get_entry_value('campaign_description') if self.campaign_id: properties['name'] = self.campaign_name properties['description'] = campaign_description cid = self.campaign_id else: try: cid = self.application.rpc('campaign/new', campaign_name, description=campaign_description) except advancedhttpserver.RPCError as error: if not error.is_remote_exception: raise error if not error.remote_exception['name'] == 'exceptions.ValueError': raise error error_message = error.remote_exception.get('message', 'an unknown error occurred').capitalize() + '.' gui_utilities.show_dialog_error('Failed To Create Campaign', self.parent, error_message) set_current_page('Basic Settings') return True self.application.emit('campaign-created', cid) properties['campaign_type_id'] = self._get_tag_from_combobox(self.gobjects['combobox_campaign_type'], 'campaign_types') properties['company_id'] = company_id properties['expiration'] = expiration properties['max_credentials'] = (1 if self.gobjects['checkbutton_reject_after_credentials'].get_property('active') else None) self.application.rpc('db/table/set', 'campaigns', cid, tuple(properties.keys()), tuple(properties.values())) should_subscribe = self.gobjects['checkbutton_alert_subscribe'].get_property('active') if should_subscribe != self.application.rpc('campaign/alerts/is_subscribed', cid): if should_subscribe: self.application.rpc('campaign/alerts/subscribe', cid) else: self.application.rpc('campaign/alerts/unsubscribe', cid) self.application.emit('campaign-changed', cid) self._close_ready = True return
def signal_assistant_apply(self, _): self._close_ready = False # have to do it this way because the next page will be selected when the apply signal is complete set_current_page = lambda page_name: self.assistant.set_current_page(max(0, self._page_titles[page_name] - 1)) # get and validate the campaign name campaign_name = self.gobjects['entry_campaign_name'].get_text() campaign_name = campaign_name.strip() if not campaign_name: gui_utilities.show_dialog_error('Invalid Campaign Name', self.parent, 'A unique and valid campaign name must be specified.') set_current_page('Basic Settings') return True # validate the company company_id = None if self.gobjects['radiobutton_company_existing'].get_active(): company_id = self._get_company_existing_id() if company_id is None: gui_utilities.show_dialog_error('Invalid Company', self.parent, 'A valid existing company must be specified.') set_current_page('Company') return True elif self.gobjects['radiobutton_company_new'].get_active(): company_id = self._get_company_new_id() if company_id is None: gui_utilities.show_dialog_error('Invalid Company', self.parent, 'The new company settings are invalid.') set_current_page('Company') return True # get and validate the campaign expiration expiration = None if self.gobjects['checkbutton_expire_campaign'].get_property('active'): expiration = datetime.datetime.combine( gui_utilities.gtk_calendar_get_pydate(self.gobjects['calendar_campaign_expiration']), datetime.time( int(self.gobjects['spinbutton_campaign_expiration_hour'].get_value()), int(self.gobjects['spinbutton_campaign_expiration_minute'].get_value()) ) ) expiration = utilities.datetime_local_to_utc(expiration) if self.is_new_campaign and expiration <= datetime.datetime.now(): gui_utilities.show_dialog_error('Invalid Campaign Expiration', self.parent, 'The expiration date is set in the past.') set_current_page('Expiration') return True properties = {} # point of no return campaign_description = self.gobjects['entry_campaign_description'].get_text() campaign_description = campaign_description.strip() if campaign_description == '': campaign_description = None if self.campaign_id: properties['name'] = self.campaign_name properties['description'] = campaign_description cid = self.campaign_id else: try: cid = self.application.rpc('campaign/new', campaign_name, description=campaign_description) except AdvancedHTTPServer.AdvancedHTTPServerRPCError as error: if not error.is_remote_exception: raise error if not error.remote_exception['name'] == 'exceptions.ValueError': raise error error_message = error.remote_exception.get('message', 'an unknown error occurred').capitalize() + '.' gui_utilities.show_dialog_error('Failed To Create Campaign', self.parent, error_message) set_current_page('Basic Settings') return True properties['campaign_type_id'] = self._get_tag_from_combobox(self.gobjects['combobox_campaign_type'], 'campaign_types') properties['company_id'] = company_id properties['expiration'] = expiration properties['reject_after_credentials'] = self.gobjects['checkbutton_reject_after_credentials'].get_property('active') self.application.rpc('db/table/set', 'campaigns', cid, properties.keys(), properties.values()) should_subscribe = self.gobjects['checkbutton_alert_subscribe'].get_property('active') if should_subscribe != self.application.rpc('campaign/alerts/is_subscribed', cid): if should_subscribe: self.application.rpc('campaign/alerts/subscribe', cid) else: self.application.rpc('campaign/alerts/unsubscribe', cid) self.application.emit('campaign-changed', cid) self._close_ready = True return
def signal_assistant_apply(self, _): self._close_ready = False # have to do it this way because the next page will be selected when the apply signal is complete set_current_page = lambda page_name: self.assistant.set_current_page(max(0, self._page_titles[page_name] - 1)) # get and validate the campaign name campaign_name = self.gobjects['entry_campaign_name'].get_text() campaign_name = campaign_name.strip() if not campaign_name: gui_utilities.show_dialog_error('Invalid Campaign Name', self.parent, 'A unique and valid campaign name must be specified.') set_current_page('Basic Settings') return True properties = {} # validate the credential validation regular expressions for field in ('username', 'password', 'mfa_token'): regex = self.gobjects['entry_validation_regex_' + field].get_text() if regex: try: re.compile(regex) except re.error: label = self.gobjects['label_validation_regex_' + field].get_text() gui_utilities.show_dialog_error('Invalid Regex', self.parent, "The '{0}' regular expression is invalid.".format(label)) return True else: regex = None # keep empty strings out of the database properties['credential_regex_' + field] = regex # validate the company company_id = None if self.gobjects['radiobutton_company_existing'].get_active(): company_id = self._get_company_existing_id() if company_id is None: gui_utilities.show_dialog_error('Invalid Company', self.parent, 'A valid existing company must be specified.') set_current_page('Company') return True elif self.gobjects['radiobutton_company_new'].get_active(): company_id = self._get_company_new_id() if company_id is None: gui_utilities.show_dialog_error('Invalid Company', self.parent, 'The new company settings are invalid.') set_current_page('Company') return True # get and validate the campaign expiration expiration = None if self.gobjects['checkbutton_expire_campaign'].get_property('active'): expiration = datetime.datetime.combine( gui_utilities.gtk_calendar_get_pydate(self.gobjects['calendar_campaign_expiration']), self._expiration_time.time ) expiration = utilities.datetime_local_to_utc(expiration) if self.is_new_campaign and expiration <= datetime.datetime.now(): gui_utilities.show_dialog_error('Invalid Campaign Expiration', self.parent, 'The expiration date is set in the past.') set_current_page('Expiration') return True # point of no return campaign_description = self.get_entry_value('campaign_description') if self.campaign_id: properties['name'] = self.campaign_name properties['description'] = campaign_description cid = self.campaign_id else: try: cid = self.application.rpc('campaign/new', campaign_name, description=campaign_description) properties['name'] = campaign_name except advancedhttpserver.RPCError as error: if not error.is_remote_exception: raise error if not error.remote_exception['name'] == 'exceptions.ValueError': raise error error_message = error.remote_exception.get('message', 'an unknown error occurred').capitalize() + '.' gui_utilities.show_dialog_error('Failed To Create Campaign', self.parent, error_message) set_current_page('Basic Settings') return True self.application.emit('campaign-created', cid) properties['campaign_type_id'] = self._get_tag_from_combobox(self.gobjects['combobox_campaign_type'], 'campaign_types') properties['company_id'] = company_id properties['expiration'] = expiration properties['max_credentials'] = (1 if self.gobjects['checkbutton_reject_after_credentials'].get_property('active') else None) self.application.rpc('db/table/set', 'campaigns', cid, tuple(properties.keys()), tuple(properties.values())) should_subscribe = self.gobjects['checkbutton_alert_subscribe'].get_property('active') if should_subscribe != self.application.rpc('campaign/alerts/is_subscribed', cid): if should_subscribe: self.application.rpc('campaign/alerts/subscribe', cid) else: self.application.rpc('campaign/alerts/unsubscribe', cid) self.application.emit('campaign-changed', cid) old_cid = self.config.get('campaign_id') self.config['campaign_id'] = cid self.config['campaign_name'] = properties['name'] _kpm_pathing = self._get_kpm_path() if all(_kpm_pathing): if not self.application.main_tabs['mailer'].emit('message-data-import', _kpm_pathing.kpm_file, _kpm_pathing.destination_folder): gui_utilities.show_dialog_info('Failure', self.parent, 'Failed to import the message configuration.') else: gui_utilities.show_dialog_info('Success', self.parent, 'Successfully imported the message configuration.') url_model, url_iter = self.gobjects['treeselection_url_selector'].get_selected() if url_iter: selected_row = [] for column_n in range(0, url_model.get_n_columns()): selected_row.append(url_model.get_value(url_iter, column_n)) selected_row = _ModelNamedRow(*selected_row) self.config['mailer.webserver_url'] = selected_row.url self.application.emit('campaign-set', old_cid, cid) self._close_ready = True return
def signal_assistant_apply(self, _): self._close_ready = False # have to do it this way because the next page will be selected when the apply signal is complete set_current_page = lambda page_name: self.assistant.set_current_page(max(0, self._page_titles[page_name] - 1)) # get and validate the campaign name campaign_name = self.gobjects["entry_campaign_name"].get_text() campaign_name = campaign_name.strip() if not campaign_name: gui_utilities.show_dialog_error( "Invalid Campaign Name", self.parent, "A unique and valid campaign name must be specified." ) set_current_page("Basic Settings") return True # validate the company company_id = None if self.gobjects["radiobutton_company_existing"].get_active(): company_id = self._get_company_existing_id() if company_id is None: gui_utilities.show_dialog_error( "Invalid Company", self.parent, "A valid existing company must be specified." ) set_current_page("Company") return True elif self.gobjects["radiobutton_company_new"].get_active(): company_id = self._get_company_new_id() if company_id is None: gui_utilities.show_dialog_error("Invalid Company", self.parent, "The new company settings are invalid.") set_current_page("Company") return True # get and validate the campaign expiration expiration = None if self.gobjects["checkbutton_expire_campaign"].get_property("active"): expiration = datetime.datetime.combine( gui_utilities.gtk_calendar_get_pydate(self.gobjects["calendar_campaign_expiration"]), datetime.time( int(self.gobjects["spinbutton_campaign_expiration_hour"].get_value()), int(self.gobjects["spinbutton_campaign_expiration_minute"].get_value()), ), ) expiration = utilities.datetime_local_to_utc(expiration) if expiration <= datetime.datetime.now(): gui_utilities.show_dialog_error( "Invalid Campaign Expiration", self.parent, "The expiration date is set in the past." ) set_current_page("Expiration") return True properties = {} # point of no return campaign_description = self.gobjects["entry_campaign_description"].get_text() campaign_description = campaign_description.strip() if campaign_description == "": campaign_description = None if self.campaign_id: properties["name"] = self.campaign_name properties["description"] = campaign_description cid = self.campaign_id else: try: cid = self.application.rpc("campaign/new", campaign_name, description=campaign_description) except AdvancedHTTPServer.AdvancedHTTPServerRPCError as error: if not error.is_remote_exception: raise error if not error.remote_exception["name"] == "exceptions.ValueError": raise error error_message = error.remote_exception.get("message", "an unknown error occurred").capitalize() + "." gui_utilities.show_dialog_error("Failed To Create Campaign", self.parent, error_message) set_current_page("Basic Settings") return True properties["campaign_type_id"] = self._get_tag_from_combobox( self.gobjects["combobox_campaign_type"], "campaign_types" ) properties["company_id"] = company_id properties["expiration"] = expiration properties["reject_after_credentials"] = self.gobjects["checkbutton_reject_after_credentials"].get_property( "active" ) self.application.rpc("db/table/set", "campaigns", cid, properties.keys(), properties.values()) should_subscribe = self.gobjects["checkbutton_alert_subscribe"].get_property("active") if should_subscribe != self.application.rpc("campaign/alerts/is_subscribed", cid): if should_subscribe: self.application.rpc("campaign/alerts/subscribe", cid) else: self.application.rpc("campaign/alerts/unsubscribe", cid) self._close_ready = True return
def signal_assistant_apply(self, _): self._close_ready = False # have to do it this way because the next page will be selected when the apply signal is complete set_current_page = lambda page_name: self.assistant.set_current_page( max(0, self._page_titles[page_name] - 1)) # get and validate the campaign name campaign_name = self.gobjects['entry_campaign_name'].get_text() campaign_name = campaign_name.strip() if not campaign_name: gui_utilities.show_dialog_error( 'Invalid Campaign Name', self.parent, 'A unique and valid campaign name must be specified.') set_current_page('Basic Settings') return True # validate the company company_id = None if self.gobjects['radiobutton_company_existing'].get_active(): company_id = self._get_company_existing_id() if company_id is None: gui_utilities.show_dialog_error( 'Invalid Company', self.parent, 'A valid existing company must be specified.') set_current_page('Company') return True elif self.gobjects['radiobutton_company_new'].get_active(): company_id = self._get_company_new_id() if company_id is None: gui_utilities.show_dialog_error( 'Invalid Company', self.parent, 'The new company settings are invalid.') set_current_page('Company') return True # get and validate the campaign expiration expiration = None if self.gobjects['checkbutton_expire_campaign'].get_property('active'): expiration = datetime.datetime.combine( gui_utilities.gtk_calendar_get_pydate( self.gobjects['calendar_campaign_expiration']), datetime.time( int(self.gobjects['spinbutton_campaign_expiration_hour']. get_value()), int(self.gobjects['spinbutton_campaign_expiration_minute']. get_value()))) expiration = utilities.datetime_local_to_utc(expiration) if self.is_new_campaign and expiration <= datetime.datetime.now(): gui_utilities.show_dialog_error( 'Invalid Campaign Expiration', self.parent, 'The expiration date is set in the past.') set_current_page('Expiration') return True properties = {} # point of no return campaign_description = self.gobjects[ 'entry_campaign_description'].get_text() campaign_description = campaign_description.strip() if campaign_description == '': campaign_description = None if self.campaign_id: properties['name'] = self.campaign_name properties['description'] = campaign_description cid = self.campaign_id else: try: cid = self.application.rpc('campaign/new', campaign_name, description=campaign_description) except AdvancedHTTPServer.AdvancedHTTPServerRPCError as error: if not error.is_remote_exception: raise error if not error.remote_exception[ 'name'] == 'exceptions.ValueError': raise error error_message = error.remote_exception.get( 'message', 'an unknown error occurred').capitalize() + '.' gui_utilities.show_dialog_error('Failed To Create Campaign', self.parent, error_message) set_current_page('Basic Settings') return True properties['campaign_type_id'] = self._get_tag_from_combobox( self.gobjects['combobox_campaign_type'], 'campaign_types') properties['company_id'] = company_id properties['expiration'] = expiration properties['reject_after_credentials'] = self.gobjects[ 'checkbutton_reject_after_credentials'].get_property('active') self.application.rpc('db/table/set', 'campaigns', cid, properties.keys(), properties.values()) should_subscribe = self.gobjects[ 'checkbutton_alert_subscribe'].get_property('active') if should_subscribe != self.application.rpc( 'campaign/alerts/is_subscribed', cid): if should_subscribe: self.application.rpc('campaign/alerts/subscribe', cid) else: self.application.rpc('campaign/alerts/unsubscribe', cid) self.application.emit('campaign-changed', cid) self._close_ready = True return
def resolve_created(self, info, **kwargs): return utilities.datetime_local_to_utc(datetime.datetime.fromtimestamp(os.path.getctime(self._disk_path)))