mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-12 10:35:39 +00:00
Deploying to gh-pages from @ 333c8ef426c33a6e9a1999dad72e459e0a15ed5e 🚀
This commit is contained in:
@@ -279,17 +279,6 @@
|
||||
<a href="#279" id="279">279</a>
|
||||
<a href="#280" id="280">280</a>
|
||||
<a href="#281" id="281">281</a>
|
||||
<a href="#282" id="282">282</a>
|
||||
<a href="#283" id="283">283</a>
|
||||
<a href="#284" id="284">284</a>
|
||||
<a href="#285" id="285">285</a>
|
||||
<a href="#286" id="286">286</a>
|
||||
<a href="#287" id="287">287</a>
|
||||
<a href="#288" id="288">288</a>
|
||||
<a href="#289" id="289">289</a>
|
||||
<a href="#290" id="290">290</a>
|
||||
<a href="#291" id="291">291</a>
|
||||
<a href="#292" id="292">292</a>
|
||||
</pre></div><pre class="rust"><code><span class="comment">// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
@@ -297,6 +286,7 @@
|
||||
|
||||
//use actix::prelude::*;
|
||||
</span><span class="kw">use </span>actix_web::{web, HttpResponse, Responder};
|
||||
<span class="kw">use </span>libmcaptcha::pow::PoWConfig;
|
||||
<span class="kw">use </span>libmcaptcha::{
|
||||
defense::LevelBuilder, master::messages::AddSiteBuilder, DefenseBuilder,
|
||||
MCaptchaBuilder,
|
||||
@@ -313,9 +303,15 @@
|
||||
<span class="kw">pub </span>key: String,
|
||||
}
|
||||
|
||||
<span class="comment">// API keys are mcaptcha actor names
|
||||
<span class="attr">#[derive(Clone, Serialize, Deserialize, Debug)]
|
||||
</span><span class="kw">pub struct </span>ApiPoWConfig {
|
||||
<span class="kw">pub </span>string: String,
|
||||
<span class="kw">pub </span>difficulty_factor: u32,
|
||||
<span class="kw">pub </span>salt: String,
|
||||
<span class="kw">pub </span>max_recorded_nonce: u32,
|
||||
}
|
||||
|
||||
</span><span class="doccomment">/// get PoW configuration for an mcaptcha key
|
||||
<span class="doccomment">/// get PoW configuration for an mcaptcha key
|
||||
</span><span class="attr">#[my_codegen::post(path = <span class="string">"V1_API_ROUTES.pow.get_config()"</span>)]
|
||||
</span><span class="kw">pub async fn </span>get_config(
|
||||
payload: web::Json<GetConfigPayload>,
|
||||
@@ -327,53 +323,35 @@
|
||||
}
|
||||
<span class="kw">let </span>payload = payload.into_inner();
|
||||
|
||||
<span class="kw">match </span>data.captcha.get_pow(payload.key.clone()).<span class="kw">await </span>{
|
||||
<span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(config)) => {
|
||||
data.stats.record_fetch(<span class="kw-2">&</span>data, <span class="kw-2">&</span>payload.key).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(HttpResponse::Ok().json(config))
|
||||
}
|
||||
<span class="prelude-val">Ok</span>(<span class="prelude-val">None</span>) => {
|
||||
init_mcaptcha(<span class="kw-2">&</span>data, <span class="kw-2">&</span>payload.key).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>config = data
|
||||
.captcha
|
||||
.get_pow(payload.key.clone())
|
||||
.<span class="kw">await
|
||||
</span>.expect(<span class="string">"mcaptcha should be initialized and ready to go"</span>);
|
||||
<span class="comment">// background it. would require data::Data to be static
|
||||
// to satidfy lifetime
|
||||
</span>data.stats.record_fetch(<span class="kw-2">&</span>data, <span class="kw-2">&</span>payload.key).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(HttpResponse::Ok().json(config))
|
||||
}
|
||||
<span class="prelude-val">Err</span>(e) => <span class="prelude-val">Err</span>(e.into()),
|
||||
}
|
||||
<span class="kw">let </span>config: ServiceResult<PoWConfig> =
|
||||
<span class="kw">match </span>data.captcha.get_pow(payload.key.clone()).<span class="kw">await </span>{
|
||||
<span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(config)) => <span class="prelude-val">Ok</span>(config),
|
||||
<span class="prelude-val">Ok</span>(<span class="prelude-val">None</span>) => {
|
||||
init_mcaptcha(<span class="kw-2">&</span>data, <span class="kw-2">&</span>payload.key).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>config = data
|
||||
.captcha
|
||||
.get_pow(payload.key.clone())
|
||||
.<span class="kw">await
|
||||
</span>.expect(<span class="string">"mcaptcha should be initialized and ready to go"</span>);
|
||||
<span class="prelude-val">Ok</span>(config.unwrap())
|
||||
}
|
||||
<span class="prelude-val">Err</span>(e) => <span class="prelude-val">Err</span>(e.into()),
|
||||
};
|
||||
<span class="kw">let </span>config = config<span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>max_nonce = data
|
||||
.db
|
||||
.get_max_nonce_for_level(<span class="kw-2">&</span>payload.key, config.difficulty_factor)
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
data.stats.record_fetch(<span class="kw-2">&</span>data, <span class="kw-2">&</span>payload.key).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// match res.exists {
|
||||
// Some(true) => {
|
||||
// match data.captcha.get_pow(payload.key.clone()).await {
|
||||
// Ok(Some(config)) => {
|
||||
// record_fetch(&payload.key, &data.db).await;
|
||||
// Ok(HttpResponse::Ok().json(config))
|
||||
// }
|
||||
// Ok(None) => {
|
||||
// init_mcaptcha(&data, &payload.key).await?;
|
||||
// let config = data
|
||||
// .captcha
|
||||
// .get_pow(payload.key.clone())
|
||||
// .await
|
||||
// .expect("mcaptcha should be initialized and ready to go");
|
||||
// // background it. would require data::Data to be static
|
||||
// // to satidfy lifetime
|
||||
// record_fetch(&payload.key, &data.db).await;
|
||||
// Ok(HttpResponse::Ok().json(config))
|
||||
// }
|
||||
// Err(e) => Err(e.into()),
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Some(false) => Err(ServiceError::TokenNotFound),
|
||||
// None => Err(ServiceError::TokenNotFound),
|
||||
// }
|
||||
</span>}
|
||||
<span class="kw">let </span>config = ApiPoWConfig {
|
||||
string: config.string,
|
||||
difficulty_factor: config.difficulty_factor,
|
||||
salt: config.salt,
|
||||
max_recorded_nonce: max_nonce,
|
||||
};
|
||||
<span class="prelude-val">Ok</span>(HttpResponse::Ok().json(config))
|
||||
}
|
||||
<span class="doccomment">/// Call this when [MCaptcha][libmcaptcha::MCaptcha] is not in master.
|
||||
///
|
||||
/// This fn gets mcaptcha config from database, builds [Defense][libmcaptcha::Defense],
|
||||
|
||||
@@ -254,6 +254,10 @@
|
||||
<a href="#254" id="254">254</a>
|
||||
<a href="#255" id="255">255</a>
|
||||
<a href="#256" id="256">256</a>
|
||||
<a href="#257" id="257">257</a>
|
||||
<a href="#258" id="258">258</a>
|
||||
<a href="#259" id="259">259</a>
|
||||
<a href="#260" id="260">260</a>
|
||||
</pre></div><pre class="rust"><code><span class="comment">// Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
@@ -321,6 +325,7 @@
|
||||
<span class="kw">let </span>payload = payload.into_inner();
|
||||
<span class="kw">let </span>worker_type = payload.worker_type.clone();
|
||||
<span class="kw">let </span>time = payload.time;
|
||||
<span class="kw">let </span>nonce = payload.nonce;
|
||||
<span class="kw">let </span>(res, difficulty_factor) = data.captcha.verify_pow(payload.into(), ip).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
data.stats.record_solve(<span class="kw-2">&</span>data, <span class="kw-2">&</span>key).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">if let </span>(<span class="prelude-val">Some</span>(time), <span class="prelude-val">Some</span>(worker_type)) = (time, worker_type) {
|
||||
@@ -331,6 +336,9 @@
|
||||
};
|
||||
data.db.analysis_save(<span class="kw-2">&</span>key, <span class="kw-2">&</span>analytics).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
}
|
||||
data.db
|
||||
.update_max_nonce_for_level(<span class="kw-2">&</span>key, difficulty_factor, nonce <span class="kw">as </span>u32)
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>payload = ValidationToken { token: res };
|
||||
<span class="prelude-val">Ok</span>(HttpResponse::Ok().json(payload))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user