Alpha first commit
This commit is contained in:
		
							
								
								
									
										4
									
								
								config.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								config.conf
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| [general] | ||||
| domain = 10.1.9.118 | ||||
| proto = http | ||||
| templatepath = /etc/apache2/sites-available/999-template.conf | ||||
							
								
								
									
										71
									
								
								create.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										71
									
								
								create.py
									
									
									
									
									
										Executable file
									
								
							| @@ -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('<pre><b>Contenu de', VHOSTNAME, '</b><p>', TEMPLATE, '</p></pre>') | ||||
|  | ||||
|  | ||||
|  | ||||
| print('<br><a href="', PROTO , '://', DOMAIN , '/index.py">Retour</a>', sep='') | ||||
|  | ||||
|  | ||||
| printfooter() | ||||
							
								
								
									
										41
									
								
								file.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										41
									
								
								file.py
									
									
									
									
									
										Executable file
									
								
							| @@ -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('<b>', VHOSTNAME , '</b>') | ||||
| print("<pre>") | ||||
| print('<p>', VHOST, '</p>' ) | ||||
| print('</pre>') | ||||
| print('<a href="', PROTO , '://', DOMAIN , '/index.py">Retour</a>', sep='') | ||||
|  | ||||
| # AFFICHAGE DU FOOTER | ||||
| printfooter() | ||||
|  | ||||
							
								
								
									
										16
									
								
								functions/headfoot.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										16
									
								
								functions/headfoot.py
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| #!/usr/bin/python3.5 | ||||
|  | ||||
| # DEBUG  | ||||
| import cgitb  | ||||
| cgitb.enable() | ||||
|  | ||||
| def printheader(): | ||||
|     print("Content-Type: text/html\n") | ||||
|      | ||||
|     print (""" | ||||
|             <html> | ||||
|                 <title> Ma Jolie petite Page</title> | ||||
|             """) | ||||
|  | ||||
| def printfooter(): | ||||
|     print("</html>") | ||||
							
								
								
									
										8
									
								
								functions/htmlsyntaxfc.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								functions/htmlsyntaxfc.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| #!/usr/bin/python3.5 | ||||
|  | ||||
| import re | ||||
|  | ||||
| def htmlsyntax(DATA): | ||||
|     DATA = re.sub('<', '<', DATA) | ||||
|     DATA = re.sub('>', '>', DATA) | ||||
|     return(DATA) | ||||
							
								
								
									
										30
									
								
								index.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										30
									
								
								index.py
									
									
									
									
									
										Executable file
									
								
							| @@ -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('<a href="http://', DOMAIN , '/new.py">Nouveau VHOST</a>', "<br>" , sep='' ) | ||||
|  | ||||
| for i in os.listdir("/etc/apache2/sites-available"): | ||||
|     if os.path.isfile("/etc/apache2/sites-enabled/" + i): | ||||
|         print('<a href="', PROTO , '://', DOMAIN, '/file.py?file=',i, '">', i ,'</a> is enable!<br>', sep='') | ||||
|     else: | ||||
|         print('<a href="', PROTO , '://', DOMAIN, '/file.py?file=',i, '">', i ,'</a> is disable!<br>', sep='') | ||||
| # AFFICHAGE DES FOOTERS | ||||
| printfooter() | ||||
							
								
								
									
										47
									
								
								new.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										47
									
								
								new.py
									
									
									
									
									
										Executable file
									
								
							| @@ -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('<form action="/create.py">') | ||||
| print('Nom du VirtualHost : <input type="text" name="VHOSTNAME"><br>') | ||||
|  | ||||
| for i in VARIABLES.split(): | ||||
|     print(i, ':') | ||||
|     print('<input type="text" name="', i , '"><br>', sep="") | ||||
|  | ||||
| print('<input type="submit" value="GO">') | ||||
|  | ||||
| print('</form>') | ||||
| print('<br><a href="', PROTO , '://', DOMAIN , '/index.py">Retour</a>', sep='') | ||||
|  | ||||
|  | ||||
| printfooter() | ||||
|  | ||||
		Reference in New Issue
	
	Block a user