Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 38 additions & 43 deletions cmd/gui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"net/http"
"time"
Expand All @@ -20,7 +20,7 @@ func main() {
defer ui.Close()
termWidth, termHeight := ui.TerminalDimensions()
title := widgets.NewParagraph()
title.Text = "Welcome to Miniatureby DevGenie, press q to quit"
title.Text = "Welcome to Miniature by DevGenie, press q to quit. Total runtime: n/a"
title.TextStyle.Modifier = ui.ModifierBold
title.WrapText = true
title.TextStyle.Fg = ui.ColorGreen
Expand All @@ -30,48 +30,46 @@ func main() {
title.PaddingRight = 1
title.PaddingLeft = 1

info := widgets.NewList()
info.BorderStyle.Fg = ui.ColorCyan
info.Title = "Info"
info.TitleStyle.Fg = ui.ColorGreen

systemStats := widgets.NewList()
systemStats.BorderStyle.Fg = ui.ColorCyan
systemStats.Title = "System"
systemStats.TitleStyle.Fg = ui.ColorGreen
networkDataIn := widgets.NewSparkline()
networkDataIn.Title = "Bytes in"
networkDataIn.Data = make([]float64, 0)
networkDataIn.LineColor = ui.ColorGreen
networkDataIn.TitleStyle.Modifier = ui.ModifierBold
networkDataIn.TitleStyle.Fg = ui.ColorGreen

peerStats := widgets.NewList()
peerStats.BorderStyle.Fg = ui.ColorCyan
peerStats.Title = "Peers"
peerStats.TitleStyle.Fg = ui.ColorGreen
networkDataOut := widgets.NewSparkline()
networkDataOut.Title = "Bytes out"
networkDataOut.Data = make([]float64, 0)
networkDataOut.LineColor = ui.ColorCyan
networkDataOut.TitleStyle.Modifier = ui.ModifierBold
networkDataOut.TitleStyle.Fg = ui.ColorCyan

networkStats := widgets.NewList()
networkStats.BorderStyle.Fg = ui.ColorCyan
networkStats.Title = "Network"
networkStats.TitleStyle.Fg = ui.ColorGreen

networkData := widgets.NewSparkline()
networkData.Title = "Peers connected: 0"
networkData.LineColor = ui.ColorCyan
networkData.Data = make([]float64, 1)
networkData.TitleStyle.Modifier = ui.ModifierBold
networkData.TitleStyle.Fg = ui.ColorGreen

sparklineGroup := widgets.NewSparklineGroup(networkData)
sparklineGroup := widgets.NewSparklineGroup(networkDataIn, networkDataOut)
sparklineGroup.Title = "Network stats"

grid := ui.NewGrid()
grid.SetRect(0, 0, termWidth, termHeight)

grid.Set(
ui.NewRow(0.4/6,title),
ui.NewRow(0.4/6, title),
ui.NewRow(5.6/6,
ui.NewCol(1.0/4,
ui.NewRow(2.0/6,systemStats),
ui.NewRow(2.0/6,peerStats),
ui.NewRow(2.0/6,networkStats),
ui.NewRow(2.0/6, info),
),
ui.NewCol(3.0/4, sparklineGroup),
),
)

ui.Render(grid)
tickerCount := 1
lastConnIn := new(int)
lastConnOut := new(int)
*lastConnIn = 0
*lastConnOut = 0
uiEvents := ui.PollEvents()
ticker := time.NewTicker(time.Second).C
for {
Expand All @@ -89,21 +87,18 @@ func main() {
}
case <-ticker:
usageStats := callStats()
generalStatsRows := []string{fmt.Sprintf("Available: %d", usageStats.AvailableSlots),
fmt.Sprintf("Total: %d", usageStats.AvailableSlots),
fmt.Sprintf("Connected: %d", usageStats.Peers),
fmt.Sprintf("Bytes in: %d", usageStats.ConnectionsIn),
fmt.Sprintf("Bytes out: %d", usageStats.ConnectionsOut),
}

systemStatsRows := []string{fmt.Sprintf("Running time: %s", usageStats.TimeElapsed),
title.Text = fmt.Sprintf("Welcome to Miniature by DevGenie, press q to quit. Total runtime: %s", usageStats.TimeElapsed)
generalStatsRows := []string{
fmt.Sprintf("Available connections: %d", usageStats.AvailableSlots),
fmt.Sprintf("Peers connected: %d", usageStats.Peers),
fmt.Sprintf("Total bytes in: %d", usageStats.ConnectionsIn),
fmt.Sprintf("Total bytes out: %d", usageStats.ConnectionsOut),
}
networkData.Data = append(networkData.Data, float64(usageStats.Peers))
peerStats.Rows = generalStatsRows
systemStats.Rows = systemStatsRows

networkDataIn.Data = append(networkDataIn.Data, float64(usageStats.ConnectionsIn))
networkDataOut.Data = append(networkDataOut.Data, float64(usageStats.ConnectionsOut))
info.Rows = generalStatsRows
ui.Render(grid)
tickerCount++
networkData.Title = fmt.Sprintf("Peers Connected: %d %s", tickerCount, termWidth)
}
}
}
Expand All @@ -121,11 +116,11 @@ func callStats() miniature.Stats {
fmt.Print(err.Error())
}
defer resp.Body.Close()
bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Print(err.Error())
}
var responseObject miniature.Stats
json.Unmarshal(bodyBytes, &responseObject)
return responseObject
}
}
27 changes: 12 additions & 15 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,31 @@ func main() {
serverConfigFlag := runFlag.String("config", "/etc/miniature/config.yml", "Server configuration file")

clientConfig := flag.NewFlagSet("newclient", flag.ExitOnError)
configFile := clientConfig.String("config", "/etc/miniature/config.yml", "Server Configuration File")
username := clientConfig.String("username", "", "Username")
password := clientConfig.String("password", "", "Password")

if len(os.Args) > 1 {
switch os.Args[1] {
case "newclient":
serverConfig := new(miniature.ServerConfig)
if len(os.Args) == 3 {
if len(os.Args) == 4 {
err := clientConfig.Parse(os.Args[2:])
if err != nil {
log.Fatal(err)
}
serverConfigYamlPath := *configFile
err = utilities.FileToYaml(serverConfigYamlPath, serverConfig)

db := new(miniature.DatabaseObject)
db.Init()
vpnUser := new(miniature.User)
vpnUser.Username = *username
vpnUser.Password = *password

err = db.AddUser(vpnUser)
if err != nil {
log.Fatal(err)
}
} else {
serverConfig.CertificatesDirectory = "/etc/miniature/certs"
serverConfig.Network = "10.2.0.0/24"
}
server := new(miniature.Server)
server.Config = *serverConfig
config, err := server.CreateClientConfig()
if err != nil {
log.Fatal(err)
break
log.Println(os.Args)
}
log.Println(config)
case "run":
startServer(*serverConfigFlag)
if len(os.Args) == 3 {
Expand Down
6 changes: 5 additions & 1 deletion dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM golang:1.12.5-alpine
FROM golang:1.21.5-alpine
RUN apk update
RUN apk upgrade
RUN apk add git
RUN apk add sqlite
RUN apk add iptables
RUN apk add bash
RUN apk add curl
Expand All @@ -12,3 +13,6 @@ RUN mkdir /miniature
COPY . /miniature
WORKDIR /miniature
RUN export GO111MODULE=on
EXPOSE 8080
EXPOSE 443
EXPOSE 4321/udp
54 changes: 44 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
module github.com/devgenie/miniature

go 1.12
go 1.21

toolchain go1.21.5

require (
fyne.io/fyne/v2 v2.1.3
github.com/aead/ecdh v0.2.0
github.com/gizak/termui/v3 v3.1.0 // indirect
github.com/go-chi/chi v1.5.4 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/lithammer/shortuuid/v3 v3.0.5
github.com/gizak/termui/v3 v3.1.0
github.com/go-chi/chi v1.5.4
github.com/pierrec/lz4 v2.6.0+incompatible
github.com/pierrec/lz4/v4 v4.1.3
github.com/rickb777/date v1.20.5
github.com/robfig/cron v1.2.0
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
golang.org/x/net v0.18.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/mattn/go-sqlite3 v1.14.19 // indirect
gorm.io/driver/sqlite v1.5.4 // indirect
gorm.io/gorm v1.25.5 // indirect
)

require (
fyne.io/fyne v1.4.3
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/frankban/quicktest v1.14.2 // indirect
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-gl/gl v0.0.0-20210813123233-e4099ee2221f // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211024062804-40e447a793be // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff // indirect
github.com/mattn/go-runewidth v0.0.2 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d // indirect
github.com/onsi/gomega v1.30.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rickb777/plural v1.4.1 // indirect
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 // indirect
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 // indirect
github.com/stretchr/testify v1.6.1 // indirect
github.com/yuin/goldmark v1.4.13 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v2 v2.4.0
)
129 changes: 129 additions & 0 deletions gui/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package main

import (
"bytes"
"encoding/gob"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"github.com/aead/ecdh"
"github.com/devgenie/miniature/internal/miniature"
yaml "gopkg.in/yaml.v2"
)

type UserResponse struct {
Name string `json:"name"`
Password string `json:"password"`
}

func main() {
a := app.New()
w := a.NewWindow("Miniature VPN")

serverAddresslabel := widget.NewLabel("Server Address")
serverAddress := widget.NewEntry()
serverAddress.SetPlaceHolder("192.0.0.2 or xyz.com")

usernameLabel := widget.NewLabel("Username")
username := widget.NewEntry()
username.SetPlaceHolder("Username")

passwordLabel := widget.NewLabel("Password")
password := widget.NewPasswordEntry()
password.SetPlaceHolder("Password")

connectButton := widget.NewButton("Connect", nil)
connectButtonLayout := container.New(layout.NewGridLayout(3), layout.NewSpacer(), connectButton, layout.NewSpacer())

authArea := container.New(layout.NewFormLayout(),
serverAddresslabel,
serverAddress,
usernameLabel,
username,
passwordLabel,
password)

w.SetContent(container.New(layout.NewVBoxLayout(),
authArea,
connectButtonLayout))
w.SetFixedSize(true)
w.Resize(fyne.NewSize(400, 80))

connectButton.OnTapped = func() {
serverAddress.Disable()
password.Disable()
loadingLabel := widget.NewLabel("Authenticating")
loadingBar := widget.NewProgressBarInfinite()
cancelButton := widget.NewButton("Cancel", nil)
popup := widget.NewModalPopUp(container.NewVBox(loadingLabel, loadingBar, cancelButton), w.Canvas())
popup.Resize(fyne.NewSize(200, 100))
popup.Show()
cancelButton.OnTapped = func() {
popup.Hide()
serverAddress.Enable()
password.Enable()
}
connectClient(serverAddress.Text, username.Text, password.Text)
}

w.SetPadded(true)
w.CenterOnScreen()
w.ShowAndRun()
}

func connectClient(serverAddress, username, password string) error {
client := &http.Client{}
gob.Register(ecdh.Point{})
serverAddr := fmt.Sprintf("http://%s:8080/client/auth", serverAddress)
reqBody := &miniature.User{
Username: username,
Password: password,
}
payloadBuf := new(bytes.Buffer)
json.NewEncoder(payloadBuf).Encode(reqBody)
fmt.Println(payloadBuf)
req, err := http.NewRequest("POST", serverAddr, payloadBuf)
if err != nil {
fmt.Print(err.Error())
return err
}

req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
resp, err := client.Do(req)
if err != nil {
fmt.Print(err.Error())
return err
}

defer resp.Body.Close()
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Print(err.Error())
return err
}
var clientResponse miniature.ClientResponse
json.Unmarshal(bodyBytes, &clientResponse)
clientConfig := new(miniature.ClientConfig)
err = yaml.Unmarshal(clientResponse.Cert, clientConfig)
if err != nil {
log.Fatal(err)
return err
}
vpnClient := new(miniature.Client)
clientConfig.ServerAddress = serverAddress
err = vpnClient.Run(*clientConfig)
if err != nil {
log.Fatal(err)
return err
}
return nil
}
Loading