2022-08-10 05:10:47 +00:00
|
|
|
// Package config holds some (mostly static) configuration for the app.
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Branding
|
|
|
|
const (
|
2022-08-13 06:11:36 +00:00
|
|
|
Title = "nonshy"
|
2022-08-14 21:40:57 +00:00
|
|
|
Subtitle = "A social network for nudists and exhibitionists."
|
2022-08-10 05:10:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Paths and layouts
|
|
|
|
const (
|
|
|
|
TemplatePath = "./web/templates"
|
|
|
|
StaticPath = "./web/static"
|
|
|
|
SettingsPath = "./settings.json"
|
2022-08-12 06:03:06 +00:00
|
|
|
|
|
|
|
// Web path where photos are kept. Photos in DB store only their filenames, this
|
|
|
|
// is the base URL that goes in front. TODO: support setting a CDN URL prefix.
|
|
|
|
JpegQuality = 90
|
2022-08-13 06:11:36 +00:00
|
|
|
PhotoWebPath = "/static/photos"
|
2022-08-12 06:03:06 +00:00
|
|
|
PhotoDiskPath = "./web/static/photos"
|
2022-08-10 05:10:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Security
|
|
|
|
const (
|
|
|
|
BcryptCost = 14
|
|
|
|
SessionCookieName = "session_id"
|
2022-08-30 03:00:15 +00:00
|
|
|
CSRFCookieName = "xsrf_token"
|
2022-08-10 05:10:47 +00:00
|
|
|
CSRFInputName = "_csrf" // html input name
|
|
|
|
SessionCookieMaxAge = 60 * 60 * 24 * 30
|
|
|
|
SessionRedisKeyFormat = "session/%s"
|
2023-06-26 05:55:07 +00:00
|
|
|
MaxBodySize = 1024 * 1024 * 8 // max upload file (e.g., 8 MB gifs)
|
2022-08-12 06:03:06 +00:00
|
|
|
MultipartMaxMemory = 1024 * 1024 * 1024 * 20 // 20 MB
|
2023-09-19 00:22:50 +00:00
|
|
|
|
|
|
|
TwoFactorBackupCodeCount = 12
|
|
|
|
TwoFactorBackupCodeLength = 8 // characters a-z0-9
|
2022-08-10 05:10:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Authentication
|
|
|
|
const (
|
|
|
|
// Skip the email verification step. The signup page will directly ask for
|
|
|
|
// email+username+password rather than only email and needing verification.
|
|
|
|
SkipEmailVerification = false
|
2022-08-14 21:40:57 +00:00
|
|
|
|
2022-08-10 05:10:47 +00:00
|
|
|
SignupTokenRedisKey = "signup-token/%s"
|
2022-08-14 21:40:57 +00:00
|
|
|
ResetPasswordRedisKey = "reset-password/%s"
|
|
|
|
ChangeEmailRedisKey = "change-email/%s"
|
|
|
|
SignupTokenExpires = 24 * time.Hour // used for all tokens so far
|
|
|
|
|
2022-09-27 02:12:24 +00:00
|
|
|
// Rate limits
|
2022-08-14 21:40:57 +00:00
|
|
|
RateLimitRedisKey = "rate-limit/%s/%s" // namespace, id
|
|
|
|
LoginRateLimitWindow = 1 * time.Hour
|
|
|
|
LoginRateLimit = 10 // 10 failed login attempts = locked for full hour
|
|
|
|
LoginRateLimitCooldownAt = 3 // 3 failed attempts = start throttling
|
|
|
|
LoginRateLimitCooldown = 30 * time.Second
|
|
|
|
|
2022-09-27 02:12:24 +00:00
|
|
|
// Contact form rate limits for logged-out users to curb spam robots:
|
|
|
|
// - One message can be submitted every 2 minutes
|
|
|
|
// - If they post 10 minutes in an hour they are paused for one hour.
|
|
|
|
ContactRateLimitWindow = 1 * time.Hour
|
|
|
|
ContactRateLimit = 10
|
|
|
|
ContactRateLimitCooldownAt = 1
|
|
|
|
ContactRateLimitCooldown = 2 * time.Minute
|
|
|
|
|
2022-08-14 21:40:57 +00:00
|
|
|
// How frequently to refresh LastLoginAt since sessions are long-lived.
|
2023-09-14 05:58:00 +00:00
|
|
|
LastLoginAtCooldown = time.Hour
|
2023-06-08 04:59:15 +00:00
|
|
|
|
|
|
|
// Chat room status refresh interval.
|
|
|
|
ChatStatusRefreshInterval = 30 * time.Second
|
2022-08-10 05:10:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-02-11 00:17:15 +00:00
|
|
|
UsernameRegexp = regexp.MustCompile(`^[a-z0-9_.-]{3,32}$`)
|
2022-08-21 22:56:41 +00:00
|
|
|
ReservedUsernames = []string{
|
|
|
|
"admin",
|
|
|
|
"admins",
|
|
|
|
"administrator",
|
|
|
|
"moderator",
|
|
|
|
"support",
|
|
|
|
"staff",
|
|
|
|
"nonshy",
|
2023-09-09 19:23:54 +00:00
|
|
|
"here",
|
|
|
|
"all",
|
|
|
|
"everyone",
|
|
|
|
"everybody",
|
2022-08-21 22:56:41 +00:00
|
|
|
}
|
2022-08-10 05:10:47 +00:00
|
|
|
)
|
|
|
|
|
2022-08-12 06:03:06 +00:00
|
|
|
// Photo Galleries
|
|
|
|
const (
|
|
|
|
MaxPhotoWidth = 1280
|
|
|
|
ProfilePhotoWidth = 512
|
2024-03-16 05:02:24 +00:00
|
|
|
AltTextMaxLength = 5000
|
2022-08-21 22:40:24 +00:00
|
|
|
|
|
|
|
// Quotas for uploaded photos.
|
|
|
|
PhotoQuotaUncertified = 6
|
2022-12-07 05:50:42 +00:00
|
|
|
PhotoQuotaCertified = 100
|
2023-05-24 18:27:42 +00:00
|
|
|
|
|
|
|
// Min number of public photos for inner circle members to see the prompt to invite.
|
|
|
|
InnerCircleMinimumPublicPhotos = 5
|
2024-01-06 03:08:44 +00:00
|
|
|
|
|
|
|
// Rate limit for too many Site Gallery pictures.
|
|
|
|
// Some users sign up and immediately max out their gallery and spam
|
|
|
|
// the Site Gallery page. These limits can ensure only a few Site Gallery
|
|
|
|
// pictures can be posted per day.
|
|
|
|
SiteGalleryRateLimitMax = 5
|
|
|
|
SiteGalleryRateLimitInterval = 24 * time.Hour
|
2022-08-12 06:03:06 +00:00
|
|
|
)
|
|
|
|
|
2022-08-31 05:13:57 +00:00
|
|
|
// Forum settings
|
|
|
|
const (
|
|
|
|
// Only ++ the Views count per user per thread within a small
|
|
|
|
// window of time - if a user keeps reloading the same thread
|
|
|
|
// rapidly it does not increment the view counter more.
|
|
|
|
ThreadViewDebounceRedisKey = "debounce-view/user=%d/thr=%d"
|
|
|
|
ThreadViewDebounceCooldown = 1 * time.Hour
|
2022-12-21 03:15:45 +00:00
|
|
|
)
|
2022-12-15 06:57:06 +00:00
|
|
|
|
2022-12-21 03:15:45 +00:00
|
|
|
// Poll settings
|
|
|
|
var (
|
2022-12-15 06:57:06 +00:00
|
|
|
// Max number of responses to accept for a poll (how many form
|
|
|
|
// values the app will read in). NOTE: also enforced in frontend
|
|
|
|
// UX in new_post.html, update there if you change this.
|
|
|
|
PollMaxAnswers = 100
|
2022-12-21 03:15:45 +00:00
|
|
|
|
|
|
|
// Poll color CSS classes (Bulma). Plugged in to templates like:
|
|
|
|
// <progress class="$CLASS">
|
|
|
|
// Values will wrap around for long polls.
|
|
|
|
PollProgressBarClasses = []string{
|
|
|
|
"progress is-success",
|
|
|
|
"progress is-link",
|
|
|
|
"progress is-warning",
|
|
|
|
"progress is-danger",
|
|
|
|
"progress is-primary",
|
|
|
|
"progress is-info",
|
|
|
|
}
|
2022-08-31 05:13:57 +00:00
|
|
|
)
|
|
|
|
|
2022-08-10 05:10:47 +00:00
|
|
|
// Variables set by main.go to make them readily available.
|
|
|
|
var (
|
|
|
|
RuntimeVersion string
|
|
|
|
RuntimeBuild string
|
|
|
|
RuntimeBuildDate string
|
|
|
|
Debug bool // app is in debug mode
|
|
|
|
)
|