diff --git a/orchestra/contrib/webapps/backends/limesurvey.py b/orchestra/contrib/webapps/backends/limesurvey.py new file mode 100644 index 00000000..eec76402 --- /dev/null +++ b/orchestra/contrib/webapps/backends/limesurvey.py @@ -0,0 +1,89 @@ +import os +import textwrap + +from django.utils.translation import gettext_lazy as _ + +from orchestra.contrib.orchestration import ServiceController, replace +from django.template import Template, Context +from orchestra.settings import NEW_SERVERS +from .. import settings + +from . import WebAppServiceMixin + + +class LimesurveyController(WebAppServiceMixin, ServiceController): + """ + Installs the latest version of Limesurvey available on git github.com/LimeSurvey/LimeSurvey + """ + verbose_name = _("Limesurvey") + model = 'webapps.WebApp' + default_route_match = "webapp.type == 'limesurvey-php'" + doc_settings = (settings, + ('WEBAPPS_DEFAULT_MYSQL_DATABASE_HOST',) + ) + + + def save(self, webapp): + context = self.get_context(webapp) + perms = Template(textwrap.dedent("""\ + {% if sftpuser %} + chown -R {{sftpuser}}:{{sftpuser}} {{home}}/webapps/{{app_name}} + {% else %} + chown -R {{user}}:{{group}} {{home}}/webapps/{{app_name}} + {% endif %} + """ + )) + linenohub = Template(textwrap.dedent("""\ + {% if sftpuser %} + su - {{sftpuser}} --shell /bin/bash << 'EOF' + {% else %} + su - {{user}} --shell /bin/bash << 'EOF' + {% endif %} + """ + )) + context.update({'perms' : perms.render(Context(context)), 'linenohub' : linenohub.render(Context(context)) }) + self.append(textwrap.dedent("""\ + if [[ $(ls "%(app_path)s" | wc -l) -gt 1 ]]; then + echo "App directory not empty." 2> /dev/null + exit 0 + fi + mkdir -p %(app_path)s + + # Download limesurvey + git clone --depth 1 https://github.com/LimeSurvey/LimeSurvey.git %(app_path)s/ + + # create database config + if [[ ! -e %(app_path)s/application/config/config.php ]]; then + cp %(app_path)s/application/config/config-sample-mysql.php %(app_path)s/application/config/config.php + sed -i "s/'connectionString' => .*/'connectionString' => 'mysql:host=%(db_host)s;port=3306;dbname=%(db_name)s;',/" %(app_path)s/application/config/config.php + sed -i "s/'username' => .*/'username' => '%(db_user)s',/" %(app_path)s/application/config/config.php + sed -i "s/'password' => .*/'password' => '%(password)s',/" %(app_path)s/application/config/config.php + + fi + + # add correct perms + %(perms)s + find %(app_path)s/ -type f -exec chmod -x {} ";" + + # Run install moodle cli command on the background, because it takes so long... + stdout=$(mktemp) + stderr=$(mktemp) + %(linenohub)s + cd %(app_path)s/application/commands/ + php console.php install admin "%(password)s" admin "%(email)s" verbose + EOF + """) % context + ) + + def get_context(self, webapp): + context = super(LimesurveyController, self).get_context(webapp) + contents = webapp.content_set.all() + context.update({ + 'db_name': webapp.data['db_name'], + 'db_user': webapp.data['db_user'], + 'password': webapp.data['password'], + 'db_host': 'localhost' if webapp.target_server.name in NEW_SERVERS else settings.WEBAPPS_DEFAULT_MYSQL_DATABASE_HOST, + 'email': webapp.account.email, + 'sftpuser': webapp.sftpuser.username if webapp.target_server.name in NEW_SERVERS else None , + }) + return replace(context, '"', "'") diff --git a/orchestra/contrib/webapps/types/cms.py b/orchestra/contrib/webapps/types/cms.py index 7707fdce..247090a1 100644 --- a/orchestra/contrib/webapps/types/cms.py +++ b/orchestra/contrib/webapps/types/cms.py @@ -21,7 +21,7 @@ class CMSAppForm(PHPAppForm): db_user = forms.CharField(label=_("Database user"), help_text=_("Database user exclusively used for this webapp.")) password = forms.CharField(label=_("Password"), - help_text=_("Initial database and WordPress admin password.
" + help_text=_("Initial database and App admin password.
" "Subsequent changes to the admin password will not be reflected.")) def __init__(self, *args, **kwargs): diff --git a/orchestra/contrib/webapps/types/limesurvey.py b/orchestra/contrib/webapps/types/limesurvey.py new file mode 100644 index 00000000..d0691104 --- /dev/null +++ b/orchestra/contrib/webapps/types/limesurvey.py @@ -0,0 +1,19 @@ +from django.utils.translation import gettext_lazy as _ + +from .cms import CMSApp + + +class LimesurveyApp(CMSApp): + name = 'limesurvey-php' + verbose_name = "Limesurvey" + help_text = _( + "This installs the latest version of Limesurvey into the webapp directory.
" + "A database and database user will automatically be created for this webapp.
" + "This installer creates a user 'admin' with a randomly generated password.
" + "The password will be visible in the 'password' field after the installer has finished." + ) + icon = 'orchestra/icons/apps/limesurvey.png' + db_prefix = 'lime_' + + def get_detail(self): + return self.instance.data.get('php_version', '') diff --git a/orchestra/static/orchestra/icons/apps/limesurvey.png b/orchestra/static/orchestra/icons/apps/limesurvey.png new file mode 100644 index 00000000..d07d42ef Binary files /dev/null and b/orchestra/static/orchestra/icons/apps/limesurvey.png differ diff --git a/orchestra/static/orchestra/icons/apps/limesurvey.svg b/orchestra/static/orchestra/icons/apps/limesurvey.svg new file mode 100644 index 00000000..7f84f0f9 --- /dev/null +++ b/orchestra/static/orchestra/icons/apps/limesurvey.svg @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +