crabatool 1.0.281 → 1.0.282

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/hash.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "http://crabadoc.ca.com/js/utils/utils.js": "sha384-yqLsT1eKgMFhyGpdBnVBHom80H3rQ4iCLbg9kAmJ2zuJCF6oCxj1najJz5KPnRS/",
3
+ "F:/newcrabadoc/www/js/utils/utils.js": "sha384-yqLsT1eKgMFhyGpdBnVBHom80H3rQ4iCLbg9kAmJ2zuJCF6oCxj1najJz5KPnRS/",
4
+ "./test/test.js": "sha384-VQy3WyY/3vG+HckZphZEXGAZGOVP/NhqD8fx6wBjMPtfIaX5dUjMOxR+F23VhxAw",
5
+ "./test/beefun.js": "sha384-pkh4Pn8P8Bt2R3KEeN7N2WBZHd7xFWCD8fY2LuCdypHQv1DXLG538f1Jr+pCyJcM",
6
+ "https://s5.vip.wpscdn.cn/web-libs/2t/js/userinfo-collect/1.0.3/vas2t-userinfo-collect.min.js": "sha384-2Un6NCB1ePpHBqkNtvTjXtHbxHbwcNV/f72LUUSB7ysPpPkauvVsVTs61wW7cKq2"
7
+ }
package/index.js CHANGED
@@ -110,5 +110,13 @@ function checkFast(args) {
110
110
  }
111
111
 
112
112
 
113
+ if (args.includes('-makeHash')) {
114
+ start.bindAndCheckConfig('-files');
115
+ start.bindAndCheckConfig('-outJson');
116
+ require('./tool/hash.js').start(); // wps安全改造,工具生成js和css的hash值
117
+ return false;
118
+ }
119
+
120
+
113
121
  return true;
114
122
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crabatool",
3
- "version": "1.0.281",
3
+ "version": "1.0.282",
4
4
  "description": "crabatool",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -16,7 +16,8 @@
16
16
  "checkUpdate": "node run.js -checkUpdate -version master -webPath F:\\crabaevery\\www",
17
17
  "upload": "node run.js -upload -version master -Debug true -host http://127.0.0.1:9998 -hidejspath true -targetPath F:\\CarpaNET_NEW",
18
18
  "crabaNgp": "node run.js -mergejs -hidejspath true -targetPath F:\\CarpaNET_NEW\\src\\Carpa.Web\\js\\crabaNgp -inNames initMs.js,businessControl.js -outName F:\\CarpaMS\\src\\js\\crabaNgp.js",
19
- "webPath": "node ./test/test.js -checkjs -webhooks 0 -webPath F:\\crabaevery\\www -modName crabaevery"
19
+ "webPath": "node ./test/test.js -checkjs -webhooks 0 -webPath F:\\crabaevery\\www -modName crabaevery",
20
+ "makeHash": "node run.js -makeHash -files http://crabadoc.ca.com/js/utils/utils.js,F:/newcrabadoc/www/js/utils/utils.js,./test/test.js,./test/beefun.js,https://s5.vip.wpscdn.cn/web-libs/2t/js/userinfo-collect/1.0.3/vas2t-userinfo-collect.min.js?a=1 -outJson ./hash.json"
20
21
  },
21
22
  "author": "wssf",
22
23
  "dependencies": {
package/tool/hash.js ADDED
@@ -0,0 +1,54 @@
1
+
2
+ var config = require('../lib/config.js');
3
+ var path = require('path');
4
+ var fs = require('fs');
5
+ var utils = require('../lib/utils.js');
6
+ var os = require('os');
7
+ const crypto = require('crypto');
8
+ var requestSync = require('sync-request');
9
+
10
+
11
+ module.exports.start = function() {
12
+ var hash = {};
13
+ var files = config.files.split(',');
14
+ files.forEach(function(f) {
15
+
16
+ console.log(f);
17
+ var content;
18
+ if (f.startsWith('http')) {
19
+ var res = requestSync("GET", f);
20
+ content = res.getBody();
21
+ } else if (fs.existsSync(f)) {
22
+ content = fs.readFileSync(f);
23
+ } else {
24
+ console.error('文件不存在:' + f);
25
+ return;
26
+ }
27
+
28
+ var index = f.indexOf('?');
29
+ if (index > 0) {
30
+ f = f.substr(0, index);
31
+ }
32
+
33
+ // SRI Hash Generator
34
+ // https://www.srihash.org/
35
+
36
+ var hex = sha384(content); // 将文件内容进行hash计算
37
+ hash[f] = 'sha384-' + hex; // 使用 base64 编码 sha384 算法计算出摘要后的 integrity 值的示例
38
+ });
39
+
40
+ utils.mkdirsSync(config.outJson);
41
+ fs.writeFileSync(config.outJson, JSON.stringify(hash));
42
+ }
43
+
44
+ function sha256(str) {
45
+ const hash = crypto.createHash('sha256');
46
+ hash.update(str);
47
+ return hash.digest('base64');
48
+ }
49
+
50
+ function sha384(str) {
51
+ const hash = crypto.createHash('sha384');
52
+ hash.update(str);
53
+ return hash.digest('base64');
54
+ }