mirror of
https://github.com/mariocandela/beelzebub.git
synced 2025-07-01 18:47:26 -04:00
Small refactor to reduce LOC and keep code DRY. (#53)
This commit is contained in:
18
main.go
18
main.go
@ -4,16 +4,16 @@ import (
|
|||||||
"beelzebub/builder"
|
"beelzebub/builder"
|
||||||
"beelzebub/parser"
|
"beelzebub/parser"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var quit = make(chan struct{})
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var configurationsCorePath string
|
var (
|
||||||
var configurationsServicesDirectory string
|
quit = make(chan struct{})
|
||||||
|
configurationsCorePath string
|
||||||
|
configurationsServicesDirectory string
|
||||||
|
)
|
||||||
|
|
||||||
flag.StringVar(&configurationsCorePath, "confCore", "./configurations/beelzebub.yaml", "Provide the path of configurations core")
|
flag.StringVar(&configurationsCorePath, "confCore", "./configurations/beelzebub.yaml", "Provide the path of configurations core")
|
||||||
flag.StringVar(&configurationsServicesDirectory, "confServices", "./configurations/services/", "Directory config services")
|
flag.StringVar(&configurationsServicesDirectory, "confServices", "./configurations/services/", "Directory config services")
|
||||||
@ -22,20 +22,20 @@ func main() {
|
|||||||
parser := parser.Init(configurationsCorePath, configurationsServicesDirectory)
|
parser := parser.Init(configurationsCorePath, configurationsServicesDirectory)
|
||||||
|
|
||||||
coreConfigurations, err := parser.ReadConfigurationsCore()
|
coreConfigurations, err := parser.ReadConfigurationsCore()
|
||||||
failOnError(err, fmt.Sprintf("Error during ReadConfigurationsCore: "))
|
failOnError(err, "Error during ReadConfigurationsCore: ")
|
||||||
|
|
||||||
beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
|
beelzebubServicesConfiguration, err := parser.ReadConfigurationsServices()
|
||||||
failOnError(err, fmt.Sprintf("Error during ReadConfigurationsServices: "))
|
failOnError(err, "Error during ReadConfigurationsServices: ")
|
||||||
|
|
||||||
beelzebubBuilder := builder.NewBuilder()
|
beelzebubBuilder := builder.NewBuilder()
|
||||||
|
|
||||||
director := builder.NewDirector(beelzebubBuilder)
|
director := builder.NewDirector(beelzebubBuilder)
|
||||||
|
|
||||||
beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration)
|
beelzebubBuilder, err = director.BuildBeelzebub(coreConfigurations, beelzebubServicesConfiguration)
|
||||||
failOnError(err, fmt.Sprintf("Error during BuildBeelzebub: "))
|
failOnError(err, "Error during BuildBeelzebub: ")
|
||||||
|
|
||||||
err = beelzebubBuilder.Run()
|
err = beelzebubBuilder.Run()
|
||||||
failOnError(err, fmt.Sprintf("Error during run beelzebub core: "))
|
failOnError(err, "Error during run beelzebub core: ")
|
||||||
|
|
||||||
defer beelzebubBuilder.Close()
|
defer beelzebubBuilder.Close()
|
||||||
|
|
||||||
|
@ -11,8 +11,12 @@ import (
|
|||||||
"github.com/go-resty/resty/v2"
|
"github.com/go-resty/resty/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ChatGPTPluginName = "OpenAIGPTLinuxTerminal"
|
const (
|
||||||
const openAIGPTEndpoint = "https://api.openai.com/v1/completions"
|
// Reference: https://www.engraved.blog/building-a-virtual-machine-inside/
|
||||||
|
promptVirtualizeLinuxTerminal = "I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do no write explanations. Do not type commands unless I instruct you to do so.\n\nA:pwd\n\nQ:/home/user\n\n"
|
||||||
|
ChatGPTPluginName = "OpenAIGPTLinuxTerminal"
|
||||||
|
openAIGPTEndpoint = "https://api.openai.com/v1/completions"
|
||||||
|
)
|
||||||
|
|
||||||
type History struct {
|
type History struct {
|
||||||
Input, Output string
|
Input, Output string
|
||||||
@ -62,7 +66,6 @@ type gptRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reference: https://www.engraved.blog/building-a-virtual-machine-inside/
|
// Reference: https://www.engraved.blog/building-a-virtual-machine-inside/
|
||||||
const promptVirtualizeLinuxTerminal = "I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. Do no write explanations. Do not type commands unless I instruct you to do so.\n\nA:pwd\n\nQ:/home/user\n\n"
|
|
||||||
|
|
||||||
func buildPrompt(histories []History, command string) string {
|
func buildPrompt(histories []History, command string) string {
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
|
@ -30,7 +30,10 @@ type Event struct {
|
|||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Protocol int
|
type (
|
||||||
|
Protocol int
|
||||||
|
Status int
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HTTP Protocol = iota
|
HTTP Protocol = iota
|
||||||
@ -42,8 +45,6 @@ func (status Protocol) String() string {
|
|||||||
return [...]string{"HTTP", "SSH", "TCP"}[status]
|
return [...]string{"HTTP", "SSH", "TCP"}[status]
|
||||||
}
|
}
|
||||||
|
|
||||||
type Status int
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Start Status = iota
|
Start Status = iota
|
||||||
End
|
End
|
||||||
@ -105,12 +106,9 @@ func (tracer *tracer) TraceEvent(event Event) {
|
|||||||
switch event.Protocol {
|
switch event.Protocol {
|
||||||
case HTTP.String():
|
case HTTP.String():
|
||||||
eventsHTTPTotal.Inc()
|
eventsHTTPTotal.Inc()
|
||||||
break
|
|
||||||
case SSH.String():
|
case SSH.String():
|
||||||
eventsSSHTotal.Inc()
|
eventsSSHTotal.Inc()
|
||||||
break
|
|
||||||
case TCP.String():
|
case TCP.String():
|
||||||
eventsTCPTotal.Inc()
|
eventsTCPTotal.Inc()
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user