reading ip address to start headless browser from config file

This commit is contained in:
2021-07-25 09:07:07 +04:00
parent 345a657bbd
commit b5b38bda46
3 changed files with 26 additions and 86 deletions

26
main.go
View File

@@ -49,14 +49,23 @@ func main() {
// Running in headless mode
if *headless {
Config, err := config.ConfigInit()
if err != nil {
log.Fatalln(err)
}
// Returns the URl address type
Addr := Ip4or6(Config.IPAddress)
// Starting screen share headless
cmd := exec.Command("chromium" ,"--auto-select-desktop-capture-source=Entire screen","--url","https://" + *addr + "/?mode=headless","--ignore-certificate-errors")
cmd := exec.Command("chromium" ,"--auto-select-desktop-capture-source=Entire screen","--url","https://" + Addr + ":8888/?mode=headless","--ignore-certificate-errors")
if err := cmd.Run(); err != nil {
log.Fatalln(err)
}
return
}
// kills laplace server
if *killServer {
cmd := exec.Command("pkill" ,"laplace")
@@ -100,3 +109,18 @@ func PrettyPrint(data interface{}) {
}
fmt.Printf("%s \n", p)
}
// Ip4or6 Helper function to check if the IP address is IPV4 or
//IPV6 (https://socketloop.com/tutorials/golang-check-if-ip-address-is-version-4-or-6)
func Ip4or6(s string) string {
for i := 0; i < len(s); i++ {
switch s[i] {
case '.':
return s
case ':':
return "[" + s + "]"
}
}
return "[" + s + "]"
}