@winner-fed/winner-deploy 4.3.6 → 4.3.8

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.
@@ -0,0 +1,16 @@
1
+ 1. scripts/js/confuse.js
2
+ 用 path.join(pkgRoot, webAppName, configBase + '.js') 定位配置文件。
3
+ 参数:argv[1]=webAppName;argv[2]=配置名(不含 .js,默认 sysconfig);argv[3]=发布包根目录。
4
+ 依赖 node + javascript-obfuscator(obfuscator.js),强混淆。
5
+
6
+ 2. scripts/js/confuse.sh
7
+ 无 node 时的 bash 兜底:整文件 base64 + `(function(_0x){eval(atob(_0x))})('...')` 包裹。
8
+ 参数与 confuse.js 相同。强度远弱于 confuse.js,仅兼容无 node 环境。
9
+ 已带 `__WINNER_BASH_OBFUSCATED__` 标记时会跳过,避免重复包裹。
10
+
11
+ 3. scripts/afterInstall.sh
12
+ `enableObfuscation` 为真时:有 node 走 confuse.js,否则走 confuse.sh。
13
+ 调用前先 `pkg_root=\`pwd\``,再 `cd` 到脚本目录,执行 `./js/confuse.*`。
14
+
15
+ 4. genWebPackage.ts
16
+ `enableObfuscation === true` 时拷贝 `templates/see/{bash|python}/scripts/js` 到 `tmp/scripts/{name}/js`。
@@ -1,26 +1,57 @@
1
1
  #!/usr/bin/python
2
2
  # -*- coding: UTF-8 -*-
3
3
 
4
- # 为上传之后的 pkg 包赋755权限
5
4
  import os
5
+ import sys
6
6
  import utils
7
7
 
8
8
  # 读取 deploy.xml 配置文件定义的 webAppName
9
9
  webAppName = "${webAppName}"
10
10
  # TIPS: 执行脚本的路径是在 安装目录 下,对应 deploy.xml 里的 workspace 字段
11
11
  pkgPath = os.path.join(os.getcwd(), webAppName)
12
+ pkg_root = os.getcwd()
12
13
 
13
14
  def chmodPkg():
14
15
  for root,dirs,files in os.walk(pkgPath):
15
16
  for file in files:
16
17
  if(not file[0] == "."):
17
- # 生成完整路径
18
18
  fp = os.path.join(root, file)
19
19
  utils.chmod(fp, "755")
20
20
  for dir in dirs:
21
21
  if(not dir[0] == "."):
22
- # 这句话没有起作用,因为walk自己还是会遍历到.dir下面去
23
22
  dp = os.path.join(root, dir)
24
23
  utils.chmod(dp, "755")
25
24
 
25
+ if not os.path.isdir(webAppName):
26
+ sys.stderr.write("错误: 安装检查失败。应用目录 '%s' 不存在。\n" % webAppName)
27
+ sys.exit(1)
28
+
29
+ if len(os.listdir(webAppName)) == 0:
30
+ sys.stderr.write("错误: 安装检查失败。应用目录 '%s' 存在但为空。\n" % webAppName)
31
+ sys.exit(1)
32
+
26
33
  chmodPkg()
34
+
35
+ <% if (enableObfuscation) { %>
36
+ import subprocess
37
+ script_dir = os.path.dirname(os.path.abspath(__file__))
38
+ confuse_js = os.path.normpath(os.path.join(script_dir, 'js', 'confuse.js'))
39
+ confuse_sh = os.path.normpath(os.path.join(script_dir, 'js', 'confuse.sh'))
40
+ config_name = '{{configFileName}}'
41
+
42
+ def which(cmd):
43
+ for p in os.environ.get('PATH', '').split(os.pathsep):
44
+ f = os.path.join(p, cmd)
45
+ if os.path.isfile(f) and os.access(f, os.X_OK):
46
+ return f
47
+ return None
48
+
49
+ if which('node'):
50
+ cmd = ['node', confuse_js, webAppName, config_name, pkg_root]
51
+ else:
52
+ cmd = ['bash', confuse_sh, webAppName, config_name, pkg_root]
53
+ ret = subprocess.call(cmd)
54
+ if ret != 0:
55
+ sys.stderr.write("错误: 混淆配置文件失败。\n")
56
+ sys.exit(ret)
57
+ <% } %>
@@ -0,0 +1,43 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const JavaScriptObfuscator = require('./obfuscator')
4
+ try {
5
+ const webAppName = process.argv[2] || process.env.WEB_APP_NAME
6
+ const configBase = process.argv[3] || process.env.CONFIG_FILE_NAME || 'sysconfig'
7
+ const pkgRoot = process.argv[4] ? path.resolve(process.argv[4]) : path.resolve(__dirname, '..', '..')
8
+ if (!webAppName) {
9
+ console.error('缺少前端应用目录名:请传入第 1 个参数或设置环境变量 WEB_APP_NAME')
10
+ process.exit(1)
11
+ }
12
+ const filepath = path.join(pkgRoot, webAppName, `${configBase}.js`)
13
+ console.log(`__filename:${__filename}`)
14
+ console.log(`文件路径:${filepath}`)
15
+ if (!fs.existsSync(filepath)) {
16
+ console.error(`文件不存在: ${filepath}`)
17
+ process.exit(1)
18
+ }
19
+ const sourceCode = fs.readFileSync(filepath, 'utf8')
20
+ const obfuscationResult = JavaScriptObfuscator.obfuscate(
21
+ sourceCode,
22
+ {
23
+ compact: true,
24
+ controlFlowFlattening: true,
25
+ controlFlowFlatteningThreshold: 0.75,
26
+ deadCodeInjection: true,
27
+ deadCodeInjectionThreshold: 0.5,
28
+ numbersToExpressions: true,
29
+ simplify: true,
30
+ selfDefending: true,
31
+ shuffleStringArray: true,
32
+ splitStrings: true,
33
+ stringArrayThreshold: 0.75,
34
+ unicodeEscapeSequence: true
35
+ }
36
+ )
37
+ fs.writeFileSync(filepath, obfuscationResult.getObfuscatedCode())
38
+ console.log('代码混淆完成,并已更新成功')
39
+ console.log(`更新路径:${filepath}`)
40
+ } catch (e) {
41
+ console.error(e)
42
+ process.exit(1)
43
+ }
@@ -0,0 +1,58 @@
1
+ #!/bin/bash
2
+ # 无 node 时的轻量混淆:整文件 base64 + atob/eval 包裹。
3
+ # 强度远低于 confuse.js(javascript-obfuscator),仅作兼容兜底。
4
+ # 参数:webAppName configBase [pkgRoot]
5
+
6
+ ERROR_ICON="❌"
7
+ INFO_ICON="ℹ️"
8
+ CHECK_ICON="✅"
9
+
10
+ webAppName="${1:-${WEB_APP_NAME}}"
11
+ configBase="${2:-${CONFIG_FILE_NAME:-sysconfig}}"
12
+ pkgRoot="${3:-}"
13
+
14
+ if [ -z "$pkgRoot" ]; then
15
+ pkgRoot="$(cd "$(dirname "$0")/../.." && pwd)"
16
+ fi
17
+
18
+ if [ -z "$webAppName" ]; then
19
+ echo -e "${ERROR_ICON} 缺少前端应用目录名:请传入第 1 个参数或设置 WEB_APP_NAME" >&2
20
+ exit 1
21
+ fi
22
+
23
+ filepath="${pkgRoot}/${webAppName}/${configBase}.js"
24
+ echo -e "${INFO_ICON} 文件路径:${filepath}"
25
+
26
+ if [ ! -f "$filepath" ]; then
27
+ echo -e "${ERROR_ICON} 文件不存在: ${filepath}" >&2
28
+ exit 1
29
+ fi
30
+
31
+ # 已混淆过则跳过,避免重复包裹
32
+ if grep -q '__WINNER_BASH_OBFUSCATED__' "$filepath" 2>/dev/null; then
33
+ echo -e "${CHECK_ICON} 配置文件已混淆,跳过"
34
+ exit 0
35
+ fi
36
+
37
+ b64=$(base64 < "$filepath" | tr -d '\n\r')
38
+ if [ -z "$b64" ]; then
39
+ echo -e "${ERROR_ICON} base64 编码失败" >&2
40
+ exit 1
41
+ fi
42
+
43
+ tmpfile="${filepath}.obf.$$"
44
+ cat > "$tmpfile" <<EOF
45
+ /* __WINNER_BASH_OBFUSCATED__ */
46
+ (function(_0x){eval(atob(_0x))})('${b64}');
47
+ EOF
48
+
49
+ if [ $? -ne 0 ]; then
50
+ rm -f "$tmpfile"
51
+ echo -e "${ERROR_ICON} 写入临时文件失败" >&2
52
+ exit 1
53
+ fi
54
+
55
+ mv "$tmpfile" "$filepath"
56
+ echo -e "${CHECK_ICON} bash 轻量混淆完成"
57
+ echo -e "${INFO_ICON} 更新路径:${filepath}"
58
+ exit 0