This commit is contained in:
JMARyA 2023-07-04 19:08:56 +02:00
parent 6d55f0ff92
commit 2b903cccda
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 398 additions and 357 deletions

741
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -5,10 +5,10 @@ WORKDIR /app
RUN cargo build --release
FROM debian
FROM archlinux
RUN apt-get update
RUN apt-get install -y gnupg ca-certificates
RUN pacman -Syu --noconfirm
RUN pacman -S --noconfirm gnupg ca-certificates openssl-1.1
COPY --from=builder /app/target/release/me-site /me-site

View file

@ -1,14 +1,14 @@
use std::io::Write;
pub fn encrypt(msg: String) -> String {
pub fn encrypt(msg: &str) -> String {
let pgp = gnupg::GnuPG::new().expect("no gpg");
let pub_key = pgp
.import_key(&std::fs::read_to_string("./config/pub.key").expect("key could not be read"))
.expect("key import error");
pgp.encrypt(&pub_key, &msg).expect("encryption failed")
pgp.encrypt(&pub_key, msg).expect("encryption failed")
}
pub fn save_message(msg: String, name: &str) {
pub fn save_message(msg: &str, name: &str) {
std::fs::create_dir_all("./data/messages").expect("couldn't create msg dir");
let time = chrono::offset::Utc::now();
let time = time.format("%Y-%m-%d.%H-%M").to_string();

View file

@ -14,7 +14,7 @@ pub struct MessageForm {
#[post("/message")]
pub async fn message_post(r: HttpRequest, f: Form<MessageForm>) -> impl Responder {
let config: &web::Data<config::Config> = r.app_data().expect("get config failed");
crate::msg::save_message(f.message.clone(), &f.msg_name.to_string());
crate::msg::save_message(&f.message, &f.msg_name.to_string());
crate::notification::notify(
&format!("New Message from {}", f.msg_name),
"New Message",