mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 22:06:38 +08:00
172 lines
5.5 KiB
Go
172 lines
5.5 KiB
Go
package common
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
var StartTime = time.Now().Unix() // unit: second
|
|
var Version = "dev" // release builds inject the tag version via ldflags
|
|
var SystemName = "OpenFlare"
|
|
var ServerAddress = "http://localhost:3000"
|
|
var Footer = ""
|
|
var HomePageLink = ""
|
|
|
|
// Any options with "Secret", "Token" in its key won't be return by GetOptions
|
|
|
|
var SessionSecret = uuid.New().String()
|
|
var SQLitePath = "openflare.db"
|
|
var SQLDSN = ""
|
|
|
|
var OptionMap map[string]string
|
|
var OptionMapRWMutex sync.RWMutex
|
|
|
|
var ItemsPerPage = 10
|
|
|
|
var PasswordLoginEnabled = true
|
|
var PasswordRegisterEnabled = true
|
|
var EmailVerificationEnabled = false
|
|
var GitHubOAuthEnabled = false
|
|
var WeChatAuthEnabled = false
|
|
var TurnstileCheckEnabled = false
|
|
var RegisterEnabled = true
|
|
|
|
var SMTPServer = ""
|
|
var SMTPPort = 587
|
|
var SMTPAccount = ""
|
|
var SMTPToken = ""
|
|
|
|
var GitHubClientId = ""
|
|
var GitHubClientSecret = ""
|
|
|
|
var WeChatServerAddress = ""
|
|
var WeChatServerToken = ""
|
|
var WeChatAccountQRCodeImageURL = ""
|
|
|
|
var TurnstileSiteKey = ""
|
|
var TurnstileSecretKey = ""
|
|
var AgentToken = ""
|
|
var AgentDiscoveryToken = ""
|
|
var NodeOfflineThreshold = 2 * time.Minute
|
|
|
|
// V3 operational settings (hot-reloadable via Option table)
|
|
var AgentHeartbeatInterval = 10000 // milliseconds
|
|
var AgentUpdateRepo = "Rain-kl/OpenFlare"
|
|
var GeoIPProvider = "ipinfo"
|
|
|
|
// V5 OpenResty performance settings (hot-reloadable via Option table)
|
|
var OpenRestyWorkerProcesses = "auto"
|
|
var OpenRestyWorkerConnections = 4096
|
|
var OpenRestyWorkerRlimitNofile = 65535
|
|
var OpenRestyEventsUse = ""
|
|
var OpenRestyEventsMultiAcceptEnabled = false
|
|
var OpenRestyKeepaliveTimeout = 65
|
|
var OpenRestyKeepaliveRequests = 1000
|
|
var OpenRestyClientHeaderTimeout = 15
|
|
var OpenRestyClientBodyTimeout = 15
|
|
var OpenRestyClientMaxBodySize = "64m"
|
|
var OpenRestyLargeClientHeaderBuffers = "4 16k"
|
|
var OpenRestySendTimeout = 30
|
|
var OpenRestyProxyConnectTimeout = 5
|
|
var OpenRestyProxySendTimeout = 60
|
|
var OpenRestyProxyReadTimeout = 60
|
|
var OpenRestyWebsocketEnabled = true
|
|
var OpenRestyProxyRequestBufferingEnabled = false
|
|
var OpenRestyProxyBufferingEnabled = true
|
|
var OpenRestyProxyBuffers = "16 16k"
|
|
var OpenRestyProxyBufferSize = "8k"
|
|
var OpenRestyProxyBusyBuffersSize = "64k"
|
|
var OpenRestyGzipEnabled = true
|
|
var OpenRestyGzipMinLength = 1024
|
|
var OpenRestyGzipCompLevel = 5
|
|
var OpenRestyResolvers = ""
|
|
var OpenRestyCacheEnabled = false
|
|
var OpenRestyCachePath = ""
|
|
var OpenRestyCacheLevels = "1:2"
|
|
var OpenRestyCacheInactive = "30m"
|
|
var OpenRestyCacheMaxSize = "1g"
|
|
var OpenRestyCacheKeyTemplate = "$scheme$proxy_host$request_uri"
|
|
var OpenRestyCacheLockEnabled = true
|
|
var OpenRestyCacheLockTimeout = "5s"
|
|
var OpenRestyCacheUseStale = "error timeout updating http_500 http_502 http_503 http_504"
|
|
var OpenRestyMainConfigTemplate = `# This file is generated by OpenFlare. Do not edit manually.
|
|
worker_processes {{OpenRestyWorkerProcesses}};
|
|
worker_rlimit_nofile {{OpenRestyWorkerRlimitNofile}};
|
|
pid logs/nginx.pid;
|
|
|
|
events {
|
|
worker_connections {{OpenRestyWorkerConnections}};
|
|
{{OpenRestyEventsUseDirective}}{{OpenRestyEventsMultiAcceptDirective}}}
|
|
|
|
http {
|
|
include mime.types;
|
|
default_type application/octet-stream;
|
|
{{OpenRestyConnectionUpgradeMap}}{{OpenRestyDefaultServerBlock}} log_format openflare_json escape=json '{"ts":"$time_iso8601","host":"$host","path":"$request_uri","remote_addr":"$remote_addr","status":$status,"request_time":$request_time,"bytes_sent":$body_bytes_sent,"request_length":$request_length}';
|
|
access_log {{OpenRestyAccessLogPath}} openflare_json;
|
|
sendfile on;
|
|
tcp_nopush on;
|
|
tcp_nodelay on;
|
|
keepalive_timeout {{OpenRestyKeepaliveTimeout}};
|
|
keepalive_requests {{OpenRestyKeepaliveRequests}};
|
|
client_header_timeout {{OpenRestyClientHeaderTimeout}};
|
|
client_body_timeout {{OpenRestyClientBodyTimeout}};
|
|
client_max_body_size {{OpenRestyClientMaxBodySize}};
|
|
large_client_header_buffers {{OpenRestyLargeClientHeaderBuffers}};
|
|
send_timeout {{OpenRestySendTimeout}};
|
|
proxy_connect_timeout {{OpenRestyProxyConnectTimeout}};
|
|
proxy_send_timeout {{OpenRestyProxySendTimeout}};
|
|
proxy_read_timeout {{OpenRestyProxyReadTimeout}};
|
|
proxy_request_buffering {{OpenRestyProxyRequestBuffering}};
|
|
proxy_buffering {{OpenRestyProxyBuffering}};
|
|
proxy_buffers {{OpenRestyProxyBuffers}};
|
|
proxy_buffer_size {{OpenRestyProxyBufferSize}};
|
|
proxy_busy_buffers_size {{OpenRestyProxyBusyBuffersSize}};
|
|
gzip {{OpenRestyGzip}};
|
|
gzip_min_length {{OpenRestyGzipMinLength}};
|
|
gzip_comp_level {{OpenRestyGzipCompLevel}};
|
|
{{OpenRestyResolverDirective}}{{OpenRestyCacheBlock}} include {{OpenRestyRouteConfigInclude}};
|
|
}
|
|
`
|
|
|
|
const (
|
|
RoleGuestUser = 0
|
|
RoleCommonUser = 1
|
|
RoleAdminUser = 10
|
|
RoleRootUser = 100
|
|
)
|
|
|
|
var (
|
|
FileUploadPermission = RoleGuestUser
|
|
FileDownloadPermission = RoleGuestUser
|
|
ImageUploadPermission = RoleGuestUser
|
|
ImageDownloadPermission = RoleGuestUser
|
|
)
|
|
|
|
// All duration's unit is seconds
|
|
// Shouldn't larger then RateLimitKeyExpirationDuration
|
|
var (
|
|
GlobalApiRateLimitNum = 300
|
|
GlobalApiRateLimitDuration int64 = 3 * 60
|
|
|
|
GlobalWebRateLimitNum = 300
|
|
GlobalWebRateLimitDuration int64 = 3 * 60
|
|
|
|
UploadRateLimitNum = 50
|
|
UploadRateLimitDuration int64 = 60
|
|
|
|
DownloadRateLimitNum = 50
|
|
DownloadRateLimitDuration int64 = 60
|
|
|
|
CriticalRateLimitNum = 100
|
|
CriticalRateLimitDuration int64 = 20 * 60
|
|
)
|
|
|
|
var RateLimitKeyExpirationDuration = 20 * time.Minute
|
|
|
|
const (
|
|
UserStatusEnabled = 1 // don't use 0, 0 is the default value!
|
|
UserStatusDisabled = 2 // also don't use 0
|
|
)
|