2019-11-12 01:10:00 +00:00
//go:generate goversioninfo -manifest=setup.exe.manifest
//Add new firewall rule in Go.
package main
import (
"os"
"os/exec"
"io/ioutil"
"syscall"
"fmt"
"log"
"static" // Your fileb0x.
)
func main ( ) {
// Grab files from virtual filesystem
files , err := static . WalkDirs ( "" , false )
if err != nil {
log . Fatal ( err )
log . Println ( "ALL FILES" , files )
}
// here we'll read the file from the virtual file system
b , err := static . ReadFile ( "server.exe" )
if err != nil {
log . Fatal ( err )
}
// Copy file from virtual filesystem to real filesystem
err = ioutil . WriteFile ( "server.exe" , b , 0644 )
if err != nil {
fmt . Println ( "Error creating" , "server.exe" )
fmt . Println ( err )
return
}
// Get current working directory and set it to 'dir'.
dir , err := os . Getwd ( )
if err != nil {
log . Fatal ( err )
}
// Set server file path to 'file'
var file = "-Program '" + dir + "\\server.exe'"
2019-11-20 22:31:40 +00:00
//Create firewall rule if no firewall rule exists.
cmdinstance := exec . Command ( "powershell.exe" , "-WindowStyle" , "Hidden" , "-Command" , "$r" , "=" , "Get-NetFirewallRule" , "-DisplayName" , "'Go Web Server'" , "2>" , "$null;" , "if" , "($r)" , "{write-host 'found rule';}" , "else" , "{New-NetFirewallRule" , "-DisplayName" , "'Go Web Server'" , "-Direction" , "Inbound" , file , "-Action" , "Allow}" )
2019-11-12 01:10:00 +00:00
cmdinstance . SysProcAttr = & syscall . SysProcAttr { HideWindow : true } // Make it silent.
2019-11-12 04:31:06 +00:00
cmdinstance2 := exec . Command ( "cmd" , "/C" , "start" , "http://localhost:8100" )
cmdinstance2 . SysProcAttr = & syscall . SysProcAttr { HideWindow : true } // Make it silent.
2019-11-13 00:02:46 +00:00
cmdinstance3 := exec . Command ( "cmd" , "/K" , "start" , "server.exe" )
2019-11-12 04:24:15 +00:00
cmdinstance3 . SysProcAttr = & syscall . SysProcAttr { HideWindow : true } // Make it silent.
2019-11-12 04:31:06 +00:00
2019-11-12 01:10:00 +00:00
cmdoutput , cmderr := cmdinstance . Output ( )
if cmderr != nil {
fmt . Println ( cmderr )
fmt . Println ( cmdoutput )
}
2019-11-12 04:24:15 +00:00
cmdoutput2 , cmderr2 := cmdinstance2 . Output ( )
if cmderr != nil {
fmt . Println ( cmderr2 )
fmt . Println ( cmdoutput2 )
}
cmdoutput3 , cmderr3 := cmdinstance3 . Output ( )
if cmderr != nil {
fmt . Println ( cmderr3 )
fmt . Println ( cmdoutput3 )
}
2019-11-12 01:10:00 +00:00
}