added fix for update function for config file

This commit is contained in:
2023-02-25 00:26:04 +00:00
parent 50530866ed
commit 4011f3e83f
2 changed files with 35 additions and 26 deletions

View File

@@ -1,7 +1,9 @@
package config package config
import ( import (
"encoding/json"
"github.com/spf13/viper" "github.com/spf13/viper"
"io/ioutil"
"os" "os"
"os/user" "os/user"
) )
@@ -131,33 +133,37 @@ func ConfigInit() (*Config, error) {
func (c *Config) WriteConfig() error { func (c *Config) WriteConfig() 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 + "/"
//
//Setting default paths for the config file ////Setting default paths for the config file
defaults["SystemUsername"] = c.SystemUsername //defaults["SystemUsername"] = c.SystemUsername
defaults["BarrierHostName"] = c.BarrierHostName //defaults["BarrierHostName"] = c.BarrierHostName
defaults["Rooms"] = c.Rooms //defaults["Rooms"] = c.Rooms
defaults["IPAddress"] = c.IPAddress //defaults["IPAddress"] = c.IPAddress
defaults["ScriptToExecute"] = c.ScriptToExecute //defaults["ScriptToExecute"] = c.ScriptToExecute
defaults["SSHPassword"] = c.SSHPassword //defaults["SSHPassword"] = c.SSHPassword
defaults["NATEscapeServerPort"] = c.NATEscapeServerPort //defaults["NATEscapeServerPort"] = c.NATEscapeServerPort
defaults["NATEscapeBarrierPort"] = c.NATEscapeBarrierPort //defaults["NATEscapeBarrierPort"] = c.NATEscapeBarrierPort
// 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
} //}
file, _ := json.MarshalIndent(c, "", " ")
_ = ioutil.WriteFile("config.json", file, 0644)
return nil return nil
} }

View File

@@ -18,7 +18,7 @@ func main() {
addr := flag.String("addr", "localhost", "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")
@@ -34,8 +34,11 @@ func main() {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
server := core.GetHttp() server := core.GetHttp()
err := config.SetDefaults() if *setconfig {
if err != nil { err := config.SetDefaults()
if err != nil {
return
}
return return
} }