18 Commits
0.1.4 ... main

Author SHA1 Message Date
Hannes Kuchelmeister
77d0251f57 Update version number 2024-07-26 21:01:11 +02:00
ede6aaf8aa run cargo update 2024-07-26 11:23:59 +02:00
a5b36ab0fb add timestamps to printing statements 2024-07-26 11:19:47 +02:00
c6afed3b11 add any pool in prep for differenc db backends 2024-07-25 18:21:31 +02:00
2c4c78125e bump dependency version 2024-07-25 18:18:09 +02:00
Hannes Kuchelmeister
365bb52772 Merge pull request #18 from 13hannes11/dependabot/cargo/openssl-0.10.66
Bump openssl from 0.10.64 to 0.10.66
2024-07-23 10:13:27 +02:00
dependabot[bot]
4bf9f20fd5 Bump openssl from 0.10.64 to 0.10.66
Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.64 to 0.10.66.
- [Release notes](https://github.com/sfackler/rust-openssl/releases)
- [Commits](https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.64...openssl-v0.10.66)

---
updated-dependencies:
- dependency-name: openssl
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-07-22 18:14:08 +00:00
Hannes Kuchelmeister
884fa56545 Update version number in cargo.toml to match actual version number 2024-04-26 08:22:05 +02:00
18beebfdd0 add last used fieldi and some logging 2024-04-25 23:21:21 +02:00
5964a1ddad add migrations 2024-04-25 22:35:23 +02:00
Hannes Kuchelmeister
98d5539fdd Merge pull request #15 from 13hannes11/dependabot/cargo/mio-0.8.11
Bump mio from 0.8.8 to 0.8.11
2024-03-22 09:15:02 +01:00
dependabot[bot]
c08bd57c89 Bump mio from 0.8.8 to 0.8.11
Bumps [mio](https://github.com/tokio-rs/mio) from 0.8.8 to 0.8.11.
- [Release notes](https://github.com/tokio-rs/mio/releases)
- [Changelog](https://github.com/tokio-rs/mio/blob/master/CHANGELOG.md)
- [Commits](https://github.com/tokio-rs/mio/compare/v0.8.8...v0.8.11)

---
updated-dependencies:
- dependency-name: mio
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-04 21:57:59 +00:00
Hannes Kuchelmeister
a45d4cef1f Merge pull request #14 from 13hannes11/dependabot/cargo/h2-0.3.24
Bump h2 from 0.3.21 to 0.3.24
2024-01-19 23:00:09 +01:00
dependabot[bot]
dc854e9a4e Bump h2 from 0.3.21 to 0.3.24
Bumps [h2](https://github.com/hyperium/h2) from 0.3.21 to 0.3.24.
- [Release notes](https://github.com/hyperium/h2/releases)
- [Changelog](https://github.com/hyperium/h2/blob/v0.3.24/CHANGELOG.md)
- [Commits](https://github.com/hyperium/h2/compare/v0.3.21...v0.3.24)

---
updated-dependencies:
- dependency-name: h2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-19 16:19:42 +00:00
Hannes Kuchelmeister
5011696de9 Merge pull request #13 from 13hannes11/dependabot/cargo/openssl-0.10.60
Bump openssl from 0.10.57 to 0.10.60
2023-12-19 14:49:09 +01:00
dependabot[bot]
fc52e31ef6 Bump openssl from 0.10.57 to 0.10.60
Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.57 to 0.10.60.
- [Release notes](https://github.com/sfackler/rust-openssl/releases)
- [Commits](https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.57...openssl-v0.10.60)

---
updated-dependencies:
- dependency-name: openssl
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-28 21:44:40 +00:00
Hannes Kuchelmeister
799d310815 Merge pull request #12 from 13hannes11/dependabot/cargo/rustix-0.38.19
Bump rustix from 0.38.15 to 0.38.19
2023-10-20 14:42:26 +02:00
dependabot[bot]
9e02170c0e Bump rustix from 0.38.15 to 0.38.19
Bumps [rustix](https://github.com/bytecodealliance/rustix) from 0.38.15 to 0.38.19.
- [Release notes](https://github.com/bytecodealliance/rustix/releases)
- [Commits](https://github.com/bytecodealliance/rustix/compare/v0.38.15...v0.38.19)

---
updated-dependencies:
- dependency-name: rustix
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-18 18:44:51 +00:00
7 changed files with 1241 additions and 674 deletions

1843
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,16 @@
[package] [package]
name = "ics-proxy" name = "ics-proxy"
version = "0.1.2" version = "0.1.6"
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
[dependencies] [dependencies]
actix-web = "4.0" actix-web = "4.8"
uuid = { version = "1.0", features = ["v4"] } uuid = { version = "1.10", features = ["v4"] }
url = "2.2" url = "2.5"
reqwest = { version = "0.11", features = ["blocking"] } reqwest = { version = "0.12", features = ["blocking"] }
tera = "1.15" tera = "1.20"
dotenv = "0.15" dotenv = "0.15"
sqlx = { version = "0.8", features = ["sqlite", "any", "tls-rustls", "runtime-tokio"] }
sqlx = { version = "0.5", features = [ "sqlite", "runtime-actix-rustls" ] } chrono = "0.4.38"

View File

@@ -1,8 +1,10 @@
FROM rust:1.72 as builder FROM rust:1.77 as builder
RUN apt-get update && apt-get install -y sqlite3 && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y sqlite3 && rm -rf /var/lib/apt/lists/*
RUN cargo install sqlx-cli
WORKDIR /usr/src/ics-proxy WORKDIR /usr/src/ics-proxy
COPY . . COPY . .
RUN cd db && ./create_db.sh RUN sqlx database create
RUN sqlx migrate run
RUN cargo install --path . RUN cargo install --path .
FROM debian:stable-slim FROM debian:stable-slim

View File

@@ -1,4 +1,5 @@
-- Add migration script here
CREATE TABLE IF NOT EXISTS LINKS( CREATE TABLE IF NOT EXISTS LINKS(
UUID TEXT NOT NULL PRIMARY KEY, UUID TEXT NOT NULL PRIMARY KEY,
DESTINATION TEXT NOT NULL DESTINATION TEXT NOT NULL
); );

View File

@@ -0,0 +1,2 @@
-- Add migration script here
ALTER TABLE LINKS ADD COLUMN last_used TEXT;

View File

@@ -5,15 +5,17 @@ use actix_web::http::StatusCode;
use actix_web::web::Data; use actix_web::web::Data;
use actix_web::{error, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder, Result}; use actix_web::{error, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder, Result};
use sqlx::{Pool, Sqlite, SqlitePool}; use sqlx::{Pool, Sqlite, SqlitePool};
use std::time::SystemTime;
use tera::Tera; use tera::Tera;
use uuid::Uuid; use uuid::Uuid;
extern crate dotenv; extern crate dotenv;
use actix_web::middleware::Logger;
use dotenv::dotenv; use dotenv::dotenv;
mod model; mod model;
use model::Link; use chrono::DateTime;
use chrono::Utc;
use model::Link;
const REDIRECT_TIMEOUT_S: i32 = 2; const REDIRECT_TIMEOUT_S: i32 = 2;
#[derive(Clone)] #[derive(Clone)]
@@ -23,7 +25,8 @@ struct Config {
async fn make_ics_request(req: HttpRequest, db_pool: web::Data<Pool<Sqlite>>) -> impl Responder { async fn make_ics_request(req: HttpRequest, db_pool: web::Data<Pool<Sqlite>>) -> impl Responder {
let id = req.match_info().get("id").unwrap_or(""); let id = req.match_info().get("id").unwrap_or("");
let now = <SystemTime as Into<DateTime<Utc>>>::into(SystemTime::now()).to_rfc3339();
println!("{now} serving ics request");
match Uuid::parse_str(id) { match Uuid::parse_str(id) {
Ok(uuid) => match Link::find_by_uuid(uuid.to_string(), db_pool).await { Ok(uuid) => match Link::find_by_uuid(uuid.to_string(), db_pool).await {
Ok(link) => match reqwest::get(link.destination).await { Ok(link) => match reqwest::get(link.destination).await {
@@ -60,6 +63,8 @@ async fn edit_page(
db_pool: web::Data<Pool<Sqlite>>, db_pool: web::Data<Pool<Sqlite>>,
conf: web::Data<Config>, conf: web::Data<Config>,
) -> Result<HttpResponse, Error> { ) -> Result<HttpResponse, Error> {
let now = <SystemTime as Into<DateTime<Utc>>>::into(SystemTime::now()).to_rfc3339();
println!("{now} serving edit page");
// one uuid: 9228c1a4-8956-4f1c-8b5f-53cc575bd78 // one uuid: 9228c1a4-8956-4f1c-8b5f-53cc575bd78
if let Some(uuid_str) = query.get("uuid") { if let Some(uuid_str) = query.get("uuid") {
match Uuid::parse_str(uuid_str) { match Uuid::parse_str(uuid_str) {
@@ -257,7 +262,8 @@ async fn index_process(
// store tera template in application state // store tera template in application state
async fn index(tmpl: web::Data<tera::Tera>) -> Result<HttpResponse, Error> { async fn index(tmpl: web::Data<tera::Tera>) -> Result<HttpResponse, Error> {
// TODO: add option to prefill link with parameter // TODO: add option to prefill link with parameter
let now = <SystemTime as Into<DateTime<Utc>>>::into(SystemTime::now()).to_rfc3339();
println!("{now} serving index page");
let s = tmpl let s = tmpl
.render("index.html", &tera::Context::new()) .render("index.html", &tera::Context::new())
.map_err(|_| error::ErrorInternalServerError("Template error"))?; .map_err(|_| error::ErrorInternalServerError("Template error"))?;
@@ -292,6 +298,8 @@ async fn main() -> std::io::Result<()> {
.await .await
.expect("could not create db pool"); .expect("could not create db pool");
sqlx::migrate!("./migrations").run(&db_pool).await.unwrap();
println!( println!(
"Listening on: {}://{}, open browser and visit have a try!", "Listening on: {}://{}, open browser and visit have a try!",
protocol, base_url protocol, base_url
@@ -300,6 +308,7 @@ async fn main() -> std::io::Result<()> {
let tera = Tera::new("templates/**/*.html").unwrap(); let tera = Tera::new("templates/**/*.html").unwrap();
App::new() App::new()
.wrap(Logger::new("%a %{User-Agent}i"))
.app_data(Data::new(db_pool.clone())) // pass database pool to application so we can access it inside handlers .app_data(Data::new(db_pool.clone())) // pass database pool to application so we can access it inside handlers
.app_data(Data::new(tera)) .app_data(Data::new(tera))
.app_data(Data::new(conf.clone())) .app_data(Data::new(conf.clone()))

View File

@@ -1,5 +1,8 @@
use actix_web::web; use actix_web::web;
use chrono::DateTime;
use chrono::Utc;
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
use std::time::SystemTime;
// Change to strings if to much headache // Change to strings if to much headache
pub struct Link { pub struct Link {
@@ -12,16 +15,27 @@ impl Link {
uuid: String, uuid: String,
pool: web::Data<Pool<Sqlite>>, pool: web::Data<Pool<Sqlite>>,
) -> Result<Link, sqlx::Error> { ) -> Result<Link, sqlx::Error> {
let now = <SystemTime as Into<DateTime<Utc>>>::into(SystemTime::now()).to_rfc3339();
let mut tx = pool.begin().await?; let mut tx = pool.begin().await?;
println!("{now} find by uuid {uuid}");
let rec = sqlx::query!( let rec = sqlx::query!(
r#" r#"
SELECT * FROM links WHERE uuid = $1 SELECT * FROM links WHERE uuid = $1
"#, "#,
uuid uuid
) )
.fetch_one(&mut tx) .fetch_one(&mut *tx)
.await?; .await?;
sqlx::query!(
r#" UPDATE links SET last_used = $1 WHERE uuid = $2"#,
now,
uuid,
)
.execute(&mut *tx)
.await?;
tx.commit().await?;
Ok(Link { Ok(Link {
uuid: rec.UUID, uuid: rec.UUID,
destination: rec.DESTINATION, destination: rec.DESTINATION,
@@ -32,9 +46,10 @@ impl Link {
sqlx::query("UPDATE links SET destination = $2 WHERE uuid = $1;") sqlx::query("UPDATE links SET destination = $2 WHERE uuid = $1;")
.bind(&link.uuid) .bind(&link.uuid)
.bind(&link.destination) .bind(&link.destination)
.execute(&mut tx) .execute(&mut *tx)
.await?; .await?;
let now = <SystemTime as Into<DateTime<Utc>>>::into(SystemTime::now()).to_rfc3339();
println!("{} update uuid {}", now, link.uuid);
tx.commit().await?; tx.commit().await?;
Ok(link) Ok(link)
} }
@@ -43,9 +58,10 @@ impl Link {
sqlx::query("INSERT INTO links (uuid, destination) VALUES ($1, $2);") sqlx::query("INSERT INTO links (uuid, destination) VALUES ($1, $2);")
.bind(&link.uuid) .bind(&link.uuid)
.bind(&link.destination) .bind(&link.destination)
.execute(&mut tx) .execute(&mut *tx)
.await?; .await?;
let now = <SystemTime as Into<DateTime<Utc>>>::into(SystemTime::now()).to_rfc3339();
println!("{} create uuid {}", now, link.uuid);
tx.commit().await?; tx.commit().await?;
Ok(link) Ok(link)
} }