38 Commits
0.1.0 ... 0.1.5

Author SHA1 Message Date
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
7e6cfa7f8f fix blocking code in asynch 2023-10-04 18:21:18 +02:00
Hannes Kuchelmeister
bdf96b366a Merge pull request #11 from 13hannes11/dependabot/cargo/openssl-0.10.55
Bump openssl from 0.10.48 to 0.10.55
2023-06-22 10:40:49 +02:00
dependabot[bot]
569e7f71ef Bump openssl from 0.10.48 to 0.10.55
Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.48 to 0.10.55.
- [Release notes](https://github.com/sfackler/rust-openssl/releases)
- [Commits](https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.48...openssl-v0.10.55)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-21 22:54:44 +00:00
Hannes Kuchelmeister
41234a1fac Merge pull request #8 from 13hannes11/dependabot/cargo/h2-0.3.17
Bump h2 from 0.3.13 to 0.3.17
2023-06-13 13:45:38 +02:00
dependabot[bot]
0064698574 Bump h2 from 0.3.13 to 0.3.17
Bumps [h2](https://github.com/hyperium/h2) from 0.3.13 to 0.3.17.
- [Release notes](https://github.com/hyperium/h2/releases)
- [Changelog](https://github.com/hyperium/h2/blob/master/CHANGELOG.md)
- [Commits](https://github.com/hyperium/h2/compare/v0.3.13...v0.3.17)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-13 16:56:16 +00:00
Hannes Kuchelmeister
271af82794 Merge pull request #7 from 13hannes11/dependabot/cargo/openssl-0.10.48
Bump openssl from 0.10.40 to 0.10.48
2023-03-25 20:50:08 +01:00
dependabot[bot]
776dccb15c Bump openssl from 0.10.40 to 0.10.48
Bumps [openssl](https://github.com/sfackler/rust-openssl) from 0.10.40 to 0.10.48.
- [Release notes](https://github.com/sfackler/rust-openssl/releases)
- [Commits](https://github.com/sfackler/rust-openssl/compare/openssl-v0.10.40...openssl-v0.10.48)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-25 01:07:34 +00:00
Hannes Kuchelmeister
64b416e8b6 Merge pull request #5 from 13hannes11/dependabot/cargo/bumpalo-3.12.0
Bump bumpalo from 3.10.0 to 3.12.0
2023-02-09 09:22:50 +01:00
Hannes Kuchelmeister
977110fa99 Merge pull request #4 from 13hannes11/dependabot/cargo/tokio-1.25.0
Bump tokio from 1.19.2 to 1.25.0
2023-02-09 09:22:17 +01:00
dependabot[bot]
a701eb9a76 Bump bumpalo from 3.10.0 to 3.12.0
Bumps [bumpalo](https://github.com/fitzgen/bumpalo) from 3.10.0 to 3.12.0.
- [Release notes](https://github.com/fitzgen/bumpalo/releases)
- [Changelog](https://github.com/fitzgen/bumpalo/blob/main/CHANGELOG.md)
- [Commits](https://github.com/fitzgen/bumpalo/compare/3.10.0...3.12.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-09 08:20:52 +00:00
dependabot[bot]
b3aeef646a Bump tokio from 1.19.2 to 1.25.0
Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.19.2 to 1.25.0.
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.19.2...tokio-1.25.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-09 08:20:36 +00:00
b89e4af7ac update dependencies to mitigate vulnearability in time-rs 2022-06-22 14:46:52 +02:00
074c194c0c cargo update to fix security vulnearabilities in dependencies 2022-06-07 14:06:28 +02:00
af1e32ac24 update the debian image to use debian stable-slim 2022-06-07 13:45:46 +02:00
129481840f update uuid crate version to 1.0 2022-06-07 12:57:50 +02:00
16cd3ca123 update to rust version 1.61 2022-06-07 12:57:04 +02:00
936c536cc0 add docker-compose build instructions for readme 2022-06-07 12:56:21 +02:00
4a8f9c1ab8 fix outdated versions not allowing server to start (issue with GLIBC) 2022-02-26 11:25:38 +01:00
6bd3ef4537 add dev docker-compose to make local building and running easier 2022-02-26 11:24:51 +01:00
7eabecf6b4 update to use new actix version 2022-02-25 21:25:12 +01:00
3d83a6761a update to use actix-web 4.0.0 rc.3 2022-02-11 16:41:48 +01:00
Hannes Kuchelmeister
ba11157687 added contributing to the README 2022-02-11 11:01:35 +01:00
1aa117a28f replace deprecated function .data by .app_data(Data::new(...)) 2021-11-22 15:28:26 +01:00
f59b49b1ad upgrade compiler version and rust edition 2021-11-22 15:22:41 +01:00
36c01035d5 switch to 4.0 alpha of actix to update to newest sqlx version 2021-11-22 15:21:48 +01:00
Hannes Kuchelmeister
c38971af3a Update registry link in readme 2021-10-08 14:49:48 +02:00
Hannes Kuchelmeister
5f45e52fb9 Add screenshots to readme file 2021-10-08 14:47:51 +02:00
Hannes Kuchelmeister
e804305a68 Update issue templates 2021-10-02 01:00:50 +02:00
11 changed files with 1404 additions and 1470 deletions

38
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.

View File

@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

2726
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,17 @@
[package] [package]
name = "ics-proxy" name = "ics-proxy"
version = "0.1.0" version = "0.1.2"
edition = "2018" 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 = "3" actix-web = "4.0"
uuid = { version = "0.8.2", features = ["v4"] } uuid = { version = "1.0", features = ["v4"] }
url = "2.2" url = "2.2"
reqwest = { version = "0.11", features = ["blocking"] } reqwest = { version = "0.11", features = ["blocking"] }
tera = "1.12.1" tera = "1.15"
dotenv = "0.15" dotenv = "0.15"
sqlx = { version = "0.4.2", features = [ "sqlite", "runtime-actix-native-tls" ] } sqlx = { version = "0.5", features = ["sqlite", "runtime-actix-rustls"] }
chrono = "0.4.38"

View File

@@ -1,11 +1,13 @@
FROM rust:1.54 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:buster-slim FROM debian:stable-slim
RUN apt-get update && apt-get install -y sqlite3 openssl ca-certificates && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y sqlite3 openssl ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR app WORKDIR app
COPY --from=builder /usr/local/cargo/bin/ics-proxy ./ics-proxy COPY --from=builder /usr/local/cargo/bin/ics-proxy ./ics-proxy

View File

@@ -1,6 +1,13 @@
# ics-proxy # ics-proxy
You can find a running instance of this code on [ics-proxy.de](https://ics-proxy.de). The docker image is published on [DockerHub](https://hub.docker.com/repository/docker/13hannes11/ics-proxy). You can find a running instance of this code on [ics-proxy.de](https://ics-proxy.de). The docker image is published on the [GitHub Container Registry](https://github.com/13hannes11/ics-proxy/pkgs/container/ics-proxy).
## Screenshots
![image](https://user-images.githubusercontent.com/9381167/136559243-2a7c9062-33e3-436e-a781-fef3173e1671.png)
![image](https://user-images.githubusercontent.com/9381167/136559368-3404a94f-35d1-4235-8c98-2f837b75fda0.png)
## Motivation ## Motivation
@@ -12,6 +19,11 @@ Additionally, each semester this needed to be done as well. I therefore created
The easiest way to build this repository is to use docker. You can simply run `docker build -t ics-proxy .` The easiest way to build this repository is to use docker. You can simply run `docker build -t ics-proxy .`
Alternatively you can build and run a local dev version with `docker-compose -f docker-compose.dev.yml up`.
## Deployment ## Deployment
To deploy you can simply use the `docker-compose.yml` file. To deploy you can simply use the `docker-compose.yml` file.
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

12
docker-compose.dev.yml Normal file
View File

@@ -0,0 +1,12 @@
version: '3'
services:
ics-proxy:
container_name: ics-proxy
build: .
env_file: .env
ports:
- "8080:8080"
volumes:
- database:/app/db
volumes:
database:

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

@@ -2,6 +2,7 @@ use std::collections::HashMap;
use url::Url; use url::Url;
use actix_web::http::StatusCode; use actix_web::http::StatusCode;
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 tera::Tera; use tera::Tera;
@@ -22,11 +23,11 @@ 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("");
println!("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::blocking::get(link.destination) { Ok(link) => match reqwest::get(link.destination).await {
Ok(r) => match r.text() { Ok(r) => match r.text().await {
Ok(res) => HttpResponse::Ok().content_type("text/calendar").body(res), Ok(res) => HttpResponse::Ok().content_type("text/calendar").body(res),
Err(err) => HttpResponse::Ok() Err(err) => HttpResponse::Ok()
.status(StatusCode::INTERNAL_SERVER_ERROR) .status(StatusCode::INTERNAL_SERVER_ERROR)
@@ -59,6 +60,7 @@ 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> {
println!("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) {
@@ -256,7 +258,7 @@ 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
println!("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"))?;
@@ -291,6 +293,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
@@ -299,9 +303,9 @@ async fn main() -> std::io::Result<()> {
let tera = Tera::new("templates/**/*.html").unwrap(); let tera = Tera::new("templates/**/*.html").unwrap();
App::new() App::new()
.data(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
.data(tera) .app_data(Data::new(tera))
.data(conf.clone()) .app_data(Data::new(conf.clone()))
.route("/{id}/events.ics", web::get().to(make_ics_request)) .route("/{id}/events.ics", web::get().to(make_ics_request))
.service(web::resource("/").route(web::get().to(index))) .service(web::resource("/").route(web::get().to(index)))
.service(web::resource("/edit").route(web::get().to(edit_page))) .service(web::resource("/edit").route(web::get().to(edit_page)))

View File

@@ -1,4 +1,8 @@
use actix_web::web; use actix_web::web;
use chrono::DateTime;
use chrono::Utc;
use std::time::SystemTime;
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
// Change to strings if to much headache // Change to strings if to much headache
@@ -13,6 +17,7 @@ impl Link {
pool: web::Data<Pool<Sqlite>>, pool: web::Data<Pool<Sqlite>>,
) -> Result<Link, sqlx::Error> { ) -> Result<Link, sqlx::Error> {
let mut tx = pool.begin().await?; let mut tx = pool.begin().await?;
println!("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
@@ -22,6 +27,19 @@ impl Link {
.fetch_one(&mut tx) .fetch_one(&mut tx)
.await?; .await?;
let now = SystemTime::now();
let now: DateTime<Utc> = now.into();
let now = now.to_rfc3339();
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,
@@ -35,6 +53,7 @@ impl Link {
.execute(&mut tx) .execute(&mut tx)
.await?; .await?;
println!("update uuid {}", link.uuid);
tx.commit().await?; tx.commit().await?;
Ok(link) Ok(link)
} }
@@ -46,6 +65,7 @@ impl Link {
.execute(&mut tx) .execute(&mut tx)
.await?; .await?;
println!("create uuid {}", link.uuid);
tx.commit().await?; tx.commit().await?;
Ok(link) Ok(link)
} }