forked from solderpunk/molly-brown
Run gofmt on everything for the first time ever!
This commit is contained in:
parent
3e80488f92
commit
b0b18971f4
10
dynamic.go
10
dynamic.go
|
@ -22,9 +22,9 @@ func handleCGI(config Config, path string, URL *url.URL, log *LogEntry, conn net
|
|||
|
||||
// Set environment variables
|
||||
vars := prepareCGIVariables(config, URL, conn, path)
|
||||
cmd.Env = []string{ }
|
||||
cmd.Env = []string{}
|
||||
for key, value := range vars {
|
||||
cmd.Env = append(cmd.Env, key + "=" + value)
|
||||
cmd.Env = append(cmd.Env, key+"="+value)
|
||||
}
|
||||
|
||||
response, err := cmd.Output()
|
||||
|
@ -65,13 +65,13 @@ func handleSCGI(socket_path string, config Config, URL *url.URL, log *LogEntry,
|
|||
// Send variables
|
||||
vars := prepareSCGIVariables(config, URL, conn)
|
||||
length := 0
|
||||
for key, value := range(vars) {
|
||||
for key, value := range vars {
|
||||
length += len(key)
|
||||
length += len(value)
|
||||
length += 2
|
||||
}
|
||||
socket.Write([]byte(strconv.Itoa(length) + ":"))
|
||||
for key, value := range(vars) {
|
||||
for key, value := range vars {
|
||||
socket.Write([]byte(key + "\x00"))
|
||||
socket.Write([]byte(value + "\x00"))
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ func prepareGatewayVariables(config Config, URL *url.URL, conn net.Conn) map[str
|
|||
// Add TLS variables
|
||||
var tlsConn (*tls.Conn) = conn.(*tls.Conn)
|
||||
connState := tlsConn.ConnectionState()
|
||||
// vars["TLS_CIPHER"] = CipherSuiteName(connState.CipherSuite)
|
||||
// vars["TLS_CIPHER"] = CipherSuiteName(connState.CipherSuite)
|
||||
|
||||
// Add client cert variables
|
||||
clientCerts := connState.PeerCertificates
|
||||
|
|
31
handler.go
31
handler.go
|
@ -5,6 +5,7 @@ import (
|
|||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/BurntSushi/toml"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"mime"
|
||||
|
@ -15,7 +16,6 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry) {
|
||||
|
@ -127,7 +127,7 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
|
|||
}
|
||||
|
||||
// Don't serve Molly files
|
||||
if ! info.IsDir() && filepath.Base(path) == ".molly" {
|
||||
if !info.IsDir() && filepath.Base(path) == ".molly" {
|
||||
conn.Write([]byte("51 Not found!\r\n"))
|
||||
log.Status = 51
|
||||
return
|
||||
|
@ -146,7 +146,7 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
|
|||
return
|
||||
}
|
||||
// Check for index.gmi if path is a directory
|
||||
index_path := filepath.Join(path, "index." + config.GeminiExt)
|
||||
index_path := filepath.Join(path, "index."+config.GeminiExt)
|
||||
index_info, err := os.Stat(index_path)
|
||||
if err == nil && uint64(index_info.Mode().Perm())&0444 == 0444 {
|
||||
serveFile(index_path, &log, conn, config)
|
||||
|
@ -160,8 +160,8 @@ func handleGeminiRequest(conn net.Conn, config Config, logEntries chan LogEntry)
|
|||
}
|
||||
|
||||
// If this file is executable, get dynamic content
|
||||
if info.Mode().Perm() & 0111 == 0111 {
|
||||
for _, cgiPath := range(config.CGIPaths) {
|
||||
if info.Mode().Perm()&0111 == 0111 {
|
||||
for _, cgiPath := range config.CGIPaths {
|
||||
inCGIPath, err := regexp.Match(cgiPath, []byte(path))
|
||||
if err == nil && inCGIPath {
|
||||
handleCGI(config, path, URL, &log, conn)
|
||||
|
@ -228,7 +228,7 @@ func resolvePath(path string, config Config) (string, os.FileInfo, error) {
|
|||
func parseMollyFiles(path string, info os.FileInfo, config *Config) {
|
||||
// Build list of directories to check
|
||||
dirs := make([]string, 16)
|
||||
if ! info.IsDir() {
|
||||
if !info.IsDir() {
|
||||
path = filepath.Dir(path)
|
||||
}
|
||||
dirs = append(dirs, path)
|
||||
|
@ -242,7 +242,7 @@ func parseMollyFiles(path string, info os.FileInfo, config *Config) {
|
|||
}
|
||||
// Parse files
|
||||
var mollyFile MollyFile
|
||||
for i := len(dirs)-1; i >= 0; i-- {
|
||||
for i := len(dirs) - 1; i >= 0; i-- {
|
||||
dir := dirs[i]
|
||||
mollyPath := filepath.Join(dir, ".molly")
|
||||
_, err := os.Stat(mollyPath)
|
||||
|
@ -299,13 +299,13 @@ func generatePrettyFileLabel(info os.FileInfo) string {
|
|||
} else if info.Size() < 1024 {
|
||||
size = fmt.Sprintf("%4d B", info.Size())
|
||||
} else if info.Size() < (1024 << 10) {
|
||||
size = fmt.Sprintf("%4d KiB", info.Size() >> 10)
|
||||
} else if info.Size() < 1024 << 20 {
|
||||
size = fmt.Sprintf("%4d MiB", info.Size() >> 20)
|
||||
} else if info.Size() < 1024 << 30 {
|
||||
size = fmt.Sprintf("%4d GiB", info.Size() >> 30)
|
||||
} else if info.Size() < 1024 << 40 {
|
||||
size = fmt.Sprintf("%4d TiB", info.Size() >> 40)
|
||||
size = fmt.Sprintf("%4d KiB", info.Size()>>10)
|
||||
} else if info.Size() < 1024<<20 {
|
||||
size = fmt.Sprintf("%4d MiB", info.Size()>>20)
|
||||
} else if info.Size() < 1024<<30 {
|
||||
size = fmt.Sprintf("%4d GiB", info.Size()>>30)
|
||||
} else if info.Size() < 1024<<40 {
|
||||
size = fmt.Sprintf("%4d TiB", info.Size()>>40)
|
||||
} else {
|
||||
size = "GIGANTIC"
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config) {
|
|||
// Get MIME type of files
|
||||
ext := filepath.Ext(path)
|
||||
var mimeType string
|
||||
if ext == "." + config.GeminiExt {
|
||||
if ext == "."+config.GeminiExt {
|
||||
mimeType = "text/gemini"
|
||||
} else {
|
||||
mimeType = mime.TypeByExtension(ext)
|
||||
|
@ -349,4 +349,3 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config) {
|
|||
log.Status = 20
|
||||
conn.Write(contents)
|
||||
}
|
||||
|
||||
|
|
6
main.go
6
main.go
|
@ -44,7 +44,7 @@ func main() {
|
|||
}
|
||||
|
||||
// Create TLS listener
|
||||
listener, err := tls.Listen("tcp", ":" + strconv.Itoa(config.Port), tlscfg)
|
||||
listener, err := tls.Listen("tcp", ":"+strconv.Itoa(config.Port), tlscfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -52,9 +52,9 @@ func main() {
|
|||
|
||||
// Start log handling routine
|
||||
logEntries := make(chan LogEntry, 10)
|
||||
go func () {
|
||||
go func() {
|
||||
for {
|
||||
entry := <- logEntries
|
||||
entry := <-logEntries
|
||||
writeLogEntry(logfile, entry)
|
||||
}
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue