aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rpkid/portal-gui/settings.py.in52
-rw-r--r--rpkid/rpki/gui/models.py7
2 files changed, 43 insertions, 16 deletions
diff --git a/rpkid/portal-gui/settings.py.in b/rpkid/portal-gui/settings.py.in
index 19bad89b..8246304c 100644
--- a/rpkid/portal-gui/settings.py.in
+++ b/rpkid/portal-gui/settings.py.in
@@ -21,22 +21,44 @@ rpki.config.default_dirname = '%(AC_SYSCONFDIR)s'
# load the sql authentication bits from the system rpki.conf
rpki_config = rpki.config.parser(section='web_portal')
+
+def get_conv():
+ """Add a custom data converter to encode long() as a hex string
+ in generated SQL statements.
+
+ This is necessary since Django doesn't support binary field types, and
+ assumes all strings are UTF-8. Without this conversion, the generated SQL
+ uses a raw byte string.
+
+ See https://trac.rpki.net/ticket/434
+
+ """
+ from MySQLdb.converters import conversions
+ import types
+ conv = conversions.copy()
+ # WARNING: the extra percents in the following line are due to the fact
+ # that this entire script is used as a format string to generate
+ # settings.py
+ conv[types.LongType] = lambda x, conv: "0x%%x" %% x
+ return conv
+
DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.mysql',
- 'NAME': rpki_config.get('sql-database'),
- 'USER': rpki_config.get('sql-username'),
- 'PASSWORD': rpki_config.get('sql-password'),
-
- # Ensure the default storage engine is InnoDB since we need
- # foreign key support. The Django documentation suggests
- # removing this after the syncdb is performed as an optimization,
- # but there isn't an easy way to do this automatically.
-
- 'OPTIONS': {
- 'init_command': 'SET storage_engine=INNODB'
- }
- }
+ 'default': {
+ 'ENGINE': 'django.db.backends.mysql',
+ 'NAME': rpki_config.get('sql-database'),
+ 'USER': rpki_config.get('sql-username'),
+ 'PASSWORD': rpki_config.get('sql-password'),
+
+ # Ensure the default storage engine is InnoDB since we need
+ # foreign key support. The Django documentation suggests
+ # removing this after the syncdb is performed as an optimization,
+ # but there isn't an easy way to do this automatically.
+
+ 'OPTIONS': {
+ 'init_command': 'SET storage_engine=INNODB',
+ 'conv': get_conv(),
+ }
+ }
}
diff --git a/rpkid/rpki/gui/models.py b/rpkid/rpki/gui/models.py
index 0ea0924b..d6073c2f 100644
--- a/rpkid/rpki/gui/models.py
+++ b/rpkid/rpki/gui/models.py
@@ -39,7 +39,12 @@ class IPv6AddressField(models.Field):
return rpki.POW.IPAddress.fromBytes(value)
def get_db_prep_value(self, value, connection, prepared):
- return value.toBytes()
+ """
+ Note that we add a custom conversion to encode long values as hex
+ strings in SQL statements. See settings.get_conv() for details.
+
+ """
+ return long(value)
class IPv4AddressField(models.Field):