Fix the UI code not displaying any channel names
use crate::models::ChannelInfo;
use crate::models::PatternGroup;
use colored::ColoredString;
use colored::Colorize;
use crossterm::style::Stylize;
use prettytable::{row, Table};
use tui::text::Span;
use tui::text::Spans;
use std::io;
use tui::{
backend::CrosstermBackend,
layout::{Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
widgets::{Block, Borders, Cell, Paragraph, Row as TuiRow, Table as TuiTable, Tabs},
Frame, Terminal,
};
pub fn run_ui(patterns: Vec, channels: Vec) -> Result<(), io::Error> {
// Set up terminal
let stdout = io::stdout();
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
// Create app and run it
let app = App::new(patterns, channels);
let res = tui_run(&mut terminal, app);
// Restore terminal
terminal.show_cursor()?;
res
let paragraph = Paragraph::new(format!(
"Total Valid Channels: {}\nChannels with 'feature' in their name: {}",
total_channels, feature_channels
))
.block(Block::default().borders(Borders::ALL).title("Overview"));
f.render_widget(paragraph, area);
let text = app.patterns.iter().fold(String::new(), |acc, pattern| {
format!(
"{}Pattern: {}\nChannels: {}\n\n",
acc,
pattern.pattern.clone().bold().underlined(),
pattern.channels.join(", ")
)
});
let paragraph = Paragraph::new(text)
.block(Block::default())
.wrap(tui::widgets::Wrap { trim: true });
f.render_widget(paragraph, inner);
}
mod checker;
mod cli;
mod errors;
mod models;
mod pattern;
mod ui;
use checker::check_channel;
use cli::parse_args;
use errors::AppError;
use indicatif::{ProgressBar, ProgressStyle};
use itertools::Itertools;
use models::ChannelInfo;
use rayon::prelude::*;
use reqwest::blocking::Client;
use std::collections::HashSet;
use std::fs;
use std::io::{self, BufRead};
use std::path::Path;
use std::time::Duration;
use tracing::{error, info};
use tracing_subscriber::fmt::format::FmtSpan;
use ui::run_ui;
use rand::{thread_rng, Rng};
use rand::distributions::Alphanumeric;
// Parse command-line arguments
let matches = parse_args();
// Set verbosity
if matches.get_one::<String>("verbose").is_some() {
tracing::subscriber::with_default(tracing_subscriber::fmt::Subscriber::new(), || {
info!("Verbose mode enabled");
});
}
// Read wordlist from file or stdin
let wordlist = if let Some(input_path) = matches.get_one::<String>("input") {
read_wordlist_from_file(input_path)?
} else {
info!("Reading wordlist from stdin. Enter words followed by Enter. Press Ctrl+D (Unix) or Ctrl+Z (Windows) to finish:");
read_wordlist_from_stdin()?
};
// Deduplicate wordlist
let mut unique_wordlist: Vec<String> = wordlist.into_iter().unique().collect();
unique_wordlist.sort();
// Wordlist Augmentation
if let Some(prefixes_str) = matches.get_one::<String>("prefixes") {
let prefixes: Vec<&str> = prefixes_str.split(',').collect();
augment_wordlist_with_prefixes(&mut unique_wordlist, &prefixes);
info!("Augmented wordlist with prefixes.");
}
if let Some(suffixes_str) = matches.get_one::<String>("suffixes") {
let suffixes: Vec<&str> = suffixes_str.split(',').collect();
augment_wordlist_with_suffixes(&mut unique_wordlist, &suffixes);
info!("Augmented wordlist with suffixes.");
}
if let Some(num_random_str) = matches.get_one::<String>("random-strings") {
let num_random: usize = num_random_str.parse().unwrap_or(0);
augment_wordlist_with_random_strings(&mut unique_wordlist, num_random);
info!("Augmented wordlist with {} random strings.", num_random);
}
if unique_wordlist.is_empty() {
error!("Wordlist is empty. Please provide at least one word.");
return Ok(());
}
info!("Generating combinations...");
let combinations = generate_combinations(&unique_wordlist);
info!("Total combinations generated: {}", combinations.len());
// Configure HTTP client
let timeout = matches
.get_one::<String>("timeout")
.unwrap()
.parse::<u64>()
.unwrap_or(10);
let client = Client::builder()
.timeout(Duration::from_secs(timeout))
.build()?;
// Setup progress bar
let pb = ProgressBar::new(combinations.len() as u64);
pb.set_style(
ProgressStyle::default_bar()
.template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({eta})")
.unwrap()
.progress_chars("#>-"),
);
let concurrency = matches
.get_one::<String>("concurrency")
.unwrap()
.parse::<usize>()
.unwrap_or(8);
rayon::ThreadPoolBuilder::new()
.num_threads(concurrency)
.build_global()
.unwrap();
info!("Starting channel checks with concurrency level: {}", concurrency);
// Process combinations in parallel
let results: Vec<ChannelInfo> = combinations
.par_iter()
.map(|combination| {
let result = check_channel(&client, combination);
pb.inc(1);
result
})
.filter_map(|res| res)
.collect();
pb.finish_with_message("Channel checks completed.");
info!("Analyzing channel patterns...");
let patterns = pattern::analyze_patterns(&results.iter().map(|c| c.original_channel.clone()).collect::<Vec<_>>());
// Display results in advanced UI
run_ui(patterns.clone(), results.clone())?;
// Save results to file if output path is provided
if let Some(output_path) = matches.get_one::<String>("output") {
info!("Saving results to {}", output_path);
save_results_to_file(&results, output_path)?;
}
Ok(())
}
// Reads wordlist from a file
fn read_wordlist_from_file<P: AsRef>(path: P) -> Result<Vec, AppError> {
info!("Reading wordlist from file: {:?}", path.as_ref());
let file = fs::File::open(path)?;
let reader = io::BufReader::new(file);
let wordlist = reader
.lines()
.filter_map(Result::ok)
.filter(|line| !line.trim().is_empty())
.collect();
Ok(wordlist)
}
// Reads wordlist from standard input
fn read_wordlist_from_stdin() -> Result<Vec, AppError> {
let stdin = io::stdin();
let wordlist = stdin
.lock()
.lines()
.filter_map(Result::ok)
.filter(|line| !line.trim().is_empty())
.collect();
Ok(wordlist)
}
// Generates combinations of words
fn generate_combinations(wordlist: &[String]) -> HashSet {
let mut combinations = HashSet::new();
let max_combination_length = 3; // Adjust as needed
for length in 1..=max_combination_length {
for combo in wordlist.iter().permutations(length) {
let concatenated = combo.into_iter().join("");
combinations.insert(concatenated);
}
}
combinations
}
// Augments the wordlist with prefixes
fn augment_wordlist_with_prefixes(wordlist: &mut Vec, prefixes: &[&str]) {
let mut new_words = Vec::new();
for prefix in prefixes {
for word in wordlist.iter() {
new_words.push(format!("{}{}", prefix, word));
}
}
wordlist.append(&mut new_words);
}
// Augments the wordlist with suffixes
fn augment_wordlist_with_suffixes(wordlist: &mut Vec, suffixes: &[&str]) {
let mut new_words = Vec::new();
for suffix in suffixes {
for word in wordlist.iter() {
new_words.push(format!("{}{}", word, suffix));
}
}
wordlist.append(&mut new_words);
}
// Augments the wordlist with random strings
fn augment_wordlist_with_random_strings(wordlist: &mut Vec, num_strings: usize) {
let rng = thread_rng();
for _ in 0..num_strings {
let random_string: String = rng
.clone()
.sample_iter(&Alphanumeric)
.take(8) // Adjust the length of random strings as needed
.map(char::from)
.collect();
wordlist.push(random_string);
}
}
// Saves results to a JSON file
fn save_results_to_file(results: &[ChannelInfo], path: &str) -> Result<(), AppError> {
let json = serde_json::to_string_pretty(results)?;
fs::write(path, json)?;
Ok(())
}
use crate::{
errors::AppError,
models::ChannelInfo,
};
use colored::ColoredString;
use colored::Colorize;
use reqwest::blocking::Client;
use reqwest::StatusCode;
use retry::{delay::Exponential, retry};
use serde_json::Value;
use tracing::{debug, error, info};
use regex::Regex;
The issue you're experiencing—the UI not displaying any channel names—is likely due to how the current page state is managed within your application. Specifically, the App::next and App::previous methods update the selected index but do not update the page enum, which is used to determine which view to render. As a result, the UI may always render the Overview page, causing the Channels page (where channel names are displayed) to never be shown.
The UI rendering relies on the app.page to decide which view to display.
Problem Identified:
Since the page is never updated, the UI always renders the Overview page regardless of user navigation (e.g., pressing Tab to switch tabs). Therefore, the Channels page, which should display channel names, is never rendered, making it seem like channel names are not displayed.
Solution
To resolve this, ensure that the page is updated whenever the selected index changes. This synchronizes the navigation actions with the UI rendering logic.
Step-by-Step Fix
Update the next and previous Methods:
Modify these methods to update the page based on the new selected index.
Note: The selected index starts at 0, which corresponds to Page::Overview.
Optional Enhancements:
Display All Pages Initially for Testing:
To verify that other pages (like Channels) are rendering correctly, you can temporarily set the page directly in the App::new method. For example: