Pass XMPP password as file to xmppc if the version supports it
This commit is contained in:
parent
79730bd7df
commit
2e42778d2c
46
src/main.rs
46
src/main.rs
@ -14,6 +14,8 @@ struct AppState {
|
|||||||
listen: String,
|
listen: String,
|
||||||
receiver: String,
|
receiver: String,
|
||||||
jid: String,
|
jid: String,
|
||||||
|
supports_password_file: bool,
|
||||||
|
password_file: String,
|
||||||
password: String,
|
password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,6 +25,8 @@ impl AppState{
|
|||||||
listen: String::from("[::]:9199"),
|
listen: String::from("[::]:9199"),
|
||||||
receiver: String::from(""),
|
receiver: String::from(""),
|
||||||
jid: String::from(""),
|
jid: String::from(""),
|
||||||
|
supports_password_file: false,
|
||||||
|
password_file: String::from(""),
|
||||||
password: String::from(""),
|
password: String::from(""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,6 +97,7 @@ async fn main() {
|
|||||||
if password_file == String::from("") {
|
if password_file == String::from("") {
|
||||||
println!("--password-file not specified");
|
println!("--password-file not specified");
|
||||||
} else {
|
} else {
|
||||||
|
app_state.password_file = password_file.clone();
|
||||||
app_state.password = std::fs::read_to_string(password_file).unwrap().trim().to_string();
|
app_state.password = std::fs::read_to_string(password_file).unwrap().trim().to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +106,34 @@ async fn main() {
|
|||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut command = std::process::Command::new("xmppc");
|
||||||
|
command.arg("--help").stdout(std::process::Stdio::piped());
|
||||||
|
|
||||||
|
let mut child = match command.spawn() {
|
||||||
|
Ok(child) => child,
|
||||||
|
Err(_) => {
|
||||||
|
println!("ERROR: Error starting xmppc");
|
||||||
|
std::process::exit(1)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let status = match child.wait() {
|
||||||
|
Ok(status) => status,
|
||||||
|
Err(_) => {
|
||||||
|
println!("ERROR: Error executing xmppc");
|
||||||
|
std::process::exit(1)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
println!("ERROR: xmppc failed sending message");
|
||||||
|
std::process::exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if std::io::read_to_string(child.stdout.unwrap()).unwrap().contains("--pwd-file") {
|
||||||
|
app_state.supports_password_file = true;
|
||||||
|
}
|
||||||
|
|
||||||
let mut app = Router::new();
|
let mut app = Router::new();
|
||||||
app = app.route("/alert", post(alert));
|
app = app.route("/alert", post(alert));
|
||||||
|
|
||||||
@ -216,9 +249,16 @@ async fn alert(State(app_state): State<AppState>, Json(payload): Json<serde_json
|
|||||||
println!("{}", message);
|
println!("{}", message);
|
||||||
|
|
||||||
let mut command = std::process::Command::new("xmppc");
|
let mut command = std::process::Command::new("xmppc");
|
||||||
command.arg("--jid").arg(app_state.jid)
|
command.arg("--jid").arg(app_state.jid);
|
||||||
.arg("--pwd").arg(app_state.password)
|
|
||||||
.arg("--mode").arg("message")
|
if app_state.supports_password_file {
|
||||||
|
command.arg("--pwd-file").arg(app_state.password_file);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
command.arg("--pwd").arg(app_state.password);
|
||||||
|
}
|
||||||
|
|
||||||
|
command.arg("--mode").arg("message")
|
||||||
.arg("chat").arg(app_state.receiver).arg(message);
|
.arg("chat").arg(app_state.receiver).arg(message);
|
||||||
|
|
||||||
let mut child = match command.spawn() {
|
let mut child = match command.spawn() {
|
||||||
|
Loading…
Reference in New Issue
Block a user