Skip to content
Snippets Groups Projects
Commit 5165d381 authored by David Huss's avatar David Huss :speech_balloon:
Browse files

Multiple changes and fixes

- add chmod +x and systemctl restart to deploy script
- change the wording of some messages
- overhaul the eventhandler
parent b3a777f4
No related branches found
No related tags found
No related merge requests found
...@@ -1376,7 +1376,7 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" ...@@ -1376,7 +1376,7 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]] [[package]]
name = "sms-gateway" name = "sms-gateway"
version = "0.3.0" version = "0.3.2"
dependencies = [ dependencies = [
"actix-rt", "actix-rt",
"actix-web", "actix-web",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
name = "sms-gateway" name = "sms-gateway"
description = "A http frontend for SMS Server Tools 3" description = "A http frontend for SMS Server Tools 3"
authors = ["David Huss <david.huss@hfbk-hamburg.de>"] authors = ["David Huss <david.huss@hfbk-hamburg.de>"]
version = "0.3.1" version = "0.4.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
......
...@@ -34,6 +34,8 @@ function build_and_deploy { ...@@ -34,6 +34,8 @@ function build_and_deploy {
echo -------------------------------------------------- echo --------------------------------------------------
echo "Deploying Binary $1 to Host $TARGET_HOST:$TARGET_PATH$1"; echo "Deploying Binary $1 to Host $TARGET_HOST:$TARGET_PATH$1";
rsync ${SOURCE_PATH}$1 $TARGET_HOST:$TARGET_PATH$1 rsync ${SOURCE_PATH}$1 $TARGET_HOST:$TARGET_PATH$1
# chmod +x the binary
ssh -p ${TARGET_PORT} -t ${TARGET_HOST} "chmod +x $TARGET_PATH$1"
echo echo
} }
...@@ -45,6 +47,6 @@ do ...@@ -45,6 +47,6 @@ do
done done
# Finally restart the service # Finally restart the service
# ssh -p ${TARGET_PORT} -t ${TARGET_HOST} ${TARGET_PATH}$1 ssh -p ${TARGET_PORT} -t ${TARGET_HOST} "systemctl restart sms-gateway"
echo "done" echo "done"
\ No newline at end of file
[Unit] [Unit]
Description=sms-gateway web-frontend Description=sms-gateway web-frontend
DefaultDependencies=no DefaultDependencies=no
After=network.target After=network.target smstools.target
[Service] [Service]
Type=simple Type=simple
......
use std::process::exit; use std::process::exit;
use std::env::args; use std::env::args;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::PathBuf;
use reqwest; use reqwest;
pub use log::{info, warn, debug, error}; pub use log::{info, warn, debug, error};
...@@ -16,15 +17,24 @@ const BINARY_NAME: &str = env!("CARGO_BIN_NAME"); ...@@ -16,15 +17,24 @@ const BINARY_NAME: &str = env!("CARGO_BIN_NAME");
fn help() {
info!("Error: Insufficient number of arguments! Expected two or three arguments.");
exit(1);
}
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Started {} {}", PACKAGE_NAME, BINARY_NAME); info!("Started {} {}", PACKAGE_NAME, BINARY_NAME);
if args().len() != 3 {
error!("Error: Insufficient number of arguments! Expected two arguments."); let args: Vec<String> = args().collect();
exit(1);
} match args.len() {
let kind = args().nth(1).unwrap().to_ascii_lowercase(); 2 | 3 => {
let content = args().nth(2).unwrap(); let kind = args[0].to_ascii_lowercase();
let path = PathBuf::from(&args[1]);
let content = std::fs::read_to_string(&path)?;
match &kind[..] { match &kind[..] {
"received" => { "received" => {
...@@ -63,4 +73,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { ...@@ -63,4 +73,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
Ok(()) Ok(())
},
_ => {
error!("Error: Insufficient number of arguments! Expected two or three arguments.");
help();
Ok(())
}
}
} }
\ No newline at end of file
...@@ -19,9 +19,9 @@ pub enum SmsError { ...@@ -19,9 +19,9 @@ pub enum SmsError {
UnknownEventKind(String), UnknownEventKind(String),
#[error("Failed to deserialize SMS from string: '{0}'")] #[error("Failed to deserialize SMS from string: '{0}'")]
DeserializationError(String), DeserializationError(String),
#[error("The provided number '{0}' was not in the whitelist")] #[error("The provided number '{0}' was not on the whitelist")]
NotInWhiteList(String), NotInWhiteList(String),
#[error("The provided number '{0}' was on the blacklist")] #[error("The provided number '{0}' as it matched at least one entry of the blacklist")]
InBlackList(String), InBlackList(String),
} }
......
...@@ -116,7 +116,7 @@ impl Sms { ...@@ -116,7 +116,7 @@ impl Sms {
// If this is the case, return an Error // If this is the case, return an Error
if in_blacklist { if in_blacklist {
warn!("Refused to send SMS to \"{}\" as it was blacklisted", self.number); warn!("Refused to send SMS to \"{}\" as it matched at least one entry of the blacklist", self.number);
return Err(SmsError::InBlackList(self.number.clone())); return Err(SmsError::InBlackList(self.number.clone()));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment