wordpress complete

This commit is contained in:
jorgepastorr 2023-08-03 19:16:27 +02:00 committed by Marc Aymerich
parent d69a53ad66
commit 037c8f14e6
6 changed files with 65 additions and 22 deletions

View File

@ -19,7 +19,7 @@ class WebAppServiceMixin(object):
CREATED=0 CREATED=0
if [[ ! -e %(app_path)s ]]; then if [[ ! -e %(app_path)s ]]; then
mkdir -p %(app_path)s mkdir -p %(app_path)s
chown %(sftpuser)s:%(sftpuser)s %(app_path)s #chown %(sftpuser)s:%(sftpuser)s %(app_path)s
CREATED=1 CREATED=1
elif [[ -z $( ls -A %(app_path)s ) ]]; then elif [[ -z $( ls -A %(app_path)s ) ]]; then
CREATED=1 CREATED=1

View File

@ -4,6 +4,8 @@ import textwrap
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from orchestra.contrib.orchestration import ServiceController, replace from orchestra.contrib.orchestration import ServiceController, replace
from orchestra.settings import NEW_SERVERS
from django.template import Template, Context
from .. import settings from .. import settings
@ -41,6 +43,14 @@ class WordPressController(WebAppServiceMixin, ServiceController):
def save(self, webapp): def save(self, webapp):
context = self.get_context(webapp) context = self.get_context(webapp)
perms = Template(textwrap.dedent("""\
{% if sftpuser %}
exc('chown -R {{ sftpuser }}:{{ sftpuser }} {{ app_path }}'); {% else %}
exc('chown -R {{ user }}:{{ group }} {{ app_path }}');
{% endif %}
"""
))
context.update({'perms' : perms.render(Context(context))})
self.append(textwrap.dedent("""\ self.append(textwrap.dedent("""\
if (count(glob("%(app_path)s/*")) > 1) { if (count(glob("%(app_path)s/*")) > 1) {
die("App directory not empty."); die("App directory not empty.");
@ -96,7 +106,8 @@ class WordPressController(WebAppServiceMixin, ServiceController):
foreach ( $config_file as $line_num => $line ) { foreach ( $config_file as $line_num => $line ) {
fwrite($fw, $line); fwrite($fw, $line);
} }
exc('chown -R %(user)s:%(group)s %(app_path)s'); //exc('chown -R %(user)s:%(group)s %(app_path)s');
%(perms)s
// Run wordpress installation process // Run wordpress installation process
@ -140,9 +151,10 @@ class WordPressController(WebAppServiceMixin, ServiceController):
'db_name': webapp.data['db_name'], 'db_name': webapp.data['db_name'],
'db_user': webapp.data['db_user'], 'db_user': webapp.data['db_user'],
'password': webapp.data['password'], 'password': webapp.data['password'],
'db_host': settings.WEBAPPS_DEFAULT_MYSQL_DATABASE_HOST, 'db_host': 'localhost' if webapp.target_server.name in NEW_SERVERS else settings.WEBAPPS_DEFAULT_MYSQL_DATABASE_HOST,
'email': webapp.account.email, 'email': webapp.account.email,
'title': "%s blog's" % webapp.account.get_full_name(), 'title': "%s blog's" % webapp.account.get_full_name(),
'cms_cache_dir': os.path.normpath(settings.WEBAPPS_CMS_CACHE_DIR) 'cms_cache_dir': os.path.normpath(settings.WEBAPPS_CMS_CACHE_DIR),
'sftpuser': webapp.sftpuser.username if webapp.target_server.name in NEW_SERVERS else None ,
}) })
return replace(context, '"', "'") return replace(context, '"', "'")

View File

@ -33,7 +33,7 @@ class DetailListFilter(SimpleListFilter):
for field, values in apptype.get_detail_lookups().items(): for field, values in apptype.get_detail_lookups().items():
for value in values: for value in values:
lookup_map[value[0]] = field lookup_map[value[0]] = field
ret.add(value) ret.add(tuple(value))
self.lookup_map = lookup_map self.lookup_map = lookup_map
return sorted(list(ret), key=lambda e: e[1]) return sorted(list(ret), key=lambda e: e[1])
@ -47,5 +47,5 @@ class DetailListFilter(SimpleListFilter):
except KeyError: except KeyError:
return queryset return queryset
else: else:
return queryset.filter(data__contains='"%s":"%s"' % (field, value)) return queryset.filter(data__contains=value)
return queryset return queryset

View File

@ -99,12 +99,26 @@ WEBAPPS_PHP_VERSIONS = Setting('WEBAPPS_PHP_VERSIONS', (
('5.3-cgi', 'PHP 5.3 FCGID'), ('5.3-cgi', 'PHP 5.3 FCGID'),
('5.2-cgi', 'PHP 5.2 FCGID'), ('5.2-cgi', 'PHP 5.2 FCGID'),
('4-cgi', 'PHP 4 FCGID'), ('4-cgi', 'PHP 4 FCGID'),
('7-fpm', 'PHP 7 FPM') ('7.0-fpm', 'PHP 7 FPM'),
('7.3-fpm', 'PHP 7.3 FPM'),
('7.4-fpm', 'PHP 7.4 FPM (web-11)'),
('8.1-fpm', 'PHP 8.1 FPM (web-12)'),
('8.2-fpm', 'PHP 8.2 FPM (web-12)'),
), ),
help_text="Execution modle choose by ending -fpm or -cgi.", help_text="Execution modle choose by ending -fpm or -cgi.",
validators=[Setting.validate_choices] validators=[Setting.validate_choices]
) )
WEBAPPS_PHP_VERSIONS_SERVERS = Setting('WEBAPPS_PHP_VERSIONS_SERVERS', {
'web.pangea.lan' : ('php5.6-fpm', '7.0-fpm',),
'web-ng' : ('5.6-fpm', '7.0-fpm', '7.3-fpm',),
'web-11.pangea.lan': ('7.4-fpm',),
'web-12.pangea.lan' : ('8.1-fpm', '8.2-fpm'),
'bookworm' : ('8.1-fpm', '8.2-fpm'),
},
help_text="PHP available for each server",
)
WEBAPPS_DEFAULT_PHP_VERSION = Setting('WEBAPPS_DEFAULT_PHP_VERSION', WEBAPPS_DEFAULT_PHP_VERSION = Setting('WEBAPPS_DEFAULT_PHP_VERSION',
'5.6-fpm', '5.6-fpm',

View File

@ -6,10 +6,13 @@ from django.utils.translation import gettext_lazy as _
from rest_framework import serializers from rest_framework import serializers
from orchestra.contrib.databases.models import Database, DatabaseUser from orchestra.contrib.databases.models import Database, DatabaseUser
from orchestra.contrib.orchestration.models import Server
from orchestra.forms.widgets import SpanWidget from orchestra.forms.widgets import SpanWidget
from orchestra.utils.python import random_ascii from orchestra.utils.python import random_ascii
from orchestra.settings import NEW_SERVERS
from .php import PHPApp, PHPAppForm, PHPAppSerializer from .php import PHPApp, PHPAppForm, PHPAppSerializer
from .. import settings
class CMSAppForm(PHPAppForm): class CMSAppForm(PHPAppForm):
@ -69,13 +72,19 @@ class CMSApp(PHPApp):
def get_password(self): def get_password(self):
return random_ascii(10) return random_ascii(10)
def get_server(self):
server = self.instance.target_server
return server
def validate(self): def validate(self):
super(CMSApp, self).validate() super(CMSApp, self).validate()
create = not self.instance.pk create = not self.instance.pk
if create: if create:
db = Database(name=self.get_db_name(), account=self.instance.account, type=self.db_type) default_server_mysql = Server.objects.get(name=settings.WEBAPPS_DEFAULT_MYSQL_DATABASE_HOST)
server = self.get_server() if self.get_server().name in NEW_SERVERS else default_server_mysql
db = Database(name=self.get_db_name(), account=self.instance.account, type=self.db_type, target_server=server)
user = DatabaseUser(username=self.get_db_user(), password=self.get_password(), user = DatabaseUser(username=self.get_db_user(), password=self.get_password(),
account=self.instance.account, type=self.db_type) account=self.instance.account, type=self.db_type, target_server=server)
for obj in (db, user): for obj in (db, user):
try: try:
obj.full_clean() obj.full_clean()
@ -88,9 +97,11 @@ class CMSApp(PHPApp):
db_name = self.get_db_name() db_name = self.get_db_name()
db_user = self.get_db_user() db_user = self.get_db_user()
password = self.get_password() password = self.get_password()
db, db_created = self.instance.account.databases.get_or_create(name=db_name, type=self.db_type) default_server_mysql = Server.objects.get(name=settings.WEBAPPS_DEFAULT_MYSQL_DATABASE_HOST)
server = self.get_server() if self.get_server().name in NEW_SERVERS else default_server_mysql
db, db_created = self.instance.account.databases.get_or_create(name=db_name, type=self.db_type, target_server=server)
if db_created: if db_created:
user = DatabaseUser(username=db_user, account=self.instance.account, type=self.db_type) user = DatabaseUser(username=db_user, account=self.instance.account, type=self.db_type, target_server=server)
user.set_password(password) user.set_password(password)
user.save() user.save()
db.users.add(user) db.users.add(user)

View File

@ -26,16 +26,22 @@ class PHPAppForm(ExtendedPluginDataForm):
initial=settings.WEBAPPS_DEFAULT_PHP_VERSION, initial=settings.WEBAPPS_DEFAULT_PHP_VERSION,
help_text=help_message) help_text=help_message)
# def clean_php_version(self): def clean_php_version(self):
# # TODO: restriccin PHP diferentes servers # valida que la version PHP este asignada al servidor
# if not self.instance.id: php_version = self.cleaned_data.get('php_version')
# webapp_server = self.cleaned_data.get("target_server") if not self.instance.id:
# php_version = self.cleaned_data.get('php_version') webapp_server = self.cleaned_data.get("target_server")
# if webapp_server is None: else:
# pass webapp_server = self.instance.target_server
# else:
# if webapp_server.name in NEW_SERVERS and not username: if webapp_server is None:
# self.add_error("php_version", _(f"Server {webapp_server} not allow {php_version}")) pass
else:
if php_version not in settings.WEBAPPS_PHP_VERSIONS_SERVERS[webapp_server.name]:
self.add_error("php_version", _(f"Server {webapp_server.name} not allow {php_version}"))
else:
return php_version
class PHPAppSerializer(serializers.Serializer): class PHPAppSerializer(serializers.Serializer):