diff options
| author | Jeff Carr <[email protected]> | 2024-01-01 15:27:59 -0600 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-01 15:27:59 -0600 | 
| commit | 5e485f20d9893034eb37d4c92608ee4cb9b57c6a (patch) | |
| tree | 72e86e072513a5e3165e11bc1d946ce86a77c36b | |
initial commit
Signed-off-by: Jeff Carr <[email protected]>
| -rw-r--r-- | .gitignore | 7 | ||||
| -rw-r--r-- | Makefile | 27 | ||||
| -rw-r--r-- | argv.go | 17 | ||||
| -rw-r--r-- | config.go | 72 | ||||
| -rw-r--r-- | main.go | 35 | 
5 files changed, 158 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5c613c6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +control-panel-dns +/files/* +/*.deb +*.swp +/plugins/* + +control-panel-cloudflare diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c5947f9 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +run: build +	./control-panel-cloudflare + +build-release: +	go get -v -u -x . +	go build +	./control-panel-cloudflare + +build: +	GO111MODULE="off" go get -v -x . +	GO111MODULE="off" go build + +update: +	GO111MODULE="off" go get -v -u -x . + +log: +	reset +	tail -f /tmp/witgui.* /tmp/guilogfile + +debug: build +	./control-panel-cloudflare --gui-debug + +gocui: build +	./control-panel-cloudflare --gui gocui >/tmp/witgui.log.stderr 2>&1 + +quiet: +	./control-panel-cloudflare >/tmp/witgui.log.stderr 2>&1 @@ -0,0 +1,17 @@ +package main + +/* +	this enables command line options from other packages like 'gui' and 'log' +*/ + +import 	( +	arg "github.com/alexflint/go-arg" +	"go.wit.com/gui/gui" +	"go.wit.com/log" +) + + +func init() { +	arg.MustParse() +	log.Bool(true, "INIT() args.ArgDebug =", gui.ArgDebug()) +} diff --git a/config.go b/config.go new file mode 100644 index 0000000..a3cf226 --- /dev/null +++ b/config.go @@ -0,0 +1,72 @@ +package main + +import 	( +	"os" +	"log" +	"bufio" +	"strings" + +	"go.wit.com/control-panel-dns/cloudflare" +) + +var configfile string = ".config/wit/cloudflare" + +func saveConfig() { +	log.Println("TODO") +} + +func readConfig() { +	homeDir, err := os.UserHomeDir() +	if err != nil { +		log.Println("searchPaths() error. exiting here?") +	} +	filename := homeDir + "/" + configfile +	log.Println("filename =", filename) + +	readFileLineByLine(filename) +	// os.Exit(0) +} + +// readFileLineByLine opens a file and reads through each line. +func readFileLineByLine(filename string) error { +	// Open the file. +	file, err := os.Open(filename) +	if err != nil { +		return err +	} +	defer file.Close() + +	log.Println("readFileLineByLine() =", filename) + +	// Create a new Scanner for the file. +	scanner := bufio.NewScanner(file) + +	// Read through each line using scanner. +	for scanner.Scan() { +		var newc *cloudflare.ConfigT +		newc = new(cloudflare.ConfigT) + +		line := scanner.Text() +		parts := strings.Fields(line) + +		if (len(parts) < 4) { +			log.Println("readFileLineByLine() SKIP =", parts) +			continue +		} + +		newc.Domain = parts[0] +		newc.ZoneID = parts[1] +		newc.Auth = parts[2] +		newc.Email = parts[3] + +		cloudflare.Config[parts[0]] = newc +		log.Println("readFileLineByLine() =", newc.Domain, newc.ZoneID, newc.Auth, newc.Email) +	} + +	// Check for errors during Scan. +	if err := scanner.Err(); err != nil { +		return err +	} + +	return nil +} @@ -0,0 +1,35 @@ +package main + +import 	( +	"go.wit.com/log" +	"go.wit.com/gui/gui" +	"go.wit.com/gui/cloudflare" +) + +var title string = "Cloudflare DNS Control Panel" + +var myGui *gui.Node + +// var cloudflareURL string = "https://api.cloudflare.com/client/v4/zones/" + +func main() { +	// send all log() output to a file in /tmp +	log.SetTmp() + +	// parse the config file +	readConfig() + +	// initialize a new GO GUI instance +	myGui = gui.New().Default() + +	// draw the cloudflare control panel window +	win := cloudflare.MakeCloudflareWindow(myGui) +	win.SetText(title) + +	// This is just a optional goroutine to watch that things are alive +	gui.Watchdog() +	gui.StandardExit() + +	// update the config file +	saveConfig() +}  | 
