[internal/logging] add logging lib
This commit is contained in:
19
README.md
19
README.md
@@ -1,4 +1,23 @@
|
|||||||
# gokill
|
# gokill
|
||||||
|
|
||||||
|
gokill is aimed at activists, journalists and others that need to protect their data against access under all circumstances.
|
||||||
|
gokill falls under the category of anti-forensic tools, helping you to protect yourself against repression.
|
||||||
|
It is built for worst case scenarios when intruders physical gaining access to a device.
|
||||||
|
In such heated situations gokill helps you automatically executing tasks like:
|
||||||
|
- locking the screen
|
||||||
|
- notify someone
|
||||||
|
- deleting data
|
||||||
|
- encrypting partitions
|
||||||
|
- destroying encrypted partitions
|
||||||
|
- and many more
|
||||||
|
|
||||||
|
the tasks gokill executes could be done by hand using shellscripts, cronjobs, daemons ect.
|
||||||
|
but that means everyone needs to figure it out for themselves, and eventually make mistakes.
|
||||||
|
the idea of gokill is to provide a wide variarity of possibilities out of the box while making sure they are well tested.
|
||||||
|
|
||||||
|
|
||||||
|
gokill aims to be highly configurable and easily extendable.
|
||||||
|
|
||||||
'gokill' is a tool that completes some actions when a certain event occurs.
|
'gokill' is a tool that completes some actions when a certain event occurs.
|
||||||
actions can vary from shuting down the machine to sending mails over erasing data.
|
actions can vary from shuting down the machine to sending mails over erasing data.
|
||||||
actions can be triggert by certain conditions like specific outcomes of unix
|
actions can be triggert by certain conditions like specific outcomes of unix
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func (a StagedActions) executeInternal(f func(Action)) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Execute Stage %v\n", idx+1)
|
internal.Log.Infof("Execute Stage %v", idx+1)
|
||||||
for actionidx, _ := range stage.Actions {
|
for actionidx, _ := range stage.Actions {
|
||||||
go f(stage.Actions[actionidx])
|
go f(stage.Actions[actionidx])
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,7 @@ func (a StagedActions) executeInternal(f func(Action)) {
|
|||||||
err := <-a.ActionChan
|
err := <-a.ActionChan
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error occured on Stage %d: %s\n", idx+1, err)
|
internal.Log.Errorf("Error occured on Stage %d: %s", idx+1, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package actions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"unknown.com/gokill/internal"
|
"unknown.com/gokill/internal"
|
||||||
)
|
)
|
||||||
@@ -13,12 +12,12 @@ type Printer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p Printer) Execute() {
|
func (p Printer) Execute() {
|
||||||
fmt.Printf("Print action fires. Message: %s\n", p.Message)
|
internal.LogDoc(p).Infof("Print action fires. Message: %s", p.Message)
|
||||||
p.ActionChan <- nil
|
p.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p Printer) DryExecute() {
|
func (p Printer) DryExecute() {
|
||||||
fmt.Printf("Print action fire test. Message: %s\n", p.Message)
|
internal.LogDoc(p).Infof("Print action fire test. Message: %s", p.Message)
|
||||||
p.ActionChan <- nil
|
p.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func (s SendMatrix) sendMessage(message string) error {
|
|||||||
|
|
||||||
client.Crypto = cryptoHelper
|
client.Crypto = cryptoHelper
|
||||||
|
|
||||||
fmt.Println("Matrix Client Now running")
|
internal.LogDoc(s).Info("Matrix Client Now running")
|
||||||
syncCtx, cancelSync := context.WithCancel(context.Background())
|
syncCtx, cancelSync := context.WithCancel(context.Background())
|
||||||
var syncStopWait sync.WaitGroup
|
var syncStopWait sync.WaitGroup
|
||||||
syncStopWait.Add(1)
|
syncStopWait.Add(1)
|
||||||
@@ -72,8 +72,8 @@ func (s SendMatrix) sendMessage(message string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to send event")
|
return fmt.Errorf("Failed to send event")
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Matrix Client: Message sent")
|
internal.LogDoc(s).Info("Matrix Client: Message sent")
|
||||||
fmt.Printf("Matrix Client: event_id: %s", resp.EventID.String())
|
internal.LogDoc(s).Infof("Matrix Client: event_id: %s", resp.EventID.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelSync()
|
cancelSync()
|
||||||
@@ -87,22 +87,22 @@ func (s SendMatrix) sendMessage(message string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s SendMatrix) DryExecute() {
|
func (s SendMatrix) DryExecute() {
|
||||||
fmt.Println("SendMatrix: Trying to send test message")
|
internal.LogDoc(s).Info("SendMatrix: Trying to send test message")
|
||||||
err := s.sendMessage(s.TestMessage)
|
err := s.sendMessage(s.TestMessage)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("SendMatrix: failed to send test message")
|
internal.LogDoc(s).Info("SendMatrix: failed to send test message")
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ActionChan <- err
|
s.ActionChan <- err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SendMatrix) Execute() {
|
func (s SendMatrix) Execute() {
|
||||||
fmt.Println("SendMatrix: Trying to send message")
|
internal.LogDoc(s).Info("SendMatrix: Trying to send message")
|
||||||
err := s.sendMessage(s.Message)
|
err := s.sendMessage(s.Message)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("SendMatrix: failed to send message")
|
internal.LogDoc(s).Info("SendMatrix: failed to send message")
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ActionChan <- err
|
s.ActionChan <- err
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ func (s SendTelegram) sendMessage(message string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bot.Debug = true
|
bot.Debug = true
|
||||||
|
|
||||||
fmt.Printf("Authorized on account %s", bot.Self.UserName)
|
|
||||||
|
|
||||||
u := tgbotapi.NewUpdate(0)
|
u := tgbotapi.NewUpdate(0)
|
||||||
u.Timeout = 60
|
u.Timeout = 60
|
||||||
|
|
||||||
@@ -37,22 +34,22 @@ func (s SendTelegram) sendMessage(message string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s SendTelegram) DryExecute() {
|
func (s SendTelegram) DryExecute() {
|
||||||
fmt.Println("SendTelegram: Trying to send test message")
|
internal.LogDoc(s).Info("SendTelegram: Trying to send test message")
|
||||||
err := s.sendMessage(s.TestMessage)
|
err := s.sendMessage(s.TestMessage)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("SendTelegram: failed to send test message")
|
internal.LogDoc(s).Info("SendTelegram: failed to send test message")
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ActionChan <- err
|
s.ActionChan <- err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SendTelegram) Execute() {
|
func (s SendTelegram) Execute() {
|
||||||
fmt.Println("SendTelegram: Trying to send message")
|
internal.LogDoc(s).Info("SendTelegram: Trying to send message")
|
||||||
err := s.sendMessage(s.Message)
|
err := s.sendMessage(s.Message)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("SendTelegram: failed to send message")
|
internal.LogDoc(s).Info("SendTelegram: failed to send message")
|
||||||
}
|
}
|
||||||
|
|
||||||
s.ActionChan <- err
|
s.ActionChan <- err
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ func isExecutableFile(path string) bool {
|
|||||||
fi, err := os.Lstat(path)
|
fi, err := os.Lstat(path)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Test executing Shellscript Failed.")
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,18 +32,18 @@ func isExecutableFile(path string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c ShellScript) DryExecute() {
|
func (c ShellScript) DryExecute() {
|
||||||
fmt.Printf("Test Executing ShellScript:\n%s\n", c.Path)
|
internal.LogDoc(c).Infof("Test Executing ShellScript:\n%s", c.Path)
|
||||||
|
|
||||||
_, err := os.Open(c.Path)
|
_, err := os.Open(c.Path)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Test executing Shellscript Failed.")
|
internal.LogDoc(c).Warning("Test executing Shellscript Failed.")
|
||||||
c.ActionChan <- err
|
c.ActionChan <- err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isExecutableFile(c.Path) {
|
if !isExecutableFile(c.Path) {
|
||||||
fmt.Println("Test executing Shellscript Failed.")
|
internal.LogDoc(c).Warning("Test executing Shellscript Failed.")
|
||||||
c.ActionChan <- fmt.Errorf("File is not executable: %s", c.Path)
|
c.ActionChan <- fmt.Errorf("File is not executable: %s", c.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -54,7 +53,7 @@ func (c ShellScript) DryExecute() {
|
|||||||
|
|
||||||
func (c ShellScript) Execute() {
|
func (c ShellScript) Execute() {
|
||||||
if !isExecutableFile(c.Path) {
|
if !isExecutableFile(c.Path) {
|
||||||
fmt.Println("Test executing Shellscript Failed.")
|
internal.LogDoc(c).Warning("Executing Shellscript Failed.")
|
||||||
c.ActionChan <- fmt.Errorf("File is not executable: %s", c.Path)
|
c.ActionChan <- fmt.Errorf("File is not executable: %s", c.Path)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -64,11 +63,11 @@ func (c ShellScript) Execute() {
|
|||||||
stdout, err := cmd.Output()
|
stdout, err := cmd.Output()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
internal.LogDoc(c).Warning("Failed to execute Shellscript")
|
||||||
c.ActionChan <- err
|
c.ActionChan <- fmt.Errorf("Error during ShellScript execute: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(string(stdout[:]))
|
internal.LogDoc(c).Infof("Shellscript output:\n%s", string(stdout[:]))
|
||||||
c.ActionChan <- nil
|
c.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package actions
|
package actions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
@@ -14,17 +13,17 @@ type Shutdown struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s Shutdown) DryExecute() {
|
func (s Shutdown) DryExecute() {
|
||||||
fmt.Printf("shutdown -h %s\n", s.Timeout)
|
internal.LogDoc(s).Infof("shutdown -h %s", s.Timeout)
|
||||||
fmt.Println("Test Shutdown executed...")
|
internal.LogDoc(s).Info("Test Shutdown executed...")
|
||||||
s.ActionChan <- nil
|
s.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Shutdown) Execute() {
|
func (s Shutdown) Execute() {
|
||||||
if err := exec.Command("shutdown", "-h", s.Timeout).Run(); err != nil {
|
if err := exec.Command("shutdown", "-h", s.Timeout).Run(); err != nil {
|
||||||
fmt.Println("Failed to initiate shutdown:", err)
|
internal.LogDoc(s).Errorf("Failed to initiate shutdown: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Shutdown executed...")
|
internal.LogDoc(s).Notice("Shutdown executed...")
|
||||||
|
|
||||||
s.ActionChan <- nil
|
s.ActionChan <- nil
|
||||||
}
|
}
|
||||||
@@ -37,7 +36,7 @@ func (s Shutdown) Create(config internal.ActionConfig, c ActionResultChan) (Acti
|
|||||||
err := json.Unmarshal(config.Options, &result)
|
err := json.Unmarshal(config.Options, &result)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Parsing Shutdown options failed.")
|
internal.LogDoc(s).Warning("Parsing Shutdown options failed.")
|
||||||
return Shutdown{}, err
|
return Shutdown{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package actions
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"unknown.com/gokill/internal"
|
"unknown.com/gokill/internal"
|
||||||
@@ -18,7 +17,7 @@ func (t TimeOut) DryExecute() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t TimeOut) Execute() {
|
func (t TimeOut) Execute() {
|
||||||
fmt.Printf("Waiting %d seconds\n", t.Duration)
|
internal.LogDoc(t).Infof("Waiting %d seconds", t.Duration)
|
||||||
time.Sleep(time.Duration(t.Duration) * time.Second)
|
time.Sleep(time.Duration(t.Duration) * time.Second)
|
||||||
t.ActionChan <- nil
|
t.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,19 +24,19 @@ func isCommandAvailable(name string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Command) DryExecute() {
|
func (c Command) DryExecute() {
|
||||||
fmt.Printf("Test Executing Command:\n%s\n", c.Command)
|
internal.LogDoc(c).Infof("Test Executing Command: %s", c.Command)
|
||||||
command, _, err := c.splitCommandString()
|
command, _, err := c.splitCommandString()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error during argument parsing of command '%s'\n", c.Command)
|
internal.LogDoc(c).Errorf("Error during argument parsing of command '%s'", c.Command)
|
||||||
fmt.Println(err)
|
c.ActionChan <- fmt.Errorf("Error on Command action: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
isAvailable := isCommandAvailable(command)
|
isAvailable := isCommandAvailable(command)
|
||||||
|
|
||||||
if !isAvailable {
|
if !isAvailable {
|
||||||
fmt.Printf("Command %s not found\n", command)
|
internal.LogDoc(c).Warningf("Command %s not found", command)
|
||||||
c.ActionChan <- fmt.Errorf("Command %s not found!", command)
|
c.ActionChan <- fmt.Errorf("Command %s not found!", command)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ func (c Command) splitCommandString() (string, []string, error) {
|
|||||||
|
|
||||||
func (c Command) Execute() {
|
func (c Command) Execute() {
|
||||||
command, args, err := c.splitCommandString()
|
command, args, err := c.splitCommandString()
|
||||||
fmt.Println("Executing command: ", c.Command)
|
internal.LogDoc(c).Infof("Executing command: ", c.Command)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.ActionChan <- err
|
c.ActionChan <- err
|
||||||
@@ -72,11 +72,11 @@ func (c Command) Execute() {
|
|||||||
stdout, err := cmd.Output()
|
stdout, err := cmd.Output()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
internal.LogDoc(c).Errorf("%s", err.Error())
|
||||||
c.ActionChan <- err
|
c.ActionChan <- fmt.Errorf("Executing Command '%s' failed: %s", c.Command, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(string(stdout[:]))
|
internal.LogDoc(c).Infof("Command Output:\n%s", string(stdout[:]))
|
||||||
|
|
||||||
c.ActionChan <- nil
|
c.ActionChan <- nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func writeToFile(path string, documenter internal.Documenter) error {
|
|||||||
f, err := os.Create(fileName)
|
f, err := os.Create(fileName)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
internal.Log.Errorf("Error during writeToFile: %s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ func writeToFile(path string, documenter internal.Documenter) error {
|
|||||||
_, err = f.WriteString(getMarkdown(documenter))
|
_, err = f.WriteString(getMarkdown(documenter))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
internal.Log.Errorf("Error during writeToFile: %s", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,9 +86,12 @@ func printDocumentersSummary() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
outputPath := flag.String("output", "", "path where docs/ shoud be created")
|
outputPath := flag.String("output", "", "path where docs/ shoud be created")
|
||||||
|
verbose := flag.Bool("verbose", false, "log debug information")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
internal.InitLogger()
|
||||||
|
internal.SetVerbose(*verbose)
|
||||||
|
|
||||||
if *outputPath == "" {
|
if *outputPath == "" {
|
||||||
printDocumentersSummary()
|
printDocumentersSummary()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -37,19 +37,24 @@ func GetDocumentation() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
configFilePath := flag.String("c", "", "path to config file")
|
configFilePath := flag.String("c", "", "path to config file")
|
||||||
showDoc := flag.Bool("d", false, "show doc")
|
showDoc := flag.Bool("d", false, "show doc")
|
||||||
testRun := flag.Bool("t", false, "test run")
|
testRun := flag.Bool("t", false, "test run")
|
||||||
|
verbose := flag.Bool("verbose", false, "log debug info")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
internal.InitLogger()
|
||||||
|
internal.SetVerbose(*verbose)
|
||||||
|
|
||||||
if *showDoc {
|
if *showDoc {
|
||||||
fmt.Print(GetDocumentation())
|
fmt.Print(GetDocumentation())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if *configFilePath == "" {
|
if *configFilePath == "" {
|
||||||
fmt.Println("No config file given. Use --help to show usage.")
|
internal.Log.Warning("No config file given. Use --help to show usage.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +63,7 @@ func main() {
|
|||||||
configFile, err := os.ReadFile(*configFilePath)
|
configFile, err := os.ReadFile(*configFilePath)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error loading config file: ", err)
|
internal.Log.Errorf("Error loading config file: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +71,7 @@ func main() {
|
|||||||
err = json.Unmarshal(configFile, &f)
|
err = json.Unmarshal(configFile, &f)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
internal.Log.Errorf("Error pasing json file: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,7 +80,7 @@ func main() {
|
|||||||
trigger, err := triggers.NewTrigger(cfg)
|
trigger, err := triggers.NewTrigger(cfg)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
internal.Log.Errorf("%s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
docbuilder
Executable file
BIN
docbuilder
Executable file
Binary file not shown.
@@ -12,6 +12,7 @@
|
|||||||
(utils.lib.eachSystem (utils.lib.defaultSystems) ( system:
|
(utils.lib.eachSystem (utils.lib.defaultSystems) ( system:
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
currentVendorHash = "sha256-Q14p7L2Ez/kvBhMUxlyMA1I/XEIxgSXOp4dpmH/SQyI=";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
gokill = pkgs.buildGoModule rec {
|
gokill = pkgs.buildGoModule rec {
|
||||||
pname = "gokill";
|
pname = "gokill";
|
||||||
version = "1.0";
|
version = "1.0";
|
||||||
vendorHash = "sha256-8xHjVwNskgiSoDKbOpL2phHub1F21ios1t9BcZB944o=";
|
vendorHash = currentVendorHash;
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
@@ -41,7 +42,7 @@
|
|||||||
gokill-docbuilder = pkgs.buildGoModule rec {
|
gokill-docbuilder = pkgs.buildGoModule rec {
|
||||||
pname = "docbuilder";
|
pname = "docbuilder";
|
||||||
version = "1.0";
|
version = "1.0";
|
||||||
vendorHash = "sha256-8xHjVwNskgiSoDKbOpL2phHub1F21ios1t9BcZB944o=";
|
vendorHash = currentVendorHash;
|
||||||
buildFLags = "-o . $dest/cmd/gokill/docbuilder";
|
buildFLags = "-o . $dest/cmd/gokill/docbuilder";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -3,6 +3,7 @@ module unknown.com/gokill
|
|||||||
go 1.21.3
|
go 1.21.3
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/apsdehal/go-logger v0.0.0-20190515212710-b0d6ccfee0e6
|
||||||
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
|
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
|
||||||
github.com/mattn/go-sqlite3 v1.14.17
|
github.com/mattn/go-sqlite3 v1.14.17
|
||||||
maunium.net/go/mautrix v0.16.1
|
maunium.net/go/mautrix v0.16.1
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -1,5 +1,7 @@
|
|||||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||||
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||||
|
github.com/apsdehal/go-logger v0.0.0-20190515212710-b0d6ccfee0e6 h1:qISSdUEX4sjDHfdD/vf65fhuCh3pIhiILDB7ktjJrqU=
|
||||||
|
github.com/apsdehal/go-logger v0.0.0-20190515212710-b0d6ccfee0e6/go.mod h1:U3/8D6R9+bVpX0ORZjV+3mU9pQ86m7h1lESgJbXNvXA=
|
||||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
|||||||
63
internal/logging.go
Normal file
63
internal/logging.go
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package internal
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/apsdehal/go-logger"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Log *logger.Logger
|
||||||
|
var documenterLoggers map[string]*logger.Logger
|
||||||
|
var verbose bool
|
||||||
|
|
||||||
|
var formatNormal string = "%{message}"
|
||||||
|
var formatVerbose string = "%{time} %{level}: %{message}"
|
||||||
|
var formatModuleNormal string = "%{module}: %{message}"
|
||||||
|
var formatModuleVerbose string = "%{time} %{level} %{module}: %{message}"
|
||||||
|
|
||||||
|
func InitLogger() error {
|
||||||
|
var err error
|
||||||
|
Log, err = logger.New("UsbDisconnect", 1, os.Stdout)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Logger initialization error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
documenterLoggers = make(map[string]*logger.Logger)
|
||||||
|
verbose = false
|
||||||
|
Log.SetLogLevel(logger.InfoLevel)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func LogDoc(documenter Documenter) *logger.Logger {
|
||||||
|
documenterLogger, ok := documenterLoggers[documenter.GetName()]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
documenterLogger, _ = logger.New(documenter.GetName(), 1, os.Stdout)
|
||||||
|
documenterLoggers[documenter.GetName()] = documenterLogger
|
||||||
|
}
|
||||||
|
|
||||||
|
SetVerbose(verbose)
|
||||||
|
//documenterLogger.SetFormat("%{message}")
|
||||||
|
|
||||||
|
return documenterLogger
|
||||||
|
}
|
||||||
|
|
||||||
|
func SetVerbose(value bool) {
|
||||||
|
verbose = value
|
||||||
|
toggleVerbosity := func(l *logger.Logger, formatN string, formatV string) {
|
||||||
|
if value {
|
||||||
|
l.SetLogLevel(logger.DebugLevel)
|
||||||
|
l.SetFormat(formatV)
|
||||||
|
} else {
|
||||||
|
l.SetLogLevel(logger.InfoLevel)
|
||||||
|
l.SetFormat(formatN)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleVerbosity(Log, formatNormal, formatVerbose)
|
||||||
|
for _, documenterLogger := range documenterLoggers {
|
||||||
|
toggleVerbosity(documenterLogger, formatModuleNormal, formatModuleVerbose)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ func isEthernetConnected(deviceName string) bool {
|
|||||||
content, err := os.ReadFile(fmt.Sprintf("/sys/class/net/%s/operstate", deviceName))
|
content, err := os.ReadFile(fmt.Sprintf("/sys/class/net/%s/operstate", deviceName))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
internal.LogDoc(EthernetDisconnect{}).Errorf("Cant read devices operstate. Check the deviceName. error: %s", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package triggers
|
package triggers
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"unknown.com/gokill/actions"
|
"unknown.com/gokill/actions"
|
||||||
@@ -14,10 +13,10 @@ type TimeOut struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t TimeOut) Listen() {
|
func (t TimeOut) Listen() {
|
||||||
fmt.Println("TimeOut listens")
|
internal.LogDoc(t).Info("TimeOut listens")
|
||||||
fmt.Println(t.Duration)
|
internal.LogDoc(t).Infof("%d", t.Duration)
|
||||||
time.Sleep(time.Duration(t.Duration) * time.Second)
|
time.Sleep(time.Duration(t.Duration) * time.Second)
|
||||||
fmt.Println("TimeOut fires")
|
internal.LogDoc(t).Notice("TimeOut fires")
|
||||||
actions.Fire(t.action)
|
actions.Fire(t.action)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package triggers
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -35,8 +34,8 @@ func (t UsbDisconnect) Listen() {
|
|||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Device %s detected.\n", t.DeviceName)
|
internal.LogDoc(t).Infof("Device %s detected.\n", t.DeviceName)
|
||||||
fmt.Println("UsbDisconnect Trigger is Armed")
|
internal.LogDoc(t).Notice("Trigger is Armed")
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|||||||
Reference in New Issue
Block a user