diff --git a/README.md b/README.md index a49637882..a174ad59e 100644 --- a/README.md +++ b/README.md @@ -110,10 +110,9 @@ docker run -itd --name mw-server --privileged=true -p 7200:7200 -p 80:80 -p 443: ``` -### 版本更新 0.16.6 +### 版本更新 0.16.7 -- openresty【1.25.3.1】配置更新,支持h3; -- 修复php83的扩展bcmath在centos7安装出错。 +- mongodb副本设置/备份/认证。 ### JSDelivr安装地址 diff --git a/class/core/config_api.py b/class/core/config_api.py index bf74ca51c..9dd2b01a1 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -28,7 +28,7 @@ from flask import request class config_api: - __version = '0.16.6' + __version = '0.16.7' __api_addr = 'data/api.json' # 统一默认配置文件 diff --git a/class/core/crontab_api.py b/class/core/crontab_api.py index 3aa06b88b..72c114f01 100755 --- a/class/core/crontab_api.py +++ b/class/core/crontab_api.py @@ -396,14 +396,16 @@ class crontab_api: if soft_name == 'postgresql': sqlite3_name = 'pgsql' + if soft_name == 'mongodb': + sqlite3_name = 'mongodb' + db_list = {} db_list['orderOpt'] = bak_data if not os.path.exists(path + '/' + sqlite3_name + '.db'): db_list['data'] = [] else: - db_list['data'] = mw.M('databases').dbPos( - path, sqlite3_name).field('name,ps').select() + db_list['data'] = mw.M('databases').dbPos(path, sqlite3_name).field('name,ps').select() return mw.getJson(db_list) if stype == 'path': diff --git a/class/core/mw.py b/class/core/mw.py index 181e52c75..b54ad11dd 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -908,6 +908,11 @@ def aesDecrypt_Crypto(data, key, vi): text_decrypted = text_decrypted.decode('utf8').rstrip() # 去掉补位的右侧空格 return text_decrypted +def getDefault(data,val,def_val=''): + if val in data: + return data[val] + return def_val + def encodeImage(imgsrc, newsrc): # 图片加密 import struct diff --git a/plugins/data_query/nosql_mongodb.py b/plugins/data_query/nosql_mongodb.py index 4cbb9a158..32d5ca0f2 100755 --- a/plugins/data_query/nosql_mongodb.py +++ b/plugins/data_query/nosql_mongodb.py @@ -7,6 +7,7 @@ import time import re import pymongo import json +import yaml from bson.objectid import ObjectId from bson.json_util import dumps @@ -23,6 +24,95 @@ def singleton(cls): return _instance[cls] return inner +def getPluginName(): + return 'mongodb' + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + +def getConf(): + path = getServerDir() + "/mongodb.conf" + return path + + +def getConfTpl(): + path = getPluginDir() + "/config/mongodb.conf" + return path + +def pSqliteDb(dbname='users'): + file = getServerDir() + '/mongodb.db' + name = 'mongodb' + + sql_file = getPluginDir() + '/config/mongodb.sql' + import_sql = mw.readFile(sql_file) + # print(sql_file,import_sql) + md5_sql = mw.md5(import_sql) + + import_sign = False + save_md5_file = getServerDir() + '/import_mongodb.md5' + if os.path.exists(save_md5_file): + save_md5_sql = mw.readFile(save_md5_file) + if save_md5_sql != md5_sql: + import_sign = True + mw.writeFile(save_md5_file, md5_sql) + else: + mw.writeFile(save_md5_file, md5_sql) + + if not os.path.exists(file) or import_sql: + conn = mw.M(dbname).dbPos(getServerDir(), name) + csql_list = import_sql.split(';') + for index in range(len(csql_list)): + conn.execute(csql_list[index], ()) + + conn = mw.M(dbname).dbPos(getServerDir(), name) + return conn + +def getConfigData(): + cfg = getConf() + # print(cfg) + config_data = mw.readFile(cfg) + try: + config = yaml.safe_load(config_data) + except: + config = { + "systemLog": { + "destination": "file", + "logAppend": True, + "path": mw.getServerDir()+"/mongodb/log/mongodb.log" + }, + "storage": { + "dbPath": mw.getServerDir()+"/mongodb/data", + "directoryPerDB": True, + "journal": { + "enabled": True + } + }, + "processManagement": { + "fork": True, + "pidFilePath": mw.getServerDir()+"/mongodb/log/mongodb.pid" + }, + "net": { + "port": 27017, + "bindIp": "0.0.0.0" + }, + "security": { + "authorization": "disabled", + "javascriptEnabled": False + } + } + return config + +def getConfPort(): + data = getConfigData() + return data['net']['port'] + +def getConfAuth(): + data = getConfigData() + return data['security']['authorization'] @singleton class nosqlMongodb(): @@ -49,15 +139,22 @@ class nosqlMongodb(): if not self.__DB_LOCAL: self.__DB_PORT = int(self.__config['port']) - # print(self.__DB_HOST,self.__DB_PORT, self.__DB_PASS) + auth = getConfAuth() + port = getConfPort() + mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root') + # print(auth,self.__DB_HOST,port, self.__DB_PASS) try: - self.__DB_CONN = pymongo.MongoClient(host=self.__DB_HOST, port=self.__DB_PORT, maxPoolSize=10) + if auth == 'disabled': + self.__DB_CONN = pymongo.MongoClient(host=self.__DB_HOST, port=port, directConnection=True) + else: + self.__DB_CONN = pymongo.MongoClient(host=self.__DB_HOST, port=port, directConnection=True, username='root',password=mg_root) self.__DB_CONN.admin.command('ping') return self.__DB_CONN except pymongo.errors.ConnectionFailure: return False - except Exception: - self.__DB_ERR = mw.get_error_info() + except Exception as e: + # print(e) + self.__DB_ERR = mw.getTracebackInfo() return False # 获取配置项 @@ -122,7 +219,7 @@ class nosqlMongodbCtr(): mgdb_instance = self.getInstanceBySid(sid).mgdb_conn() if mgdb_instance is False: - return mw.returnData(False,'无法链接') + return mw.returnData(False,'无法链接.') result = {} collections = mgdb_instance[name].list_collection_names() @@ -164,7 +261,7 @@ class nosqlMongodbCtr(): where[mg_field] = re.compile(mg_value) # print(where) - result = collection_instance.find(where).skip(start_index).limit(size).sort({'_id':-1}) + result = collection_instance.find(where).skip(start_index).limit(size).sort('_id',-1) count = collection_instance.count_documents(where) d = [] for document in result: diff --git a/plugins/mariadb/js/mariadb.js b/plugins/mariadb/js/mariadb.js index c29703b14..63b680785 100755 --- a/plugins/mariadb/js/mariadb.js +++ b/plugins/mariadb/js/mariadb.js @@ -1153,7 +1153,7 @@ function dbList(page, search){ list += ''+rdata.data[i]['ps']+''; list += ''; - list += ''+(rdata.data[i]['is_backup']?'备份':'未备份') +' | '; + list += ''+(rdata.data[i]['is_backup']?'已备份':'未备份') +' | '; var rw = ''; var rw_change = 'all'; diff --git a/plugins/mongodb/config/mongodb.bak.conf b/plugins/mongodb/config/mongodb.bak.conf new file mode 100644 index 000000000..2e1ecfdf6 --- /dev/null +++ b/plugins/mongodb/config/mongodb.bak.conf @@ -0,0 +1,18 @@ +directoryperdb = true +dbpath = {$SERVER_PATH}/mongodb/data +logpath = {$SERVER_PATH}/mongodb/logs/mongodb.log +logappend = true +bind_ip = 127.0.0.1 +port = 27017 +fork = true +auth = false +#smallfiles = true + +oplogSize=100 + +# Master/slave replication is no longer supported +#master = true + +#replSet = test + +pidfilepath = {$SERVER_PATH}/mongodb/mongodb.pid diff --git a/plugins/mongodb/config/mongodb.conf b/plugins/mongodb/config/mongodb.conf index 1b500a7d1..025138a43 100644 --- a/plugins/mongodb/config/mongodb.conf +++ b/plugins/mongodb/config/mongodb.conf @@ -1,17 +1,19 @@ -dbpath = {$SERVER_PATH}/mongodb/data -logpath = {$SERVER_PATH}/mongodb/logs/mongodb.log -logappend = true -bind_ip = 127.0.0.1 -port = 27017 -fork = true -auth = false -#smallfiles = true - -oplogSize=100 - -# Master/slave replication is no longer supported -#master = true - -#replSet = test - -pidfilepath = {$SERVER_PATH}/mongodb/mongodb.pid +net: + bindIp: 127.0.0.1 + port: 27017 +processManagement: + fork: true + pidFilePath: {$SERVER_PATH}/mongodb/mongodb.pid +security: + authorization: disabled + javascriptEnabled: false +storage: + dbPath: {$SERVER_PATH}/mongodb/data + directoryPerDB: true +systemLog: + destination: file + logAppend: true + logRotate: reopen + path: {$SERVER_PATH}/mongodb/logs/mongodb.log +replication: + oplogSizeMB: 2048 \ No newline at end of file diff --git a/plugins/mongodb/config/mongodb.sql b/plugins/mongodb/config/mongodb.sql new file mode 100644 index 000000000..37c875509 --- /dev/null +++ b/plugins/mongodb/config/mongodb.sql @@ -0,0 +1,19 @@ +CREATE TABLE IF NOT EXISTS `config` ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `mg_root` TEXT +); + +INSERT INTO `config` (`id`, `mg_root`) VALUES (1, 'mg_root'); + + +CREATE TABLE IF NOT EXISTS `databases` ( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `name` TEXT, + `username` TEXT, + `password` TEXT, + `accept` TEXT, + `rw` TEXT DEFAULT 'rw', + `ps` TEXT, + `addtime` TEXT +); + diff --git a/plugins/mongodb/index.html b/plugins/mongodb/index.html index 68bd81ae6..954e0bb6a 100755 --- a/plugins/mongodb/index.html +++ b/plugins/mongodb/index.html @@ -6,7 +6,48 @@ white-space: nowrap; display: inline-block; vertical-align: middle; -} +} + +.bingfa .bt-input-text { + width: 200px; +} + +.inlineBlock { + display: inline-block; +} + +.db_list{ + padding: 0px 0 10px 0; + font-size: 13px; + line-height: 35px; + height: 45px; +} +.db_list a{ + margin-right: 15px; + color: #555; + font-weight: 600; +} +.db_list span:nth-child(1){ + display: block; + float: left; + padding-left: 15px; + background: #ececec; + border-radius: 3px; +} + +#db_tools button { + margin-right: 10px; +} +#db_tools button:last-child{ + margin-right: 0; +} + +.conf_p span { + display: inline-block; + margin-right: 10px; + width: 115px; + text-align: right; +}
@@ -14,9 +55,12 @@

服务

自启动

-

配置修改

-

负载状态

+

配置修改

+

配置文件

+

配置[KEY]

+

数据列表

文档状态

+

负载状态

复制状态

日志

@@ -25,9 +69,12 @@
+ +