Skip to content

Commit

Permalink
Merge pull request #577 from midoks/dev
Browse files Browse the repository at this point in the history
0.16.9
  • Loading branch information
midoks authored May 22, 2024
2 parents dd25ebe + de4e134 commit dcae829
Show file tree
Hide file tree
Showing 66 changed files with 2,106 additions and 323 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ plugins/v2ray
plugins/frp
plugins/file_search
plugins/proxysql
plugins/tidb
debug.out


Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443:
```


### 版本更新 0.16.8
### 版本更新 0.16.9

- 首页对网络/磁盘IO进行更细致的展示。
- mysql同步优化,享受丝滑般感觉。
- 网站统计 - 实时-可调节1-10s。
- 网站统计 - 加入大小条件。
- Sphinx优化。

### JSDelivr安装地址

Expand Down
2 changes: 1 addition & 1 deletion class/core/config_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class config_api:

__version = '0.16.8'
__version = '0.16.9'
__api_addr = 'data/api.json'

# 统一默认配置文件
Expand Down
15 changes: 15 additions & 0 deletions class/core/files_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def deleteApi(self):
def fileAccessApi(self):
filename = request.form.get('filename', '')
data = self.getAccess(filename)
data['sys_users'] = self.getSysUserList()
return mw.getJson(data)

def setFileAccessApi(self):
Expand Down Expand Up @@ -933,6 +934,20 @@ def getAccess(self, filename):
data['chown'] = 'www'
return data

def getSysUserList(self):
pwd_file = '/etc/passwd'
if os.path.exists(pwd_file):
content = mw.readFile(pwd_file)
clist = content.split('\n')
sys_users = []
for line in clist:
if line.find(":")<0:
continue
lines = line.split(":",1)
sys_users.append(lines[0])
return sys_users
return ['root','mysql','www']

# 计算文件数量
def getCount(self, path, search):
i = 0
Expand Down
3 changes: 2 additions & 1 deletion class/core/mw.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ def getRootDir():
def getPluginDir():
return getRunDir() + '/plugins'


def getPanelDataDir():
return getRunDir() + '/data'

def getMWLogs():
return getRunDir() + '/logs'

def getPanelTmp():
return getRunDir() + '/tmp'
Expand Down
34 changes: 29 additions & 5 deletions class/plugin/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,50 @@ class ORM:
__DB_CUR = None
__DB_ERR = None
__DB_CNF = '/etc/my.cnf'
__DB_TIMEOUT=1
__DB_SOCKET = '/www/server/mysql/mysql.sock'

__DB_CHARSET = "utf8"

def __Conn(self):
# print(self.__DB_HOST, self.__DB_USER)
'''连接数据库'''
try:

if os.path.exists(self.__DB_SOCKET):
if self.__DB_HOST != 'localhost':
try:
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS,
database=self.__DB_NAME,
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT,
cursorclass=pymysql.cursors.DictCursor)
except Exception as e:
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS,
database=self.__DB_NAME,
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT,
cursorclass=pymysql.cursors.DictCursor)
elif os.path.exists(self.__DB_SOCKET):
try:
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS,
database=self.__DB_NAME,
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1,
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT,
unix_socket=self.__DB_SOCKET, cursorclass=pymysql.cursors.DictCursor)
except Exception as e:
self.__DB_HOST = '127.0.0.1'
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS,
database=self.__DB_NAME,
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1,
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT,
unix_socket=self.__DB_SOCKET, cursorclass=pymysql.cursors.DictCursor)
else:
try:
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS,
database=self.__DB_NAME,
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1,
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT,
cursorclass=pymysql.cursors.DictCursor)
except Exception as e:
self.__DB_HOST = '127.0.0.1'
self.__DB_CONN = pymysql.connect(host=self.__DB_HOST, user=self.__DB_USER, passwd=self.__DB_PASS,
database=self.__DB_NAME,
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=1,
port=int(self.__DB_PORT), charset=self.__DB_CHARSET, connect_timeout=self.__DB_TIMEOUT,
cursorclass=pymysql.cursors.DictCursor)

self.__DB_CUR = self.__DB_CONN.cursor()
Expand Down Expand Up @@ -80,6 +93,10 @@ def setPwd(self, pwd):
def getPwd(self):
return self.__DB_PASS

def setTimeout(self, timeout = 1):
self.__DB_TIMEOUT = timeout
return True

def setDbName(self, name):
self.__DB_NAME = name

Expand All @@ -95,6 +112,13 @@ def execute(self, sql):
except Exception as ex:
return ex

def ping(self):
try:
self.__DB_CONN.ping()
except Exception as e:
print(e)
return True

def query(self, sql):
# 执行SQL语句返回数据集
if not self.__Conn():
Expand Down
3 changes: 2 additions & 1 deletion cmd.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

```
/etc/init.d/mw default | 显示登录信息
/etc/init.d/mw db | 快捷连接数据库
/etc/init.d/mw db | 快捷连接MySQL
/etc/init.d/mw redis | 快捷连接Redis
----------------------------------------
mw open | 开启面板
mw close | 关闭面板
Expand Down
1 change: 1 addition & 0 deletions plugins/clean/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def initConf():
"/www/server/php/82/var/log",
"/www/server/php/83/var/log",
"/www/server/php/84/var/log",
"/www/server/openresty/nginx/logs",
"/www/server/phpmyadmin",
"/www/server/redis/data",
"/www/server/cron",
Expand Down
10 changes: 10 additions & 0 deletions plugins/data_query/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
white-space: nowrap;
vertical-align: middle;
}

#select_db xm-select{
min-height: 30px;
line-height: 30px;
}

#select_db xm-select *{
font-size: 12px;
}

</style>

<div class="bt-form">
Expand Down
13 changes: 10 additions & 3 deletions plugins/data_query/static/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,16 @@
<input name="mongodb_field_value" type="text" class="bt-input-text" placeholder="请输入查找内容">
</div>

<button type="button" class="mongodb_find btn btn-success btn-sm mr5 ml5" style="float:right;">
<span>查找</span>
</button>
<div style="float:right;">

<button type="button" class="mongodb_find btn btn-success btn-sm mr5 ml5" >
<span>查找</span>
</button>

<button type="button" class="mongodb_refresh btn btn-success btn-sm mr5 ml5">
<span>刷新</span>
</button>
</div>
</div>

<div class="pull-right" style="padding-top: 5px;">
Expand Down
6 changes: 5 additions & 1 deletion plugins/data_query/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,10 @@ function mongodbInitField(f, data){
}
mongodbDataList(1);
});

$('#mongodb .mongodb_refresh').unbind('click').click(function(){
mongodbDataList(1);
});
}

var mogodb_db_list;
Expand Down Expand Up @@ -1252,7 +1256,7 @@ function redisBatchClear(){

xm_db_list = xmSelect.render({
el: '#select_db',
repeat: true,
repeat: false,
toolbar: {show: true},
data: idx_db,
});
Expand Down
1 change: 1 addition & 0 deletions plugins/mongodb/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<p onclick="mongoStatus();">负载状态</p>
<p onclick="mongoReplStatus();">复制状态</p>
<p onclick="pluginLogs('mongodb','','run_log');">日志</p>
<p onclick="mgdbReadme();">相关说明</p>
</div>
<div class="bt-w-con pd15">
<div class="soft-man-con" style="height:455px;overflow: auto;"></div>
Expand Down
36 changes: 24 additions & 12 deletions plugins/mongodb/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@


# /usr/lib/systemd/system/mongod.service
# /var/lib/mongo

# python3 /www/server/mdserver-web/plugins/mongodb/index.py repl_init
# python3 /www/server/mdserver-web/plugins/mongodb/index.py run_repl_info
Expand Down Expand Up @@ -107,6 +106,9 @@ def getConfIp():
data = getConfigData()
return data['net']['bindIp']

def getConfLocalIp():
return '127.0.0.1'

def getConfPort():
data = getConfigData()
return data['net']['port']
Expand Down Expand Up @@ -186,7 +188,7 @@ def mongdbClientS():
import pymongo
port = getConfPort()
auth = getConfAuth()
ip = getConfIp()
ip = getConfLocalIp()
mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root')

if auth == 'disabled':
Expand All @@ -200,7 +202,7 @@ def mongdbClient():
import pymongo
port = getConfPort()
auth = getConfAuth()
ip = getConfIp()
ip = getConfLocalIp()
mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root')
# print(ip,port,auth,mg_root)
if auth == 'disabled':
Expand Down Expand Up @@ -488,14 +490,13 @@ def runDocInfo():
def runReplInfo():
client = mongdbClient()
db = client.admin

result = {}
try:
serverStatus = db.command('serverStatus')
except Exception as e:
return mw.returnJson(False, str(e))

d = getConfigData()
result = {}
if 'replication' in d and 'replSetName' in d['replication']:
result['repl_name'] = d['replication']['replSetName']

Expand All @@ -518,7 +519,22 @@ def runReplInfo():
hosts = mw.getDefault(repl,'hosts', '')
result['hosts'] = ','.join(hosts)


result['members'] = []
try:
members_list = []
replStatus = db.command('replSetGetStatus')
if 'members' in replStatus:
members = replStatus['members']
for m in members:
t = {}
t['name'] = m['name']
t['stateStr'] = m['stateStr']
t['uptime'] = m['uptime']
members_list.append(t)
result['members'] = members_list
except Exception as e:
pass

return mw.returnJson(True, 'OK', result)

def getDbList():
Expand Down Expand Up @@ -602,7 +618,7 @@ def addDb():
username = data_name


client[data_name].chat.insert_one({})
client[data_name].zchat.insert_one({})
user_roles = [{'role': 'dbOwner', 'db': data_name}, {'role': 'userAdmin', 'db': data_name}]
if auth_status:
# db.command("dropUser", username)
Expand Down Expand Up @@ -787,7 +803,7 @@ def toDbBase(find):
data_name = find['name']
db = client[data_name]

db.chat.insert_one({})
db.zchat.insert_one({})
user_roles = [{'role': 'dbOwner', 'db': data_name}, {'role': 'userAdmin', 'db': data_name}]
try:
db_admin.command("createUser", find['username'], pwd=find['password'], roles=user_roles)
Expand Down Expand Up @@ -1011,10 +1027,6 @@ def replSetNode():
add_node = args['node'].strip()
idx = int(args['idx'])





priority = -1
if 'priority' in args:
priority = args['priority'].strip()
Expand Down
Loading

0 comments on commit dcae829

Please sign in to comment.