@onxdev/silentium 0.0.0-stage → 0.1.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/Cargo.lock +1122 -0
- package/Cargo.toml +36 -0
- package/LICENSE +21 -0
- package/README.md +54 -2
- package/npm/bin/silentium.js +45 -0
- package/npm/install.js +31 -0
- package/npm/lib.js +220 -0
- package/package.json +44 -4
- package/rust-toolchain.toml +2 -0
- package/src/cli.rs +140 -0
- package/src/detect.rs +248 -0
- package/src/discord.rs +273 -0
- package/src/main.rs +345 -0
- package/src/net.rs +371 -0
- package/src/ui.rs +373 -0
package/src/ui.rs
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
// rust — src/ui.rs — tela inicial: banner, diagnóstico local e menu interativo
|
|
2
|
+
use crate::cli::{Cli, TargetArgs, VoiceCmd};
|
|
3
|
+
use crate::detect;
|
|
4
|
+
use anyhow::Result;
|
|
5
|
+
use std::io::{self, IsTerminal, Write};
|
|
6
|
+
use std::process::Command;
|
|
7
|
+
|
|
8
|
+
const ACCENT: &str = "\x1b[38;5;111m";
|
|
9
|
+
const OK: &str = "\x1b[38;5;114m";
|
|
10
|
+
const WARN: &str = "\x1b[38;5;179m";
|
|
11
|
+
const BAD: &str = "\x1b[38;5;203m";
|
|
12
|
+
const DIM: &str = "\x1b[2m";
|
|
13
|
+
const BOLD: &str = "\x1b[1m";
|
|
14
|
+
const OFF: &str = "\x1b[0m";
|
|
15
|
+
|
|
16
|
+
const BANNER: [&str; 6] = [
|
|
17
|
+
"██████╗ ██╗ ██╗ ██████╗ ███╗ ██╗ ████████╗ ██╗ ██╗ ██╗ ███╗ ███╗",
|
|
18
|
+
"██╔═══╝ ██║ ██║ ██╔═══╝ ████╗ ██║ ╚══██╔══╝ ██║ ██║ ██║ ████╗ ████║",
|
|
19
|
+
"██████╗ ██║ ██║ █████╗ ██╔██╗ ██║ ██║ ██║ ██║ ██║ ██╔████╔██║",
|
|
20
|
+
"╚═══██║ ██║ ██║ ██╔══╝ ██║╚██╗██║ ██║ ██║ ██║ ██║ ██║╚██╔╝██║",
|
|
21
|
+
"██████║ ██║ ██████╗ ██████╗ ██║ ╚████║ ██║ ██║ ╚██████╔╝ ██║ ╚═╝ ██║",
|
|
22
|
+
"╚═════╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const MENU: [(&str, &str, &str); 7] = [
|
|
26
|
+
("1", "detectar call", "sockets locais, sem token"),
|
|
27
|
+
("2", "ver quem está em voz", "precisa de token"),
|
|
28
|
+
("3", "derrubar todos da call", "precisa de token"),
|
|
29
|
+
("4", "mutar todos", "precisa de token"),
|
|
30
|
+
("5", "ensurdecer todos", "precisa de token"),
|
|
31
|
+
("6", "restaurar todos", "desfaz mute e deafen"),
|
|
32
|
+
("7", "cortar internet do Discord", "precisa de root"),
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
pub fn interactive(cli: &Cli) -> Result<()> {
|
|
36
|
+
let color = io::stdout().is_terminal();
|
|
37
|
+
banner(color);
|
|
38
|
+
status(cli, color);
|
|
39
|
+
|
|
40
|
+
if !io::stdin().is_terminal() {
|
|
41
|
+
println!(
|
|
42
|
+
"\n{}sem terminal interativo — use silentium --help para todos os comandos{}",
|
|
43
|
+
dim(color),
|
|
44
|
+
reset(color)
|
|
45
|
+
);
|
|
46
|
+
return Ok(());
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
menu(color);
|
|
50
|
+
loop {
|
|
51
|
+
print!("\n{}silentium ›{} ", accent(color), reset(color));
|
|
52
|
+
io::stdout().flush()?;
|
|
53
|
+
|
|
54
|
+
let Some(line) = read_line()? else {
|
|
55
|
+
break;
|
|
56
|
+
};
|
|
57
|
+
let choice = line.trim().to_ascii_lowercase();
|
|
58
|
+
if choice.is_empty() {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if matches!(choice.as_str(), "q" | "quit" | "sair" | "exit") {
|
|
62
|
+
println!("{}até.{}", dim(color), reset(color));
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
println!();
|
|
67
|
+
match choice.as_str() {
|
|
68
|
+
"1" => {
|
|
69
|
+
crate::print_detect()?;
|
|
70
|
+
}
|
|
71
|
+
"2" => voice(cli, VoiceCmd::List(TargetArgs::default()))?,
|
|
72
|
+
"3" => voice(cli, VoiceCmd::Drop(TargetArgs::default()))?,
|
|
73
|
+
"4" => voice(cli, VoiceCmd::Mute(TargetArgs::default()))?,
|
|
74
|
+
"5" => voice(cli, VoiceCmd::Deafen(TargetArgs::default()))?,
|
|
75
|
+
"6" => voice(cli, VoiceCmd::Restore(TargetArgs::default()))?,
|
|
76
|
+
"7" => cut_discord(color)?,
|
|
77
|
+
"?" | "h" | "help" => help_hint(color),
|
|
78
|
+
other => println!(
|
|
79
|
+
"{}opção desconhecida: {}{}",
|
|
80
|
+
bad(color),
|
|
81
|
+
other,
|
|
82
|
+
reset(color)
|
|
83
|
+
),
|
|
84
|
+
}
|
|
85
|
+
menu(color);
|
|
86
|
+
}
|
|
87
|
+
Ok(())
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
fn banner(color: bool) {
|
|
91
|
+
println!();
|
|
92
|
+
for line in BANNER {
|
|
93
|
+
println!(" {}{}{}", accent(color), line, reset(color));
|
|
94
|
+
}
|
|
95
|
+
println!(
|
|
96
|
+
" {}kill switch de voz para Discord · v{}{}",
|
|
97
|
+
bold(color),
|
|
98
|
+
env!("CARGO_PKG_VERSION"),
|
|
99
|
+
reset(color)
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fn status(cli: &Cli, color: bool) {
|
|
104
|
+
println!();
|
|
105
|
+
row(color, "sistema", &platform_line());
|
|
106
|
+
row(color, "discord", &discord_line(color));
|
|
107
|
+
row(color, "call", &call_line(color));
|
|
108
|
+
row(color, "token", &token_line(cli, color));
|
|
109
|
+
row(color, "guild", &guild_line(cli, color));
|
|
110
|
+
row(color, "firewall", &privilege_line(color));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fn row(color: bool, label: &str, value: &str) {
|
|
114
|
+
println!(" {}{:<9}{} {}", dim(color), label, reset(color), value);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fn dot(color: bool, on: bool) -> String {
|
|
118
|
+
if on {
|
|
119
|
+
format!("{}{}●{}", ok(color), "", reset(color))
|
|
120
|
+
} else {
|
|
121
|
+
format!("{}○{}", dim(color), reset(color))
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
fn platform_line() -> String {
|
|
126
|
+
let arch = format!("{}-{}", std::env::consts::OS, std::env::consts::ARCH);
|
|
127
|
+
#[cfg(unix)]
|
|
128
|
+
{
|
|
129
|
+
let uid = Command::new("id").arg("-u").output().ok().and_then(|o| {
|
|
130
|
+
String::from_utf8_lossy(&o.stdout)
|
|
131
|
+
.trim()
|
|
132
|
+
.parse::<u32>()
|
|
133
|
+
.ok()
|
|
134
|
+
});
|
|
135
|
+
match uid {
|
|
136
|
+
Some(0) => format!("{arch} · uid 0 (root)"),
|
|
137
|
+
Some(uid) => format!("{arch} · uid {uid}"),
|
|
138
|
+
None => arch,
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
#[cfg(not(unix))]
|
|
142
|
+
{
|
|
143
|
+
arch
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
fn discord_line(color: bool) -> String {
|
|
148
|
+
match detect::discord_running() {
|
|
149
|
+
Some(pid) => format!("{} rodando — pid {pid}", dot(color, true)),
|
|
150
|
+
None => format!("{} não encontrado", dot(color, false)),
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
fn call_line(color: bool) -> String {
|
|
155
|
+
match detect::voice_peers() {
|
|
156
|
+
Ok(peers) => {
|
|
157
|
+
let voice: Vec<_> = peers.iter().filter(|p| p.is_voice()).collect();
|
|
158
|
+
if voice.is_empty() {
|
|
159
|
+
format!("{} nenhuma call ativa", dot(color, false))
|
|
160
|
+
} else {
|
|
161
|
+
let ports: Vec<String> = voice.iter().map(|p| p.port.to_string()).take(4).collect();
|
|
162
|
+
format!(
|
|
163
|
+
"{} ativa — {} socket(s) de mídia ({}{})",
|
|
164
|
+
dot(color, true),
|
|
165
|
+
voice.len(),
|
|
166
|
+
ports.join(", "),
|
|
167
|
+
if voice.len() > 4 { ", …" } else { "" }
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
Err(_) => format!("{} não verificável (ss indisponível)", dot(color, false)),
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
fn token_line(cli: &Cli, color: bool) -> String {
|
|
176
|
+
match &cli.token {
|
|
177
|
+
Some(t) => format!(
|
|
178
|
+
"{} definido ({}…{})",
|
|
179
|
+
dot(color, true),
|
|
180
|
+
t.chars().take(4).collect::<String>(),
|
|
181
|
+
if cli.user_token { ", user token" } else { "" }
|
|
182
|
+
),
|
|
183
|
+
None => format!("{} DISCORD_TOKEN não definido", dot(color, false)),
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
fn guild_line(cli: &Cli, color: bool) -> String {
|
|
188
|
+
match &cli.guild {
|
|
189
|
+
Some(g) => format!("{} {g}", dot(color, true)),
|
|
190
|
+
None => format!("{} --guild não definido (use --invite)", dot(color, false)),
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
fn privilege_line(color: bool) -> String {
|
|
195
|
+
if is_root() {
|
|
196
|
+
format!(
|
|
197
|
+
"{} privilegiado — pode cortar e moldar tráfego",
|
|
198
|
+
dot(color, true)
|
|
199
|
+
)
|
|
200
|
+
} else {
|
|
201
|
+
format!("{} sem privilégio — net só com sudo", dot(color, false))
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
fn is_root() -> bool {
|
|
206
|
+
#[cfg(unix)]
|
|
207
|
+
{
|
|
208
|
+
Command::new("id")
|
|
209
|
+
.arg("-u")
|
|
210
|
+
.output()
|
|
211
|
+
.ok()
|
|
212
|
+
.map(|o| String::from_utf8_lossy(&o.stdout).trim() == "0")
|
|
213
|
+
.unwrap_or(false)
|
|
214
|
+
}
|
|
215
|
+
#[cfg(not(unix))]
|
|
216
|
+
{
|
|
217
|
+
false
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
fn menu(color: bool) {
|
|
222
|
+
println!("\n {}menu{}", bold(color), reset(color));
|
|
223
|
+
for (key, label, hint) in MENU {
|
|
224
|
+
println!(
|
|
225
|
+
" {}{:>2}{} {:<28} {}{}{}",
|
|
226
|
+
accent(color),
|
|
227
|
+
key,
|
|
228
|
+
reset(color),
|
|
229
|
+
label,
|
|
230
|
+
dim(color),
|
|
231
|
+
hint,
|
|
232
|
+
reset(color)
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
println!(
|
|
236
|
+
" {}{:>2}{} {:<28} {}todos os comandos e flags{}",
|
|
237
|
+
dim(color),
|
|
238
|
+
"?",
|
|
239
|
+
reset(color),
|
|
240
|
+
"ajuda completa",
|
|
241
|
+
dim(color),
|
|
242
|
+
reset(color)
|
|
243
|
+
);
|
|
244
|
+
println!(
|
|
245
|
+
" {}{:>2}{} {:<28} {}encerra o menu{}",
|
|
246
|
+
dim(color),
|
|
247
|
+
"q",
|
|
248
|
+
reset(color),
|
|
249
|
+
"sair",
|
|
250
|
+
dim(color),
|
|
251
|
+
reset(color)
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
fn help_hint(color: bool) {
|
|
256
|
+
println!(
|
|
257
|
+
"{}silentium --help{} lista comandos",
|
|
258
|
+
dim(color),
|
|
259
|
+
reset(color)
|
|
260
|
+
);
|
|
261
|
+
println!(
|
|
262
|
+
"{}silentium voice list --invite discord.gg/xxx{}",
|
|
263
|
+
dim(color),
|
|
264
|
+
reset(color)
|
|
265
|
+
);
|
|
266
|
+
println!(
|
|
267
|
+
"{}silentium net auto --seconds 30{}",
|
|
268
|
+
dim(color),
|
|
269
|
+
reset(color)
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
fn voice(cli: &Cli, cmd: VoiceCmd) -> Result<()> {
|
|
274
|
+
if cli.token.is_none() {
|
|
275
|
+
println!(
|
|
276
|
+
"{}token ausente — exporte DISCORD_TOKEN ou use --token{}",
|
|
277
|
+
warn(color_or_off()),
|
|
278
|
+
reset(color_or_off())
|
|
279
|
+
);
|
|
280
|
+
return Ok(());
|
|
281
|
+
}
|
|
282
|
+
crate::voice_dispatch(cli, &cmd)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
fn cut_discord(color: bool) -> Result<()> {
|
|
286
|
+
if !is_root() {
|
|
287
|
+
println!(
|
|
288
|
+
"{}sem privilégio.{} isso mexe no firewall — rode com sudo: {}sudo silentium{}",
|
|
289
|
+
warn(color),
|
|
290
|
+
reset(color),
|
|
291
|
+
bold(color),
|
|
292
|
+
reset(color)
|
|
293
|
+
);
|
|
294
|
+
return Ok(());
|
|
295
|
+
}
|
|
296
|
+
println!(
|
|
297
|
+
"{}cortando o Discord por processo…{}",
|
|
298
|
+
dim(color),
|
|
299
|
+
reset(color)
|
|
300
|
+
);
|
|
301
|
+
crate::net::block()?;
|
|
302
|
+
println!(
|
|
303
|
+
"{}internet do Discord cortada.{} Enter restaura.",
|
|
304
|
+
warn(color),
|
|
305
|
+
reset(color)
|
|
306
|
+
);
|
|
307
|
+
let _ = read_line()?;
|
|
308
|
+
crate::net::unblock()?;
|
|
309
|
+
Ok(())
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
fn read_line() -> Result<Option<String>> {
|
|
313
|
+
let mut buf = String::new();
|
|
314
|
+
let read = io::stdin().read_line(&mut buf)?;
|
|
315
|
+
if read == 0 {
|
|
316
|
+
return Ok(None);
|
|
317
|
+
}
|
|
318
|
+
Ok(Some(buf))
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
fn color_or_off() -> bool {
|
|
322
|
+
io::stdout().is_terminal()
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
fn accent(on: bool) -> &'static str {
|
|
326
|
+
if on {
|
|
327
|
+
ACCENT
|
|
328
|
+
} else {
|
|
329
|
+
""
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
fn ok(on: bool) -> &'static str {
|
|
333
|
+
if on {
|
|
334
|
+
OK
|
|
335
|
+
} else {
|
|
336
|
+
""
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
fn warn(on: bool) -> &'static str {
|
|
340
|
+
if on {
|
|
341
|
+
WARN
|
|
342
|
+
} else {
|
|
343
|
+
""
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
fn bad(on: bool) -> &'static str {
|
|
347
|
+
if on {
|
|
348
|
+
BAD
|
|
349
|
+
} else {
|
|
350
|
+
""
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
fn dim(on: bool) -> &'static str {
|
|
354
|
+
if on {
|
|
355
|
+
DIM
|
|
356
|
+
} else {
|
|
357
|
+
""
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
fn bold(on: bool) -> &'static str {
|
|
361
|
+
if on {
|
|
362
|
+
BOLD
|
|
363
|
+
} else {
|
|
364
|
+
""
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
fn reset(on: bool) -> &'static str {
|
|
368
|
+
if on {
|
|
369
|
+
OFF
|
|
370
|
+
} else {
|
|
371
|
+
""
|
|
372
|
+
}
|
|
373
|
+
}
|