Skip to content

Commit

Permalink
Merge pull request #199 from midoks/dev
Browse files Browse the repository at this point in the history
0.9.10
  • Loading branch information
midoks authored Sep 21, 2022
2 parents 8573528 + aa3950c commit 535f6dd
Show file tree
Hide file tree
Showing 66 changed files with 618 additions and 207 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ data/datadir.pl
data/502Task.pl
data/default.pl
data/backup.pl
data/debug.pl
data/default_site.pl
lib/python*

Expand Down Expand Up @@ -151,6 +152,7 @@ plugins/gdrive
plugins/mtproxy
plugins/zimg
plugins/bk_demo
plugins/mail
debug.out


Expand Down
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,14 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443:
```


### 版本更新 0.9.9

* 更换Logo。
* 增加amazon linux系统支持。
* 修复rsyncd在debian或ubuntu下安装失败问题。
* Readme加入一AD。
* PHP-YUM|PHP-APT优化[性能调整]
* 优化Gogs使用MySQL的方式。
* 配置模板添加一个whmcs。
* MySQL和MariaDB无法直接卸载。
* OpenResty加入http_realip_module模块。
* PHP加入igbinary扩展。
### 版本更新 0.9.10

* 防跨站攻击(open_basedir)功能优化。
* 创建站点域名批量添加优化。
* 首页CPU显示tip添加。
* 优化日志读取。
* 加入开发模式开关。
* redis添加性能调整功能。


### JSDelivr安装地址
Expand Down
18 changes: 16 additions & 2 deletions class/core/config_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class config_api:

__version = '0.9.9'
__version = '0.9.10'

def __init__(self):
pass
Expand Down Expand Up @@ -207,6 +207,14 @@ def closePanelApi(self):
mw.execShell("chown root.root " + filename)
return mw.returnJson(True, '面板已关闭!')

def openDebugApi(self):
filename = 'data/debug.pl'
if os.path.exists(filename):
os.remove(filename)
return mw.returnJson(True, '开发模式关闭!')
mw.writeFile(filename, 'True')
return mw.returnJson(True, '开发模式开启!')

def setIpv6StatusApi(self):
ipv6_file = 'data/ipv6.pl'
if os.path.exists('data/ipv6.pl'):
Expand Down Expand Up @@ -316,11 +324,17 @@ def get(self):
data['admin_path'] = mw.readFile(admin_path_file)

ipv6_file = 'data/ipv6.pl'
if os.path.exists('data/ipv6.pl'):
if os.path.exists(ipv6_file):
data['ipv6'] = 'checked'
else:
data['ipv6'] = ''

debug_file = 'data/debug.pl'
if os.path.exists(debug_file):
data['debug'] = 'checked'
else:
data['debug'] = ''

ssl_file = 'data/ssl.pl'
if os.path.exists('data/ssl.pl'):
data['ssl'] = 'checked'
Expand Down
2 changes: 1 addition & 1 deletion class/core/crontab_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def logsApi(self):
logFile = mw.getServerDir() + '/cron/' + echo['echo'] + '.log'
if not os.path.exists(logFile):
return mw.returnJson(False, '当前日志为空!')
log = mw.getNumLines(logFile, 500)
log = mw.getLastLine(logFile, 500)
return mw.returnJson(True, log)

def addApi(self):
Expand Down
2 changes: 1 addition & 1 deletion class/core/files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def getLastBodyApi(self):
return mw.returnJson(False, '文件不存在', (path,))

try:
data = mw.getNumLines(path, int(line))
data = mw.getLastLine(path, int(line))
return mw.returnJson(True, 'OK', data)
except Exception as ex:
return mw.returnJson(False, u'无法正确读取文件!' + str(ex))
Expand Down
17 changes: 14 additions & 3 deletions class/core/mw.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def getNumLines(path, num, p=1):
break
fp.close()
except Exception as e:
return ''
return str(e)

return "\n".join(data)

Expand Down Expand Up @@ -714,13 +714,24 @@ def getStrBetween(startStr, endStr, srcStr):


def getCpuType():
cpuType = ''
if isAppleSystem():
cmd = "system_profiler SPHardwareDataType | grep 'Processor Name' | awk -F ':' '{print $2}'"
cpuinfo = execShell(cmd)
return cpuinfo[0].strip()

# 取CPU类型
cpuinfo = open('/proc/cpuinfo', 'r').read()
rep = "model\s+name\s+:\s+(.+)"
tmp = re.search(rep, cpuinfo)
cpuType = None
tmp = re.search(rep, cpuinfo, re.I)
if tmp:
cpuType = tmp.groups()[0]
else:
cpuinfo = execShell('LANG="en_US.UTF-8" && lscpu')[0]
rep = "Model\s+name:\s+(.+)"
tmp = re.search(rep, cpuinfo, re.I)
if tmp:
cpuType = tmp.groups()[0]
return cpuType


Expand Down
63 changes: 39 additions & 24 deletions class/core/site_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,26 +340,35 @@ def getDirUserIniApi(self):
name = mw.M('sites').where("id=?", (mid,)).getField('name')
data = {}
data['logs'] = self.getLogsStatus(name)
data['runPath'] = self.getSiteRunPath(mid)

data['userini'] = False
if os.path.exists(path + '/.user.ini'):
data['userini'] = True
data['runPath'] = self.getSiteRunPath(mid)

if data['runPath']['runPath'] != '/':
if os.path.exists(path + data['runPath']['runPath'] + '/.user.ini'):
data['userini'] = True

data['pass'] = self.getHasPwd(name)
data['path'] = path
data['name'] = name
return mw.returnJson(True, 'OK', data)

def setDirUserIniApi(self):
path = request.form.get('path', '')
runPath = request.form.get('runPath', '')
filename = path + '/.user.ini'
self.delUserInI(path)

if os.path.exists(filename):
self.delUserInI(path)
mw.execShell("which chattr && chattr -i " + filename)
os.remove(filename)
return mw.returnJson(True, '已清除防跨站设置!')
mw.writeFile(filename, 'open_basedir=' + path +
'/:/www/server/php:/tmp/:/proc/')

self.setDirUserINI(path, runPath)
mw.execShell("which chattr && chattr +i " + filename)

return mw.returnJson(True, '已打开防跨站设置!')

def logsOpenApi(self):
Expand Down Expand Up @@ -730,11 +739,11 @@ def httpToHttpsApi(self):
if conf.find('ssl_certificate') == -1:
return mw.returnJson(False, '当前未开启SSL')
to = """#error_page 404/404.html;
#HTTP_TO_HTTPS_START
# HTTP_TO_HTTPS_START
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
#HTTP_TO_HTTPS_END"""
# HTTP_TO_HTTPS_END"""
conf = conf.replace('#error_page 404/404.html;', to)
mw.writeFile(file, conf)

Expand Down Expand Up @@ -1095,6 +1104,7 @@ def setSiteRunPathApi(self):
sitePath = mw.M('sites').where('id=?', (mid,)).getField('path')

newPath = sitePath + runPath

# 处理Nginx
filename = self.getHostConf(siteName)
if os.path.exists(filename):
Expand All @@ -1104,8 +1114,7 @@ def setSiteRunPathApi(self):
conf = conf.replace(path, newPath)
mw.writeFile(filename, conf)

self.delUserInI(sitePath)
self.setDirUserINI(newPath)
self.setDirUserINI(sitePath, runPath)

mw.restartWeb()
return mw.returnJson(True, '设置成功!')
Expand Down Expand Up @@ -1562,7 +1571,7 @@ def setProxyApi(self):

# location ~* ^{from}(.*)$ {
tpl = """
# PROXY-START/
#PROXY-START/
location ^~ {from} {
proxy_pass {to};
proxy_set_header Host {host};
Expand All @@ -1585,7 +1594,7 @@ def setProxyApi(self):
add_header Cache-Control no-cache;
}
}
# PROXY-END/
#PROXY-END/
"""

# replace
Expand Down Expand Up @@ -1829,13 +1838,13 @@ def getLogs(self, siteName):
logPath = mw.getLogsDir() + '/' + siteName + '.log'
if not os.path.exists(logPath):
return mw.returnJson(False, '日志为空')
return mw.returnJson(True, mw.getNumLines(logPath, 100))
return mw.returnJson(True, mw.getLastLine(logPath, 100))

def getErrorLogs(self, siteName):
logPath = mw.getLogsDir() + '/' + siteName + '.error.log'
if not os.path.exists(logPath):
return mw.returnJson(False, '日志为空')
return mw.returnJson(True, mw.getNumLines(logPath, 100))
return mw.returnJson(True, mw.getLastLine(logPath, 100))

# 取日志状态
def getLogsStatus(self, siteName):
Expand Down Expand Up @@ -2094,12 +2103,16 @@ def getRewriteList(self):
return rewriteList

def createRootDir(self, path):
autoInit = False
if not os.path.exists(path):
autoInit = True
os.makedirs(path)
if not mw.isAppleSystem():
mw.execShell('chown -R www:www ' + path)
mw.writeFile(path + '/index.html', 'Work has started!!!')
mw.execShell('chmod -R 755 ' + path)

if autoInit:
mw.writeFile(path + '/index.html', 'Work has started!!!')
mw.execShell('chmod -R 755 ' + path)

def nginxAddDomain(self, webname, domain, port):
file = self.getHostConf(webname)
Expand Down Expand Up @@ -2182,19 +2195,16 @@ def add(self, webname, port, ps, path, version):
return mw.returnJson(False, '您添加的域名已存在!')
mw.M('domain').where('pid=?', (opid,)).delete()

self.createRootDir(self.sitePath)
self.nginxAddConf()

# 添加更多域名
for domain in siteMenu['domainlist']:
sdomain = domain
swebname = self.siteName
spid = str(pid)
self.addDomain(domain, webname, pid)
self.addDomain(domain, self.siteName, pid)

mw.M('domain').add('pid,name,port,addtime',
(pid, self.siteName, self.sitePort, mw.getDate()))

self.createRootDir(self.sitePath)
self.nginxAddConf()

data = {}
data['siteStatus'] = False
mw.restartWeb()
Expand Down Expand Up @@ -2350,16 +2360,21 @@ def delUserInI(self, path, up=0):
return True

# 设置目录防御
def setDirUserINI(self, newPath):
def setDirUserINI(self, sitePath, runPath):
newPath = sitePath + runPath

filename = newPath + '/.user.ini'
if os.path.exists(filename):
mw.execShell("chattr -i " + filename)
os.remove(filename)
return mw.returnJson(True, '已清除防跨站设置!')

self.delUserInI(newPath)
mw.writeFile(filename, 'open_basedir=' +
newPath + '/:/www/server/php:/tmp/:/proc/')
openPath = 'open_basedir={}/:{}/'.format(newPath, sitePath)
if runPath == '/':
openPath = 'open_basedir={}/'.format(sitePath)

mw.writeFile(filename, openPath + ':/www/server/php:/tmp/:/proc/')
mw.execShell("chattr +i " + filename)

return mw.returnJson(True, '已打开防跨站设置!')
Expand Down
19 changes: 14 additions & 5 deletions class/core/system_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def getPanelInfo(self, get=None):
except:
port = mw.readFile('data/port.pl')
except:
port = '8888'
port = '7200'
domain = ''
if os.path.exists('data/domain.conf'):
domain = mw.readFile('data/domain.conf')
Expand Down Expand Up @@ -201,9 +201,9 @@ def getSystemTotal(self, interval=1):
def getLoadAverage(self):
c = os.getloadavg()
data = {}
data['one'] = float(c[0])
data['five'] = float(c[1])
data['fifteen'] = float(c[2])
data['one'] = round(float(c[0]), 2)
data['five'] = round(float(c[1]), 2)
data['fifteen'] = round(float(c[2]), 2)
data['max'] = psutil.cpu_count() * 2
data['limit'] = data['max']
data['safe'] = data['max'] * 0.75
Expand Down Expand Up @@ -276,8 +276,17 @@ def getBootTime(self):
def getCpuInfo(self, interval=1):
# 取CPU信息
cpuCount = psutil.cpu_count()
cpuLogicalNum = psutil.cpu_count(logical=False)
used = psutil.cpu_percent(interval=interval)
return used, cpuCount

if os.path.exists('/proc/cpuinfo'):
c_tmp = mw.readFile('/proc/cpuinfo')
d_tmp = re.findall("physical id.+", c_tmp)
cpuLogicalNum = len(set(d_tmp))

used_all = psutil.cpu_percent(percpu=True)
cpu_name = mw.getCpuType() + " * {}".format(cpuLogicalNum)
return used, cpuCount, used_all, cpu_name, cpuCount, cpuLogicalNum

def getMemInfo(self):
# 取内存信息
Expand Down
7 changes: 1 addition & 6 deletions plugins/gogs/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,12 +681,7 @@ def getTotalStatistics():
data = {}
if st.strip() == 'start':
list_count = pQuery('select count(id) as num from repository')

if list_count.find("error") > -1:
data['status'] = False
data['count'] = 0
return mw.returnJson(False, 'fail', data)

count = list_count[0]["num"]
data['status'] = True
data['count'] = count
data['ver'] = mw.readFile(getServerDir() + '/version.pl').strip()
Expand Down
2 changes: 1 addition & 1 deletion plugins/mariadb/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def getErrorLog():
if 'close' in args:
mw.writeFile(filename, '')
return mw.returnJson(False, '日志已清空')
info = mw.getNumLines(filename, 18)
info = mw.getLastLine(filename, 18)
return mw.returnJson(True, 'OK', info)


Expand Down
2 changes: 1 addition & 1 deletion plugins/mysql/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def getErrorLog():
if 'close' in args:
mw.writeFile(filename, '')
return mw.returnJson(False, '日志已清空')
info = mw.getNumLines(filename, 18)
info = mw.getLastLine(filename, 18)
return mw.returnJson(True, 'OK', info)


Expand Down
2 changes: 1 addition & 1 deletion plugins/mysql/versions/5.6/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Install_mysql()
OPENSSL_VERSION=`openssl version|awk '{print $2}'|awk -F '.' '{print $1}'`
if [ "${OPENSSL_VERSION}" -ge "3" ];then
#openssl version to high
cd $serverPath/mdserver-web/plugins/php/lib && /bin/bash openssl.sh
cd ${rootPath}/plugins/php/lib && /bin/bash openssl.sh
export PKG_CONFIG_PATH=$serverPath/lib/openssl/lib/pkgconfig
OPTIONS="-DWITH_SSL=${serverPath}/lib/openssl"
fi
Expand Down
Loading

0 comments on commit 535f6dd

Please sign in to comment.