mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-05 17:40:26 +00:00
Support configuration files
See https://mycorrhiza.lesarbr.es/hypha/configuration for an example. A copy of this example is stored at assets/config.ini. Use option -config-path to pass the config file. Note that all other CLI options have been removed. Some of them may be returned later. Also note that no real testing has been done.
This commit is contained in:
parent
adfe080a31
commit
0426c372de
3
Makefile
3
Makefile
@ -7,6 +7,9 @@ auth_run: build
|
||||
gemini_run: build
|
||||
./mycorrhiza -gemini-cert-path "." metarrhiza
|
||||
|
||||
config_run: build
|
||||
./mycorrhiza -config-path "assets/config.ini" metarrhiza
|
||||
|
||||
build:
|
||||
go generate
|
||||
go build .
|
||||
|
@ -1,10 +1,10 @@
|
||||
# 🍄 MycorrhizaWiki 0.13
|
||||
# 🍄 MycorrhizaWiki 0.14
|
||||
A wiki engine.
|
||||
|
||||
[Main wiki](https://mycorrhiza.lesarbr.es)
|
||||
|
||||
## Building
|
||||
Also see [detailed instructions](https://mycorrhiza.lesarbr.es/page/deploy) on wiki.
|
||||
Also see [detailed instructions](https://mycorrhiza.lesarbr.es/hypha/deploy) on wiki.
|
||||
```sh
|
||||
git clone --recurse-submodules https://github.com/bouncepaw/mycorrhiza
|
||||
cd mycorrhiza
|
||||
|
@ -61,7 +61,7 @@ header { width: 100%; margin-bottom: 1rem; }
|
||||
|
||||
@media screen and (max-width: 800px) {
|
||||
.amnt-grid { grid-template-columns: 1fr; }
|
||||
.layout { grid-template-column: auto; grid-template-row: auto auto auto; }
|
||||
.layout { grid-template-columns: auto; grid-template-rows: auto auto auto; }
|
||||
.main-width { width: 100%; }
|
||||
main { padding: 1rem; margin: 0; }
|
||||
}
|
||||
@ -178,7 +178,7 @@ figcaption { padding-bottom: .5rem; }
|
||||
.rc-entry__links, .rc-entry__msg { grid-column: 1 / span 2; }
|
||||
.rc-entry__author { font-style: italic; }
|
||||
|
||||
.prevnext__el { display: block-inline; min-width: 40%; padding: .5rem; margin-bottom: .25rem; text-decoration: none; border-radius: .25rem; }
|
||||
.prevnext__el { display: inline-block; min-width: 40%; padding: .5rem; margin-bottom: .25rem; text-decoration: none; border-radius: .25rem; }
|
||||
.prevnext__prev { float: left; }
|
||||
.prevnext__next { float: right; text-align: right; }
|
||||
|
||||
|
16
assets/config.ini
Normal file
16
assets/config.ini
Normal file
@ -0,0 +1,16 @@
|
||||
WikiName = My wiki
|
||||
NaviTitleIcon = 🐑
|
||||
|
||||
[Hyphae]
|
||||
HomeHypha = home
|
||||
UserHypha = u
|
||||
HeaderLinksHypha = header-links
|
||||
|
||||
[Network]
|
||||
HTTPPort = 8080
|
||||
URL = https://wiki
|
||||
GeminiCertificatePath = /home/wiki/gemcerts
|
||||
|
||||
[Authorization]
|
||||
UseFixedAuth = true
|
||||
FixedAuthCredentialsPath = /home/wiki/mycocredentials.json
|
37
flag.go
37
flag.go
@ -10,16 +10,17 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&util.URL, "url", "http://0.0.0.0:$port", "URL at which your wiki can be found. Used to generate feeds and social media previews")
|
||||
flag.StringVar(&util.ServerPort, "port", "1737", "Port to serve the wiki at using HTTP")
|
||||
flag.StringVar(&util.HomePage, "home", "home", "The home page name")
|
||||
flag.StringVar(&util.SiteNavIcon, "icon", "🍄", "What to show in the navititle in the beginning, before the colon")
|
||||
flag.StringVar(&util.SiteName, "name", "wiki", "What is the name of your wiki")
|
||||
flag.StringVar(&util.UserHypha, "user-hypha", "u", "Hypha which is a superhypha of all user pages")
|
||||
flag.StringVar(&util.AuthMethod, "auth-method", "none", "What auth method to use. Variants: \"none\", \"fixed\"")
|
||||
flag.StringVar(&util.FixedCredentialsPath, "fixed-credentials-path", "mycocredentials.json", "Used when -auth-method=fixed. Path to file with user credentials.")
|
||||
flag.StringVar(&util.HeaderLinksHypha, "header-links-hypha", "", "Optional hypha that overrides the header links")
|
||||
flag.StringVar(&util.GeminiCertPath, "gemini-cert-path", "", "Directory where you store Gemini certificates. Leave empty if you don't want to use Gemini.")
|
||||
// flag.StringVar(&util.URL, "url", "http://0.0.0.0:$port", "URL at which your wiki can be found. Used to generate feeds and social media previews")
|
||||
// flag.StringVar(&util.ServerPort, "port", "1737", "Port to serve the wiki at using HTTP")
|
||||
// flag.StringVar(&util.HomePage, "home", "home", "The home page name")
|
||||
// flag.StringVar(&util.SiteNavIcon, "icon", "🍄", "What to show in the navititle in the beginning, before the colon")
|
||||
// flag.StringVar(&util.SiteName, "name", "wiki", "What is the name of your wiki")
|
||||
// flag.StringVar(&util.UserHypha, "user-hypha", "u", "Hypha which is a superhypha of all user pages")
|
||||
// flag.StringVar(&util.AuthMethod, "auth-method", "none", "What auth method to use. Variants: \"none\", \"fixed\"")
|
||||
// flag.StringVar(&util.FixedCredentialsPath, "fixed-credentials-path", "mycocredentials.json", "Used when -auth-method=fixed. Path to file with user credentials.")
|
||||
// flag.StringVar(&util.HeaderLinksHypha, "header-links-hypha", "", "Optional hypha that overrides the header links")
|
||||
// flag.StringVar(&util.GeminiCertPath, "gemini-cert-path", "", "Directory where you store Gemini certificates. Leave empty if you don't want to use Gemini.")
|
||||
flag.StringVar(&util.ConfigFilePath, "config-path", "", "Path to a configuration file. Leave empty if you don't want to use it.")
|
||||
}
|
||||
|
||||
// Do the things related to cli args and die maybe
|
||||
@ -31,6 +32,10 @@ func parseCliArgs() {
|
||||
log.Fatal("Error: pass a wiki directory")
|
||||
}
|
||||
|
||||
if util.ConfigFilePath != "" {
|
||||
util.ReadConfigFile(util.ConfigFilePath)
|
||||
}
|
||||
|
||||
var err error
|
||||
WikiDir, err = filepath.Abs(args[0])
|
||||
util.WikiDir = WikiDir
|
||||
@ -38,20 +43,12 @@ func parseCliArgs() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if util.URL == "http://0.0.0.0:$port" {
|
||||
if util.URL == "" {
|
||||
util.URL = "http://0.0.0.0:" + util.ServerPort
|
||||
}
|
||||
|
||||
util.HomePage = util.CanonicalName(util.HomePage)
|
||||
util.UserHypha = util.CanonicalName(util.UserHypha)
|
||||
util.HeaderLinksHypha = util.CanonicalName(util.HeaderLinksHypha)
|
||||
|
||||
switch util.AuthMethod {
|
||||
case "none":
|
||||
case "fixed":
|
||||
user.AuthUsed = true
|
||||
user.ReadUsersFromFilesystem()
|
||||
default:
|
||||
log.Fatal("Error: unknown auth method:", util.AuthMethod)
|
||||
}
|
||||
user.AuthUsed = util.UseFixedAuth
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -5,8 +5,8 @@ go 1.14
|
||||
require (
|
||||
git.sr.ht/~adnano/go-gemini v0.1.13
|
||||
github.com/adrg/xdg v0.2.2
|
||||
github.com/go-ini/ini v1.62.0 // indirect
|
||||
github.com/gorilla/feeds v1.1.1
|
||||
github.com/kr/pretty v0.2.1 // indirect
|
||||
github.com/valyala/quicktemplate v1.6.3
|
||||
tildegit.org/solderpunk/gemcert v0.0.0-20200801165357-fc14deb27512 // indirect
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -5,6 +5,8 @@ github.com/adrg/xdg v0.2.2/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ
|
||||
github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-ini/ini v1.62.0 h1:7VJT/ZXjzqSrvtraFp4ONq80hTcRQth1c9ZnQ3uNQvU=
|
||||
github.com/go-ini/ini v1.62.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY=
|
||||
github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA=
|
||||
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||
@ -35,5 +37,3 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
tildegit.org/solderpunk/gemcert v0.0.0-20200801165357-fc14deb27512 h1:reGEt1vmGompn/6FitHdBatILTsK9CYnQOCw3weoW/s=
|
||||
tildegit.org/solderpunk/gemcert v0.0.0-20200801165357-fc14deb27512/go.mod h1:gqBK7AJ5wPR1bpFOuPmlQObYxwXrFdZmNb2vdzquqoA=
|
||||
|
70
util/config.go
Normal file
70
util/config.go
Normal file
@ -0,0 +1,70 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-ini/ini"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
WikiName string
|
||||
NaviTitleIcon string
|
||||
Hyphae
|
||||
Network
|
||||
Authorization
|
||||
}
|
||||
|
||||
type Hyphae struct {
|
||||
HomeHypha string
|
||||
UserHypha string
|
||||
HeaderLinksHypha string
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
HTTPPort uint64
|
||||
URL string
|
||||
GeminiCertificatePath string
|
||||
}
|
||||
|
||||
type Authorization struct {
|
||||
UseFixedAuth bool
|
||||
FixedAuthCredentialsPath string
|
||||
}
|
||||
|
||||
func ReadConfigFile(path string) {
|
||||
log.Println("Loading config at", path)
|
||||
cfg := &Config{
|
||||
WikiName: "MycorrhizaWiki",
|
||||
NaviTitleIcon: "🍄",
|
||||
Hyphae: Hyphae{
|
||||
HomeHypha: "home",
|
||||
UserHypha: "u",
|
||||
HeaderLinksHypha: "",
|
||||
},
|
||||
Network: Network{
|
||||
HTTPPort: 1737,
|
||||
URL: "",
|
||||
GeminiCertificatePath: "",
|
||||
},
|
||||
Authorization: Authorization{
|
||||
UseFixedAuth: false,
|
||||
FixedAuthCredentialsPath: "",
|
||||
},
|
||||
}
|
||||
err := ini.MapTo(cfg, path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
SiteName = cfg.WikiName
|
||||
SiteNavIcon = cfg.NaviTitleIcon
|
||||
HomePage = cfg.HomeHypha
|
||||
UserHypha = cfg.UserHypha
|
||||
HeaderLinksHypha = cfg.HeaderLinksHypha
|
||||
ServerPort = strconv.FormatUint(cfg.HTTPPort, 10)
|
||||
URL = cfg.URL
|
||||
GeminiCertPath = cfg.GeminiCertificatePath
|
||||
UseFixedAuth = cfg.UseFixedAuth
|
||||
FixedCredentialsPath = cfg.FixedAuthCredentialsPath
|
||||
}
|
26
util/util.go
26
util/util.go
@ -9,18 +9,24 @@ import (
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// TODO: make names match to fields of config file
|
||||
var (
|
||||
URL string
|
||||
ServerPort string
|
||||
HomePage string
|
||||
SiteNavIcon string
|
||||
SiteName string
|
||||
WikiDir string
|
||||
UserHypha string
|
||||
HeaderLinksHypha string
|
||||
AuthMethod string
|
||||
SiteName string
|
||||
SiteNavIcon string
|
||||
|
||||
HomePage string
|
||||
UserHypha string
|
||||
HeaderLinksHypha string
|
||||
|
||||
ServerPort string
|
||||
URL string
|
||||
GeminiCertPath string
|
||||
|
||||
UseFixedAuth bool
|
||||
FixedCredentialsPath string
|
||||
GeminiCertPath string
|
||||
|
||||
WikiDir string
|
||||
ConfigFilePath string
|
||||
)
|
||||
|
||||
// LettersNumbersOnly keeps letters and numbers only in the given string.
|
||||
|
@ -352,7 +352,7 @@ func StreamAboutHTML(qw422016 *qt422016.Writer) {
|
||||
//line views/stuff.qtpl:98
|
||||
qw422016.N().S(`</h1>
|
||||
<ul>
|
||||
<li><b><a href="https://mycorrhiza.lesarbr.es">MycorrhizaWiki</a> version:</b> β 0.13 indev</li>
|
||||
<li><b><a href="https://mycorrhiza.lesarbr.es">MycorrhizaWiki</a> version:</b> β 0.13</li>
|
||||
`)
|
||||
//line views/stuff.qtpl:101
|
||||
if user.AuthUsed {
|
||||
@ -445,7 +445,7 @@ func StreamAdminPanelHTML(qw422016 *qt422016.Writer) {
|
||||
qw422016.N().S(`
|
||||
<div class="layout">
|
||||
<main class="main-width">
|
||||
<h1>Admininstrative functions</h1>
|
||||
<h1>Administrative functions</h1>
|
||||
<section>
|
||||
<h2>Safe things</h2>
|
||||
<ul>
|
||||
|
Loading…
Reference in New Issue
Block a user