Fixed bugs to create servers
This commit is contained in:
parent
92ae8e7d36
commit
44ffe2da55
5 changed files with 144 additions and 8 deletions
|
|
@ -39,8 +39,6 @@ if [ "$DISTRO" = 'debian' ] || [ "$DISTRO" = 'ubuntu' ]; then
|
||||||
sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
|
sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
|
||||||
sudo ln -s /usr/share/keyrings/deb.sury.org-php.gpg /etc/apt/trusted.gpg.d/deb.sury.org-php.gpg
|
sudo ln -s /usr/share/keyrings/deb.sury.org-php.gpg /etc/apt/trusted.gpg.d/deb.sury.org-php.gpg
|
||||||
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
|
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
|
||||||
sudo apt-get update
|
|
||||||
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
|
|
@ -62,6 +60,8 @@ if [ "$DISTRO" = 'debian' ] || [ "$DISTRO" = 'ubuntu' ]; then
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#sudo DEBIAN_FRONTEND="noninteractive" apt-get -y upgrade
|
||||||
|
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
|
|
@ -71,11 +71,54 @@ if [ "$DISTRO" = 'debian' ] || [ "$DISTRO" = 'ubuntu' ]; then
|
||||||
else
|
else
|
||||||
|
|
||||||
echo '{"error": 1, "status": 1, "progress": 100, "no_progress":0, "message": "Error: cannot update apt repos with sury repos, retriying..."}'
|
echo '{"error": 1, "status": 1, "progress": 100, "no_progress":0, "message": "Error: cannot update apt repos with sury repos, retriying..."}'
|
||||||
|
|
||||||
|
sudo curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg
|
||||||
|
sudo ln -s /usr/share/keyrings/deb.sury.org-php.gpg /etc/apt/trusted.gpg.d/deb.sury.org-php.gpg
|
||||||
|
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
|
||||||
|
|
||||||
|
sudo apt-get update
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
|
||||||
|
echo '{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Updated with sury repos sucessfully..."}'
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
echo '{"error": 1, "status": 1, "progress": 100, "no_progress":0, "message": "Error: cannot update apt repos with sury repos, probably a bug in sury repos?"}'
|
||||||
|
|
||||||
|
exit
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Reinstall normal php because sury repos upgrade change stable php
|
||||||
|
|
||||||
|
sudo DEBIAN_FRONTEND="noninteractive" apt-get install -y php-fpm php-gd php-json php-mysql php-curl php-mbstring php-intl php-imagick php-xml php-zip php-redis unzip
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
|
||||||
|
echo '{"error": 0, "status": 0, "progress": 100, "no_progress":0, "message": "Updated php with sury repos sucessfully..."}'
|
||||||
|
|
||||||
|
else
|
||||||
|
|
||||||
|
echo '{"error": 1, "status": 1, "progress": 100, "no_progress":0, "message": "Error: cannot update php with sury repos, retriying..."}'
|
||||||
|
|
||||||
exit
|
exit
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Reload php version because sury repos upgrade change stable php
|
||||||
|
|
||||||
|
PHP_VERSION=$(php -v 2>/dev/null | grep -oE "PHP ([0-9]+\.[0-9]+)" | grep -oE "[0-9]+\.[0-9]+")
|
||||||
|
|
||||||
|
CHOOSE_PHP_VERSION="8.2"
|
||||||
|
|
||||||
|
if [ -n $1 ]; then
|
||||||
|
|
||||||
|
CHOOSE_PHP_VERSION=$1
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$PHP_VERSION" = "$CHOOSE_PHP_VERSION" ]; then
|
if [ "$PHP_VERSION" = "$CHOOSE_PHP_VERSION" ]; then
|
||||||
|
|
||||||
|
|
@ -87,7 +130,7 @@ if [ "$DISTRO" = 'debian' ] || [ "$DISTRO" = 'ubuntu' ]; then
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
sudo apt-get install -y php${CHOOSE_PHP_VERSION} php${CHOOSE_PHP_VERSION}-fpm php${CHOOSE_PHP_VERSION}-gd php${CHOOSE_PHP_VERSION}-mysql php${CHOOSE_PHP_VERSION}-curl php${CHOOSE_PHP_VERSION}-mbstring php${CHOOSE_PHP_VERSION}-intl php${CHOOSE_PHP_VERSION}-imagick php${CHOOSE_PHP_VERSION}-xml php${CHOOSE_PHP_VERSION}-zip php${CHOOSE_PHP_VERSION}-redis unzip mariadb-client
|
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php${CHOOSE_PHP_VERSION} php${CHOOSE_PHP_VERSION}-fpm php${CHOOSE_PHP_VERSION}-gd php${CHOOSE_PHP_VERSION}-mysql php${CHOOSE_PHP_VERSION}-curl php${CHOOSE_PHP_VERSION}-mbstring php${CHOOSE_PHP_VERSION}-intl php${CHOOSE_PHP_VERSION}-imagick php${CHOOSE_PHP_VERSION}-xml php${CHOOSE_PHP_VERSION}-zip php${CHOOSE_PHP_VERSION}-redis unzip mariadb-client
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
|
|
||||||
|
|
@ -163,7 +206,7 @@ if [ "$DISTRO" = 'debian' ] || [ "$DISTRO" = 'ubuntu' ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
elif [ "$DISTRO" = 'rocky' ] || [ "$DISTRO" = 'fedora' ]; then
|
elif [ "$DISTRO" = 'rocky' ] || [ "$DISTRO" = 'almalinux' ] || [ "$DISTRO" = 'fedora' ]; then
|
||||||
|
|
||||||
echo "Update PHP if you need..."
|
echo "Update PHP if you need..."
|
||||||
|
|
||||||
|
|
@ -242,7 +285,7 @@ else
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sed -i 's/pm = dynamic/pm = ondemand/g' /etc/php-legacy/php-fpm.d/www.conf
|
sudo sed -i 's/pm = dynamic/pm = ondemand/g' /etc/php-legacy/php-fpm.d/www.conf
|
||||||
sudo sed -i 's/^;zend_extension=opcache$/zend_extension=opcache/g' /etc/php-legacy/php.ini
|
sudo sed -i 's/^;zend_extension=opcache$/zend_extension=opcache/g' /etc/php-legacy/php.ini
|
||||||
sudo sed -i 's/^;extension=iconv$/extension=iconv/g' /etc/php-legacy/php.ini
|
sudo sed -i 's/^;extension=iconv$/extension=iconv/g' /etc/php-legacy/php.ini
|
||||||
sudo sed -i 's/^;extension=intl$/extension=intl/g' /etc/php-legacy/php.ini
|
sudo sed -i 's/^;extension=intl$/extension=intl/g' /etc/php-legacy/php.ini
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,9 @@ if linux_distro=='arch':
|
||||||
|
|
||||||
if linux_distro=='rocky' or linux_distro=='almalinux' or linux_distro=='fedora':
|
if linux_distro=='rocky' or linux_distro=='almalinux' or linux_distro=='fedora':
|
||||||
|
|
||||||
if linux.shell_command('sudo systemctl status firewalld'):
|
ret=linux.shell_command('sudo systemctl status firewalld')
|
||||||
|
print(ret)
|
||||||
|
if ret:
|
||||||
|
|
||||||
linux.shell_command("sudo firewall-cmd --add-service=http && sudo firewall-cmd --add-service=http --permanent && sudo firewall-cmd --add-service=https && sudo firewall-cmd --add-service=https --permanent")
|
linux.shell_command("sudo firewall-cmd --add-service=http && sudo firewall-cmd --add-service=http --permanent && sudo firewall-cmd --add-service=https && sudo firewall-cmd --add-service=https --permanent")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import pwd
|
||||||
import distro
|
import distro
|
||||||
import subprocess
|
import subprocess
|
||||||
import pwd
|
import pwd
|
||||||
|
import grp
|
||||||
|
|
||||||
php_version={'php74': 'php7.4', 'php80': 'php8.0', 'php81': 'php8.1', 'php82': 'php8.2'}
|
php_version={'php74': 'php7.4', 'php80': 'php8.0', 'php81': 'php8.1', 'php82': 'php8.2'}
|
||||||
|
|
||||||
|
|
@ -397,7 +398,19 @@ def manage():
|
||||||
if not ret_user:
|
if not ret_user:
|
||||||
|
|
||||||
print("User %s exists, used for the new site" % args.user)
|
print("User %s exists, used for the new site" % args.user)
|
||||||
|
|
||||||
|
#Need add to group apache if not. Need for red hat and derivatives.
|
||||||
|
|
||||||
|
|
||||||
|
g=grp.getgrnam('apache')
|
||||||
|
#grp.struct_group(gr_name='apache', gr_passwd='x', gr_gid=48, gr_mem=['absurdo'])
|
||||||
|
|
||||||
|
if args.user not in g.gr_mem:
|
||||||
|
if call("sudo usermod -a -G %s %s" % (apache_group, args.user), shell=True) > 0:
|
||||||
|
print('Error, cannot add group to user')
|
||||||
|
exit(1)
|
||||||
|
else:
|
||||||
|
print('Added user to apache group')
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#!/opt/pythonenv/bin/python3 -u
|
#!/usr/bin/python3 -u
|
||||||
|
|
||||||
import sys, os
|
import sys, os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
@ -32,6 +32,8 @@ user=args.user
|
||||||
|
|
||||||
json_return={}
|
json_return={}
|
||||||
|
|
||||||
|
print('Updating phpmyadmin...')
|
||||||
|
|
||||||
if subprocess.call("sudo su %s -s /bin/bash -c 'cd %s && composer update'" % (user, home_user), shell=True) > 0:
|
if subprocess.call("sudo su %s -s /bin/bash -c 'cd %s && composer update'" % (user, home_user), shell=True) > 0:
|
||||||
json_return['error']=1
|
json_return['error']=1
|
||||||
json_return['status']=1
|
json_return['status']=1
|
||||||
|
|
|
||||||
76
tasks/apache/apache/delete_vhost.py
Normal file
76
tasks/apache/apache/delete_vhost.py
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
#/usr/bin/env python3
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
|
#from modules.pastafari2.models.servers import Server
|
||||||
|
from modules.webservers.models.webservers import WebServer, VirtualHost
|
||||||
|
import json
|
||||||
|
|
||||||
|
from modules.pastafari2.libraries.task import Task
|
||||||
|
from modules.pastafari2.models.pastafari2 import ServerDbTask
|
||||||
|
#import distro
|
||||||
|
|
||||||
|
class ServerTask(Task):
|
||||||
|
|
||||||
|
def __init__(self, server, conn, remote_user='root', remote_password='', private_key='./ssh/id_rsa', password_key='', remote_path='pastafari2', task_id=0, data={}, port=22):
|
||||||
|
|
||||||
|
super().__init__(server, conn, remote_user, remote_password, private_key, password_key, remote_path, task_id, data, port)
|
||||||
|
|
||||||
|
self.name_task='Remove virtualhost in server'
|
||||||
|
|
||||||
|
self.description_task='Virtual host delete in a server, or many of them'
|
||||||
|
|
||||||
|
self.codename_task='del_virtualhost_apache'
|
||||||
|
|
||||||
|
self.files=[]
|
||||||
|
|
||||||
|
self.files=[['modules/apache/scripts/manage_apache.py', 0o755]]
|
||||||
|
|
||||||
|
# Format first array element is command with the interpreter, the task is agnostic, the files in os directory. The commands are setted with 750 permission.
|
||||||
|
# First element is the file, next elements are the arguments
|
||||||
|
|
||||||
|
self.commands_to_execute=[['modules/apache/scripts/manage_apache.py', '']]
|
||||||
|
|
||||||
|
#THe files to delete
|
||||||
|
|
||||||
|
self.delete_files=[]
|
||||||
|
|
||||||
|
self.delete_directories=['modules/webservers/scripts']
|
||||||
|
|
||||||
|
#self.task=Task(conn)
|
||||||
|
|
||||||
|
self.one_time=False
|
||||||
|
|
||||||
|
self.version='1.0'
|
||||||
|
|
||||||
|
self.path_module='admin_app.webservers'
|
||||||
|
|
||||||
|
def pre_task(self):
|
||||||
|
|
||||||
|
#self.commands_to_execute=[['modules/webservers/scripts/manager/${os_server}/manage_apache.py', '--password=%s' % self.extra_data['mysql_password']]]
|
||||||
|
|
||||||
|
# usage: manager.py [-h] --operation OPERATION --domain DOMAIN [--email EMAIL] [--user USER] [--root_dir ROOT_DIR] [--indexes] [--allow_override]
|
||||||
|
|
||||||
|
indexes=''
|
||||||
|
|
||||||
|
if 'indexes' in self.data:
|
||||||
|
indexes='--indexes'
|
||||||
|
|
||||||
|
allow_override=''
|
||||||
|
|
||||||
|
if 'allow_override' in self.data:
|
||||||
|
allow_override='--allow_override'
|
||||||
|
|
||||||
|
self.commands_to_execute=[['modules/apache/scripts/manage_apache.py', '--operation=remove --domain=%s --email=%s --user=%s --root_dir=%s --type_cgi=%s %s %s' % (self.data['domain'], self.data['email'], self.data['user'], self.data['root_dir'], self.data['cgi_type'], indexes, allow_override), 'sudo']]
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def post_task(self):
|
||||||
|
|
||||||
|
vhost=VirtualHost(self.connection)
|
||||||
|
vhost.safe_query()
|
||||||
|
|
||||||
|
#vhost.insert({'servers': servers, 'principal_ip': servers[0], 'domain': self.extra_data['domain'], 'email': self.extra_data['email'], 'user': self.extra_data['user'], 'root_dir': self.extra_data['root_dir'], 'indexes': self.extra_data['indexes'], 'allow_override': self.extra_data['allow_override']})
|
||||||
|
if not vhost.set_conditions('WHERE domain=%s', [self.data['domain']]).delete():
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
Loading…
Add table
Add a link
Reference in a new issue