From 8f1e671793dac03ba34f4e324fadfa25c64fdddf Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 17 Dec 2018 16:47:40 +0800 Subject: [PATCH] update --- class/core/site_api.py | 105 +++++++++++++++++++++++++ route/site.py | 34 +++++--- static/app/firewall.js | 1 - static/app/public.js | 11 +++ static/app/site.js | 153 +++++------------------------------- templates/default/site.html | 7 +- 6 files changed, 158 insertions(+), 153 deletions(-) create mode 100755 class/core/site_api.py diff --git a/class/core/site_api.py b/class/core/site_api.py new file mode 100755 index 000000000..9bb95fb66 --- /dev/null +++ b/class/core/site_api.py @@ -0,0 +1,105 @@ +# coding: utf-8 + +import psutil +import time +import os +import sys +import public +import re +import json +import pwd + + +class site_api: + + def __init__(self): + pass + + # 域名编码转换 + def toPunycode(self, domain): + import re + if sys.version_info[0] == 2: + domain = domain.encode('utf8') + tmp = domain.split('.') + newdomain = '' + for dkey in tmp: + # 匹配非ascii字符 + match = re.search(u"[\x80-\xff]+", dkey) + if not match: + newdomain += dkey + '.' + else: + newdomain += 'xn--' + \ + dkey.decode('utf-8').encode('punycode') + '.' + return newdomain[0:-1] + + # 中文路径处理 + def toPunycodePath(self, path): + if sys.version_info[0] == 2: + path = path.encode('utf-8') + if os.path.exists(path): + return path + import re + match = re.search(u"[\x80-\xff]+", path) + if not match: + return path + npath = '' + for ph in path.split('/'): + npath += '/' + self.toPunycode(ph) + return npath.replace('//', '/') + + # 路径处理 + def getPath(self, path): + if path[-1] == '/': + return path[0:-1] + return path + + def list(self): + _list = public.M('sites').where('', ()).field( + 'id,name,path,status,ps,addtime').limit('0,5').order('id desc').select() + _ret = {} + _ret['data'] = _list + + count = public.M('sites').where('', ()).count() + _page = {} + _page['count'] = count + _page['tojs'] = 'getWeb' + + _ret['page'] = public.getPage(_page) + return public.getJson(_ret) + + def getPhpVersion(self): + phpVersions = ('00', '52', '53', '54', '55', + '56', '70', '71', '72', '73', '74') + data = [] + for val in phpVersions: + tmp = {} + if val == '00': + tmp['name'] = '纯静态' + data.append(tmp) + + checkPath = public.getServerDir() + '/php/' + val + '/bin/php' + if os.path.exists(checkPath): + tmp['version'] = val + tmp['name'] = 'PHP-' + val + data.append(tmp) + + return public.getJson(data) + + def add(self, webname, ps, path, version): + + self.siteMenu = json.loads(webname) + self.siteName = self.toPunycode( + siteMenu['domain'].strip().split(':')[0]).strip() + self.sitePath = self.toPunycodePath( + self.getPath(path.replace(' ', ''))) + self.sitePort = port.strip().replace(' ', '') + + # 写入数据库 + # pid = public.M('sites').add('name,path,status,ps,addtime', + # (self.siteName, self.sitePath, '1', ps, '')) + + # public.M('domain').add('pid,name,port,addtime', + # (get.pid, self.siteName, self.sitePort, public.getDate())) + data = {} + data['siteStatus'] = False + return public.getJson(data) diff --git a/route/site.py b/route/site.py index 5f907cb55..5d8349a32 100644 --- a/route/site.py +++ b/route/site.py @@ -7,11 +7,13 @@ import json from flask import Flask from flask import Blueprint, render_template +from flask import request +site = Blueprint('site', __name__, template_folder='templates') sys.path.append("class/core") import public -site = Blueprint('site', __name__, template_folder='templates') +import site_api @site.route('/') @@ -21,15 +23,21 @@ def index(): @site.route('/list', methods=['POST']) def list(): - _list = public.M('sites').where('', ()).field( - 'id,name,path,status,ps,addtime').limit('0,5').order('id desc').select() - _ret = {} - _ret['data'] = _list - - count = public.M('sites').where('', ()).count() - _page = {} - _page['count'] = count - _page['tojs'] = 'getWeb' - - _ret['page'] = public.getPage(_page) - return public.getJson(_ret) + return site_api.site_api().list() + + +@site.route('get_php_version', methods=['POST']) +def getPhpVersion(): + return site_api.site_api().getPhpVersion() + + +@site.route('add', methods=['POST']) +def add(): + webname = request.form.get('webname', '').encode('utf-8') + ps = request.form.get('ps', '').encode('utf-8') + path = request.form.get('path', '').encode('utf-8') + version = request.form.get('version', '').encode('utf-8') + port = request.form.get('port', '').encode('utf-8') + webname = request.form.get('webname', '').encode('utf-8') + print webname + return site_api.site_api().add(webname, ps, path, version) diff --git a/static/app/firewall.js b/static/app/firewall.js index 283064141..3767e2bcb 100755 --- a/static/app/firewall.js +++ b/static/app/firewall.js @@ -174,7 +174,6 @@ function showAccept(page,search) { search = search == undefined ? '':search; var loadT = layer.load(); $.post('/firewall/get_list','limit=10&p=' + page+"&search="+search, function(data) { - console.log(data); layer.close(loadT); var body = ''; for (var i = 0; i < data.data.length; i++) { diff --git a/static/app/public.js b/static/app/public.js index f88d7c7d5..4e6e7b6b9 100755 --- a/static/app/public.js +++ b/static/app/public.js @@ -33,6 +33,17 @@ function randomStrPwd(b) { return d } +function getRandomString(len) { + len = len || 32; + var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1 + var maxPos = $chars.length; + var pwd = ''; + for (i = 0; i < len; i++) { + pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); + } + return pwd; +} + function msgTpl(msg, args){ if (typeof args == 'string'){ return msg.replace('{1}', args); diff --git a/static/app/site.js b/static/app/site.js index 7d8e5512a..a3d49e107 100755 --- a/static/app/site.js +++ b/static/app/site.js @@ -17,7 +17,6 @@ function getWeb(page, search) { var loadT = layer.load(); //取回数据 $.post(sUrl, pdata, function(data) { - console.log(data) layer.close(loadT); //构造数据列表 var Body = ''; @@ -129,7 +128,7 @@ function webAdd(type) { var str=""; var domainlist=''; var domain = array = $("#mainDomain").val().replace('http://','').replace('https://','').split("\n"); - var Webport=[]; + var webport=[]; var checkDomain = domain[0].split('.'); if(checkDomain.length < 1){ layer.msg(lan.site.domain_err_txt,{icon:2}); @@ -138,41 +137,29 @@ function webAdd(type) { for(var i=1; i\ -

"+lan.site.user+":" + ret.ftpUser + "

\ -

"+lan.site.password+":" + ret.ftpPass + "

\ -

"+lan.site.ftp_tips+"

" - } - var sqlData = ''; - if (ret.databaseStatus) { - sqlData = "

"+lan.site.database_txt+"

\ -

"+lan.site.database_name+":" + ret.databaseUser + "

\ -

"+lan.site.user+":" + ret.databaseUser + "

\ -

"+lan.site.password+":" + ret.databasePass + "

" - } if (ret.siteStatus == true) { getWeb(1); layer.closeAll(); if(ftpData == '' && sqlData == ''){ layer.msg(lan.site.success_txt,{icon:1}) - } - else{ + } else { layer.open({ type: 1, area: '600px', @@ -200,11 +187,12 @@ function webAdd(type) { }); } layer.close(loadT); - }); + },'json'); return; } - $.post('/site?action=GetPHPVersion',function(rdata){ + $.post('/site/get_php_version',function(rdata){ + var defaultPath = $("#defaultPath").html(); var php_version = "
"+lan.site.php_ver+"\
\ - \ -
\ - FTP\ -
\ - \ -
\ -
\ -
\ - "+lan.site.ftp_set+"\ -
\ -
"+lan.site.user+":\ - "+lan.site.password+":
\ -

"+lan.site.ftp_help+"

\ -
\ -
\ -
\ - "+lan.site.database+"\ -
\ - \ - \ -
\ -
\ -
\ - "+lan.site.database_set+"\ -
\ -
"+lan.site.user+":\ - "+lan.site.password+":
\ -

"+lan.site.database_help+"

\ -
\
\ "+php_version+"\
\ - \ - \ + \ + \
\ ", }); + $(function() { var placeholder = "
"+lan.site.domain_help+"
"; $('#mainDomain').after(placeholder); @@ -311,27 +260,7 @@ function webAdd(type) { $('#php_w').text(''); } }) - - - //FTP账号数据绑定域名 - $('#mainDomain').on('input', function() { - var array; - var res,ress; - var str = $(this).val().replace('http://','').replace('https://',''); - var len = str.replace(/[^\x00-\xff]/g, "**").length; - array = str.split("\n"); - ress =array[0].split(":")[0]; - res = ress.replace(new RegExp(/([-.])/g), '_'); - if(res.length > 15) res = res.substr(0,15); - if($("#inputPath").val().substr(0,defaultPath.length) == defaultPath) $("#inputPath").val(defaultPath+'/'+ress); - if(!isNaN(res.substr(0,1))) res = "sql"+res; - if(res.length > 15) res = res.substr(0,15); - $("#Wbeizhu").val(ress); - $("#ftp-user").val(res); - $("#data-user").val(res); - if(isChineseChar(str)) $('.btn-zhm').show(); - else $('.btn-zhm').hide(); - }) + //备注 $('#Wbeizhu').on('input', function() { var str = $(this).val(); var len = str.replace(/[^\x00-\xff]/g, "**").length; @@ -346,52 +275,8 @@ function webAdd(type) { //获取当前时间时间戳,截取后6位 var timestamp = new Date().getTime().toString(); var dtpw = timestamp.substring(7); - $("#data-user").val("sql" + dtpw); - - //生成n位随机密码 - function _getRandomString(len) { - len = len || 32; - var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1 - var maxPos = $chars.length; - var pwd = ''; - for (i = 0; i < len; i++) { - pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); - } - return pwd; - } - $("#ftp-password").val(_getRandomString(16)); - $("#data-password").val(_getRandomString(16)); - - - $("#ftpss,#datass").hide(); - //不创建 - $("#c_k1").change(function() { - var val = $("#c_k1").val(); - if (val == 'false') { - $("#ftp-user").attr("disabled", true); - $("#ftp-password").attr("disabled", true); - $("#ftpss").hide(); - } else { - $("#ftp-user").attr("disabled", false); - $("#ftp-password").attr("disabled", false); - $("#ftpss").show(); - } - }) - //不创建 - $("#c_k2").change(function() { - var val = $("#c_k2").val(); - if (val == 'false') { - $("#data-user").attr("disabled", true); - $("#data-password").attr("disabled", true); - $("#datass").hide(); - } else { - $("#data-user").attr("disabled", false); - $("#data-password").attr("disabled", false); - $("#datass").show(); - } - }); }); - }); + }, 'json'); } //修改网站目录 diff --git a/templates/default/site.html b/templates/default/site.html index 08f627b32..67cd0904c 100755 --- a/templates/default/site.html +++ b/templates/default/site.html @@ -23,6 +23,7 @@   + @@ -56,11 +57,7 @@ -