def config_bbdd(path_bbdd): """ Configure database information. :param path_bbdd: string with output BBDD. :type path_bbdd: str """ if not isinstance(path_bbdd, basestring): raise TypeError("Expected basestring, got '%s' instead" % type(path_bbdd)) from standalone.conf import settings global settings m_path = os.path.join(os.path.abspath(path_bbdd), "openvas.sqlite3") settings = settings( DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': '%s' % m_path, } }, )
from standalone.conf import settings settings = settings( DATABASE_ENGINE='mysql', DATABASE_NAME='air', DATABASE_USER='******', DATABASE_PASSWORD='******', MEDIA_ROOT='/home/scott/android/autobuild/mywork/air/python/air/storage', ) MEDIA_ROOT = '/home/scott/android/autobuild/mywork/air/python/air/storage'
'PORT' : '3306', } } elif (DOMAIN_NAME in ['HORNRA3']): DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': options.database, 'USER' : 'raychorn', 'PASSWORD' : 'peekab00', 'HOST' : '127.0.0.1', 'PORT' : '23337', } } settings = settings( DATABASES = DATABASES ) # build the models we want to have in the database from standalone import models class ScheduledJob(models.StandaloneModel): taskid = models.IntegerField(blank=False) taskname = models.CharField(max_length=128,blank=False) created_at = models.DateTimeField(blank=False) modified_at = models.DateTimeField(blank=False) run_at = models.DateTimeField(blank=False) info = models.TextField(blank=False) runnable = models.BooleanField(blank=False) class Meta: db_table = u'scheduledjob'
def parse_results(openvas_results, ip = None): """ Convert the OpenVAS scan results to the GoLismero data model. :param openvas_results: OpenVAS scan results. :type openvas_results: list(OpenVASResult) :param ip: (Optional) IP address to link the vulnerabilities to. :type ip: IP | None :returns: Scan results converted to the GoLismero data model. :rtype: list(Data) """ # This is where we'll store the results. results = [] # Remember the hosts we've seen so we don't create them twice. hosts_seen = {} # Map of OpenVAS levels to GoLismero levels. OPV_LEVELS_TO_GLM_LEVELS = { 'debug' : 'informational', 'log' : 'informational', 'low' : "low", 'medium': 'middle', 'high' : "high", } # Do we have the OpenVAS plugin database? use_openvas_db = os.path.exists(openvas_db) if not use_openvas_db: Logger.log_error( "OpenVAS plugin not initialized, please run setup.py") else: # Load the database using the Django ORM. from standalone.conf import settings settings = settings( DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': '%s' % openvas_db, } }, ) # Load the ORM model. sys.path.insert(0, openvas_dir) try: from models import Families, Plugin finally: sys.path.remove(openvas_dir) # Load the categories. CATEGORIES = {} if os.path.exists(openvas_yaml): try: CATEGORIES = yaml.load( open(openvas_yaml, 'rU') ) except Exception, e: tb = format_exc() Logger.log_error_verbose( "Failed to load categories, reason: %s" % str(e)) Logger.log_error_more_verbose(tb) else:
help="should the database be created?") parser.add_option('-r', '--repl', dest='repl', action="store_true", help="start a REPL with access to your models") options, args = parser.parse_args() if not options.database: parser.error("You must specify the database name") # fetch the settings and cache them for later use from standalone.conf import settings settings = settings( DATABASE_ENGINE='sqlite3', DATABASE_NAME=options.database, ) # build the models we want to have in the database from standalone import models class MyModel(models.StandaloneModel): col1 = models.CharField(max_length=1000) col2 = models.IntegerField() col3 = models.BooleanField() def __unicode__(self): return self.col1
} } elif options.sqlite3: __database_name__ = '%s/%s.sqlite' % (os.path.dirname( sys.argv[0]).replace(os.sep, '/'), __database_name__) print 'INFO: Using sqlite3... Database "%s".' % (__database_name__) if (DOMAIN_NAME in ['HPDV7-6163us']): DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': __database_name__, } } settings = settings(DATABASES=DATABASES) import models from django.core.management import call_command if options.syncdb: # run a simple command - here syncdb - from the management suite call_command('syncdb') sys.exit(1) elif options.repl: # start the shell, access to your models through import standalone.models call_command('shell') sys.exit(1) elif options.dumpdata: call_command('dumpdata') sys.exit(1)