Commit 84e040d6 by anun

update flags edge

parent ccd7441a
......@@ -32,3 +32,5 @@ _testmain.go
*.exe
*.test
*.prof
.env
.tmp
VERSION=$(shell git describe --abbrev=0 --tags)
BUILD=$(shell git rev-parse HEAD)
DIRBASE=./build
DIR=${DIRBASE}/${VERSION}/${BUILD}/bin
# a helper shell script
MAKE_VERSION=1.2.8
LDFLAGS=-ldflags "-s -w ${XBUILD} -buildid=${BUILD} -X dev.nexpie.com/anun/chisel/share.BuildVersion=${VERSION}"
define MAKEFUNCTIONCODE
function hasChanges() {
# old version, just track uncommited + untracked files
# test -n "$$(git status -s .)"
# expect 1 to be normal so the untracked file .make-funcition will be ignored
test 0 -ne "$$(git status -s . | sed -e '/.make-function/d' | wc -l)"
}
GOFILES=`go list ./...`
GOFILESNOTEST=`go list ./... | grep -v test`
function getRelease() {
# old : use tag in release.conf
# awk -F= '/^RELEASE=/{print $$2}' release.conf
# Make Directory to store executables
$(shell mkdir -p ${DIR})
# new use tag from git of the form -> 1.0.1-2-3b10c420
TAGN=$$(git describe | sed -e "s/-g.*//")
TV=$$(echo $$TAGN | sed -e "s/-.*//")
TM=$$(echo $$TAGN | sed -e "s/^[^\-]*//")
if [ -z "$$TM" ]
then
TM="-0"
fi
echo $$TV$$TM
}
all:
@goreleaser build --skip-validate --single-target --config .github/goreleaser.yml
function getBaseTag() {
sed -n -e "s/^tag=\(.*\)$$(getRelease)\$$/\1/p" release.conf
}
freebsd: lint
env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-freebsd_amd64 .
function getTag() {
if [ -z "$$1" ] ; then
awk -F= '/^tag/{print $$2}' release.conf
else
echo "$$(getBaseTag)$$1"
fi
}
linux: lint
env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-linux_amd64 .
function setRelease() {
if [ -n "$$1" ] ; then
sed -i.x -e "s/^tag=.*/tag=$$(getTag $$1)/" release.conf
sed -i.x -e "s/^RELEASE=.*/RELEASE=$$1/g" release.conf
rm -f release.conf.x
runPreTagCommand "$$1"
else
echo "ERROR: missing release version parameter " >&2
return 1
fi
}
windows: lint
env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-windows_amd64 .
function runPreTagCommand() {
if [ -n "$$1" ] ; then
COMMAND=$$(sed -n -e "s/@@RELEASE@@/$$1/g" -e 's/^pre_tag_command=\(.*\)/\1/p' release.conf)
if [ -n "$$COMMAND" ] ; then
if ! OUTPUT=$$(bash -c "$$COMMAND" 2>&1) ; then echo $$OUTPUT >&2 && exit 1 ; fi
fi
else
echo "ERROR: missing release version parameter " >&2
return 1
fi
}
darwin:
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-darwin_amd64 .
function tagExists() {
tag=$${1:-$$(getTag)}
test -n "$$tag" && test -n "$$(git tag | grep "^$$tag\$$")"
}
docker:
@docker build .
function differsFromRelease() {
tag=$$(getTag)
! tagExists $$tag || test -n "$$(git diff --shortstat -r $$tag .)"
}
dep: ## Get the dependencies
@go get -u github.com/goreleaser/goreleaser
@go get -u github.com/boumenot/gocover-cobertura
@go get -v -d ./...
@go get -u all
@go mod tidy
function getVersion() {
result=$$(getRelease)
lint: ## Lint the files
@go fmt ${GOFILES}
@go vet ${GOFILESNOTEST}
if hasChanges ; then
result="$$result-dirty"
fi
echo $$result
}
test: ## Run unit tests
@go test -coverprofile=${DIR}/coverage.out -race -short ${GOFILESNOTEST}
@go tool cover -html=${DIR}/coverage.out -o ${DIR}/coverage.html
@gocover-cobertura < ${DIR}/coverage.out > ${DIR}/coverage.xml
function getVersionWithHash() {
result=$$(getRelease)
release: lint test
goreleaser release --config .github/goreleaser.yml
if differsFromRelease; then
# output only first 7 characters
# result="$$result-$$(git log -n 1 --format=%h .)"
clean:
rm -rf ${DIRBASE}/*
# output first 8 characters
result="$$result-$$(git log -n 1 --format=%H . | head -c 8)"
fi
.PHONY: all freebsd linux windows docker dep lint test release clean
\ No newline at end of file
if hasChanges ; then
result="$$result-dirty"
fi
echo $$result
}
function nextPatchLevel() {
version=$${1:-$$(getRelease)}
major_and_minor=$$(echo $$version | cut -d. -f1,2)
patch=$$(echo $$version | cut -d. -f3)
version=$$(printf "%s.%d" $$major_and_minor $$(($$patch + 1)))
echo $$version
}
function nextMinorLevel() {
version=$${1:-$$(getRelease)}
major=$$(echo $$version | cut -d. -f1);
minor=$$(echo $$version | cut -d. -f2);
version=$$(printf "%d.%d.0" $$major $$(($$minor + 1))) ;
echo $$version
}
function nextMajorLevel() {
version=$${1:-$$(getRelease)}
major=$$(echo $$version | cut -d. -f1);
version=$$(printf "%d.0.0" $$(($$major + 1)))
echo $$version
}
endef
SHELL=/bin/bash
include release.conf
IMAGE=$(REGISTRY_HOST)/$(GROUPNAME)/$(PROJECTNAME)
VERSION=$(shell . $(RELEASE_SUPPORT) ; getVersion)
VERSIONHASH=$(shell . $(RELEASE_SUPPORT) ; getVersionWithHash)
TAG=$(shell . $(RELEASE_SUPPORT); getTag)
PROJECTPATH?=.
BUILDARG?=
RELEASE_SUPPORT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))/.make-function
export MAKEFUNCTIONCODE
# If the first argument is "run"...
doit=
ifeq (rmi,$(firstword $(MAKECMDGOALS)))
doit=true
endif
ifeq (images,$(firstword $(MAKECMDGOALS)))
doit=true
endif
ifeq (deploy,$(firstword $(MAKECMDGOALS)))
doit=true
endif
ifeq (deploy-dev,$(firstword $(MAKECMDGOALS)))
doit=true
endif
ifeq (show-deploy,$(firstword $(MAKECMDGOALS)))
doit=true
endif
ifeq (annotate,$(firstword $(MAKECMDGOALS)))
doit=true
endif
ifeq (rollback,$(firstword $(MAKECMDGOALS)))
doit=true
endif
ifdef doit
# use the rest as arguments for "make xxx"
#CMD_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
# ...and turn them into do-nothing targets
#$(eval $(CMD_ARGS):;@:)
ifdef n
DEPLOYARG= -n $(n) --context=$(c)
else
DEPLOYARG= -n nexpieio --context=$(c)
endif
endif
# ifeq ($(CMD_ARGS),)
# else
# EMPTY=
# SPACE=$(EMPTY) $(EMPTY)
# TDARG = $(subst $(SPACE), --context=,$(CMD_ARGS))
# DARG = -n $(TDARG)
# endif
.PHONY: pre-build docker-build post-build build cleanbuild release patch-release minor-release major-release tag check-status check-release showtag show-tag \
push do-push post-push post-init update-make rmi images deploy show-deploy annotate rollback
init:
@echo "$$MAKEFUNCTIONCODE" > ./.make-function
build: init pre-build docker-build post-build
buildx: init pre-build docker-buildx post-build
cleanbuild: init pre-build docker-cleanbuild post-build
pre-build:
post-build:
@rm .make-function
post-push:
@rm .make-function
post-init:
@rm .make-function
docker-buildx:
docker buildx build --push --platform linux/arm64/v8,linux/amd64 $(BUILDARG) --tag $(IMAGE):$(VERSIONHASH) $(PROJECTPATH)
docker-build:
docker build --platform=linux/amd64 $(BUILDARG) -t $(IMAGE):$(VERSIONHASH) $(PROJECTPATH)
@DOCKER_MAJOR=$(shell docker -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f1) ; \
DOCKER_MINOR=$(shell docker -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f2) ; \
if [ $$DOCKER_MAJOR -eq 1 ] && [ $$DOCKER_MINOR -lt 10 ] ; then \
echo docker tag -f $(IMAGE):$(VERSIONHASH) $(IMAGE):latest ;\
docker tag -f $(IMAGE):$(VERSIONHASH) $(IMAGE):latest ;\
echo docker tag -f $(IMAGE):$(VERSIONHASH) $(IMAGE):$(VERSION) ;\
docker tag -f $(IMAGE):$(VERSIONHASH) $(IMAGE):$(VERSION) ;\
else \
echo docker tag $(IMAGE):$(VERSIONHASH) $(IMAGE):latest ;\
docker tag $(IMAGE):$(VERSIONHASH) $(IMAGE):latest ; \
echo docker tag $(IMAGE):$(VERSIONHASH) $(IMAGE):$(VERSION) ;\
docker tag $(IMAGE):$(VERSIONHASH) $(IMAGE):$(VERSION) ;\
fi
docker-cleanbuild:
docker build --platform=linux/amd64 --no-cache -t $(IMAGE):$(VERSIONHASH) $(PROJECTPATH)
@DOCKER_MAJOR=$(shell docker -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f1) ; \
DOCKER_MINOR=$(shell docker -v | sed -e 's/.*version //' -e 's/,.*//' | cut -d\. -f2) ; \
if [ $$DOCKER_MAJOR -eq 1 ] && [ $$DOCKER_MINOR -lt 10 ] ; then \
echo docker tag -f $(IMAGE):$(VERSIONHASH) $(IMAGE):latest ;\
docker tag -f $(IMAGE):$(VERSIONHASH) $(IMAGE):latest ;\
echo docker tag -f $(IMAGE):$(VERSIONHASH) $(IMAGE):$(VERSION) ;\
docker tag -f $(IMAGE):$(VERSIONHASH) $(IMAGE):$(VERSION) ;\
else \
echo docker tag $(IMAGE):$(VERSIONHASH) $(IMAGE):latest ;\
docker tag $(IMAGE):$(VERSIONHASH) $(IMAGE):latest ; \
echo docker tag $(IMAGE):$(VERSIONHASH) $(IMAGE):$(VERSION) ;\
docker tag $(IMAGE):$(VERSIONHASH) $(IMAGE):$(VERSION) ;\
fi
release: check-status check-release build push
push: init do-push post-push
rmi: delete-docker-image
images: list-docker-image
do-push:
docker push $(IMAGE):$(VERSIONHASH)
docker push $(IMAGE):$(VERSION)
docker push $(IMAGE):latest
build-push: build push
show-tag: init release.conf
@. $(RELEASE_SUPPORT); getVersionWithHash
@rm .make-function
showtag: init release.conf
@. $(RELEASE_SUPPORT); getVersionWithHash
@rm .make-function
check-status: init
@. $(RELEASE_SUPPORT) ; ! hasChanges || (echo "ERROR: there are still outstanding changes" >&2) ;
@rm .make-function
check-release: init release.conf post-init
@. $(RELEASE_SUPPORT) ; tagExists $(TAG) || (echo "ERROR: version not yet tagged in git. make [minor,major,patch]-release." >&2 && exit 1) ;
@. $(RELEASE_SUPPORT) ; ! differsFromRelease $(TAG) || (echo "ERROR: current directory differs from tagged $(TAG). make [minor,major,patch]-release." ; exit 1)
update-make: init
@rm Makefile
wget https://dev.nexpie.com/sample/docker-makefile-sample/raw/master/Makefile
@rm .make-function
make-version:
@echo $(MAKE_VERSION)
# awk to cut the column 3, xargs to run command passing arg from pipe
delete-docker-image:
@docker images | grep $(CMD_ARGS) | awk '{print $$3}' | xargs docker rmi || true
# || true to force exoit code to 0 otherwise if no line matched, make will show some error
list-docker-image:
@docker images | grep $(CMD_ARGS) || true
env-snippet:
@jq -r '..|select(type=="string") + "="' config/custom-environment-variables.json > _temp_file_.env
@keg -s nexpieconfig _temp_file_.env > /dev/null
@cat env-snippet-nexpieconfig.yaml
@rm _temp_file_.env
@rm nexpieconfig.yaml
@rm env-snippet-nexpieconfig.yaml
show-deploy: init release.conf
ifndef c
@echo Please run make show-deploy c={context}
else
kubectl rollout history deployment/$(DEPLOYMENT) $(DEPLOYARG)
endif
@rm .make-function
annotate: init release.conf
ifndef c
@echo Please run make show-deploy c={context} a="{annotation text}"
else ifndef a
@echo Please run make show-deploy c={context} a="{annotation text}"
else
kubectl annotate deployment/$(DEPLOYMENT) kubernetes.io/change-cause="$(a)" $(DEPLOYARG)
endif
@rm .make-function
rollback: init release.conf
ifndef r
@echo Please run make rollback r={revision} c={context}
else
kubectl rollout undo deployment/$(DEPLOYMENT) --to-revision=$(r) $(DEPLOYARG)
endif
@rm .make-function
deploy: init release.conf
ifndef c
@echo Deploy failed : Please make deploy with c={context}
else
@cat k8s/deployment.yaml | sed "s/{{IMAGE_TAG}}/$(VERSIONHASH)/g" | kubectl apply -f - $(DEPLOYARG)
@rm .make-function
ifdef a
@kubectl annotate deployment/$(DEPLOYMENT) kubernetes.io/change-cause="$(a)" $(DEPLOYARG)
endif
endif
deploy-dev: init release.conf
ifndef c
@echo Deploy failed : Please make deploy with c={context}
else
@cat k8s/deployment-dev.yaml | sed "s/{{IMAGE_TAG}}/$(VERSIONHASH)/g" | kubectl apply -f - $(DEPLOYARG)
@rm .make-function
ifdef a
@kubectl annotate deployment/$(DEPLOYMENT) kubernetes.io/change-cause="$(a)" $(DEPLOYARG)
endif
endif
VERSION=$(shell git describe --abbrev=0 --tags)
BUILD=$(shell git rev-parse HEAD)
DIRBASE=./build
DIR=${DIRBASE}/${VERSION}/${BUILD}/bin
LDFLAGS=-ldflags "-s -w ${XBUILD} -buildid=${BUILD} -X dev.nexpie.com/anun/chisel/share.BuildVersion=${VERSION}"
GOFILES=`go list ./...`
GOFILESNOTEST=`go list ./... | grep -v test`
# Make Directory to store executables
$(shell mkdir -p ${DIR})
all:
@goreleaser build --skip-validate --single-target --config .github/goreleaser.yml
freebsd: lint
env CGO_ENABLED=0 GOOS=freebsd GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-freebsd_amd64 .
linux: lint
env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-linux_amd64 .
windows: lint
env CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-windows_amd64 .
darwin:
env CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath ${LDFLAGS} ${GCFLAGS} ${ASMFLAGS} -o ${DIR}/chisel-darwin_amd64 .
docker:
@docker build .
dep: ## Get the dependencies
@go get -u github.com/goreleaser/goreleaser
@go get -u github.com/boumenot/gocover-cobertura
@go get -v -d ./...
@go get -u all
@go mod tidy
lint: ## Lint the files
@go fmt ${GOFILES}
@go vet ${GOFILESNOTEST}
test: ## Run unit tests
@go test -coverprofile=${DIR}/coverage.out -race -short ${GOFILESNOTEST}
@go tool cover -html=${DIR}/coverage.out -o ${DIR}/coverage.html
@gocover-cobertura < ${DIR}/coverage.out > ${DIR}/coverage.xml
release: lint test
goreleaser release --config .github/goreleaser.yml
clean:
rm -rf ${DIRBASE}/*
.PHONY: all freebsd linux windows docker dep lint test release clean
\ No newline at end of file
No preview for this file type
......@@ -44,7 +44,7 @@ type Config struct {
TLS TLSConfig
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
Verbose bool
Code string
Edge EdgeConfig
}
// TLSConfig for a Client
......@@ -56,19 +56,25 @@ type TLSConfig struct {
ServerName string
}
// Edge NEXPIE
type EdgeConfig struct {
EdgeId string
EdgeSecret string
}
// Client represents a client instance
type Client struct {
*cio.Logger
config *Config
computed settings.Config
sshConfig *ssh.ClientConfig
tlsConfig *tls.Config
proxyURL *url.URL
server string
connCount cnet.ConnCount
stop func()
eg *errgroup.Group
tunnel *tunnel.Tunnel
config *Config
computed settings.Config
sshConfig *ssh.ClientConfig
tlsConfig *tls.Config
proxyURL *url.URL
server string
connCount cnet.ConnCount
stop func()
eg *errgroup.Group
tunnel *tunnel.Tunnel
}
func getPort(s string) (response []byte, error error) {
......@@ -112,6 +118,7 @@ func NewClient(c *Config) (*Client, error) {
config: c,
computed: settings.Config{
Version: chshare.BuildVersion,
// Edge: nil,
},
server: u.String(),
tlsConfig: nil,
......@@ -120,12 +127,14 @@ func NewClient(c *Config) (*Client, error) {
//set default log level
client.Logger.Info = true
//Anun
/*
p, e := getPort(c.Server+"/register")
client.Debugf("---> p = %s", p)
if e != nil {
client.Errorf("request %s/register : %s", c.Server, e)
}
*/
//configure tls
if u.Scheme == "wss" {
tc := &tls.Config{}
......@@ -159,14 +168,24 @@ func NewClient(c *Config) (*Client, error) {
}
client.tlsConfig = tc
}
if c.Code == "" {
c.Code = settings.RandString(16)
// Anun
if c.Edge.EdgeId != "" {
client.computed.Edge.EdgeId = c.Edge.EdgeId
}
if c.Edge.EdgeSecret != "" {
client.computed.Edge.EdgeSecret = c.Edge.EdgeSecret
}
client.Debugf("---> c.Edge = %s", c.Edge)
client.Debugf("---> c.EdgeId = %s", c.Edge.EdgeId)
client.Debugf("---> c.EdgeSecret = %s", c.Edge.EdgeSecret)
//validate remotes
// client.Debugf("---> c.Remotes = %s", c.Remotes)
for _, s := range c.Remotes {
//Anun
/*
s = "R:"+string(p)+":"+s
client.Debugf("s = %s", s)
*/
r, err := settings.DecodeRemote(s)
client.Debugf("r = %s", r)
if err != nil {
......@@ -190,7 +209,7 @@ func NewClient(c *Config) (*Client, error) {
}
client.computed.Remotes = append(client.computed.Remotes, r)
}
client.computed.Code = c.Code
// client.computed.Edge = c.Edge
client.Infof("---> Remotes client.computed# %s", client.computed)
//outbound proxy
if p := c.Proxy; p != "" {
......
......@@ -16,7 +16,9 @@ require (
require (
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2 // indirect
github.com/jmoiron/sqlx v1.4.0 // indirect
github.com/jpillora/ansi v1.0.3 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
......
dev.nexpie.com/anun/chisel v1.9.1 h1:nGOF58+45WHlvDcq6AZu7En8nWOBCZHqj9boo5rB4qU=
dev.nexpie.com/anun/chisel v1.9.1/go.mod h1:qvgGfFR9ZhiDoYJM4IM1omX1HLbQSkZag8miP9u4SsQ=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2 h1:axBiC50cNZOs7ygH5BgQp4N+aYrZ2DNpWZ1KG3VOSOM=
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2/go.mod h1:jnzFpU88PccN/tPPhCpnNU8mZphvKxYM9lLNkd8e+os=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
github.com/jpillora/ansi v1.0.3 h1:nn4Jzti0EmRfDxm7JtEs5LzCbNwd5sv+0aE+LdS9/ZQ=
github.com/jpillora/ansi v1.0.3/go.mod h1:D2tT+6uzJvN1nBVQILYWkIdq7zG+b5gcFN5WI/VyjMY=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
dev.nexpie.com/anun/chisel v1.9.1 h1:nGOF58+45WHlvDcq6AZu7En8nWOBCZHqj9boo5rB4qU=
dev.nexpie.com/anun/chisel v1.9.1/go.mod h1:qvgGfFR9ZhiDoYJM4IM1omX1HLbQSkZag8miP9u4SsQ=
github.com/jpillora/requestlog v1.0.0 h1:bg++eJ74T7DYL3DlIpiwknrtfdUA9oP/M4fL+PpqnyA=
github.com/jpillora/requestlog v1.0.0/go.mod h1:HTWQb7QfDc2jtHnWe2XEIEeJB7gJPnVdpNn52HXPvy8=
github.com/jpillora/sizestr v1.0.0 h1:4tr0FLxs1Mtq3TnsLDV+GYUWG7Q26a6s+tV5Zfw2ygw=
github.com/jpillora/sizestr v1.0.0/go.mod h1:bUhLv4ctkknatr6gR42qPxirmd5+ds1u7mzD+MZ33f0=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce h1:fb190+cK2Xz/dvi9Hv8eCYJYvIGUTN2/KLq1pT6CjEc=
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce/go.mod h1:o8v6yHRoik09Xen7gje4m9ERNah1d1PPsVq1VEx9vE4=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
......
......@@ -417,7 +417,9 @@ var clientHelp = `
private key. The certificate must have client authentication
enabled (mutual-TLS).
--code, serial number, token, text
--edgeid, id of device
--edgesecret, secret of device
` + commonHelp
func client(args []string) {
......@@ -434,7 +436,8 @@ func client(args []string) {
flags.StringVar(&config.TLS.Cert, "tls-cert", "", "")
flags.StringVar(&config.TLS.Key, "tls-key", "", "")
flags.Var(&headerFlags{config.Headers}, "header", "")
flags.StringVar(&config.Code, "code", "", "")
flags.StringVar(&config.Edge.EdgeId, "edgeid", "", "")
flags.StringVar(&config.Edge.EdgeSecret, "edgesecret", "", "")
hostname := flags.String("hostname", "", "")
sni := flags.String("sni", "", "")
pid := flags.Bool("pid", false, "")
......
REGISTRY_HOST=dock.nexpie.com
GROUPNAME=anun
PROJECTNAME=chisel
RELEASE=1.0.0
......@@ -19,8 +19,32 @@ import (
"dev.nexpie.com/anun/chisel/share/settings"
"github.com/jpillora/requestlog"
"golang.org/x/crypto/ssh"
"fmt"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq" // The database driver in use.
)
// Anun
type DdConfig struct {
User string
Password string
Host string
Port int
Name string
DisableTLS bool
}
func DbOpen(cfg DdConfig) (*sqlx.DB, error) {
sslmode := "require"
if cfg.DisableTLS {
sslmode = "disable"
}
var dataSoruce = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s", cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.Name, sslmode)
return sqlx.Connect("postgres", dataSoruce)
}
// Config is the configuration for the chisel service
type Config struct {
KeySeed string
......@@ -140,6 +164,47 @@ func NewServer(c *Config) (*Server, error) {
if c.Reverse {
server.Infof("Reverse tunnelling enabled")
}
//Anun
dbenable:= settings.EnvBool("DB_ENABLE")
dbuser:= settings.EnvString("DB_USERNAME")
dbpassword:= settings.EnvString("DB_PASSWORD")
dbhost:= settings.EnvString("DB_HOST")
dbport:= settings.EnvInt("DB_PORT",0)
dbschema:= settings.EnvString("DB_NAME")
dbDisableTLS:= settings.EnvBool("DB_DISABLE_TLS")
dbConfig := DdConfig{
User: dbuser,
Password: dbpassword,
Host: dbhost,
Port: dbport,
Name: dbschema,
DisableTLS: dbDisableTLS,
}
server.Infof("dbConfig %s", dbConfig)
server.Infof("%s", dbenable)
server.Infof("%s", dbuser)
server.Infof("%s", dbpassword)
server.Infof("%s", dbhost)
server.Infof("%s", dbport)
server.Infof("%s", dbschema)
server.Infof("%s", dbDisableTLS)
db, err := DbOpen(dbConfig)
if err != nil {
server.Infof("connecting database fail", err)
}else{
server.Infof("connecting database, %s", db)
}
dbEnable := settings.EnvBool("DB_ENABLE")
server.Infof("dbEnable: %s", dbEnable)
if settings.EnvBool("DB_ENABLE") {
server.Infof("Edge Platform enabled")
}
return server, nil
}
......@@ -171,6 +236,7 @@ func (s *Server) StartContext(ctx context.Context, host, port string) error {
if err != nil {
return err
}
h := http.Handler(http.HandlerFunc(s.handleClientHandler))
if s.Debug {
o := requestlog.DefaultOptions
......
......@@ -9,11 +9,35 @@ import (
"os"
"os/user"
"path/filepath"
// "fmt"
"dev.nexpie.com/anun/chisel/share/settings"
"golang.org/x/crypto/acme/autocert"
// "github.com/jmoiron/sqlx"
// _ "github.com/lib/pq" // The database driver in use.
)
// Anun
/*
type DbConfig struct {
User string
Password string
Host string
Port int
Name string
DisableTLS bool
}
func DbOpen(cfg DbConfig) (*sqlx.DB, error) {
sslmode := "require"
if cfg.DisableTLS {
sslmode = "disable"
}
var dataSoruce = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s", cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.Name, sslmode)
return sqlx.Connect("postgres", dataSoruce)
}
*/
//TLSConfig enables configures TLS
type TLSConfig struct {
Key string
......
package database
import (
"fmt"
"github.com/jmoiron/sqlx"
_ "github.com/lib/pq" // The database driver in use.
)
type Config struct {
User string
Password string
Host string
Port int
Name string
DisableTLS bool
}
func Open(cfg Config) (*sqlx.DB, error) {
sslmode := "require"
if cfg.DisableTLS {
sslmode = "disable"
}
var dataSoruce = fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=%s", cfg.Host, cfg.Port, cfg.User, cfg.Password, cfg.Name, sslmode)
return sqlx.Connect("postgres", dataSoruce)
}
package edge
import (
// "time"
"github.com/jmoiron/sqlx"
)
type PostgresDB struct {
DB *sqlx.DB
}
func (postgres PostgresDB) GetEdge(id string) (PostgresDB, error) {
var edge PostgresDB
const query = `SELECT * FROM EdgeDevice WHERE edgeid=$1`
err := postgres.DB.Get(&edge, query, id)
if err != nil {
return PostgresDB{}, err
}
// edge.createtime = edge.createtime.UTC()
return edge, nil
}
......@@ -8,7 +8,7 @@ import (
type Config struct {
Version string
Remotes
Code string
Edge
}
func DecodeConfig(b []byte) (*Config, error) {
......
......@@ -33,3 +33,9 @@ func EnvBool(name string) bool {
v := Env(name)
return v == "1" || strings.ToLower(v) == "true"
}
//Anun
func EnvString(name string) string {
return os.Getenv(name)
}
......@@ -38,7 +38,11 @@ type Remote struct {
LocalHost, LocalPort, LocalProto string
RemoteHost, RemotePort, RemoteProto string
Socks, Reverse, Stdio bool
Code string
}
// Anun
type Edge struct {
EdgeId, EdgeSecret string
}
const revPrefix = "R:"
......
......@@ -6,4 +6,4 @@ package chshare
//mismatch.
var ProtocolVersion = "chisel-v3"
var BuildVersion = "0.0.0-src"
var BuildVersion = "24.06.00-edge"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment