This commit is contained in:
kayos@tcp.direct 2021-11-14 14:06:15 -08:00
parent 2d058ff892
commit 9ec5c96045
6 changed files with 18 additions and 23 deletions

View File

@ -3,7 +3,7 @@ package config
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"runtime"
"strconv"
@ -34,7 +34,7 @@ func writeConfig() {
}
if _, err := os.Stat(prefConfigLocation); os.IsNotExist(err) {
if err = os.MkdirAll(prefConfigLocation, 0755); err != nil {
if err = os.MkdirAll(prefConfigLocation, 0o755); err != nil {
println("error writing new config: " + err.Error())
os.Exit(1)
}
@ -136,11 +136,8 @@ func setConfigFileLocations() {
configLocations = append(configLocations, "./")
if runtime.GOOS != "windows" {
configLocations = append(configLocations, prefConfigLocation)
configLocations = append(configLocations, "/etc/"+Title+"/")
configLocations = append(configLocations, "../")
configLocations = append(configLocations, "../../")
configLocations = append(configLocations,
prefConfigLocation, "/etc/"+Title+"/", "../", "../../")
}
}
@ -149,7 +146,7 @@ func loadCustomConfig(path string) {
println("Error opening specified config file: " + path)
panic("config file open fatal error: " + err.Error())
}
buf, err := ioutil.ReadAll(f)
buf, err := io.ReadAll(f)
err2 := snek.ReadConfig(bytes.NewBuffer(buf))
switch {
case err != nil:
@ -183,9 +180,7 @@ func argParse() {
noColorForce = true
case "--banner":
BannerOnly = true
case "--config":
fallthrough
case "-c":
case "-c", "--config":
if len(os.Args) <= i-1 {
panic("syntax error! expected file after -c")
}

View File

@ -21,7 +21,7 @@ var (
func StartLogger() zerolog.Logger {
logDir = snek.GetString("logger.directory")
if !strings.HasSuffix(logDir, "/") {
logDir = logDir + "/"
logDir += "/"
}
if err := os.MkdirAll(logDir, os.ModePerm); err != nil {
println("cannot create log directory: " + logDir + "(" + err.Error() + ")")
@ -31,14 +31,14 @@ func StartLogger() zerolog.Logger {
logFileName := "HellPot"
if snek.GetBool("logger.use_date_filename") {
tn := strings.Replace(time.Now().Format(time.RFC822), " ", "_", -1)
tn = strings.Replace(logFileName, ":", "-", -1)
tn := strings.ReplaceAll(time.Now().Format(time.RFC822), " ", "_")
tn = strings.ReplaceAll(logFileName, ":", "-")
logFileName = logFileName + "_" + tn
}
CurrentLogFile = logDir + logFileName + ".log"
if logFile, err = os.OpenFile(CurrentLogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666); err != nil {
if logFile, err = os.OpenFile(CurrentLogFile, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666); err != nil {
println("cannot create log file: " + err.Error())
os.Exit(1)
}

View File

@ -7,7 +7,7 @@ import (
"encoding/base64"
"encoding/binary"
"fmt"
"io/ioutil"
"io"
"strings"
"github.com/yunginnanet/HellPot/config"
@ -43,13 +43,13 @@ func process(in string) (s string) {
for n := 1; n < 5; n++ {
s = cproc(s, fmt.Sprintf("%d", n))
}
s = strings.Replace(s, "$maj", maj, -1)
s = strings.Replace(s, "$min", min, -1)
s = strings.ReplaceAll(s, "$maj", maj)
s = strings.ReplaceAll(s, "$min", min)
return
}
func gz(data []byte) string {
gz, err1 := gzip.NewReader(bytes.NewReader(data))
out, err2 := ioutil.ReadAll(gz)
out, err2 := io.ReadAll(gz)
if err1 != nil || err2 != nil {
bannerFail(err1, err2)
}

View File

@ -62,7 +62,7 @@ func (h *Heffalump) WriteHell(bw *bufio.Writer) (int64, error) {
buf := h.getBuffer()
defer h.putBuffer(buf)
if _, err = io.WriteString(bw, "<HTML>\n<BODY>\n"); err != nil {
if _, err = bw.WriteString("<HTML>\n<BODY>\n"); err != nil {
return n, err
}

View File

@ -4,7 +4,7 @@ import (
"bytes"
"compress/gzip"
"encoding/base64"
"io/ioutil"
"io"
)
func gz(data []byte) string {
@ -12,7 +12,7 @@ func gz(data []byte) string {
if err != nil {
panic(err)
}
out, err := ioutil.ReadAll(gz)
out, err := io.ReadAll(gz)
if err != nil {
panic(err)
}

View File

@ -24,7 +24,7 @@ func listenOnUnixSocket(addr string, r *router.Router) error {
_ = syscall.Unlink(addr)
// Before we set socket permissions, we want to make sure only the user HellPot is running under
// has permission to the socket.
oldmask := syscall.Umask(0077)
oldmask := syscall.Umask(0o077)
unixListener, err = net.ListenUnix("unix", unixAddr)
syscall.Umask(oldmask)
if err == nil {