Fixes in proxy virtualhost
This commit is contained in:
parent
b2b879c3f8
commit
d3d041f569
9 changed files with 84 additions and 21 deletions
50
scripts/delete_php.py
Normal file
50
scripts/delete_php.py
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/python3 -u
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
#from pastafariutils.unix import add_user, del_user
|
||||||
|
from pathlib import Path
|
||||||
|
from subprocess import call, DEVNULL
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
import shutil
|
||||||
|
import pwd
|
||||||
|
import distro
|
||||||
|
import subprocess
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
parser=argparse.ArgumentParser(prog='delete_wordpress.py', description='A tool for delete wordpress')
|
||||||
|
|
||||||
|
parser.add_argument('--domain', help='Domain to delete', required=True)
|
||||||
|
|
||||||
|
args=parser.parse_args()
|
||||||
|
|
||||||
|
apache_cmd='apache2'
|
||||||
|
|
||||||
|
apachectl='apache2ctl'
|
||||||
|
|
||||||
|
linux_distro=distro.id()
|
||||||
|
|
||||||
|
if linux_distro!='debian' and linux_distro!='ubuntu':
|
||||||
|
apache_cmd='httpd'
|
||||||
|
apachectl='apachectl'
|
||||||
|
|
||||||
|
print('Deleting the php apache configuration of virtualhost..')
|
||||||
|
|
||||||
|
apache_php='/etc/{}/vhosts.d/php/{}-php.conf'.format(apache_cmd, args.domain)
|
||||||
|
|
||||||
|
if os.path.isfile(apache_php):
|
||||||
|
if subprocess.call("sudo rm %s" % (apache_php), shell=True) > 0:
|
||||||
|
print('Error: cannot delete php config %s' % apache_php)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print('Deleted the php apache configuration of virtualhost..')
|
||||||
|
|
||||||
|
if subprocess.call("sudo systemctl restart %s" % (apache_cmd), shell=True) > 0:
|
||||||
|
print('Error: cannot restart Apache server')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print('Deleted the apache configuration of virtualhost successfully..')
|
||||||
|
|
||||||
|
|
@ -13,6 +13,8 @@
|
||||||
Require all granted
|
Require all granted
|
||||||
</Directory>
|
</Directory>
|
||||||
IncludeOptional vhosts.d/extra/$domain-*.conf
|
IncludeOptional vhosts.d/extra/$domain-*.conf
|
||||||
|
IncludeOptional vhosts.d/extra/proxy/$domain-*.conf
|
||||||
|
IncludeOptional vhosts.d/extra/proxyphp/$domain-*.conf
|
||||||
ErrorLog /var/log/$apache_cmd/$domain-error.log
|
ErrorLog /var/log/$apache_cmd/$domain-error.log
|
||||||
LogLevel error
|
LogLevel error
|
||||||
CustomLog /var/log/$apache_cmd/$domain-access.log combined
|
CustomLog /var/log/$apache_cmd/$domain-access.log combined
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,11 @@ Linux::install_package($linux_package);
|
||||||
|
|
||||||
Linux::json_log('Create directories for Apache manager...', $error=0, $status=0, $progress=0, $no_progress=1);
|
Linux::json_log('Create directories for Apache manager...', $error=0, $status=0, $progress=0, $no_progress=1);
|
||||||
|
|
||||||
$create_dirs=['debian' => ["sudo mkdir -p /etc/apache2/vhosts.d/ && sudo mkdir -p /etc/apache2/vhosts.d/php/ && sudo mkdir -p /etc/apache2/vhosts.d/extra/"]];
|
$create_dirs=['debian' => ["sudo mkdir -p /etc/apache2/vhosts.d/ && sudo mkdir -p /etc/apache2/vhosts.d/{php,extra/proxyphp,extra/proxy}"]];
|
||||||
|
|
||||||
$create_dirs['ubuntu']=$create_dirs['debian'];
|
$create_dirs['ubuntu']=$create_dirs['debian'];
|
||||||
|
|
||||||
$create_dirs['fedora']=["sudo mkdir -p /etc/httpd/vhosts.d/{php,extra} "];
|
$create_dirs['fedora']=["sudo mkdir -p /etc/httpd/vhosts.d/{php,extra/proxyphp,extra/proxy} "];
|
||||||
|
|
||||||
$create_dirs['almalinux']=$create_dirs['fedora'];
|
$create_dirs['almalinux']=$create_dirs['fedora'];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,9 @@ if os.path.isfile(apache_php):
|
||||||
|
|
||||||
apache_webapp='/etc/{}/vhosts.d/extra/{}-{}.conf'.format(apache_cmd, args.domain, args.webapp)
|
apache_webapp='/etc/{}/vhosts.d/extra/{}-{}.conf'.format(apache_cmd, args.domain, args.webapp)
|
||||||
|
|
||||||
apache_sub0_webapp='/etc/{}/vhosts.d/extra/{}-000-{}.conf'.format(apache_cmd, args.domain, args.webapp)
|
apache_sub0_webapp='/etc/{}/vhosts.d/extra/proxy/{}-{}.conf'.format(apache_cmd, args.domain, args.webapp)
|
||||||
|
|
||||||
apache_sub1_webapp='/etc/{}/vhosts.d/extra/{}-001-{}.conf'.format(apache_cmd, args.domain, args.webapp)
|
apache_sub1_webapp='/etc/{}/vhosts.d/extra/proxyphp/{}-{}.conf'.format(apache_cmd, args.domain, args.webapp)
|
||||||
|
|
||||||
if os.path.isfile(apache_webapp):
|
if os.path.isfile(apache_webapp):
|
||||||
if subprocess.call("sudo rm %s" % (apache_webapp), shell=True) > 0:
|
if subprocess.call("sudo rm %s" % (apache_webapp), shell=True) > 0:
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,11 @@ name_service=os.path.basename(home_user[:-1]).strip()
|
||||||
|
|
||||||
domain=os.path.basename(home_user[:-1].replace(name_service, '')[:-1]).strip()
|
domain=os.path.basename(home_user[:-1].replace(name_service, '')[:-1]).strip()
|
||||||
|
|
||||||
|
if home_user.find('/htdocs/', -8)!=-1:
|
||||||
|
home_user=home_user.replace('htdocs', 'flask')
|
||||||
|
|
||||||
if name_service=='htdocs':
|
if name_service=='htdocs':
|
||||||
name_service='flask'
|
name_service='flask'
|
||||||
#home_user=home_user.replace('flask', 'htdocs')
|
|
||||||
|
|
||||||
#print(domain)
|
#print(domain)
|
||||||
|
|
||||||
|
|
@ -45,7 +47,7 @@ if subprocess.call('sudo systemctl stop %s-%s.service && sudo rm /etc/systemd/sy
|
||||||
print('Error: cannot delete app service in systemd...')
|
print('Error: cannot delete app service in systemd...')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if subprocess.call("sudo su %s -s /bin/bash -c 'rm -f -r %s'" % (args.user, args.home_user), shell=True) > 0:
|
if subprocess.call("sudo su %s -s /bin/bash -c 'rm -f -r %s'" % (args.user, home_user), shell=True) > 0:
|
||||||
print('Error: cannot delete %s' % args.home_user)
|
print('Error: cannot delete %s' % args.home_user)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,12 +148,14 @@ if subprocess.call("sudo su %s -s /bin/bash -c 'git clone %s %sapp && cd %sapp &
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if path=='/':
|
if path=='/':
|
||||||
base_name_file='{}-001-{}.conf'.format(args.domain, name)
|
base_name_file='{}-{}.conf'.format(args.domain, name)
|
||||||
else:
|
else:
|
||||||
base_name_file='{}-000-{}.conf'.format(args.domain, name)
|
base_name_file='{}-{}.conf'.format(args.domain, name)
|
||||||
|
|
||||||
name_file='/home/{}/{}'.format(system_user, base_name_file)
|
name_file='/home/{}/{}'.format(system_user, base_name_file)
|
||||||
|
|
||||||
|
apache_path='/proxy'
|
||||||
|
|
||||||
with open(name_file, 'w') as f:
|
with open(name_file, 'w') as f:
|
||||||
|
|
||||||
f.write("ProxyPreserveHost On\n")
|
f.write("ProxyPreserveHost On\n")
|
||||||
|
|
@ -177,9 +179,12 @@ with open(name_file, 'w') as f:
|
||||||
f.write("ProxyPass !\n")
|
f.write("ProxyPass !\n")
|
||||||
f.write("</Location>\n")
|
f.write("</Location>\n")
|
||||||
|
|
||||||
|
else:
|
||||||
|
apache_path=''
|
||||||
|
|
||||||
|
|
||||||
print('Updating apache configuration for flask outside of htdocs...')
|
print('Updating apache configuration for flask outside of htdocs...')
|
||||||
if subprocess.call('sudo mv {} /etc/{}/vhosts.d/extra && sudo chown root:root /etc/{}/vhosts.d/extra/{}'.format(name_file, apache_cmd, apache_cmd, base_name_file), shell=True) > 0:
|
if subprocess.call('sudo mv {} /etc/{}/vhosts.d/extra{} && sudo chown root:root /etc/{}/vhosts.d/extra{}/{}'.format(name_file, apache_cmd, apache_path, apache_cmd, apache_path, base_name_file), shell=True) > 0:
|
||||||
print('Error')
|
print('Error')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -182,16 +182,16 @@ if args.path!='/':
|
||||||
</Location> \n\
|
</Location> \n\
|
||||||
".format(args.path[:-1], home_user, home_user, args.path[:-1])
|
".format(args.path[:-1], home_user, home_user, args.path[:-1])
|
||||||
|
|
||||||
base_name_file='{}-002-{}.conf'.format(args.domain, os.path.basename(args.path[1:-1]))
|
base_name_file='{}-{}.conf'.format(args.domain, os.path.basename(args.path[1:-1]))
|
||||||
|
|
||||||
name_file='/home/{}/{}-002-{}.conf'.format(system_user, args.domain, os.path.basename(args.path[1:-1]))
|
name_file='/home/{}/{}-{}.conf'.format(system_user, args.domain, os.path.basename(args.path[1:-1]))
|
||||||
|
|
||||||
with open(name_file, 'w') as f:
|
with open(name_file, 'w') as f:
|
||||||
f.write(alias_apache)
|
f.write(alias_apache)
|
||||||
|
|
||||||
|
|
||||||
print('Updating apache configuration for wordpress outside of htdocs...\n')
|
print('Updating apache configuration for wordpress outside of htdocs...\n')
|
||||||
if subprocess.call('sudo mv {} /etc/{}/vhosts.d/extra && sudo chown root:root /etc/{}/vhosts.d/extra/{}'.format(name_file, apache_cmd, apache_cmd, base_name_file), shell=True) > 0:
|
if subprocess.call('sudo mv {} /etc/{}/vhosts.d/extra/proxyphp && sudo chown root:root /etc/{}/vhosts.d/extra/proxyphp/{}'.format(name_file, apache_cmd, apache_cmd, base_name_file), shell=True) > 0:
|
||||||
print('Error')
|
print('Error')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
@ -200,7 +200,7 @@ if args.path!='/':
|
||||||
print('Restarting apache...')
|
print('Restarting apache...')
|
||||||
|
|
||||||
if subprocess.call('sudo '+apachectl+' configtest && sudo systemctl restart '+apache_cmd, shell=True) > 0:
|
if subprocess.call('sudo '+apachectl+' configtest && sudo systemctl restart '+apache_cmd, shell=True) > 0:
|
||||||
subprocess.call('sudo rm /etc/{}/vhosts.d/extra/{}'.format(apache_cmd, base_name_file), shell=True)
|
subprocess.call('sudo rm /etc/{}/vhosts.d/extra/proxyphp/{}'.format(apache_cmd, base_name_file), shell=True)
|
||||||
print('Error: Error in configtest\n')
|
print('Error: Error in configtest\n')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,21 +69,25 @@ if args.path:
|
||||||
if path=='':
|
if path=='':
|
||||||
path='/'
|
path='/'
|
||||||
|
|
||||||
|
apache_path='/proxy'
|
||||||
|
|
||||||
if path=='/':
|
if path=='/':
|
||||||
|
|
||||||
name='proxy'
|
name='proxy'
|
||||||
|
|
||||||
base_name_file='{}-001-{}.conf'.format(args.domain, name)
|
#base_name_file='{}-{}.conf'.format(args.domain, name)
|
||||||
|
|
||||||
name_file='/home/{}/{}-001-{}.conf'.format(system_user, args.domain, name)
|
#name_file='/home/{}/{}-{}.conf'.format(system_user, args.domain, name)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
apache_path=''
|
||||||
|
|
||||||
name=os.path.basename(home_user[:-1]).strip()
|
name=os.path.basename(home_user[:-1]).strip()
|
||||||
|
|
||||||
base_name_file='{}-000-{}.conf'.format(args.domain, name)
|
base_name_file='{}-{}.conf'.format(args.domain, name)
|
||||||
|
|
||||||
name_file='/home/{}/{}-000-{}.conf'.format(system_user, args.domain, name)
|
name_file='/home/{}/{}-{}.conf'.format(system_user, args.domain, name)
|
||||||
|
|
||||||
with open(name_file, 'w') as f:
|
with open(name_file, 'w') as f:
|
||||||
|
|
||||||
|
|
@ -126,7 +130,7 @@ with open(name_file, 'w') as f:
|
||||||
|
|
||||||
print('Updating apache configuration for application outside of htdocs...')
|
print('Updating apache configuration for application outside of htdocs...')
|
||||||
|
|
||||||
if subprocess.call('sudo mv {} /etc/{}/vhosts.d/extra && sudo chown root:root /etc/{}/vhosts.d/extra/{}'.format(name_file, apache_cmd, apache_cmd, base_name_file), shell=True) > 0:
|
if subprocess.call('sudo mv {} /etc/{}/vhosts.d/extra{} && sudo chown root:root /etc/{}/vhosts.d/extra{}/{}'.format(name_file, apache_cmd, apache_path, apache_cmd, apache_path, base_name_file), shell=True) > 0:
|
||||||
print('Error')
|
print('Error')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -155,14 +155,14 @@ if args.path!='/':
|
||||||
</Location> \n\
|
</Location> \n\
|
||||||
".format(args.path[:-1], home_user, home_user, args.path[:-1])
|
".format(args.path[:-1], home_user, home_user, args.path[:-1])
|
||||||
|
|
||||||
name_file='/home/{}/{}-002-{}.conf'.format(system_user, args.domain, os.path.basename(args.path[1:-1]))
|
name_file='/home/{}/{}-{}.conf'.format(system_user, args.domain, os.path.basename(args.path[1:-1]))
|
||||||
|
|
||||||
with open(name_file, 'w') as f:
|
with open(name_file, 'w') as f:
|
||||||
f.write(alias_apache)
|
f.write(alias_apache)
|
||||||
|
|
||||||
|
|
||||||
print('Updating apache configuration for wordpress outside of htdocs...')
|
print('Updating apache configuration for wordpress outside of htdocs...')
|
||||||
if subprocess.call('sudo mv {} /etc/{}/vhosts.d/extra'.format(name_file, apache_cmd), shell=True) > 0:
|
if subprocess.call('sudo mv {} /etc/{}/vhosts.d/extra/proxyphp'.format(name_file, apache_cmd), shell=True) > 0:
|
||||||
print('Error')
|
print('Error')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue