diff --git a/README.md b/README.md index 792e5d1..0c7a32c 100644 --- a/README.md +++ b/README.md @@ -45,4 +45,4 @@ Here is an example of what the **config.json** should look like. ``` ## Misc. Info -![](https://img.shields.io/github/go-mod/go-version/gamma-gws/gws) ![](https://img.shields.io/github/v/release/gamma-gws/gws?include_prereleases) ![](https://img.shields.io/github/license/gamma-gws/gws) \ No newline at end of file +![](https://img.shields.io/github/go-mod/go-version/r1con/gws) ![](https://img.shields.io/github/v/release/r1c0n/gws?include_prereleases) ![](https://img.shields.io/github/license/r1c0n/gws) \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md index fb66279..ce4fed6 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,9 +6,11 @@ This is the security policy for the GWS. | Version | Supported | | ------- | ------------------ | -| 1.1.x | :white_check_mark: | +| 1.3.x | :white_check_mark: | +| 1.2.x | :white_check_mark: | +| 1.1.x | :x: | | 1.0.x | :x: | ## Reporting a Vulnerability -To report a vulnerability in the GWS code, please [create an issue](https://github.com/gamma-gws/gws/issues). +To report a vulnerability in the GWS code, please [create an issue](https://github.com/r1c0n/gws/issues). diff --git a/build.py b/build.py index 54411fd..666455d 100644 --- a/build.py +++ b/build.py @@ -1,6 +1,7 @@ import os import shutil import zipfile +import json # create bin folder if it doesn't exist if not os.path.exists("./bin"): @@ -11,8 +12,13 @@ os.system("go build -o ./bin/gws.exe") print("Project files built") +# read repo_config from gws-data.json +with open("gws-data.json", "r") as data_file: + data = json.load(data_file) + repo_config = data.get("repo_config") + # create config.json -config_data = '''{ +config_data = { "port": ":8080", "domain": "localhost", "static_dir": "html", @@ -20,16 +26,11 @@ "cert_file": "server.crt", "key_file": "server.key" }, - "repo_config": { - "version": "1.2.0", - "author": "recon (contact@mail.recon.best)", - "product": "Gamma Web Server", - "repository": "https://github.com/gamma-gws/gws" - } -}''' + "repo_config": repo_config +} with open("./bin/config.json", "w") as config_file: - config_file.write(config_data) + json.dump(config_data, config_file, indent=4) print("Config created") diff --git a/go.sum b/go.sum index 0c6ea32..84d440e 100644 --- a/go.sum +++ b/go.sum @@ -2,15 +2,9 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3 h1:fO9A67/izFYFYky7l1pDP5Dr0BTCRkaQJUG6Jm5ehsk= github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3/go.mod h1:Ey4uAp+LvIl+s5jRbOHLcZpUDnkjLBROl15fZLwPlTM= -golang.org/x/crypto v0.4.0 h1:UVQgzMY87xqpKNgb+kDsll2Igd33HszWHFLmpaRMq/8= -golang.org/x/crypto v0.4.0/go.mod h1:3quD/ATkf6oY+rnes5c3ExXTbLc8mueNue5/DoinL80= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= -golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ= -golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI= -golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= diff --git a/gws-data.json b/gws-data.json new file mode 100644 index 0000000..f3e9bd7 --- /dev/null +++ b/gws-data.json @@ -0,0 +1,8 @@ +{ + "repo_config": { + "version": "1.3.0", + "author": "recon (contact@mail.recon.best)", + "product": "Gamma Web Server", + "repository": "https://github.com/gamma-gws/gws" + } +} \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..64e70b2 --- /dev/null +++ b/main.go @@ -0,0 +1,56 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "log" + + "github.com/inancgumus/screen" +) + +type Config struct { + Port string `json:"port"` + Domain string `json:"domain"` + StaticDir string `json:"static_dir"` + TLSConfig struct { + CertFile string `json:"cert_file"` + KeyFile string `json:"key_file"` + } `json:"tls_config"` + RepoConfig struct { + Version string `json:"version"` + Author string `json:"author"` + Product string `json:"product"` + Repository string `json:"repository"` + } `json:"repo_config"` +} + +func main() { + config := loadConfig("config.json") + + printHeader(config) + startServer(config) +} + +func loadConfig(filename string) Config { + configData, err := ioutil.ReadFile(filename) + if err != nil { + log.Fatal(err) + } + + var config Config + if err := json.Unmarshal(configData, &config); err != nil { + log.Fatal(err) + } + + return config +} + +func printHeader(config Config) { + screen.Clear() + fmt.Printf("Hello, World! | %s v%s | Created by %s\n", config.RepoConfig.Product, config.RepoConfig.Version, config.RepoConfig.Author) + fmt.Printf("To contribute, check out our GitHub repo: %s\n", config.RepoConfig.Repository) + fmt.Println("----------------------------------------------------------------------------") + fmt.Printf("To exit the program, enter the key combination \"CTRL + C\".\n") + fmt.Printf("Site URL: http://%s%s\n", config.Domain, config.Port) +} diff --git a/server.go b/server.go index d69845c..40fd451 100644 --- a/server.go +++ b/server.go @@ -1,65 +1,16 @@ package main import ( - "encoding/json" - "fmt" - "io/ioutil" - "log" "net/http" "github.com/gorilla/mux" - "github.com/inancgumus/screen" ) -type Config struct { - Port string `json:"port"` // Port is the port number that the server will listen on. - Domain string `json:"domain"` // Domain represents the hostname or address of the server. - StaticDir string `json:"static_dir"` // StaticDir is the directory where static assets (e.g. HTML, CSS, JavaScript) are stored. +func startServer(config Config) { + r := mux.NewRouter() - // TLSConfig contains configuration options for TLS (Transport Layer Security). - TLSConfig struct { - CertFile string `json:"cert_file"` // CertFile is the path to the TLS certificate file. - KeyFile string `json:"key_file"` // KeyFile is the path to the TLS key file. - } `json:"tls_config"` - - // RepoConfig contains information about the repository. - RepoConfig struct { - Version string `json:"version"` // Version is the version of the repository. - Author string `json:"author"` // Author is the author of the repository. - Product string `json:"product"` // Product is the name of the product that the repository is for. - Repository string `json:"repository"` // Repository is the name of the repository. - } `json:"repo_config"` -} - -func main() { - // Read the configuration file - configData, err := ioutil.ReadFile("config.json") - if err != nil { - log.Fatal(err) // If there is an error reading the file, log the error and exit the program. - } - - // Parse the configuration data into a Config struct. - var config Config - if err := json.Unmarshal(configData, &config); err != nil { - log.Fatal(err) // If there is an error parsing the data, log the error and exit the program. - } - - // Clear the screen. - screen.Clear() - - // Print a message coontaining information from the Config struct. Mostly repository information. - fmt.Print("Hello, World! | ", config.RepoConfig.Product, " v", config.RepoConfig.Version, " | Created by ", config.RepoConfig.Author) - fmt.Print("\nTo contribute, check out our GitHub repo: ", config.RepoConfig.Repository, ".") - fmt.Print("\n----------------------------------------------------------------------------\n") - fmt.Print("To exit the program, enter the key combination \"CTRL + C\".\n") - fmt.Print("Site URL: http://", config.Domain, config.Port, "\n") - - r := mux.NewRouter() // Create a new router. - - // Set up a FileServer to serve static assets. fs := http.FileServer(http.Dir(config.StaticDir)) r.PathPrefix("/").Handler(http.StripPrefix("/", fs)) - // Start the server. http.ListenAndServe(config.Port, r) }