all repos

mugit @ c8261120f46661cba86861f09889fea875ee4395

馃惍 git server that your cow will love
5 files changed, 22 insertions(+), 6 deletions(-)
support custom ssh user name (for future switch to ssh)
Author: Oleksandr Smirnov olexsmir@gmail.com
Committed at: 2026-03-05 21:09:09 +0200
Authored at: 2026-03-05 21:08:14 +0200
Change ID: usyrorzswltynllxvoxsvlxlporxyyuv
Parent: 9d3f4dd
M README.md
路路路
        89
        89
         ssh:

      
        90
        90
           enable: true

      
        91
        91
           port: 2222  # SSH port (default 2222)

      
        
        92
        +  user: "git" # user as which the app operates (default "git")

      
        92
        93
           host_key: /var/lib/mugit/host   # path to SSH host key (generate with ssh-keygen)

      
        93
        94
           # Only these public keys can access private repos and push to others.

      
        94
        95
           keys:

      
M internal/config/config.go
路路路
        36
        36
         

      
        37
        37
         type SSHConfig struct {

      
        38
        38
         	Enable  bool     `yaml:"enable"`

      
        
        39
        +	User    string   `yaml:"user"`

      
        39
        40
         	Port    int      `yaml:"port"`

      
        40
        41
         	HostKey string   `yaml:"host_key"`

      
        41
        42
         	Keys    []string `yaml:"keys"`

      路路路
        117
        118
         }

      
        118
        119
         

      
        119
        120
         func (c *Config) ensureDefaults() {

      
        120
        
        -	// ports

      
        
        121
        +	// http

      
        121
        122
         	if c.Server.Port == 0 {

      
        122
        123
         		c.Server.Port = 8080

      
        123
        
        -	}

      
        124
        
        -

      
        125
        
        -	if c.SSH.Port == 0 {

      
        126
        
        -		c.SSH.Port = 2222

      
        127
        124
         	}

      
        128
        125
         

      
        129
        126
         	// meta

      路路路
        143
        140
         			"README.txt", "readme.txt",

      
        144
        141
         			"readme",

      
        145
        142
         		}

      
        
        143
        +	}

      
        
        144
        +

      
        
        145
        +	// ssh

      
        
        146
        +	if c.SSH.Port == 0 {

      
        
        147
        +		c.SSH.Port = 2222

      
        
        148
        +	}

      
        
        149
        +

      
        
        150
        +	if c.SSH.User == "" {

      
        
        151
        +		c.SSH.User = "git"

      
        146
        152
         	}

      
        147
        153
         

      
        148
        154
         	// mirroring

      
M internal/config/validate.go
路路路
        3
        3
         import (

      
        4
        4
         	"errors"

      
        5
        5
         	"fmt"

      
        
        6
        +	"regexp"

      
        6
        7
         	"strings"

      
        7
        8
         )

      
        
        9
        +

      
        
        10
        +var validUserNameRe = regexp.MustCompile("^[a-z_][a-z0-9_-]{0,31}$")

      
        8
        11
         

      
        9
        12
         func (c Config) validate() error {

      
        10
        13
         	var errs []error

      路路路
        32
        35
         

      
        33
        36
         		if c.SSH.Port == c.Server.Port {

      
        34
        37
         			errs = append(errs, fmt.Errorf("ssh.port must differ from server.port (both are %d)", c.Server.Port))

      
        
        38
        +		}

      
        
        39
        +

      
        
        40
        +		if !validUserNameRe.MatchString(c.SSH.User) {

      
        
        41
        +			errs = append(errs, fmt.Errorf("ssh.user must be correct linux user name(^[a-z_][a-z0-9_-]{0,31}$)"))

      
        35
        42
         		}

      
        36
        43
         

      
        37
        44
         		if !isFileExists(c.SSH.HostKey) {

      
M internal/handlers/repo.go
路路路
        50
        50
         

      
        51
        51
         type RepoIndex struct {

      
        52
        52
         	Desc           string

      
        
        53
        +	SSHUser        string

      
        53
        54
         	IsEmpty        bool

      
        54
        55
         	Readme         template.HTML

      
        55
        56
         	Ref            string

      路路路
        106
        107
         		p.MirrorLastSync, _ = repo.LastSync()

      
        107
        108
         	}

      
        108
        109
         

      
        
        110
        +	p.SSHUser = h.c.SSH.User

      
        109
        111
         	h.templ(w, "repo_index", h.pageData(repo, p))

      
        110
        112
         }

      
        111
        113
         

      
M web/templates/repo_index.html
路路路
        35
        35
                 <div class="repo-index-side">

      
        36
        36
                   <h2>Clone urls</h2>

      
        37
        37
                   <pre>https://{{.Meta.Host}}/{{.RepoName}}</pre>

      
        38
        
        -          {{ if .Meta.SSHEnabled }}<pre>git@{{.Meta.Host}}:{{.RepoName}}</pre>{{end}}

      
        
        38
        +          {{ if .Meta.SSHEnabled }}<pre>{{ .P.SSHUser }}@{{.Meta.Host}}:{{.RepoName}}</pre>{{end}}

      
        39
        39
                   {{- if .P.IsMirror -}}

      
        40
        40
                   <br>

      
        41
        41
                   <h2>Mirror status</h2>