logmon-cli 1.0.15 → 1.0.18
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/index.js +23 -130
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,161 +1,54 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { execSync } = require('child_process');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const os = require('os');
|
|
7
|
-
const readline = require('readline');
|
|
8
4
|
const pkg = require('./package.json');
|
|
9
5
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// 전체 인자 중 'uninstall'이 포함되어 있는지 견고하게 확인
|
|
6
|
+
// 전체 인자 중 'uninstall'이 포함되어 있는지 확인
|
|
13
7
|
const isUninstall = process.argv.some(arg => arg.toLowerCase().includes('uninstall'));
|
|
14
8
|
|
|
15
|
-
function checkBackendHealth(url) {
|
|
16
|
-
return new Promise((resolve) => {
|
|
17
|
-
const matches = url.match(/https?:\/\/([^:/]+)(?::(\d+))?/);
|
|
18
|
-
if (!matches) {
|
|
19
|
-
resolve(false);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const host = matches[1];
|
|
23
|
-
const port = matches[2] || 80;
|
|
24
|
-
const path = '/api/health';
|
|
25
|
-
|
|
26
|
-
const req = http.get({ host, port, path, timeout: 500 }, (res) => {
|
|
27
|
-
resolve(res.statusCode === 200);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
req.on('error', () => {
|
|
31
|
-
resolve(false);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
req.on('timeout', () => {
|
|
35
|
-
req.destroy();
|
|
36
|
-
resolve(false);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getSavedConfig() {
|
|
42
|
-
const homeDir = os.homedir();
|
|
43
|
-
const unixConfigPath = path.join(homeDir, '.logmon_agent', 'logmon_config.json');
|
|
44
|
-
const winConfigPath = path.join(homeDir, '.logmon_config.json');
|
|
45
|
-
|
|
46
|
-
if (fs.existsSync(unixConfigPath)) {
|
|
47
|
-
try {
|
|
48
|
-
return JSON.parse(fs.readFileSync(unixConfigPath, 'utf8'));
|
|
49
|
-
} catch (e) {}
|
|
50
|
-
}
|
|
51
|
-
if (fs.existsSync(winConfigPath)) {
|
|
52
|
-
try {
|
|
53
|
-
return JSON.parse(fs.readFileSync(winConfigPath, 'utf8'));
|
|
54
|
-
} catch (e) {}
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function askQuestion(query) {
|
|
60
|
-
const rl = readline.createInterface({
|
|
61
|
-
input: process.stdin,
|
|
62
|
-
output: process.stdout,
|
|
63
|
-
});
|
|
64
|
-
return new Promise((resolve) => rl.question(query, (ans) => {
|
|
65
|
-
rl.close();
|
|
66
|
-
resolve(ans);
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
9
|
async function run() {
|
|
71
|
-
// 버전 확인 파라미터 체크
|
|
10
|
+
// 버전 확인 파라미터 체크 (-v, --version)
|
|
72
11
|
const isVersion = process.argv.includes('--version') || process.argv.includes('-v') || process.argv.includes('version');
|
|
73
12
|
if (isVersion) {
|
|
74
13
|
console.log(`logmon v${pkg.version}`);
|
|
75
14
|
process.exit(0);
|
|
76
15
|
}
|
|
77
16
|
|
|
78
|
-
|
|
79
|
-
|
|
17
|
+
// [인프라 일원화] 우리 서버의 안전한 공식 SSL 도메인 관문 고정
|
|
18
|
+
const BASE_URL = "https://logmon.haroo.site";
|
|
80
19
|
|
|
81
|
-
//
|
|
82
|
-
const savedConfig = getSavedConfig();
|
|
83
|
-
if (savedConfig) {
|
|
84
|
-
if (savedConfig.api_key) apiKey = savedConfig.api_key;
|
|
85
|
-
if (savedConfig.backend_url) backendUrl = savedConfig.backend_url;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// HTTP/HTTPS 프로토콜로 시작하는 인자 검색
|
|
89
|
-
const foundUrl = process.argv.find(arg => arg.startsWith('http://') || arg.startsWith('https://'));
|
|
90
|
-
|
|
91
|
-
if (isUninstall) {
|
|
92
|
-
backendUrl = foundUrl || process.env.BACKEND_URL || backendUrl;
|
|
93
|
-
} else {
|
|
94
|
-
// 설치 시
|
|
95
|
-
const firstArg = process.argv[2];
|
|
96
|
-
if (firstArg && !firstArg.startsWith('http://') && !firstArg.startsWith('https://') && firstArg !== 'uninstall') {
|
|
97
|
-
apiKey = firstArg;
|
|
98
|
-
} else {
|
|
99
|
-
apiKey = process.env.API_KEY || apiKey;
|
|
100
|
-
}
|
|
101
|
-
backendUrl = foundUrl || process.env.BACKEND_URL || backendUrl;
|
|
102
|
-
|
|
103
|
-
// 자동 감지(Auto-detect) 및 덮어쓰기 로직 (유저 타이핑 완전 제거)
|
|
104
|
-
if (!foundUrl && !process.env.BACKEND_URL && process.env.LOGMON_TEST_MODE !== 'true') {
|
|
105
|
-
const is3008Healthy = await checkBackendHealth("http://localhost:3008");
|
|
106
|
-
if (is3008Healthy) {
|
|
107
|
-
backendUrl = "http://localhost:3008/api/logmon";
|
|
108
|
-
} else {
|
|
109
|
-
const is8000Healthy = await checkBackendHealth("http://localhost:8000");
|
|
110
|
-
if (is8000Healthy) {
|
|
111
|
-
backendUrl = "http://localhost:8000/api/logmon";
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// 터미널 화면 보안 세척
|
|
20
|
+
// 터미널 화면 깔끔하게 청소
|
|
118
21
|
process.stdout.write('\x1Bc');
|
|
119
22
|
|
|
120
|
-
// 설치인 경우에만 상단 타이틀을 띄워 중복 방지
|
|
121
23
|
if (!isUninstall) {
|
|
122
24
|
console.log('===============================================');
|
|
123
|
-
console.log(' 👾 LogMon CLI 에이전트
|
|
25
|
+
console.log(' 👾 LogMon CLI 에이전트 자동 설치기 (No-Input)');
|
|
26
|
+
console.log('===============================================');
|
|
27
|
+
console.log('🔄 서버로부터 개인화된 보안 설정을 동기화하는 중...');
|
|
28
|
+
} else {
|
|
29
|
+
console.log('===============================================');
|
|
30
|
+
console.log(' Clean Cap 🧹 Logmon Agent 제거 마법사');
|
|
124
31
|
console.log('===============================================');
|
|
125
32
|
}
|
|
126
33
|
|
|
127
34
|
try {
|
|
128
35
|
if (isUninstall) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
console.log(' 🧹 Logmon Agent 제거 마법사 (macOS/Linux) ');
|
|
133
|
-
console.log('===============================================');
|
|
134
|
-
console.log('\n🔄 macOS LaunchAgent(com.logmon.agent) 데몬을 중지합니다...');
|
|
135
|
-
console.log('🗑️ PLIST 파일이 제거되었습니다.');
|
|
136
|
-
console.log('\n✨ Logmon 에이전트가 시스템에서 완전히 제거되었습니다!');
|
|
137
|
-
} else {
|
|
138
|
-
execSync(uninstallCmd, { stdio: 'inherit' });
|
|
139
|
-
}
|
|
36
|
+
// [★ 영구 패치 완료] 정적 파일 간섭을 완전히 배제하기 위해 백엔드 스트리밍 전용 API 주소로 전격 전환!
|
|
37
|
+
const uninstallCmd = `curl -sL ${BASE_URL}/api/logmon/agent-uninstall-script | bash`;
|
|
38
|
+
execSync(uninstallCmd, { stdio: 'inherit' });
|
|
140
39
|
} else {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
console.log(' > 보안 인증: 매핑 완료! ✓\n');
|
|
145
|
-
console.log('✅ 설정 및 최신 에이전트 코드 동기화 완료! ✓');
|
|
146
|
-
console.log('🍎 macOS LaunchAgent 등록 완료 (5분 주기 실행)');
|
|
147
|
-
} else {
|
|
148
|
-
execSync(installCmd, { stdio: 'inherit' });
|
|
149
|
-
}
|
|
40
|
+
// [핵심] 정적 파일이 아닌, 백엔드가 키를 동적으로 구워내는 '라우터 API'를 직접 파이프로 실행!
|
|
41
|
+
const installCmd = `curl -sL ${BASE_URL}/api/logmon/agent-setup-script | bash`;
|
|
42
|
+
execSync(installCmd, { stdio: 'inherit' });
|
|
150
43
|
|
|
151
|
-
console.log('\n🎉 Logmon 로컬 수집기
|
|
152
|
-
console.log(`
|
|
44
|
+
console.log('\n🎉 Logmon 로컬 수집기 동기화가 완전히 끝났습니다!');
|
|
45
|
+
console.log(` 제거를 원하시면: npx logmon-cli uninstall\n`);
|
|
153
46
|
console.log(' /\\_/\\ ');
|
|
154
47
|
console.log(' (。・ω・。)つ━☆・*。');
|
|
155
|
-
console.log(' ⊂
|
|
156
|
-
console.log('
|
|
48
|
+
console.log(' ⊂ | ・゜+. 🐾 LogMon Agent is Watching You!');
|
|
49
|
+
console.log(' しーJ °。+ *´`');
|
|
157
50
|
console.log('===============================================');
|
|
158
|
-
console.log(` [ System Build: v${pkg.version} /
|
|
51
|
+
console.log(` [ System Build: v${pkg.version} / Powered by SSL ]`);
|
|
159
52
|
console.log('===============================================');
|
|
160
53
|
}
|
|
161
54
|
} catch (error) {
|
|
@@ -164,4 +57,4 @@ async function run() {
|
|
|
164
57
|
}
|
|
165
58
|
}
|
|
166
59
|
|
|
167
|
-
run();
|
|
60
|
+
run();
|