Changeset 71 in code


Ignore:
Timestamp:
Apr 17, 2025, 6:18:24 PM (7 weeks ago)
Author:
yakumo.izuru
Message:

今では重荷がなくなったので...

Location:
trunk
Files:
4 added
8 deleted
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r63 r71  
     1GO ?= go
    12PREFIX ?= /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"`
     3GOFLAGS ?= -v -ldflags "-w -X `${GO} list`.Version=${VERSION}"
     4VERSION ?= 2025.04.17
    55
    66build:
    7         go build ${GOFLAGS} ./cmd/mai
     7        ${GO} build ${GOFLAGS} ./cmd/mai
    88clean:
    99        rm -f mai
  • trunk/cmd/mai/main.go

    r70 r71  
    1313        "syscall"
    1414
    15         "marisa.chaotic.ninja/mai"
    16         "marisa.chaotic.ninja/mai/engines"
     15        "mahou-no-mori.yakumo.dev/mai"
     16        "mahou-no-mori.yakumo.dev/mai/engines"
    1717
    1818        "github.com/gofiber/fiber/v2"
     
    2525var (
    2626        configfile string
    27         groupname string
    28         username string
     27        verbose bool
    2928)
    3029var conf struct {
    31         danmaku int
     30        group string
    3231        listen string
    33         staticpath string
    34         tmplpath string
     32        requests int
     33        static string
     34        templates string
     35        user string
    3536}
    3637func MaiSkipLimiter(c *fiber.Ctx) bool {
    3738        // Paths listed here are not considered for rate limiting
    3839        path := c.Path()
    39         return strings.HasPrefix(path, "/static") ||
    40                 strings.HasPrefix(path, "/docs")
     40        return strings.HasPrefix(path, "/static")
    4141}
    4242func main() {
    4343        parseFlags()
    4444
     45        conf.listen = "127.0.0.1:5000"
     46        conf.requests = 5
     47        conf.static = "./static"
     48        conf.templates = "./views"
     49
    4550        if configfile != "" {
     51                if verbose {
     52                        log.Printf("Reading configuration from %s", configfile)
     53                }
    4654                readConf(configfile)
    4755        }
    4856
    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)
    5759                if err != nil {
    5860                        log.Fatal(err)
     
    6264        }
    6365       
    64         engine := html.New(conf.tmplpath, ".html")
     66        engine := html.New(conf.templates, ".html")
    6567        engine.AddFunc("inc", func(i int) int { return i + 1 })
    6668
     
    8688        server.Use(favicon.New(
    8789                favicon.Config{
    88                         File: conf.staticpath + "/favicon.ico",
     90                        File: conf.static + "/favicon.ico",
    8991                },
    9092        ))
     
    101103        server.Use(limiter.New(limiter.Config{
    102104                Next: MaiSkipLimiter,
    103                 Max: conf.danmaku,
     105                Max: conf.requests,
    104106                Expiration: 30 * time.Second,
    105107                LimiterMiddleware: limiter.SlidingWindow{},
     
    297299
    298300        server.Get("/toomanyrequests", func(c *fiber.Ctx) error {
    299                 return c.SendFile(conf.tmplpath + "/429.html")
     301                return c.SendFile(conf.templates + "/429.html")
    300302                return c.SendStatus(429)
    301303        })
     
    326328                return c.Redirect("/")
    327329        })
    328         server.Static("/static", conf.staticpath, fiber.Static{
    329                 Compress: true,
     330        server.Static("/static", conf.static, fiber.Static{
    330331                ByteRange: true,
    331332                Browse: true,
    332333        })
    333334
    334         server.Static("/docs", "./docs", fiber.Static{})
    335 
    336335        server.Listen(conf.listen)
    337336}
  • trunk/cmd/mai/parseflags.go

    r67 r71  
    88func parseFlags() {
    99        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")
    1211        flag.Parse()
    1312}
  • trunk/cmd/mai/readconf.go

    r70 r71  
    1111                return err                                             
    1212        }
    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()
    1713
     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()
    1820        return nil
    1921}
  • trunk/example/mai.ini

    r67 r71  
     1[http]
     2# TCP socket to listen on.
     3# Must not be already used by something else.
     4listen = 127.0.0.1:5000
     5# How many requests per minute are allowed
     6# before a rate-limit happens.
     7requests = 10
    18[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
     17static = ./static
     18# Where to locate the pages to be served
     19templates = ./views
  • trunk/example/mai.nginx

    r68 r71  
    22    listen 80;
    33    listen [::]:80;
    4     server_name mai.example.com;
     4    server_name mai.example.org;
    55
    66    location / {
     
    1212    listen 443 ssl;
    1313    listen [::]:443 ssl;
    14     server_name mai.example.com;
     14    server_name mai.example.org;
    1515
    1616    ssl_certificate /path/to/fullchain.pem;
  • trunk/go.mod

    r70 r71  
    1 module marisa.chaotic.ninja/mai
     1module mahou-no-mori.yakumo.dev/mai
    22
    33go 1.20
  • trunk/rc.d/FreeBSD

    r67 r71  
    11#!/bin/sh
    2 # $TheSupernovaDuo$
     2# $YakumoLabs$
    33#
    44# PROVIDE: mai
  • trunk/rc.d/NetBSD

    r67 r71  
    11#!/bin/sh
    2 # $TheSupernovaDuo$
     2# $YakumoLabs$
    33#
    44# PROVIDE: mai
    55# REQUIRE: NETWORKING DAEMON
    6 # BEFORE: LOGIN
    7 # KEYWORD: shutdown
    86
    97$_rc_subr_loaded . /etc/rc.subr
     
    119name="mai"
    1210rcvar=$name
    13 command="/usr/pkg/bin/mai"
    14 command_args="-f /usr/pkg/etc/mai/mai.ini -u www -g www"
     11command="/usr/local/bin/mai"
     12command_args="-f /usr/local/etc/mai/mai.ini"
    1513pidfile="/var/run/${name}.pid"
    1614start_cmd="mai_start"
    1715
    18 required_files="/usr/pkg/etc/mai/mai.ini"
     16required_files="/usr/local/etc/mai/mai.ini"
    1917
    2018mai_start() {
  • trunk/rc.d/OpenBSD

    r67 r71  
    11#!/bin/ksh
    2 # $TheSupernovaDuo$
     2# $YakumoLabs$
    33
    44daemon="/usr/local/bin/mai"
    5 daemon_flags="-f /usr/local/etc/mai/mai.ini -u www -g www"
     5daemon_flags="-f /usr/local/etc/mai/mai.ini"
    66
    77. /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$
     2cmd: /usr/local/bin/mai -f /usr/local/etc/mai/mai.ini
    23cwd: /usr/local/share/mai
  • trunk/version.go

    r63 r71  
    88        // Version release version
    99        Version = "0.0.1"
    10 
    11         // Commit will be overwritten automatically by the build system
    12         Commit = "HEAD"
    1310)
    1411
    1512// FullVersion display the full version and build
    1613func FullVersion() string {
    17         return fmt.Sprintf("%s@%s", Version, Commit)
     14        return fmt.Sprintf("%s", Version)
    1815}
Note: See TracChangeset for help on using the changeset viewer.