mirror of
				https://github.com/osmarks/mycorrhiza.git
				synced 2025-11-04 09:33:01 +00:00 
			
		
		
		
	@@ -37,8 +37,8 @@ var (
 | 
			
		||||
 | 
			
		||||
// These variables are set before reading the config file, they are set in main.parseCliArgs.
 | 
			
		||||
var (
 | 
			
		||||
	// WikiGitDir is a full path to the wiki storage directory, which also must be a git repo.
 | 
			
		||||
	WikiGitDir string
 | 
			
		||||
	// WikiDir is a full path to the wiki storage directory, which also must be a git repo.
 | 
			
		||||
	WikiDir string
 | 
			
		||||
	// ConfigFilePath is a path to the config file. Its value is used when calling ReadConfigFile.
 | 
			
		||||
	ConfigFilePath string
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -61,7 +61,7 @@ func tokenStoragePath() (string, error) {
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "", err
 | 
			
		||||
	}
 | 
			
		||||
	if strings.HasPrefix(dir, cfg.WikiGitDir) {
 | 
			
		||||
	if strings.HasPrefix(dir, cfg.WikiDir) {
 | 
			
		||||
		return "", errors.New("wiki storage directory includes private config files")
 | 
			
		||||
	}
 | 
			
		||||
	return dir, nil
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								flag.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								flag.go
									
									
									
									
									
								
							@@ -51,7 +51,7 @@ func parseCliArgs() {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	wikiDir, err := filepath.Abs(args[0])
 | 
			
		||||
	cfg.WikiGitDir = wikiDir
 | 
			
		||||
	cfg.WikiDir = wikiDir
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -162,7 +162,7 @@ func (rev *Revision) bestLink() string {
 | 
			
		||||
func gitsh(args ...string) (out bytes.Buffer, err error) {
 | 
			
		||||
	fmt.Printf("$ %v\n", args)
 | 
			
		||||
	cmd := exec.Command(gitpath, args...)
 | 
			
		||||
	cmd.Dir = cfg.WikiGitDir
 | 
			
		||||
	cmd.Dir = cfg.WikiDir
 | 
			
		||||
	cmd.Env = gitEnv
 | 
			
		||||
 | 
			
		||||
	b, err := cmd.CombinedOutput()
 | 
			
		||||
@@ -175,7 +175,7 @@ func gitsh(args ...string) (out bytes.Buffer, err error) {
 | 
			
		||||
// silentGitsh is like gitsh, except it writes less to the stdout.
 | 
			
		||||
func silentGitsh(args ...string) (out bytes.Buffer, err error) {
 | 
			
		||||
	cmd := exec.Command(gitpath, args...)
 | 
			
		||||
	cmd.Dir = cfg.WikiGitDir
 | 
			
		||||
	cmd.Dir = cfg.WikiDir
 | 
			
		||||
	cmd.Env = gitEnv
 | 
			
		||||
 | 
			
		||||
	b, err := cmd.CombinedOutput()
 | 
			
		||||
 
 | 
			
		||||
@@ -176,7 +176,7 @@ func parseRevisionLine(line string) Revision {
 | 
			
		||||
 | 
			
		||||
// FileAtRevision shows how the file with the given file path looked at the commit with the hash. It may return an error if git fails.
 | 
			
		||||
func FileAtRevision(filepath, hash string) (string, error) {
 | 
			
		||||
	out, err := gitsh("show", hash+":"+strings.TrimPrefix(filepath, cfg.WikiGitDir+"/"))
 | 
			
		||||
	out, err := gitsh("show", hash+":"+strings.TrimPrefix(filepath, cfg.WikiDir+"/"))
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "", err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								main.go
									
									
									
									
									
								
							@@ -30,19 +30,19 @@ func main() {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	log.Println("Running Mycorrhiza Wiki 1.2.0 indev")
 | 
			
		||||
	if err := os.Chdir(cfg.WikiGitDir); err != nil {
 | 
			
		||||
	if err := os.Chdir(cfg.WikiDir); err != nil {
 | 
			
		||||
		log.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	log.Println("Wiki storage directory is", cfg.WikiGitDir)
 | 
			
		||||
	log.Println("Wiki storage directory is", cfg.WikiDir)
 | 
			
		||||
 | 
			
		||||
	// Init the subsystems:
 | 
			
		||||
	hyphae.Index(cfg.WikiGitDir)
 | 
			
		||||
	hyphae.Index(cfg.WikiDir)
 | 
			
		||||
	user.InitUserDatabase()
 | 
			
		||||
	history.Start()
 | 
			
		||||
	shroom.SetHeaderLinks()
 | 
			
		||||
 | 
			
		||||
	// Static files:
 | 
			
		||||
	static.InitFS(cfg.WikiGitDir + "/static")
 | 
			
		||||
	static.InitFS(cfg.WikiDir + "/static")
 | 
			
		||||
 | 
			
		||||
	// Network:
 | 
			
		||||
	go handleGemini()
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,6 @@ package shroom
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/bouncepaw/mycorrhiza/cfg"
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"log"
 | 
			
		||||
	"mime/multipart"
 | 
			
		||||
@@ -11,6 +10,8 @@ import (
 | 
			
		||||
	"path/filepath"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/bouncepaw/mycorrhiza/cfg"
 | 
			
		||||
 | 
			
		||||
	"github.com/bouncepaw/mycorrhiza/history"
 | 
			
		||||
	"github.com/bouncepaw/mycorrhiza/hyphae"
 | 
			
		||||
	"github.com/bouncepaw/mycorrhiza/mimetype"
 | 
			
		||||
@@ -64,10 +65,10 @@ func UploadBinary(h *hyphae.Hypha, mime string, file multipart.File, u *user.Use
 | 
			
		||||
// uploadHelp is a helper function for UploadText and UploadBinary
 | 
			
		||||
func uploadHelp(h *hyphae.Hypha, hop *history.HistoryOp, ext string, data []byte, u *user.User) (*history.HistoryOp, string) {
 | 
			
		||||
	var (
 | 
			
		||||
		fullPath         = filepath.Join(cfg.WikiGitDir, h.Name+ext)
 | 
			
		||||
		fullPath         = filepath.Join(cfg.WikiDir, h.Name+ext)
 | 
			
		||||
		originalFullPath = &h.TextPath
 | 
			
		||||
	)
 | 
			
		||||
	if !strings.HasPrefix(fullPath, cfg.WikiGitDir) { // If the path somehow got outside the wiki dir
 | 
			
		||||
	if !strings.HasPrefix(fullPath, cfg.WikiDir) { // If the path somehow got outside the wiki dir
 | 
			
		||||
		err := errors.New("bad path")
 | 
			
		||||
		return hop.WithErrAbort(err), err.Error()
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								util/util.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								util/util.go
									
									
									
									
									
								
							@@ -3,12 +3,13 @@ package util
 | 
			
		||||
import (
 | 
			
		||||
	"crypto/rand"
 | 
			
		||||
	"encoding/hex"
 | 
			
		||||
	"github.com/bouncepaw/mycomarkup/util"
 | 
			
		||||
	"github.com/bouncepaw/mycorrhiza/cfg"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net/http"
 | 
			
		||||
	"regexp"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/bouncepaw/mycomarkup/util"
 | 
			
		||||
	"github.com/bouncepaw/mycorrhiza/cfg"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// PrepareRq strips the trailing / in rq.URL.Path. In the future it might do more stuff for making all request structs uniform.
 | 
			
		||||
@@ -16,10 +17,10 @@ func PrepareRq(rq *http.Request) {
 | 
			
		||||
	rq.URL.Path = strings.TrimSuffix(rq.URL.Path, "/")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ShorterPath is used by handlerList to display shorter path to the files. It simply strips WikiGitDir.
 | 
			
		||||
// ShorterPath is used by handlerList to display shorter path to the files. It simply strips WikiDir.
 | 
			
		||||
func ShorterPath(path string) string {
 | 
			
		||||
	if strings.HasPrefix(path, cfg.WikiGitDir) {
 | 
			
		||||
		tmp := strings.TrimPrefix(path, cfg.WikiGitDir)
 | 
			
		||||
	if strings.HasPrefix(path, cfg.WikiDir) {
 | 
			
		||||
		tmp := strings.TrimPrefix(path, cfg.WikiDir)
 | 
			
		||||
		if tmp == "" {
 | 
			
		||||
			return ""
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -41,9 +41,9 @@ func handlerReindex(w http.ResponseWriter, rq *http.Request) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	hyphae.ResetCount()
 | 
			
		||||
	log.Println("Wiki storage directory is", cfg.WikiGitDir)
 | 
			
		||||
	log.Println("Wiki storage directory is", cfg.WikiDir)
 | 
			
		||||
	log.Println("Start indexing hyphae...")
 | 
			
		||||
	hyphae.Index(cfg.WikiGitDir)
 | 
			
		||||
	hyphae.Index(cfg.WikiDir)
 | 
			
		||||
	log.Println("Indexed", hyphae.Count(), "hyphae")
 | 
			
		||||
	http.Redirect(w, rq, "/", http.StatusSeeOther)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user