def delete(self, dataset_id): """ Delete a dataset from the list of datasets """ # Verify the decision print_warning( 'Warning! The connections and models created from this dataset WILL be deleted. However, all the labels created from this dataset WILL NOT be deleted (due to their associations with third-party modules). You should delete the labels by hand.' ) input = raw_input( 'Are you sure you want to delete this dataset? (YES/NO): ') if input != 'YES': return False # Before deleting the dataset, delete the connections from stf.core.connections import __group_of_group_of_connections__ __group_of_group_of_connections__.delete_group_of_connections( dataset_id) # Before deleting the dataset, delete the models from stf.core.models import __groupofgroupofmodels__ __groupofgroupofmodels__.delete_group_of_models_with_dataset_id( dataset_id) try: # Now delete the dataset self.datasets.pop(dataset_id) print_info("Deleted dataset #{0}".format(dataset_id)) # If it was the current dataset, we have no current if self.current and self.current.get_id() == dataset_id: self.current = False except ValueError: print_info('You should give an dataset id') except KeyError: print_info('Dataset ID non existant.')
def delete(self, dataset_id): """ Delete a dataset from the list of datasets """ # Verify the decision print_warning('Warning! The connections and models created from this dataset WILL be deleted. However, all the labels created from this dataset WILL NOT be deleted (due to their associations with third-party modules). You should delete the labels by hand.') input = raw_input('Are you sure you want to delete this dataset? (YES/NO): ') if input != 'YES': return False # Before deleting the dataset, delete the connections from stf.core.connections import __group_of_group_of_connections__ __group_of_group_of_connections__.delete_group_of_connections(dataset_id) # Before deleting the dataset, delete the models from stf.core.models import __groupofgroupofmodels__ __groupofgroupofmodels__.delete_group_of_models_with_dataset_id(dataset_id) try: # Now delete the dataset self.datasets.pop(dataset_id) print_info("Deleted dataset #{0}".format(dataset_id)) # If it was the current dataset, we have no current if self.current and self.current.get_id() == dataset_id: self.current = False except ValueError: print_info('You should give an dataset id') except KeyError: print_info('Dataset ID non existant.')
def delete(self, dataset_id): """ Delete a dataset from the list of datasets """ # Before deleting the dataset, delete the connections from stf.core.connections import __group_of_group_of_connections__ __group_of_group_of_connections__.delete_group_of_connections( dataset_id) # Before deleting the dataset, delete the models from stf.core.models import __groupofgroupofmodels__ __groupofgroupofmodels__.delete_group_of_models_with_dataset_id( dataset_id) try: # Now delete the dataset self.datasets.pop(dataset_id) print_info("Deleted dataset #{0}".format(dataset_id)) # If it was the current dataset, we have no current if self.current and self.current.get_id() == dataset_id: self.current = False except ValueError: print_info('You should give an dataset id') except KeyError: print_info('Dataset ID non existant.')
def cmd_connections(self, *args): parser = argparse.ArgumentParser(prog="connections", description="Manage connections", epilog="Manage connections") parser.add_argument('-l', '--list', action="store_true", help="List all existing connections") parser.add_argument('-g', '--generate', action="store_true", help="Generate the connections from the binetflow file in the current dataset") parser.add_argument('-d', '--delete', metavar="group_of_connections_id", help="Delete the group of connections.") parser.add_argument('-L', '--listconnections', metavar="group_connection_id", help="List the connections inside a group.") parser.add_argument('-F', '--showflows', metavar="connection_id", type=str, help="List the flows inside a specific connection.") parser.add_argument('-f', '--filter', metavar="filter", nargs='+', help="Use this filter to work with connections. Format: \"variable[!=<>]value\". You can use the variables: name, flowamount. Example: \"name=tcp\". Or \"flowamount<10\"") parser.add_argument('-D', '--deleteconnection', metavar="group_connection_id", help="Delete a connection from the group. This is the id of the group. Use -i to give the connection id to delete (4-tuple) or -f to use a filter.") parser.add_argument('-i', '--connectionid', metavar="connection_id", help="Use this connection id (4-tuple). Commonly used with -D.") parser.add_argument('-M', '--deleteconnectionifmodel', metavar="group_connection_id", help="Delete the connections from the group which models were deleted. Only give the connection group id. Useful to clean the database of connections that are not used.") parser.add_argument('-t', '--trimgroupid', metavar="group_connection_id", help="Trim all the connections so that each connection has at most 100 flows. Only give the connection group id. Useful to have some info about the connections but not all the data.") parser.add_argument('-a', '--amounttotrim', metavar="amount_to_trim", type=int, help="Define the amount of flows to trim with -t. By default 100.") parser.add_argument('-C', '--countconnections', metavar="group_connection_id", help="Count the amount of connections matching the filter. This is the id of the group.") parser.add_argument('-H', '--histogram', metavar="connection_id", type=str, help="Show the histograms for state len, duration and size of all the flows in this connection id (4-tuple).") try: args = parser.parse_args(args) except: return # Subcomand to list if args.list: __group_of_group_of_connections__.list_group_of_connections() # Subcomand to create a new group of connections elif args.generate: __group_of_group_of_connections__.create_group_of_connections() __database__.root._p_changed = True # Subcomand to delete a group of connections elif args.delete: __group_of_group_of_connections__.delete_group_of_connections(int(args.delete)) __database__.root._p_changed = True # Subcomand to list the connections in a group elif args.listconnections: filter = '' try: filter = args.filter except AttributeError: pass try: __group_of_group_of_connections__.list_connections_in_group(int(args.listconnections), filter) except ValueError: print_error('The id of the group of connections should be an integer.') __database__.root._p_changed = True # Subcomand to show the flows in a connection elif args.showflows: filter = '' try: filter = args.filter except AttributeError: pass __group_of_group_of_connections__.show_flows_in_connnection(args.showflows, filter) __database__.root._p_changed = True # Subcomand to delete a connection from a group by id elif args.deleteconnection: if args.connectionid: # By id __group_of_group_of_connections__.delete_a_connection_from_the_group_by_id(args.deleteconnection, args.connectionid) elif args.filter: __group_of_group_of_connections__.delete_a_connection_from_the_group_by_filter(args.deleteconnection, args.filter) __database__.root._p_changed = True # Subcomand to delete the connections from a group which models were deleted elif args.deleteconnectionifmodel: __group_of_group_of_connections__.delete_a_connection_from_the_group_if_model_deleted(int(args.deleteconnectionifmodel)) __database__.root._p_changed = True # Subcomand to trim the amount of flows in the connections elif args.trimgroupid: # Now just trim to keep 100 flows if args.amounttotrim: amount_to_trim = args.amounttotrim else: amount_to_trim = 100 __group_of_group_of_connections__.trim_flows(int(args.trimgroupid), amount_to_trim) __database__.root._p_changed = True # Subcomand to count the amount of models elif args.countconnections: try: filter = args.filter except AttributeError: pass __group_of_group_of_connections__.count_connections_in_group(args.countconnections, filter) __database__.root._p_changed = True # Subcomand to show the histograms elif args.histogram: __group_of_group_of_connections__.show_histograms(args.histogram)
def cmd_connections(self, *args): parser = argparse.ArgumentParser(prog="connections", description="Manage connections", epilog="Manage connections") parser.add_argument('-l', '--list', action="store_true", help="List all existing connections") parser.add_argument('-g', '--generate', action="store_true", help="Generate the connections from the binetflow file in the current dataset") parser.add_argument('-d', '--delete', metavar="group_of_connections_id", help="Delete the group of connections.") parser.add_argument('-L', '--listconnections', metavar="group_connection_id", help="List the connections inside a group.") parser.add_argument('-F', '--showflows', metavar="connection_id", type=str, help="List the flows inside a specific connection.") parser.add_argument('-f', '--filter', metavar="filter", nargs='+', help="Use this filter to work with connections. Format: \"variable[!=<>]value\". You can use the variables: name, flowamount. Example: \"name=tcp\". Or \"flowamount<10\"") parser.add_argument('-D', '--deleteconnection', metavar="group_connection_id", help="Delete a connection from the group. This is the id of the group. Use -i to give the connection id to delete (4-tuple) or -f to use a filter.") parser.add_argument('-i', '--connectionid', metavar="connection_id", help="Use this connection id (4-tuple). Commonly used with -D.") parser.add_argument('-M', '--deleteconnectionifmodel', metavar="group_connection_id", help="Delete the connections from the group which models were deleted. Only give the connection group id. Useful to clean the database of connections that are not used.") parser.add_argument('-t', '--trimgroupid', metavar="group_connection_id", help="Trim all the connections so that each connection has at most 100 flows. Only give the connection group id. Useful to have some info about the connections but not all the data.") parser.add_argument('-a', '--amounttotrim', metavar="amount_to_trim", type=int, help="Define the amount of flows to trim with -t. By default 100.") parser.add_argument('-C', '--countconnections', metavar="group_connection_id", help="Count the amount of connections matching the filter. This is the id of the group.") parser.add_argument('-H', '--histogram', metavar="connection_id", type=str, help="Show the histograms for state len, duration and size of all the flows in this connection id (4-tuple).") try: args = parser.parse_args(args) except: return # Subcomand to list if args.list: __group_of_group_of_connections__.list_group_of_connections() # Subcomand to create a new group of connections elif args.generate: __group_of_group_of_connections__.create_group_of_connections() __database__.root._p_changed = True # Subcomand to delete a group of connections elif args.delete: __group_of_group_of_connections__.delete_group_of_connections(int(args.delete)) __database__.root._p_changed = True # Subcomand to list the connections in a group elif args.listconnections: filter = '' try: filter = args.filter except AttributeError: pass try: __group_of_group_of_connections__.list_connections_in_group(int(args.listconnections), filter) except ValueError: print_error('The id of the group of connections should be an integer.') __database__.root._p_changed = True # Subcomand to show the flows in a connection elif args.showflows: filter = '' try: filter = args.filter except AttributeError: pass __group_of_group_of_connections__.show_flows_in_connnection(args.showflows, filter) __database__.root._p_changed = True # Subcomand to delete a connection from a group by id elif args.deleteconnection: if args.connectionid: # By id __group_of_group_of_connections__.delete_a_connection_from_the_group_by_id(args.deleteconnection, args.connectionid) elif args.filter: __group_of_group_of_connections__.delete_a_connection_from_the_group_by_filter(args.deleteconnection, args.filter) __database__.root._p_changed = True # Subcomand to delete the connections from a group which models were deleted elif args.deleteconnectionifmodel: __group_of_group_of_connections__.delete_a_connection_from_the_group_if_model_deleted(int(args.deleteconnectionifmodel)) __database__.root._p_changed = True # Subcomand to trim the amount of flows in the connections elif args.trimgroupid: # Now just trim to keep 100 flows if args.amounttotrim: amount_to_trim = args.amounttotrim else: amount_to_trim = 100 __group_of_group_of_connections__.trim_flows(int(args.trimgroupid), amount_to_trim) __database__.root._p_changed = True # Subcomand to count the amount of models elif args.countconnections: try: filter = args.filter except AttributeError: pass __group_of_group_of_connections__.count_connections_in_group(args.countconnections, filter) __database__.root._p_changed = True # Subcomand to show the histograms elif args.histogram: __group_of_group_of_connections__.show_histograms(args.histogram)