From 3063e78dd921b84f22e0e4bee234d071f034eb5e Mon Sep 17 00:00:00 2001 From: jorgepastorr Date: Wed, 6 Mar 2024 22:52:19 +0100 Subject: [PATCH] add webapp limesurvey --- .../contrib/webapps/backends/limesurvey.py | 89 ++++++++++++++++++ orchestra/contrib/webapps/types/cms.py | 2 +- orchestra/contrib/webapps/types/limesurvey.py | 19 ++++ .../orchestra/icons/apps/limesurvey.png | Bin 0 -> 4782 bytes .../orchestra/icons/apps/limesurvey.svg | 32 +++++++ 5 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 orchestra/contrib/webapps/backends/limesurvey.py create mode 100644 orchestra/contrib/webapps/types/limesurvey.py create mode 100644 orchestra/static/orchestra/icons/apps/limesurvey.png create mode 100644 orchestra/static/orchestra/icons/apps/limesurvey.svg 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 0000000000000000000000000000000000000000..d07d42eff2d1375b0e632e48a1b10b931485e60e GIT binary patch literal 4782 zcmV;f5>f4mP)b>4y-#7iy|+t z07A|H4z4}@|NHj*@+GVQ^!xVn{O;}d?*OSV0HZDdg8%@R9sq{`0FW8C;iu;K+~)M) z&hfqP`{&&C(ZS@i)9lLQ_u0$o(&Y2!)$iNDmZ00NIIvS!w`z3Bh?mi$EvZPd)U{x_aw(8BJe5RLrCoWsfQPz^ zOs82jp+{-6b5*)6Zo^NA-ePIiGIqsSt>}`5%W-DMJG~1?-2ea)KuJVFRCt`_oeNjm z*cQjjOF=DY((sTJ0;nJ=MMS|@ZD;J%I_auRk$H~qkeNMuQ7tdS5>YMH6$9M1l`1Ab3hYzoaK72So|Ld=hv%WC*5>|KKeff6v z`O~YSqUBebiXV1neRb}XZ+^V~^V7wJj5F3N9aiyOe%4pWuKd={m(QP;i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chestra/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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +