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

Essentially Rewrite HellPot + Fun Bonus Features #162

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ef69b86
Add optional `-b`/`--book` flag to choose source file other than Niet…
ginger51011 Jan 18, 2024
ac77dcc
Remove globals from heffalump/*, add NewDefault{Heffalump,MarkovMap}()
ginger51011 Jan 19, 2024
1b8de3d
Add short flags to help, add `--help` flag
ginger51011 Jan 20, 2024
0a3cc6d
Rename --book to --grimoire, fix comments
ginger51011 Feb 2, 2024
6e183db
Merge pull request #131 from ginger51011/feat/add-file-flag
yunginnanet Apr 14, 2024
e016fba
add JSON hell, and enable more kinds of hell in the future
ShadowJonathan Jan 31, 2024
54e492c
fix plaintext
ShadowJonathan Jan 31, 2024
53afe56
Merge pull request #137 from ShadowJonathan/with-json
yunginnanet Apr 19, 2024
a06c356
Merge branch 'main' into development
yunginnanet Apr 19, 2024
b647b54
Feat[CI]: run release build matrix on github release creation
yunginnanet May 1, 2024
81e2fb3
Fix[CD]: run release build matrix on github release creation
yunginnanet May 1, 2024
a4ab0cb
Fix[CD]: run release build matrix on github release creation, workflo…
yunginnanet May 1, 2024
e63d81a
Fix[CD]: bump go version and don't package tar.gz in favor of just bin
yunginnanet May 1, 2024
cefb21b
Fix[CD]: bump go version and don't package tar.gz in favor of just bi…
yunginnanet May 1, 2024
c309667
Fix[CD]: try to fix go-release-action config
yunginnanet May 1, 2024
e8888b2
Merge branch 'main' into development
yunginnanet May 19, 2024
67877b7
Merge branch 'main' into development
yunginnanet Jun 19, 2024
20c41be
Merge branch 'main' into development
yunginnanet Jun 20, 2024
14ba022
Merge branch 'main' into development
yunginnanet Jun 21, 2024
cc7020f
TeeHee: Essentially rewrite HellPot :^)
yunginnanet Jun 21, 2024
3c2059a
Fix: build and vet errors
yunginnanet Jun 21, 2024
df5c936
Fix: Remove unused git stash lint
yunginnanet Jun 21, 2024
db0ec03
SAST: Resolve gosec G304
yunginnanet Jun 21, 2024
8519480
Fix: don't parse flags during unit tests
yunginnanet Jun 21, 2024
843d04a
Chore: prune deps
yunginnanet Jun 21, 2024
be9700a
Resolve https://github.com/yunginnanet/HellPot/pull/162#discussion_r1…
yunginnanet Jun 21, 2024
da2fadd
Fix: nil check on buffer pointer
yunginnanet Jun 21, 2024
ee11dd3
WIP rewrite progress, config loading broken atm
yunginnanet Jun 26, 2024
833b424
Fix: fix configuration file loading
yunginnanet Jun 26, 2024
317fd91
Security (logger): Resolve gosec G301 (CWE-276)
yunginnanet Jun 26, 2024
e9785d2
Security (logger): Resolve gosec G302 (CWE-276)
yunginnanet Jun 26, 2024
dfad295
Chore: Tidy up, split up files in main package
yunginnanet Jun 26, 2024
303aa0b
Chore: go mod tidy
yunginnanet Jun 26, 2024
362c1d3
Fix: cli arg, config, and logger fixes
yunginnanet Jun 26, 2024
888142b
Fix: Embolden main package test, improve default config warning
yunginnanet Jun 26, 2024
eac788b
Fix: add missing `util.go`
yunginnanet Jun 26, 2024
031e116
Revert "add JSON hell, and enable more kinds of hell in the future"
yunginnanet Jun 26, 2024
e5831c0
Revert "fix plaintext"
yunginnanet Jun 26, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Clients (hopefully bots) that disregard `robots.txt` and connect to your instanc

HellPot will send an infinite stream of data that is _just close enough_ to being a real website that they might just stick around until their soul is ripped apart and they cease to exist.

Under the hood of this eternal suffering is a markov engine that chucks bits and pieces of [The Birth of Tragedy (Hellenism and Pessimism)](https://www.gutenberg.org/files/51356/51356-h/51356-h.htm) by Friedrich Nietzsche at the client using [fasthttp](https://github.com/valyala/fasthttp).
Under the hood of this eternal suffering is a markov engine that chucks bits and pieces of [The Birth of Tragedy (Hellenism and Pessimism)](https://www.gutenberg.org/files/51356/51356-h/51356-h.htm) by Friedrich Nietzsche at the client~~~~ using [fasthttp](https://github.com/valyala/fasthttp), or optionally you may synchronize HellPot with your nightmares by using the `-g`/`--grimoire` flag

## Building From Source

Expand Down
130 changes: 103 additions & 27 deletions cmd/HellPot/HellPot.go
Original file line number Diff line number Diff line change
@@ -1,59 +1,135 @@
package main

import (
"io"
"os"
"os/signal"
"path/filepath"
"strconv"
"syscall"

"github.com/rs/zerolog"
"time"

"github.com/yunginnanet/HellPot/internal/config"
"github.com/yunginnanet/HellPot/internal/extra"
"github.com/yunginnanet/HellPot/internal/http"
"github.com/yunginnanet/HellPot/internal/logger"
"github.com/yunginnanet/HellPot/internal/version"
)

var (
log zerolog.Logger
version string // set by linker
runningConfig *config.Parameters
)

func init() {
if version != "" {
config.Version = version[1:]
func writeConfig(target string) bool {
var f *os.File
var err error
f, err = os.Create(target) // #nosec G304 -- go home gosec, you're drunk
if err != nil {
println("failed to create config file: " + err.Error())
return false
}
config.Init()
if config.BannerOnly {
extra.Banner()
os.Exit(0)
if _, err = io.Copy(f, config.Defaults.IO); err != nil {
println("failed to write default config to file: " + err.Error())
_ = f.Close()
return false
}
println("wrote default config to " + target)
runningConfig, _ = config.Setup(f)
_ = f.Close()
return true
}

switch config.DockerLogging {
case true:
config.CurrentLogFile = "/dev/stdout"
config.NoColor = true
log = config.StartLogger(false, os.Stdout)
default:
log = config.StartLogger(true)
func main() {
conf := config.CLIFlags.Lookup("config").Value
if conf.String() == "" {
conf = config.CLIFlags.Lookup("c").Value
}

extra.Banner()
usingDefaults := true
resolvedConf := conf.String()

log.Info().Str("caller", "config").Str("file", config.Filename).Msg(config.Filename)
log.Info().Str("caller", "logger").Msg(config.CurrentLogFile)
log.Debug().Str("caller", "logger").Msg("debug enabled")
log.Trace().Str("caller", "logger").Msg("trace enabled")
uconf, _ := os.UserConfigDir()
if uconf == "" && os.Getenv("HOME") != "" {
uconf = filepath.Join(os.Getenv("HOME"), ".config")
}

}
if resolvedConf == "" {
for _, path := range []string{
"/etc/HellPot/config.toml",
"/usr/local/etc/HellPot/config.toml",
"./config.toml",
filepath.Join(uconf, "HellPot", "config.toml"),
} {
if _, err := os.Stat(path); err == nil {
resolvedConf = path
break
}
}
}

var setupErr error
var err error
var f *os.File

f, err = os.Open(resolvedConf) // #nosec G304 go home gosec, you're drunk
if err == nil {
runningConfig, setupErr = config.Setup(f)
}
switch {
case setupErr != nil:
println("failed to setup config: " + setupErr.Error())
case err != nil:
println("failed to open config file for reading: " + err.Error())
println("trying to create it....")
wroteOK := writeConfig(resolvedConf)
if wroteOK {
break
}
case runningConfig != nil:
usingDefaults = false
_ = f.Close()
}

if runningConfig == nil {
if runningConfig, err = config.Setup(nil); err != nil || runningConfig == nil {
panic("failed to setup default config...\n" + err.Error())
}
}

log, _ := logger.New(runningConfig.Logger)

if usingDefaults {
log.Warn().Msg("continuing with default configuration in ")
for i := 5; i > 0; i-- {
print(strconv.Itoa(i))
for i := 0; i < 5; i++ {
time.Sleep(200 * time.Millisecond)
print(".")
}
}
}

if !runningConfig.Logger.NoColor {
extra.Banner()
}

log.Info().Msg("🔥 Starting HellPot 🔥")
log.Info().Msg("Version: " + version.Version)
log.Info().Msg("PID: " + strconv.Itoa(os.Getpid()))
log.Info().Msg("Using config file: " + resolvedConf)
if usingDefaults {
log.Warn().Msg("Using default configuration")
}
log.Debug().Msg("Debug logging enabled")
log.Trace().Msg("Trace logging enabled")

func main() {
stopChan := make(chan os.Signal, 1)
signal.Notify(stopChan, syscall.SIGINT, syscall.SIGTERM)

go func() {
log.Fatal().Err(http.Serve()).Msg("HTTP error")
log.Fatal().Err(http.Serve(runningConfig)).Msg("HTTP error")
}()

<-stopChan // wait for SIGINT
log.Warn().Msg("Shutting down server...")

}
5 changes: 0 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@ require (
github.com/fasthttp/router v1.5.1
github.com/knadh/koanf/parsers/toml v0.1.0
github.com/knadh/koanf/providers/env v0.1.0
github.com/knadh/koanf/providers/file v0.1.0
github.com/knadh/koanf/v2 v2.1.1
github.com/rs/zerolog v1.33.0
github.com/spf13/afero v1.11.0
github.com/valyala/fasthttp v1.55.0
golang.org/x/term v0.21.0
)

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/knadh/koanf/maps v0.1.1 // indirect
Expand All @@ -29,5 +25,4 @@ require (
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
)
11 changes: 0 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSV
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/fasthttp/router v1.5.1 h1:uViy8UYYhm5npJSKEZ4b/ozM//NGzVCfJbh6VJ0VKr8=
github.com/fasthttp/router v1.5.1/go.mod h1:WrmsLo3mrerZP2VEXRV1E8nL8ymJFYCDTr4HmnB8+Zs=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 h1:TQcrn6Wq+sKGkpyPvppOz99zsMBaUOKXq6HSv655U1c=
github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand All @@ -19,8 +17,6 @@ github.com/knadh/koanf/parsers/toml v0.1.0 h1:S2hLqS4TgWZYj4/7mI5m1CQQcWurxUz6OD
github.com/knadh/koanf/parsers/toml v0.1.0/go.mod h1:yUprhq6eo3GbyVXFFMdbfZSo928ksS+uo0FFqNMnO18=
github.com/knadh/koanf/providers/env v0.1.0 h1:LqKteXqfOWyx5Ab9VfGHmjY9BvRXi+clwyZozgVRiKg=
github.com/knadh/koanf/providers/env v0.1.0/go.mod h1:RE8K9GbACJkeEnkl8L/Qcj8p4ZyPXZIQ191HJi44ZaQ=
github.com/knadh/koanf/providers/file v0.1.0 h1:fs6U7nrV58d3CFAFh8VTde8TM262ObYf3ODrc//Lp+c=
github.com/knadh/koanf/providers/file v0.1.0/go.mod h1:rjJ/nHQl64iYCtAW2QQnF0eSmDEX/YZ/eNFj5yR6BvA=
github.com/knadh/koanf/v2 v2.1.1 h1:/R8eXqasSTsmDCsAyYj+81Wteg8AqrV9CP6gvsTsOmM=
github.com/knadh/koanf/v2 v2.1.1/go.mod h1:4mnTRbZCK+ALuBXHZMjDfG9y714L7TykVnZkXbMU3Es=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand All @@ -41,22 +37,15 @@ github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 h1:KanIMPX0QdEdB4R3CiimCAbxFrhB3j7h0/OvpYGVQa8=
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511/go.mod h1:sM7Mt7uEoCeFSCBM+qBrqvEo+/9vdmj19wzp3yzUhmg=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
nullprogram.com/x/rng v1.1.0 h1:SMU7DHaQSWtKJNTpNFIFt8Wd/KSmOuSDPXrMFp/UMro=
48 changes: 36 additions & 12 deletions heffalump/heffalump.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ import (
"bufio"
"io"
"sync"

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

var log = config.GetLogger()

// DefaultHeffalump represents a Heffalump type
var DefaultHeffalump *Heffalump
const DefaultBuffSize = 100 * 1 << 10

// Heffalump represents our buffer pool and markov map from Heffalump
type Heffalump struct {
Expand All @@ -36,22 +31,51 @@ func NewHeffalump(mm MarkovMap, buffsize int) *Heffalump {
}
}

// NewDefaultHeffalump instantiates a new default Heffalump from a MarkovMap created using
// using the default source text.
func NewDefaultHeffalump() *Heffalump {
return NewHeffalump(NewDefaultMarkovMap(), DefaultBuffSize)
}

type ContentType int

const (
PlainText ContentType = iota
HTML
JSON
)

// WriteHell writes markov chain heffalump hell to the provided io.Writer
func (h *Heffalump) WriteHell(bw *bufio.Writer) (int64, error) {
func (h *Heffalump) WriteHell(bw *bufio.Writer, cType ContentType) (int64, error) {
var n int64
var err error

defer func() {
/* defer func() {
if r := recover(); r != nil {
log.Error().Interface("caller", r).Msg("panic recovered!")
}
}()
}()*/
yunginnanet marked this conversation as resolved.
Show resolved Hide resolved

buf := h.pool.Get().([]byte)

if _, err = bw.WriteString("<html>\n<body>\n"); err != nil {
h.pool.Put(buf)
return n, err
switch cType {
case PlainText:
if _, err = bw.WriteString("# Chapter 1\n"); err != nil {
return n, err
}
break
case HTML:
if _, err = bw.WriteString("<html>\n<body>\n"); err != nil {
return n, err
}
break
case JSON:
if _, err = bw.WriteString("[\""); err != nil {
return n, err
}
break
default:
panic("unhandled default case")
}
if n, err = io.CopyBuffer(bw, h.mm, buf); err != nil {
h.pool.Put(buf)
Expand Down
10 changes: 4 additions & 6 deletions heffalump/markov.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@ import (
"git.tcp.direct/kayos/common/squish"
)

var DefaultMarkovMap MarkovMap

func init() {
// DefaultMarkovMap is a Markov chain based on src.
// NewDefaultMarkovMap creates a new MarkovMap from the default source text.
func NewDefaultMarkovMap() MarkovMap {
src, err := squish.UnpackStr(srcGz)
if err != nil {
panic(err)
}
if len(src) < 1 {
panic("failed to unpack source")
}
DefaultMarkovMap = MakeMarkovMap(strings.NewReader(src))
DefaultHeffalump = NewHeffalump(DefaultMarkovMap, 100*1<<10)

return MakeMarkovMap(strings.NewReader(src))
}

// ScanHTML is a basic split function for a Scanner that returns each
Expand Down
37 changes: 0 additions & 37 deletions internal/config/arguments.go

This file was deleted.

Loading