Added support for phplist cron configuration
This commit is contained in:
parent
d8c529f936
commit
99071f01b1
18
TODO.md
18
TODO.md
|
@ -427,30 +427,12 @@ Case
|
||||||
|
|
||||||
# round decimals on every billing operation
|
# round decimals on every billing operation
|
||||||
|
|
||||||
# Serie1
|
|
||||||
|
|
||||||
# cleanup monitor data: helpers.functions into ServiceMonitor methods
|
|
||||||
|
|
||||||
# Add SPF record type
|
# Add SPF record type
|
||||||
|
|
||||||
# OVZ TRAFFIC ACCOUNTING!!
|
# OVZ TRAFFIC ACCOUNTING!!
|
||||||
|
|
||||||
# PHPlist cron, bounces and traffic (maybe specific mail script with sitename)
|
# PHPlist cron, bounces and traffic (maybe specific mail script with sitename)
|
||||||
'crontab': settings.SAAS_PHPLIST_CRONTAB.replace('$', '$$')
|
|
||||||
}
|
|
||||||
*/10 * * * * PHPLIST=%(php_list_path)s; export SITE="%(site)s"; php $PHPLIST/admin/index.php -c $PHPLIST/config/config.php -p processqueue > /dev/null
|
|
||||||
*/40 * * * * PHPLIST=%(php_list_path)s; export SITE="%(site)s"; php $PHPLIST/admin/index.php -c $PHPLIST/config/config.php -p processbounces > /dev/null
|
|
||||||
|
|
||||||
if settings.SAAS_PHPLIST_CRONTAB:
|
|
||||||
self.append(textwrap.dedent("""
|
|
||||||
# Configuring phpList crontabs
|
|
||||||
if [[ ! $(crontab -l | grep "^%(site)s") ]]; then
|
|
||||||
cat << EOF | crontab
|
|
||||||
$(crontab -l)
|
|
||||||
# %(banner)s
|
|
||||||
%(crontab)s
|
|
||||||
EOF
|
|
||||||
fi
|
|
||||||
|
|
||||||
# use "su $user --shell /bin/bash" on backends for security : MKDIR -p...
|
# use "su $user --shell /bin/bash" on backends for security : MKDIR -p...
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,10 @@ class PhpListSaaSBackend(ServiceController):
|
||||||
but all sites share the same code.
|
but all sites share the same code.
|
||||||
|
|
||||||
<tt>// config/config.php
|
<tt>// config/config.php
|
||||||
$site = array_shift((explode(".",$_SERVER['HTTP_HOST'])));
|
$site = getenv("SITE");
|
||||||
|
if ( $site == '' ) {
|
||||||
|
$site = array_shift((explode(".",$_SERVER['HTTP_HOST'])));
|
||||||
|
}
|
||||||
$database_name = "phplist_mu_{$site}";</tt>
|
$database_name = "phplist_mu_{$site}";</tt>
|
||||||
"""
|
"""
|
||||||
verbose_name = _("phpList SaaS")
|
verbose_name = _("phpList SaaS")
|
||||||
|
@ -57,16 +60,8 @@ class PhpListSaaSBackend(ServiceController):
|
||||||
else:
|
else:
|
||||||
md5_password = hashlib.md5()
|
md5_password = hashlib.md5()
|
||||||
md5_password.update(saas.password.encode('ascii'))
|
md5_password.update(saas.password.encode('ascii'))
|
||||||
context = {
|
context = self.get_context(saas)
|
||||||
'name': saas.name,
|
context['digest'] = md5_password.hexdigest()
|
||||||
'site_name': saas.name,
|
|
||||||
'db_user': settings.SAAS_PHPLIST_DB_USER,
|
|
||||||
'db_pass': settings.SAAS_PHPLIST_DB_PASS,
|
|
||||||
'db_name': settings.SAAS_PHPLIST_DB_NAME,
|
|
||||||
'db_host': settings.SAAS_PHPLIST_DB_HOST,
|
|
||||||
'digest': md5_password.hexdigest(),
|
|
||||||
}
|
|
||||||
context['db_name'] = context['db_name'] % context
|
|
||||||
cmd = textwrap.dedent("""\
|
cmd = textwrap.dedent("""\
|
||||||
mysql \\
|
mysql \\
|
||||||
--host=%(db_host)s \\
|
--host=%(db_host)s \\
|
||||||
|
@ -81,3 +76,47 @@ class PhpListSaaSBackend(ServiceController):
|
||||||
def save(self, saas):
|
def save(self, saas):
|
||||||
if hasattr(saas, 'password'):
|
if hasattr(saas, 'password'):
|
||||||
self.append(self._save, saas)
|
self.append(self._save, saas)
|
||||||
|
context = self.get_context(saas)
|
||||||
|
if context['crontab']:
|
||||||
|
context['escaped_crontab'] = context['crontab'].replace('$', '\\$')
|
||||||
|
self.append(textwrap.dedent("""\
|
||||||
|
# Configuring phpList crontabs
|
||||||
|
if [[ ! $(crontab -u %(user)s -l | grep 'phpList:"%(site_name)s"') ]]; then
|
||||||
|
cat << EOF | su %(user)s --shell /bin/bash -c 'crontab'
|
||||||
|
$(crontab -u %(user)s -l)
|
||||||
|
|
||||||
|
# %(banner)s - phpList:"%(site_name)s"
|
||||||
|
%(escaped_crontab)s
|
||||||
|
EOF
|
||||||
|
fi""") % context
|
||||||
|
)
|
||||||
|
|
||||||
|
def delete(self, saas):
|
||||||
|
context = self.get_context(saas)
|
||||||
|
if context['crontab']:
|
||||||
|
context['crontab_regex'] = '\\|'.join(context['crontab'].splitlines())
|
||||||
|
context['crontab_regex'] = context['crontab_regex'].replace('*', '\\*')
|
||||||
|
self.append(textwrap.dedent("""\
|
||||||
|
crontab -u %(user)s -l \\
|
||||||
|
| grep -v 'phpList:"%(site_name)s"\\|%(crontab_regex)s' \\
|
||||||
|
| su %(user)s --shell /bin/bash -c 'crontab'
|
||||||
|
""") % context
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_context(self, saas):
|
||||||
|
context = {
|
||||||
|
'banner': self.get_banner(),
|
||||||
|
'name': saas.name,
|
||||||
|
'site_name': saas.name,
|
||||||
|
'phplist_path': settings.SAAS_PHPLIST_PATH,
|
||||||
|
'user': settings.SAAS_PHPLIST_SYSTEMUSER,
|
||||||
|
'db_user': settings.SAAS_PHPLIST_DB_USER,
|
||||||
|
'db_pass': settings.SAAS_PHPLIST_DB_PASS,
|
||||||
|
'db_name': settings.SAAS_PHPLIST_DB_NAME,
|
||||||
|
'db_host': settings.SAAS_PHPLIST_DB_HOST,
|
||||||
|
}
|
||||||
|
context.update({
|
||||||
|
'crontab': settings.SAAS_PHPLIST_CRONTAB % context,
|
||||||
|
'db_name': context['db_name'] % context,
|
||||||
|
})
|
||||||
|
return context
|
||||||
|
|
|
@ -110,9 +110,27 @@ SAAS_PHPLIST_BASE_DOMAIN = Setting('SAAS_PHPLIST_BASE_DOMAIN',
|
||||||
|
|
||||||
SAAS_PHPLIST_VERIFY_SSL = Setting('SAAS_PHPLIST_VERIFY_SSL',
|
SAAS_PHPLIST_VERIFY_SSL = Setting('SAAS_PHPLIST_VERIFY_SSL',
|
||||||
True,
|
True,
|
||||||
help_text="Verify SSL certificate on the HTTP requests performed by the backend.",
|
help_text=_("Verify SSL certificate on the HTTP requests performed by the backend."),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SAAS_PHPLIST_PATH = Setting('SAAS_PHPLIST_PATH',
|
||||||
|
'/var/www/phplist-mu',
|
||||||
|
help_text=_("Filesystem path to the phpList source code installed on the server. "
|
||||||
|
"Used by <tt>SAAS_PHPLIST_CRONTAB</tt>.")
|
||||||
|
)
|
||||||
|
|
||||||
|
SAAS_PHPLIST_SYSTEMUSER = Setting('SAAS_PHPLIST_SYSTEMUSER',
|
||||||
|
'root',
|
||||||
|
help_text=_("System user running phpList on the server."
|
||||||
|
"Used by <tt>SAAS_PHPLIST_CRONTAB</tt>.")
|
||||||
|
)
|
||||||
|
|
||||||
|
SAAS_PHPLIST_CRONTAB = Setting('SAAS_PHPLIST_CRONTAB',
|
||||||
|
('*/10 * * * * PHPLIST=%(phplist_path)s; export SITE="%(site_name)s"; php $PHPLIST/admin/index.php -c $PHPLIST/config/config.php -p processqueue > /dev/null\n'
|
||||||
|
'*/40 * * * * PHPLIST=%(phplist_path)s; export SITE="%(site_name)s"; php $PHPLIST/admin/index.php -c $PHPLIST/config/config.php -p processbounces > /dev/null'),
|
||||||
|
help_text=_("<tt>processqueue</tt> and <tt>processbounce</tt> phpList cron execution. "
|
||||||
|
"Left blank if you don't want crontab to be configured")
|
||||||
|
)
|
||||||
|
|
||||||
SAAS_SEAFILE_DOMAIN = Setting('SAAS_SEAFILE_DOMAIN',
|
SAAS_SEAFILE_DOMAIN = Setting('SAAS_SEAFILE_DOMAIN',
|
||||||
'seafile.{}'.format(ORCHESTRA_BASE_DOMAIN),
|
'seafile.{}'.format(ORCHESTRA_BASE_DOMAIN),
|
||||||
|
|
Loading…
Reference in New Issue