Compare commits

..

9 Commits

Author SHA1 Message Date
Aravinth Manivannan
0d2c02348b feat: document environment variable name changes 2023-10-16 21:15:15 +05:30
Aravinth Manivannan
98efe3ae56 feat: manually read configuration from environment variables 2023-10-16 21:15:15 +05:30
Aravinth Manivannan
060291d174 chore: bump config version 2023-10-16 21:15:15 +05:30
Aravinth Manivannan
65c3b9ad67 feat: use nvm to manage node versions 2023-10-16 21:15:15 +05:30
Aravinth Manivannan
d3e08ff49e chore: update sailfish
NOTE: Updating to 0.8 causes memory leak during compilation
2023-10-16 21:15:15 +05:30
Aravinth Manivannan
431463a397 Merge pull request #110 from mCaptcha/fix-docker-img
fix: get rid of docker caching
2023-10-16 21:14:23 +05:30
Aravinth Manivannan
342d03b58b fix: CI: port actions actionx-rust-lang and checkout@v4 2023-10-16 20:30:41 +05:30
Aravinth Manivannan
765be413c4 debug: rm GH actions caching 2023-10-16 20:17:00 +05:30
Aravinth Manivannan
e0203c660d fix: get rid of caching 2023-10-16 20:04:19 +05:30
15 changed files with 646 additions and 446 deletions

View File

@@ -12,3 +12,4 @@ src/cache_buster_data.json
browser/target
browser/cobertura.xml
browser/docs
**/target

View File

@@ -12,54 +12,21 @@ jobs:
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: ⚡ Cache
uses: actions/cache@v2
- uses: actions/checkout@v4
# Ensure rustfmt is installed and setup problem matcher
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
path: |
~/.cargo/registry
~/.cargo/git
node_modules
./docs/openapi/node_modules
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt
- name: Check with rustfmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Rustfmt Check
uses: actions-rust-lang/rustfmt@v1
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: ⚡ Cache
uses: actions/cache@v2
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
path: |
~/.cargo/registry
~/.cargo/git
node_modules
./docs/openapi/node_modules
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true
- uses: actions/setup-node@v2
with:
@@ -68,8 +35,5 @@ jobs:
- name: Build frontend
run: make frontend
- name: Check with Clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace --tests --all-features
- name: clippy Check
run: cargo clippy --workspace --tests --all-features

View File

@@ -68,18 +68,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: ⚡ Cache
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
node_modules
./docs/openapi/node_modules
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/checkout@v4
- name: load env
run: |
@@ -92,12 +81,7 @@ jobs:
with:
node-version: "18.0.0"
- name: Install ${{ matrix.version }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.version }}-x86_64-unknown-linux-gnu
profile: minimal
override: true
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Build frontend
run: make frontend

View File

@@ -9,7 +9,7 @@ on:
branches:
- master
- "*"
- '!gh-pages'
- "!gh-pages"
jobs:
build_and_test:
@@ -17,9 +17,7 @@ jobs:
fail-fast: false
matrix:
version:
#- 1.51.0
- stable
# - nightly
name: ${{ matrix.version }} - x86_64-unknown-linux-gnu
runs-on: ubuntu-latest
@@ -55,7 +53,7 @@ jobs:
maria:
image: mariadb:10
env:
env:
MARIADB_USER: "maria"
MARIADB_PASSWORD: "password"
MARIADB_ROOT_PASSWORD: "password"
@@ -69,17 +67,17 @@ jobs:
- 3306:3306
steps:
- uses: actions/checkout@v2
- name: ⚡ Cache
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
node_modules
./docs/openapi/node_modules
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/checkout@v4
#- name: ⚡ Cache
# uses: actions/cache@v2
# with:
# path: |
# ~/.cargo/registry
# ~/.cargo/git
# node_modules
# ./docs/openapi/node_modules
# target
# key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: configure GPG key
if: (github.ref == 'refs/heads/master' || github.event_name == 'push') && github.repository == 'mCaptcha/mCaptcha'
@@ -97,12 +95,7 @@ jobs:
with:
node-version: "18.0.0"
- name: Install ${{ matrix.version }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.version }}-x86_64-unknown-linux-gnu
profile: minimal
override: true
- uses: actions-rust-lang/setup-rust-toolchain@v1
- name: install nightwatch dep
run: sudo apt-get install xvfb
@@ -117,7 +110,8 @@ jobs:
run: make
env:
POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}"
MARIA_DATABASE_URL: "${{ env.MARIA_DATABASE_URL }}"
MARIA_DATABASE_URL:
"${{ env.MARIA_DATABASE_URL }}"
# - name: build frontend
# run: make frontend

1
.nvmrc Normal file
View File

@@ -0,0 +1 @@
18

437
Cargo.lock generated
View File

@@ -119,7 +119,7 @@ dependencies = [
"actix-utils",
"actix-web",
"futures-util",
"serde 1.0.147",
"serde",
"serde_json",
"time 0.3.22",
]
@@ -131,7 +131,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "465a6172cf69b960917811022d8f29bc0b7fa1398bc4f78b3c466673db1213b6"
dependencies = [
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -143,7 +143,7 @@ dependencies = [
"bytestring",
"http",
"regex",
"serde 1.0.147",
"serde",
"tracing",
]
@@ -246,7 +246,7 @@ dependencies = [
"once_cell",
"pin-project-lite",
"regex",
"serde 1.0.147",
"serde",
"serde_json",
"serde_urlencoded",
"smallvec",
@@ -263,7 +263,7 @@ dependencies = [
"actix-router",
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -275,7 +275,7 @@ dependencies = [
"actix-router",
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -286,7 +286,7 @@ checksum = "6d44b8fee1ced9671ba043476deddef739dd0959bf77030b26b738cc591737a7"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -427,12 +427,6 @@ version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "arrayvec"
version = "0.7.4"
@@ -447,7 +441,7 @@ checksum = "ed6aa3524a2dfcf9fe180c51eae2b58738348d819517ceadf95789c51fff7600"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -456,7 +450,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5"
dependencies = [
"num-traits 0.2.15",
"num-traits",
]
[[package]]
@@ -504,7 +498,7 @@ dependencies = [
"percent-encoding",
"pin-project-lite",
"rand",
"serde 1.0.147",
"serde",
"serde_json",
"serde_urlencoded",
"tokio",
@@ -561,7 +555,7 @@ version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
dependencies = [
"serde 1.0.147",
"serde",
]
[[package]]
@@ -577,7 +571,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c2f0dc9a68c6317d884f97cc36cf5a3d20ba14ce404227df55e1af708ab04bc"
dependencies = [
"arrayref",
"arrayvec 0.7.4",
"arrayvec",
"constant_time_eq 0.2.6",
]
@@ -647,7 +641,7 @@ dependencies = [
"derive_builder",
"mime",
"mime_guess",
"serde 1.0.147",
"serde",
"serde_json",
"sha2",
"walkdir",
@@ -694,17 +688,20 @@ dependencies = [
[[package]]
name = "config"
version = "0.11.0"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1b9d958c2b1368a663f05538fc1b5975adce1e19f435acceae987aceeeb369"
checksum = "d379af7f68bfc21714c6c7dea883544201741d2ce8274bb12fa54f89507f52a7"
dependencies = [
"async-trait",
"json5",
"lazy_static",
"nom 5.1.3",
"nom",
"pathdiff",
"ron",
"rust-ini",
"serde 1.0.147",
"serde-hjson",
"serde",
"serde_json",
"toml",
"toml 0.5.11",
"yaml-rust",
]
@@ -891,7 +888,7 @@ dependencies = [
"proc-macro2",
"quote",
"strsim",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -902,7 +899,7 @@ checksum = "29b5acf0dea37a7f66f7b25d2c5e93fd46f8f6968b1a5d7a3e02e97768afc95a"
dependencies = [
"darling_core",
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -917,7 +914,7 @@ version = "0.1.0"
dependencies = [
"async-trait",
"libmcaptcha",
"serde 1.0.147",
"serde",
"serde_json",
"thiserror",
"url",
@@ -978,7 +975,7 @@ dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -988,7 +985,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8a2ac71b4a9a590dde6cee3ca4687aca5e7ce06f4ee297c5a959de5f1e42b2e"
dependencies = [
"derive_builder_core",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -1001,7 +998,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustc_version 0.4.0",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -1041,6 +1038,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]]
name = "dlv-list"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
[[package]]
name = "dotenv"
version = "0.15.0"
@@ -1053,7 +1056,7 @@ version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
dependencies = [
"serde 1.0.147",
"serde",
]
[[package]]
@@ -1094,6 +1097,12 @@ dependencies = [
"termcolor",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.1"
@@ -1259,7 +1268,7 @@ checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -1341,7 +1350,7 @@ dependencies = [
"futures-sink",
"futures-util",
"http",
"indexmap",
"indexmap 1.9.3",
"slab",
"tokio",
"tokio-util",
@@ -1362,6 +1371,15 @@ name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
dependencies = [
"ahash 0.7.6",
]
[[package]]
name = "hashbrown"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12"
[[package]]
name = "hashlink"
@@ -1451,7 +1469,7 @@ dependencies = [
"markup5ever",
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -1539,6 +1557,16 @@ dependencies = [
"hashbrown 0.12.3",
]
[[package]]
name = "indexmap"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897"
dependencies = [
"equivalent",
"hashbrown 0.14.1",
]
[[package]]
name = "inout"
version = "0.1.3"
@@ -1607,6 +1635,17 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "json5"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1"
dependencies = [
"pest",
"pest_derive",
"serde",
]
[[package]]
name = "language-tags"
version = "0.3.2"
@@ -1640,7 +1679,7 @@ dependencies = [
"idna 0.3.0",
"mime",
"native-tls",
"nom 7.1.3",
"nom",
"once_cell",
"quoted_printable",
"socket2",
@@ -1648,19 +1687,6 @@ dependencies = [
"tokio-native-tls",
]
[[package]]
name = "lexical-core"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
dependencies = [
"arrayvec 0.5.2",
"bitflags",
"cfg-if",
"ryu",
"static_assertions",
]
[[package]]
name = "libc"
version = "0.2.147"
@@ -1688,7 +1714,7 @@ dependencies = [
"pretty_env_logger",
"rand",
"redis",
"serde 1.0.147",
"serde",
"serde_json",
"tokio",
]
@@ -1814,7 +1840,7 @@ dependencies = [
"rand",
"rust-embed",
"sailfish",
"serde 1.0.147",
"serde",
"serde_json",
"sqlx",
"tokio",
@@ -1906,17 +1932,6 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54"
[[package]]
name = "nom"
version = "5.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08959a387a676302eebf4ddbcbc611da04285579f76f88ee0506c63b1a61dd4b"
dependencies = [
"lexical-core",
"memchr",
"version_check",
]
[[package]]
name = "nom"
version = "7.1.3"
@@ -1938,7 +1953,7 @@ dependencies = [
"num-integer",
"num-iter",
"num-rational",
"num-traits 0.2.15",
"num-traits",
]
[[package]]
@@ -1949,7 +1964,7 @@ checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3"
dependencies = [
"autocfg",
"num-integer",
"num-traits 0.2.15",
"num-traits",
]
[[package]]
@@ -1960,8 +1975,8 @@ checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
dependencies = [
"autocfg",
"num-integer",
"num-traits 0.2.15",
"serde 1.0.147",
"num-traits",
"serde",
]
[[package]]
@@ -1975,7 +1990,7 @@ dependencies = [
"libm",
"num-integer",
"num-iter",
"num-traits 0.2.15",
"num-traits",
"rand",
"smallvec",
"zeroize",
@@ -1987,8 +2002,8 @@ version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d"
dependencies = [
"num-traits 0.2.15",
"serde 1.0.147",
"num-traits",
"serde",
]
[[package]]
@@ -1998,7 +2013,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits 0.2.15",
"num-traits",
]
[[package]]
@@ -2009,7 +2024,7 @@ checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252"
dependencies = [
"autocfg",
"num-integer",
"num-traits 0.2.15",
"num-traits",
]
[[package]]
@@ -2020,17 +2035,8 @@ checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0"
dependencies = [
"autocfg",
"num-integer",
"num-traits 0.2.15",
"serde 1.0.147",
]
[[package]]
name = "num-traits"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
dependencies = [
"num-traits 0.2.15",
"num-traits",
"serde",
]
[[package]]
@@ -2097,7 +2103,7 @@ checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -2128,6 +2134,16 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "ordered-multimap"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ccd746e37177e1711c20dd619a1620f34f5c8b569c53590a72dedd5344d8924a"
dependencies = [
"dlv-list",
"hashbrown 0.12.3",
]
[[package]]
name = "parking_lot"
version = "0.11.2"
@@ -2182,6 +2198,12 @@ version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79"
[[package]]
name = "pathdiff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "pem-rfc7468"
version = "0.3.1"
@@ -2197,6 +2219,51 @@ version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
[[package]]
name = "pest"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c022f1e7b65d6a24c0dbbd5fb344c66881bc01f3e5ae74a1c8100f2f985d98a4"
dependencies = [
"memchr",
"thiserror",
"ucd-trie",
]
[[package]]
name = "pest_derive"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35513f630d46400a977c4cb58f78e1bfbe01434316e60c37d27b9ad6139c66d8"
dependencies = [
"pest",
"pest_generator",
]
[[package]]
name = "pest_generator"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc9fc1b9e7057baba189b5c626e2d6f40681ae5b6eb064dc7c7834101ec8123a"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn 2.0.38",
]
[[package]]
name = "pest_meta"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1df74e9e7ec4053ceb980e7c0c8bd3594e977fde1af91daba9c928e8e8c6708d"
dependencies = [
"once_cell",
"pest",
"sha2",
]
[[package]]
name = "phf"
version = "0.10.1"
@@ -2295,7 +2362,7 @@ dependencies = [
"bincode",
"derive_builder",
"num",
"serde 1.0.147",
"serde",
"sha2",
]
@@ -2307,7 +2374,7 @@ dependencies = [
"bincode",
"derive_builder",
"num",
"serde 1.0.147",
"serde",
"sha2",
]
@@ -2342,7 +2409,7 @@ dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
"version_check",
]
@@ -2365,11 +2432,11 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068"
[[package]]
name = "proc-macro2"
version = "1.0.36"
version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da"
dependencies = [
"unicode-xid",
"unicode-ident",
]
[[package]]
@@ -2380,9 +2447,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "1.0.19"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f53dc8cf16a769a6f677e09e7ff2cd4be1ea0f48754aac39520536962011de0d"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
@@ -2520,6 +2587,17 @@ dependencies = [
"winapi",
]
[[package]]
name = "ron"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a"
dependencies = [
"base64 0.13.1",
"bitflags",
"serde",
]
[[package]]
name = "rsa"
version = "0.6.1"
@@ -2531,7 +2609,7 @@ dependencies = [
"num-bigint-dig",
"num-integer",
"num-iter",
"num-traits 0.2.15",
"num-traits",
"pkcs1",
"pkcs8",
"rand_core",
@@ -2572,7 +2650,7 @@ dependencies = [
"proc-macro2",
"quote",
"rust-embed-utils",
"syn",
"syn 1.0.94",
"walkdir",
]
@@ -2588,9 +2666,13 @@ dependencies = [
[[package]]
name = "rust-ini"
version = "0.13.0"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2"
checksum = "f6d5f2436026b4f6e79dc829837d467cc7e9a55ee40e750d716713540715a2df"
dependencies = [
"cfg-if",
"ordered-multimap",
]
[[package]]
name = "rustc-demangle"
@@ -2651,9 +2733,9 @@ checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
[[package]]
name = "sailfish"
version = "0.4.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "948a7edfc2f03d7c58a097dda25ed29440a72e8528894a6e182fe9171195fed1"
checksum = "82a03fcade08eb837d7ba0d8f775f1fe6cddb00d413de0c655ab2b93e821a0eb"
dependencies = [
"itoap",
"ryu",
@@ -2663,25 +2745,25 @@ dependencies = [
[[package]]
name = "sailfish-compiler"
version = "0.4.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f0a01133d6ce146020e6416ac6a823f813f1cbb30ff77548b4fa20749524947"
checksum = "0cf1deecb07747a1f7ab55745edcc406875db007602b037af5fcf59f40dd2005"
dependencies = [
"filetime",
"home",
"memchr",
"proc-macro2",
"quote",
"serde 1.0.147",
"syn",
"toml",
"serde",
"syn 2.0.38",
"toml 0.7.8",
]
[[package]]
name = "sailfish-macros"
version = "0.4.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86326c1f1dce0b316e0a47071f683b185417dc64e1a704380b5c706b09e871b1"
checksum = "c3e5946289d6daa26cde6ffb06678d7a8ba276ec6a7a55d36f64b35e7f644d22"
dependencies = [
"proc-macro2",
"sailfish-compiler",
@@ -2774,12 +2856,6 @@ version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]]
name = "serde"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
[[package]]
name = "serde"
version = "1.0.147"
@@ -2789,18 +2865,6 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde-hjson"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8"
dependencies = [
"lazy_static",
"num-traits 0.1.43",
"regex",
"serde 0.8.23",
]
[[package]]
name = "serde_derive"
version = "1.0.147"
@@ -2809,7 +2873,7 @@ checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -2820,7 +2884,16 @@ checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3"
dependencies = [
"itoa",
"ryu",
"serde 1.0.147",
"serde",
]
[[package]]
name = "serde_spanned"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186"
dependencies = [
"serde",
]
[[package]]
@@ -2832,7 +2905,7 @@ dependencies = [
"form_urlencoded",
"itoa",
"ryu",
"serde 1.0.147",
"serde",
]
[[package]]
@@ -2946,7 +3019,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4b7922be017ee70900be125523f38bdd644f4f06a1b16e8fa5a8ee8c34bffd4"
dependencies = [
"itertools",
"nom 7.1.3",
"nom",
"unicode_categories",
]
@@ -2987,7 +3060,7 @@ dependencies = [
"hex",
"hkdf",
"hmac",
"indexmap",
"indexmap 1.9.3",
"itoa",
"libc",
"log",
@@ -3000,7 +3073,7 @@ dependencies = [
"rand",
"rsa",
"rustls",
"serde 1.0.147",
"serde",
"serde_json",
"sha-1",
"sha2",
@@ -3030,12 +3103,12 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"serde 1.0.147",
"serde",
"serde_json",
"sha2",
"sqlx-core",
"sqlx-rt",
"syn",
"syn 1.0.94",
"url",
]
@@ -3060,12 +3133,6 @@ dependencies = [
"version_check",
]
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "stdweb"
version = "0.4.20"
@@ -3088,9 +3155,9 @@ checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef"
dependencies = [
"proc-macro2",
"quote",
"serde 1.0.147",
"serde",
"serde_derive",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -3102,11 +3169,11 @@ dependencies = [
"base-x",
"proc-macro2",
"quote",
"serde 1.0.147",
"serde",
"serde_derive",
"serde_json",
"sha1 0.6.1",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -3126,7 +3193,7 @@ dependencies = [
"parking_lot 0.12.1",
"phf_shared",
"precomputed-hash",
"serde 1.0.147",
"serde",
]
[[package]]
@@ -3174,6 +3241,17 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "syn"
version = "2.0.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tempfile"
version = "3.6.0"
@@ -3225,7 +3303,7 @@ checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -3250,7 +3328,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea9e1b3cf1243ae005d9e74085d4d542f3125458f3a81af210d901dcd7411efd"
dependencies = [
"itoa",
"serde 1.0.147",
"serde",
"time-core",
"time-macros 0.2.9",
]
@@ -3290,7 +3368,7 @@ dependencies = [
"proc-macro2",
"quote",
"standback",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -3379,7 +3457,41 @@ version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
dependencies = [
"serde 1.0.147",
"serde",
]
[[package]]
name = "toml"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.19.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
dependencies = [
"indexmap 2.0.2",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]]
@@ -3409,6 +3521,12 @@ version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
[[package]]
name = "ucd-trie"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
[[package]]
name = "unicase"
version = "2.6.0"
@@ -3424,6 +3542,12 @@ version = "0.3.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460"
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-normalization"
version = "0.1.22"
@@ -3476,7 +3600,7 @@ dependencies = [
"form_urlencoded",
"idna 0.4.0",
"percent-encoding",
"serde 1.0.147",
"serde",
]
[[package]]
@@ -3498,7 +3622,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d023da39d1fde5a8a3fe1f3e01ca9632ada0a63e9797de55a879d6e2236277be"
dependencies = [
"getrandom",
"serde 1.0.147",
"serde",
]
[[package]]
@@ -3510,7 +3634,7 @@ dependencies = [
"idna 0.2.3",
"lazy_static",
"regex",
"serde 1.0.147",
"serde",
"serde_derive",
"serde_json",
"url",
@@ -3529,7 +3653,7 @@ dependencies = [
"proc-macro2",
"quote",
"regex",
"syn",
"syn 1.0.94",
"validator_types",
]
@@ -3540,7 +3664,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2ddf34293296847abfc1493b15c6e2f5d3cd19f57ad7d22673bf4c6278da329"
dependencies = [
"proc-macro2",
"syn",
"syn 1.0.94",
]
[[package]]
@@ -3592,7 +3716,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
"wasm-bindgen-shared",
]
@@ -3614,7 +3738,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 1.0.94",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@@ -3818,6 +3942,15 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]]
name = "winnow"
version = "0.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c"
dependencies = [
"memchr",
]
[[package]]
name = "yaml-rust"
version = "0.4.5"

View File

@@ -41,7 +41,7 @@ tokio = { version = "1.14", features = ["sync"]}
sqlx = { version = "0.5.13", features = [ "runtime-actix-rustls", "postgres", "time", "offline", "mysql"] }
argon2-creds = { branch = "master", git = "https://github.com/realaravinth/argon2-creds"}
#argon2-creds = { version="*", path = "../../argon2-creds/" }
config = "0.11"
config = "0.13"
validator = { version = "0.15", features = ["derive"]}
derive_builder = "0.11"
@@ -65,7 +65,7 @@ libmcaptcha = { version = "0.2.3", git = "https://github.com/mCaptcha/libmcaptch
rand = "0.8"
sailfish = "0.4.0"
sailfish = "0.7.0"
mime = "0.3.16"

View File

@@ -1,7 +1,6 @@
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
FROM node:18.0.0 as frontend
RUN set -ex; \
apt-get update; \
@@ -21,33 +20,16 @@ COPY Makefile /src/
COPY scripts /src/scripts
RUN make frontend
FROM rust:latest as planner
RUN cargo install cargo-chef
WORKDIR /src
COPY . /src/
RUN cargo chef prepare --recipe-path recipe.json
FROM rust:latest as cacher
WORKDIR /src/
RUN cargo install cargo-chef
COPY --from=planner /src/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
FROM rust:latest as rust
WORKDIR /src
COPY . .
COPY --from=cacher /src/target target
#COPY --from=cacher /src/db/db-core/target /src/db/db-core/target
#COPY --from=cacher /src/db/db-sqlx-postgres/target /src/db/db-sqlx-postgres/target
#COPY --from=cacher /src/db/db-migrations/target /src/db/db-migrations/target
#COPY --from=cacher /src/utils/cache-bust/target /src/utils/cache-bust/target
COPY --from=frontend /src/static/cache/bundle/ /src/static/cache/bundle/
COPY --from=frontend /src/docs/openapi/dist/ /src/docs/openapi/dist/
RUN cargo --version
RUN make cache-bust
RUN cargo build --release
FROM debian:bullseye as mCaptcha
FROM debian:bookworm as mCaptcha
LABEL org.opencontainers.image.source https://github.com/mCaptcha/mCaptcha
RUN useradd -ms /bin/bash -u 1001 mcaptcha
WORKDIR /home/mcaptcha

View File

@@ -34,8 +34,7 @@ endef
define run_dev_migrations ## run database migrations
cd db/db-sqlx-maria/ && \
DATABASE_URL=${MARIA_DATABASE_URL} sqlx migrate run
cd db/db-sqlx-postgres/ && \
DATABASE_URL=${MARIA_DATABASE_URL} sqlx migrate run cd db/db-sqlx-postgres/ && \
DATABASE_URL=${POSTGRES_DATABASE_URL} sqlx migrate run
endef
@@ -67,11 +66,9 @@ define test_db_sqlx_maria
endef
define test_core
cargo test --no-fail-fast
cargo test --no-fail-fast --jobs=4
endef
default: frontend ## Build app in debug mode
$(call cache_bust)
cargo build

View File

@@ -42,17 +42,11 @@ duration = 30 # cooldown period in seconds
# This section deals with the database location and how to access it
# Please note that at the moment, we have support for only postgresqa.
# Example, if you are Batman, your config would be:
# hostname = "batcave.org"
# port = "5432"
# username = "batman"
# password = "somereallycomplicatedBatmanpassword"
hostname = "localhost"
port = "5432"
username = "postgres"
password = "password"
name = "postgres"
# url = "postgres://batman:password@batcave.org:5432/batcave"
# database_type = "postgres"
# pool = 4
url = "postgres://example.org" # hack for tests to run successfully
pool = 4
database_type="postgres" # "postgres", "maria"
[redis]
# This section deals with the database location and how to access it

View File

@@ -21,54 +21,52 @@ you will be overriding the values set in the configuration files.
| Name | Value |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `MCAPTCHA_CONFIG` | Path to configuration file |
| `MCAPTCHA_COMMERCIAL` | Does this instance offer commercial plans? Please consider donating if it does :D |
| `MCAPTCHA_SOURCE_CODE` | Link to the source code of this instance |
| `MCAPTCHA_ALLOW_REGISTRATION` | Is registration allowed on this instance? |
| `MCAPTCHA_ALLOW_DEMO` | Allow demo access to the server? If registration(previous option) is disabled then demo users will not be allowed |
| `MCAPTCHA_debug` | Enable debug logging |
| `MCAPTCHA_config` | Path to configuration file |
| `MCAPTCHA_commercial` | Does this instance offer commercial plans? Please consider donating if it does :D |
| `MCAPTCHA_source_code` | Link to the source code of this instance |
| `MCAPTCHA_allow_registration` | Is registration allowed on this instance? |
| `MCAPTCHA_allow_demo` | Allow demo access to the server? If registration(previous option) is disabled then demo users will not be allowed |
#### Database
### Database
| Name | Value |
| ------------------------------------ | -------------------------------------------------------------- |
| `MCAPTCHA_DATEBASE_PASSWORD` | database user password |
| `MCAPTCHA_DATEBASE_NAME` | database name |
| `MCAPTCHA_DATEBASE_PORT` | port on which the DBMS is running |
| `MCAPTCHA_DATEBASE_HOSTNAME` | hostname of the DBMS |
| `MCAPTCHA_DATEBASE_USERNAME` | database username |
| `MCAPTCHA_DATEBASE_POOL` | database connection pool size |
| `MCAPTCHA_DATEBASE_DATABASE_TYPE` | database tpye: "postgres" or "maria" |
| Name | Value |
| ------------------------------------- | -------------------------------------------------------------- |
| `MCAPTCHA_database_DATEBASE_POOL` | database connection pool size |
| `DATABASE_URL` (overrides above vars) | database URL in `postgres://user:pass@host:port/dbname` format |
#### Redis
### Redis
| Name | Value |
| --------------------- | -------------------------- |
| `MCAPTCHA_REDIS_URL` | Redis URL |
| `MCAPTCHA_REDIS_POOL` | Redis connection pool size |
| `MCAPTCHA_redis_URL` | Redis URL |
| `MCAPTCHA_redis_POOL` | Redis connection pool size |
#### Server
### Server
| Name | Value |
| ---------------------------------------- | ---------------------------------------------------------------------------------- |
| `MCAPTCHA_SERVER_PORT` | The port on which you want mCaptcha to listen to |
| `PORT`(overrides `MCAPTCHA_SERVER_PORT`) | The port on which you want mCaptcha to listen to |
| `MCAPTCHA_SERVER_IP` | The IP address on which you want mCaptcha to listen to |
| `MCAPTCHA_SERVER_DOMAIN` | Domain under which mCaptcha will be\* |
| `MCAPTCHA_SERVER_COOKIE_SECRET` | Cookie secret, must be long and random |
| `MCAPTCHA_SERVER_PROXY_HAS_TLS` | Is mCaptcha behind a proxy? If yes, mCaptcha can send additional headers like HSTS |
| Name | Value |
| ------------------------------- | ---------------------------------------------------------------------------------- |
| `PORT` | The port on which you want mCaptcha to listen to |
| `MCAPTCHA_server_IP` | The IP address on which you want mCaptcha to listen to |
| `MCAPTCHA_server_DOMAIN` | Domain under which mCaptcha will be\* |
| `MCAPTCHA_server_COOKIE_SECRET` | Cookie secret, must be long and random |
| `MCAPTCHA_server_PROXY_HAS_TLS` | Is mCaptcha behind a proxy? If yes, mCaptcha can send additional headers like HSTS |
\* Authentication doesn't work without `MCAPTCHA_DOMAIN` set to the correct domain
### Captcha
| Name | Value |
| ---------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| `MCAPTCHA_CAPTCHA_SALT` | Salt has to be long and random |
| `MCAPTCHA_CAPTCHA_GC` | Garbage collection duration in seconds, requires tuning but 30 is a good starting point |
| `MCAPTCHA_CAPTCHA_AVG_TRAFFIC_DIFFICULTY`% | Difficulty factor to use in CAPTCHA configuration estimation for average traffic metric |
| `MCAPTCHA_CAPTCHA_PEAK_TRAFFIC_DIFFICULTY`% | Difficulty factor to use in CAPTCHA configuration estimation for peak traffic metric |
| `MCAPTCHA_CAPTCHA_BROKE_MY_SITE_TRAFFIC_DIFFICULTY`% | Difficulty factor to use in CAPTCHA configuration estimation for traffic that took the website down |
| Name | Value |
| ----------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | --- |
| `MCAPTCHA_captcha_SALT` | Salt has to be long and random |
| `MCAPTCHA_captcha_GC` | Garbage collection duration in seconds, requires tuning but 30 is a good starting point |
| `MCAPTCHA_captcha_RUNNERS` | [Performance] Number of runners to use for PoW validation. Defaults to number of CPUs available |
| `MCAPTCHA_captcha_QUEUE_LENGTH` | [Performance] PoW Validation queue length, controls how many pending validation jobs can be held in queue |
| `MCAPTCHA_captcha_ENABLE_STATS` | Record for CAPTCHA events like configuration fetch, solves and authentication of validation token. Useful for commercial deployments. | |
| `MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_avg_traffic_difficulty`% | Default difficulty factor to use in easy mode CAPTCHA configuration estimation for average traffic metric |
| `MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_peak_sustainable_traffic_difficulty`% | Default difficulty factor to use in easy mode CAPTCHA configuration estimation for peak traffic metric |
| `MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_broke_my_site_traffic_difficulty`% | Default difficulty factor to use in easy mode CAPTCHA configuration estimation for traffic that took the website down |
| `MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_duration`% | Default duration to use in CAPTCHA configuration in easy mode |
\% See commits
[`54b14291ec140e`](https://github.com/mCaptcha/mCaptcha/commit/54b14291ec140ea4cbbf73462d3d6fc2d39f2d2c)
@@ -80,9 +78,8 @@ for more info.
| Name | Value |
| ------------------------ | ----------------------------------------------- |
| `MCAPTCHA_SMTP_FROM` | email address from which the email will be sent |
| `MCAPTCHA_SMTP_REPLY_TO` | email address to which reply can be sent |
| `MCAPTCHA_URL` | SMTP server URL |
| `MCAPTCHA_SMTP_PORT` | SMTP server port |
| `MCAPTCHA_SMTP_USERNAME` | SMTP username |
| `MCAPTCHA_SMTP_PASSWORD` | SMTP password |
| `MCAPTCHA_smtp_FROM` | email address from which the email will be sent |
| `MCAPTCHA_smtp_URL` | SMTP server URL |
| `MCAPTCHA_smtp_PORT` | SMTP server port |
| `MCAPTCHA_smtp_USERNAME` | SMTP username |
| `MCAPTCHA_smtp_PASSWORD` | SMTP password |

12
package-lock.json generated
View File

@@ -8366,9 +8366,9 @@
}
},
"node_modules/postcss": {
"version": "8.4.31",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
"integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==",
"version": "8.4.24",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.24.tgz",
"integrity": "sha512-M0RzbcI0sO/XJNucsGjvWU9ERWxb/ytp1w6dKtxTKgixdtQDq4rmx/g8W1hnaheq9jgwL/oyEdH5Bc4WwJKMqg==",
"dev": true,
"funding": [
{
@@ -17362,9 +17362,9 @@
}
},
"postcss": {
"version": "8.4.31",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz",
"integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==",
"version": "8.4.24",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.24.tgz",
"integrity": "sha512-M0RzbcI0sO/XJNucsGjvWU9ERWxb/ytp1w6dKtxTKgixdtQDq4rmx/g8W1hnaheq9jgwL/oyEdH5Bc4WwJKMqg==",
"dev": true,
"requires": {
"nanoid": "^3.3.6",

View File

@@ -6,23 +6,25 @@
use std::path::Path;
use std::{env, fs};
use config::{Config, ConfigError, Environment, File};
use config::builder::DefaultState;
use config::{Config, ConfigBuilder, ConfigError, File};
use derive_more::Display;
use serde::{Deserialize, Serialize};
use url::Url;
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
pub struct Server {
pub port: u32,
pub domain: String,
pub cookie_secret: String,
pub ip: String,
// TODO: remove
pub url_prefix: Option<String>,
pub proxy_has_tls: bool,
}
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
pub struct Captcha {
pub salt: String,
pub gc: u64,
@@ -32,7 +34,7 @@ pub struct Captcha {
pub default_difficulty_strategy: DefaultDifficultyStrategy,
}
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
pub struct DefaultDifficultyStrategy {
pub avg_traffic_difficulty: u32,
pub broke_my_site_traffic_difficulty: u32,
@@ -40,7 +42,7 @@ pub struct DefaultDifficultyStrategy {
pub duration: u32,
}
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
pub struct Smtp {
pub from: String,
pub reply: String,
@@ -57,33 +59,7 @@ impl Server {
}
}
//#[derive(Debug, Clone, Deserialize)]
//struct DatabaseBuilder {
// pub port: u32,
// pub hostname: String,
// pub username: String,
// pub password: String,
// pub name: String,
//}
//impl DatabaseBuilder {
// #[cfg(not(tarpaulin_include))]
// fn extract_database_url(url: &Url) -> Self {
// debug!("Database name: {}", url.path());
// let mut path = url.path().split('/');
// path.next();
// let name = path.next().expect("no database name").to_string();
// DatabaseBuilder {
// port: url.port().expect("Enter database port").into(),
// hostname: url.host().expect("Enter database host").to_string(),
// username: url.username().into(),
// password: url.password().expect("Enter database password").into(),
// name,
// }
// }
//}
#[derive(Deserialize, Serialize, Display, PartialEq, Clone, Debug)]
#[derive(Deserialize, Serialize, Display, Eq, PartialEq, Clone, Debug)]
#[serde(rename_all = "lowercase")]
pub enum DBType {
#[display(fmt = "postgres")]
@@ -102,51 +78,112 @@ impl DBType {
}
}
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
pub struct Database {
pub url: String,
pub pool: u32,
pub database_type: DBType,
}
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
pub struct Redis {
pub url: String,
pub pool: u32,
}
#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
pub struct Settings {
pub debug: bool,
pub commercial: bool,
pub source_code: String,
pub allow_registration: bool,
pub allow_demo: bool,
pub database: Database,
pub redis: Option<Redis>,
pub server: Server,
pub captcha: Captcha,
pub source_code: String,
pub smtp: Option<Smtp>,
pub allow_registration: bool,
pub allow_demo: bool,
}
const ENV_VAR_CONFIG: [(&str, &str); 29] = [
/* top-level */
("debug", "MCAPTCHA_debug"),
("commercial", "MCAPTCHA_commercial"),
("source_code", "MCAPTCHA_source_code"),
("allow_registration", "MCAPTCHA_allow_registration"),
("allow_demo", "MCAPTCHA_allow_demo"),
/* database */
("database.url", "DATABASE_URL"),
("database.pool", "MCAPTCHA_database_POOL"),
/* redis */
("redis.url", "MCPATCHA_redis_URL"),
("redis.pool", "MCPATCHA_redis_POOL"),
/* server */
("server.port", "PORT"),
("server.domain", "MCAPTCHA_server_DOMAIN"),
("server.cookie_secret", "MCAPTCHA__server_COOKIE_SECRET"),
("server.ip", "MCAPTCHA__server_IP"),
("server.proxy_has_tls", "MCAPTCHA__server_PROXY_HAS_TLS"),
/* captcha */
("captcha.salt", "MCAPTCHA_captcha_SALT"),
("captcha.gc", "MCAPTCHA_captcha_GC"),
("captcha.runners", "MCAPTCHA_captcha_RUNNERS"),
("captcha.queue_length", "MCAPTCHA_captcha_QUEUE_LENGTH"),
("captcha.enable_stats", "MCAPTCHA_captcha_ENABLE_STATS"),
("captcha.default_difficulty_strategy.avg_traffic_difficulty", "MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_avg_traffic_difficulty"),
("captcha.default_difficulty_strategy.broke_my_site_traffic_difficulty", "MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_broke_my_site_traffic_difficulty"),
("captcha.default_difficulty_strategy.peak_sustainable_traffic_difficulty",
"MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_peak_sustainable_traffic_difficulty"),
( "captcha.default_difficulty_strategy.duration",
"MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_duration"
),
/* SMTP */
("smtp.from", "MCPATCHA_smtp_FROM"),
("smtp.reply", "MCPATCHA_smtp_REPLY"),
("smtp.url", "MCPATCHA_smtp_URL"),
("smtp.username", "MCPATCHA_smtp_USERNAME"),
("smtp.password", "MCPATCHA_smtp_PASSWORD"),
("smtp.port", "MCPATCHA_smtp_PORT"),
];
#[cfg(not(tarpaulin_include))]
impl Settings {
pub fn new() -> Result<Self, ConfigError> {
let mut s = Config::new();
let mut s = Config::builder();
const CURRENT_DIR: &str = "./config/default.toml";
const ETC: &str = "/etc/mcaptcha/config.toml";
s.set("capatcha.enable_stats", true.to_string())
s = s
.set_default("capatcha.enable_stats", true.to_string())
.expect("unable to set capatcha.enable_stats default config");
// Will be overridden after config is parsed and loaded into Settings by
// Settings::set_database_type.
// This parameter is not ergonomic for users, but it is required and can be programatically
// inferred. But we need a default value for config lib to parse successfully, since it is
// DBType and not Option<DBType>
s = s
.set_default("database.database_type", DBType::Postgres.to_string())
.expect("unable to set database.database_type default config");
if let Ok(path) = env::var("MCAPTCHA_CONFIG") {
let absolute_path = Path::new(&path).canonicalize().unwrap();
log::info!(
"Loading config file from {}",
absolute_path.to_str().unwrap()
);
s.merge(File::with_name(absolute_path.to_str().unwrap()))?;
s = s.add_source(File::with_name(absolute_path.to_str().unwrap()));
} else if Path::new(CURRENT_DIR).exists() {
let absolute_path = fs::canonicalize(CURRENT_DIR).unwrap();
log::info!(
@@ -154,102 +191,216 @@ impl Settings {
absolute_path.to_str().unwrap()
);
// merging default config from file
s.merge(File::with_name(absolute_path.to_str().unwrap()))?;
s = s.add_source(File::with_name(absolute_path.to_str().unwrap()));
} else if Path::new(ETC).exists() {
log::info!("{}", format!("Loading config file from {}", ETC));
s.merge(File::with_name(ETC))?;
s = s.add_source(File::with_name(ETC));
} else {
log::warn!("Configuration file not found");
}
s.merge(Environment::with_prefix("MCAPTCHA").separator("_"))?;
s = Self::env_override(s);
check_url(&s);
let mut settings = s.build()?.try_deserialize::<Settings>()?;
settings.check_url();
if let Ok(val) = env::var("PORT") {
s.set("server.port", val).unwrap();
log::info!("Overriding [server].port with environment variable");
}
settings.set_database_type();
match env::var("DATABASE_URL") {
Ok(val) => {
let url = Url::parse(&val).expect("couldn't parse Database URL");
s.set("database.url", url.to_string()).unwrap();
let database_type = DBType::from_url(&url).unwrap();
s.set("database.database_type", database_type.to_string())
.unwrap();
log::info!("Overriding [database].url and [database].database_type with environment variable");
}
Err(_e) => {
set_database_url(&mut s);
Ok(settings)
}
fn env_override(mut s: ConfigBuilder<DefaultState>) -> ConfigBuilder<DefaultState> {
for (parameter, env_var_name) in ENV_VAR_CONFIG.iter() {
if let Ok(val) = env::var(env_var_name) {
log::debug!(
"Overriding [{parameter}] with environment variable {env_var_name}"
);
s = s.set_override(parameter, val).unwrap();
}
}
// setting default values
#[cfg(test)]
s.set("database.pool", 2.to_string())
.expect("Couldn't set database pool count");
s
}
match s.try_into() {
Ok(val) => Ok(val),
Err(e) => Err(ConfigError::Message(format!("\n\nError: {}. If it says missing fields, then please refer to https://github.com/mCaptcha/mcaptcha#configuration to learn more about how mcaptcha reads configuration\n\n", e))),
}
fn set_database_type(&mut self) {
let url = Url::parse(&self.database.url)
.expect("couldn't parse Database URL and detect database type");
self.database.database_type = DBType::from_url(&url).unwrap();
}
fn check_url(&self) {
Url::parse(&self.source_code)
.expect("Please enter a URL for source_code in settings");
}
}
#[cfg(not(tarpaulin_include))]
fn check_url(s: &Config) {
let url = s
.get::<String>("source_code")
.expect("Couldn't access source_code");
#[cfg(test)]
mod tests {
Url::parse(&url).expect("Please enter a URL for source_code in settings");
use super::*;
#[test]
fn env_override_works() {
use crate::tests::get_settings;
let init_settings = get_settings();
// so that it can be tested outside the macro (helper) too
let mut new_settings;
macro_rules! helper {
($env:expr, $val:expr, $val_typed:expr, $($param:ident).+) => {
println!("Setting env var {} to {} for test", $env, $val);
env::set_var($env, $val);
new_settings = get_settings();
assert_eq!(new_settings.$($param).+, $val_typed);
assert_ne!(new_settings.$($param).+, init_settings.$($param).+);
env::remove_var($env);
};
($env:expr, $val:expr, $($param:ident).+) => {
helper!($env, $val.to_string(), $val, $($param).+);
};
}
/* top level */
helper!("MCAPTCHA_debug", false, debug);
helper!("MCAPTCHA_commercial", true, commercial);
helper!("MCAPTCHA_allow_registration", false, allow_registration);
helper!("MCAPTCHA_allow_demo", false, allow_demo);
/* database_type */
helper!(
"DATABASE_URL",
"postgres://postgres:password@localhost:5432/postgres",
database.url
);
assert_eq!(new_settings.database.database_type, DBType::Postgres);
helper!(
"DATABASE_URL",
"mysql://maria:password@localhost/maria",
database.url
);
assert_eq!(new_settings.database.database_type, DBType::Maria);
helper!("MCAPTCHA_database_POOL", 1000, database.pool);
/* redis */
/* redis.url */
let env = "MCPATCHA_redis_URL";
let val = "redis://redis.example.org";
println!("Setting env var {} to {} for test", env, val);
env::set_var(env, val.to_string());
new_settings = get_settings();
assert_eq!(new_settings.redis.as_ref().unwrap().url, val);
assert_ne!(
new_settings.redis.as_ref().unwrap().url,
init_settings.redis.as_ref().unwrap().url
);
env::remove_var(env);
/* redis.pool */
let env = "MCPATCHA_redis_POOL";
let val = 999;
println!("Setting env var {} to {} for test", env, val);
env::set_var(env, val.to_string());
new_settings = get_settings();
assert_eq!(new_settings.redis.as_ref().unwrap().pool, val);
assert_ne!(
new_settings.redis.as_ref().unwrap().pool,
init_settings.redis.as_ref().unwrap().pool
);
env::remove_var(env);
helper!("PORT", 0, server.port);
helper!("MCAPTCHA_server_DOMAIN", "example.org", server.domain);
helper!(
"MCAPTCHA__server_COOKIE_SECRET",
"dafasdfsdf",
server.cookie_secret
);
helper!("MCAPTCHA__server_IP", "9.9.9.9", server.ip);
helper!("MCAPTCHA__server_PROXY_HAS_TLS", true, server.proxy_has_tls);
/* captcha */
helper!("MCAPTCHA_captcha_SALT", "foobarasdfasdf", captcha.salt);
helper!("MCAPTCHA_captcha_GC", 500, captcha.gc);
helper!(
"MCAPTCHA_captcha_RUNNERS",
"500",
Some(500),
captcha.runners
);
helper!("MCAPTCHA_captcha_QUEUE_LENGTH", 500, captcha.queue_length);
helper!("MCAPTCHA_captcha_ENABLE_STATS", false, captcha.enable_stats);
helper!(
"MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_avg_traffic_difficulty",
999,
captcha.default_difficulty_strategy.avg_traffic_difficulty
);
helper!("MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_peak_sustainable_traffic_difficulty", 999 , captcha.default_difficulty_strategy.peak_sustainable_traffic_difficulty);
helper!("MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_broke_my_site_traffic_difficulty", 999 , captcha.default_difficulty_strategy.broke_my_site_traffic_difficulty);
helper!(
"MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_duration",
999,
captcha.default_difficulty_strategy.duration
);
/* SMTP */
let vals = [
"MCPATCHA_smtp_FROM",
"MCPATCHA_smtp_REPLY",
"MCPATCHA_smtp_URL",
"MCPATCHA_smtp_USERNAME",
"MCPATCHA_smtp_PASSWORD",
"MCPATCHA_smtp_PORT",
];
for env in vals.iter() {
println!("Setting env var {} to {} for test", env, env);
env::set_var(env, env.to_string());
}
let port = 9999;
env::set_var("MCPATCHA_smtp_PORT", port.to_string());
new_settings = get_settings();
let smtp_new = new_settings.smtp.as_ref().unwrap();
let smtp_old = init_settings.smtp.as_ref().unwrap();
assert_eq!(smtp_new.from, "MCPATCHA_smtp_FROM");
assert_eq!(smtp_new.reply, "MCPATCHA_smtp_REPLY");
assert_eq!(smtp_new.username, "MCPATCHA_smtp_USERNAME");
assert_eq!(smtp_new.password, "MCPATCHA_smtp_PASSWORD");
assert_eq!(smtp_new.port, port);
assert_ne!(smtp_new, smtp_old);
for env in vals.iter() {
env::remove_var(env);
}
}
// #[test]
// fn url_prefix_test() {
// let mut settings = Settings::new().unwrap();
// assert!(settings.server.url_prefix.is_none());
// settings.server.url_prefix = Some("test".into());
// settings.server.check_url_prefix();
// settings.server.url_prefix = Some(" ".into());
// settings.server.check_url_prefix();
// assert!(settings.server.url_prefix.is_none());
// }
//
// #[test]
// fn smtp_config_works() {
// let settings = Settings::new().unwrap();
// assert!(settings.smtp.is_some());
// assert_eq!(settings.smtp.as_ref().unwrap().password, "password");
// assert_eq!(settings.smtp.as_ref().unwrap().username, "admin");
// }
}
#[cfg(not(tarpaulin_include))]
fn set_database_url(s: &mut Config) {
s.set(
"database.url",
format!(
r"postgres://{}:{}@{}:{}/{}",
s.get::<String>("database.username")
.expect("Couldn't access database username"),
urlencoding::encode(
s.get::<String>("database.password")
.expect("Couldn't access database password")
.as_str()
),
s.get::<String>("database.hostname")
.expect("Couldn't access database hostname"),
s.get::<String>("database.port")
.expect("Couldn't access database port"),
s.get::<String>("database.name")
.expect("Couldn't access database name")
),
)
.expect("Couldn't set database url");
}
//#[cfg(test)]
//mod tests {
// use super::*;
//
// #[test]
// fn url_prefix_test() {
// let mut settings = Settings::new().unwrap();
// assert!(settings.server.url_prefix.is_none());
// settings.server.url_prefix = Some("test".into());
// settings.server.check_url_prefix();
// settings.server.url_prefix = Some(" ".into());
// settings.server.check_url_prefix();
// assert!(settings.server.url_prefix.is_none());
// }
//
// #[test]
// fn smtp_config_works() {
// let settings = Settings::new().unwrap();
// assert!(settings.smtp.is_some());
// assert_eq!(settings.smtp.as_ref().unwrap().password, "password");
// assert_eq!(settings.smtp.as_ref().unwrap().username, "admin");
// }
//}

View File

@@ -40,7 +40,8 @@ pub mod pg {
settings.captcha.runners = Some(1);
settings.database.url = url.clone();
settings.database.database_type = DBType::Postgres;
settings.database.pool = 2;
Data::new(&settings).await
}
}
@@ -59,7 +60,8 @@ pub mod maria {
settings.captcha.runners = Some(1);
settings.database.url = url.clone();
settings.database.database_type = DBType::Maria;
settings.database.pool = 2;
Data::new(&settings).await
}
}

View File

@@ -4317,9 +4317,9 @@ postcss-value-parser@^4.1.0, postcss-value-parser@^4.2.0:
integrity sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==
postcss@^8.4.21, postcss@^8.4.24:
version "8.4.31"
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.31.tgz#92b451050a9f914da6755af352bdc0192508656d"
integrity sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==
version "8.4.24"
resolved "https://registry.npmjs.org/postcss/-/postcss-8.4.24.tgz"
integrity sha512-M0RzbcI0sO/XJNucsGjvWU9ERWxb/ytp1w6dKtxTKgixdtQDq4rmx/g8W1hnaheq9jgwL/oyEdH5Bc4WwJKMqg==
dependencies:
nanoid "^3.3.6"
picocolors "^1.0.0"