Server IP : 85.214.239.14 / Your IP : 18.224.32.243 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /srv/modoboa/env/lib/python3.5/site-packages/modoboa_amavis/checks/ |
Upload File : |
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.conf import settings from django.core.checks import Warning, register from django.db import connections from django.utils.translation import ugettext as _ W001 = Warning( _("AMAVIS_DEFAULT_DATABASE_ENCODING does not match the character " "encoding used by the Amavis database."), hint=_("Check your database character encoding and set/update " "AMAVIS_DEFAULT_DATABASE_ENCODING."), id="modoboa-amavis.W001", ) W002 = Warning( _("Modoboa Amavis has not been tested using the selected database engine."), hint=_("Try using PostgreSQL, MySQL or MariaDB."), id="modoboa-amavis.W002", ) @register(deploy=True) def check_amavis_database_encoding(app_configs, **kwargs): """Ensure AMAVIS_DEFAULT_DATABASE_ENCODING is set to the correct value.""" errors = [] db_engine = settings.DATABASES["amavis"]["ENGINE"] sql_query = None if "postgresql" in db_engine: sql_query = "SELECT pg_encoding_to_char(encoding) "\ "FROM pg_database "\ "WHERE datname = %s;" elif "mysql" in db_engine: sql_query = "SELECT DEFAULT_CHARACTER_SET_NAME "\ "FROM INFORMATION_SCHEMA.SCHEMATA "\ "WHERE SCHEMA_NAME = %s;" elif "sqlite" in db_engine: sql_query = "PRAGMA encoding;" else: errors.append(W002) return errors with connections["amavis"].cursor() as cursor: if "sqlite" in db_engine: cursor.execute(sql_query) else: cursor.execute(sql_query, [settings.DATABASES["amavis"]["NAME"]]) encoding = cursor.fetchone()[0] if encoding.lower() != settings.AMAVIS_DEFAULT_DATABASE_ENCODING.lower(): errors.append(W001) return errors