mm_os 2.7.0 → 2.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cache/test/main/config.json +7 -0
- package/core/com/mqtt/index.js +3 -2
- package/core/com/plugin/drive.js +82 -4
- package/demo/app/test/plugin/main/api_demo_client/test/index.js +1 -1
- package/demo/config/development.json +3 -1
- package/demo/config/local.json +4 -1
- package/middleware/waf_ip/index.js +8 -2
- package/package.json +2 -2
- package/static/file/image/user/42/2025_01_02_10_58_15.png +0 -0
package/core/com/mqtt/index.js
CHANGED
|
@@ -34,6 +34,7 @@ class MQTT extends Index {
|
|
|
34
34
|
publish_qos: 1,
|
|
35
35
|
username: "de",
|
|
36
36
|
password: "asd123",
|
|
37
|
+
table: "iot_device",
|
|
37
38
|
clean: false,
|
|
38
39
|
longtime: 15000,
|
|
39
40
|
// 在线有效期时长判断 单位:毫秒,150000毫秒为2.5分钟
|
|
@@ -428,7 +429,7 @@ MQTT.prototype.save_online = async function(arr, online = 1) {
|
|
|
428
429
|
var sql = $.mysql_admin('sys');
|
|
429
430
|
sql.open();
|
|
430
431
|
var db = sql.db();
|
|
431
|
-
db.table = "
|
|
432
|
+
db.table = this.config.table || "iot_device";
|
|
432
433
|
db.size = 0;
|
|
433
434
|
var query = {};
|
|
434
435
|
if (arr) {
|
|
@@ -444,7 +445,7 @@ MQTT.prototype.get_drives = async function() {
|
|
|
444
445
|
var sql = $.mysql_admin('sys');
|
|
445
446
|
sql.open();
|
|
446
447
|
var db = sql.db();
|
|
447
|
-
db.table = "
|
|
448
|
+
db.table = this.config.table || "iot_device";
|
|
448
449
|
db.size = 0;
|
|
449
450
|
return await db.get({}, "", "clientid, online");
|
|
450
451
|
}
|
package/core/com/plugin/drive.js
CHANGED
|
@@ -66,6 +66,8 @@ class Drive extends Item {
|
|
|
66
66
|
// 配置
|
|
67
67
|
"options": []
|
|
68
68
|
};
|
|
69
|
+
// 配置
|
|
70
|
+
this.options = {};
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
|
|
@@ -74,7 +76,9 @@ class Drive extends Item {
|
|
|
74
76
|
* @param {Object} config 配置
|
|
75
77
|
*/
|
|
76
78
|
Drive.prototype.set_config = function(config) {
|
|
77
|
-
|
|
79
|
+
var file = this.filename;
|
|
80
|
+
var cg = Object.assign({}, this.config, config || {});
|
|
81
|
+
this.config = conf(cg, file);
|
|
78
82
|
this.set_config_after();
|
|
79
83
|
}
|
|
80
84
|
|
|
@@ -88,6 +92,9 @@ Drive.prototype.set_config_after = function() {
|
|
|
88
92
|
this.log = new Log({
|
|
89
93
|
filename
|
|
90
94
|
});
|
|
95
|
+
var options = this.get_config_options();
|
|
96
|
+
this.options = this.merge_options(options);
|
|
97
|
+
this.backup_options();
|
|
91
98
|
}
|
|
92
99
|
|
|
93
100
|
/**
|
|
@@ -114,7 +121,6 @@ Drive.prototype.update_options = function(options = []) {
|
|
|
114
121
|
Object.assign(obj, o);
|
|
115
122
|
} else {
|
|
116
123
|
list.push(o);
|
|
117
|
-
// options.splice(i, 1);
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
126
|
for (var i = 0; i < options.length; i++) {
|
|
@@ -138,6 +144,14 @@ Drive.prototype.update_options_after = function(options) {
|
|
|
138
144
|
* @return {Object} 返回配置参数
|
|
139
145
|
*/
|
|
140
146
|
Drive.prototype.get_options = function() {
|
|
147
|
+
return this.options;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 获取配置参数
|
|
152
|
+
* @return {Object} 返回配置参数
|
|
153
|
+
*/
|
|
154
|
+
Drive.prototype.get_config_options = function() {
|
|
141
155
|
var op = this.config.options || [];
|
|
142
156
|
var dict = {};
|
|
143
157
|
for (var i = 0; i < op.length; i++) {
|
|
@@ -148,8 +162,12 @@ Drive.prototype.get_options = function() {
|
|
|
148
162
|
} else if (o.type === "boolean") {
|
|
149
163
|
var val = false;
|
|
150
164
|
if (o.value) {
|
|
151
|
-
if (o.value ==
|
|
152
|
-
|
|
165
|
+
if (typeof(o.value) == "string") {
|
|
166
|
+
if (o.value == '1' || o.value == 'true') {
|
|
167
|
+
val = true;
|
|
168
|
+
}
|
|
169
|
+
} else if (typeof(o.value) == "boolean") {
|
|
170
|
+
val = o.value;
|
|
153
171
|
}
|
|
154
172
|
}
|
|
155
173
|
dict[o.name] = val;
|
|
@@ -161,6 +179,8 @@ Drive.prototype.get_options = function() {
|
|
|
161
179
|
dict[o.name] = o.value.toJSON();
|
|
162
180
|
} else if (o.value === "null") {
|
|
163
181
|
dict[o.name] = null;
|
|
182
|
+
} else if (o.type === "string") {
|
|
183
|
+
dict[o.name] = o.value || "";
|
|
164
184
|
} else {
|
|
165
185
|
dict[o.name] = o.value;
|
|
166
186
|
}
|
|
@@ -168,6 +188,64 @@ Drive.prototype.get_options = function() {
|
|
|
168
188
|
return dict;
|
|
169
189
|
}
|
|
170
190
|
|
|
191
|
+
/**
|
|
192
|
+
* 获取配置参数
|
|
193
|
+
* @param {Object} 设置配置
|
|
194
|
+
* @return {Object} 返回配置参数
|
|
195
|
+
*/
|
|
196
|
+
Drive.prototype.design_option = function(body) {
|
|
197
|
+
var cg = this.config;
|
|
198
|
+
if (Array.isArray(body)) {
|
|
199
|
+
cg.options = body;
|
|
200
|
+
} else {
|
|
201
|
+
var options = cg.options || [];
|
|
202
|
+
var option = options.getObj({
|
|
203
|
+
name: body.name
|
|
204
|
+
});
|
|
205
|
+
if (option) {
|
|
206
|
+
Object.assign(option, body);
|
|
207
|
+
} else {
|
|
208
|
+
options.push(body);
|
|
209
|
+
}
|
|
210
|
+
cg.options = options;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 保存配置
|
|
216
|
+
*/
|
|
217
|
+
Drive.prototype.save_option = function(options) {
|
|
218
|
+
this.options = options;
|
|
219
|
+
this.backup_options();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 保存配置
|
|
224
|
+
*/
|
|
225
|
+
Drive.prototype.backup_options = function() {
|
|
226
|
+
var l = $.slash;
|
|
227
|
+
var file = "/cache/" + l + l + this.filename.right("app" + l).replaceAll(l + "plugin", "").replace(".json",
|
|
228
|
+
"/config.json");
|
|
229
|
+
file = file.fullname();
|
|
230
|
+
file.addDir();
|
|
231
|
+
file.saveJson(this.options);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* 合并配置
|
|
236
|
+
* @param {Object} cg 配置
|
|
237
|
+
*/
|
|
238
|
+
Drive.prototype.merge_options = function(options) {
|
|
239
|
+
var l = $.slash;
|
|
240
|
+
var file = "/cache/" + l + l + this.filename.right("app" + l).replaceAll(l + "plugin", "").replace(".json",
|
|
241
|
+
"/config.json");
|
|
242
|
+
var options_cache = file.loadJson();
|
|
243
|
+
if (options_cache) {
|
|
244
|
+
$.push(options, options_cache);
|
|
245
|
+
}
|
|
246
|
+
return options;
|
|
247
|
+
}
|
|
248
|
+
|
|
171
249
|
/**
|
|
172
250
|
* 新建脚本
|
|
173
251
|
* @param {String} 文件
|
|
@@ -48,7 +48,7 @@ async function main(ctx, db) {
|
|
|
48
48
|
// var plus = $.plugin_admin('test');
|
|
49
49
|
// plus.run("main", "start");
|
|
50
50
|
// plus.run("main", "stop");
|
|
51
|
-
|
|
51
|
+
var ret = await this.sql.run(query, body, db);
|
|
52
52
|
return ret;
|
|
53
53
|
};
|
|
54
54
|
|
package/demo/config/local.json
CHANGED
|
@@ -7,13 +7,17 @@ const platform = os.platform();
|
|
|
7
7
|
/**
|
|
8
8
|
* 获取客户端IP
|
|
9
9
|
* @param {Object} req 请求对象
|
|
10
|
-
*
|
|
10
|
+
* @returns {String} 返回真实IP
|
|
11
11
|
*/
|
|
12
12
|
function getClientIP(req) {
|
|
13
|
-
|
|
13
|
+
var ip = req.headers['x-forwarded-for'] || req.headers['X-Forwarded-For'] || req.headers['x-real-ip'] ||
|
|
14
14
|
req.connection.remoteAddress ||
|
|
15
15
|
req.socket.remoteAddress ||
|
|
16
16
|
req.connection.socket.remoteAddress;
|
|
17
|
+
if (ip && ip.split(',').length > 0) {
|
|
18
|
+
ip = ip.split(',')[0]; // 取第一个IP地址
|
|
19
|
+
}
|
|
20
|
+
return ip;
|
|
17
21
|
};
|
|
18
22
|
|
|
19
23
|
/**
|
|
@@ -99,6 +103,8 @@ module.exports = function(server, config) {
|
|
|
99
103
|
time,
|
|
100
104
|
num
|
|
101
105
|
}), duration);
|
|
106
|
+
ctx.request.ip = ip;
|
|
107
|
+
ctx.ip = ip;
|
|
102
108
|
await next();
|
|
103
109
|
} else {
|
|
104
110
|
ctx.status = 429;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_os",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.2",
|
|
4
4
|
"description": "这是超级美眉服务端框架,用于快速构建应用程序。",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"mm_machine": "^1.8.1",
|
|
45
45
|
"mm_mongodb": "^1.4.2",
|
|
46
46
|
"mm_mqtt": "^1.0.6",
|
|
47
|
-
"mm_mysql": "^1.8.
|
|
47
|
+
"mm_mysql": "^1.8.9",
|
|
48
48
|
"mm_os": "^2.6.4",
|
|
49
49
|
"mm_redis": "^1.4.2",
|
|
50
50
|
"mm_ret": "^1.3.9",
|
|
Binary file
|