This commit is contained in:
Imk 2024-10-08 19:13:04 +02:00
parent e2dc92c152
commit 01d6c3d3cb
6 changed files with 277 additions and 6 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target /target
.env

223
Cargo.lock generated
View File

@ -31,7 +31,7 @@ dependencies = [
"actix-web", "actix-web",
"bitflags", "bitflags",
"bytes", "bytes",
"derive_more", "derive_more 0.99.18",
"futures-core", "futures-core",
"http-range", "http-range",
"log", "log",
@ -53,12 +53,12 @@ dependencies = [
"actix-service", "actix-service",
"actix-utils", "actix-utils",
"ahash", "ahash",
"base64", "base64 0.22.1",
"bitflags", "bitflags",
"brotli", "brotli",
"bytes", "bytes",
"bytestring", "bytestring",
"derive_more", "derive_more 0.99.18",
"encoding_rs", "encoding_rs",
"flate2", "flate2",
"futures-core", "futures-core",
@ -81,6 +81,22 @@ dependencies = [
"zstd", "zstd",
] ]
[[package]]
name = "actix-identity"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b8ddc6f6a8b19c4016aaa13519968da9969bc3bc1c1c883cdb0f25dd6c8cf7"
dependencies = [
"actix-service",
"actix-session",
"actix-utils",
"actix-web",
"derive_more 1.0.0",
"futures-core",
"serde",
"tracing",
]
[[package]] [[package]]
name = "actix-macros" name = "actix-macros"
version = "0.2.4" version = "0.2.4"
@ -144,6 +160,23 @@ dependencies = [
"pin-project-lite", "pin-project-lite",
] ]
[[package]]
name = "actix-session"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efe6976a74f34f1b6d07a6c05aadc0ed0359304a7781c367fa5b4029418db08f"
dependencies = [
"actix-service",
"actix-utils",
"actix-web",
"anyhow",
"derive_more 1.0.0",
"rand",
"serde",
"serde_json",
"tracing",
]
[[package]] [[package]]
name = "actix-utils" name = "actix-utils"
version = "3.0.1" version = "3.0.1"
@ -174,7 +207,7 @@ dependencies = [
"bytestring", "bytestring",
"cfg-if", "cfg-if",
"cookie", "cookie",
"derive_more", "derive_more 0.99.18",
"encoding_rs", "encoding_rs",
"futures-core", "futures-core",
"futures-util", "futures-util",
@ -223,6 +256,41 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "aead"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0"
dependencies = [
"crypto-common",
"generic-array",
]
[[package]]
name = "aes"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
dependencies = [
"cfg-if",
"cipher",
"cpufeatures",
]
[[package]]
name = "aes-gcm"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1"
dependencies = [
"aead",
"aes",
"cipher",
"ctr",
"ghash",
"subtle",
]
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.8.11" version = "0.8.11"
@ -324,6 +392,12 @@ dependencies = [
"windows-sys", "windows-sys",
] ]
[[package]]
name = "anyhow"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6"
[[package]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.4.0" version = "1.4.0"
@ -345,6 +419,12 @@ dependencies = [
"windows-targets", "windows-targets",
] ]
[[package]]
name = "base64"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5"
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.22.1" version = "0.22.1"
@ -371,7 +451,10 @@ name = "blog"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"actix-files", "actix-files",
"actix-identity",
"actix-web", "actix-web",
"base64 0.22.1",
"dotenv",
"env_logger", "env_logger",
"ignore", "ignore",
"lazy_static", "lazy_static",
@ -491,6 +574,16 @@ dependencies = [
"phf_codegen", "phf_codegen",
] ]
[[package]]
name = "cipher"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
dependencies = [
"crypto-common",
"inout",
]
[[package]] [[package]]
name = "colorchoice" name = "colorchoice"
version = "1.0.2" version = "1.0.2"
@ -509,7 +602,14 @@ version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb" checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb"
dependencies = [ dependencies = [
"aes-gcm",
"base64 0.20.0",
"hkdf",
"hmac",
"percent-encoding", "percent-encoding",
"rand",
"sha2",
"subtle",
"time", "time",
"version_check", "version_check",
] ]
@ -570,9 +670,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
dependencies = [ dependencies = [
"generic-array", "generic-array",
"rand_core",
"typenum", "typenum",
] ]
[[package]]
name = "ctr"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835"
dependencies = [
"cipher",
]
[[package]] [[package]]
name = "deranged" name = "deranged"
version = "0.3.11" version = "0.3.11"
@ -595,6 +705,27 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "derive_more"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05"
dependencies = [
"derive_more-impl",
]
[[package]]
name = "derive_more-impl"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22"
dependencies = [
"proc-macro2",
"quote",
"syn",
"unicode-xid",
]
[[package]] [[package]]
name = "deunicode" name = "deunicode"
version = "1.6.0" version = "1.6.0"
@ -609,8 +740,15 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [ dependencies = [
"block-buffer", "block-buffer",
"crypto-common", "crypto-common",
"subtle",
] ]
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.34" version = "0.8.34"
@ -734,6 +872,16 @@ dependencies = [
"wasi", "wasi",
] ]
[[package]]
name = "ghash"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1"
dependencies = [
"opaque-debug",
"polyval",
]
[[package]] [[package]]
name = "gimli" name = "gimli"
version = "0.31.0" version = "0.31.0"
@ -795,6 +943,24 @@ version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
[[package]]
name = "hkdf"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7"
dependencies = [
"hmac",
]
[[package]]
name = "hmac"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
dependencies = [
"digest",
]
[[package]] [[package]]
name = "http" name = "http"
version = "0.2.12" version = "0.2.12"
@ -904,6 +1070,15 @@ dependencies = [
"hashbrown", "hashbrown",
] ]
[[package]]
name = "inout"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5"
dependencies = [
"generic-array",
]
[[package]] [[package]]
name = "is_terminal_polyfill" name = "is_terminal_polyfill"
version = "1.70.1" version = "1.70.1"
@ -1068,6 +1243,12 @@ dependencies = [
"portable-atomic", "portable-atomic",
] ]
[[package]]
name = "opaque-debug"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.3" version = "0.12.3"
@ -1213,6 +1394,18 @@ version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2"
[[package]]
name = "polyval"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25"
dependencies = [
"cfg-if",
"cpufeatures",
"opaque-debug",
"universal-hash",
]
[[package]] [[package]]
name = "portable-atomic" name = "portable-atomic"
version = "1.9.0" version = "1.9.0"
@ -1518,6 +1711,12 @@ dependencies = [
"windows-sys", "windows-sys",
] ]
[[package]]
name = "subtle"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.79" version = "2.0.79"
@ -1799,6 +1998,22 @@ version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
[[package]]
name = "unicode-xid"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "universal-hash"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea"
dependencies = [
"crypto-common",
"subtle",
]
[[package]] [[package]]
name = "url" name = "url"
version = "2.5.2" version = "2.5.2"

View File

@ -5,7 +5,10 @@ edition = "2021"
[dependencies] [dependencies]
actix-files = "0.6.6" actix-files = "0.6.6"
actix-identity = "0.8.0"
actix-web = "4.9.0" actix-web = "4.9.0"
base64 = "0.22.1"
dotenv = "0.15.0"
env_logger = "0.11.5" env_logger = "0.11.5"
ignore = "0.4.23" ignore = "0.4.23"
lazy_static = "1.5.0" lazy_static = "1.5.0"

View File

@ -0,0 +1,24 @@
use std::{fs, io::Error};
use actix_web::{get, web, HttpResponse, Responder, HttpMessage};
use actix_identity::{Identity, IdentityMiddleware};
use actix_session::{config::PresistentSession, storage::CookieSessionStore, SessionMiddleware};
async fn login(req: HttpRequest) -> impl Responder{
Identity::login(&req.extension(),"user1".to_owned()).unwrap();
web::Redirect::to("/").using_status_code(StatusCode::FOUND)
}
#[get("/entry")]
pub async fn index(templates: web::Data<tera::Tera>) -> impl Responder {
let mut context = tera::Context::new();
match templates.render("login.html", &context) {
Ok(s) => HttpResponse::Ok().content_type("text/html").body(s),
Err(e) => {
println!("{:?}",e);
HttpResponse::InternalServerError()
.content_type("text/html")
.body("<p>Something is fucked up :33333 tell IMK(jet) to fix this if refreshing doesn't works or to shoot himself :3c</p>")
}
}
}

View File

@ -1,9 +1,13 @@
use dotenv::dotenv;
use actix_files::Files; use actix_files::Files;
use std::net::TcpListener; use std::net::TcpListener;
use actix_web::{dev::Server, web, App, HttpResponse, HttpServer, middleware}; use actix_identity::{Identity, IdentityMiddleware};
use actix_session::{config::PresistentSession, storage::CookieSessionStore, SessionMiddleware}
use actix_web::{dev::Server, web, http::StatusCode, HttpRequest, App, HttpResponse, HttpServer, middleware, cookie::{time::Duration, Key}};
use tera::Tera; use tera::Tera;
use base64::prelude::*;
pub mod handlers; pub mod handlers;
#[macro_use] #[macro_use]
extern crate lazy_static; extern crate lazy_static;
@ -21,13 +25,28 @@ lazy_static! {
}; };
} }
const SES_TIME: Duration = Duration::minutes(5);
pub fn start_blog(listener: TcpListener) -> Result<Server, std::io::Error>{ pub fn start_blog(listener: TcpListener) -> Result<Server, std::io::Error>{
dotenv().ok();
let secret_key = Key::from(&BASE64_STANDARD.decode(&std::env::var("KEY").expect("KEY UNSET")).unwrap());
let srv = HttpServer::new(move || { let srv = HttpServer::new(move || {
App::new() App::new()
.app_data(web::Data::new(TEMPLATES.clone())) .app_data(web::Data::new(TEMPLATES.clone()))
.wrap(middleware::Logger::default()) .wrap(middleware::Logger::default())
.wrap(IdentityMiddleware::default())
.wrap(
SessionMiddleware::builder(CookieSessionStore::default(), secret_key.clone)
.cookie_name("auth".to_owned())
.cookie_secure(false)
.session_lifecycle(PresistentSession::default().session_ttl(SES_TIME))
.build()
)
.service(Files::new("/static","static/").use_last_modified(true)) .service(Files::new("/static","static/").use_last_modified(true))
.route("/health", web::get().to(HttpResponse::Ok)) .route("/health", web::get().to(HttpResponse::Ok))
.route("/login", web::post().to(login))
.service(handlers::index) .service(handlers::index)
.service(handlers::post) .service(handlers::post)
}) })

9
templates/login.html Normal file
View File

@ -0,0 +1,9 @@
{% extends "base.html" %}
{% block title %}ALEPH 1 | IMK'S BLOG; ENTRY {% endblock title %}
{% block content %}
<div>
<h1 class="htitle">ℵ₁ | IMK'S BLOG</h1>
<hr>
</div>
{% endblock content %}