mm_os 3.3.1 → 4.0.1

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.
Files changed (380) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +498 -99
  3. package/README_EN.md +505 -0
  4. package/adapter/adapter.js +431 -0
  5. package/adapter/custom_persistence.js +660 -0
  6. package/adapter/mqtt.js +273 -0
  7. package/adapter/socket.js +113 -0
  8. package/adapter/web.js +67 -0
  9. package/adapter/websocket.js +146 -0
  10. package/com/api/com.json +5 -0
  11. package/{core/com → com}/api/config.tpl.json +8 -8
  12. package/com/api/drive.js +708 -0
  13. package/com/api/index.js +198 -0
  14. package/com/api/oauth.js +200 -0
  15. package/com/api/script.tpl.js +32 -0
  16. package/com/cmd/README.md +11 -0
  17. package/com/cmd/com.json +5 -0
  18. package/com/cmd/config.tpl.json +122 -0
  19. package/com/cmd/drive.js +1548 -0
  20. package/com/cmd/index.js +1066 -0
  21. package/com/cmd/msg.json +48 -0
  22. package/com/cmd/nlp.js +525 -0
  23. package/com/cmd/script.tpl.js +32 -0
  24. package/com/db/com.json +5 -0
  25. package/com/db/drive.js +1999 -0
  26. package/com/db/index.js +242 -0
  27. package/{core/com → com}/event/README.md +4 -4
  28. package/com/event/com.json +5 -0
  29. package/{core/com → com}/event/config.tpl.json +18 -18
  30. package/com/event/drive.js +59 -0
  31. package/com/event/index.js +409 -0
  32. package/com/event/script.tpl.js +23 -0
  33. package/com/mqtt/com.json +5 -0
  34. package/{core/com → com}/mqtt/config.tpl.json +3 -5
  35. package/com/mqtt/drive.js +676 -0
  36. package/com/mqtt/index.js +822 -0
  37. package/com/mqtt/mm_mqtt.js +425 -0
  38. package/com/mqtt/script.tpl.js +723 -0
  39. package/com/nav/com.json +5 -0
  40. package/com/nav/config.tpl.json +84 -0
  41. package/com/nav/drive.js +702 -0
  42. package/com/nav/index.js +231 -0
  43. package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
  44. package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
  45. package/com/nav/tpl/admin_pc/page_form.vue +180 -0
  46. package/com/nav/tpl/admin_pc/page_view.vue +124 -0
  47. package/com/nav/tpl/dev_pc/page_default.vue +247 -0
  48. package/com/nav/tpl/dev_pc/page_type.vue +313 -0
  49. package/com/nav/tpl/home_pc/page_default.vue +234 -0
  50. package/com/nav/tpl/home_pc/page_form.vue +137 -0
  51. package/com/nav/tpl/home_pc/page_list.vue +234 -0
  52. package/com/nav/tpl/home_pc/page_nav.vue +221 -0
  53. package/com/nav/tpl/home_pc/page_type.vue +234 -0
  54. package/com/nav/tpl/home_pc/page_view.vue +125 -0
  55. package/com/nav/tpl/home_phone/page_channel.vue +234 -0
  56. package/com/nav/tpl/home_phone/page_default.vue +234 -0
  57. package/com/nav/tpl/home_phone/page_form.vue +137 -0
  58. package/com/nav/tpl/home_phone/page_nav.vue +237 -0
  59. package/com/nav/tpl/home_phone/page_type.vue +234 -0
  60. package/com/nav/tpl/home_phone/page_view.vue +125 -0
  61. package/com/nav/viewmodel.js +446 -0
  62. package/com/param/com.json +5 -0
  63. package/{core/com → com}/param/config.tpl.json +7 -1
  64. package/com/param/drive.js +502 -0
  65. package/com/param/index.js +155 -0
  66. package/com/param/script.tpl.js +12 -0
  67. package/com/pendant/com.json +5 -0
  68. package/{core/com/component → com/pendant}/config.tpl.json +15 -13
  69. package/com/pendant/drive.js +204 -0
  70. package/com/pendant/index.js +441 -0
  71. package/com/pendant/pendant.html +16 -0
  72. package/com/pendant/script.tpl.js +18 -0
  73. package/com/socket/com.json +5 -0
  74. package/com/socket/config.tpl.json +12 -0
  75. package/com/socket/drive.js +651 -0
  76. package/com/socket/index.js +351 -0
  77. package/com/socket/script.tpl.js +41 -0
  78. package/com/sql/com.json +5 -0
  79. package/{core/com → com}/sql/config.tpl.json +13 -9
  80. package/com/sql/drive.js +1259 -0
  81. package/com/sql/index.js +150 -0
  82. package/com/sql/script.tpl.js +47 -0
  83. package/com/static/com.json +5 -0
  84. package/{core/com → com}/static/config.tpl.json +10 -6
  85. package/com/static/drive.js +194 -0
  86. package/com/static/index.js +226 -0
  87. package/com/static/script.tpl.js +28 -0
  88. package/com/task/com.json +5 -0
  89. package/{core/com → com}/task/config.tpl.json +4 -6
  90. package/com/task/drive.js +405 -0
  91. package/com/task/index.js +148 -0
  92. package/com/task/script.tpl.js +37 -0
  93. package/com/template/com.json +5 -0
  94. package/com/template/config.tpl.json +16 -0
  95. package/com/template/drive.js +80 -0
  96. package/com/template/index.js +141 -0
  97. package/com.js +156 -0
  98. package/common/README.md +2 -0
  99. package/common/handler/msg/handler.json +22 -0
  100. package/common/handler/msg/index.js +23 -0
  101. package/common/handler/player/handler.json +22 -0
  102. package/common/handler/player/index.js +287 -0
  103. package/common/handler/user/handler.json +22 -0
  104. package/common/handler/user/index.js +23 -0
  105. package/common/middleware/web_after/index.js +29 -0
  106. package/common/middleware/web_after/middleware.json +9 -0
  107. package/common/middleware/web_base/index.js +113 -0
  108. package/common/middleware/web_base/middleware.json +19 -0
  109. package/common/middleware/web_before/index.js +33 -0
  110. package/common/middleware/web_before/middleware.json +9 -0
  111. package/common/middleware/web_cors/index.js +87 -0
  112. package/common/middleware/web_cors/middleware.json +24 -0
  113. package/common/middleware/web_error/index.js +119 -0
  114. package/common/middleware/web_error/middleware.json +18 -0
  115. package/common/middleware/web_ip/index.js +15 -0
  116. package/common/middleware/web_ip/middleware.json +14 -0
  117. package/common/middleware/web_logger/index.js +156 -0
  118. package/common/middleware/web_logger/middleware.json +14 -0
  119. package/common/middleware/web_main/index.js +24 -0
  120. package/common/middleware/web_main/middleware.json +9 -0
  121. package/common/middleware/web_static/index.js +73 -0
  122. package/common/middleware/web_static/middleware.json +54 -0
  123. package/common/middleware/web_waf/index.js +385 -0
  124. package/common/middleware/web_waf/middleware.json +13 -0
  125. package/common/model/msg/index.js +88 -0
  126. package/common/model/msg/model.json +401 -0
  127. package/common/model/player/index.js +63 -0
  128. package/common/model/player/model.json +185 -0
  129. package/common/model/user/index.js +11 -0
  130. package/common/model/user/model.json +219 -0
  131. package/core/app/config.tpl.json +67 -0
  132. package/core/app/index.js +632 -0
  133. package/core/app/script.tpl.js +52 -0
  134. package/core/channel/index.js +899 -0
  135. package/core/channel/matcher.js +585 -0
  136. package/core/com/config.tpl.json +16 -0
  137. package/core/com/index.js +74 -0
  138. package/core/com/script.tpl.js +5 -0
  139. package/core/component/component.js +42 -0
  140. package/core/component/config.tpl.json +63 -0
  141. package/core/component/index.js +273 -0
  142. package/core/component/script.tpl.js +19 -0
  143. package/core/controller/config.tpl.json +14 -0
  144. package/core/controller/index.js +373 -0
  145. package/core/controller/script.tpl.js +27 -0
  146. package/core/factory/config.tpl.json +14 -0
  147. package/core/factory/entity.js +275 -0
  148. package/core/factory/index.js +241 -0
  149. package/core/factory/script.tpl.js +16 -0
  150. package/core/game/bat/index.js +137 -0
  151. package/core/game/bat/world.js +622 -0
  152. package/core/game/config.tpl.json +16 -0
  153. package/core/game/entity_admin.js +230 -0
  154. package/core/game/index.js +186 -0
  155. package/core/handler/config.tpl.json +22 -0
  156. package/core/handler/index.js +181 -0
  157. package/core/handler/script.tpl.js +23 -0
  158. package/core/logic/config.tpl.json +14 -0
  159. package/core/logic/index.js +59 -0
  160. package/core/logic/script.tpl.js +19 -0
  161. package/core/middleware/config.tpl.json +16 -0
  162. package/core/middleware/index.js +125 -0
  163. package/core/middleware/script.tpl.js +37 -0
  164. package/core/mod/config.tpl.json +22 -0
  165. package/core/mod/index.js +130 -0
  166. package/core/mod/script.tpl.js +34 -0
  167. package/core/model/config.tpl.json +219 -0
  168. package/core/model/index.js +272 -0
  169. package/core/model/model.js +27 -0
  170. package/core/model/script.tpl.js +20 -0
  171. package/core/notifier/config.tpl.json +14 -0
  172. package/core/notifier/index.js +77 -0
  173. package/core/notifier/script.tpl.js +20 -0
  174. package/core/plugin/config.tpl.json +24 -0
  175. package/core/plugin/index.js +232 -0
  176. package/core/plugin/script.tpl.js +51 -0
  177. package/core/pusher/config.tpl.json +14 -0
  178. package/core/pusher/index.js +161 -0
  179. package/core/pusher/script.tpl.js +20 -0
  180. package/core/room/bat/index.js +170 -0
  181. package/core/room/bat/room.js +524 -0
  182. package/core/room/config.tpl.json +20 -0
  183. package/core/room/index.js +249 -0
  184. package/core/room/room.js +61 -0
  185. package/core/scene/config.tpl.json +14 -0
  186. package/core/scene/index.js +466 -0
  187. package/core/scene/loop.js +1255 -0
  188. package/core/scene/map.js +28 -0
  189. package/core/scene/script.tpl.js +22 -0
  190. package/core/sender/config.tpl.json +14 -0
  191. package/core/sender/index.js +79 -0
  192. package/core/sender/script.tpl.js +20 -0
  193. package/core/service/config.tpl.json +14 -0
  194. package/core/service/index.js +100 -0
  195. package/core/service/script.tpl.js +25 -0
  196. package/core/store/config.tpl.json +26 -0
  197. package/core/store/index.js +1755 -0
  198. package/core/store/script.tpl.js +22 -0
  199. package/core/store/sql.js +1464 -0
  200. package/core/system/config.tpl.json +18 -0
  201. package/core/system/index.js +312 -0
  202. package/core/system/script.tpl.js +77 -0
  203. package/core/view/config.tpl.json +14 -0
  204. package/core/view/index.js +91 -0
  205. package/core/view/script.tpl.js +20 -0
  206. package/core/zone/bat/index.js +725 -0
  207. package/core/zone/config.tpl.json +54 -0
  208. package/core/zone/index.js +614 -0
  209. package/core/zone/script.tpl.js +10 -0
  210. package/core/zone/zone_bat.js +136 -0
  211. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
  212. package/index.js +17 -333
  213. package/os.js +57 -0
  214. package/package.json +65 -55
  215. package/server.js +598 -0
  216. package/README.en.md +0 -36
  217. package/conf.json +0 -3
  218. package/core/base/mqtt/index.js +0 -1110
  219. package/core/base/mqtt/lib.js +0 -40
  220. package/core/base/web/index.js +0 -245
  221. package/core/com/api/com.json +0 -4
  222. package/core/com/api/drive.js +0 -668
  223. package/core/com/api/index.js +0 -108
  224. package/core/com/api/oauth.js +0 -158
  225. package/core/com/api/script.js +0 -32
  226. package/core/com/app/README.md +0 -3
  227. package/core/com/app/com.json +0 -4
  228. package/core/com/app/config.tpl.json +0 -16
  229. package/core/com/app/drive.js +0 -309
  230. package/core/com/app/index.js +0 -211
  231. package/core/com/app/script.js +0 -155
  232. package/core/com/cmd/com.json +0 -4
  233. package/core/com/cmd/config.tpl.json +0 -66
  234. package/core/com/cmd/drive.js +0 -513
  235. package/core/com/cmd/index.js +0 -354
  236. package/core/com/cmd/old/5w2h.js +0 -54
  237. package/core/com/cmd/old/drive.js +0 -423
  238. package/core/com/cmd/script.js +0 -11
  239. package/core/com/component/README.md +0 -3
  240. package/core/com/component/com.json +0 -4
  241. package/core/com/component/component.html +0 -16
  242. package/core/com/component/drive.js +0 -197
  243. package/core/com/component/index.js +0 -312
  244. package/core/com/component/script.js +0 -18
  245. package/core/com/db/com.json +0 -4
  246. package/core/com/db/drive.js +0 -1160
  247. package/core/com/db/index.js +0 -176
  248. package/core/com/event/com.json +0 -4
  249. package/core/com/event/drive.js +0 -133
  250. package/core/com/event/index.js +0 -345
  251. package/core/com/event/script.js +0 -26
  252. package/core/com/eventer/com.js +0 -477
  253. package/core/com/eventer/com.json +0 -4
  254. package/core/com/middleware/com.js +0 -154
  255. package/core/com/middleware/com.json +0 -4
  256. package/core/com/middleware/config.tpl.json +0 -8
  257. package/core/com/middleware/script.js +0 -9
  258. package/core/com/mqtt/com.json +0 -4
  259. package/core/com/mqtt/drive.js +0 -600
  260. package/core/com/mqtt/index.js +0 -572
  261. package/core/com/mqtt/mm_mqtt.js +0 -330
  262. package/core/com/mqtt/script.js +0 -604
  263. package/core/com/msg/com.js +0 -296
  264. package/core/com/msg/com.json +0 -4
  265. package/core/com/nav/com.json +0 -4
  266. package/core/com/nav/config.tpl.json +0 -75
  267. package/core/com/nav/drive.js +0 -549
  268. package/core/com/nav/index.js +0 -182
  269. package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
  270. package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
  271. package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
  272. package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
  273. package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
  274. package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
  275. package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
  276. package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
  277. package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
  278. package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
  279. package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
  280. package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
  281. package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
  282. package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
  283. package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
  284. package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
  285. package/core/com/nav/viewmodel.js +0 -296
  286. package/core/com/param/drive.js +0 -366
  287. package/core/com/param/index.js +0 -80
  288. package/core/com/param/script.js +0 -12
  289. package/core/com/param/test.js +0 -98
  290. package/core/com/plugin/README.md +0 -3
  291. package/core/com/plugin/com.json +0 -4
  292. package/core/com/plugin/config.tpl.json +0 -26
  293. package/core/com/plugin/drive.js +0 -536
  294. package/core/com/plugin/index.js +0 -259
  295. package/core/com/plugin/script.js +0 -213
  296. package/core/com/rpc/com.json +0 -4
  297. package/core/com/rpc/drive.js +0 -160
  298. package/core/com/rpc/index.js +0 -87
  299. package/core/com/rpc/rpc.js +0 -118
  300. package/core/com/socket/com.json +0 -4
  301. package/core/com/socket/config.tpl.json +0 -14
  302. package/core/com/socket/drive.js +0 -403
  303. package/core/com/socket/index.js +0 -62
  304. package/core/com/socket/script.js +0 -42
  305. package/core/com/sql/drive.js +0 -1087
  306. package/core/com/sql/index.js +0 -83
  307. package/core/com/sql/script.js +0 -48
  308. package/core/com/static/com.json +0 -4
  309. package/core/com/static/drive.js +0 -220
  310. package/core/com/static/index.js +0 -149
  311. package/core/com/static/script.js +0 -28
  312. package/core/com/task/com.json +0 -4
  313. package/core/com/task/drive.js +0 -403
  314. package/core/com/task/index.js +0 -110
  315. package/core/com/task/script.js +0 -37
  316. package/core/com/timer/com.js +0 -217
  317. package/core/com/timer/com.json +0 -4
  318. package/core/com/tpl/com.js +0 -19
  319. package/core/com/tpl/com.json +0 -4
  320. package/lib/actions.js +0 -50
  321. package/lib/base.js +0 -361
  322. package/lib/com.js +0 -29
  323. package/lib/ref.js +0 -121
  324. package/middleware/cors/index.js +0 -119
  325. package/middleware/cors/middleware.json +0 -20
  326. package/middleware/csrf/index.js +0 -202
  327. package/middleware/csrf/middleware.json +0 -24
  328. package/middleware/ip_firewall/index.js +0 -476
  329. package/middleware/ip_firewall/middleware.json +0 -109
  330. package/middleware/mqtt_base/index.js +0 -10
  331. package/middleware/mqtt_base/middleware.json +0 -11
  332. package/middleware/security_audit/index.js +0 -543
  333. package/middleware/security_audit/middleware.json +0 -48
  334. package/middleware/waf/index.js +0 -343
  335. package/middleware/waf/middleware.json +0 -10
  336. package/middleware/waf_ddos/index.js +0 -520
  337. package/middleware/waf_ddos/middleware.json +0 -38
  338. package/middleware/waf_xss/index.js +0 -269
  339. package/middleware/waf_xss/middleware.json +0 -18
  340. package/middleware/web_after/index.js +0 -33
  341. package/middleware/web_after/middleware.json +0 -10
  342. package/middleware/web_base/index.js +0 -90
  343. package/middleware/web_base/middleware.json +0 -10
  344. package/middleware/web_before/index.js +0 -27
  345. package/middleware/web_before/middleware.json +0 -10
  346. package/middleware/web_check/index.js +0 -28
  347. package/middleware/web_check/middleware.json +0 -10
  348. package/middleware/web_main/index.js +0 -28
  349. package/middleware/web_main/middleware.json +0 -10
  350. package/middleware/web_proxy/index.js +0 -37
  351. package/middleware/web_proxy/middleware.json +0 -10
  352. package/middleware/web_render/index.js +0 -87
  353. package/middleware/web_render/middleware.json +0 -10
  354. package/middleware/web_socket/index.js +0 -34
  355. package/middleware/web_socket/middleware.json +0 -10
  356. package/middleware/web_static/index.js +0 -115
  357. package/middleware/web_static/middleware.json +0 -10
  358. /package/{core/com → com}/api/README.md +0 -0
  359. /package/{core/com → com}/db/README.md +0 -0
  360. /package/{core/com → com}/mqtt/README.md +0 -0
  361. /package/{core/com → com}/nav/README.md +0 -0
  362. /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
  363. /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
  364. /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
  365. /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
  366. /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
  367. /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
  368. /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
  369. /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
  370. /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
  371. /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
  372. /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
  373. /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
  374. /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
  375. /package/{core/com → com}/param/README.md +0 -0
  376. /package/{core/com/cmd → com/pendant}/README.md +0 -0
  377. /package/{core/com → com}/socket/README.md +0 -0
  378. /package/{core/com → com}/sql/README.md +0 -0
  379. /package/{core/com → com}/static/README.md +0 -0
  380. /package/{core/com → com}/task/README.md +0 -0
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "web_main",
3
+ "title": "请求主中间件",
4
+ "description": "用于处理请求主逻辑",
5
+ "main": "index.js",
6
+ "type": "web",
7
+ "state": 1,
8
+ "sort": 80
9
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * 增强的静态资源处理中间件
3
+ * 提供缓存控制、压缩、预加载等性能优化功能
4
+ */
5
+ const { statics } = require('mm_statics');
6
+
7
+ /**
8
+ * 静态资源请求
9
+ * @param {object} server 服务
10
+ * @param {object} config 配置参数
11
+ */
12
+ module.exports = {
13
+ /**
14
+ * 初始化
15
+ * @param {object} adapter 适配器集合
16
+ * @param {object} eventer 事件管理器
17
+ * @param {object} logger 日志管理器
18
+ */
19
+ init(adapter, eventer, logger) {
20
+ // 获取web服务
21
+ var web = adapter.web;
22
+ let config = web.config.static || {};
23
+ let cg = { ...this.config, ...config };
24
+ if (cg) {
25
+ this._setupMainStatic(web, cg);
26
+ this._setupMultiStatic(web, cg);
27
+ this._setupGlobalStatic(web);
28
+ } else {
29
+ console.log('未找到静态文件配置');
30
+ }
31
+ },
32
+ /**
33
+ * 设置主静态路径
34
+ * @private
35
+ * @param {object} web web服务
36
+ * @param {object} cg 配置
37
+ */
38
+ _setupMainStatic(web, cg) {
39
+ web.use(statics(cg));
40
+ },
41
+
42
+ /**
43
+ * 设置多静态路径
44
+ * @private
45
+ * @param {object} web web服务
46
+ * @param {object} cg 配置
47
+ */
48
+ _setupMultiStatic(web, cg) {
49
+ if (Array.isArray(cg.paths) && cg.paths.length > 0) {
50
+ for (let i = 0; i < cg.paths.length; i++) {
51
+ let path = cg.paths[i];
52
+ let config = { ...cg, root: path.fullname() };
53
+ web.use(statics(config));
54
+ }
55
+ }
56
+ },
57
+
58
+ /**
59
+ * 设置全局静态资源
60
+ * @private
61
+ * @param {object} web web服务
62
+ */
63
+ _setupGlobalStatic(web) {
64
+ if ($.admin.static) {
65
+ $.static = new $.admin.static();
66
+ $.static.call('update');
67
+
68
+ web.use(async (ctx, next) => {
69
+ await $.static.run(ctx, next);
70
+ });
71
+ }
72
+ }
73
+ };
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "web_static",
3
+ "title": "web静态文件处理",
4
+ "description": "用于处理静态文件",
5
+ "version": "1.0",
6
+ "main": "./index.js",
7
+ "type": "web",
8
+ "state": 1,
9
+ "sort": 90,
10
+ // 是否启用静态文件处理
11
+ "static": true,
12
+ // 默认首页文件
13
+ "index": "index.html",
14
+ // 缓存键前缀
15
+ "key_prefix": "static:",
16
+ // 前端缓存时间,单位秒
17
+ "max_age": 7200,
18
+ // 是否开启缓存
19
+ "cache": true,
20
+ // 后端缓存时间,单位秒
21
+ "cache_age": 31536000,
22
+ // 是否开启immutable缓存
23
+ "immutable": true,
24
+ // 是否开启隐藏文件处理
25
+ "hidden": false,
26
+ // 是否格式化文件
27
+ "format": true,
28
+ // 是否指定文件扩展名
29
+ "extensions": false,
30
+ // 是否开启brotli压缩
31
+ "brotli": false,
32
+ // 是否开启gzip压缩
33
+ "gzip": false,
34
+ // 静态文件根目录
35
+ "root": "./static",
36
+ // 编译vue文件,启动后会将vue转为js,可让前端通过 import xxx from './xxx.vue' 引入
37
+ "compile_vue": true,
38
+ // 编译markdown文件,启动后会将markdown转为html
39
+ "compile_md": true,
40
+ // 是否将files中的文件的js转换为amd格式
41
+ "convert_amd": false,
42
+ // 指定路径文件需要转换
43
+ "src_path": "/src",
44
+ // 监听路由路径
45
+ "path": "/",
46
+ // 需要转换的文件扩展名
47
+ "files": [
48
+ ".js",
49
+ ".vue",
50
+ ".html"
51
+ ],
52
+ // 是否启用文件修改监听(实时检测文件修改)
53
+ "watch": true
54
+ }
@@ -0,0 +1,385 @@
1
+ const { Ip } = require('mm_ip');
2
+
3
+ /**
4
+ * web防火墙
5
+ */
6
+ module.exports = {
7
+ /**
8
+ * 初始化
9
+ * @param {object} adapter 适配器集合
10
+ */
11
+ init(adapter) {
12
+ // 获取web服务
13
+ var web = adapter.web;
14
+
15
+ // 获取配置
16
+ let cg = { ...this.config, ...adapter.web.config };
17
+
18
+ // 初始化全局IP管理器
19
+ this._initIpManager(cg);
20
+
21
+ // 设置WAF中间件
22
+ let self = this;
23
+ web.use(async (ctx, next) => {
24
+ let waf_check_ret = await self._handleWafCheck(ctx, cg);
25
+ if (waf_check_ret) {
26
+ await next();
27
+ }
28
+ });
29
+ },
30
+
31
+ /**
32
+ * 初始化IP管理器
33
+ * @private
34
+ * @param {object} config 配置对象
35
+ */
36
+ _initIpManager(config) {
37
+ // 确保全局IP管理器存在
38
+ if (!$.ip || ($.ip && !$.is_plugin)) {
39
+ $.ip = new Ip();
40
+ $.is_plugin = true;
41
+ }
42
+
43
+ // 配置IP管理器
44
+ if (config && config.web) {
45
+ let ipConfig = {
46
+ auto_black_enable: config.web.auto_black_enable !== false,
47
+ max_req_per_min: config.web.max_req_per_min || 100,
48
+ auto_black_limit: config.web.auto_black_threshold || 50
49
+ };
50
+ $.ip.setConfig(ipConfig);
51
+ }
52
+ },
53
+
54
+ /**
55
+ * 处理WAF检查
56
+ * @private
57
+ * @param {object} ctx 上下文
58
+ * @param {object} cg 配置
59
+ * @returns {boolean} 是否通过检查
60
+ */
61
+ async _handleWafCheck(ctx, cg) {
62
+ // 获取客户端IP
63
+ var ip = this._getClientIp(ctx.req);
64
+
65
+ // 获取请求路径
66
+ let path = ctx.path;
67
+
68
+ // 检查路径是否在白名单中
69
+ if (this.isPathWhiteListed(path, cg)) {
70
+ return true;
71
+ }
72
+
73
+ // 使用mm_ip进行IP检查和频率限制
74
+ if (!this._checkIpAccess(ip)) {
75
+ this._sendWafResponse(ctx, 403, '访问被WAF阻止,IP访问受限');
76
+ return false;
77
+ }
78
+
79
+ // 检查基本攻击特征
80
+ let danger = this.wafCheck(ctx.url);
81
+ if (danger) {
82
+ this._sendWafResponse(ctx, 403, '访问被WAF阻止,请求包含潜在的攻击特征', danger.toString());
83
+ return false;
84
+ }
85
+
86
+ // 检查路径遍历攻击
87
+ let path_trav_ret = this._checkPathTrav(ctx);
88
+ if (path_trav_ret) {
89
+ this._sendWafResponse(ctx, 403, '访问被WAF阻止,检测到路径遍历攻击尝试');
90
+ return false;
91
+ }
92
+ return true;
93
+ },
94
+
95
+ /**
96
+ * 检查IP访问权限
97
+ * @private
98
+ * @param {string} ip IP地址
99
+ * @returns {boolean} 是否允许访问
100
+ */
101
+ _checkIpAccess(ip) {
102
+ return true;
103
+ try {
104
+ // 使用mm_ip的record方法进行综合检查(包含白名单、黑名单、频率限制)
105
+ return $.ip.record(ip);
106
+ } catch {
107
+ // 如果mm_ip不可用,使用备用方案
108
+ this.log('warn', 'mm_ip不可用,使用备用IP检查');
109
+
110
+ // 备用方案:检查本地白名单
111
+ const LOCAL_WHITE_LIST = ['127.0.0.1', '::1', 'localhost'];
112
+ return LOCAL_WHITE_LIST.includes(ip);
113
+ }
114
+ },
115
+
116
+ /**
117
+ * 获取客户端IP
118
+ * @private
119
+ * @param {object} req 请求对象
120
+ * @returns {string} 客户端IP
121
+ */
122
+ _getClientIp(req) {
123
+ // 标准IP获取逻辑
124
+ return req.headers['x-forwarded-for'] || req.headers['X-Forwarded-For'] ||
125
+ req.connection.remoteAddress ||
126
+ req.socket.remoteAddress ||
127
+ req.connection.socket.remoteAddress;
128
+ },
129
+
130
+ /**
131
+ * 检查路径遍历攻击
132
+ * @private
133
+ * @param {object} ctx 上下文
134
+ * @returns {string|boolean} 检测到的攻击类型或false
135
+ */
136
+ _checkPathTrav(ctx) {
137
+ var path = ctx.path;
138
+
139
+ // 检查路径本身
140
+ if (this.checkPathTrav(path)) {
141
+ return '路径本身包含攻击特征: ' + path;
142
+ }
143
+ if (!this.isSafePath(path)) {
144
+ return '路径不安全: ' + path;
145
+ }
146
+
147
+ // 检查请求参数
148
+ var query_params = ctx.query;
149
+ for (var k in query_params) {
150
+ var val = query_params[k];
151
+ if (typeof val === 'string' && this.checkPathTrav(val)) {
152
+ return '查询参数包含攻击特征: ' + k + '=' + val;
153
+ }
154
+ }
155
+
156
+ // 检查POST请求体
157
+ if (ctx.method === 'POST' && ctx.request.body) {
158
+ var body_content = JSON.stringify(ctx.request.body);
159
+ if (this.checkPathTrav(body_content)) {
160
+ return '请求体包含攻击特征';
161
+ }
162
+ }
163
+
164
+ return false;
165
+ },
166
+
167
+ /**
168
+ * 发送WAF响应
169
+ * @private
170
+ * @param {object} ctx 上下文
171
+ * @param {number} status 状态码
172
+ * @param {string} msg 消息
173
+ * @param {string} [rule] 规则
174
+ */
175
+ _sendWafResponse(ctx, status, msg, rule) {
176
+ ctx.status = status;
177
+ ctx.body = {
178
+ code: status,
179
+ msg: msg,
180
+ rule: rule
181
+ };
182
+ },
183
+
184
+ /**
185
+ * 获取SQL注入检测规则
186
+ * @private
187
+ * @returns {RegExp[]} SQL注入规则列表
188
+ */
189
+ _getSqlRules() {
190
+ return [
191
+ /select.+(from|limit)/i,
192
+ /(?:(union(.*?)select))/i,
193
+ /sleep\((\s*)(\d*)(\s*)\)/i,
194
+ /group\s+by.+\(/i,
195
+ /(?:from\W+information_schema\W)/i,
196
+ /(?:(?:current_)user|database|schema|connection_id)\s*\(/i,
197
+ /\s*or\s+.*=.*/i,
198
+ /order\s+by\s+.*--$/i,
199
+ /benchmark\((.*)\,(.*)\)/i,
200
+ /base64_decode\(/i,
201
+ /(?:(?:current_)user|database|version|schema|connection_id)\s*\(/i,
202
+ /(?:etc\/\W*passwd)/i,
203
+ /into(\s+)+(?:dump|out)file\s*/i
204
+ ];
205
+ },
206
+
207
+ /**
208
+ * 获取代码注入和XSS检测规则
209
+ * @private
210
+ * @returns {RegExp[]} 代码注入和XSS规则列表
211
+ */
212
+ _getCodeInjectRules() {
213
+ return [
214
+ /xwork.MethodAccessor/i,
215
+ /(?:define|eval|file_get_contents|include|require|require_once)\(/i,
216
+ /(?:shell_exec|phpinfo|system|passthru|preg_\w+|execute)\(/i,
217
+ /(?:echo|print|print_r|var_dump|(fp)open|alert|showmodaldialog)\(/i,
218
+ /\<(iframe|script|body|img|layer|div|meta|style|base|object|input)/i,
219
+ /(onmouseover|onmousemove|onerror|onload)\=/i,
220
+ /javascript:/i
221
+ ];
222
+ },
223
+
224
+ /**
225
+ * 获取路径遍历检测规则
226
+ * @private
227
+ * @returns {RegExp[]} 路径遍历规则列表
228
+ */
229
+ _getPathTravRules() {
230
+ return [
231
+ // 增强的路径遍历检测规则
232
+ /\.\.\//i, // 基础 ../
233
+ /\.\.\\/i, // Windows格式 ..\
234
+ /\%2e\%2e\//i, // URL编码 ../
235
+ /\%2e%2e\//i, // URL编码 ../
236
+ /\%252e%252e%2f/i, // 双重URL编码 ../
237
+ /\%252e\%252e\%2f/i, // 双重URL编码 ../
238
+ /\.\%2e\//i, // 混合编码
239
+ /\%2e\./i, // 变体形式
240
+ /\%5c/i, // 反斜杠URL编码
241
+ /\%255c/i, // 反斜杠双重URL编码
242
+ // 系统文件路径检测 - 改进以避免误判
243
+ new RegExp('(?:\\/etc\\/|\\/proc\\/|C:\\\\Windows\\|' +
244
+ 'C:\\\\winnt\\|C:\\\\Program Files\\|\\/sys\\/)', 'i')
245
+ ];
246
+ },
247
+
248
+ /**
249
+ * 获取命令注入检测规则
250
+ * @private
251
+ * @returns {RegExp[]} 命令注入规则列表
252
+ */
253
+ _getCmdInjectRules() {
254
+ return [
255
+ // 命令注入检测
256
+ new RegExp('\\|\\|.*(?:ls|pwd|whoami|ll|ifconfog|' +
257
+ 'ipconfig|&&|chmod|cd|mkdir|rmdir|cp|mv)', 'i'),
258
+ new RegExp('(?:ls|pwd|whoami|ll|ifconfog|ipconfig|' +
259
+ '&&|chmod|cd|mkdir|rmdir|cp|mv).*\\|\\|', 'i'),
260
+ new RegExp('(gopher|doc|php|glob|file|phar|zlib|ftp|' +
261
+ 'ldap|dict|ogg|data)\\:\/', 'i')
262
+ ];
263
+ },
264
+
265
+ /**
266
+ * 获取WAF规则列表
267
+ * @private
268
+ * @returns {RegExp[]} WAF规则列表
269
+ */
270
+ _getWafRules() {
271
+ return [
272
+ ...this._getSqlRules(),
273
+ ...this._getCodeInjectRules(),
274
+ ...this._getPathTravRules(),
275
+ ...this._getCmdInjectRules()
276
+ ];
277
+ },
278
+
279
+ /**
280
+ * 使用正则表达式,检测字符串是否含有攻击特征,检测到攻击特征返回true,没检测到返回false
281
+ * @param {string} url 网址
282
+ * @returns {RegExp|null} 检测到的攻击规则或null
283
+ */
284
+ wafCheck(url) {
285
+ var rules = this._getWafRules();
286
+ for (var i = 0; i < rules.length; i++) {
287
+ if (rules[i].test(url)) {
288
+ return rules[i];
289
+ }
290
+ }
291
+ return null;
292
+ },
293
+
294
+ /**
295
+ * 检查路径是否包含路径遍历攻击
296
+ * @param {string} path 路径
297
+ * @returns {boolean} 是否包含路径遍历
298
+ */
299
+ checkPathTrav(path) {
300
+ // 处理URL编码变体
301
+ let url_decoded = decodeURIComponent(path);
302
+ let double_url_decoded = decodeURIComponent(url_decoded);
303
+
304
+ // 检查路径是否包含危险模式
305
+ let danger_patterns = [
306
+ '../', '../../', '../../../', // Unix/Linux格式
307
+ '..\\', '..\\\\', '..\\\\\\\\', // Windows格式
308
+ '/%2e%2e/', '/%2e%2e%2f', // URL编码变体
309
+ '\\%2e%2e\\', '\\%2e%2e\\\\' // Windows URL编码变体
310
+ ];
311
+
312
+ // 检查系统关键文件路径(绝对路径攻击)
313
+ let sys_paths = [
314
+ '/etc/passwd', '/etc/shadow', '/etc/group', '/etc/hosts',
315
+ '/proc/', '/bin/', '/usr/bin/',
316
+ 'C:\\Windows\\', 'C:\\winnt\\', 'C:\\Program Files\\'
317
+ ];
318
+
319
+ // 检查原始路径、单次解码和双重解码后的路径
320
+ // 1. 检查相对路径遍历模式
321
+ let has_trav_pattern = danger_patterns.some(pattern =>
322
+ path.includes(pattern) ||
323
+ url_decoded.includes(pattern) ||
324
+ double_url_decoded.includes(pattern)
325
+ );
326
+
327
+ // 2. 检查绝对路径攻击(包含系统关键文件路径)
328
+ let has_abs_attack = sys_paths.some(sys_path =>
329
+ path.toLowerCase().includes(sys_path.toLowerCase()) ||
330
+ url_decoded.toLowerCase().includes(sys_path.toLowerCase()) ||
331
+ double_url_decoded.toLowerCase().includes(sys_path.toLowerCase())
332
+ );
333
+
334
+ return has_trav_pattern || has_abs_attack; // 移除starts_with_slash检查
335
+ },
336
+
337
+ /**
338
+ * 检查请求路径是否规范化,防止路径遍历攻击
339
+ * @param {string} path 请求路径
340
+ * @returns {boolean} 是否为安全路径
341
+ */
342
+ isSafePath(path) {
343
+ // 特殊处理根路径,直接返回安全
344
+ if (path === '/') {
345
+ return true;
346
+ }
347
+
348
+ // 获取规范化的路径
349
+ let norm_path = path.split('/')
350
+ .filter(segment => segment !== '')
351
+ .reduce((acc, segment) => {
352
+ // 防止路径回溯
353
+ if (segment === '..') {
354
+ acc.pop();
355
+ } else if (segment !== '.') {
356
+ acc.push(segment);
357
+ }
358
+ return acc;
359
+ }, [])
360
+ .join('/');
361
+
362
+ // 重新构建规范化的完整路径
363
+ let safe_path = '/' + norm_path;
364
+
365
+ // 检查规范化后的路径长度是否小于原始路径(表示存在路径回溯)
366
+ return safe_path.length >= path.length - 2; // 允许末尾的 '/' 差异
367
+ },
368
+
369
+ /**
370
+ * 检查路径是否在白名单中
371
+ * @param {string} path 请求路径
372
+ * @param {object} config WAF配置
373
+ * @returns {boolean} 是否在白名单中
374
+ */
375
+ isPathWhiteListed(path, config) {
376
+ // 获取配置中的路径白名单
377
+ let path_white_list = (config && config.web && config.web.path_whitelist)
378
+ || (config && config.path_whitelist)
379
+ || ['/static', '/favicon.ico', '/api', '/public', '/assets'];
380
+
381
+ // 检查路径是否以白名单中的任何路径开头
382
+ return Array.isArray(path_white_list) &&
383
+ path_white_list.some(white_path => path.startsWith(white_path));
384
+ }
385
+ };
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "web_waf",
3
+ "title": "web防火墙",
4
+ "description": "用于防止sql注入、脚本注入等",
5
+ "version": "1.0",
6
+ "main": "index.js",
7
+ "type": "web",
8
+ "state": 1,
9
+ "sort": 50,
10
+ "log": true,
11
+ "ip_whitelist": ["127.0.0.1", "::1", "localhost"],
12
+ "path_whitelist": ["/favicon.ico", "/static", "/api", "/public", "/assets"]
13
+ }
@@ -0,0 +1,88 @@
1
+ if (!$.const) {
2
+ $.const = {};
3
+ }
4
+ if ($.const) {
5
+ /**
6
+ * 消息类型枚举
7
+ */
8
+ const MESSAGE_TYPES = {
9
+ // 内容消息类
10
+ TEXT: 'text',
11
+ IMAGE: 'image',
12
+ VOICE: 'voice',
13
+ VIDEO: 'video',
14
+ FILE: 'file',
15
+
16
+ // 交互消息类
17
+ EVENT: 'event',
18
+ NOTICE: 'notice',
19
+ CARD: 'card',
20
+ LIST: 'list',
21
+
22
+ // 业务消息类
23
+ CHAT: 'chat',
24
+ MAIL: 'mail',
25
+ TRADE: 'trade'
26
+ };
27
+ $.const.MESSAGE_TYPES = MESSAGE_TYPES;
28
+
29
+ /**
30
+ * 事件类型枚举
31
+ */
32
+ const EVENT_TYPES = {
33
+ // 游戏事件
34
+ COMBAT: 'combat',
35
+ QUEST: 'quest',
36
+ LEVEL: 'level',
37
+ ACHIEVEMENT: 'achievement',
38
+
39
+ // 社交事件
40
+ FRIEND: 'friend',
41
+ GUILD: 'guild',
42
+ TEAM: 'team',
43
+ INVITE: 'invite',
44
+
45
+ // 系统事件
46
+ LOGIN: 'login',
47
+ LOGOUT: 'logout',
48
+ REWARD: 'reward',
49
+ ACTIVITY: 'activity'
50
+ };
51
+ $.const.EVENT_TYPES = EVENT_TYPES;
52
+
53
+ /**
54
+ * 消息分组枚举
55
+ */
56
+ const MESSAGE_GROUPS = {
57
+ PRIVATE: 'private',
58
+ CHANNEL: 'channel',
59
+ WORLD: 'world',
60
+ GUILD: 'guild',
61
+ SYSTEM: 'system'
62
+ };
63
+ $.const.MESSAGE_GROUPS = MESSAGE_GROUPS;
64
+
65
+ /**
66
+ * 消息优先级枚举
67
+ */
68
+ const PRIORITIES = {
69
+ LOW: 'low',
70
+ NORMAL: 'normal',
71
+ HIGH: 'high',
72
+ URGENT: 'urgent'
73
+ };
74
+ $.const.PRIORITIES = PRIORITIES;
75
+ }
76
+
77
+ /**
78
+ * 消息模型
79
+ */
80
+ module.exports = {
81
+ /**
82
+ * 添加消息模型方法
83
+ * @param {object} model 消息模型实例
84
+ */
85
+ addMethods(model) {
86
+
87
+ }
88
+ };