77 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/python3.5
 | 
						|
import cgi
 | 
						|
import cgitb 
 | 
						|
cgitb.enable()
 | 
						|
import re
 | 
						|
import configparser
 | 
						|
from functions.headfoot import printheader,printfooter
 | 
						|
from functions.htmlsyntaxfc import htmlsyntax
 | 
						|
import subprocess
 | 
						|
import os
 | 
						|
# IMPORT DE LA CONFIGURATION
 | 
						|
config = configparser.ConfigParser()
 | 
						|
config.read('config.conf')
 | 
						|
 | 
						|
DOMAIN = config.get('general','domain')
 | 
						|
TEMPLATEPATH = config.get('general','templatepath')
 | 
						|
PROTO = config.get('general','proto')
 | 
						|
 | 
						|
VHOSTPATH = '/etc/apache2/sites-available/'
 | 
						|
 | 
						|
fs = cgi.FieldStorage()
 | 
						|
VHOSTNAME= fs.getvalue('VHOSTNAME')
 | 
						|
# EXTRACTION DES VARIABLES
 | 
						|
TEMPLATEFILE = open(TEMPLATEPATH, "r")
 | 
						|
TEMPLATE = TEMPLATEFILE.read()
 | 
						|
 | 
						|
ALLVARIABLES = re.findall(r'\$\$\w+', TEMPLATE)
 | 
						|
VARIABLES = ""
 | 
						|
 | 
						|
for i in ALLVARIABLES:
 | 
						|
    if VARIABLES.find(i) == -1:
 | 
						|
        VARIABLES = VARIABLES +" "+ i
 | 
						|
 | 
						|
VARIABLES = re.sub('[$$]', '', VARIABLES)
 | 
						|
 | 
						|
#######TODO REMPLACER LA TEMPLATE
 | 
						|
 | 
						|
for i in VARIABLES.split():
 | 
						|
    j = '$$' + i
 | 
						|
    key = fs.getvalue(i)
 | 
						|
    if key is None:
 | 
						|
        TEMPLATE = TEMPLATE.replace(j,'')
 | 
						|
    else:
 | 
						|
        TEMPLATE = TEMPLATE.replace(j, key)
 | 
						|
 | 
						|
 | 
						|
#######TODO ECRIRE LE FICHIER 
 | 
						|
 | 
						|
VHOSTFILE = open(VHOSTPATH + VHOSTNAME, 'w')
 | 
						|
 | 
						|
VHOSTFILE.write(TEMPLATE)
 | 
						|
VHOSTFILE.close()
 | 
						|
 | 
						|
FNULL = open(os.devnull, 'w')
 | 
						|
 | 
						|
 | 
						|
trash = subprocess.call(['/usr/bin/sudo', '/usr/sbin/a2ensite' , VHOSTNAME], stdout=FNULL, stderr=subprocess.STDOUT)
 | 
						|
trash = subprocess.call(['/usr/bin/sudo','/bin/systemctl','reload','apache2'], stdout=FNULL, stderr=subprocess.STDOUT)
 | 
						|
 | 
						|
TEMPLATE = htmlsyntax(TEMPLATE)
 | 
						|
 | 
						|
#######TODO GENERATION DES LETSENCRYPT
 | 
						|
 | 
						|
 | 
						|
printheader()
 | 
						|
 | 
						|
# BODY
 | 
						|
 | 
						|
print('<pre><b>Contenu de', VHOSTNAME, '</b><p>', TEMPLATE, '</p></pre>')
 | 
						|
 | 
						|
 | 
						|
 | 
						|
print('<br><a href="', PROTO , '://', DOMAIN , '/index.py">Retour</a>', sep='')
 | 
						|
 | 
						|
 | 
						|
printfooter()
 |