diff --git a/class/core/public.py b/class/core/public.py index 73fa15da4..afaac55a7 100755 --- a/class/core/public.py +++ b/class/core/public.py @@ -107,6 +107,18 @@ def restartWeb(): execShell(initd + ' ' + 'reload') +def checkWebConfig(): + op_dir = getServerDir() + '/openresty' + cmd = "ulimit -n 10240 && " + op_dir + \ + "/nginx/sbin/nginx -t -c " + op_dir + "/nginx/conf/nginx.conf" + result = execShell(cmd) + searchStr = 'successful' + if result[1].find(searchStr) == -1: + writeLog("TYPE_SOFT", 'CONF_CHECK_ERR', (result[1],)) + return result[1] + return True + + def M(table): sql = db.Sql() return sql.table(table) diff --git a/class/core/site_api.py b/class/core/site_api.py index 11ef82367..0111eae59 100755 --- a/class/core/site_api.py +++ b/class/core/site_api.py @@ -129,6 +129,27 @@ class site_api: port = request.form.get('port', '').encode('utf-8') return self.add(webname, port, ps, path, version) + def addDomainApi(self): + isError = public.checkWebConfig() + if isError != True: + return public.returnJson(False, 'ERROR: 检测到配置文件有错误,请先排除后再操作

' + isError.replace("\n", '
') + '
') + + domain = request.form.get('domain', '').encode('utf-8') + webname = request.form.get('webname', '').encode('utf-8') + pid = request.form.get('id', '').encode('utf-8') + if len(domain) < 3: + return public.returnJson(False, '域名不能为空!') + domains = get.domain.split(',') + for domain in domains: + if domain == "": + continue + domain = domain.split(':') + domain_name = self.ToPunycode(domain[0]) + domain_port = '80' + + public.M('domain').add('pid,name,port,addtime', + (pid, domain_name, domain_port, public.getDate())) + def deleteApi(self): sid = request.form.get('id', '').encode('utf-8') webname = request.form.get('webname', '').encode('utf-8')