vhost
This commit is contained in:
parent
7ea0b948af
commit
6cc2f3e223
@ -1,12 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os, platform, subprocess, logging, argparse
|
||||
import sys, os, platform, subprocess, re, argparse
|
||||
|
||||
platform_support = ['Linux']
|
||||
|
||||
html_dir_path = ""
|
||||
logs_dir_path = ""
|
||||
|
||||
re_domain = r'^(?=.{1,253}$)(?!.*\.\..*)(?!\..*)([a-zA-Z0-9-]{,63}\.){,127}[a-zA-Z0-9-]{1,63}$'
|
||||
|
||||
def y_n_question(question_str):
|
||||
|
||||
yes = {'yes','y', 'ye', ''}
|
||||
@ -59,6 +61,39 @@ def sanity_chek_platform():
|
||||
else:
|
||||
sys.exit("Can not configure platform. Aborting...")
|
||||
|
||||
def vhost_add(domain):
|
||||
|
||||
global html_dir_path, logs_dir_path, re_domain
|
||||
|
||||
print(" adding vhost domain — " + domain)
|
||||
|
||||
if re.match(re_domain, domain) is None:
|
||||
print("Invalid domain name: " + domain + " -> pass")
|
||||
|
||||
www = os.path.join(html_dir_path + domain)
|
||||
os.makedirs(www, exist_ok=True)
|
||||
|
||||
logs = os.path.join(logs_dir_path + domain)
|
||||
os.makedirs(logs, exist_ok=True)
|
||||
|
||||
# debug: this file might not be here
|
||||
with open('vhost_tmpl') as vhost_tmpl_fp:
|
||||
vhost_tmpl = vhost_tmpl_fp.read()
|
||||
|
||||
usr = os.getlogin()
|
||||
|
||||
vhost = vhost_tmpl.replace("%domain?", domain).replace("%user?", usr)
|
||||
|
||||
# debug: write file directly to '/etc/apache2/sites-available/' ?
|
||||
vhost_file = os.path.join(www, domain + '.conf')
|
||||
|
||||
with open(vhost_file, 'w+') as vhost_file_fp:
|
||||
vhost_file_fp.write(vhost)
|
||||
|
||||
def vhost_remove(domain):
|
||||
print(" removing domain — " + domain)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
p = argparse.ArgumentParser(description='vhost helper')
|
||||
@ -69,7 +104,20 @@ if __name__ == "__main__":
|
||||
|
||||
args = p.parse_args()
|
||||
|
||||
print('1. sanity checks')
|
||||
|
||||
sanity_check_system()
|
||||
sanity_chek_platform()
|
||||
|
||||
print('2. vhosting')
|
||||
|
||||
for d in args.domain:
|
||||
if args.add:
|
||||
vhost_add(d)
|
||||
elif args.remove:
|
||||
vhost_remove(d)
|
||||
|
||||
print('done.')
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user