Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove vendor folder #4

Closed
wants to merge 5 commits into from
Closed
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
6 changes: 3 additions & 3 deletions .env-example → .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ PORT = 9080
APP_CONF_DIR = ./conf

# Caddy Specifications
CADDY_CONF_DIR = /etc/caddy
CADDY_CONF_DIR = ./Caddy
CADDY_INTERFACE_NAME = Caddyfile
CADDY_DOMAIN = webtun.mydomain.com
CADDY_UPPER_RANGE = 9000
CADDY_LOWER_RANGE = 8000

# NGINX Specifications
NGINX_CONF_DIR = /etc/nginx
NGINX_CONF_DIR = ./NGINX
NGINX_INTERFACE_NAME = sites-available/tunnel.mydomain.com
NGINX_DOMAIN = sshtun.mydomain.com
NGINX_UPPER_RANGE = 7000
NGINX_LOWER_RANGE = 6000
NGINX_LOWER_RANGE = 6000
19 changes: 3 additions & 16 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, build with go test -c
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Configuration FIles
conf/
.env
Caddy
NGINX
vendor
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

.PHONY: proto generate
gen:
protoc --proto_path=proto proto/*.proto --go_out=api/v1/nginx --go-grpc_out=api/v1/nginx

clean:
rm -rf server/pb/
rm -rf client/pb/

.PHONY: run server
server:
go run server/main.go redis

.PHONY: run client
client:
go run client/main.go

install:
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
sudo apt install protobuf
sudo apt install clang-format
sudo apt install grpcurl
export GO_PATH=~/go
export PATH=$PATH:/$GO_PATH/bin
go mod vendor
path:
export GO_PATH=~/go
export PATH=$PATH:/$GO_PATH/bin

test:
rm -rf tmp && mkdir tmp
go test -cover -race serializer/*.go

run:
go run . ./.env

mod:
go mod tidy
go mod vendor
74 changes: 74 additions & 0 deletions api/gRPC_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package api

import (
"context"
"log"
"net"

pb "github.com/TheLazarusNetwork/LazarusTunnel/api/v1/nginx/pb/tunnel"
"github.com/TheLazarusNetwork/LazarusTunnel/api/v2/Caddy_gRPC"
"github.com/TheLazarusNetwork/LazarusTunnel/api/v2/Nginix_gRPC"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)

type server struct {
pb.UnimplementedNginxTunnelServiceServer
}

func InitGrpc() {
listener, err := net.Listen("tcp", ":8080")
if err != nil {
panic(err)
}

s := grpc.NewServer()
reflection.Register(s)
ser := &server{}
pb.RegisterNginxTunnelServiceServer(s, ser)
if err := s.Serve(listener); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}

func (s *server) GetTunnels(ctx context.Context, in *pb.Empty) (*pb.GetTunnelResponse, error) {
tunnels, status, err := Nginix_gRPC.GetTunnels()
return &pb.GetTunnelResponse{Message: tunnels, Status: int32(status)}, err
}

func (s *server) SetTunnel(ctx context.Context, in *pb.SetTunnelRequest) (*pb.SetTunnelResponse, error) {
tunnel, status, err := Nginix_gRPC.SetTunnel(in.Name)
return &pb.SetTunnelResponse{Message: tunnel, Status: int32(status)}, err
}

func (s *server) DeleteTunnel(ctx context.Context, in *pb.SetTunnelRequest) (*pb.DeleteTunnelResponse, error) {
msg, status, err := Nginix_gRPC.DeleteTunnel(in.Name)
return &pb.DeleteTunnelResponse{Message: msg, Status: int32(status)}, err
}

func (s *server) GetByName(ctx context.Context, in *pb.SetTunnelRequest) (*pb.SetTunnelResponse, error) {
msg, status, err := Nginix_gRPC.GetTunnelByName(in.Name)
return &pb.SetTunnelResponse{Message: msg, Status: int32(status)}, err
}

// caddy==================================================================

func (s *server) GetCaddyByName(ctx context.Context, in *pb.SetTunnelRequest) (*pb.SetTunnelResponse, error) {
msg, status, err := Caddy_gRPC.CaddyGetTunnelByName(in.Name)
return &pb.SetTunnelResponse{Message: msg, Status: int32(status)}, err
}

func (s *server) GetCaddyTunnels(ctx context.Context, in *pb.Empty) (*pb.GetTunnelResponse, error) {
tunnels, status, err := Caddy_gRPC.CaddyGetTunnels()
return &pb.GetTunnelResponse{Message: tunnels, Status: int32(status)}, err
}

func (s *server) SetCaddyTunnel(ctx context.Context, in *pb.SetTunnelRequest) (*pb.SetTunnelResponse, error) {
tunnel, status, err := Caddy_gRPC.CaddySetTunnel(in.Name)
return &pb.SetTunnelResponse{Message: tunnel, Status: int32(status)}, err
}

func (s *server) DeleteCaddyTunnel(ctx context.Context, in *pb.SetTunnelRequest) (*pb.DeleteTunnelResponse, error) {
msg, status, err := Caddy_gRPC.CaddyDeleteTunnel(in.Name)
return &pb.DeleteTunnelResponse{Message: msg, Status: int32(status)}, err
}
18 changes: 17 additions & 1 deletion api/v1/caddy/caddy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package caddy

import (
"fmt"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -31,25 +32,39 @@ var resp map[string]interface{}
func addTunnel(c *gin.Context) {
//post form parameters
name := strings.ToLower(c.PostForm("name"))
fmt.Println("name :", name)

// port allocation
max, _ := strconv.Atoi(os.Getenv("CADDY_UPPER_RANGE"))
min, _ := strconv.Atoi(os.Getenv("CADDY_LOWER_RANGE"))

for {
port, err := core.GetPort(max, min)
fmt.Println("Port caddy :", port)

// fmt.Println("Port :", port)
fmt.Println("err :", err)
if err != nil {
panic(err)

// fmt.Println("this is the panic err :",err)

}

// check validity of tunnel name and port
value, msg, err := middleware.IsValidWeb(name, port)
fmt.Println("caddyValue :", value)
fmt.Println("msg :", msg)
fmt.Println("err :", err)

// fmt.Println("value :", value)
if err != nil {
fmt.Println("first err != nill")
resp = util.Message(500, "Server error, Try after some time or Contact Admin...")
c.JSON(http.StatusOK, resp)
c.JSON(http.StatusBadGateway, resp)
break
} else if value == -1 {
fmt.Println("before port is already in use")
if msg == "Port Already in use" {
continue
}
Expand Down Expand Up @@ -157,3 +172,4 @@ func deleteTunnel(c *gin.Context) {
}

}

81 changes: 80 additions & 1 deletion api/v1/nginx/nginx.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nginx

import (
"fmt"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -31,23 +32,34 @@ var resp map[string]interface{}
func addTunnel(c *gin.Context) {
//post form parameters
name := strings.ToLower(c.PostForm("name"))
fmt.Println("nameNginix :", name)

// port allocation
max, _ := strconv.Atoi(os.Getenv("NGINX_UPPER_RANGE"))
min, _ := strconv.Atoi(os.Getenv("NGINX_LOWER_RANGE"))

for {
port, err := core.GetPort(max, min)
fmt.Println("Port :", port)
fmt.Println("err :", err)
if err != nil {
panic(err)
// fmt.Println("this is the panic error", err)
}

value, msg, err := middleware.IsValidSSH(name, port)

fmt.Println("valueNginix :", value, msg)
// fmt.Println("caddyNginixValue :", value, msg, err)
fmt.Println("msg :", msg)
fmt.Println("err :", err)

if err != nil {
resp = util.Message(500, "Server error, Try after some time or Contact Admin...")
c.JSON(http.StatusOK, resp)
c.JSON(http.StatusBadRequest, resp)
break
} else if value == -1 {

if msg == "Port Already in use" {
continue
}
Expand Down Expand Up @@ -91,6 +103,72 @@ func getTunnels(c *gin.Context) {
}
}

// func GetTunnels() ([]*tunnel.Tunnel, int, error) {
// //read all tunnel config
// tunnels, err := middleware.ReadSSHTunnels()
// if err != nil {
// err = errors.New("Server error, Try after some time or Contact Admin...")
// return nil, 500, err
// }
// tun := []*tunnel.Tunnel{}
// btunn, _ := json.Marshal(tunnels.Tunnels)
// json.Unmarshal(btunn, &tun)
// return tun, 200, nil
// }

// func SetTunnel(nameIn string) (*tunnel.Tunnel, int, error) {
// //post form parameters
// name := strings.ToLower(nameIn)
// t := &tunnel.Tunnel{}
// // port allocation
// max, _ := strconv.Atoi(os.Getenv("NGINX_UPPER_RANGE"))
// min, _ := strconv.Atoi(os.Getenv("NGINX_LOWER_RANGE"))

// for {
// port, err := core.GetPort(max, min)
// if err != nil {
// panic(err)
// }

// value, msg, err := middleware.IsValidSSH(name, port)
// if err != nil {
// return nil, 500, errors.New("Server error, Try after some time or Contact Admin...")
// break
// } else if value == -1 {
// if msg == "Port Already in use" {
// continue
// }
// return nil, 404, errors.New(msg)
// break
// } else if value == 1 {
// //create a tunnel struct object
// var data model.Tunnel
// data.Name = name
// data.Port = strconv.Itoa(port)
// data.CreatedAt = time.Now().UTC().Format(time.RFC3339)
// data.Domain = os.Getenv("NGINX_DOMAIN")

// //to add tunnel config
// err := middleware.AddSSHTunnel(data)
// if err != nil {
// return nil, 500, errors.New("Server error, Try after some time or Contact Admin...")
// break
// } else {
// resp = util.MessageTunnel(200, data)
// t = &tunnel.Tunnel{
// Name: data.Name,
// Port: data.Port,
// CreatedAt: data.CreatedAt,
// Domain: data.Domain,
// Status: data.Status,
// }
// break
// }
// }
// }
// return t, 200, nil
// }

//getTunnel get specific tunnel config
func getTunnel(c *gin.Context) {
//get parameter
Expand Down Expand Up @@ -155,3 +233,4 @@ func deleteTunnel(c *gin.Context) {
}

}

Loading