jjb-cmd 2.5.8 → 2.6.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.
package/src/auth.js CHANGED
@@ -1,71 +1 @@
1
- const axios = require('axios');
2
- const path = require('path');
3
- const { getApiHost } = require('./config');
4
- const {
5
- logInfo,
6
- logSuccess,
7
- logError,
8
- fileExists,
9
- deleteFile
10
- } = require('./utils');
11
- const { saveAuth, deleteAuth } = require('./crypto-utils');
12
- const { getCredentials, interactiveAuth } = require('./password-input');
13
-
14
- /**
15
- * 用户认证模块
16
- * @param {string[]} args - 命令行参数(不再使用)
17
- */
18
- module.exports = async (args) => {
19
- const authPath = path.join(__dirname, '../.auth');
20
-
21
- try {
22
- // 强制使用完全交互式模式
23
- logInfo('启动交互式登录流程');
24
- const credentials = await interactiveAuth();
25
- const username = credentials.username;
26
- const password = credentials.password;
27
-
28
- logInfo('正在验证用户凭证...');
29
-
30
- // 验证登录
31
- const response = await axios.post(`${getApiHost()}/api/auth`, {
32
- username,
33
- password
34
- });
35
-
36
- if (response.data.status) {
37
- logSuccess('用户认证成功');
38
- try {
39
- saveAuth(username, password, authPath);
40
- logSuccess('认证信息已安全加密存储');
41
- } catch (error) {
42
- logError(`保存认证信息失败: ${error.message}`);
43
- process.exit(1);
44
- }
45
- } else {
46
- logError(`认证失败: ${response.data.message || '未知错误'}`);
47
- if (fileExists(authPath)) {
48
- deleteAuth(authPath);
49
- logInfo('已清理无效的认证信息');
50
- }
51
- process.exit(1);
52
- }
53
- } catch (error) {
54
- if (error.message.includes('用户取消输入')) {
55
- logError('用户取消登录操作');
56
- } else if (error.response) {
57
- const status = error.response.status;
58
- const message = error.response.data?.message || error.message;
59
- if (status === 401 || status === 403) {
60
- logError(`认证失败 (${status}): 用户名或密码错误`);
61
- } else {
62
- logError(`请求失败 (${status}): ${message}`);
63
- }
64
- } else if (error.request) {
65
- logError(`网络连接失败: 无法连接到服务器`);
66
- } else {
67
- logError(`登录失败: ${error.message}`);
68
- }
69
- process.exit(1);
70
- }
71
- };
1
+ function a1_0x4a13(_0x717897,_0x1b93a5){_0x717897=_0x717897-0x19d;const _0x5771c9=a1_0x5771();let _0x4a1324=_0x5771c9[_0x717897];return _0x4a1324;}const a1_0x46875e=a1_0x4a13;(function(_0x1fbf1b,_0xa63105){const _0x4174b5=a1_0x4a13,_0x494b30=_0x1fbf1b();while(!![]){try{const _0x2ebca2=-parseInt(_0x4174b5(0x1be))/0x1*(parseInt(_0x4174b5(0x1bb))/0x2)+parseInt(_0x4174b5(0x1b3))/0x3+parseInt(_0x4174b5(0x1b4))/0x4*(parseInt(_0x4174b5(0x19d))/0x5)+parseInt(_0x4174b5(0x19f))/0x6+parseInt(_0x4174b5(0x1b9))/0x7+parseInt(_0x4174b5(0x1b5))/0x8+parseInt(_0x4174b5(0x1af))/0x9*(-parseInt(_0x4174b5(0x1ba))/0xa);if(_0x2ebca2===_0xa63105)break;else _0x494b30['push'](_0x494b30['shift']());}catch(_0x4864de){_0x494b30['push'](_0x494b30['shift']());}}}(a1_0x5771,0xd31ba));const axios=require(a1_0x46875e(0x1c0)),path=require(a1_0x46875e(0x1bd)),{getApiHost}=require(a1_0x46875e(0x1a2)),{logInfo,logSuccess,logError,fileExists,deleteFile}=require(a1_0x46875e(0x1a5)),{saveAuth,deleteAuth}=require('./crypto-utils'),{getCredentials,interactiveAuth}=require('./password-input');function a1_0x5771(){const _0x176aa6=['正在验证用户凭证...','认证信息已安全加密存储','11356744QouHqW','4390IaPaPW','503396LRWZTI','username','path','3PYhYTL','保存认证信息失败:\x20','axios','request','/api/auth','../.auth','114475vYrAMu','启动交互式登录流程','3292530cYaLSm','用户取消输入','认证失败\x20(','./config','已清理无效的认证信息','登录失败:\x20','./utils','includes','网络连接失败:\x20无法连接到服务器','用户认证成功','post','):\x20','exit','用户取消登录操作','message','data','76131xrDgtl','status','response','未知错误','3003384laRRYP','172bwHkEu','9412264YrClEc','password'];a1_0x5771=function(){return _0x176aa6;};return a1_0x5771();}module['exports']=async _0x5a65bd=>{const _0x13d603=a1_0x46875e,_0xd8dd4f=path['join'](__dirname,_0x13d603(0x1c3));try{logInfo(_0x13d603(0x19e));const _0xa7e937=await interactiveAuth(),_0x204557=_0xa7e937[_0x13d603(0x1bc)],_0x33bf87=_0xa7e937[_0x13d603(0x1b6)];logInfo(_0x13d603(0x1b7));const _0x1db3da=await axios[_0x13d603(0x1a9)](getApiHost()+_0x13d603(0x1c2),{'username':_0x204557,'password':_0x33bf87});if(_0x1db3da['data'][_0x13d603(0x1b0)]){logSuccess(_0x13d603(0x1a8));try{saveAuth(_0x204557,_0x33bf87,_0xd8dd4f),logSuccess(_0x13d603(0x1b8));}catch(_0x3d51a3){logError(_0x13d603(0x1bf)+_0x3d51a3[_0x13d603(0x1ad)]),process[_0x13d603(0x1ab)](0x1);}}else logError('认证失败:\x20'+(_0x1db3da[_0x13d603(0x1ae)][_0x13d603(0x1ad)]||_0x13d603(0x1b2))),fileExists(_0xd8dd4f)&&(deleteAuth(_0xd8dd4f),logInfo(_0x13d603(0x1a3))),process[_0x13d603(0x1ab)](0x1);}catch(_0x2c74cd){if(_0x2c74cd[_0x13d603(0x1ad)][_0x13d603(0x1a6)](_0x13d603(0x1a0)))logError(_0x13d603(0x1ac));else{if(_0x2c74cd[_0x13d603(0x1b1)]){const _0x99acaf=_0x2c74cd[_0x13d603(0x1b1)][_0x13d603(0x1b0)],_0x1fac0a=_0x2c74cd[_0x13d603(0x1b1)]['data']?.[_0x13d603(0x1ad)]||_0x2c74cd['message'];_0x99acaf===0x191||_0x99acaf===0x193?logError(_0x13d603(0x1a1)+_0x99acaf+'):\x20用户名或密码错误'):logError('请求失败\x20('+_0x99acaf+_0x13d603(0x1aa)+_0x1fac0a);}else _0x2c74cd[_0x13d603(0x1c1)]?logError(_0x13d603(0x1a7)):logError(_0x13d603(0x1a4)+_0x2c74cd['message']);}process[_0x13d603(0x1ab)](0x1);}};
@@ -1,46 +1 @@
1
- const path = require('path');
2
- const inquirer = require('inquirer');
3
- const { bootstrap } = require('@cqsjjb/react-code-optimization');
4
- const {
5
- logInfo,
6
- logSuccess,
7
- logError,
8
- logWarning
9
- } = require('./utils');
10
-
11
- /**
12
- * 代码优化模块
13
- * 使用 @cqsjjb/react-code-optimization 进行代码优化
14
- */
15
- module.exports = async function () {
16
- const rootPath = path.resolve('./');
17
-
18
- logInfo('代码优化工具已启动');
19
- logWarning('此操作将优化当前目录下的代码,请确保已备份重要文件');
20
-
21
- const { confirmed } = await inquirer.prompt([
22
- {
23
- type: 'confirm',
24
- name: 'confirmed',
25
- message: '是否确认优化代码?',
26
- default: false
27
- }
28
- ]);
29
-
30
- if (confirmed) {
31
- logInfo('正在分析代码结构...');
32
-
33
- try {
34
- bootstrap(rootPath, 100, () => {
35
- logSuccess('代码优化已完成');
36
- process.exit(0);
37
- });
38
- } catch (error) {
39
- logError(`代码优化失败: ${error.message}`);
40
- process.exit(1);
41
- }
42
- } else {
43
- logInfo('操作已取消');
44
- process.exit(0);
45
- }
46
- };
1
+ function a2_0xa9a2(){const _0x2655c6=['path','18086oOqWAg','exports','9nNkmzy','代码优化失败:\x20','resolve','2343992ybdbsp','inquirer','正在分析代码结构...','434SnTTwK','代码优化工具已启动','5120910UCfLHj','@cqsjjb/react-code-optimization','278343NGQbkW','是否确认优化代码?','42372DTQXPB','exit','118vwWYiz','5910872NmepTq','代码优化已完成','./utils','7331400parFro','message','confirmed','confirm'];a2_0xa9a2=function(){return _0x2655c6;};return a2_0xa9a2();}const a2_0x242f52=a2_0x43a8;(function(_0x4363c9,_0x2d3c26){const _0x5337d9=a2_0x43a8,_0x343d9e=_0x4363c9();while(!![]){try{const _0x44362c=parseInt(_0x5337d9(0x12d))/0x1*(parseInt(_0x5337d9(0x124))/0x2)+parseInt(_0x5337d9(0x120))/0x3+-parseInt(_0x5337d9(0x119))/0x4+-parseInt(_0x5337d9(0x128))/0x5+parseInt(_0x5337d9(0x122))/0x6*(parseInt(_0x5337d9(0x11c))/0x7)+-parseInt(_0x5337d9(0x125))/0x8*(-parseInt(_0x5337d9(0x12f))/0x9)+parseInt(_0x5337d9(0x11e))/0xa;if(_0x44362c===_0x2d3c26)break;else _0x343d9e['push'](_0x343d9e['shift']());}catch(_0x2efe76){_0x343d9e['push'](_0x343d9e['shift']());}}}(a2_0xa9a2,0xc26d3));function a2_0x43a8(_0x308a3e,_0x189028){_0x308a3e=_0x308a3e-0x117;const _0xa9a2a8=a2_0xa9a2();let _0x43a8e4=_0xa9a2a8[_0x308a3e];return _0x43a8e4;}const path=require(a2_0x242f52(0x12c)),inquirer=require(a2_0x242f52(0x11a)),{bootstrap}=require(a2_0x242f52(0x11f)),{logInfo,logSuccess,logError,logWarning}=require(a2_0x242f52(0x127));module[a2_0x242f52(0x12e)]=async function(){const _0x2c5da8=a2_0x242f52,_0x3fd234=path[_0x2c5da8(0x118)]('./');logInfo(_0x2c5da8(0x11d)),logWarning('此操作将优化当前目录下的代码,请确保已备份重要文件');const {confirmed:_0x1c5096}=await inquirer['prompt']([{'type':_0x2c5da8(0x12b),'name':_0x2c5da8(0x12a),'message':_0x2c5da8(0x121),'default':![]}]);if(_0x1c5096){logInfo(_0x2c5da8(0x11b));try{bootstrap(_0x3fd234,0x64,()=>{const _0x1fe1cf=_0x2c5da8;logSuccess(_0x1fe1cf(0x126)),process[_0x1fe1cf(0x123)](0x0);});}catch(_0x235bbd){logError(_0x2c5da8(0x117)+_0x235bbd[_0x2c5da8(0x129)]),process['exit'](0x1);}}else logInfo('操作已取消'),process[_0x2c5da8(0x123)](0x0);};
package/src/config.js CHANGED
@@ -1,122 +1 @@
1
- const os = require('os');
2
- const path = require('path');
3
- const fs = require('fs');
4
-
5
- /**
6
- * API 主机配置
7
- */
8
- const API_HOST = 'http://120.26.210.58:8088';
9
- const API_HOST_HTTPS = 'https://jcloud.cqjjb.cn';
10
- const API_HOST_TEST = 'http://120.26.210.58:8089';
11
-
12
- /**
13
- * 配置文件主机地址
14
- */
15
- exports.CONFIG_FILE_HOST = 'https://cdn.cqjjb.cn/jjb-cloud-config';
16
-
17
- /**
18
- * API 主机地址
19
- */
20
- exports.API_HOST = API_HOST;
21
-
22
- /**
23
- * 测试环境 API 主机地址
24
- */
25
- exports.API_HOST_TEST = API_HOST_TEST;
26
-
27
- /**
28
- * Git 主机地址
29
- */
30
- exports.GIT_HOST = 'http://192.168.1.242:10985';
31
-
32
- /**
33
- * 临时目录名称
34
- */
35
- exports.GIT_TEMP_DIR = `jjb-assembly-${Date.now()}`;
36
-
37
- /**
38
- * Java 临时目录名称
39
- */
40
- exports.GIT_TEMP_JAVA = `jjb-assembly-java`;
41
-
42
- /**
43
- * Java 环境映射
44
- */
45
- exports.GIT_JAVA_ENV_JSON = {
46
- development: 'dev',
47
- production: 'prod',
48
- test: 'test'
49
- };
50
- /**
51
- * 云项目配置
52
- * 包含各个项目的 token 和 projectId
53
- */
54
- exports.CLOUD_PROJECT = {
55
- common: {
56
- token: 'G4HJRsHr9D7Ssmixegw2',
57
- projectId: 279
58
- },
59
- 'react-admin-component': {
60
- token: 'FT3pKzxpRynFkmddJ9Bs',
61
- projectId: 340
62
- },
63
- 'jjb-dva-runtime': {
64
- token: 'hLqARY89CN6fUD3yg4NL',
65
- projectId: 571
66
- },
67
- 'jjb-common-lib': {
68
- token: 'e9njpBd1nS_LREN8GFpR',
69
- projectId: 572
70
- },
71
- 'jjb-common-decorator': {
72
- token: 'gPSit8aJsLVmNzuQ5Cy4',
73
- projectId: 574
74
- },
75
- 'vue-unisass-component': {
76
- token: 'd4wQ7dzEjYPsgVbKnYei',
77
- projectId: 339
78
- },
79
- 'react-component': {
80
- token: 'snBxJ2i5kYarGGcsojhY',
81
- projectId: 831
82
- },
83
- 'micro-app-ts': {
84
- token: '7V-YUxhmh51Mdhgx4rq4',
85
- projectId: 830
86
- },
87
- 'micro-app': {
88
- token: 'FqNrmFAgrxasMrbbjvq9',
89
- projectId: 829
90
- },
91
- lib: {
92
- token: 'ywPtT3xCG6b_vAxp6sTj',
93
- projectId: 828
94
- }
95
- };
96
-
97
- /**
98
- * 模板文件夹路径
99
- */
100
- exports.TEMPLATE_FOLDER = path.join(os.tmpdir(), exports.GIT_TEMP_DIR);
101
-
102
- /**
103
- * 获取 API 主机地址
104
- * 根据 package.json 中的配置决定使用哪个 API 主机
105
- * @returns {string} API 主机地址
106
- */
107
- exports.getApiHost = () => {
108
- try {
109
- const packageJson = JSON.parse(
110
- fs.readFileSync(path.join(__dirname, '../package.json')).toString()
111
- );
112
-
113
- if (packageJson.env === 'test') {
114
- return API_HOST_TEST;
115
- } else {
116
- return packageJson.httpMethod === 'http' ? API_HOST : API_HOST_HTTPS;
117
- }
118
- } catch (error) {
119
- // 如果读取 package.json 失败,默认返回 HTTPS 地址
120
- return API_HOST_HTTPS;
121
- }
122
- };
1
+ const a3_0x159116=a3_0x23e6;(function(_0x2cb0ca,_0x24c2ca){const _0x5bc366=a3_0x23e6,_0x1022ce=_0x2cb0ca();while(!![]){try{const _0xefe909=-parseInt(_0x5bc366(0xba))/0x1+-parseInt(_0x5bc366(0xcd))/0x2*(parseInt(_0x5bc366(0xc0))/0x3)+-parseInt(_0x5bc366(0xb8))/0x4+parseInt(_0x5bc366(0xaf))/0x5*(-parseInt(_0x5bc366(0xd1))/0x6)+-parseInt(_0x5bc366(0xaa))/0x7+-parseInt(_0x5bc366(0xbb))/0x8*(parseInt(_0x5bc366(0xd0))/0x9)+parseInt(_0x5bc366(0xc2))/0xa;if(_0xefe909===_0x24c2ca)break;else _0x1022ce['push'](_0x1022ce['shift']());}catch(_0xbc5eea){_0x1022ce['push'](_0x1022ce['shift']());}}}(a3_0x3109,0xda84c));function a3_0x23e6(_0x344194,_0x177183){_0x344194=_0x344194-0xa6;const _0x3109ae=a3_0x3109();let _0x23e64a=_0x3109ae[_0x344194];return _0x23e64a;}function a3_0x3109(){const _0x4db4a0=['test','CONFIG_FILE_HOST','API_HOST','now','865LAaRKv','getApiHost','TEMPLATE_FOLDER','httpMethod','FT3pKzxpRynFkmddJ9Bs','http://120.26.210.58:8088','e9njpBd1nS_LREN8GFpR','GIT_TEMP_JAVA','jjb-assembly-java','1249736TYrDHv','readFileSync','185937GzTLmN','2216xnySLS','API_HOST_TEST','CLOUD_PROJECT','https://jcloud.cqjjb.cn','env','69TvnAtv','dev','53474370rbcRDN','7V-YUxhmh51Mdhgx4rq4','parse','GIT_TEMP_DIR','ywPtT3xCG6b_vAxp6sTj','https://cdn.cqjjb.cn/jjb-cloud-config','toString','hLqARY89CN6fUD3yg4NL','http://192.168.1.242:10985','http://120.26.210.58:8089','GIT_HOST','95926sVlSSE','../package.json','tmpdir','48051xGUnAm','39036KDrenp','snBxJ2i5kYarGGcsojhY','http','jjb-assembly-','join','GIT_JAVA_ENV_JSON','d4wQ7dzEjYPsgVbKnYei','1724968SSMwHE'];a3_0x3109=function(){return _0x4db4a0;};return a3_0x3109();}const os=require('os'),path=require('path'),fs=require('fs'),API_HOST=a3_0x159116(0xb4),API_HOST_HTTPS=a3_0x159116(0xbe),API_HOST_TEST=a3_0x159116(0xcb);exports[a3_0x159116(0xac)]=a3_0x159116(0xc7),exports[a3_0x159116(0xad)]=API_HOST,exports[a3_0x159116(0xbc)]=API_HOST_TEST,exports[a3_0x159116(0xcc)]=a3_0x159116(0xca),exports[a3_0x159116(0xc5)]=a3_0x159116(0xa6)+Date[a3_0x159116(0xae)](),exports[a3_0x159116(0xb6)]=a3_0x159116(0xb7),exports[a3_0x159116(0xa8)]={'development':a3_0x159116(0xc1),'production':'prod','test':a3_0x159116(0xab)},exports[a3_0x159116(0xbd)]={'common':{'token':'G4HJRsHr9D7Ssmixegw2','projectId':0x117},'react-admin-component':{'token':a3_0x159116(0xb3),'projectId':0x154},'jjb-dva-runtime':{'token':a3_0x159116(0xc9),'projectId':0x23b},'jjb-common-lib':{'token':a3_0x159116(0xb5),'projectId':0x23c},'jjb-common-decorator':{'token':'gPSit8aJsLVmNzuQ5Cy4','projectId':0x23e},'vue-unisass-component':{'token':a3_0x159116(0xa9),'projectId':0x153},'react-component':{'token':a3_0x159116(0xd2),'projectId':0x33f},'micro-app-ts':{'token':a3_0x159116(0xc3),'projectId':0x33e},'micro-app':{'token':'FqNrmFAgrxasMrbbjvq9','projectId':0x33d},'lib':{'token':a3_0x159116(0xc6),'projectId':0x33c}},exports[a3_0x159116(0xb1)]=path[a3_0x159116(0xa7)](os[a3_0x159116(0xcf)](),exports[a3_0x159116(0xc5)]),exports[a3_0x159116(0xb0)]=()=>{const _0x9b29f9=a3_0x159116;try{const _0x700dc4=JSON[_0x9b29f9(0xc4)](fs[_0x9b29f9(0xb9)](path[_0x9b29f9(0xa7)](__dirname,_0x9b29f9(0xce)))[_0x9b29f9(0xc8)]());return _0x700dc4[_0x9b29f9(0xbf)]==='test'?API_HOST_TEST:_0x700dc4[_0x9b29f9(0xb2)]===_0x9b29f9(0xd3)?API_HOST:API_HOST_HTTPS;}catch(_0x28e578){return API_HOST_HTTPS;}};
@@ -1,183 +1 @@
1
- const crypto = require('crypto');
2
- const fs = require('fs');
3
- const path = require('path');
4
-
5
- /**
6
- * 加密配置
7
- */
8
- const CRYPTO_CONFIG = {
9
- algorithm: 'aes-256-cbc',
10
- keyLength: 32, // 256 bits
11
- ivLength: 16, // 128 bits
12
- saltLength: 32 // 256 bits
13
- };
14
-
15
- /**
16
- * 生成加密密钥
17
- * @param {string} password - 主密码
18
- * @param {Buffer} salt - 盐值
19
- * @returns {Buffer} 加密密钥
20
- */
21
- function deriveKey(password, salt) {
22
- return crypto.pbkdf2Sync(password, salt, 100000, CRYPTO_CONFIG.keyLength, 'sha512');
23
- }
24
-
25
- /**
26
- * 生成随机盐值
27
- * @returns {Buffer} 随机盐值
28
- */
29
- function generateSalt() {
30
- return crypto.randomBytes(CRYPTO_CONFIG.saltLength);
31
- }
32
-
33
- /**
34
- * 生成随机IV
35
- * @returns {Buffer} 随机IV
36
- */
37
- function generateIV() {
38
- return crypto.randomBytes(CRYPTO_CONFIG.ivLength);
39
- }
40
-
41
- /**
42
- * 加密数据
43
- * @param {string} text - 要加密的文本
44
- * @param {string} password - 加密密码
45
- * @returns {string} 加密后的数据(base64编码)
46
- */
47
- function encrypt(text, password) {
48
- try {
49
- const salt = generateSalt();
50
- const iv = generateIV();
51
- const key = deriveKey(password, salt);
52
-
53
- const cipher = crypto.createCipheriv(CRYPTO_CONFIG.algorithm, key, iv);
54
- cipher.setAutoPadding(true);
55
-
56
- let encrypted = cipher.update(text, 'utf8', 'hex');
57
- encrypted += cipher.final('hex');
58
-
59
- // 组合数据:salt + iv + encrypted
60
- const combined = Buffer.concat([salt, iv, Buffer.from(encrypted, 'hex')]);
61
-
62
- return combined.toString('base64');
63
- } catch (error) {
64
- throw new Error(`加密失败: ${error.message}`);
65
- }
66
- }
67
-
68
- /**
69
- * 解密数据
70
- * @param {string} encryptedData - 加密的数据(base64编码)
71
- * @param {string} password - 解密密码
72
- * @returns {string} 解密后的文本
73
- */
74
- function decrypt(encryptedData, password) {
75
- try {
76
- const combined = Buffer.from(encryptedData, 'base64');
77
-
78
- // 分离数据
79
- const salt = combined.slice(0, CRYPTO_CONFIG.saltLength);
80
- const iv = combined.slice(CRYPTO_CONFIG.saltLength, CRYPTO_CONFIG.saltLength + CRYPTO_CONFIG.ivLength);
81
- const encrypted = combined.slice(CRYPTO_CONFIG.saltLength + CRYPTO_CONFIG.ivLength);
82
-
83
- const key = deriveKey(password, salt);
84
-
85
- const decipher = crypto.createDecipheriv(CRYPTO_CONFIG.algorithm, key, iv);
86
- decipher.setAutoPadding(true);
87
-
88
- let decrypted = decipher.update(encrypted, null, 'utf8');
89
- decrypted += decipher.final('utf8');
90
-
91
- return decrypted;
92
- } catch (error) {
93
- throw new Error(`解密失败: ${error.message}`);
94
- }
95
- }
96
-
97
- /**
98
- * 生成设备特定的加密密钥
99
- * 基于系统信息生成,确保密钥的唯一性
100
- * @returns {string} 设备密钥
101
- */
102
- function generateDeviceKey() {
103
- const os = require('os');
104
- const machineInfo = [
105
- os.platform(),
106
- os.arch(),
107
- os.hostname(),
108
- os.userInfo().username || 'unknown'
109
- ].join('|');
110
-
111
- return crypto.createHash('sha256').update(machineInfo).digest('hex');
112
- }
113
-
114
- /**
115
- * 安全存储认证信息
116
- * @param {string} username - 用户名
117
- * @param {string} password - 密码
118
- * @param {string} authPath - 认证文件路径
119
- */
120
- function saveAuth(username, password, authPath) {
121
- try {
122
- const deviceKey = generateDeviceKey();
123
- const authData = `${username}/${password}`;
124
- const encryptedData = encrypt(authData, deviceKey);
125
-
126
- // 设置文件权限为仅当前用户可读写
127
- fs.writeFileSync(authPath, encryptedData, { mode: 0o600 });
128
-
129
- return true;
130
- } catch (error) {
131
- throw new Error(`保存认证信息失败: ${error.message}`);
132
- }
133
- }
134
-
135
- /**
136
- * 安全读取认证信息
137
- * @param {string} authPath - 认证文件路径
138
- * @returns {Object} 包含用户名和密码的对象
139
- */
140
- function loadAuth(authPath) {
141
- try {
142
- if (!fs.existsSync(authPath)) {
143
- throw new Error('认证文件不存在');
144
- }
145
-
146
- const deviceKey = generateDeviceKey();
147
- const encryptedData = fs.readFileSync(authPath, 'utf8');
148
- const decryptedData = decrypt(encryptedData, deviceKey);
149
-
150
- const [username, password] = decryptedData.split('/');
151
-
152
- if (!username || !password) {
153
- throw new Error('认证数据格式错误');
154
- }
155
-
156
- return { username, password };
157
- } catch (error) {
158
- throw new Error(`读取认证信息失败: ${error.message}`);
159
- }
160
- }
161
-
162
- /**
163
- * 删除认证文件
164
- * @param {string} authPath - 认证文件路径
165
- */
166
- function deleteAuth(authPath) {
167
- try {
168
- if (fs.existsSync(authPath)) {
169
- fs.unlinkSync(authPath);
170
- }
171
- } catch (error) {
172
- throw new Error(`删除认证文件失败: ${error.message}`);
173
- }
174
- }
175
-
176
- module.exports = {
177
- encrypt,
178
- decrypt,
179
- saveAuth,
180
- loadAuth,
181
- deleteAuth,
182
- generateDeviceKey
183
- };
1
+ function a4_0x1134(){const _0x5150ee=['base64','4575940XOSoxw','final','slice','message','algorithm','2489492KwiiRh','ivLength','aes-256-cbc','join','readFileSync','保存认证信息失败:\x20','utf8','username','18HWYwnK','删除认证文件失败:\x20','createDecipheriv','633KoIwaC','concat','2558rZIOMT','认证数据格式错误','saltLength','hex','43824830nxyBqz','加密失败:\x20','crypto','arch','unknown','existsSync','7084272WhcPog','认证文件不存在','randomBytes','keyLength','sha256','exports','9585513ntDZZm','writeFileSync','digest','userInfo','from','pbkdf2Sync','update','2616760YmdFzb','createCipheriv','6orzbyK','读取认证信息失败:\x20'];a4_0x1134=function(){return _0x5150ee;};return a4_0x1134();}const a4_0x27d5c1=a4_0x18a9;(function(_0x2f958e,_0xb31b15){const _0x290724=a4_0x18a9,_0x32b976=_0x2f958e();while(!![]){try{const _0x5e79d5=parseInt(_0x290724(0x9c))/0x1*(-parseInt(_0x290724(0x9e))/0x2)+parseInt(_0x290724(0x89))/0x3*(parseInt(_0x290724(0x91))/0x4)+-parseInt(_0x290724(0x8c))/0x5+-parseInt(_0x290724(0x7a))/0x6+-parseInt(_0x290724(0x80))/0x7+parseInt(_0x290724(0x87))/0x8*(-parseInt(_0x290724(0x99))/0x9)+parseInt(_0x290724(0x74))/0xa;if(_0x5e79d5===_0xb31b15)break;else _0x32b976['push'](_0x32b976['shift']());}catch(_0x15e276){_0x32b976['push'](_0x32b976['shift']());}}}(a4_0x1134,0xaa73d));const crypto=require(a4_0x27d5c1(0x76)),fs=require('fs'),path=require('path'),CRYPTO_CONFIG={'algorithm':a4_0x27d5c1(0x93),'keyLength':0x20,'ivLength':0x10,'saltLength':0x20};function deriveKey(_0x48c165,_0xe151ab){const _0xea21a3=a4_0x27d5c1;return crypto[_0xea21a3(0x85)](_0x48c165,_0xe151ab,0x186a0,CRYPTO_CONFIG[_0xea21a3(0x7d)],'sha512');}function a4_0x18a9(_0x3f8974,_0x56d52a){_0x3f8974=_0x3f8974-0x71;const _0x11347f=a4_0x1134();let _0x18a9f4=_0x11347f[_0x3f8974];return _0x18a9f4;}function generateSalt(){const _0x2c7ab0=a4_0x27d5c1;return crypto[_0x2c7ab0(0x7c)](CRYPTO_CONFIG['saltLength']);}function generateIV(){const _0x4f3ef3=a4_0x27d5c1;return crypto[_0x4f3ef3(0x7c)](CRYPTO_CONFIG[_0x4f3ef3(0x92)]);}function encrypt(_0x684ebb,_0x9afe75){const _0x46367d=a4_0x27d5c1;try{const _0x30131a=generateSalt(),_0x2ff4ef=generateIV(),_0xdc2f4f=deriveKey(_0x9afe75,_0x30131a),_0xc587a4=crypto[_0x46367d(0x88)](CRYPTO_CONFIG[_0x46367d(0x90)],_0xdc2f4f,_0x2ff4ef);_0xc587a4['setAutoPadding'](!![]);let _0x3dfc34=_0xc587a4[_0x46367d(0x86)](_0x684ebb,'utf8',_0x46367d(0x73));_0x3dfc34+=_0xc587a4['final']('hex');const _0x4092ed=Buffer[_0x46367d(0x9d)]([_0x30131a,_0x2ff4ef,Buffer[_0x46367d(0x84)](_0x3dfc34,_0x46367d(0x73))]);return _0x4092ed['toString']('base64');}catch(_0x47b63c){throw new Error(_0x46367d(0x75)+_0x47b63c[_0x46367d(0x8f)]);}}function decrypt(_0x7bf1b4,_0x330de4){const _0x64facc=a4_0x27d5c1;try{const _0xab9102=Buffer['from'](_0x7bf1b4,_0x64facc(0x8b)),_0x4c1f9d=_0xab9102[_0x64facc(0x8e)](0x0,CRYPTO_CONFIG[_0x64facc(0x72)]),_0x5b78a2=_0xab9102[_0x64facc(0x8e)](CRYPTO_CONFIG[_0x64facc(0x72)],CRYPTO_CONFIG[_0x64facc(0x72)]+CRYPTO_CONFIG['ivLength']),_0x14bfab=_0xab9102[_0x64facc(0x8e)](CRYPTO_CONFIG[_0x64facc(0x72)]+CRYPTO_CONFIG[_0x64facc(0x92)]),_0x5f3212=deriveKey(_0x330de4,_0x4c1f9d),_0x5ad0d4=crypto[_0x64facc(0x9b)](CRYPTO_CONFIG['algorithm'],_0x5f3212,_0x5b78a2);_0x5ad0d4['setAutoPadding'](!![]);let _0x47ca47=_0x5ad0d4['update'](_0x14bfab,null,_0x64facc(0x97));return _0x47ca47+=_0x5ad0d4[_0x64facc(0x8d)](_0x64facc(0x97)),_0x47ca47;}catch(_0x35f540){throw new Error('解密失败:\x20'+_0x35f540[_0x64facc(0x8f)]);}}function generateDeviceKey(){const _0x5486c0=a4_0x27d5c1,_0x3db0dd=require('os');let _0x476807='unknown';try{_0x476807=_0x3db0dd[_0x5486c0(0x83)]()[_0x5486c0(0x98)]||_0x5486c0(0x78);}catch(_0x40d311){_0x476807=process.env.USER||process.env.LOGNAME||process.env.USERNAME||_0x5486c0(0x78);}const _0x546980=[_0x3db0dd['platform'](),_0x3db0dd[_0x5486c0(0x77)](),_0x3db0dd['hostname'](),_0x476807][_0x5486c0(0x94)]('|');return crypto['createHash'](_0x5486c0(0x7e))[_0x5486c0(0x86)](_0x546980)[_0x5486c0(0x82)]('hex');}function saveAuth(_0xd33b37,_0x5c7d7e,_0x23dc28){const _0x40e1cc=a4_0x27d5c1;try{const _0x6611b3=generateDeviceKey(),_0x3e3d58=_0xd33b37+'/'+_0x5c7d7e,_0x4764f6=encrypt(_0x3e3d58,_0x6611b3);return fs[_0x40e1cc(0x81)](_0x23dc28,_0x4764f6,{'mode':0x180}),!![];}catch(_0x58b902){throw new Error(_0x40e1cc(0x96)+_0x58b902[_0x40e1cc(0x8f)]);}}function loadAuth(_0x26c4f5){const _0x17c70d=a4_0x27d5c1;try{if(!fs[_0x17c70d(0x79)](_0x26c4f5))throw new Error(_0x17c70d(0x7b));const _0x32fd85=generateDeviceKey(),_0x25aa1f=fs[_0x17c70d(0x95)](_0x26c4f5,_0x17c70d(0x97)),_0x47ae45=decrypt(_0x25aa1f,_0x32fd85),[_0x21f9c6,_0xb9cfd3]=_0x47ae45['split']('/');if(!_0x21f9c6||!_0xb9cfd3)throw new Error(_0x17c70d(0x71));return{'username':_0x21f9c6,'password':_0xb9cfd3};}catch(_0x48b18a){throw new Error(_0x17c70d(0x8a)+_0x48b18a[_0x17c70d(0x8f)]);}}function deleteAuth(_0x3399f0){const _0x438406=a4_0x27d5c1;try{fs[_0x438406(0x79)](_0x3399f0)&&fs['unlinkSync'](_0x3399f0);}catch(_0x4f61a7){throw new Error(_0x438406(0x9a)+_0x4f61a7[_0x438406(0x8f)]);}}module[a4_0x27d5c1(0x7f)]={'encrypt':encrypt,'decrypt':decrypt,'saveAuth':saveAuth,'loadAuth':loadAuth,'deleteAuth':deleteAuth,'generateDeviceKey':generateDeviceKey};
@@ -1,79 +1 @@
1
- const inquirer = require('inquirer');
2
- const { logError } = require('./utils');
3
-
4
- /**
5
- * 安全密码输入工具
6
- * 使用 inquirer 实现隐藏密码输入,防止在控制台显示明文密码
7
- */
8
-
9
- /**
10
- * 安全获取用户名和密码
11
- * @param {string} username - 用户名(如果已提供)
12
- * @returns {Promise<Object>} 包含用户名和密码的对象
13
- */
14
- async function getCredentials(username = null) {
15
- try {
16
- let finalUsername = username;
17
- const prompts = [];
18
-
19
- // 如果没有提供用户名,则提示输入
20
- if (!finalUsername) {
21
- prompts.push({
22
- type: 'input',
23
- name: 'username',
24
- message: '请输入账号:',
25
- validate: (input) => {
26
- if (!input || !input.trim()) {
27
- return '账号不能为空';
28
- }
29
- return true;
30
- }
31
- });
32
- }
33
-
34
- // 获取密码(使用 inquirer 的 password 类型隐藏输入)
35
- prompts.push({
36
- type: 'password',
37
- name: 'password',
38
- message: '请输入密码:',
39
- mask: '*',
40
- validate: (input) => {
41
- if (!input || !input.trim()) {
42
- return '密码不能为空';
43
- }
44
- return true;
45
- }
46
- });
47
-
48
- const answers = await inquirer.prompt(prompts);
49
-
50
- finalUsername = finalUsername || answers.username.trim();
51
- const password = answers.password;
52
-
53
- return {
54
- username: finalUsername,
55
- password: password
56
- };
57
- } catch (error) {
58
- if (error.isTtyError) {
59
- logError(`获取认证信息失败: 当前环境不支持交互式输入`);
60
- } else {
61
- logError(`获取认证信息失败: ${error.message}`);
62
- }
63
- throw error;
64
- }
65
- }
66
-
67
- /**
68
- * 交互式认证输入
69
- * 当命令行参数不足时使用
70
- * @returns {Promise<Object>} 包含用户名和密码的对象
71
- */
72
- async function interactiveAuth() {
73
- return await getCredentials();
74
- }
75
-
76
- module.exports = {
77
- getCredentials,
78
- interactiveAuth
79
- };
1
+ function a5_0x52a1(_0x1d7737,_0x2131a5){_0x1d7737=_0x1d7737-0x1c7;const _0x4f8575=a5_0x4f85();let _0x52a1d9=_0x4f8575[_0x1d7737];return _0x52a1d9;}function a5_0x4f85(){const _0x187e1a=['exports','2113912DKqgiD','35FzfECd','2960YmuDoY','1732670QcUJIr','7157832aGrcQq','./utils','密码不能为空','获取认证信息失败:\x20','prompt','获取认证信息失败:\x20当前环境不支持交互式输入','4963005cxrEKv','message','trim','16242VebrFY','push','input','请输入密码:','4414518KvilrS','password','请输入账号:','inquirer','2533768GxtGUh'];a5_0x4f85=function(){return _0x187e1a;};return a5_0x4f85();}const a5_0x5319b5=a5_0x52a1;(function(_0x35e920,_0x47a6e7){const _0x3e70c7=a5_0x52a1,_0x4b1cdb=_0x35e920();while(!![]){try{const _0x4023f3=parseInt(_0x3e70c7(0x1ca))/0x1+-parseInt(_0x3e70c7(0x1c7))/0x2+-parseInt(_0x3e70c7(0x1d1))/0x3+-parseInt(_0x3e70c7(0x1cb))/0x4+parseInt(_0x3e70c7(0x1c9))/0x5*(parseInt(_0x3e70c7(0x1d4))/0x6)+parseInt(_0x3e70c7(0x1c8))/0x7*(parseInt(_0x3e70c7(0x1dc))/0x8)+parseInt(_0x3e70c7(0x1d8))/0x9;if(_0x4023f3===_0x47a6e7)break;else _0x4b1cdb['push'](_0x4b1cdb['shift']());}catch(_0x8a709d){_0x4b1cdb['push'](_0x4b1cdb['shift']());}}}(a5_0x4f85,0xddd1c));const inquirer=require(a5_0x5319b5(0x1db)),{logError}=require(a5_0x5319b5(0x1cc));async function getCredentials(_0x450855=null){const _0x36327c=a5_0x5319b5;try{let _0x196317=_0x450855;const _0x25650e=[];!_0x196317&&_0x25650e[_0x36327c(0x1d5)]({'type':_0x36327c(0x1d6),'name':'username','message':_0x36327c(0x1da),'validate':_0x974cac=>{const _0x35aa6b=_0x36327c;if(!_0x974cac||!_0x974cac[_0x35aa6b(0x1d3)]())return'账号不能为空';return!![];}});_0x25650e[_0x36327c(0x1d5)]({'type':_0x36327c(0x1d9),'name':'password','message':_0x36327c(0x1d7),'mask':'*','validate':_0x18c733=>{const _0x281b4c=_0x36327c;if(!_0x18c733||!_0x18c733[_0x281b4c(0x1d3)]())return _0x281b4c(0x1cd);return!![];}});const _0xf7adcb=await inquirer[_0x36327c(0x1cf)](_0x25650e);_0x196317=_0x196317||_0xf7adcb['username'][_0x36327c(0x1d3)]();const _0x3b6e83=_0xf7adcb[_0x36327c(0x1d9)];return{'username':_0x196317,'password':_0x3b6e83};}catch(_0x1f1c76){_0x1f1c76['isTtyError']?logError(_0x36327c(0x1d0)):logError(_0x36327c(0x1ce)+_0x1f1c76[_0x36327c(0x1d2)]);throw _0x1f1c76;}}async function interactiveAuth(){return await getCredentials();}module[a5_0x5319b5(0x1dd)]={'getCredentials':getCredentials,'interactiveAuth':interactiveAuth};