|
|
@ -25,11 +25,38 @@ def getVhostDir(): |
|
|
|
vhosts = nginx_conf+"/vhost" |
|
|
|
vhosts = nginx_conf+"/vhost" |
|
|
|
return vhosts |
|
|
|
return vhosts |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getRootDir(content): |
|
|
|
|
|
|
|
pattern = r'\s*root\s*(.+);' |
|
|
|
|
|
|
|
match = re.search(pattern, content) |
|
|
|
|
|
|
|
if match: |
|
|
|
|
|
|
|
return match.group(1) |
|
|
|
|
|
|
|
return '' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getServerName(content): |
|
|
|
|
|
|
|
pattern = r'\s*server_name\s*(.+);' |
|
|
|
|
|
|
|
match = re.search(pattern, content) |
|
|
|
|
|
|
|
if match: |
|
|
|
|
|
|
|
content = match.group(1) |
|
|
|
|
|
|
|
clist = content.strip().split(" "); |
|
|
|
|
|
|
|
return clist |
|
|
|
|
|
|
|
return [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def addDomain(site_id, site_name, domain): |
|
|
|
|
|
|
|
d = domain.split(':') |
|
|
|
|
|
|
|
port = '80' |
|
|
|
|
|
|
|
name = d[0] |
|
|
|
|
|
|
|
if len(d) == 2: |
|
|
|
|
|
|
|
port = d[1] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if thisdb.checkSitesDomainIsExist(name, port): |
|
|
|
|
|
|
|
print('您添加的域名[{}:{}],已使用。请仔细检查!'.format(name, port)) |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
thisdb.addDomain(site_id, name, port) |
|
|
|
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def parse(): |
|
|
|
def parse(): |
|
|
|
vhosts = getVhostDir() |
|
|
|
vhosts = getVhostDir() |
|
|
|
|
|
|
|
|
|
|
|
vh_list = os.listdir(vhosts) |
|
|
|
vh_list = os.listdir(vhosts) |
|
|
|
|
|
|
|
|
|
|
|
vail_list = [] |
|
|
|
vail_list = [] |
|
|
|
for f in vh_list: |
|
|
|
for f in vh_list: |
|
|
|
if f.startswith("0."): |
|
|
|
if f.startswith("0."): |
|
|
@ -49,7 +76,20 @@ def parseSite(d): |
|
|
|
vhosts = getVhostDir() |
|
|
|
vhosts = getVhostDir() |
|
|
|
domain = d.replace(".conf","") |
|
|
|
domain = d.replace(".conf","") |
|
|
|
|
|
|
|
|
|
|
|
dconf = vhosts+'/'+domain |
|
|
|
dconf = vhosts + '/' + d |
|
|
|
print(domain,dconf) |
|
|
|
content = mw.readFile(dconf) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
root_dir = getRootDir(content) |
|
|
|
|
|
|
|
sn_list = getServerName(content) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# print(domain,dconf) |
|
|
|
|
|
|
|
# print(sn_list) |
|
|
|
|
|
|
|
if thisdb.isSitesExist(domain): |
|
|
|
|
|
|
|
print('您添加的站点[%s]已存在!' % domain) |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
thisdb.addSites(domain, root_dir) |
|
|
|
|
|
|
|
info = thisdb.getSitesByName(domain) |
|
|
|
|
|
|
|
site_id = info['id'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for sn in sn_list: |
|
|
|
|
|
|
|
addDomain(site_id, d, domain) |
|
|
|