Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new command doctor to check if some wrong configurations on gitea instance #9095

Merged
merged 5 commits into from
Jan 11, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use regex match authorized_keys on doctor
  • Loading branch information
lunny committed Jan 11, 2020
commit a4c12358c23112cdc2792ca07ddeeb3ce00aab9f
51 changes: 28 additions & 23 deletions cmd/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"

"code.gitea.io/gitea/modules/setting"
Expand All @@ -32,14 +33,18 @@ type check struct {

var checklist = []check{
{
title: "Check if openssh authorized_keys file correct",
title: "Check if openssh authorized_keys file id correct",
f: runDoctorLocationMoved,
},
}

func runDoctor(ctx *cli.Context) error {
if err := initDB(); err != nil {
return err
err := initDB()
fmt.Println("Using app.ini at ", setting.CustomConf)
if err != nil {
fmt.Println(err)
fmt.Println("Check if you are using the right config file. You can use a --config directive to specify one.")
return nil
}

for i, check := range checklist {
Expand Down Expand Up @@ -90,28 +95,28 @@ func runDoctorLocationMoved(ctx *cli.Context) ([]string, error) {

// command="/Volumes/data/Projects/gitea/gitea/gitea --config
if len(firstline) > 0 {
lunny marked this conversation as resolved.
Show resolved Hide resolved
var start, end int
for i, c := range firstline {
if c == ' ' {
end = i
break
} else if c == '"' {
start = i + 1
}
exp := regexp.MustCompile(`^[ \t]*(?:command=")([^ ]+) --config='([^']+)' serv key-([^"]+)",(?:[^ ]+) ssh-rsa ([^ ]+) ([^ ]+)[ \t]*$`)

// command="/home/user/gitea --config='/home/user/etc/app.ini' serv key-999",option-1,option-2,option-n ssh-rsa public-key-value key-name
res := exp.FindAllStringSubmatch(firstline, -1)

giteaPath := res[1] // => /home/user/gitea
iniPath := res[2] // => /home/user/etc/app.ini

p, err := exePath()
if err != nil {
return nil, err
}
p, err = filepath.Abs(p)
if err != nil {
return nil, err
}
if start > 0 && end > 0 {
p, err := exePath()
if err != nil {
return nil, err
}
p, err = filepath.Abs(p)
if err != nil {
return nil, err
}

if firstline[start:end] != p {
return []string{fmt.Sprintf("Wants %s but %s on %s", p, firstline[start:end], fPath)}, nil
}
if len(giteaPath) > 0 && giteaPath[0] != p {
return []string{fmt.Sprintf("Gitea exe path wants %s but %s on %s", p, giteaPath[0], fPath)}, nil
}
if len(iniPath) > 0 && iniPath[0] != setting.CustomConf {
return []string{fmt.Sprintf("Gitea config path wants %s but %s on %s", setting.CustomConf, iniPath[0], fPath)}, nil
}
}

Expand Down