mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
Compare commits
11 Commits
v0.1.0-rc1
...
fix-154
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a7e71b499 | ||
|
|
91955501e2 | ||
|
|
cb72b0adfa | ||
|
|
c1fe45d409 | ||
|
|
59e339f287 | ||
|
|
ddcde9cf18 | ||
|
|
65c92ee96e | ||
|
|
40766ff44f | ||
|
|
ddc3008009 | ||
|
|
cba056aba6 | ||
|
|
16c975d2ec |
@@ -13,7 +13,7 @@ MCAPTCHA_redis_URL=redis://mcaptcha_redis
|
|||||||
MCAPTCHA_redis_POOL=4
|
MCAPTCHA_redis_POOL=4
|
||||||
|
|
||||||
# server
|
# server
|
||||||
PORT=7001
|
PORT=7000
|
||||||
MCAPTCHA_server_DOMAIN=localhost
|
MCAPTCHA_server_DOMAIN=localhost
|
||||||
MCAPTCHA__server_COOKIE_SECRET=pleasereplacethiswithrandomstring # PLEASE SET RANDOM STRING. MIN LENGTH=32
|
MCAPTCHA__server_COOKIE_SECRET=pleasereplacethiswithrandomstring # PLEASE SET RANDOM STRING. MIN LENGTH=32
|
||||||
MCAPTCHA__server_IP= 0.0.0.0
|
MCAPTCHA__server_IP= 0.0.0.0
|
||||||
@@ -26,8 +26,8 @@ MCAPTCHA_captcha_RUNNERS=4
|
|||||||
MCAPTCHA_captcha_QUEUE_LENGTH=2000
|
MCAPTCHA_captcha_QUEUE_LENGTH=2000
|
||||||
MCAPTCHA_captcha_ENABLE_STATS=true
|
MCAPTCHA_captcha_ENABLE_STATS=true
|
||||||
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_avg_traffic_difficulty=50000 # almost instant solution
|
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_avg_traffic_difficulty=50000 # almost instant solution
|
||||||
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_broke_my_site_traffic_difficulty=3000000 # roughly 1.5s
|
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_peak_sustainable_traffic_difficulty=3000000 # greater than 3.5s
|
||||||
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_peak_sustainable_traffic_difficulty=5000000 # greater than 3.5s
|
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_broke_my_site_traffic_difficulty=5000000 # roughly 1.5s
|
||||||
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_duration=30 # cooldown period in seconds
|
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_duration=30 # cooldown period in seconds
|
||||||
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_avg_traffic_time=1 # almost instant solution
|
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_avg_traffic_time=1 # almost instant solution
|
||||||
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_peak_sustainable_traffic_time=3
|
MCAPTCHA_captcha_DEFAULT_DIFFICULTY_STRATEGY_peak_sustainable_traffic_time=3
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ RUN cargo build --release
|
|||||||
|
|
||||||
FROM debian:bookworm as mCaptcha
|
FROM debian:bookworm as mCaptcha
|
||||||
LABEL org.opencontainers.image.source https://github.com/mCaptcha/mCaptcha
|
LABEL org.opencontainers.image.source https://github.com/mCaptcha/mCaptcha
|
||||||
|
RUN set -ex; \
|
||||||
|
apt-get update; \
|
||||||
|
DEBIAN_FRONTEND=noninteractive \
|
||||||
|
apt-get install -y --no-install-recommends curl
|
||||||
RUN useradd -ms /bin/bash -u 1001 mcaptcha
|
RUN useradd -ms /bin/bash -u 1001 mcaptcha
|
||||||
WORKDIR /home/mcaptcha
|
WORKDIR /home/mcaptcha
|
||||||
COPY --from=rust /src/target/release/mcaptcha /usr/local/bin/
|
COPY --from=rust /src/target/release/mcaptcha /usr/local/bin/
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ enable_stats = true
|
|||||||
|
|
||||||
[captcha.default_difficulty_strategy]
|
[captcha.default_difficulty_strategy]
|
||||||
avg_traffic_difficulty = 50000 # almost instant solution
|
avg_traffic_difficulty = 50000 # almost instant solution
|
||||||
#avg_traffic_time = 1 # almost instant solution
|
avg_traffic_time = 1 # almost instant solution
|
||||||
peak_sustainable_traffic_difficulty = 3000000 # roughly 1.5s
|
peak_sustainable_traffic_difficulty = 3000000 # roughly 1.5s
|
||||||
#peak_sustainable_traffic_time = 3
|
peak_sustainable_traffic_time = 3
|
||||||
broke_my_site_traffic_difficulty = 5000000 # greater than 3.5s
|
broke_my_site_traffic_difficulty = 5000000 # greater than 3.5s
|
||||||
#broke_my_site_traffic_time = 5
|
broke_my_site_traffic_time = 5
|
||||||
duration = 30 # cooldown period in seconds
|
duration = 30 # cooldown period in seconds
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ impl UpdateEasyCaptcha {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut patterns = data.db.get_all_easy_captchas(limit, offset).await?;
|
let mut patterns = data.db.get_all_easy_captchas(limit, offset).await?;
|
||||||
|
if patterns.is_empty() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
for pattern in patterns.drain(0..) {
|
for pattern in patterns.drain(0..) {
|
||||||
if !Self::can_run(rx) {
|
if !Self::can_run(rx) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@@ -85,6 +88,7 @@ impl UpdateEasyCaptcha {
|
|||||||
}
|
}
|
||||||
page += 1;
|
page += 1;
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn can_run(rx: &mut Receiver<()>) -> bool {
|
fn can_run(rx: &mut Receiver<()>) -> bool {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ SPDX-License-Identifier: MIT OR Apache-2.0
|
|||||||
<label class="widget__verification-container" for="widget__verification-checkbox">
|
<label class="widget__verification-container" for="widget__verification-checkbox">
|
||||||
<span id="widget__verification-text"
|
<span id="widget__verification-text"
|
||||||
>I'm not a robot</span>
|
>I'm not a robot</span>
|
||||||
<input
|
<input disabled
|
||||||
id="widget__verification-checkbox"
|
id="widget__verification-checkbox"
|
||||||
aria-valuenow="I'm not a robot"
|
aria-valuenow="I'm not a robot"
|
||||||
aria-checked="false"
|
aria-checked="false"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
import { Work, ServiceWorkerMessage } from "./types";
|
import {Work, ServiceWorkerMessage} from "./types";
|
||||||
import fetchPoWConfig from "./fetchPoWConfig";
|
import fetchPoWConfig from "./fetchPoWConfig";
|
||||||
import sendWork from "./sendWork";
|
import sendWork from "./sendWork";
|
||||||
import sendToParent from "./sendToParent";
|
import sendToParent from "./sendToParent";
|
||||||
@@ -12,7 +12,17 @@ import * as CONST from "./const";
|
|||||||
import "./main.scss";
|
import "./main.scss";
|
||||||
|
|
||||||
let LOCK = false;
|
let LOCK = false;
|
||||||
const worker = new Worker("/bench.js");
|
|
||||||
|
const workerPromise = new Promise<Worker>((res) => {
|
||||||
|
const worker = new Worker("/bench.js");
|
||||||
|
worker.onmessage = (event: MessageEvent) => {
|
||||||
|
const message: ServiceWorkerMessage = event.data;
|
||||||
|
if(message.type === "ready") {
|
||||||
|
console.log("worker ready");
|
||||||
|
res(worker);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
/** add mcaptcha widget element to DOM */
|
/** add mcaptcha widget element to DOM */
|
||||||
export const registerVerificationEventHandler = (): void => {
|
export const registerVerificationEventHandler = (): void => {
|
||||||
@@ -20,10 +30,14 @@ export const registerVerificationEventHandler = (): void => {
|
|||||||
document.querySelector(".widget__verification-container")
|
document.querySelector(".widget__verification-container")
|
||||||
);
|
);
|
||||||
verificationContainer.style.display = "flex";
|
verificationContainer.style.display = "flex";
|
||||||
CONST.btn().addEventListener("click", (e) => solveCaptchaRunner(e));
|
workerPromise.then((worker: Worker) => {
|
||||||
|
const btn = CONST.btn();
|
||||||
|
btn.disabled = false;
|
||||||
|
btn.addEventListener("click", (e) => solveCaptchaRunner(worker, e));
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const solveCaptchaRunner = async (e: Event): Promise<void> => {
|
export const solveCaptchaRunner = async (worker: Worker, e: Event): Promise<void> => {
|
||||||
const PROGRESS_FILL = <HTMLElement>document.querySelector(".progress__fill");
|
const PROGRESS_FILL = <HTMLElement>document.querySelector(".progress__fill");
|
||||||
|
|
||||||
const setWidth = (width: number) => {
|
const setWidth = (width: number) => {
|
||||||
@@ -94,7 +108,7 @@ export const solveCaptchaRunner = async (e: Event): Promise<void> => {
|
|||||||
}
|
}
|
||||||
if (resp.type === "progress") {
|
if (resp.type === "progress") {
|
||||||
if (width < 80) {
|
if (width < 80) {
|
||||||
width = Number(resp.nonce / max_recorded_nonce) * 100;
|
width = resp.nonce / max_recorded_nonce * 100;
|
||||||
setWidth(width);
|
setWidth(width);
|
||||||
}
|
}
|
||||||
console.log(`received nonce ${resp.nonce}`);
|
console.log(`received nonce ${resp.nonce}`);
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const prove = async (
|
|||||||
config.string,
|
config.string,
|
||||||
config.difficulty_factor,
|
config.difficulty_factor,
|
||||||
STEPS,
|
STEPS,
|
||||||
progress
|
(nonce: BigInt | number) => progress(Number(nonce))
|
||||||
);
|
);
|
||||||
const t1 = performance.now();
|
const t1 = performance.now();
|
||||||
time = t1 - t0;
|
time = t1 - t0;
|
||||||
|
|||||||
@@ -9,6 +9,12 @@ import prove from "./prove";
|
|||||||
import { PoWConfig, ServiceWorkerMessage, ServiceWorkerWork } from "./types";
|
import { PoWConfig, ServiceWorkerMessage, ServiceWorkerWork } from "./types";
|
||||||
|
|
||||||
log.log("worker registered");
|
log.log("worker registered");
|
||||||
|
|
||||||
|
const ready: ServiceWorkerMessage = {
|
||||||
|
type: "ready",
|
||||||
|
};
|
||||||
|
postMessage(ready);
|
||||||
|
|
||||||
onmessage = async (e) => {
|
onmessage = async (e) => {
|
||||||
console.debug("message received at worker");
|
console.debug("message received at worker");
|
||||||
const config: PoWConfig = e.data;
|
const config: PoWConfig = e.data;
|
||||||
|
|||||||
@@ -40,5 +40,6 @@ export type Token = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type ServiceWorkerMessage =
|
export type ServiceWorkerMessage =
|
||||||
|
| { type: "ready" }
|
||||||
| { type: "work"; value: ServiceWorkerWork }
|
| { type: "work"; value: ServiceWorkerWork }
|
||||||
| { type: "progress"; nonce: number };
|
| { type: "progress"; nonce: number };
|
||||||
|
|||||||
Reference in New Issue
Block a user