mm_os 3.3.1 → 4.0.0

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 +491 -99
  3. package/README_EN.md +498 -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 +58 -58
  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
package/lib/ref.js DELETED
@@ -1,121 +0,0 @@
1
- const {
2
- types
3
- } = require("util");
4
-
5
- /**
6
- * 行为器
7
- */
8
- class Ref {
9
- /**
10
- * 构造函数
11
- * @param {Object} obj 对象
12
- */
13
- constructor(obj) {
14
- this.msg = [];
15
- this._init(obj);
16
- }
17
- }
18
-
19
- /**
20
- * 初始化
21
- * @param {Object} config 配置参数
22
- * @returns {Object} 执行结果
23
- */
24
- Ref.prototype._init = function(obj) {
25
- Object.assign(this, obj);
26
- this.data = this.data || {};
27
- this.methods = this.methods || {};
28
- return this;
29
- }
30
-
31
- /**
32
- * 运行当前类函数
33
- * @param {String} name 函数名
34
- * @param {Object} args 参数集合
35
- * @returns {Object} 执行结果
36
- */
37
- Ref.prototype.run = async function(name, ...args) {
38
- var ret;
39
- var key = name + "_before";
40
- if (this[key]) {
41
- ret = this[key](...args);
42
- if (types.isPromise(ret)) {
43
- ret = await ret
44
- }
45
- }
46
- key = name + "_check";
47
- if (this[key]) {
48
- ret = this[key](...args);
49
- if (types.isPromise(ret)) {
50
- ret = await ret
51
- }
52
- if (ret) {
53
- return ret;
54
- }
55
- }
56
-
57
- if (this[name]) {
58
- ret = this[name](...args);
59
- if (types.isPromise(ret)) {
60
- ret = await ret
61
- }
62
- if (ret) {
63
- key = name + "_after";
64
- if (this[key]) {
65
- ret = this[key](...args);
66
- if (types.isPromise(ret)) {
67
- ret = await ret
68
- }
69
- }
70
- }
71
- }
72
- return ret;
73
- }
74
-
75
- /**
76
- * 执行子脚本函数
77
- * @param {String} name 名称
78
- * @param {String} func_name 执行方法
79
- * @param {Object} args 参数集合
80
- * @returns {Object} 返回执行结果
81
- */
82
- Ref.prototype.exec = async function(name, func_name, ...args) {
83
- var cs = this.dict[name];
84
- var ret;
85
- var key = func_name + "_before";
86
- if (cs[key]) {
87
- ret = cs[key](...args);
88
- if (types.isPromise(ret)) {
89
- ret = await ret
90
- }
91
- }
92
- key = func_name + "_check";
93
- if (cs[key]) {
94
- ret = cs[key](...args);
95
- if (types.isPromise(ret)) {
96
- ret = await ret
97
- }
98
- if (ret) {
99
- return ret;
100
- }
101
- }
102
-
103
- if (cs[func_name]) {
104
- ret = cs[func_name](...args);
105
- if (types.isPromise(ret)) {
106
- ret = await ret
107
- }
108
- if (ret) {
109
- key = func_name + "_after";
110
- if (cs[key]) {
111
- ret = cs[key](...args);
112
- if (types.isPromise(ret)) {
113
- ret = await ret
114
- }
115
- }
116
- }
117
- }
118
- return ret;
119
- }
120
-
121
- module.exports = Ref;
@@ -1,119 +0,0 @@
1
- /**
2
- * CORS跨域中间件
3
- * 处理跨域资源共享(CORS)配置
4
- */
5
- class CorsMiddleware {
6
- constructor() {
7
- this.default = {
8
- // 启用CORS
9
- enable: true,
10
- // 允许的源
11
- origin: '*',
12
- // 允许的请求头
13
- headers: '*',
14
- // 允许的HTTP方法
15
- methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD'],
16
- // 允许携带凭证
17
- credentials: false,
18
- // 预检请求的有效期(秒)
19
- max_age: 3600,
20
- // 暴露的响应头
21
- expose_headers: [],
22
- // 忽略的路径
23
- ignore_paths: []
24
- };
25
- }
26
- }
27
-
28
- CorsMiddleware.prototype.init = function(config) {
29
- this.config = Object.assign({}, this.default, config || {});
30
- return this;
31
- };
32
-
33
- CorsMiddleware.prototype.run = async function(ctx, next) {
34
- const config = this.config;
35
-
36
- if (!config.enable) {
37
- return await next();
38
- }
39
-
40
- // 检查是否应该忽略该路径
41
- const path = ctx.path;
42
- if (config.ignore_paths.some(p => path.startsWith(p))) {
43
- return await next();
44
- }
45
-
46
- // 设置CORS头
47
- this._setCorsHeaders(ctx, config);
48
-
49
- // 处理预检请求
50
- if (ctx.method === 'OPTIONS') {
51
- ctx.status = 204;
52
- return;
53
- }
54
-
55
- await next();
56
- };
57
-
58
- CorsMiddleware.prototype._setCorsHeaders = function(ctx, config) {
59
- // 设置Access-Control-Allow-Origin
60
- if (config.origin === '*') {
61
- ctx.set('Access-Control-Allow-Origin', '*');
62
- } else if (Array.isArray(config.origin)) {
63
- const requestOrigin = ctx.get('Origin');
64
- if (config.origin.includes(requestOrigin)) {
65
- ctx.set('Access-Control-Allow-Origin', requestOrigin);
66
- }
67
- } else {
68
- ctx.set('Access-Control-Allow-Origin', config.origin);
69
- }
70
-
71
- // 设置Access-Control-Allow-Headers
72
- if (config.headers === '*') {
73
- ctx.set('Access-Control-Allow-Headers', '*');
74
- } else if (Array.isArray(config.headers)) {
75
- ctx.set('Access-Control-Allow-Headers', config.headers.join(', '));
76
- } else {
77
- ctx.set('Access-Control-Allow-Headers', config.headers);
78
- }
79
-
80
- // 设置Access-Control-Allow-Methods
81
- ctx.set('Access-Control-Allow-Methods', config.methods.join(', '));
82
-
83
- // 设置Access-Control-Allow-Credentials
84
- if (config.credentials) {
85
- ctx.set('Access-Control-Allow-Credentials', 'true');
86
- }
87
-
88
- // 设置Access-Control-Max-Age
89
- if (config.max_age > 0) {
90
- ctx.set('Access-Control-Max-Age', config.max_age.toString());
91
- }
92
-
93
- // 设置Access-Control-Expose-Headers
94
- if (config.expose_headers.length > 0) {
95
- ctx.set('Access-Control-Expose-Headers', config.expose_headers.join(', '));
96
- }
97
- };
98
-
99
- // 创建中间件实例
100
- const middleware = new CorsMiddleware();
101
-
102
- // 导出符合系统期望的函数
103
- exports = module.exports = function(server, config) {
104
- // 初始化中间件
105
- middleware.init(config);
106
-
107
- // 注册中间件到服务器
108
- server.use(middleware.run.bind(middleware));
109
-
110
- // 记录中间件初始化信息
111
- if ($.log && $.log.info) {
112
- $.log.info(`CORS中间件已加载: 启用=${middleware.config.enable}, 源=${middleware.config.origin}`);
113
- }
114
-
115
- return server;
116
- };
117
-
118
- // 保留原始实例,以便其他方式调用
119
- exports.middleware = middleware;
@@ -1,20 +0,0 @@
1
- {
2
- "name": "cors",
3
- "title": "CORS跨域中间件",
4
- "description": "处理跨域资源共享(CORS)配置,支持灵活的跨域策略",
5
- "version": "1.0",
6
- "type": "web",
7
- "process_type": "common_before",
8
- "sort": 15,
9
- "state": 1,
10
- "config": {
11
- "enable": true,
12
- "origin": "*",
13
- "headers": "*",
14
- "methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD"],
15
- "credentials": false,
16
- "max_age": 3600,
17
- "expose_headers": [],
18
- "ignore_paths": []
19
- }
20
- }
@@ -1,202 +0,0 @@
1
- /**
2
- * CSRF保护中间件
3
- * 防止跨站请求伪造攻击
4
- */
5
- class CsrfMiddleware {
6
- constructor() {
7
- this.default = {
8
- // 启用CSRF保护
9
- enable: true,
10
- // CSRF令牌的Cookie名称
11
- cookie_name: 'csrf_token',
12
- // CSRF令牌的请求头名称
13
- header_name: 'X-CSRF-Token',
14
- // CSRF令牌的表单字段名称
15
- form_field: '_csrf',
16
- // CSRF令牌的过期时间(毫秒)
17
- max_age: 3600000, // 1小时
18
- // 忽略的HTTP方法
19
- ignore_methods: ['GET', 'HEAD', 'OPTIONS'],
20
- // 忽略的路径
21
- ignore_paths: [],
22
- // 是否生成新的令牌
23
- generate_new: true,
24
- // 是否验证来源
25
- check_origin: true,
26
- // 是否记录CSRF攻击尝试
27
- log: true,
28
- // 是否阻止恶意请求
29
- block: true,
30
- // 允许的来源域名
31
- allowed_origins: []
32
- };
33
- }
34
- }
35
-
36
- CsrfMiddleware.prototype.init = function(config) {
37
- this.config = Object.assign({}, this.default, config || {});
38
- return this;
39
- };
40
-
41
- CsrfMiddleware.prototype.run = async function(ctx, next) {
42
- const config = this.config;
43
-
44
- if (!config.enable) {
45
- return await next();
46
- }
47
-
48
- // 生成CSRF令牌
49
- const token = await this._generateToken(ctx);
50
-
51
- // 将令牌添加到上下文,供模板使用
52
- ctx.state.csrf = token;
53
-
54
- // 检查是否需要验证CSRF
55
- if (!this._shouldSkipCsrfValidation(ctx, config)) {
56
- // 验证来源
57
- if (config.check_origin && !this._validateOrigin(ctx, config)) {
58
- if (config.block) {
59
- ctx.status = 403;
60
- ctx.body = {
61
- code: 403,
62
- msg: 'Forbidden: Invalid request origin'
63
- };
64
- return;
65
- }
66
- }
67
-
68
- // 验证CSRF令牌
69
- if (!this._validateToken(ctx, config)) {
70
- if (config.block) {
71
- ctx.status = 403;
72
- ctx.body = {
73
- code: 403,
74
- msg: 'Forbidden: Invalid CSRF token'
75
- };
76
- return;
77
- }
78
- }
79
-
80
- // 如果需要生成新令牌
81
- if (config.generate_new) {
82
- await this._setNewToken(ctx, config);
83
- }
84
- }
85
-
86
- await next();
87
- };
88
-
89
- CsrfMiddleware.prototype._generateToken = async function(ctx) {
90
- let token = ctx.cookies.get(this.config.cookie_name);
91
-
92
- // 如果没有令牌或需要生成新令牌,则创建一个新的
93
- if (!token || this.config.generate_new) {
94
- await this._setNewToken(ctx, this.config);
95
- token = ctx.cookies.get(this.config.cookie_name);
96
- }
97
-
98
- return token;
99
- };
100
-
101
- CsrfMiddleware.prototype._setNewToken = async function(ctx, config) {
102
- // 生成随机令牌
103
- const token = this._createRandomToken();
104
-
105
- // 将令牌存储到Cookie
106
- ctx.cookies.set(config.cookie_name, token, {
107
- httpOnly: false, // CSRF令牌需要从前端读取,所以不能设置httpOnly
108
- maxAge: config.max_age,
109
- sameSite: 'lax'
110
- });
111
- };
112
-
113
- CsrfMiddleware.prototype._createRandomToken = function() {
114
- return Math.random().toString(36).substring(2) +
115
- Math.random().toString(36).substring(2) +
116
- Math.random().toString(36).substring(2);
117
- };
118
-
119
- CsrfMiddleware.prototype._shouldSkipCsrfValidation = function(ctx, config) {
120
- const method = ctx.method;
121
- const path = ctx.path;
122
-
123
- // 检查是否在忽略的方法列表中
124
- if (config.ignore_methods.includes(method)) {
125
- return true;
126
- }
127
-
128
- // 检查是否在忽略的路径列表中
129
- if (config.ignore_paths.some(p => path.startsWith(p))) {
130
- return true;
131
- }
132
-
133
- return false;
134
- };
135
-
136
- CsrfMiddleware.prototype._validateOrigin = function(ctx, config) {
137
- const origin = ctx.get('Origin');
138
- const host = ctx.get('Host');
139
-
140
- // 如果没有Origin头,可能是同源请求
141
- if (!origin) {
142
- return true;
143
- }
144
-
145
- // 检查是否在允许的来源列表中
146
- if (config.allowed_origins.length > 0) {
147
- return config.allowed_origins.includes(origin);
148
- }
149
-
150
- // 默认情况下,只允许同源请求
151
- return origin.includes(host);
152
- };
153
-
154
- CsrfMiddleware.prototype._validateToken = function(ctx, config) {
155
- const tokenFromCookie = ctx.cookies.get(config.cookie_name);
156
-
157
- // 从请求头获取令牌
158
- const tokenFromHeader = ctx.get(config.header_name);
159
-
160
- // 从请求体获取令牌
161
- let tokenFromBody = null;
162
- if (ctx.request.body && ctx.request.body[config.form_field]) {
163
- tokenFromBody = ctx.request.body[config.form_field];
164
- }
165
-
166
- // 从查询参数获取令牌
167
- const tokenFromQuery = ctx.query[config.form_field];
168
-
169
- // 检查令牌是否匹配
170
- const receivedToken = tokenFromHeader || tokenFromBody || tokenFromQuery;
171
-
172
- if (!receivedToken || !tokenFromCookie) {
173
- return false;
174
- }
175
-
176
- return receivedToken === tokenFromCookie;
177
- };
178
-
179
- // 创建中间件实例
180
- const middleware = new CsrfMiddleware();
181
-
182
- // 导出符合系统期望的函数
183
- exports = module.exports = function(server, config) {
184
- // 获取当前中间件的配置(从middleware.json加载的配置)
185
- var middleware_config = this && this.config ? this.config : config;
186
-
187
- // 初始化中间件
188
- middleware.init(middleware_config);
189
-
190
- // 注册中间件到服务器
191
- server.use(middleware.run.bind(middleware));
192
-
193
- // 记录中间件初始化信息
194
- if ($.log && $.log.info) {
195
- $.log.info(`CSRF中间件已加载: 启用=${middleware.config.enable}, 忽略路径=${middleware.config.ignore_paths.length}`);
196
- }
197
-
198
- return server;
199
- };
200
-
201
- // 保留原始实例,以便其他方式调用
202
- exports.middleware = middleware;
@@ -1,24 +0,0 @@
1
- {
2
- "name": "csrf",
3
- "title": "CSRF保护中间件",
4
- "description": "防止跨站请求伪造攻击,提供安全的令牌验证机制",
5
- "version": "1.0",
6
- "type": "web",
7
- "process_type": "common_before",
8
- "sort": 20,
9
- "state": 1,
10
- "config": {
11
- "enable": true,
12
- "cookie_name": "csrf_token",
13
- "header_name": "X-CSRF-Token",
14
- "form_field": "_csrf",
15
- "max_age": 3600000,
16
- "ignore_methods": ["GET", "HEAD", "OPTIONS"],
17
- "ignore_paths": ["/api/user/sign_in", "/user/login", "/login", "/admin/login"],
18
- "generate_new": true,
19
- "check_origin": true,
20
- "log": true,
21
- "block": true,
22
- "allowed_origins": []
23
- }
24
- }