ultima chance
This commit is contained in:
+76
-14
@@ -367,25 +367,54 @@ fn load_csv_targets(file: Option<&Path>, inline: Option<&str>) -> Result<Vec<Str
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(file) = file {
|
if let Some(file) = file {
|
||||||
let content = fs::read_to_string(file)
|
match fs::read_to_string(file) {
|
||||||
.with_context(|| format!("failed to read CSV file {}", file.display()))?;
|
Ok(content) => {
|
||||||
let targets = parse_csv_targets(&content);
|
let targets = parse_csv_targets(&content);
|
||||||
if !targets.is_empty() {
|
if !targets.is_empty() {
|
||||||
return Ok(targets);
|
return Ok(targets);
|
||||||
|
}
|
||||||
|
return Err(anyhow!("arquivo CSV vazio: {}", file.display()));
|
||||||
|
}
|
||||||
|
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
|
||||||
|
let targets = parse_csv_targets(include_str!("../camfinder-open-rtsp.csv"));
|
||||||
|
if !targets.is_empty() {
|
||||||
|
return Ok(targets);
|
||||||
|
}
|
||||||
|
return Err(anyhow!(
|
||||||
|
"arquivo CSV padrão embutido vazio: ../camfinder-open-rtsp.csv"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
return Err(anyhow!(err))
|
||||||
|
.with_context(|| format!("failed to read CSV file {}", file.display()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Err(anyhow!("arquivo CSV vazio: {}", file.display()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(path) = env::var("RTSP_TARGETS_FILE") {
|
if let Ok(path) = env::var("RTSP_TARGETS_FILE") {
|
||||||
let path = path.trim();
|
let path = path.trim();
|
||||||
if !path.is_empty() {
|
if !path.is_empty() {
|
||||||
let content = fs::read_to_string(path)
|
match fs::read_to_string(path) {
|
||||||
.with_context(|| format!("failed to read CSV file {path}"))?;
|
Ok(content) => {
|
||||||
let targets = parse_csv_targets(&content);
|
let targets = parse_csv_targets(&content);
|
||||||
if !targets.is_empty() {
|
if !targets.is_empty() {
|
||||||
return Ok(targets);
|
return Ok(targets);
|
||||||
|
}
|
||||||
|
return Err(anyhow!("arquivo CSV vazio: {path}"));
|
||||||
|
}
|
||||||
|
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
|
||||||
|
let targets = parse_csv_targets(include_str!("../camfinder-open-rtsp.csv"));
|
||||||
|
if !targets.is_empty() {
|
||||||
|
return Ok(targets);
|
||||||
|
}
|
||||||
|
return Err(anyhow!(
|
||||||
|
"arquivo CSV padrão embutido vazio: ../camfinder-open-rtsp.csv"
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
return Err(err).with_context(|| format!("failed to read CSV file {path}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Err(anyhow!("arquivo CSV vazio: {path}"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -449,7 +478,20 @@ fn load_rtsp_paths(file: Option<&Path>, inline: Option<&str>) -> Result<Vec<Stri
|
|||||||
if let Ok(path) = env::var("RTSP_PATHS_FILE") {
|
if let Ok(path) = env::var("RTSP_PATHS_FILE") {
|
||||||
let path = path.trim();
|
let path = path.trim();
|
||||||
if !path.is_empty() {
|
if !path.is_empty() {
|
||||||
return load_rtsp_paths_from_file(Path::new(path));
|
return match load_rtsp_paths_from_file(Path::new(path)) {
|
||||||
|
Ok(paths) => Ok(paths),
|
||||||
|
Err(err) if is_not_found(&err) => {
|
||||||
|
let paths = parse_rtsp_paths(include_str!("../rtsp_paths.txt"));
|
||||||
|
if !paths.is_empty() {
|
||||||
|
Ok(paths)
|
||||||
|
} else {
|
||||||
|
Err(anyhow!(
|
||||||
|
"arquivo de paths RTSP padrão embutido vazio: ../rtsp_paths.txt"
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,7 +505,20 @@ fn load_rtsp_paths(file: Option<&Path>, inline: Option<&str>) -> Result<Vec<Stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
load_rtsp_paths_from_file(Path::new("/app/rtsp_paths.txt"))
|
match load_rtsp_paths_from_file(Path::new("/app/rtsp_paths.txt")) {
|
||||||
|
Ok(paths) => Ok(paths),
|
||||||
|
Err(err) if is_not_found(&err) => {
|
||||||
|
let paths = parse_rtsp_paths(include_str!("../rtsp_paths.txt"));
|
||||||
|
if !paths.is_empty() {
|
||||||
|
Ok(paths)
|
||||||
|
} else {
|
||||||
|
Err(anyhow!(
|
||||||
|
"arquivo de paths RTSP padrão embutido vazio: ../rtsp_paths.txt"
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_rtsp_paths_from_file(file: &Path) -> Result<Vec<String>> {
|
fn load_rtsp_paths_from_file(file: &Path) -> Result<Vec<String>> {
|
||||||
@@ -476,6 +531,13 @@ fn load_rtsp_paths_from_file(file: &Path) -> Result<Vec<String>> {
|
|||||||
Err(anyhow!("arquivo de paths RTSP vazio: {}", file.display()))
|
Err(anyhow!("arquivo de paths RTSP vazio: {}", file.display()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_not_found(err: &anyhow::Error) -> bool {
|
||||||
|
err.chain()
|
||||||
|
.find_map(|cause| cause.downcast_ref::<std::io::Error>())
|
||||||
|
.map(|err| err.kind() == std::io::ErrorKind::NotFound)
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_rtsp_paths(input: &str) -> Vec<String> {
|
fn parse_rtsp_paths(input: &str) -> Vec<String> {
|
||||||
let mut seen = std::collections::HashSet::new();
|
let mut seen = std::collections::HashSet::new();
|
||||||
input
|
input
|
||||||
|
|||||||
+20
-4
@@ -548,8 +548,15 @@ async fn sqlite_exec(sqlite_path: &Path, sql: &str) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn load_ip_list(input: &str) -> Result<Vec<String>> {
|
fn load_ip_list(input: &str) -> Result<Vec<String>> {
|
||||||
let content =
|
let content = match fs::read_to_string(input) {
|
||||||
fs::read_to_string(input).with_context(|| format!("failed to read input CSV {input}"))?;
|
Ok(content) => content,
|
||||||
|
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
|
||||||
|
include_str!("../camfinder-open-rtsp.csv").to_string()
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
return Err(anyhow!(err)).with_context(|| format!("failed to read input CSV {input}"));
|
||||||
|
}
|
||||||
|
};
|
||||||
let mut ips = Vec::new();
|
let mut ips = Vec::new();
|
||||||
|
|
||||||
for line in content.lines() {
|
for line in content.lines() {
|
||||||
@@ -682,8 +689,17 @@ impl RtspCredential {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn load_rtsp_credentials(path: &Path) -> Result<Vec<RtspCredential>> {
|
fn load_rtsp_credentials(path: &Path) -> Result<Vec<RtspCredential>> {
|
||||||
let content = fs::read_to_string(path)
|
let content = match fs::read_to_string(path) {
|
||||||
.with_context(|| format!("failed to read RTSP credential file {}", path.display()))?;
|
Ok(content) => content,
|
||||||
|
Err(err) if err.kind() == std::io::ErrorKind::NotFound => {
|
||||||
|
include_str!("../main_ids.json").to_string()
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
return Err(anyhow!(err)).with_context(|| {
|
||||||
|
format!("failed to read RTSP credential file {}", path.display())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
let usernames = parse_json_string_array(&content, "usernames")?;
|
let usernames = parse_json_string_array(&content, "usernames")?;
|
||||||
let passwords = parse_json_string_array(&content, "passwords")?;
|
let passwords = parse_json_string_array(&content, "passwords")?;
|
||||||
Ok(build_rtsp_credentials(&usernames, &passwords))
|
Ok(build_rtsp_credentials(&usernames, &passwords))
|
||||||
|
|||||||
Reference in New Issue
Block a user