"]
+repository = "https://git.4rs.nl/awiteb/forgejo-guardian"
+license = "AGPL-3.0-or-later"
+
+
+[dependencies]
+serde = { version = "1.0.214", features = ["derive"] }
+serde_json = "1.0.132"
+toml = "0.8.19"
+tracing = "0.1.40"
+tracing-subscriber = "0.3.18"
+thiserror = "2.0.2"
+regex = "1.11.1"
+
+reqwest = { version = "0.12.9", default-features = false, features = [
+ "charset",
+ "http2",
+ "rustls-tls",
+] }
+tokio-util = { version = "0.7.12", default-features = false }
+tokio = { version = "1.41.1", default-features = false, features = [
+ "rt-multi-thread",
+ "macros",
+ "sync",
+ "signal",
+] }
+url = { version = "2.5.3", default-features = false, features = ["serde"] }
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..99f7c81
--- /dev/null
+++ b/README.md
@@ -0,0 +1,100 @@
+
+
+# Forgejo Guardian
+
+Simple Forgejo instance guardian, banning users and alerting admins based on certain regular expressions (regex)
+
+
+
+[![agplv3-or-later](https://www.gnu.org/graphics/agplv3-88x31.png)](https://www.gnu.org/licenses/agpl-3.0.html)
+
+
+
+## Installation
+
+You can let [cargo](https://doc.rust-lang.org/cargo/) build the binary for you, or build it yourself.
+
+### Build it
+
+#### `cargo-install`
+
+> [!TIP]
+> This will install the binary in `~/.cargo/bin/forgejo-guardian`. Make sure to add this directory to your `PATH`.
+> If you want to update it, run `cargo install ...` again.
+
+```sh
+cargo install --git https://git.4rs.nl/awiteb/forgejo-guardian
+```
+
+#### `cargo-install` (from source)
+
+> [!TIP]
+> Then when you want to update it, pull the changes and run `cargo install --path .` again.
+
+```sh
+git clone https://git.4rs.nl/awiteb/forgejo-guardian
+cd forgejo-guardian
+cargo install --path .
+```
+
+#### Build (from source)
+
+> [!TIP]
+> The binary will be in `./target/release/forgejo-guardian`.
+
+```sh
+git clone https://git.4rs.nl/awiteb/forgejo-guardian
+cd forgejo-guardian
+cargo build --release
+```
+
+## Configuration
+
+We use `TOML` format for configuration, the default configuration file is `/app/forgejo-guardian.toml`, but you can specify a different one with `FORGEJO_GUARDIAN_CONFIG` environment variable.
+
+### Structure
+
+In our configuration file, we have two main sections:
+
+- `forgejo`: Forgejo instance configuration
+- `expressions`: Regular expressions to match against
+
+
+#### `forgejo`
+
+Forgejo configuration section, with the following fields:
+
+- `instance_url`: Forgejo instance URL (must be HTTPS or HTTP)
+- `token`: Token to use to get the new users and ban them, requires `read:admin` and `write:admin` scopes.
+
+```toml
+[forgejo]
+instance_url = "https://forgejo.example
+token = "your-token"
+```
+
+#### `expressions`
+
+Expressions configuration section, with the following fields:
+
+- `ban`: Regular expressions to match against to ban the user
+- `sus`: Regular expressions to match against to alert the admins
+
+`ban` and `sus` are tables, and each one have the following fields:
+
+- `usernames`: Regular expressions to match against the usernames
+- `full_names`: Regular expressions to match against the full names
+- `biographies`: Regular expressions to match against the biographies
+- `emails`: Regular expressions to match against the emails
+- `websites`: Regular expressions to match against the websites
+- `locations`: Regular expressions to match against the locations
+
+```toml
+[expressions.ban]
+usernames = ['^admin.*$']
+
+[expressions.sus]
+usernames = ['^mod.*$']
+```
+
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
new file mode 100644
index 0000000..08fa59f
--- /dev/null
+++ b/rust-toolchain.toml
@@ -0,0 +1,13 @@
+[toolchain]
+# We use nightly in development only, the project will always be compliant with
+# the latest stable release and the MSRV as defined in `Cargo.toml` file.
+channel = "nightly-2024-11-12"
+components = [
+ "rustc",
+ "cargo",
+ "rust-std",
+ "rust-src",
+ "rustfmt",
+ "rust-analyzer",
+ "clippy",
+]
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 0000000..a897997
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1,21 @@
+unstable_features = true
+style_edition = "2021"
+
+combine_control_expr = false
+wrap_comments = true
+condense_wildcard_suffixes = true
+edition = "2021"
+enum_discrim_align_threshold = 20
+force_multiline_blocks = true
+format_code_in_doc_comments = true
+format_generated_files = false
+format_macro_matchers = true
+format_strings = true
+imports_layout = "HorizontalVertical"
+newline_style = "Unix"
+normalize_comments = true
+reorder_impl_items = true
+group_imports = "StdExternalCrate"
+single_line_let_else_max_width = 0
+struct_field_align_threshold = 20
+use_try_shorthand = true
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..9af9836
--- /dev/null
+++ b/src/config.rs
@@ -0,0 +1,132 @@
+// Simple Forgejo instance guardian, banning users and alerting admins based on
+// certain regular expressions. Copyright (C) 2024 Awiteb