commit 0f53680f316069dbc4cd08225318e67a91eff56c Author: root Date: Tue Dec 19 23:39:22 2017 +0000 Alpha first commit diff --git a/config.conf b/config.conf new file mode 100644 index 0000000..926976c --- /dev/null +++ b/config.conf @@ -0,0 +1,4 @@ +[general] +domain = 10.1.9.118 +proto = http +templatepath = /etc/apache2/sites-available/999-template.conf diff --git a/create.py b/create.py new file mode 100755 index 0000000..8cdd221 --- /dev/null +++ b/create.py @@ -0,0 +1,71 @@ +#!/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) + 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('
Contenu de', VHOSTNAME, '

', TEMPLATE, '

') + + + +print('
Retour', sep='') + + +printfooter() diff --git a/file.py b/file.py new file mode 100755 index 0000000..9b74258 --- /dev/null +++ b/file.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3.5 +# -*- coding: utf-8 -*- + +import cgi +import cgitb +cgitb.enable() +import re +import configparser +from functions.headfoot import printheader,printfooter +from functions.htmlsyntaxfc import htmlsyntax +# IMPORT DE LA CONFIGURATION +config = configparser.ConfigParser() +config.read('config.conf') + +DOMAIN = config.get('general','domain') +PROTO = config.get('general','proto') + +# TRAITEMENT DES DATA +fs = cgi.FieldStorage() +VHOSTNAME = cgi.escape(fs.getvalue('file')) +VHOSTPATH = "/etc/apache2/sites-available/" + VHOSTNAME +VHOSTFILE = open(VHOSTPATH, "r") +VHOST = VHOSTFILE.read() + +VHOST = htmlsyntax(VHOST) +#VHOST = re.sub('<', '<', VHOST) +#VHOST = re.sub('>', '>', VHOST) + +# AFFICHAGE DES ENTETES +printheader() + +# BODY +print('', VHOSTNAME , '') +print("
")
+print('

', VHOST, '

' ) +print('
') +print('Retour', sep='') + +# AFFICHAGE DU FOOTER +printfooter() + diff --git a/functions/headfoot.py b/functions/headfoot.py new file mode 100755 index 0000000..59f4669 --- /dev/null +++ b/functions/headfoot.py @@ -0,0 +1,16 @@ +#!/usr/bin/python3.5 + +# DEBUG +import cgitb +cgitb.enable() + +def printheader(): + print("Content-Type: text/html\n") + + print (""" + + Ma Jolie petite Page + """) + +def printfooter(): + print("") diff --git a/functions/htmlsyntaxfc.py b/functions/htmlsyntaxfc.py new file mode 100644 index 0000000..08afe51 --- /dev/null +++ b/functions/htmlsyntaxfc.py @@ -0,0 +1,8 @@ +#!/usr/bin/python3.5 + +import re + +def htmlsyntax(DATA): + DATA = re.sub('<', '<', DATA) + DATA = re.sub('>', '>', DATA) + return(DATA) diff --git a/index.py b/index.py new file mode 100755 index 0000000..734ca6a --- /dev/null +++ b/index.py @@ -0,0 +1,30 @@ +#!/usr/bin/python3.5 + +# DEBUG +import cgitb +cgitb.enable() + +# IMPORT DES MODULES +import configparser +import os +from functions.headfoot import printheader,printfooter +# IMPORT DE LA CONFIGURATION +config = configparser.ConfigParser() +config.read('config.conf') + +DOMAIN = config.get('general','domain') +PROTO = config.get('general','proto') + +# AFFICHAGE DES ENTETES +printheader() + +# BODY +print('Nouveau VHOST', "
" , sep='' ) + +for i in os.listdir("/etc/apache2/sites-available"): + if os.path.isfile("/etc/apache2/sites-enabled/" + i): + print('', i ,' is enable!
', sep='') + else: + print('', i ,' is disable!
', sep='') +# AFFICHAGE DES FOOTERS +printfooter() diff --git a/new.py b/new.py new file mode 100755 index 0000000..8958cf1 --- /dev/null +++ b/new.py @@ -0,0 +1,47 @@ +#!/usr/bin/python3.5 +import cgi +import cgitb +cgitb.enable() +import re +import configparser +from functions.headfoot import printheader,printfooter + +# 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') + +# 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) + +printheader() + +# BODY +print('
') +print('Nom du VirtualHost :
') + +for i in VARIABLES.split(): + print(i, ':') + print('
', sep="") + +print('') + +print('
') +print('
Retour', sep='') + + +printfooter() +