diff --git a/Nekrochan.toml.template b/Nekrochan.toml.template index 06f3fba..9e513e9 100755 --- a/Nekrochan.toml.template +++ b/Nekrochan.toml.template @@ -33,6 +33,7 @@ reply_limit = 1000 locked = false user_ids = false flags = false +flags_reg = false thread_captcha = "off" reply_captcha = "off" board_theme = "yotsuba.css" diff --git a/src/cfg.rs b/src/cfg.rs index f049f72..d1cc5f8 100755 --- a/src/cfg.rs +++ b/src/cfg.rs @@ -64,6 +64,7 @@ pub struct BoardCfg { pub locked: bool, pub user_ids: bool, pub flags: bool, + pub flags_reg: bool, pub thread_captcha: String, pub reply_captcha: String, pub board_theme: String, diff --git a/src/db/banner.rs b/src/db/banner.rs index ab2b68f..46ecba9 100644 --- a/src/db/banner.rs +++ b/src/db/banner.rs @@ -20,7 +20,7 @@ impl Banner { pub async fn read(ctx: &Ctx, id: i32) -> Result, NekrochanError> { let banners: Vec = ctx.cache().zrangebyscore("banners", id, id).await?; - let json = banners.get(0); + let json = banners.first(); let banner = match json { Some(json) => Some(serde_json::from_str(json)?), diff --git a/src/db/board.rs b/src/db/board.rs index f701333..7fef431 100755 --- a/src/db/board.rs +++ b/src/db/board.rs @@ -37,6 +37,7 @@ impl Board { files JSONB NOT NULL, password VARCHAR(64) DEFAULT NULL, country VARCHAR(2) NOT NULL, + region VARCHAR(64) NOT NULL, ip INET NOT NULL, bumps INT NOT NULL DEFAULT 0, replies INT NOT NULL DEFAULT 0, diff --git a/src/db/models.rs b/src/db/models.rs index 797ce19..3e21838 100755 --- a/src/db/models.rs +++ b/src/db/models.rs @@ -60,6 +60,7 @@ pub struct Post { pub files: Json>, pub password: String, pub country: String, + pub region: Option, pub ip: IpAddr, pub bumps: i32, pub replies: i32, diff --git a/src/db/post.rs b/src/db/post.rs index 8dfd198..1fde8f8 100755 --- a/src/db/post.rs +++ b/src/db/post.rs @@ -27,13 +27,14 @@ impl Post { files: Vec, password: String, country: String, + region: Option, ip: IpAddr, bump: bool, ) -> Result { let post: Post = query_as(&format!( r#"INSERT INTO posts_{} - (thread, name, tripcode, capcode, email, content, content_nomarkup, files, password, country, ip) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) + (thread, name, tripcode, capcode, email, content, content_nomarkup, files, password, country, region, ip) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *"#, board.id) ) .bind(thread) @@ -46,6 +47,7 @@ impl Post { .bind(Json(files)) .bind(password) .bind(country) + .bind(region) .bind(ip) .fetch_one(ctx.db()) .await?; diff --git a/src/web/actions/appeal_ban.rs b/src/web/actions/appeal_ban.rs index e6e02f9..4567dfe 100644 --- a/src/web/actions/appeal_ban.rs +++ b/src/web/actions/appeal_ban.rs @@ -26,7 +26,7 @@ pub async fn appeal_ban( QsForm(form): QsForm, ) -> Result { let tcx = TemplateCtx::new(&ctx, &req).await?; - let (ip, _) = ip_from_req(&req)?; + let (ip, _, _) = ip_from_req(&req)?; let ban = Ban::read_by_id(&ctx, form.id) .await? diff --git a/src/web/actions/create_post.rs b/src/web/actions/create_post.rs index b138249..bec8c02 100644 --- a/src/web/actions/create_post.rs +++ b/src/web/actions/create_post.rs @@ -49,7 +49,7 @@ pub async fn create_post( None => PermissionWrapper::new(0, false), }; - let (ip, country) = ip_from_req(&req)?; + let (ip, country, region) = ip_from_req(&req)?; let board = form.board.0; let board = Board::read(&ctx, board.clone()) @@ -238,6 +238,7 @@ pub async fn create_post( files, password, country, + region, ip, bump, ) diff --git a/src/web/actions/report_posts.rs b/src/web/actions/report_posts.rs index b98347b..68e5821 100644 --- a/src/web/actions/report_posts.rs +++ b/src/web/actions/report_posts.rs @@ -29,7 +29,7 @@ pub async fn report_posts( QsForm(form): QsForm, ) -> Result { let tcx = TemplateCtx::new(&ctx, &req).await?; - let (reporter_ip, reporter_country) = ip_from_req(&req)?; + let (reporter_ip, reporter_country, _) = ip_from_req(&req)?; let bans = Ban::read_by_ip(&ctx, reporter_ip).await?; if let Some(ban) = bans.get(&None) { diff --git a/src/web/actions/user_post_actions.rs b/src/web/actions/user_post_actions.rs index 6c9f580..c301f8f 100644 --- a/src/web/actions/user_post_actions.rs +++ b/src/web/actions/user_post_actions.rs @@ -34,7 +34,7 @@ pub async fn user_post_actions( QsForm(form): QsForm, ) -> Result { let tcx = TemplateCtx::new(&ctx, &req).await?; - let (ip, _) = ip_from_req(&req)?; + let (ip, _, _) = ip_from_req(&req)?; let bans = Ban::read_by_ip(&ctx, ip).await?; if let Some(ban) = bans.get(&None) { diff --git a/src/web/staff/actions/update_board_config.rs b/src/web/staff/actions/update_board_config.rs index bce3864..8b19081 100755 --- a/src/web/staff/actions/update_board_config.rs +++ b/src/web/staff/actions/update_board_config.rs @@ -18,6 +18,7 @@ pub struct UpdateBoardConfigForm { locked: Option, user_ids: Option, flags: Option, + flags_reg: Option, thread_captcha: String, reply_captcha: String, board_theme: String, @@ -58,6 +59,7 @@ pub async fn update_board_config( let locked = form.locked.is_some(); let user_ids = form.user_ids.is_some(); let flags = form.flags.is_some(); + let flags_reg = form.flags_reg.is_some(); let thread_captcha = form.thread_captcha; let reply_captcha = form.reply_captcha; let board_theme = form.board_theme; @@ -81,6 +83,7 @@ pub async fn update_board_config( locked, user_ids, flags, + flags_reg, thread_captcha, reply_captcha, board_theme, diff --git a/src/web/tcx.rs b/src/web/tcx.rs index e721af0..9c659f2 100755 --- a/src/web/tcx.rs +++ b/src/web/tcx.rs @@ -34,7 +34,7 @@ impl TemplateCtx { None => PermissionWrapper::new(0, false), }; - let (ip, _) = ip_from_req(req)?; + let (ip, _, _) = ip_from_req(req)?; let yous = ctx.cache().zrange(format!("by_ip:{ip}"), 0, -1).await?; let account = account.map(|account| account.username); @@ -99,7 +99,7 @@ pub async fn account_from_auth_opt( Ok(account) } -pub fn ip_from_req(req: &HttpRequest) -> Result<(IpAddr, String), NekrochanError> { +pub fn ip_from_req(req: &HttpRequest) -> Result<(IpAddr, String, Option), NekrochanError> { let ip = req .connection_info() .realip_remote_addr() @@ -107,10 +107,27 @@ pub fn ip_from_req(req: &HttpRequest) -> Result<(IpAddr, String), NekrochanError ip.parse().unwrap_or(IpAddr::V4(Ipv4Addr::UNSPECIFIED)) }); - let country = req.headers().get("X-Country-Code").map_or_else( - || "xx".into(), - |hdr| hdr.to_str().unwrap_or("xx").to_ascii_lowercase(), - ); + let country = req + .headers() + .get("X-Country-Code") + .and_then(|hdr| hdr.to_str().ok()) + .unwrap_or("xx") + .to_ascii_lowercase(); - Ok((ip, country)) + let region = req + .headers() + .get("X-Region-Code") + .and_then(|hdr| hdr.to_str().ok()) + .unwrap_or("xx") + .to_ascii_lowercase(); + + let region = if country == "cz" { + Some(region) + } else if country == "ru" && region == "kgd" { + Some("kralovec".into()) + } else { + None + }; + + Ok((ip, country, region)) } diff --git a/static/flags/reg/10.png b/static/flags/reg/10.png new file mode 100644 index 0000000..11fafc8 Binary files /dev/null and b/static/flags/reg/10.png differ diff --git a/static/flags/reg/20.png b/static/flags/reg/20.png new file mode 100644 index 0000000..31e1609 Binary files /dev/null and b/static/flags/reg/20.png differ diff --git a/static/flags/reg/31.png b/static/flags/reg/31.png new file mode 100644 index 0000000..821e23d Binary files /dev/null and b/static/flags/reg/31.png differ diff --git a/static/flags/reg/32.png b/static/flags/reg/32.png new file mode 100644 index 0000000..4cf4509 Binary files /dev/null and b/static/flags/reg/32.png differ diff --git a/static/flags/reg/41.png b/static/flags/reg/41.png new file mode 100644 index 0000000..0536153 Binary files /dev/null and b/static/flags/reg/41.png differ diff --git a/static/flags/reg/42.png b/static/flags/reg/42.png new file mode 100644 index 0000000..b1c6b0c Binary files /dev/null and b/static/flags/reg/42.png differ diff --git a/static/flags/reg/51.png b/static/flags/reg/51.png new file mode 100644 index 0000000..c5e311a Binary files /dev/null and b/static/flags/reg/51.png differ diff --git a/static/flags/reg/52.png b/static/flags/reg/52.png new file mode 100644 index 0000000..252ca1e Binary files /dev/null and b/static/flags/reg/52.png differ diff --git a/static/flags/reg/53.png b/static/flags/reg/53.png new file mode 100644 index 0000000..68b19ca Binary files /dev/null and b/static/flags/reg/53.png differ diff --git a/static/flags/reg/63.png b/static/flags/reg/63.png new file mode 100644 index 0000000..4c35d3f Binary files /dev/null and b/static/flags/reg/63.png differ diff --git a/static/flags/reg/64.png b/static/flags/reg/64.png new file mode 100644 index 0000000..bf96d48 Binary files /dev/null and b/static/flags/reg/64.png differ diff --git a/static/flags/reg/71.png b/static/flags/reg/71.png new file mode 100644 index 0000000..db2fbb4 Binary files /dev/null and b/static/flags/reg/71.png differ diff --git a/static/flags/reg/72.png b/static/flags/reg/72.png new file mode 100644 index 0000000..faa39f4 Binary files /dev/null and b/static/flags/reg/72.png differ diff --git a/static/flags/reg/80.png b/static/flags/reg/80.png new file mode 100644 index 0000000..a22a61d Binary files /dev/null and b/static/flags/reg/80.png differ diff --git a/static/flags/reg/kralovec.png b/static/flags/reg/kralovec.png new file mode 100644 index 0000000..0ba5063 Binary files /dev/null and b/static/flags/reg/kralovec.png differ diff --git a/static/flags/reg/xx.png b/static/flags/reg/xx.png new file mode 100755 index 0000000..ba351ca Binary files /dev/null and b/static/flags/reg/xx.png differ diff --git a/templates/macros/post.html b/templates/macros/post.html index 5c77062..35fde14 100644 --- a/templates/macros/post.html +++ b/templates/macros/post.html @@ -23,6 +23,11 @@ {% if board.config.0.flags %} {% endif %} + {% if board.config.0.flags_reg %} + {% if let Some(region) = post.region %} + + {% endif %} + {% endif %} {% if board.config.0.user_ids %} {{ post.user_id }} diff --git a/templates/staff/board-config.html b/templates/staff/board-config.html index 6946050..07651e8 100755 --- a/templates/staff/board-config.html +++ b/templates/staff/board-config.html @@ -69,6 +69,15 @@ + + Vlajky Regionů + +
+ +
+ + + CAPTCHA (vlákno)