Skip to content

Commit

Permalink
Add: Windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
yunginnanet committed Sep 15, 2021
1 parent 010392b commit d248ca2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
56 changes: 45 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"fmt"
"io/ioutil"
"os"
"runtime"

"github.com/rs/zerolog"
"github.com/spf13/viper"
)

const (
version = "0.2"
title = "HellPot"
Version = "0.2"
Title = "HellPot"
)

var (
Expand All @@ -34,6 +35,7 @@ var (
f *os.File
err error

NoColor bool
customconfig = false
home string
configLocations []string
Expand All @@ -58,7 +60,7 @@ func init() {
if home, err = os.UserHomeDir(); err != nil {
panic(err)
}
prefConfigLocation = home + "/.config/" + title
prefConfigLocation = home + "/.config/" + Title
Opt = make(map[string]map[string]interface{})
snek = viper.New()
}
Expand All @@ -83,10 +85,10 @@ func Init() {
snek.AddConfigPath(loc)
}

if err = snek.MergeInConfig(); err != nil {
if err = snek.MergeInConfig(); err != nil && runtime.GOOS != "windows" {
if _, err := os.Stat(prefConfigLocation); os.IsNotExist(err) {
if err = os.Mkdir(prefConfigLocation, 0755); err != nil {
panic(err)
println("error writing new config: " + err.Error())
}
}

Expand All @@ -100,6 +102,19 @@ func Init() {
Filename = newconfig
}

if runtime.GOOS == "windows" {
newconfig := "hellpot-config"
snek.SetConfigName(newconfig)
if err = snek.MergeInConfig(); err != nil {
if err = snek.SafeWriteConfigAs(newconfig + ".toml"); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}

Filename = newconfig
}

if len(Filename) < 1 {
Filename = snek.ConfigFileUsed()
}
Expand All @@ -108,11 +123,21 @@ func Init() {
}

func setDefaults() {
var configSections = []string{"logger", "http"}
var (
configSections = []string{"logger", "http"}
deflogdir = home + "/.config/" + Title + "/logs/"
defNoColor = false
)

if runtime.GOOS == "windows" {
deflogdir = "logs/"
defNoColor = true
}

Opt["logger"] = map[string]interface{}{
"debug": true,
"directory": home + "/.config/" + title + "/logs/",
"directory": deflogdir,
"nocolor": defNoColor,
"use_date_filename": true,
}
Opt["http"] = map[string]interface{}{
Expand All @@ -130,11 +155,14 @@ func setDefaults() {
}

func acquireClue() {
configLocations = append(configLocations, prefConfigLocation)
configLocations = append(configLocations, "/etc/"+title+"/")
configLocations = append(configLocations, "./")
configLocations = append(configLocations, "../")
configLocations = append(configLocations, "../../")

if runtime.GOOS != "windows" {
configLocations = append(configLocations, prefConfigLocation)
configLocations = append(configLocations, "/etc/"+Title+"/")
configLocations = append(configLocations, "../")
configLocations = append(configLocations, "../../")
}
}

func loadCustomConfig(path string) {
Expand All @@ -159,6 +187,11 @@ func loadCustomConfig(path string) {
func argParse() {
for i, arg := range os.Args {
switch arg {
case "-h":
println("HellPot: use -c <file.toml> to specify config file.")
os.Exit(0)
case "--config":
fallthrough
case "-c":
if len(os.Args) <= i-1 {
panic("syntax error! expected file after -c")
Expand All @@ -184,6 +217,7 @@ func associate() {
Opt = newOpt
Debug = snek.GetBool("logger.debug")
logDir = snek.GetString("logger.directory")
NoColor = snek.GetBool("logger.nocolor")
BindAddr = snek.GetString("http.bind_addr")
BindPort = snek.GetString("http.bind_port")
Paths = snek.GetStringSlice("http.paths")
Expand Down
6 changes: 4 additions & 2 deletions config/logger.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package config

import (
"github.com/rs/zerolog"
"os"
"strings"
"time"

"github.com/rs/zerolog"
)

var (
Expand Down Expand Up @@ -34,6 +35,7 @@ func Logger() zerolog.Logger {
println("cannot create log file: " + err.Error())
os.Exit(1)
}
multi := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{Out: os.Stderr}, logFile)

multi := zerolog.MultiLevelWriter(zerolog.ConsoleWriter{NoColor: NoColor, Out: os.Stdout}, logFile)
return zerolog.New(multi).With().Timestamp().Logger()
}
9 changes: 9 additions & 0 deletions extra/decorate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import (
"bufio"
"encoding/base64"
"fmt"
"runtime"
"strings"

"github.com/yunginnanet/HellPot/config"
)

const banner = "ChtbOTc7NDBtIBtbOTc7NDNt4paEG1szMzs0MG3ilojilpIbWzk3OzQwbSAbWzMzOzQwbeKWiOKWiBtbMzc7NDBtIBtbMG0bWzBtICAbWzMzOzQwbeKWkxtbOTc7NDNtIOKWhOKWhBtbMzM7NDBt4paI4paIG1szNzs0MG0gG1swbRtbMG0gIBtbOTc7NDBtIBtbMzM7NDBt4paI4paI4paTG1szNzs0MG0gICAgG1swbRtbMG0gIBtbOTc7NDBtIBtbMzM7NDBt4paI4paI4paTG1szNzs0MG0gICAgG1swbRtbMG0gIBtbOTc7NDBtIBtbMzM7NDBt4paI4paI4paS4paI4paI4paIG1szNzs0MG0gIBtbMG0bWzBtICAbWzk3OzQwbSAbWzMzOzQwbeKWk+KWiBtbOTc7NDNt4paE4paEG1szMzs0MG3ilojilogbWzM3OzQwbSAgG1swbRtbMG0gIBtbMzM7NDBt4paE4paE4paE4paIG1s5Nzs0M23iloQbWzMzOzQwbeKWiOKWiOKWiOKWkxtbMG0bWzBtICAbWzBtChtbMzM7NDBt4paTG1s5Nzs0M23ilogbWzMzOzQwbeKWiOKWkRtbOTc7NDBtIBtbMzM7NDBt4paIG1s5Nzs0M23iloQbWzMzOzQwbeKWkhtbMG0bWzBtICAbWzMzOzQwbeKWkxtbOTc7NDNt4paIIBtbOTc7NDBtICAbWzMzOzQwbeKWgBtbMzc7NDBtIBtbMG0bWzBtICAbWzMzOzQwbeKWk+KWiOKWiOKWkhtbMzc7NDBtICAgIBtbMG0bWzBtICAbWzMzOzQwbeKWk+KWiOKWiOKWkhtbMzc7NDBtICAgIBtbMG0bWzBtICAbWzMzOzQwbeKWkxtbOTc7NDNt4paIG1szMzs0MG3ilojilpEbWzk3OzQwbSAbWzMzOzQwbSDilojilojilpMbWzBtG1swbSAgG1szMzs0MG3ilpPilogbWzk3OzQzbeKWiBtbMzM7NDBt4paSG1s5Nzs0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1swbSAgG1swbQoK"
Expand All @@ -21,6 +24,12 @@ const banner = "ChtbOTc7NDBtIBtbOTc7NDNt4paEG1szMzs0MG3ilojilpIbWzk3OzQwbSAbWzMz
and just fmt.Println(dec) to print the banner without additional styling
*/
func Banner() {
if runtime.GOOS == "windows" {
println(config.Title + " " + config.Version)
println(" ")
return
}

if len(banner) < 1 {
panic("invalid banner data")
}
Expand Down

0 comments on commit d248ca2

Please sign in to comment.