11import re
2- import string
32
43from flask import Blueprint , redirect , render_template , request , url_for
54from werkzeug .exceptions import BadRequest , Forbidden , NotFound
109from srcf .database import Domain
1110
1211from . import inspect_services , utils
13- from .utils import create_job_maybe_email_and_redirect , find_mem_society , parse_domain_name , srcf_db_sess as sess
12+ from .utils import (
13+ create_job_maybe_email_and_redirect , find_mem_society , parse_domain_name ,
14+ validate_domain_docroot , srcf_db_sess as sess ,
15+ )
1416
1517
1618bp = Blueprint ("society" , __name__ )
@@ -286,6 +288,7 @@ def add_vhost(society):
286288
287289 domain = request .form .get ("domain" , "" ).strip ()
288290 root = request .form .get ("root" , "" ).strip ()
291+
289292 if domain :
290293 parsed = parse_domain_name (domain )
291294 if domain != parsed :
@@ -304,6 +307,11 @@ def add_vhost(society):
304307 else :
305308 errors ["domain" ] = "Please enter a domain or subdomain."
306309
310+ if root :
311+ root , msg = validate_domain_docroot (mem , root )
312+ if msg :
313+ errors ["root" ] = msg
314+
307315 if request .form .get ("edit" ) or errors :
308316 return render_template ("society/add_vhost.html" , society = soc , member = mem , domain = domain , root = root , errors = errors )
309317 elif not request .form .get ("confirm" ):
@@ -337,12 +345,10 @@ def change_vhost_docroot(society, domain):
337345
338346 if request .method == "POST" :
339347 root = request .form .get ("root" , "" ).strip ()
340- if any ([ch in root for ch in string .whitespace + "\\ " + "\" " + "\' " ]) or ".." in root :
341- errors ["root" ] = "This document root is invalid."
342- try :
343- domain = parse_domain_name (domain )
344- except ValueError as e :
345- errors ["domain" ] = e .args [0 ]
348+ if root :
349+ root , msg = validate_domain_docroot (mem , root )
350+ if msg :
351+ errors ["root" ] = msg
346352
347353 if request .method == "POST" and not errors :
348354 return create_job_maybe_email_and_redirect (
0 commit comments