Changeset 71 in code
- Timestamp:
- Apr 17, 2025, 6:18:24 PM (7 weeks ago)
- Location:
- trunk
- Files:
-
- 4 added
- 8 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Makefile
r63 r71 1 GO ?= go 1 2 PREFIX ?= /usr/local 2 GOFLAGS ?= -v -ldflags "-w -X `go list`.Version=${VERSION} -X `go list`.Commit=${COMMIT}" 3 VERSION = `git describe --abbrev=0 --tags 2>/dev/null || echo "VERSION"` 4 COMMIT = `git rev-parse --short HEAD || echo "COMMIT"` 3 GOFLAGS ?= -v -ldflags "-w -X `${GO} list`.Version=${VERSION}" 4 VERSION ?= 2025.04.17 5 5 6 6 build: 7 gobuild ${GOFLAGS} ./cmd/mai7 ${GO} build ${GOFLAGS} ./cmd/mai 8 8 clean: 9 9 rm -f mai -
trunk/cmd/mai/main.go
r70 r71 13 13 "syscall" 14 14 15 "ma risa.chaotic.ninja/mai"16 "ma risa.chaotic.ninja/mai/engines"15 "mahou-no-mori.yakumo.dev/mai" 16 "mahou-no-mori.yakumo.dev/mai/engines" 17 17 18 18 "github.com/gofiber/fiber/v2" … … 25 25 var ( 26 26 configfile string 27 groupname string 28 username string 27 verbose bool 29 28 ) 30 29 var conf struct { 31 danmaku int30 group string 32 31 listen string 33 staticpath string 34 tmplpath string 32 requests int 33 static string 34 templates string 35 user string 35 36 } 36 37 func MaiSkipLimiter(c *fiber.Ctx) bool { 37 38 // Paths listed here are not considered for rate limiting 38 39 path := c.Path() 39 return strings.HasPrefix(path, "/static") || 40 strings.HasPrefix(path, "/docs") 40 return strings.HasPrefix(path, "/static") 41 41 } 42 42 func main() { 43 43 parseFlags() 44 44 45 conf.listen = "127.0.0.1:5000" 46 conf.requests = 5 47 conf.static = "./static" 48 conf.templates = "./views" 49 45 50 if configfile != "" { 51 if verbose { 52 log.Printf("Reading configuration from %s", configfile) 53 } 46 54 readConf(configfile) 47 55 } 48 56 49 // Default settings 50 conf.danmaku = 10 51 conf.listen = "127.0.0.1:5000" 52 conf.staticpath = "./static" 53 conf.tmplpath = "./views" 54 55 if username != "" { 56 uid, gid, err := usergroupids(username, groupname) 57 if conf.user != "" { 58 uid, gid, err := usergroupids(conf.user, conf.group) 57 59 if err != nil { 58 60 log.Fatal(err) … … 62 64 } 63 65 64 engine := html.New(conf.t mplpath, ".html")66 engine := html.New(conf.templates, ".html") 65 67 engine.AddFunc("inc", func(i int) int { return i + 1 }) 66 68 … … 86 88 server.Use(favicon.New( 87 89 favicon.Config{ 88 File: conf.static path+ "/favicon.ico",90 File: conf.static + "/favicon.ico", 89 91 }, 90 92 )) … … 101 103 server.Use(limiter.New(limiter.Config{ 102 104 Next: MaiSkipLimiter, 103 Max: conf. danmaku,105 Max: conf.requests, 104 106 Expiration: 30 * time.Second, 105 107 LimiterMiddleware: limiter.SlidingWindow{}, … … 297 299 298 300 server.Get("/toomanyrequests", func(c *fiber.Ctx) error { 299 return c.SendFile(conf.t mplpath+ "/429.html")301 return c.SendFile(conf.templates + "/429.html") 300 302 return c.SendStatus(429) 301 303 }) … … 326 328 return c.Redirect("/") 327 329 }) 328 server.Static("/static", conf.staticpath, fiber.Static{ 329 Compress: true, 330 server.Static("/static", conf.static, fiber.Static{ 330 331 ByteRange: true, 331 332 Browse: true, 332 333 }) 333 334 334 server.Static("/docs", "./docs", fiber.Static{})335 336 335 server.Listen(conf.listen) 337 336 } -
trunk/cmd/mai/parseflags.go
r67 r71 8 8 func parseFlags() { 9 9 flag.StringVar(&configfile, "f", "", "Configuration file") 10 flag.StringVar(&username, "u", "", "Sets the user to which privilege dropping is done") 11 flag.StringVar(&groupname, "g", "", "Sets the group to which privilege dropping is done") 10 flag.BoolVar(&verbose, "v", false, "Be verbose") 12 11 flag.Parse() 13 12 } -
trunk/cmd/mai/readconf.go
r70 r71 11 11 return err 12 12 } 13 conf.danmaku, _ = cfg.Section("mai").Key("danmaku").Int()14 conf.listen = cfg.Section("mai").Key("listen").String()15 conf.staticpath = cfg.Section("mai").Key("static").String()16 conf.tmplpath = cfg.Section("mai").Key("templates").String()17 13 14 conf.group = cfg.Section("mai").Key("group").String() 15 conf.listen = cfg.Section("http").Key("listen").String() 16 conf.requests, _ = cfg.Section("http").Key("requests").Int() 17 conf.static = cfg.Section("paths").Key("static").String() 18 conf.templates = cfg.Section("paths").Key("templates").String() 19 conf.user = cfg.Section("mai").Key("user").String() 18 20 return nil 19 21 } -
trunk/example/mai.ini
r67 r71 1 [http] 2 # TCP socket to listen on. 3 # Must not be already used by something else. 4 listen = 127.0.0.1:5000 5 # How many requests per minute are allowed 6 # before a rate-limit happens. 7 requests = 10 1 8 [mai] 2 listen = "127.0.0.1:5000" 3 rootdir = "./static" 4 tmplpath = "./views" 9 # Drop privilege to the user and group specified. 10 # When only the user is specified, the default group of the user will 11 # be used. 12 # 13 # user = www 14 # group = www 15 [paths] 16 # Where to locate resources such as CSS, etc 17 static = ./static 18 # Where to locate the pages to be served 19 templates = ./views -
trunk/example/mai.nginx
r68 r71 2 2 listen 80; 3 3 listen [::]:80; 4 server_name mai.example. com;4 server_name mai.example.org; 5 5 6 6 location / { … … 12 12 listen 443 ssl; 13 13 listen [::]:443 ssl; 14 server_name mai.example. com;14 server_name mai.example.org; 15 15 16 16 ssl_certificate /path/to/fullchain.pem; -
trunk/go.mod
r70 r71 1 module ma risa.chaotic.ninja/mai1 module mahou-no-mori.yakumo.dev/mai 2 2 3 3 go 1.20 -
trunk/rc.d/FreeBSD
r67 r71 1 1 #!/bin/sh 2 # $ TheSupernovaDuo$2 # $YakumoLabs$ 3 3 # 4 4 # PROVIDE: mai -
trunk/rc.d/NetBSD
r67 r71 1 1 #!/bin/sh 2 # $ TheSupernovaDuo$2 # $YakumoLabs$ 3 3 # 4 4 # PROVIDE: mai 5 5 # REQUIRE: NETWORKING DAEMON 6 # BEFORE: LOGIN7 # KEYWORD: shutdown8 6 9 7 $_rc_subr_loaded . /etc/rc.subr … … 11 9 name="mai" 12 10 rcvar=$name 13 command="/usr/ pkg/bin/mai"14 command_args="-f /usr/ pkg/etc/mai/mai.ini -u www -g www"11 command="/usr/local/bin/mai" 12 command_args="-f /usr/local/etc/mai/mai.ini" 15 13 pidfile="/var/run/${name}.pid" 16 14 start_cmd="mai_start" 17 15 18 required_files="/usr/ pkg/etc/mai/mai.ini"16 required_files="/usr/local/etc/mai/mai.ini" 19 17 20 18 mai_start() { -
trunk/rc.d/OpenBSD
r67 r71 1 1 #!/bin/ksh 2 # $ TheSupernovaDuo$2 # $YakumoLabs$ 3 3 4 4 daemon="/usr/local/bin/mai" 5 daemon_flags="-f /usr/local/etc/mai/mai.ini -u www -g www"5 daemon_flags="-f /usr/local/etc/mai/mai.ini" 6 6 7 7 . /etc/rc.d/rc.subr -
trunk/rc.d/immortal.yml
r67 r71 1 cmd: /usr/local/bin/mai -f /usr/local/etc/mai/mai.ini -g www -u www 1 # $YakumoLabs$ 2 cmd: /usr/local/bin/mai -f /usr/local/etc/mai/mai.ini 2 3 cwd: /usr/local/share/mai -
trunk/version.go
r63 r71 8 8 // Version release version 9 9 Version = "0.0.1" 10 11 // Commit will be overwritten automatically by the build system12 Commit = "HEAD"13 10 ) 14 11 15 12 // FullVersion display the full version and build 16 13 func FullVersion() string { 17 return fmt.Sprintf("%s @%s", Version, Commit)14 return fmt.Sprintf("%s", Version) 18 15 }
Note:
See TracChangeset
for help on using the changeset viewer.