Documentation
¶
Index ¶
- Constants
- Variables
- func DeleteBoardConfig(dir string)
- func GetUser() (int, int)
- func InitConfig() (err error)
- func InitTestConfig()
- func JSONLocation() string
- func PreloadModule(l *lua.LState) int
- func SetBoardConfig(board string, boardCfg *BoardConfig) error
- func SetRandomSeed(seed string)
- func SetSiteConfig(siteConfig *SiteConfig)
- func SetSystemCriticalConfig(systemCritical *SystemCriticalConfig)
- func SetTestDBConfig(dbType string, dbHost string, dbName string, dbUsername string, ...)
- func SetTestTemplateDir(dir string)
- func TakeOwnership(fp string) (err error)
- func TakeOwnershipOfFile(f *os.File) error
- func UpdateBoardConfig(dir string) error
- func WebPath(part ...string) string
- func WriteConfig() error
- type BoardConfig
- type BoardCooldowns
- type CaptchaConfig
- type EmbedMatcher
- type EmbedTemplateData
- type GochanConfig
- type IncludeScript
- type InvalidValueError
- type MissingField
- type PageBanner
- type PostConfig
- func (pc *PostConfig) GetEmbedMediaID(url string) (string, string, error)
- func (pc *PostConfig) GetEmbedTemplates(embedID string) (*template.Template, *template.Template, error)
- func (pc *PostConfig) GetLinkTemplate(embedID string) (*template.Template, error)
- func (pc *PostConfig) HasEmbedMatchers() bool
- type SQLConfig
- type SiteConfig
- type Style
- type SystemCriticalConfig
- type UploadConfig
Constants ¶
const ( DefaultSQLTimeout = 15 DefaultSQLMaxConns = 10 DefaultSQLConnMaxLifetimeMin = 3 GochanVersion = "4.2.0" )
const ( DirFileMode fs.FileMode = 0775 NormalFileMode fs.FileMode = 0664 )
Variables ¶
var (
ErrNoMatchingEmbedHandler = errors.New("no matching handler for the embed URL")
)
Functions ¶
func DeleteBoardConfig ¶
func DeleteBoardConfig(dir string)
DeleteBoardConfig removes the custom board configuration data, normally should be used when a board is deleted
func GetUser ¶
GetUser returns the IDs of the user and group gochan should be acting as when creating files. If they are 0, it is using the current user
func InitConfig ¶
func InitConfig() (err error)
InitConfig loads and parses gochan.json on startup and verifies its contents
func InitTestConfig ¶
func InitTestConfig()
InitTestConfig should only be used for tests, where a config file wouldn't be loaded
func JSONLocation ¶
func JSONLocation() string
JSONLocation returns the path to the configuration file, if loaded
func PreloadModule ¶
func SetBoardConfig ¶
func SetBoardConfig(board string, boardCfg *BoardConfig) error
SetBoardConfig applies the configuration to the given board. It will panic if it is not run in a test environment
func SetRandomSeed ¶
func SetRandomSeed(seed string)
SetRandomSeed is usd to set a deterministic seed to make testing easier. If it is not run via `go test`, it will panic
func SetSiteConfig ¶
func SetSiteConfig(siteConfig *SiteConfig)
SetSiteConfig sets the site configuration values in testing. It will panic if it is not run in a test environment
func SetSystemCriticalConfig ¶
func SetSystemCriticalConfig(systemCritical *SystemCriticalConfig)
SetSystemCriticalConfig sets system critical configuration values in testing. It will panic if it is not run in a test environment
func SetTestDBConfig ¶
func SetTestDBConfig(dbType string, dbHost string, dbName string, dbUsername string, dbPassword string, dbPrefix string)
SetTestDBConfig sets up the database configuration for a testing environment. If it is not run via `go test`, it will panic
func SetTestTemplateDir ¶
func SetTestTemplateDir(dir string)
SetTestTemplateDir sets the directory for templates, used only in testing. If it is not run via `go test`, it will panic.
func TakeOwnership ¶
func TakeOwnershipOfFile ¶
func UpdateBoardConfig ¶
UpdateBoardConfig updates or establishes the configuration for the given board
func WriteConfig ¶
func WriteConfig() error
Types ¶
type BoardConfig ¶
type BoardConfig struct { // InheritGlobalStyles determines whether to use the global styles in addition to the board's styles, as opposed to only the board's styles // Default: true InheritGlobalStyles bool // Styles is a list of Gochan themes with Name and Filename fields, choosable by the user Styles []Style // DefaultStyle is the filename of the default style to use for the board or the site. If it is not set, the first style in the Styles list will be used // Default: pipes.css DefaultStyle string // IncludeGlobalStyles is a list of additional CSS files to be loaded on the board pages, or all pages if this is the global configuration. IncludeGlobalStyles []string // IncludeScripts is a list of additional scripts to be loaded on the board pages, or all pages if this is the global configuration. IncludeScripts []IncludeScript // Banners is a list of banners to display on the board's front page, with Filename, Width, and Height fields Banners []PageBanner // Lockdown prevents users from posting if true // Default: false Lockdown bool // LockdownMessage is the message displayed to users if they try to cretae a post when the site is in lockdown // Default: This imageboard has temporarily disabled posting. We apologize for the inconvenience LockdownMessage string PostConfig UploadConfig // DateTimeFormat is the human readable format to use for showing post timestamps. See [the official documentation](https://pkg.go.dev/time#Time.Format) for more information. // Default: Mon, January 02, 2006 3:04:05 PM DateTimeFormat string // ShowPosterID determines whether to show the generated thread-unique poster ID in the post header (not yet implemented) // Default: false ShowPosterID bool // EnableSpoileredImages determines whether to allow users to spoiler images (not yet implemented) // Default: true EnableSpoileredImages bool // EnableSpoileredThreads determines whether to allow users to spoiler threads (not yet implemented) // Default: true EnableSpoileredThreads bool // Worksafe determines whether the board is worksafe or not. If it is set to true, threads cannot be marked NSFW // (given a hashtag with the text NSFW, case insensitive). // Default: true Worksafe bool // Cooldowns is used to prevent spamming by setting the number of seconds the user must wait before creating new threads or replies Cooldowns BoardCooldowns // RenderURLsAsLinks determines whether to render URLs as clickable links in posts // Default: true RenderURLsAsLinks bool // ThreadsPerPage is the number of threads to display per page // Default: 20 ThreadsPerPage int // EnableGeoIP shows a dropdown box allowing the user to set their post flag as their country // Default: false EnableGeoIP bool // EnableNoFlag allows the user to post without a flag. It is only used if EnableGeoIP or CustomFlags is true // Default: false EnableNoFlag bool // CustomFlags is a list of non-geoip flags with Name (viewable to the user) and Flag (flag image filename) fields CustomFlags []geoip.Country // contains filtered or unexported fields }
BoardConfig contains information about a specific board to be stored in /path/to/board/board.json or all boards if it is stored in the main gochan.json file. If a board doesn't have board.json, the site's default board config (with values set in gochan.json) will be used
func GetBoardConfig ¶
func GetBoardConfig(board string) *BoardConfig
GetBoardConfig returns the custom configuration for the specified board (if it exists) or the global board configuration if board is an empty string or it doesn't exist
func (*BoardConfig) CheckCustomFlag ¶
func (bc *BoardConfig) CheckCustomFlag(flag string) (string, bool)
CheckCustomFlag returns true if the given flag and name are configured for the board (or are globally set)
func (*BoardConfig) IsGlobal ¶
func (bc *BoardConfig) IsGlobal() bool
IsGlobal returns true if this is the global configuration applied to all boards by default, or false if it is an explicitly configured board
type BoardCooldowns ¶
type BoardCooldowns struct { // NewThread is the number of seconds the user must wait before creating new threads. // Default: 30 NewThread int `json:"threads"` // NewReply is the number of seconds the user must wait after replying to a thread before they can create another reply. // Default: 7 Reply int `json:"replies"` // NewImageReply is the number of seconds the user must wait after replying to a thread with an upload before they can create another reply. // Default: 7 ImageReply int `json:"images"` }
type CaptchaConfig ¶
type CaptchaConfig struct { // Type is the type of captcha to use. Currently only "hcaptcha" is supported Type string // OnlyNeededForThreads determines whether to require a captcha only when creating a new thread, or for all posts OnlyNeededForThreads bool // SiteKey is the public key for the captcha service. Usage depends on the captcha service SiteKey string // AccountSecret is the secret key for the captcha service. Usage depends on the captcha service AccountSecret string }
type EmbedMatcher ¶
type EmbedMatcher struct { // URLRegex checks the incoming embed and determines if it should be embedded with the EmbedTemplate URLRegex string // EmbedTemplate is the template for embedding the media in place of an upload. It uses the MediaID, HandlerID, // ThumbWidth, ThumbHeight fields of EmbedMediaData EmbedTemplate string // MediaIDSubmatchIndex is the index of the submatch in the URLRegex that contains the media ID // Default: 1 MediaIDSubmatchIndex *int // ThumbnailURLTemplate is the template for embedding the media thumbnail in place of the EmbedTemplate // HTML. If it is not set, the media will be embedded directly. It uses the MediaID field of EmbedMediaData ThumbnailURLTemplate string // MediaURLTemplate is used to construct the media URL from the media ID. It uses the MediaID field of EmbedMediaData MediaURLTemplate string }
func (*EmbedMatcher) HasThumbnail ¶
func (em *EmbedMatcher) HasThumbnail() bool
type EmbedTemplateData ¶
type GochanConfig ¶
type GochanConfig struct { SystemCriticalConfig SiteConfig BoardConfig // contains filtered or unexported fields }
func (*GochanConfig) ValidateValues ¶
func (gcfg *GochanConfig) ValidateValues() error
ValidateValues checks to make sure that the configuration options are usable (e.g., ListenAddress is a valid IP address, Port isn't a negative number, etc)
func (*GochanConfig) Write ¶
func (gcfg *GochanConfig) Write() error
type IncludeScript ¶
type InvalidValueError ¶
InvalidValueError represents a GochanConfig field with a bad value
func (*InvalidValueError) Error ¶
func (iv *InvalidValueError) Error() string
type MissingField ¶
MissingField represents a field missing from the configuration file
type PageBanner ¶
type PageBanner struct { // Filename is the name of the image file to display as seen by the browser Filename string // Width is the width of the image in pixels Width int // Height is the height of the image in pixels Height int }
PageBanner represents the filename and dimensions of a banner image to display on board and thread pages
type PostConfig ¶
type PostConfig struct { // MaxMessageLength is the maximum number of characters allowed in a post // Default: 2000 MaxMessageLength int // ReservedTrips is used for reserving secure tripcodes. It should be a map of input strings to output tripcode strings. For example, if you have `{"abcd":"WXYZ"}` and someone posts with the name Name##abcd, their name will instead show up as Name!!WXYZ on the site. ReservedTrips map[string]string // ThreadsPerPage is the number of threads to display per page // Default: 20 ThreadsPerPage int // RepliesOnBoardPage is the number of replies to display on the board page // Default: 3 RepliesOnBoardPage int // StickyRepliesOnBoardPage is the number of replies to display on the board page for sticky threads // Default: 1 StickyRepliesOnBoardPage int // NewThreadsRequireUpload determines whether to require an upload to create a new thread // Default: false NewThreadsRequireUpload bool // EnableCyclicThreads allows users to create threads that have a maximum number of replies before the oldest reply is deleted // Default: true EnableCyclicThreads bool // CyclicThreadNumPost determines the number of posts a cyclic thread can have before the oldest post is deleted // Default: 500 CyclicThreadNumPosts int // BanColors is a list of colors to use for the ban message with the staff name as the key. If the staff name is not found in the list, the default style color will be used. BanColors map[string]string // BanMessage is the default message shown on a post that a user was banned for // Default: USER WAS BANNED FOR THIS POST BanMessage string // EmbedWidth is the width of embedded external media files // Default: 400 EmbedWidth int // EmbedHeight is the height of embedded external media files // Default: 300 EmbedHeight int // EmbedMatchers is a map of site ID keys to objects used to match (via regular expression) URLs and embed them in posts via templates, // with an optional image thumbnail if supported. If a URL template is not provided, the video/frame will be embedded directly. // If EmbedMatchers is nil, embedding is disabled for the board, or globally if it is in the global configuration. EmbedMatchers map[string]EmbedMatcher // ImagesOpenNewTab determines whether to open images in a new tab when an image link is clicked // Default: true ImagesOpenNewTab bool // NewTabOnExternalLinks determines whether to open external links in a new tab // Default: true NewTabOnExternalLinks bool // NewTabOnOutlinks is an alias for the NewTabOnExternalLinks field. // // Deprecated: Use NewTabOnExternalLinks instead NewTabOnOutlinks bool `json:",omitempty"` // DisableBBcode will disable BBCode to HTML conversion if true // Default: false DisableBBcode bool // AllowDiceRerolls determines whether to allow users to edit posts to reroll dice // Default: false AllowDiceRerolls bool // contains filtered or unexported fields }
func (*PostConfig) GetEmbedMediaID ¶
func (pc *PostConfig) GetEmbedMediaID(url string) (string, string, error)
GetEmbedMediaID returns the site ID, and media ID for the given URL if it is compatible with any configured embed handlers. It returns an error if none are found
func (*PostConfig) GetEmbedTemplates ¶
func (pc *PostConfig) GetEmbedTemplates(embedID string) (*template.Template, *template.Template, error)
GetEmbedTemplates returns the embed and (if it has one) thumbnail URL templates for the given embed ID
func (*PostConfig) GetLinkTemplate ¶
func (pc *PostConfig) GetLinkTemplate(embedID string) (*template.Template, error)
func (*PostConfig) HasEmbedMatchers ¶
func (pc *PostConfig) HasEmbedMatchers() bool
HasEmbedMatchers returns true if the board has embed handlers configured
type SQLConfig ¶
type SQLConfig struct { // DBtype is the type of SQL database to use. Currently supported values are "mysql", "postgres", and "sqlite3" DBtype string // DBhost is the hostname or IP address of the SQL server, or the path to the SQLite database file. // To connect to a MySQL database, set `DBhost` to "x.x.x.x:3306" (replacing x.x.x.x with your database server's // IP or domain) or a different port, if necessary. You can also use a UNIX socket if you have it set up, like // "unix(/var/run/mysqld/mysqld.sock)". // To connect to a PostgreSQL database, set `DBhost` to the IP address or hostname. Using a UNIX socket may work // as well, but it is currently untested. DBhost string // DBname is the name of the SQL database to connect to DBname string // DBusername is the username to use when authenticating with the SQL server DBusername string // DBpassword is the password to use when authenticating with the SQL server DBpassword string // DBprefix is the prefix to add to table names in the database. It is not requried but may be useful if you need to share a database. // Once you set it and do the initial setup, do not change it, as gochan will think the tables are missing and try to recreate them. DBprefix string // DBTimeoutSeconds sets the timeout for SQL queries in seconds, 0 means no timeout. // Default: 15 DBTimeoutSeconds int // DBMaxOpenConnections is the maximum number of open connections to the database connection pool. // Default: 10 DBMaxOpenConnections int // DBMaxIdleConnections is the maximum number of idle connections to the database connection pool. // Default: 10 DBMaxIdleConnections int // DBConnMaxLifetimeMin is the maximum lifetime of a connection in minutes. // Default: 3 DBConnMaxLifetimeMin int }
func GetSQLConfig ¶
func GetSQLConfig() SQLConfig
GetSQLConfig returns SQL configuration info. It returns a value instead of a a pointer to it because it is not safe to edit while Gochan is running
type SiteConfig ¶
type SiteConfig struct { // FirstPage is a list of possible filenames to look for if a directory is requested // Default: ["index.html", "firstrun.html", "1.html"] FirstPage []string // Username is the name of the user that the server will run as, if set, or the current user if empty or unset. // It must be a valid user on the system if it is set Username string // CookieMaxAge is the parsed max age duration of cookies, e.g. "1 year 2 months 3 days 4 hours" or "1y2mo3d4h". // Default: 1y CookieMaxAge string // StaffSessionDuration is the parsed max age duration of staff session cookies, e.g. "1 year 2 months 3 days 4 hours" or "1y2mo3d4h". // Default: 3mo StaffSessionDuration string // SiteName is the name of the site, displayed in the title and front page header // Default: Gochan SiteName string // SiteSlogan is the community slogan displayed on the front page below the site name SiteSlogan string // Modboard was intended to be the board that moderators would use to discuss moderation, but it is not currently used. // Deprecated: This field is not currently used and may be removed in the future Modboard string // MaxRecentPosts is the number of recent posts to display on the front page // Default: 15 MaxRecentPosts int // RecentPostsWithNoFile determines whether to include posts with no file in the recent posts list // Default: false RecentPostsWithNoFile bool // EnableAppeals determines whether to allow users to appeal bans // Default: true EnableAppeals bool // MinifyHTML tells the server to minify HTML output before sending it to the client // Default: true MinifyHTML bool // MinifyJS tells the server to minify JavaScript and JSON output before sending it to the client // Default: true MinifyJS bool // GeoIPType is the type of GeoIP database to use. Currently only "mmdb" is supported, though other types may be provided by plugins GeoIPType string // GeoIPOptions is a map of options to pass to the GeoIP plugin GeoIPOptions map[string]any // Captcha options for spam prevention. Currently only hcaptcha is supported Captcha *CaptchaConfig // FingerprintVideoThumbnails determines whether to use video thumbnails for image fingerprinting. If false, the video file will not be checked by fingerprinting filters // Default: false FingerprintVideoThumbnails bool // FingerprintHashLength is the length of the hash used for image fingerprinting // Default: 16 FingerprintHashLength int // contains filtered or unexported fields }
SiteConfig contains information about the site/community, e.g. the name of the site, the slogan (if set), the first page to look for if a directory is requested, etc
func GetSiteConfig ¶
func GetSiteConfig() *SiteConfig
GetSiteConfig returns the global site configuration (site name, slogan, etc)
func (*SiteConfig) CookieMaxAgeDuration ¶
func (sc *SiteConfig) CookieMaxAgeDuration() (time.Duration, error)
type Style ¶
type Style struct { // Name is the display name of the style Name string // Filename is the name of the CSS file in /static to use for the style Filename string }
Style represents a theme (Pipes, Dark, etc)
type SystemCriticalConfig ¶
type SystemCriticalConfig struct { // ListenAddress is the IP address or domain name that the server will listen on ListenAddress string // ListenIP is an alias for the ListenAddress field. // // Deprecated: Use ListenAddress instead ListenIP string `json:",omitempty"` // Port is the port that the server will listen on // Default: 80 Port int // UseFastCGI tells the server to listen on FastCGI instead of HTTP if true // Default: false UseFastCGI bool // DocumentRoot is the path to the directory that contains the served static files DocumentRoot string // TemplateDir is the path to the directory that contains the template files TemplateDir string // LogDir is the path to the directory that contains the log files. It must be writable by the server and will be created if it doesn't exist LogDir string // Plugins is a list of paths to plugins to be loaded on startup. In Windows, only .lua plugins are supported. In Unix, .so plugins are also supported, // but they must be compiled with the same Go version as the server and must be compiled in plugin mode Plugins []string // WebRoot is the base URL path that the server will serve files and generated pages from. // Default: / WebRoot string // SiteHost is the publicly accessible domain name or IP address of the site, e.g. "example.com" used for anti-spam checking SiteHost string // SiteDomain is an alias for the the SiteHost field. // // Deprecated: Use SiteHost instead SiteDomain string `json:",omitempty"` SQLConfig // CheckRequestReferer tells the server to validate the Referer header from requests to prevent CSRF attacks. // Default: true CheckRequestReferer bool // LogLevel determines the minimum level of log event to output. Any events lower than this level will be ignored. // Valid values are "trace", "debug", "info", "warn", "error", "fatal", and "panic". // Default: info LogLevelStr string `json:"LogLevel"` // RandomSeed is a random string used for generating secure tokens. It will be generated if not set and must not be changed RandomSeed string TimeZone int `json:"-"` // contains filtered or unexported fields }
SystemCriticalConfig contains configuration options that are extremely important, and fucking with them while the server is running could have site breaking consequences. It should only be changed by modifying the configuration file and restarting the server.
func GetSystemCriticalConfig ¶
func GetSystemCriticalConfig() *SystemCriticalConfig
GetSystemCriticalConfig returns system-critical configuration options like listening IP It returns a value instead of a pointer, because it is not usually safe to edit while Gochan is running.
func (*SystemCriticalConfig) LogLevel ¶
func (scc *SystemCriticalConfig) LogLevel() zerolog.Level
LogLevel returns the minimum log event level to write to the log file
type UploadConfig ¶
type UploadConfig struct { // RejectDuplicateUploads determines whether to reject images and videos that have already been uploaded // Default: false RejectDuplicateUploads bool // ThumbWidth is the maximum width that thumbnails in the top thread post will be scaled down to // Default: 200 ThumbWidth int // ThumbHeight is the maximum height that thumbnails in the top thread post will be scaled down to // Default: 200 ThumbHeight int // ThumbWidthReply is the maximum width that thumbnails in thread replies will be scaled down to // Default: 125 ThumbWidthReply int // ThumbHeightReply is the maximum height that thumbnails in thread replies will be scaled down to // Default: 125 ThumbHeightReply int // ThumbWidthCatalog is the maximum width that thumbnails on the board catalog page will be scaled down to // Default: 50 ThumbWidthCatalog int // ThumbHeightCatalog is the maximum height that thumbnails on the board catalog page will be scaled down to // Default: 50 ThumbHeightCatalog int // AllowOtherExtensions is a map of file extensions to use for uploads that are not images or videos // The key is the extension (e.g. ".pdf") and the value is the filename of the thumbnail to use in /static AllowOtherExtensions map[string]string // StripImageMetadata sets what (if any) metadata to remove from uploaded images using exiftool. // Valid values are "", "none" (has the same effect as ""), "exif", or "all" (for stripping all metadata) StripImageMetadata string // ExiftoolPath is the path to the exiftool command. If unset or empty, the system path will be used to find it ExiftoolPath string }
func (*UploadConfig) AcceptedExtension ¶
func (uc *UploadConfig) AcceptedExtension(filename string) bool