Skip to content

Commit

Permalink
Merge pull request #1 from r1c0n/1.3.0
Browse files Browse the repository at this point in the history
1.3.0 rc1
  • Loading branch information
r1c0n authored Jun 28, 2023
2 parents 8185447 + 136ff6b commit e53a958
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 69 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
![](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)
6 changes: 4 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
19 changes: 10 additions & 9 deletions build.py
Original file line number Diff line number Diff line change
@@ -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"):
Expand All @@ -11,25 +12,25 @@
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",
"tls_config": {
"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")

Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
8 changes: 8 additions & 0 deletions gws-data.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
56 changes: 56 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -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)
}
53 changes: 2 additions & 51 deletions server.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit e53a958

Please sign in to comment.