def configure_node(self, input_block): """ @param input_block: its a totally unmaintainable dict @return: None """ store = self.getStore('configure_node') try: node_data = store.find(Node, 1 == Node.id).one() except NotOneError: store.close() raise NodeNotFound if node_data is None: store.close() raise NodeNotFound node_data.description = input_block['description'] node_data.name = input_block['name'] node_data.public_site = input_block['public_site'] node_data.hidden_service = input_block['hidden_service'] node_data.public_stats_update_time = int(input_block['public_stats_update_time']) node_data.private_stats_update_time = int(input_block['private_stats_update_time']) node_data.email = input_block['email'] node_data.languages = input_block['languages'] log.msg("Updated node main configuration") store.commit() store.close()
def update(self, context_gus, context_dict): """ @param context_gus: the universal unique identifier @param context_dict: the information fields that need to be update, here is supported to be already validated, sanitized and logically verified by handlers @return: None or Exception on error """ log.debug("[D] %s %s " % (__file__, __name__), "Context update of", context_gus) store = self.getStore('context update') try: requested_c = store.find(Context, Context.context_gus == unicode(context_gus)).one() except NotOneError: store.close() raise ContextGusNotFound if requested_c is None: store.close() raise ContextGusNotFound try: requested_c._import_dict(context_dict) except KeyError: store.rollback() store.close() raise InvalidInputFormat("Import failed near the Storm") requested_c.update_date = gltime.utcDateNow() store.commit() log.msg("Updated context %s in %s, created in %s" % (requested_c.name, requested_c.update_date, requested_c.creation_date) ) store.close()
def new(self, context_dict): """ @param context_dict: a dictionary containing the expected field of a context, is called and define as contextDescriptionDict @return: context_gus, the universally unique identifier of the context """ log.debug("[D] %s %s " % (__file__, __name__), "Context new", context_dict) store = self.getStore('context new') cntx = Context() cntx.context_gus = idops.random_context_gus() cntx.node_id = 1 cntx.creation_date = gltime.utcDateNow() cntx.update_date = gltime.utcDateNow() cntx.last_activity = gltime.utcDateNow() cntx.receivers = [] try: cntx._import_dict(context_dict) except KeyError: store.rollback() store.close() raise InvalidInputFormat("Import failed near the Storm") store.add(cntx) log.msg("Created context %s at the %s" % (cntx.name, cntx.creation_date) ) store.commit() store.close() # return context_dict return cntx.context_gus
def _import_dict(self, context_dict): self.name = context_dict['name'] self.fields = context_dict['fields'] self.description = context_dict['description'] self.selectable_receiver = context_dict['selectable_receiver'] self.escalation_threshold = context_dict['escalation_threshold'] self.tip_max_access = context_dict['tip_max_access'] self.tip_timetolive = context_dict['tip_timetolive'] self.file_max_download = context_dict['file_max_download'] if self.selectable_receiver and self.escalation_threshold: log.msg("[!] Selectable receiver feature and escalation threshold can't work both: threshold ignored") self.escalation_threshold = 0
def configure(self, input_dict): """ @param input_dict: input dictionary @return: None """ store = self.getStore() try: node_data = store.find(Node, 1 == Node.id).one() except NotOneError: raise NodeNotFound if node_data is None: raise NodeNotFound cls_info = get_cls_info(Node) for name in cls_info.attributes.iterkeys(): if name in input_dict: setattr(node_data, name, input_dict[name]) log.msg("Updated node main configuration")
def delete_context(self, context_gus): """ @param context_gus: the universal unique identifier of the context @return: None if is deleted correctly, or raise an exception if something is wrong. """ from globaleaks.models.receiver import Receiver log.debug("[D] %s %s " % (__file__, __name__), "Context delete of", context_gus) # first, perform existence checks, this would avoid continuous try/except here if not self.exists(context_gus): raise ContextGusNotFound # delete all the reference to the context in the receivers receiver_iface = Receiver() # this is not a yield because getStore is not yet called! unlinked_receivers = receiver_iface.unlink_context(context_gus) # TODO - delete all the tips associated with the context # TODO - delete all the jobs associated with the context # TODO - delete all the stats associated with the context # TODO - align all the receivers present in self.receivers store = self.getStore('context delete') try: requested_c = store.find(Context, Context.context_gus == unicode(context_gus)).one() except NotOneError: store.close() raise ContextGusNotFound if requested_c is None: store.close() raise ContextGusNotFound store.remove(requested_c) store.commit() store.close() log.msg("Deleted context %s, created in %s used by %d receivers" % (requested_c.name, requested_c.creation_date, unlinked_receivers) )
self.update_date = gltime.utcTimeNow() self.last_activity = gltime.utcTimeNow() self.receivers = [] try: self._import_dict(context_dict) except KeyError, e: raise InvalidInputFormat("Context Import failed (missing %s)" % e) except TypeError, e: raise InvalidInputFormat("Context Import failed (wrong %s)" % e) if self.selectable_receiver and self.escalation_threshold: raise InvalidInputFormat("selectable_receiver and escalation_threshold are mutually exclusive") self.store.add(self) log.msg("Created context %s at the %s" % (self.name, self.creation_date)) return self._description_dict() def update(self, context_gus, context_dict): """ @param context_gus: the universal unique identifier @param context_dict: the information fields that need to be update, here is supported to be already validated, sanitized and logically verified by handlers @return: None or Exception on error """ try: requested_c = self.store.find(Context, Context.context_gus == unicode(context_gus)).one() except NotOneError:
try: node_data = self.store.find(Node, 1 == Node.id).one() except NotOneError: raise NodeNotFound if node_data is None: raise NodeNotFound try: node_data._import_dict(input_dict) except KeyError, e: raise InvalidInputFormat("Node update fail (missing %s)" % e) except TypeError, e: raise InvalidInputFormat("Node update fail (wrong %s)" % e) log.msg("Updated node main configuration") return node_data._description_dict() def get_single(self): node_list = self.store.find(Node) if node_list.count() != 1: raise NotImplementedError("Unexpected condition: More than one Node configured (%d)" % node_list.count()) return node_list[0]._description_dict() def _import_dict(self, input_dict): self.description = input_dict['description']