diff options
Diffstat (limited to 'rpki')
-rw-r--r-- | rpki/db_router.py | 57 | ||||
-rw-r--r-- | rpki/django_settings.py | 245 | ||||
-rw-r--r-- | rpki/django_settings/__init__.py | 0 | ||||
-rw-r--r-- | rpki/django_settings/common.py | 72 | ||||
-rw-r--r-- | rpki/django_settings/gui.py | 156 | ||||
-rw-r--r-- | rpki/django_settings/irdb.py | 49 | ||||
-rw-r--r-- | rpki/django_settings/pubd.py | 48 | ||||
-rw-r--r-- | rpki/django_settings/rpkid.py | 48 | ||||
-rw-r--r-- | rpki/gui/script_util.py | 38 | ||||
-rw-r--r-- | rpki/irdbd.py | 2 | ||||
-rw-r--r-- | rpki/pubd.py | 6 | ||||
-rw-r--r-- | rpki/pubdb/migrations/0001_initial.py | 3 | ||||
-rw-r--r-- | rpki/rpkic.py | 41 |
13 files changed, 389 insertions, 376 deletions
diff --git a/rpki/db_router.py b/rpki/db_router.py deleted file mode 100644 index 89ed6e5d..00000000 --- a/rpki/db_router.py +++ /dev/null @@ -1,57 +0,0 @@ -# $Id$ - -# Copyright (C) 2014 Dragon Research Labs ("DRL") -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND DRL DISCLAIMS ALL WARRANTIES WITH -# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -# AND FITNESS. IN NO EVENT SHALL DRL BE LIABLE FOR ANY SPECIAL, DIRECT, -# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -# PERFORMANCE OF THIS SOFTWARE. - -""" -Global Django ORM database router for the RPKI CA code. -""" - -# Reference: -# https://docs.djangoproject.com/en/1.6/topics/db/multi-db/ - -class RPKIDBRouter(object): - """ - Django ORM database router for RPKI code. rpkid and pubd get their - own databases, named "rpkidb" and "pubdb", respectively. Everything - else goes to the "default" database. - """ - - dedicated = ("rpkidb", "pubdb") - - def db_for_read(self, model, **hints): - if model._meta.app_label in self.dedicated: - return model._meta.app_label - else: - return "default" - - def db_for_write(self, model, **hints): - if model._meta.app_label in self.dedicated: - return model._meta.app_label - else: - return "default" - - def allow_relation(self, obj1, obj2, **hints): - if obj1._meta.app_label in self.dedicated and obj1._meta.app_label == obj2._meta.app_label: - return True - elif obj1._meta.app_label not in self.dedicated and obj2._meta.app_label not in self.dedicated: - return True - else: - return None - - def allow_syncdb(self, db, model): - if model._meta.app_label in self.dedicated: - return db == model._meta.app_label - else: - return db not in self.dedicated diff --git a/rpki/django_settings.py b/rpki/django_settings.py deleted file mode 100644 index d3cadcfc..00000000 --- a/rpki/django_settings.py +++ /dev/null @@ -1,245 +0,0 @@ -# $Id$ - -# Copyright (C) 2014 Dragon Research Labs ("DRL") -# -# Permission to use, copy, modify, and distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND DRL DISCLAIMS ALL WARRANTIES WITH -# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -# AND FITNESS. IN NO EVENT SHALL DRL BE LIABLE FOR ANY SPECIAL, DIRECT, -# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -# PERFORMANCE OF THIS SOFTWARE. - -""" -This module contains configuration settings for Django libraries. - -Most of our CA code uses at least the Django ORM; the web interface -uses a lot more of Django. We also want to handle all normal user -configuration via rpki.conf, so some of the code here is just pulling -settings from rpki.conf and stuffing them into the form Django wants. -""" - -__version__ = "$Id$" - -import os -import socket - -import rpki.config -import rpki.autoconf - -# Some configuration, including SQL authorization, comes from rpki.conf. -cfg = rpki.config.parser() - - -# Do -not- turn on DEBUG here except for short-lived tests, otherwise -# long-running programs like irdbd will eventually run out of memory -# and crash. This is also why this is controlled by an environment -# variable rather than by an rpki.conf setting: just because we want -# debugging enabled in the GUI doesn't mean we want it in irdb. -# -# If you must enable debugging, you may need to add code that uses -# django.db.reset_queries() to clear the query list manually, but it's -# probably better just to run with debugging disabled, since that's -# the expectation for production code. -# -# https://docs.djangoproject.com/en/dev/faq/models/#why-is-django-leaking-memory - -if os.getenv("RPKI_DJANGO_DEBUG") == "yes": - DEBUG = True - - -# Database configuration. This is always enabled, and uses a database -# "router" to handle multiple databases. We may want to add yet -# another database to hold South's migration tables, to avoid the -# silliness of requiring an IRDB on, eg, a pubd-only server. -# -# We used to set an option to force MySQL to create InnnoDB databases, -# and we used to set HOST and PORT to the null string, but all of -# these are the defaults with recent versions of MySQL and Django, so -# in theory none of them should be necessary. - -DATABASES = dict( - default = dict(ENGINE = "django.db.backends.mysql", - NAME = cfg.get("sql-database", section = "irdbd"), - USER = cfg.get("sql-username", section = "irdbd"), - PASSWORD = cfg.get("sql-password", section = "irdbd"))) - -if cfg.getboolean("start_rpkid", section = "myrpki"): - DATABASES.update( - rpkidb = dict(ENGINE = "django.db.backends.mysql", - NAME = cfg.get("sql-database", section = "rpkid"), - USER = cfg.get("sql-username", section = "rpkid"), - PASSWORD = cfg.get("sql-password", section = "rpkid"))) - -if cfg.getboolean("start_pubd", section = "myrpki"): - DATABASES.update( - pubdb = dict(ENGINE = "django.db.backends.mysql", - NAME = cfg.get("sql-database", section = "pubd"), - USER = cfg.get("sql-username", section = "pubd"), - PASSWORD = cfg.get("sql-password", section = "pubd"))) - -# ORM database "router" to sort out which apps use which databases. - -DATABASE_ROUTERS = ["rpki.db_router.RPKIDBRouter"] - -# Figure out which apps we're running -- GUI code below adds many more. - -INSTALLED_APPS = ["south"] - -if cfg.getboolean("start_irdbd", section = "myrpki"): - INSTALLED_APPS.append("rpki.irdb") - -if cfg.getboolean("start_rpkid", section = "myrpki"): - INSTALLED_APPS.append("rpki.rpkidb") - -if cfg.getboolean("start_pubd", section = "myrpki"): - INSTALLED_APPS.append("rpki.pubdb") - -# That's about it if we just need the ORM, but Django throws a hissy -# fit if SECRET_KEY isn't set, whether we use it for anything or not. -# -# Make this unique, and don't share it with anybody. -if cfg.has_option("secret-key", section = "web_portal"): - SECRET_KEY = cfg.get("secret-key", section = "web_portal") -else: - SECRET_KEY = os.urandom(66).encode("hex") - - -# If we're the GUI (or a program like rpki-manage that might be -# configuring the GUI) we need a lot of other stuff, so check for an -# environment variable that rpki.wsgi and rpki-manage set for us. - -if os.getenv("RPKI_GUI_ENABLE") == "yes": - - # Where to put static files. - STATIC_ROOT = rpki.autoconf.datarootdir + "/rpki/media" - - # Must end with a slash! - STATIC_URL = "/media/" - - # Where to email server errors. - ADMINS = (("Administrator", "root@localhost"),) - - LOGGING = { - "version": 1, - "formatters": { - "verbose": { - # see http://docs.python.org/2.7/library/logging.html#logging.LogRecord - "format": "%(levelname)s %(asctime)s %(name)s %(message)s" - }, - }, - "handlers": { - "stderr": { - "class": "logging.StreamHandler", - "level": "DEBUG", - "formatter": "verbose", - }, - "mail_admins": { - "level": "ERROR", - "class": "django.utils.log.AdminEmailHandler", - }, - }, - "loggers": { - "django": { - "level": "ERROR", - "handlers": ["stderr", "mail_admins"], - }, - "rpki.gui": { - "level": "WARNING", - "handlers": ["stderr"], - }, - }, - } - - def select_tz(): - "Find a supported timezone that looks like UTC" - for tz in ("UTC", "GMT", "Etc/UTC", "Etc/GMT"): - if os.path.exists("/usr/share/zoneinfo/" + tz): - return tz - # Can't determine the proper timezone, fall back to UTC and let Django - # report the error to the user. - return "UTC" - - # Local time zone for this installation. Choices can be found here: - # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name - # although not all choices may be available on all operating systems. - # If running in a Windows environment this must be set to the same as your - # system time zone. - TIME_ZONE = select_tz() - - # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts - # for details on why you might need this. - def get_allowed_hosts(): - allowed_hosts = set(cfg.multiget("allowed-hosts", section = "web_portal")) - allowed_hosts.add(socket.getfqdn()) - allowed_hosts.add("127.0.0.1") - allowed_hosts.add("::1") - try: - import netifaces - for interface in netifaces.interfaces(): - addresses = netifaces.ifaddresses(interface) - for af in (netifaces.AF_INET, netifaces.AF_INET6): - if af in addresses: - for address in addresses[af]: - if "addr" in address: - allowed_hosts.add(address["addr"]) - except ImportError: - pass - return list(allowed_hosts) - - ALLOWED_HOSTS = get_allowed_hosts() - - # List of callables that know how to import templates from various sources. - TEMPLATE_LOADERS = ( - "django.template.loaders.filesystem.Loader", - "django.template.loaders.app_directories.Loader", - "django.template.loaders.eggs.Loader" - ) - - MIDDLEWARE_CLASSES = ( - "django.middleware.common.CommonMiddleware", - "django.contrib.sessions.middleware.SessionMiddleware", - "django.middleware.csrf.CsrfViewMiddleware", - "django.contrib.auth.middleware.AuthenticationMiddleware", - "django.contrib.messages.middleware.MessageMiddleware" - ) - - ROOT_URLCONF = "rpki.gui.urls" - - INSTALLED_APPS.extend(( - "django.contrib.auth", - #"django.contrib.admin", - #"django.contrib.admindocs", - "django.contrib.contenttypes", - "django.contrib.sessions", - "django.contrib.staticfiles", - "rpki.gui.app", - "rpki.gui.cacheview", - "rpki.gui.routeview", - )) - - TEMPLATE_CONTEXT_PROCESSORS = ( - "django.contrib.auth.context_processors.auth", - "django.core.context_processors.debug", - "django.core.context_processors.i18n", - "django.core.context_processors.media", - "django.contrib.messages.context_processors.messages", - "django.core.context_processors.request", - "django.core.context_processors.static" - ) - -# End of GUI-specific settings. - - -# Allow local site to override any setting above -- but if there's -# anything that local sites routinely need to modify, please consider -# putting that configuration into rpki.conf and just adding code here -# to read that configuration. -try: - from local_settings import * -except: - pass diff --git a/rpki/django_settings/__init__.py b/rpki/django_settings/__init__.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/rpki/django_settings/__init__.py diff --git a/rpki/django_settings/common.py b/rpki/django_settings/common.py new file mode 100644 index 00000000..330ab165 --- /dev/null +++ b/rpki/django_settings/common.py @@ -0,0 +1,72 @@ +# $Id$ + +# Copyright (C) 2014 Dragon Research Labs ("DRL") +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND DRL DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL DRL BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +""" +This module contains common configuration settings for Django libraries. + +Most of our CA code uses at least the Django ORM; the web interface +uses a lot more of Django. We also want to handle all normal user +configuration via rpki.conf, so some of the code here is just pulling +settings from rpki.conf and stuffing them into the form Django wants. +""" + +__version__ = "$Id$" + +import os +import rpki.config +import rpki.autoconf + +# Some configuration, including SQL authorization, comes from rpki.conf. +cfg = rpki.config.parser() + + +# Do -not- turn on DEBUG here except for short-lived tests, otherwise +# long-running programs like irdbd will eventually run out of memory +# and crash. This is also why this is controlled by an environment +# variable rather than by an rpki.conf setting: just because we want +# debugging enabled in the GUI doesn't mean we want it in irdb. +# +# If you must enable debugging, you may need to add code that uses +# django.db.reset_queries() to clear the query list manually, but it's +# probably better just to run with debugging disabled, since that's +# the expectation for production code. +# +# https://docs.djangoproject.com/en/dev/faq/models/#why-is-django-leaking-memory + +if os.getenv("RPKI_DJANGO_DEBUG") == "yes": + DEBUG = True + + +# Database configuration is handled in the modules that import this +# one, as it differs from program to program. We tried using a Django +# "database router" here, and it sort of worked, but it was a bit +# fragile, tedious to use, and generally more complex than we need, +# because any given program is only going to be using one database. + +# Figure out which apps we're running. Modules that import this add +# others. "south" will go away when we upgrade to Django 1.7+, at +# which point we may leave this entirely for the importing modules. + +INSTALLED_APPS = ["south"] + +# That would be it if we just need the ORM, but Django throws a hissy +# fit if SECRET_KEY isn't set, whether we use it for anything or not. +# +# Make this unique, and don't share it with anybody. +if cfg.has_option("secret-key", section = "web_portal"): + SECRET_KEY = cfg.get("secret-key", section = "web_portal") +else: + SECRET_KEY = os.urandom(66).encode("hex") diff --git a/rpki/django_settings/gui.py b/rpki/django_settings/gui.py new file mode 100644 index 00000000..5007df8b --- /dev/null +++ b/rpki/django_settings/gui.py @@ -0,0 +1,156 @@ +# $Id$ + +# Copyright (C) 2014 Dragon Research Labs ("DRL") +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND DRL DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL DRL BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +""" +This module contains GUI-specific configuration settings for Django libraries. +""" + +# Pull in the irdb configuration, which in turn pulls in the common configuration. + +from .irdb import * + +__version__ = "$Id$" + +import socket + +# GUI uses the IRDB database configuration, so we don't need to set +# anything here. + +# Where to put static files. +STATIC_ROOT = rpki.autoconf.datarootdir + "/rpki/media" + +# Must end with a slash! +STATIC_URL = "/media/" + +# Where to email server errors. +ADMINS = (("Administrator", "root@localhost"),) + +LOGGING = { + "version": 1, + "formatters": { + "verbose": { + # see http://docs.python.org/2.7/library/logging.html#logging.LogRecord + "format": "%(levelname)s %(asctime)s %(name)s %(message)s" + }, + }, + "handlers": { + "stderr": { + "class": "logging.StreamHandler", + "level": "DEBUG", + "formatter": "verbose", + }, + "mail_admins": { + "level": "ERROR", + "class": "django.utils.log.AdminEmailHandler", + }, + }, + "loggers": { + "django": { + "level": "ERROR", + "handlers": ["stderr", "mail_admins"], + }, + "rpki.gui": { + "level": "WARNING", + "handlers": ["stderr"], + }, + }, +} + +def select_tz(): + "Find a supported timezone that looks like UTC" + for tz in ("UTC", "GMT", "Etc/UTC", "Etc/GMT"): + if os.path.exists("/usr/share/zoneinfo/" + tz): + return tz + # Can't determine the proper timezone, fall back to UTC and let Django + # report the error to the user. + return "UTC" + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = select_tz() + +# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts +# for details on why you might need this. +def get_allowed_hosts(): + allowed_hosts = set(cfg.multiget("allowed-hosts", section = "web_portal")) + allowed_hosts.add(socket.getfqdn()) + allowed_hosts.add("127.0.0.1") + allowed_hosts.add("::1") + try: + import netifaces + for interface in netifaces.interfaces(): + addresses = netifaces.ifaddresses(interface) + for af in (netifaces.AF_INET, netifaces.AF_INET6): + if af in addresses: + for address in addresses[af]: + if "addr" in address: + allowed_hosts.add(address["addr"]) + except ImportError: + pass + return list(allowed_hosts) + +ALLOWED_HOSTS = get_allowed_hosts() + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + "django.template.loaders.filesystem.Loader", + "django.template.loaders.app_directories.Loader", + "django.template.loaders.eggs.Loader" +) + +MIDDLEWARE_CLASSES = ( + "django.middleware.common.CommonMiddleware", + "django.contrib.sessions.middleware.SessionMiddleware", + "django.middleware.csrf.CsrfViewMiddleware", + "django.contrib.auth.middleware.AuthenticationMiddleware", + "django.contrib.messages.middleware.MessageMiddleware" +) + +ROOT_URLCONF = "rpki.gui.urls" + +INSTALLED_APPS.extend(( + "django.contrib.auth", + #"django.contrib.admin", + #"django.contrib.admindocs", + "django.contrib.contenttypes", + "django.contrib.sessions", + "django.contrib.staticfiles", + "rpki.gui.app", + "rpki.gui.cacheview", + "rpki.gui.routeview", +)) + +TEMPLATE_CONTEXT_PROCESSORS = ( + "django.contrib.auth.context_processors.auth", + "django.core.context_processors.debug", + "django.core.context_processors.i18n", + "django.core.context_processors.media", + "django.contrib.messages.context_processors.messages", + "django.core.context_processors.request", + "django.core.context_processors.static" +) + +# Allow local site to override any setting above -- but if there's +# anything that local sites routinely need to modify, please consider +# putting that configuration into rpki.conf and just adding code here +# to read that configuration. +try: + from local_settings import * +except: + pass diff --git a/rpki/django_settings/irdb.py b/rpki/django_settings/irdb.py new file mode 100644 index 00000000..8a33e674 --- /dev/null +++ b/rpki/django_settings/irdb.py @@ -0,0 +1,49 @@ +# $Id$ + +# Copyright (C) 2014 Dragon Research Labs ("DRL") +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND DRL DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL DRL BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +""" +This module contains configuration settings for Django libraries. All +of the back-end programs (rpkic, irdbd, etc) use this configuration; +the GUI code also uses this but adds a bunch of other stuff, thus has +its own settings file. +""" + +from .common import * + +__version__ = "$Id$" + + +# Database configuration. + +DATABASES = dict( + default = dict(ENGINE = "django.db.backends.mysql", + NAME = cfg.get("sql-database", section = "irdbd"), + USER = cfg.get("sql-username", section = "irdbd"), + PASSWORD = cfg.get("sql-password", section = "irdbd"))) + +# Apps. See comment in .common re the "south" app. + +INSTALLED_APPS.append("rpki.irdb") + + +# Allow local site to override any setting above -- but if there's +# anything that local sites routinely need to modify, please consider +# putting that configuration into rpki.conf and just adding code here +# to read that configuration. +try: + from local_settings import * +except: + pass diff --git a/rpki/django_settings/pubd.py b/rpki/django_settings/pubd.py new file mode 100644 index 00000000..80618652 --- /dev/null +++ b/rpki/django_settings/pubd.py @@ -0,0 +1,48 @@ +# $Id$ + +# Copyright (C) 2014 Dragon Research Labs ("DRL") +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND DRL DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL DRL BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +""" +This module contains configuration settings for Django libraries for +the pubd program. +""" + +from .common import * + +__version__ = "$Id$" + + +# Database configuration. + +DATABASES = dict( + default = dict(ENGINE = "django.db.backends.mysql", + NAME = cfg.get("sql-database", section = "pubd"), + USER = cfg.get("sql-username", section = "pubd"), + PASSWORD = cfg.get("sql-password", section = "pubd"))) + + +# Apps -- see comment in .common re "south" app. + +INSTALLED_APPS.append("rpki.pubdb") + + +# Allow local site to override any setting above -- but if there's +# anything that local sites routinely need to modify, please consider +# putting that configuration into rpki.conf and just adding code here +# to read that configuration. +try: + from local_settings import * +except: + pass diff --git a/rpki/django_settings/rpkid.py b/rpki/django_settings/rpkid.py new file mode 100644 index 00000000..64938647 --- /dev/null +++ b/rpki/django_settings/rpkid.py @@ -0,0 +1,48 @@ +# $Id$ + +# Copyright (C) 2014 Dragon Research Labs ("DRL") +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND DRL DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL DRL BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +""" +This module contains configuration settings for Django libraries for +the rpkid program. +""" + +from .common import * + +__version__ = "$Id$" + + +# Database configuration. + +DATABASES = dict( + default = dict(ENGINE = "django.db.backends.mysql", + NAME = cfg.get("sql-database", section = "rpkid"), + USER = cfg.get("sql-username", section = "rpkid"), + PASSWORD = cfg.get("sql-password", section = "rpkid"))) + + +# Apps -- see .common re "south" app. + +INSTALLED_APPS.append("rpki.rpkidb") + + +# Allow local site to override any setting above -- but if there's +# anything that local sites routinely need to modify, please consider +# putting that configuration into rpki.conf and just adding code here +# to read that configuration. +try: + from local_settings import * +except: + pass diff --git a/rpki/gui/script_util.py b/rpki/gui/script_util.py index 24b6d313..31e40821 100644 --- a/rpki/gui/script_util.py +++ b/rpki/gui/script_util.py @@ -24,39 +24,7 @@ def setup(): Configure Django enough to use the ORM. """ - # In theory we no longer need to call settings.configure, which - # probably means this whole module can go away soon, but leave - # breadcrumbs for now. + import os - if True: - import os - os.environ.update(DJANGO_SETTINGS_MODULE = "rpki.django_settings") - - else: - import django - from rpki import config - from rpki import autoconf - from django.conf import settings - - cfg = config.parser(section='web_portal') - # INSTALLED_APPS doesn't seem necessary so long as you are only accessing - # existing tables. - settings.configure( - DATABASES={ - 'default': { - 'ENGINE': 'django.db.backends.mysql', - 'NAME': cfg.get('sql-database'), - 'USER': cfg.get('sql-username'), - 'PASSWORD': cfg.get('sql-password'), - }, - }, - MIDDLEWARE_CLASSES = (), - DOWNLOAD_DIRECTORY = cfg.get('download-directory', '/var/tmp'), - ) - # Can't populate apps if we don't know what they are. If this - # explodes with an AppRegistryNotReady exception, the above comment - # about not needing to set INSTALLED_APPS is no longer true and - # you'll need to fix that here. - if False and django.VERSION >= (1, 7): - from django.apps import apps - apps.populate(settings.INSTALLED_APPS) + # If this doesn't work, try changing it to "rpki.django_settings.gui". + os.environ.update(DJANGO_SETTINGS_MODULE = "rpki.django_settings.irdb") diff --git a/rpki/irdbd.py b/rpki/irdbd.py index 805280d7..4990405c 100644 --- a/rpki/irdbd.py +++ b/rpki/irdbd.py @@ -143,7 +143,7 @@ class main(object): global rpki # pylint: disable=W0602 os.environ.update(TZ = "UTC", - DJANGO_SETTINGS_MODULE = "rpki.django_settings") + DJANGO_SETTINGS_MODULE = "rpki.django_settings.irdb") time.tzset() parser = argparse.ArgumentParser(description = __doc__) diff --git a/rpki/pubd.py b/rpki/pubd.py index 9de2fd46..71a62fee 100644 --- a/rpki/pubd.py +++ b/rpki/pubd.py @@ -52,7 +52,7 @@ class main(object): def __init__(self): os.environ.update(TZ = "UTC", - DJANGO_SETTINGS_MODULE = "rpki.django_settings") + DJANGO_SETTINGS_MODULE = "rpki.django_settings.pubd") time.tzset() self.irbe_cms_timestamp = None @@ -146,7 +146,7 @@ class main(object): try: q_pdu = None - with transaction.atomic(using = "pubdb"): + with transaction.atomic(): for q_pdu in q_msg: if q_pdu.tag != rpki.publication_control.tag_client: @@ -240,7 +240,7 @@ class main(object): type = "reply", version = rpki.publication.version) delta = None try: - with transaction.atomic(using = "pubdb"): + with transaction.atomic(): for q_pdu in q_msg: if q_pdu.get("uri"): logger.info("Client %s request for %s", q_pdu.tag, q_pdu.get("uri")) diff --git a/rpki/pubdb/migrations/0001_initial.py b/rpki/pubdb/migrations/0001_initial.py index c796d020..73cecd0e 100644 --- a/rpki/pubdb/migrations/0001_initial.py +++ b/rpki/pubdb/migrations/0001_initial.py @@ -1,10 +1,9 @@ # -*- coding: utf-8 -*- from south.utils import datetime_utils as datetime -from south.db import dbs +from south.db import db from south.v2 import SchemaMigration from django.db import models -db = dbs["pubdb"] class Migration(SchemaMigration): diff --git a/rpki/rpkic.py b/rpki/rpkic.py index 417c53fe..0e485200 100644 --- a/rpki/rpkic.py +++ b/rpki/rpkic.py @@ -128,35 +128,7 @@ class main(Cmd): self.histfile = cfg.get("history_file", os.path.expanduser("~/.rpkic_history")) self.autosync = cfg.getboolean("autosync", True, section = "rpkic") - # This should go away now that we have rpki.django_settings, but - # let's get a verbose log with it present first to see what - # changes. - - use_south = True - setup_db = False - - if use_south: - os.environ.update(DJANGO_SETTINGS_MODULE = "rpki.django_settings") - - else: - import django - from django.conf import settings - settings.configure( - DATABASES = { "default" : { - "ENGINE" : "django.db.backends.mysql", - "NAME" : cfg.get("sql-database", section = "irdbd"), - "USER" : cfg.get("sql-username", section = "irdbd"), - "PASSWORD" : cfg.get("sql-password", section = "irdbd"), - "HOST" : "", - "PORT" : "", - "OPTIONS" : { "init_command": "SET storage_engine=INNODB" }}}, - INSTALLED_APPS = ("rpki.irdb",), - MIDDLEWARE_CLASSES = (), # API change, feh - ) - - if django.VERSION >= (1, 7): # API change, feh - from django.apps import apps - apps.populate(settings.INSTALLED_APPS) + os.environ.update(DJANGO_SETTINGS_MODULE = "rpki.django_settings.irdb") import rpki.irdb # pylint: disable=W0621 @@ -178,12 +150,15 @@ class main(Cmd): except rpki.config.ConfigParser.Error: pass - if setup_db: + # Need to figure out whether we really want rpkic setting up + # databases or not. Defer until we've caught up to a current + # version of Django, are past the change from South to Django + # 1.7+'s migration scheme, and other potential complications. + + if False: import django.core.management django.core.management.call_command("syncdb", verbosity = 3, load_initial_data = False) - - if setup_db and use_south: - django.core.management.call_command("migrate", verbosity = 3) + django.core.management.call_command("migrate", verbosity = 3) self.zoo = rpki.irdb.Zookeeper(cfg = cfg, handle = self.handle, logstream = sys.stdout) |