added NAT traversal
This commit is contained in:
223
config/config.go
223
config/config.go
@@ -1,127 +1,168 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
defaultPath string
|
defaultPath string
|
||||||
defaults = map[string]interface{}{
|
defaults = map[string]interface{}{
|
||||||
"SystemUsername": "",
|
"SystemUsername": "",
|
||||||
"BarrierHostName": "",
|
"BarrierHostName": "",
|
||||||
}
|
}
|
||||||
configName = "config"
|
configName = "config"
|
||||||
configType = "json"
|
configType = "json"
|
||||||
configFile = "config.json"
|
configFile = "config.json"
|
||||||
configPaths []string
|
configPaths []string
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
SystemUsername string
|
SystemUsername string
|
||||||
BarrierHostName string
|
BarrierHostName string
|
||||||
Rooms string
|
Rooms string
|
||||||
IPAddress string
|
IPAddress string
|
||||||
ScriptToExecute string
|
ScriptToExecute string
|
||||||
SSHPassword string
|
SSHPassword string
|
||||||
|
NATEscapeServerPort string
|
||||||
|
NATEscapeBarrierPort string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exists reports whether the named file or directory exists.
|
// Exists reports whether the named file or directory exists.
|
||||||
func fileExists(name string) bool {
|
func fileExists(name string) bool {
|
||||||
if _, err := os.Stat(name); err != nil {
|
if _, err := os.Stat(name); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDefaults This function to be called only during a
|
// SetDefaults This function to be called only during a
|
||||||
// make install
|
// make install
|
||||||
func SetDefaults() error {
|
func SetDefaults() error {
|
||||||
//Getting Current Directory from environment variable
|
//Getting Current Directory from environment variable
|
||||||
curDir := os.Getenv("REMOTEGAMING")
|
curDir := os.Getenv("REMOTEGAMING")
|
||||||
|
|
||||||
//Setting current directory to default path
|
//Setting current directory to default path
|
||||||
defaultPath = curDir + "/"
|
defaultPath = curDir + "/"
|
||||||
|
|
||||||
// Get system username
|
// Get system username
|
||||||
user, err := user.Current()
|
user, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Hostname
|
// Get Hostname
|
||||||
name, err := os.Hostname()
|
name, err := os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//Setting default paths for the config file
|
//Setting default paths for the config file
|
||||||
defaults["SystemUsername"] = user.Username
|
defaults["SystemUsername"] = user.Username
|
||||||
defaults["BarrierHostName"] = name
|
defaults["BarrierHostName"] = name
|
||||||
defaults["Rooms"] = defaultPath + "room.json"
|
defaults["Rooms"] = defaultPath + "room.json"
|
||||||
defaults["IPAddress"] = "0.0.0.0"
|
defaults["IPAddress"] = "0.0.0.0"
|
||||||
defaults["ScriptToExecute"] = ""
|
defaults["ScriptToExecute"] = ""
|
||||||
defaults["SSHPassword"] = ""
|
defaults["SSHPassword"] = ""
|
||||||
|
|
||||||
//Paths to search for config file
|
//Paths to search for config file
|
||||||
configPaths = append(configPaths, defaultPath)
|
configPaths = append(configPaths, defaultPath)
|
||||||
|
|
||||||
//Create rooms.json file
|
//Create rooms.json file
|
||||||
os.Create(defaultPath + "room.json")
|
os.Create(defaultPath + "room.json")
|
||||||
|
|
||||||
// If the config file exists remove and make a new one
|
// If the config file exists remove and make a new one
|
||||||
if fileExists(defaultPath + "config.json") {
|
if fileExists(defaultPath + "config.json") {
|
||||||
err = os.Remove(defaultPath + "config.json")
|
err = os.Remove(defaultPath + "config.json")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Calling configuration file
|
//Calling configuration file
|
||||||
_, err = ConfigInit()
|
_, err = ConfigInit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConfigInit() (*Config, error) {
|
func ConfigInit() (*Config, error) {
|
||||||
|
|
||||||
curDir := os.Getenv("REMOTEGAMING")
|
curDir := os.Getenv("REMOTEGAMING")
|
||||||
//Setting current directory to default path
|
//Setting current directory to default path
|
||||||
defaultPath = curDir + "/"
|
defaultPath = curDir + "/"
|
||||||
//Paths to search for config file
|
//Paths to search for config file
|
||||||
configPaths = append(configPaths, defaultPath)
|
configPaths = append(configPaths, defaultPath)
|
||||||
|
|
||||||
//Add all possible configurations paths
|
//Add all possible configurations paths
|
||||||
for _, v := range configPaths {
|
for _, v := range configPaths {
|
||||||
viper.AddConfigPath(v)
|
viper.AddConfigPath(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Read config file
|
//Read config file
|
||||||
if err := viper.ReadInConfig(); err != nil {
|
if err := viper.ReadInConfig(); err != nil {
|
||||||
// If the error thrown is config file not found
|
// If the error thrown is config file not found
|
||||||
//Sets default configuration to viper
|
//Sets default configuration to viper
|
||||||
for k, v := range defaults {
|
for k, v := range defaults {
|
||||||
viper.SetDefault(k, v)
|
viper.SetDefault(k, v)
|
||||||
}
|
}
|
||||||
viper.SetConfigName(configName)
|
viper.SetConfigName(configName)
|
||||||
viper.SetConfigFile(configFile)
|
viper.SetConfigFile(configFile)
|
||||||
viper.SetConfigType(configType)
|
viper.SetConfigType(configType)
|
||||||
|
|
||||||
if err = viper.WriteConfig(); err != nil {
|
if err = viper.WriteConfig(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds configuration to the struct
|
// Adds configuration to the struct
|
||||||
var config Config
|
var config Config
|
||||||
if err := viper.Unmarshal(&config); err != nil {
|
if err := viper.Unmarshal(&config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &config, nil
|
return &config, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Config) WriteConfig() error {
|
||||||
|
//Getting Current Directory from environment variable
|
||||||
|
curDir := os.Getenv("REMOTEGAMING")
|
||||||
|
|
||||||
|
//Setting current directory to default path
|
||||||
|
defaultPath = curDir + "/"
|
||||||
|
|
||||||
|
//Setting default paths for the config file
|
||||||
|
defaults["SystemUsername"] = c.SystemUsername
|
||||||
|
defaults["BarrierHostName"] = c.BarrierHostName
|
||||||
|
defaults["Rooms"] = c.Rooms
|
||||||
|
defaults["IPAddress"] = c.IPAddress
|
||||||
|
defaults["ScriptToExecute"] = c.ScriptToExecute
|
||||||
|
defaults["SSHPassword"] = c.SSHPassword
|
||||||
|
defaults["NATEscapeServerPort"] = c.NATEscapeServerPort
|
||||||
|
defaults["NATEscapeBarrierPort"] = c.NATEscapeBarrierPort
|
||||||
|
|
||||||
|
//Paths to search for config file
|
||||||
|
configPaths = append(configPaths, defaultPath)
|
||||||
|
|
||||||
|
//Create rooms.json file
|
||||||
|
os.Create(defaultPath + "room.json")
|
||||||
|
|
||||||
|
// If the config file exists remove and make a new one
|
||||||
|
if fileExists(defaultPath + "config.json") {
|
||||||
|
err := os.Remove(defaultPath + "config.json")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Calling configuration file
|
||||||
|
_, err := ConfigInit()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
165
core/escape-NAT.go
Normal file
165
core/escape-NAT.go
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatedier/frp/client"
|
||||||
|
"github.com/fatedier/frp/pkg/config"
|
||||||
|
"github.com/phayes/freeport"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Server struct {
|
||||||
|
address string
|
||||||
|
port int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client This struct stores
|
||||||
|
// client information with server
|
||||||
|
// proxy connected
|
||||||
|
type Client struct {
|
||||||
|
Name string
|
||||||
|
Server *Server
|
||||||
|
ClientMappings []ClientMapping
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClientMapping Stores client mapping ports
|
||||||
|
// to proxy server
|
||||||
|
type ClientMapping struct {
|
||||||
|
LocalIP string
|
||||||
|
LocalPort int
|
||||||
|
RemotePort int
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartFRPClientForServer Starts Server using FRP server
|
||||||
|
// returns back a port
|
||||||
|
func StartFRPClientForServer(ipaddress string, serverport string, localport string) (string, error) {
|
||||||
|
// Setup server information
|
||||||
|
var s Server
|
||||||
|
s.address = ipaddress
|
||||||
|
// convert serverport to int
|
||||||
|
portInt, err := strconv.Atoi(serverport)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
s.port = portInt
|
||||||
|
|
||||||
|
// Setup client information
|
||||||
|
var c Client
|
||||||
|
c.Name = "ServerPort"
|
||||||
|
c.Server = &s
|
||||||
|
|
||||||
|
// converts localport to int
|
||||||
|
portInt, err = strconv.Atoi(localport)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
//random serverport
|
||||||
|
//randPort := rangeIn(10000, 99999)
|
||||||
|
OpenPorts, err := freeport.GetFreePorts(1)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
c.ClientMappings = []ClientMapping{
|
||||||
|
{
|
||||||
|
LocalIP: "localhost",
|
||||||
|
LocalPort: portInt,
|
||||||
|
RemotePort: OpenPorts[0],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start client server
|
||||||
|
go c.StartFRPClient()
|
||||||
|
|
||||||
|
return strconv.Itoa(OpenPorts[0]), nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartFRPClient Starts FRP client
|
||||||
|
func (c *Client) StartFRPClient() error {
|
||||||
|
|
||||||
|
cfg := config.GetDefaultClientConf()
|
||||||
|
|
||||||
|
var proxyConfs map[string]config.ProxyConf
|
||||||
|
var visitorCfgs map[string]config.VisitorConf
|
||||||
|
|
||||||
|
proxyConfs = make(map[string]config.ProxyConf)
|
||||||
|
|
||||||
|
cfg.ServerAddr = c.Server.address
|
||||||
|
cfg.ServerPort = c.Server.port
|
||||||
|
|
||||||
|
for i, _ := range c.ClientMappings {
|
||||||
|
var tcpcnf config.TCPProxyConf
|
||||||
|
tcpcnf.LocalIP = c.ClientMappings[i].LocalIP
|
||||||
|
tcpcnf.LocalPort = c.ClientMappings[i].LocalPort
|
||||||
|
tcpcnf.RemotePort = c.ClientMappings[i].RemotePort
|
||||||
|
|
||||||
|
proxyConfs[tcpcnf.ProxyName] = &tcpcnf
|
||||||
|
}
|
||||||
|
|
||||||
|
cli, err := client.NewService(cfg, proxyConfs, visitorCfgs, "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cli.Run()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetFRPServerPort(host string) (string, error) {
|
||||||
|
resp, err := http.Get(host + "/FRPPort")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(body), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// EscapeNAT Func to escape NAT
|
||||||
|
// - 1 port for server
|
||||||
|
// - 2 port for barrierKVM
|
||||||
|
func EscapeNAT(Port string) (ServerPort string, barrierKVMport string, err error) {
|
||||||
|
// Get free port from P2PRC server node
|
||||||
|
serverPort, err := GetFRPServerPort("http://64.227.168.102:8088")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
// port for the remote gameplay server
|
||||||
|
ServerPort, err = StartFRPClientForServer("64.227.168.102", serverPort, Port)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get free port from P2PRC server node
|
||||||
|
serverPort, err = GetFRPServerPort("http://64.227.168.102:8088")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
|
//port for the barrierKVM server
|
||||||
|
barrierKVMport, err = StartFRPClientForServer("64.227.168.102", serverPort, "24800")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
16
core/escape-NAT_test.go
Normal file
16
core/escape-NAT_test.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestEscapeNAT(t *testing.T) {
|
||||||
|
nat, s, err := EscapeNAT("8090")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
fmt.Println(nat)
|
||||||
|
fmt.Println(s)
|
||||||
|
}
|
||||||
@@ -149,6 +149,9 @@ function initUI() {
|
|||||||
LaplaceVar.ui.SSHPassword = document.getElementById('SSHPassword')
|
LaplaceVar.ui.SSHPassword = document.getElementById('SSHPassword')
|
||||||
LaplaceVar.headless = { result :"0"};
|
LaplaceVar.headless = { result :"0"};
|
||||||
|
|
||||||
|
//getting server hostname
|
||||||
|
getServerIPandHostname()
|
||||||
|
|
||||||
LaplaceVar.ui.joinForm.onsubmit = async e => {
|
LaplaceVar.ui.joinForm.onsubmit = async e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
LaplaceVar.roomID = LaplaceVar.ui.inputRoomID.value;
|
LaplaceVar.roomID = LaplaceVar.ui.inputRoomID.value;
|
||||||
@@ -199,9 +202,6 @@ function initUI() {
|
|||||||
return startStream(mediaOption, pcOption);
|
return startStream(mediaOption, pcOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
//getting server hostname
|
|
||||||
getServerIPandHostname()
|
|
||||||
|
|
||||||
//getting SSHPassword
|
//getting SSHPassword
|
||||||
getSSHPassword()
|
getSSHPassword()
|
||||||
|
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -3,6 +3,8 @@ module github.com/Akilan1999/remotegameplay
|
|||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gorilla/websocket v1.4.2
|
github.com/fatedier/frp v0.47.0
|
||||||
|
github.com/gorilla/websocket v1.5.0
|
||||||
|
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
|
||||||
github.com/spf13/viper v1.8.1
|
github.com/spf13/viper v1.8.1
|
||||||
)
|
)
|
||||||
|
|||||||
268
main.go
268
main.go
@@ -1,163 +1,183 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Akilan1999/remotegameplay/config"
|
"github.com/Akilan1999/remotegameplay/config"
|
||||||
"github.com/Akilan1999/remotegameplay/core"
|
"github.com/Akilan1999/remotegameplay/core"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
addr := flag.String("addr", "0.0.0.0:443", "Listen address")
|
addr := flag.String("addr", "localhost", "Listen address")
|
||||||
port := flag.String("port", "8888", "port for running the server")
|
port := flag.String("port", "8888", "port for running the server")
|
||||||
tls := flag.Bool("tls", false, "Use TLS")
|
tls := flag.Bool("tls", false, "Use TLS")
|
||||||
setconfig := flag.Bool("setconfig", false, "Generates a config file")
|
setconfig := flag.Bool("setconfig", false, "Generates a config file")
|
||||||
certFile := flag.String("certFile", "files/server.crt", "TLS cert file")
|
certFile := flag.String("certFile", "files/server.crt", "TLS cert file")
|
||||||
keyFile := flag.String("keyFile", "files/server.key", "TLS key file")
|
keyFile := flag.String("keyFile", "files/server.key", "TLS key file")
|
||||||
headless := flag.Bool("headless", false, "Creating screenshare using headless mode")
|
headless := flag.Bool("headless", false, "Creating screenshare using headless mode")
|
||||||
roomInfo := flag.Bool("roomInfo", false, "Getting room id of headless server")
|
roomInfo := flag.Bool("roomInfo", false, "Getting room id of headless server")
|
||||||
killServer := flag.Bool("killServer", false, "Kills the laplace")
|
killServer := flag.Bool("killServer", false, "Kills the laplace")
|
||||||
killChromium := flag.Bool("killChromium", false, "Kills all chromuim")
|
killChromium := flag.Bool("killChromium", false, "Kills all chromuim")
|
||||||
BinaryToExcute := flag.String("BinaryToExecute", "", "Providing path (i.e Absolute path) of binary to execute")
|
BinaryToExcute := flag.String("BinaryToExecute", "", "Providing path (i.e Absolute path) of binary to execute")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Action performed when the config file is called
|
// Action performed when the config file is called
|
||||||
if *setconfig {
|
if *setconfig {
|
||||||
config.SetDefaults()
|
config.SetDefaults()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
server := core.GetHttp()
|
server := core.GetHttp()
|
||||||
|
|
||||||
// Print out room information
|
// Print out room information
|
||||||
if *roomInfo {
|
if *roomInfo {
|
||||||
room, err := core.ReadRoomsFile()
|
room, err := core.ReadRoomsFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
PrettyPrint(room)
|
PrettyPrint(room)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Running in headless mode
|
// Running in headless mode
|
||||||
if *headless {
|
if *headless {
|
||||||
Config, err := config.ConfigInit()
|
Config, err := config.ConfigInit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the URl address type
|
// Returns the URl address type
|
||||||
Addr := Ip4or6(Config.IPAddress)
|
Addr := Ip4or6(Config.IPAddress)
|
||||||
|
|
||||||
// If address is provided
|
// If address is provided
|
||||||
if *addr != "" {
|
if *addr != "" {
|
||||||
Addr = *addr
|
Addr = *addr
|
||||||
// Add brackets if the ip address is ipv6
|
// Add brackets if the ip address is ipv6
|
||||||
Addr = Ip4or6(Addr)
|
Addr = Ip4or6(Addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
var TaskExecute string
|
var TaskExecute string
|
||||||
|
|
||||||
if *BinaryToExcute != "" {
|
if *BinaryToExcute != "" {
|
||||||
TaskExecute = *BinaryToExcute
|
TaskExecute = *BinaryToExcute
|
||||||
} else {
|
} else {
|
||||||
// Read binary from config file
|
// Read binary from config file
|
||||||
TaskExecute = Config.ScriptToExecute
|
TaskExecute = Config.ScriptToExecute
|
||||||
}
|
}
|
||||||
|
|
||||||
// Starting screen share headless
|
// Starting screen share headless
|
||||||
cmd := exec.Command("chromium-browser", "--no-sandbox", "--auto-select-desktop-capture-source=Entire screen", "--url", "https://"+Addr+":"+*port+"/?mode=headless", "--ignore-certificate-errors")
|
cmd := exec.Command("chromium-browser", "--no-sandbox", "--auto-select-desktop-capture-source=Entire screen", "--url", "https://"+Addr+":"+*port+"/?mode=headless", "--ignore-certificate-errors")
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makes program sleep for 2 seconds to allow chromium browser to open
|
// Makes program sleep for 2 seconds to allow chromium browser to open
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
// Task to be executed
|
// Task to be executed
|
||||||
err = RunTask(TaskExecute)
|
err = RunTask(TaskExecute)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// kills laplace server
|
// kills laplace server
|
||||||
if *killServer {
|
if *killServer {
|
||||||
cmd := exec.Command("pkill", "remotegameplay")
|
cmd := exec.Command("pkill", "remotegameplay")
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// kills chromium server
|
// kills chromium server
|
||||||
if *killChromium {
|
if *killChromium {
|
||||||
cmd := exec.Command("pkill", "chromium")
|
cmd := exec.Command("pkill", "chromium")
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// running implementation to escape NAT
|
||||||
|
Server, barrireKVM, err := core.EscapeNAT(*port)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
Config, err := config.ConfigInit()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
Config.IPAddress = "64.227.168.102"
|
||||||
|
Config.NATEscapeServerPort = Server
|
||||||
|
Config.NATEscapeBarrierPort = barrireKVM
|
||||||
|
|
||||||
|
err = Config.WriteConfig()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if *tls {
|
||||||
|
log.Println("Listening on TLS:", *addr+":"+*port)
|
||||||
|
if err := http.ListenAndServeTLS(*addr+":"+*port, *certFile, *keyFile, server); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Println("Listening:", *addr+":"+*port)
|
||||||
|
if err := http.ListenAndServe(*addr+":"+*port, server); err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if *tls {
|
|
||||||
log.Println("Listening on TLS:", *addr)
|
|
||||||
if err := http.ListenAndServeTLS(*addr, *certFile, *keyFile, server); err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.Println("Listening:", *addr)
|
|
||||||
if err := http.ListenAndServe(*addr, server); err != nil {
|
|
||||||
log.Fatalln(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrettyPrint print the contents of the obj (
|
// PrettyPrint print the contents of the obj (
|
||||||
// Reference: https://stackoverflow.com/questions/24512112/how-to-print-struct-variables-in-console
|
// Reference: https://stackoverflow.com/questions/24512112/how-to-print-struct-variables-in-console
|
||||||
func PrettyPrint(data interface{}) {
|
func PrettyPrint(data interface{}) {
|
||||||
var p []byte
|
var p []byte
|
||||||
// var err := error
|
// var err := error
|
||||||
p, err := json.MarshalIndent(data, "", "\t")
|
p, err := json.MarshalIndent(data, "", "\t")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("%s \n", p)
|
fmt.Printf("%s \n", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ip4or6 Helper function to check if the IP address is IPV4 or
|
// 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)
|
//IPV6 (https://socketloop.com/tutorials/golang-check-if-ip-address-is-version-4-or-6)
|
||||||
func Ip4or6(s string) string {
|
func Ip4or6(s string) string {
|
||||||
for i := 0; i < len(s); i++ {
|
for i := 0; i < len(s); i++ {
|
||||||
switch s[i] {
|
switch s[i] {
|
||||||
case '.':
|
case '.':
|
||||||
return s
|
return s
|
||||||
case ':':
|
case ':':
|
||||||
return "[" + s + "]"
|
return "[" + s + "]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "[" + s + "]"
|
return "[" + s + "]"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunTask(task string) error {
|
func RunTask(task string) error {
|
||||||
// Halts the process
|
// Halts the process
|
||||||
cmd := exec.Command("sh", task)
|
cmd := exec.Command("sh", task)
|
||||||
if err := cmd.Start(); err != nil {
|
if err := cmd.Start(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user