mm_os 2.7.7 → 2.7.9

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.
@@ -1,499 +0,0 @@
1
- var fs = require("fs");
2
- var sql = $.mysql_admin('sys');
3
- var dbs = sql.db();
4
-
5
- class Server {
6
-
7
- }
8
-
9
- /**
10
- * 获取用户
11
- * @param {String} table 数据表
12
- * @param {Number} project_id 项目ID
13
- * @param {String} customId 自定义身份ID
14
- * @param {String} name 用户姓名
15
- * @param {String} phone 用户手机号码
16
- * @param {String} idcard 用户身份证号
17
- * @returns {Object} 返回用户对象
18
- */
19
- Server.prototype.get_enter_sub = async function(table, project_id, customId, name, phone, idcard) {
20
- var db1 = dbs.new("face_" + table, table == "enter" ? "user_id" : "visitor_id");
21
- var query = {
22
- project_id
23
- }
24
- if (customId && customId !== "0") {
25
- query.customId = customId;
26
- } else {
27
- query.name = name;
28
- if (phone) {
29
- query.phone = phone;
30
- } else if (idcard) {
31
- query.idcard = idcard;
32
- }
33
- }
34
- // 先查询1次,看人员是否存在
35
- var enter = await db1.getObj(query, "", "*", false);
36
-
37
- if (!enter) {
38
- // 如果不存在,则用名字再查一次
39
- query = {
40
- project_id,
41
- name
42
- };
43
- enter = await db1.getObj(query, "`time_create` desc", "*", false);
44
- }
45
- return enter;
46
- }
47
-
48
- /**
49
- * 获取用户
50
- * @param {String} project_id 项目ID
51
- * @param {String} table 数据表
52
- * @param {Number} project_id 项目ID
53
- * @param {String} customId 自定义身份ID
54
- * @param {String} name 用户姓名
55
- * @param {String} phone 用户手机号码
56
- * @param {String} idcard 用户身份证号
57
- * @returns {Object} 返回用户对象和用户类型
58
- */
59
- Server.prototype.get_enter = async function(project_id, customId, name, phone, idcard) {
60
- // 默认为 1内部人员类型
61
- var user_type = 1;
62
- var enter = await this.get_enter_sub("enter", project_id, customId, name, phone, idcard);
63
-
64
- if (!enter) {
65
- // 2为访客
66
- user_type = 2;
67
- enter = await this.get_enter_sub("visitor", project_id, customId, name, phone, idcard);
68
- }
69
-
70
- if (enter) {
71
- var by = {};
72
- if (!enter.customId && customId && customId !== "0") {
73
- by.customId = customId;
74
- }
75
- if (!enter.phone && phone) {
76
- by.phone = phone;
77
- }
78
- if (!enter.idcard && idcard && idcard !== '0') {
79
- by.idcard = idcard;
80
- }
81
- if (Object.keys(by).length) {
82
- var db3;
83
- var qy = {};
84
- if (user_type == 2) {
85
- db3 = dbs.new("face_visitor", "visitor_id");
86
- qy.visitor_id = enter.visitor_id
87
- } else {
88
- db3 = dbs.new("face_enter", "user_id");
89
- qy.user_id == enter.user_id;
90
- qy.project_id = enter.project_id;
91
- }
92
- await db3.set(qy, by);
93
- enter = await db3.getObj(qy);
94
- }
95
- } else {
96
- // 3为外部人员(非平台成员)
97
- user_type = 3;
98
- enter = {
99
- department_id: 0,
100
- team_id: 0,
101
- name,
102
- job: "",
103
- phone,
104
- idcard
105
- };
106
- }
107
- return {
108
- user_type,
109
- enter
110
- }
111
- }
112
-
113
- /**
114
- * 处理上传记录
115
- * @param {String} clientid 设备ID
116
- * @param {Object} log 记录
117
- */
118
- Server.prototype.exec_log = async function(clientid, log) {
119
- var {
120
- device,
121
- tip
122
- } = await this.check_device(clientid);
123
-
124
- if (tip) {
125
- return tip
126
- }
127
-
128
- var project_id = device.project_id;
129
- var {
130
- project,
131
- tip
132
- } = await this.check_project(project_id);
133
-
134
- if (tip) {
135
- return tip
136
- }
137
-
138
- var {
139
- customId,
140
- name,
141
- phone,
142
- idcard,
143
- time,
144
- type,
145
- record_type,
146
- person_type,
147
- action,
148
- avatar,
149
- nfc
150
- } = log;
151
- // 通过项目id和用户唯一标识获取用户
152
- var {
153
- enter,
154
- user_type
155
- } = await this.get_enter(project_id, customId, name, phone, idcard);
156
-
157
- // 如果不记录外部人员,则终止,不保存记录
158
- if (!project.save_outboard && user_type === 3) {
159
- return
160
- }
161
-
162
- log = {
163
- project_id,
164
- user_id: 0,
165
- name: "",
166
- // 1内部人员|2访客|3非系统名单
167
- user_type,
168
- direction: "",
169
- // 1刷脸验证|2远程开门|3扫码开门|4刷卡验证
170
- type,
171
- record_type,
172
- action: action || "刷脸验证",
173
- // 1白名单|2黑名单
174
- person_type,
175
- department_id: 0,
176
- team_id: 0,
177
- job: "",
178
- phone: "",
179
- idcard: "",
180
- nfc: "",
181
- note: "",
182
- time: ""
183
- }
184
-
185
- $.push(log, enter);
186
- log.avatar = avatar;
187
- log.time = time;
188
- log.clientid = clientid;
189
- log.direction = device.direction;
190
- if (nfc && !log.nfc) {
191
- log.nfc = nfc;
192
- }
193
- if (log.person_type === 0) {
194
- log.person_type = enter.state == 4 ? 2 : 1;
195
- }
196
- return this.save_log(log, project.upload_pic);
197
- }
198
-
199
- /**
200
- * 检查设备
201
- * @param {String} clientid 客户端ID
202
- * @param {Object} key 键
203
- */
204
- Server.prototype.check_device = async function(clientid, key) {
205
- var tip;
206
- var db_device = dbs.new("face_device", "device_id");
207
- var device = await db_device.getObj({
208
- clientid
209
- });
210
- if (device) {
211
- if (device.available) {
212
- if (key && !device[key]) {
213
- tip = "没有功能权限"
214
- }
215
- } else {
216
- tip = "设备已禁用"
217
- }
218
- } else {
219
- tip = "没有找到设备"
220
- }
221
- return {
222
- device,
223
- tip
224
- };
225
- }
226
-
227
- /**
228
- * 检查项目
229
- * @param {String} project_id 项目ID
230
- * @param {Object} key 键
231
- */
232
- Server.prototype.check_project = async function(project_id, key) {
233
- var tip;
234
- var db2 = dbs.new("sys_project", "project_id");
235
- var project = await db2.getObj({
236
- project_id
237
- });
238
- if (project) {
239
- if (project.available) {
240
- var now = new Date().getTime();
241
- if (now > new Date(project.time_valid).getTime()) {
242
- tip = "项目已过期"
243
- } else if (key && !project[key]) {
244
- tip = "没有功能权限"
245
- }
246
- } else {
247
- tip = "项目已禁用"
248
- }
249
- } else {
250
- tip = "没有找到项目"
251
- }
252
- return {
253
- project,
254
- tip
255
- }
256
- }
257
-
258
- /**
259
- * 保存记录
260
- * @param {Object} log 记录
261
- * @param {Boolean} upload_pic 上传头像
262
- */
263
- Server.prototype.save_log = async function(log, upload_pic) {
264
- var db = dbs.new("face_log", "user_id");
265
- var project_id = log.project_id;
266
- var user_id = log.user_id || 0;
267
- var time = log.time;
268
- var clientid = log.clientid;
269
- var count = await db.count({
270
- project_id,
271
- user_id,
272
- clientid,
273
- time
274
- }, false);
275
-
276
- // 如果记录已存在,则不再保存
277
- if (count > 0) {
278
- return
279
- }
280
-
281
- // 重新定义方向
282
- var direction = log.direction;
283
- if (user_id && direction == "通用") {
284
- var qy = {
285
- project_id,
286
- user_id,
287
- type_has: "1,3,4",
288
- time_min: time.toTime().toStr('yyyy-MM-dd 00:00:00')
289
- };
290
- var obj = await db.getObj(qy, '`time` desc');
291
- if (obj) {
292
- direction = obj.direction == "进" ? "出" : "进"
293
- } else {
294
- direction = "进"
295
- }
296
- }
297
- log.direction = direction;
298
-
299
- // 重新定义头像
300
- var pic;
301
- var fname = time.replace(/[-: ]/g, '_');
302
- var avatar = log.avatar || '';
303
- var p = `/file/image/user/${user_id}/${fname}.png`;
304
- if (avatar) {
305
- if (upload_pic) {
306
- pic = avatar;
307
- avatar = p;
308
- } else {
309
- avatar = "";
310
- }
311
- }
312
- log.avatar = avatar;
313
-
314
- // 如果是访客则追加备注
315
- var visitor_id = log.visitor_id;
316
- if (visitor_id) {
317
- var {
318
- respondent,
319
- date,
320
- source
321
- } = log;
322
- if (typeof(date) == "string") {
323
- date = date.toTime().toStr("yyyy-MM-dd");
324
- } else if (typeof(date) == "object") {
325
- date = date.toStr("yyyy-MM-dd");
326
- } else {
327
- date = ''
328
- }
329
- log.note = `${visitor_id},${source},${date},${respondent},${log.nfc}`;
330
- delete log.visitor_id;
331
- delete log.respondent;
332
- delete log.date;
333
- delete log.source;
334
- }
335
-
336
- // 添加新记录
337
- var n = await db.add(log);
338
-
339
- var bl = n > 0;
340
- if (bl) {
341
- // 更新用户状态
342
- var body = {
343
- clientid,
344
- direction,
345
- time
346
- };
347
- if (log.user_type == 1) {
348
- var db4 = dbs.new("face_enter", "enter_id");
349
- await db4.set({
350
- project_id,
351
- user_id
352
- }, body);
353
- } else if (log.user_type == 2) {
354
- var db4 = dbs.new("face_visitor", "visitor_id");
355
- await db4.set({
356
- visitor_id
357
- }, body);
358
- }
359
-
360
- if (pic) {
361
- var file = ('/static' + p).fullname();
362
- file.addDir();
363
- var po = pic.replace(/^data:image\/\w+;base64,/, "");
364
- var bf = Buffer.from(po, 'base64');
365
- fs.writeFileSync(file, bf);
366
- }
367
- }
368
- return bl;
369
- }
370
-
371
- /**
372
- * 处理扫描二维码开门
373
- * @param {String} clientid 客户端ID
374
- * @param {String} qrcode 二维码内容
375
- */
376
- Server.prototype.exec_qrcode = async function(clientid, qrcode = "") {
377
- var ret;
378
- var db = dbs.new("face_qrcode", "qrcode_id");
379
- var now = new Date();
380
- var time = now.toStr('yyyy-MM-dd hh:mm:ss');
381
- var obj = await db.getObj({
382
- qrcode
383
- });
384
-
385
- if (obj) {
386
- if (now.getTime() > obj.time_end.getTime()) {
387
- // 发送开门控制
388
- return {
389
- "uuid": obj.user_id,
390
- // 0不开门,1开门
391
- "pass": false,
392
- "tip": "二维码已过期"
393
- }
394
- };
395
- var {
396
- device,
397
- tip
398
- } = await this.check_device(clientid, "qrcode");
399
- if (tip) {
400
- // 发送开门控制
401
- ret = {
402
- "uuid": obj.user_id,
403
- // 0不开门,1开门
404
- "pass": false,
405
- "tip": tip
406
- }
407
- } else {
408
- if (obj.count == 0 || obj.num < obj.count) {
409
- var db = dbs.new("face_enter");
410
- var user = await db.getObj({
411
- project_id: obj.project_id,
412
- user_id: obj.user_id,
413
- state: 3
414
- });
415
- if (user) {
416
- if (user.client && user.client.toLocaleUpperCase().indexOf(clientid.toLocaleUpperCase()) !==
417
- -1) {
418
- obj.num++;
419
- // 发送开门控制
420
- ret = {
421
- "uuid": user.customId || user.project_id + "-" + user.user_id,
422
- // 0不开门,1开门
423
- "pass": true,
424
- "tip": "请通行",
425
- user
426
- }
427
- var log = {
428
- project_id: 0,
429
- user_id: 0,
430
- name: "",
431
- // 1内部人员|2访客|3非系统名单
432
- user_type: 1,
433
- // 1刷脸验证|2远程开门|3扫码开门|4刷卡验证
434
- type: 3,
435
- record_type: 1,
436
- action: "智码开门",
437
- // 1白名单|2黑名单
438
- person_type: 1,
439
- department_id: 0,
440
- team_id: 0,
441
- job: "",
442
- phone: "",
443
- idcard: "",
444
- nfc: "",
445
- note: ""
446
- }
447
- $.push(log, user);
448
- log.direction = device.direction;
449
- log.clientid = clientid;
450
- log.time = time;
451
- await this.save_log(log);
452
- ret = {
453
- "uuid": user.customId || user.project_id + "-" + user.user_id,
454
- "pass": true,
455
- "tip": "请通行",
456
- device
457
- }
458
- } else {
459
- // 发送开门控制
460
- ret = {
461
- "uuid": user.customId || user.project_id + "-" + user.user_id,
462
- // 0不开门,1开门
463
- "pass": false,
464
- "tip": "没有访问权限"
465
- }
466
- }
467
- } else {
468
- // 发送开门控制
469
- ret = {
470
- "uuid": obj.project_id + "-" + obj.user_id,
471
- // 0不开门,1开门
472
- "pass": false,
473
- "tip": "非法用户"
474
- }
475
- }
476
- } else {
477
- // 发送开门控制
478
- ret = {
479
- "uuid": obj.project_id + "-" + obj.user_id,
480
- // 0不开门,1开门
481
- "pass": false,
482
- "tip": "使用次数超限"
483
- }
484
- }
485
- }
486
- } else {
487
- // 发送开门控制
488
- ret = {
489
- "uuid": "0",
490
- // 0不开门,1开门
491
- "pass": false,
492
- "tip": "非法二维码"
493
- }
494
- }
495
-
496
- return ret;
497
- }
498
-
499
- $.server = new Server();
@@ -1,115 +0,0 @@
1
- {
2
- "sys": {
3
- // 服务端名称
4
- "name": "mm",
5
- // 服务端中文名
6
- "title": "超级美眉",
7
- // 缓存方式 memory redis mongodb
8
- "cache": "redis",
9
- // 系统使用的语言
10
- "lang": "zh_CN",
11
- // 定时任务
12
- "task": true,
13
- // 热重载
14
- "hot_reload": false
15
- },
16
- "web": {
17
- "state": true,
18
- // 访问地址
19
- "host": "0.0.0.0",
20
- // 访问端口号
21
- "port": 8000,
22
- // 是否启用websocket
23
- "socket": false,
24
- // 是否启用压缩
25
- "compress": false,
26
- // 是否启用事件
27
- "event": true,
28
- // 是否启用日志
29
- "log": true,
30
- // 是否启用静态文件
31
- "static": true,
32
- // 静态文件路径
33
- "static_path": "./static",
34
- // 静态文件缓存时长
35
- "max_age": 120000,
36
- // 代理转发
37
- "proxy": {},
38
- // 跨域
39
- "cos": {
40
- "status": true,
41
- "origin": "*",
42
- "headers": "Content-Type,Content-Length,Authorization,Accept,X-Requested-With,x-auth-token,token,client_id,appid,apikey,user_id,x-forwarded-for,x-real-ip,user-agent,cache-control,pragma,accept-encoding,connection,host"
43
- },
44
- // 单位秒, 3600 = 1小时
45
- "request_duration": 60,
46
- // 请求次数上限
47
- "request_limit": 100,
48
- // 是否加入黑名单
49
- "request_block": true
50
- },
51
- "mqtt": {
52
- // 是否启用MQTT
53
- "state": false,
54
- // mqtt访问端口号
55
- "socket_port": 1883,
56
- // websocket 访问端口
57
- "http_port": 8083,
58
- // 缓存方式 memory、mongodb、redis
59
- "cache": "redis",
60
- // 缓存服务器地址
61
- "cache_host": "mongodb://localhost:27017/mosca",
62
- // MQTT订阅方式
63
- "subscribe_qos": 0,
64
- // 清除历史
65
- "clean": true,
66
- // 协议头
67
- "protocol": "mqtt",
68
- // MQTT服务器地址
69
- "hostname": "mqtt.aieliantong.com",
70
- // MQTT服务器用户名
71
- "username": "developer",
72
- // MQTT服务器密码
73
- "password": "asd123",
74
- // MQTT端口号
75
- "port": 1883,
76
- // 连接的数据表
77
- "table": "face_device"
78
- },
79
- "mysql": {
80
- // 服务器地址
81
- "host": "127.0.0.1",
82
- // 端口号
83
- "port": 3306,
84
- // 用户名
85
- "user": "root",
86
- // 密码
87
- "password": "Asd159357",
88
- // 数据库名称
89
- "database": "face"
90
- },
91
- "redis": {
92
- // 服务器地址
93
- "host": "127.0.0.1",
94
- // 端口号
95
- "port": 6379,
96
- // 密码
97
- "password": "asd159357",
98
- // 选用的数据库0-9
99
- "database": 0,
100
- // 键前缀
101
- "prefix": "mm_"
102
- },
103
- "mongodb": {
104
- // 服务器地址
105
- "host": "localhost",
106
- // 端口号
107
- "port": 27017,
108
- // 数据库名
109
- "database": "mqtt",
110
- // 用户名
111
- "user": "mqtt",
112
- // 密码 无则代表连接不需要账号密码
113
- "password": "asd123"
114
- }
115
- }
@@ -1,116 +0,0 @@
1
- {
2
- "sys": {
3
- // 服务端名称
4
- "name": "mm",
5
- // 服务端中文名
6
- "title": "超级美眉",
7
- // 缓存方式
8
- "cache": "redis",
9
- // 系统使用的语言
10
- "lang": "zh_CN",
11
- // 定时任务
12
- "task": true,
13
- // 热重载
14
- "hot_reload": true
15
- },
16
- "web": {
17
- "state": true,
18
- // 访问地址
19
- "host": "0.0.0.0",
20
- // 访问端口号
21
- "port": 8000,
22
- // 是否启用websocket
23
- "socket": true,
24
- // 是否启用压缩
25
- "compress": false,
26
- // 是否启用事件
27
- "event": true,
28
- // 是否启用事件
29
- "log": true,
30
- // 是否启用静态文件
31
- "static": true,
32
- // 静态文件路径
33
- "static_path": "./static",
34
- // 静态文件缓存时长
35
- "max_age": 3600,
36
- // 代理转发
37
- "proxy": {},
38
- // 跨域
39
- "cos": {
40
- "status": true,
41
- "origin": "*"
42
- // "headers": "Content-Type,Content-Length,Authorization,Accept,X-Requested-With,x-auth-token,token,client_id,appid,apikey,user_id,x-forwarded-for,x-real-ip,User-Agent,cache-control,pragma,accept-encoding,connection,host"
43
- },
44
- // 单位秒, 3600 = 1小时
45
- "request_duration": 60,
46
- // 请求次数上限
47
- "request_limit": 100,
48
- // 是否加入黑名单
49
- "request_block": true
50
- },
51
- "mqtt": {
52
- "state": true,
53
- // mqtt访问端口号
54
- "socket_port": 1883,
55
- // 服务端
56
- "http_host": "localhost",
57
- // websocket 访问端口
58
- "http_port": 8083,
59
- // 缓存方式 memory、mongodb、redis
60
- "cache": "memory",
61
- // 缓存服务器地址
62
- "cache_host": "mongodb://localhost:27017/mosca",
63
- // MQTT订阅方式
64
- "subscribe_qos": 1,
65
- // 清除历史
66
- "clean": true,
67
- "protocol": "mqtt",
68
- "hostname": "127.0.0.1",
69
- // MQTT服务器客户端ID
70
- "clientId": "server",
71
- // MQTT服务器用户名
72
- "username": "server",
73
- // MQTT服务器密码
74
- "password": "asd123",
75
- // MQTT端口号
76
- "port": 1883,
77
- // 连接的数据表
78
- "table": "face_device"
79
- },
80
- "mysql": {
81
- // 服务器地址
82
- "host": "127.0.0.1",
83
- // 端口号
84
- "port": 3306,
85
- // 用户名
86
- "user": "face",
87
- // 密码
88
- "password": "Asd159357",
89
- // 数据库名称
90
- "database": "face"
91
- },
92
- "redis": {
93
- // 服务器地址
94
- "host": "127.0.0.1",
95
- // 端口号
96
- "port": 6379,
97
- // 密码
98
- "password": "asd159357",
99
- // 选用的数据库0-9
100
- "database": 0,
101
- // 键前缀
102
- "prefix": "mm_"
103
- },
104
- "mongodb": {
105
- // 服务器地址
106
- "host": "localhost",
107
- // 端口号
108
- "port": 27017,
109
- // 数据库名
110
- "database": "face",
111
- // 用户名
112
- "user": "face",
113
- // 密码 无则代表连接不需要账号密码
114
- "password": "asd159357"
115
- }
116
- }