Compare commits
3 Commits
58946000e1
...
d4a660383e
| Author | SHA1 | Date | |
|---|---|---|---|
| d4a660383e | |||
| e96bbb5f49 | |||
| ad9060c8f6 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,6 +4,6 @@ result
|
||||
example.json
|
||||
go.sum
|
||||
go.mod
|
||||
gokill
|
||||
./gokill
|
||||
output.md
|
||||
thoughts.md
|
||||
|
||||
86
cmd/gokill/gokill.go
Normal file
86
cmd/gokill/gokill.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"unknown.com/gokill/actions"
|
||||
"unknown.com/gokill/internal"
|
||||
"unknown.com/gokill/triggers"
|
||||
)
|
||||
|
||||
func GetDocumentation() string {
|
||||
actions := actions.GetDocumenters()
|
||||
|
||||
var result string
|
||||
|
||||
writeOptions := func(documenters []internal.Documenter) {
|
||||
for _, act := range documenters {
|
||||
result += fmt.Sprintf("\n### %v\nDescription: %v \nValues:\n", act.GetName(), act.GetDescription())
|
||||
|
||||
for _, opt := range act.GetOptions() {
|
||||
result += fmt.Sprintf("- Name: **%v**\n\t- Type: %v\n\t- Descr: %v\n\t- Default: %v\n",
|
||||
opt.Name, opt.Type, opt.Description, opt.Default)
|
||||
result += "\n\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = "# Available Triggers:\n\n"
|
||||
writeOptions(triggers.GetDocumenters())
|
||||
result += "\n\n# Available Actions:\n\n"
|
||||
writeOptions(actions)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func main() {
|
||||
configFilePath := flag.String("c", "", "path to config file")
|
||||
showDoc := flag.Bool("d", false, "show doc")
|
||||
testRun := flag.Bool("t", false, "test run")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *showDoc {
|
||||
fmt.Print(GetDocumentation())
|
||||
return
|
||||
}
|
||||
|
||||
if *configFilePath == "" {
|
||||
fmt.Println("No config file given. Use --help to show usage.")
|
||||
return
|
||||
}
|
||||
|
||||
actions.TestRun = *testRun
|
||||
|
||||
configFile, err := os.ReadFile(*configFilePath)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Error loading config file: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
var f []internal.KillSwitchConfig
|
||||
err = json.Unmarshal(configFile, &f)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
var triggerList []triggers.Trigger
|
||||
for _, cfg := range f {
|
||||
trigger, err := triggers.NewTrigger(cfg)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
trigger.Listen() //TODO: not block here
|
||||
triggerList = append(triggerList, trigger)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
# Available Triggers:
|
||||
|
||||
|
||||
### Timeout
|
||||
Description: Triggers after given duration.
|
||||
Values:
|
||||
- **duration**
|
||||
- Type: int
|
||||
- Descr: duration in seconds
|
||||
- Default: 0
|
||||
|
||||
# EthernetDisconnect
|
||||
Description: Triggers if Ethernetcable is disconnected.
|
||||
Values:
|
||||
- **waitTillConnected**
|
||||
- Type: bool
|
||||
- Descr: Only trigger when device was connected before
|
||||
- Default: true
|
||||
- **interfaceName**
|
||||
- Type: string
|
||||
- Descr: Name of ethernet adapter
|
||||
- Default: ""
|
||||
|
||||
### UsbDisconnect
|
||||
Description: Triggers when given usb drive is disconnected
|
||||
Values:
|
||||
- **waitTillConnected**
|
||||
- Type: bool
|
||||
- Descr: Only trigger when device was connected before
|
||||
- Default: true
|
||||
- **deviceId**
|
||||
- Type: string
|
||||
- Descr: Name of device under /dev/disk/by-id/
|
||||
- Default: ""
|
||||
|
||||
|
||||
# Available Actions:
|
||||
|
||||
|
||||
# Print
|
||||
Description: When triggered prints the configured message to stdout
|
||||
Values:
|
||||
- **message**
|
||||
- Type: string
|
||||
- Descr: Message that should be printed
|
||||
- Default: ""
|
||||
|
||||
### Timeout
|
||||
Description: When triggered waits given duration before continuing with next stage
|
||||
Values:
|
||||
- **duration**
|
||||
- Type: int
|
||||
- Descr: duration in seconds
|
||||
- Default: 0
|
||||
|
||||
# Command
|
||||
Description: When triggered executes given command
|
||||
Values:
|
||||
- **command**
|
||||
- Type: string
|
||||
- Descr: command to execute
|
||||
- Default:
|
||||
- **args**
|
||||
- Type: string[]
|
||||
- Descr: args
|
||||
- Default:
|
||||
|
||||
### Shutdown
|
||||
Description: When triggered shuts down the machine
|
||||
Values:
|
||||
|
||||
Reference in New Issue
Block a user