mirror of
https://github.com/edgebox-iot/edgeboxctl.git
synced 2026-09-30 08:35:45 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6202d13b9b |
@@ -13,16 +13,16 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Go
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v3
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: ^1.15
|
go-version: ^1.15
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v2
|
||||||
- name: Build
|
- name: Build
|
||||||
run: make build
|
run: make build
|
||||||
- name: Test
|
- name: Test
|
||||||
run: make test-with-coverage
|
run: make test-with-coverage
|
||||||
- uses: codecov/codecov-action@v1
|
# - uses: codecov/codecov-action@v1
|
||||||
with:
|
# with:
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
# token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
files: coverage.out
|
# files: coverage.out
|
||||||
|
|||||||
@@ -21,6 +21,3 @@ main
|
|||||||
# Build
|
# Build
|
||||||
|
|
||||||
/bin
|
/bin
|
||||||
|
|
||||||
# Logs from executed scripts
|
|
||||||
/scripts/output.log
|
|
||||||
|
|||||||
@@ -15,15 +15,6 @@ build-prod:
|
|||||||
build-cloud:
|
build-cloud:
|
||||||
GOOS=linux GOARCH=amd64 RELEASE=cloud make build
|
GOOS=linux GOARCH=amd64 RELEASE=cloud make build
|
||||||
|
|
||||||
build-arm64:
|
|
||||||
GOOS=linux GOARCH=arm64 RELEASE=prod make build
|
|
||||||
|
|
||||||
build-armhf:
|
|
||||||
GOOS=linux GOARCH=arm RELEASE=prod make build
|
|
||||||
|
|
||||||
build-amd64:
|
|
||||||
GOOS=linux GOARCH=amd64 RELEASE=prod make build
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@echo "Building ${GOOS}-${GOARCH}"
|
@echo "Building ${GOOS}-${GOARCH}"
|
||||||
GOOS=${GOOS} GOARCH=${GOARCH} go build \
|
GOOS=${GOOS} GOARCH=${GOARCH} go build \
|
||||||
@@ -42,20 +33,3 @@ test:
|
|||||||
|
|
||||||
test-with-coverage:
|
test-with-coverage:
|
||||||
go test -tags=unit -timeout=600s -v ./... -coverprofile=coverage.out
|
go test -tags=unit -timeout=600s -v ./... -coverprofile=coverage.out
|
||||||
|
|
||||||
install-cloud: build-cloud
|
|
||||||
systemctl stop edgeboxctl
|
|
||||||
cp ./bin/edgeboxctl /usr/local/bin/edgeboxctl
|
|
||||||
cp ./edgeboxctl/edgeboxctl.service /lib/systemd/system/edgeboxctl.service
|
|
||||||
systemctl daemon-reload
|
|
||||||
@echo "Edgeboxctl installed successfully"
|
|
||||||
@echo "To start edgeboxctl run: systemctl start edgeboxctl"
|
|
||||||
|
|
||||||
install-prod: build-prod
|
|
||||||
-sudo systemctl stop edgeboxctl
|
|
||||||
sudo rm -rf /usr/local/bin/edgeboxctl /lib/systemd/system/edgeboxctl.service
|
|
||||||
sudo cp ./bin/edgeboxctl /usr/local/bin/edgeboxctl
|
|
||||||
sudo cp ./edgeboxctl.service /lib/systemd/system/edgeboxctl.service
|
|
||||||
sudo systemctl daemon-reload
|
|
||||||
@echo "Edgeboxctl installed successfully"
|
|
||||||
@echo "To start edgeboxctl run: systemctl start edgeboxctl"
|
|
||||||
+3
-2
@@ -1,3 +1,4 @@
|
|||||||
|
codecov:
|
||||||
|
require_ci_to_pass: no
|
||||||
|
|
||||||
comment: false
|
comment: false
|
||||||
github_checks:
|
|
||||||
annotations: false
|
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Edgebox Control Module Service
|
|
||||||
ConditionPathExists=/home/system/
|
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
User=root
|
|
||||||
Group=root
|
|
||||||
LimitNOFILE=1024
|
|
||||||
|
|
||||||
Restart=on-failure
|
|
||||||
RestartSec=10
|
|
||||||
startLimitIntervalSec=60
|
|
||||||
|
|
||||||
WorkingDirectory=/home/system/components/edgeboxctl
|
|
||||||
ExecStart=edgeboxctl --name=edgebox-cloud
|
|
||||||
|
|
||||||
# make sure log directory exists and owned by syslog
|
|
||||||
PermissionsStartOnly=true
|
|
||||||
ExecStartPre=/bin/mkdir -p /var/log/edgeboxctl
|
|
||||||
ExecStartPre=/bin/chown root:root /var/log/edgeboxctl
|
|
||||||
ExecStartPre=/bin/chmod 755 /var/log/edgeboxctl
|
|
||||||
StandardOutput=syslog
|
|
||||||
StandardError=syslog
|
|
||||||
SyslogIdentifier=edgeboxctl
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
@@ -4,14 +4,12 @@ go 1.15
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
|
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
|
||||||
github.com/dariubs/percent v0.0.0-20200128140941-b7801cf1c7e2 // indirect
|
|
||||||
github.com/dustin/go-humanize v1.0.0 // indirect
|
|
||||||
github.com/go-ole/go-ole v1.2.5 // indirect
|
github.com/go-ole/go-ole v1.2.5 // indirect
|
||||||
github.com/go-sql-driver/mysql v1.5.0
|
github.com/go-sql-driver/mysql v1.5.0
|
||||||
github.com/joho/godotenv v1.3.0
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/mattn/go-sqlite3 v1.14.7 // indirect
|
github.com/mattn/go-sqlite3 v1.14.7
|
||||||
github.com/shirou/gopsutil v3.21.4+incompatible // indirect
|
github.com/shirou/gopsutil v3.21.4+incompatible
|
||||||
|
github.com/stretchr/testify v1.8.2 // indirect
|
||||||
github.com/tklauser/go-sysconf v0.3.6 // indirect
|
github.com/tklauser/go-sysconf v0.3.6 // indirect
|
||||||
golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549 // indirect
|
golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549 // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,72 +1,37 @@
|
|||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
|
||||||
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 h1:5sXbqlSomvdjlRbWyNqkPsJ3Fg+tQZCbgeX1VGljbQY=
|
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 h1:5sXbqlSomvdjlRbWyNqkPsJ3Fg+tQZCbgeX1VGljbQY=
|
||||||
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||||
github.com/dariubs/percent v0.0.0-20200128140941-b7801cf1c7e2 h1:5EPE4Uk7ucthLTJAZqZxu6LZluox5/AqXUxJDpzgJjg=
|
|
||||||
github.com/dariubs/percent v0.0.0-20200128140941-b7801cf1c7e2/go.mod h1:NDZpkezJ8QqyIW/510MywB5T2KdC8v/0oTlEoPcMsRM=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
|
|
||||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
|
||||||
github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
|
github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
|
||||||
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||||
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
||||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA=
|
github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA=
|
||||||
github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
|
||||||
github.com/shirou/gopsutil v3.21.4+incompatible h1:fuHcTm5mX+wzo542cmYcV9RTGQLbnHLI5SyQ5ryTVck=
|
github.com/shirou/gopsutil v3.21.4+incompatible h1:fuHcTm5mX+wzo542cmYcV9RTGQLbnHLI5SyQ5ryTVck=
|
||||||
github.com/shirou/gopsutil v3.21.4+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
github.com/shirou/gopsutil v3.21.4+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||||
|
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
github.com/tklauser/go-sysconf v0.3.6 h1:oc1sJWvKkmvIxhDHeKWvZS4f6AW+YcoguSfRF2/Hmo4=
|
github.com/tklauser/go-sysconf v0.3.6 h1:oc1sJWvKkmvIxhDHeKWvZS4f6AW+YcoguSfRF2/Hmo4=
|
||||||
github.com/tklauser/go-sysconf v0.3.6/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI=
|
github.com/tklauser/go-sysconf v0.3.6/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI=
|
||||||
github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA=
|
github.com/tklauser/numcpus v0.2.2 h1:oyhllyrScuYI6g+h/zUvNXNp1wy7x8qQy3t/piefldA=
|
||||||
github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM=
|
github.com/tklauser/numcpus v0.2.2/go.mod h1:x3qojaO3uyYt0i56EW/VUYs7uBvdl2fkfZFu0T9wgjM=
|
||||||
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
|
|
||||||
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
|
||||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
|
||||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
|
||||||
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
|
|
||||||
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
|
|
||||||
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
|
||||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
|
||||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
|
||||||
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
|
|
||||||
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
|
||||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210316164454-77fc1eacc6aa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549 h1:OL5GcZ2XPkte3dpfuFQ9o884vrE3BZQhajdntNMruv4=
|
golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549 h1:OL5GcZ2XPkte3dpfuFQ9o884vrE3BZQhajdntNMruv4=
|
||||||
golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210531080801-fdfd190a6549/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
|
||||||
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
|
||||||
|
|||||||
@@ -4,13 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"bufio"
|
|
||||||
"path/filepath"
|
|
||||||
"io/ioutil"
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||||
|
|
||||||
@@ -18,12 +11,6 @@ import (
|
|||||||
"github.com/shirou/gopsutil/host"
|
"github.com/shirou/gopsutil/host"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cloudflaredTunnelJson struct {
|
|
||||||
AccountTag string `json:"AccountTag"`
|
|
||||||
TunnelSecret string `json:"TunnelSecret"`
|
|
||||||
TunnelID string `json:"TunnelID"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetUptimeInSeconds: Returns a value (as string) of the total system uptime
|
// GetUptimeInSeconds: Returns a value (as string) of the total system uptime
|
||||||
func GetUptimeInSeconds() string {
|
func GetUptimeInSeconds() string {
|
||||||
uptime, _ := host.Uptime()
|
uptime, _ := host.Uptime()
|
||||||
@@ -98,191 +85,3 @@ func SetupCloudOptions() {
|
|||||||
// In the end of this operation takes place, remove the env file as to not overwrite any options once they are set.
|
// In the end of this operation takes place, remove the env file as to not overwrite any options once they are set.
|
||||||
utils.Exec("/", "rm", []string{cloudEnvFileLocationPath})
|
utils.Exec("/", "rm", []string{cloudEnvFileLocationPath})
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartService: Starts a service
|
|
||||||
func StartService(serviceID string) {
|
|
||||||
wsPath := utils.GetPath(utils.WsPath)
|
|
||||||
fmt.Println("Starting" + serviceID + "service")
|
|
||||||
cmdargs := []string{"start", serviceID}
|
|
||||||
utils.Exec(wsPath, "systemctl", cmdargs)
|
|
||||||
}
|
|
||||||
|
|
||||||
// StopService: Stops a service
|
|
||||||
func StopService(serviceID string) {
|
|
||||||
wsPath := utils.GetPath(utils.WsPath)
|
|
||||||
fmt.Println("Stopping" + serviceID + "service")
|
|
||||||
cmdargs := []string{"stop", "cloudflared"}
|
|
||||||
utils.Exec(wsPath, "systemctl", cmdargs)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RestartService: Restarts a service
|
|
||||||
func RestartService(serviceID string) {
|
|
||||||
wsPath := utils.GetPath(utils.WsPath)
|
|
||||||
fmt.Println("Restarting" + serviceID + "service")
|
|
||||||
cmdargs := []string{"restart", serviceID}
|
|
||||||
utils.Exec(wsPath, "systemctl", cmdargs)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetServiceStatus: Returns the status output of a service
|
|
||||||
func GetServiceStatus(serviceID string) string {
|
|
||||||
wsPath := utils.GetPath(utils.WsPath)
|
|
||||||
cmdargs := []string{"status", serviceID}
|
|
||||||
return utils.Exec(wsPath, "systemctl", cmdargs)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateTunnel: Creates a tunnel via cloudflared, needs to be authenticated first
|
|
||||||
func CreateTunnel(configDestination string) {
|
|
||||||
fmt.Println("Creating Tunnel for Edgebox.")
|
|
||||||
cmd := exec.Command("sh", "/home/system/components/edgeboxctl/scripts/cloudflared_tunnel_create.sh")
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
scanner := bufio.NewScanner(stdout)
|
|
||||||
err = cmd.Start()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
for scanner.Scan() {
|
|
||||||
fmt.Println(scanner.Text())
|
|
||||||
text := scanner.Text()
|
|
||||||
fmt.Println(text)
|
|
||||||
}
|
|
||||||
if scanner.Err() != nil {
|
|
||||||
cmd.Process.Kill()
|
|
||||||
cmd.Wait()
|
|
||||||
panic(scanner.Err())
|
|
||||||
}
|
|
||||||
|
|
||||||
// This also needs to be executed in root and non root variants
|
|
||||||
fmt.Println("Reading cloudflared folder to get the JSON file.")
|
|
||||||
isRoot := false
|
|
||||||
dir := "/home/system/.cloudflared/"
|
|
||||||
dir2 := "/root/.cloudflared/"
|
|
||||||
files, err := os.ReadDir(dir)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
var jsonFile os.DirEntry
|
|
||||||
for _, file := range files {
|
|
||||||
// check if file has json extension
|
|
||||||
if filepath.Ext(file.Name()) == ".json" {
|
|
||||||
fmt.Println("Non-Root JSON file found: " + file.Name())
|
|
||||||
jsonFile = file
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the files are not in the home folder, try the root folder
|
|
||||||
if jsonFile == nil {
|
|
||||||
files, err = os.ReadDir(dir2)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
for _, file := range files {
|
|
||||||
// check if file has json extension
|
|
||||||
if filepath.Ext(file.Name()) == ".json" {
|
|
||||||
fmt.Println("Root JSON file found: " + file.Name())
|
|
||||||
jsonFile = file
|
|
||||||
isRoot = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if jsonFile == nil {
|
|
||||||
panic("No JSON file found in directory")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Reading JSON file.")
|
|
||||||
targetDir := "/home/system/.cloudflared/"
|
|
||||||
if isRoot {
|
|
||||||
targetDir = "/root/.cloudflared/"
|
|
||||||
}
|
|
||||||
|
|
||||||
jsonFilePath := filepath.Join(targetDir, jsonFile.Name())
|
|
||||||
jsonBytes, err := ioutil.ReadFile(jsonFilePath)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Parsing JSON file.")
|
|
||||||
var data cloudflaredTunnelJson
|
|
||||||
err = json.Unmarshal(jsonBytes, &data)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error reading tunnel JSON file: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Tunnel ID is:" + data.TunnelID)
|
|
||||||
|
|
||||||
// create the config.yml file with the following content in each line:
|
|
||||||
// "url": "http://localhost:80"
|
|
||||||
// "tunnel": "<TunnelID>"
|
|
||||||
// "credentials-file": "/root/.cloudflared/<tunnelID>.json"
|
|
||||||
|
|
||||||
file := configDestination
|
|
||||||
f, err := os.Create(file)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
_, err = f.WriteString("url: http://localhost:80\ntunnel: " + data.TunnelID + "\ncredentials-file: " + jsonFilePath)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteTunnel: Deletes a tunnel via cloudflared, this does not remove the service
|
|
||||||
func DeleteTunnel() {
|
|
||||||
fmt.Println("Deleting possible previous tunnel.")
|
|
||||||
|
|
||||||
// Configure the service and start it
|
|
||||||
cmd := exec.Command("sh", "/home/system/components/edgeboxctl/scripts/cloudflared_tunnel_delete.sh")
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
scanner := bufio.NewScanner(stdout)
|
|
||||||
err = cmd.Start()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
for scanner.Scan() {
|
|
||||||
fmt.Println(scanner.Text())
|
|
||||||
text := scanner.Text()
|
|
||||||
fmt.Println(text)
|
|
||||||
}
|
|
||||||
if scanner.Err() != nil {
|
|
||||||
cmd.Process.Kill()
|
|
||||||
cmd.Wait()
|
|
||||||
panic(scanner.Err())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// InstallTunnelService: Installs the tunnel service
|
|
||||||
func InstallTunnelService(config string) {
|
|
||||||
fmt.Println("Installing cloudflared service.")
|
|
||||||
cmd := exec.Command("cloudflared", "--config", config, "service", "install")
|
|
||||||
cmd.Start()
|
|
||||||
cmd.Wait()
|
|
||||||
}
|
|
||||||
|
|
||||||
// RemoveTunnelService: Removes the tunnel service
|
|
||||||
func RemoveTunnelService() {
|
|
||||||
wsPath := utils.GetPath(utils.WsPath)
|
|
||||||
fmt.Println("Removing possibly previous service install.")
|
|
||||||
cmd := exec.Command("cloudflared", "service", "uninstall")
|
|
||||||
cmd.Start()
|
|
||||||
cmd.Wait()
|
|
||||||
|
|
||||||
fmt.Println("Removing cloudflared files")
|
|
||||||
cmdargs := []string{"-rf", "/home/system/.cloudflared"}
|
|
||||||
utils.Exec(wsPath, "rm", cmdargs)
|
|
||||||
cmdargs = []string{"-rf", "/etc/cloudflared/config.yml"}
|
|
||||||
utils.Exec(wsPath, "rm", cmdargs)
|
|
||||||
cmdargs = []string{"-rf", "/root/.cloudflared/cert.pem"}
|
|
||||||
utils.Exec(wsPath, "rm", cmdargs)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
+15
-160
@@ -7,17 +7,12 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
"os"
|
|
||||||
"bufio"
|
|
||||||
|
|
||||||
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
"github.com/edgebox-iot/edgeboxctl/internal/diagnostics"
|
||||||
"github.com/edgebox-iot/edgeboxctl/internal/edgeapps"
|
"github.com/edgebox-iot/edgeboxctl/internal/edgeapps"
|
||||||
"github.com/edgebox-iot/edgeboxctl/internal/storage"
|
"github.com/edgebox-iot/edgeboxctl/internal/storage"
|
||||||
"github.com/edgebox-iot/edgeboxctl/internal/system"
|
"github.com/edgebox-iot/edgeboxctl/internal/system"
|
||||||
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
"github.com/edgebox-iot/edgeboxctl/internal/utils"
|
||||||
|
|
||||||
_ "github.com/go-sql-driver/mysql" // Mysql Driver
|
_ "github.com/go-sql-driver/mysql" // Mysql Driver
|
||||||
_ "github.com/mattn/go-sqlite3" // SQlite Driver
|
_ "github.com/mattn/go-sqlite3" // SQlite Driver
|
||||||
)
|
)
|
||||||
@@ -34,7 +29,10 @@ type Task struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type taskSetupTunnelArgs struct {
|
type taskSetupTunnelArgs struct {
|
||||||
DomainName string `json:"domain_name"`
|
BootnodeAddress string `json:"bootnode_address"`
|
||||||
|
BootnodeToken string `json:"bootnode_token"`
|
||||||
|
AssignedAddress string `json:"assigned_address"`
|
||||||
|
NodeName string `json:"node_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type taskStartEdgeAppArgs struct {
|
type taskStartEdgeAppArgs struct {
|
||||||
@@ -66,7 +64,6 @@ type taskEnablePublicDashboardArgs struct {
|
|||||||
InternetURL string `json:"internet_url"`
|
InternetURL string `json:"internet_url"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const STATUS_CREATED int = 0
|
const STATUS_CREATED int = 0
|
||||||
const STATUS_EXECUTING int = 1
|
const STATUS_EXECUTING int = 1
|
||||||
const STATUS_FINISHED int = 2
|
const STATUS_FINISHED int = 2
|
||||||
@@ -137,36 +134,16 @@ func ExecuteTask(task Task) Task {
|
|||||||
switch task.Task {
|
switch task.Task {
|
||||||
case "setup_tunnel":
|
case "setup_tunnel":
|
||||||
|
|
||||||
log.Println("Setting up Cloudflare Tunnel...")
|
log.Println("Setting up bootnode connection...")
|
||||||
var args taskSetupTunnelArgs
|
var args taskSetupTunnelArgs
|
||||||
err := json.Unmarshal([]byte(task.Args.String), &args)
|
err := json.Unmarshal([]byte(task.Args.String), &args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error reading arguments of setup_tunnel task: %s", err)
|
log.Printf("Error reading arguments of setup_bootnode task: %s", err)
|
||||||
status := "{\"status\": \"error\", \"message\": \"The Domain Name you are going to Authorize must be provided beforehand! Please insert a domain name and try again.\"}"
|
|
||||||
utils.WriteOption("TUNNEL_STATUS", status)
|
|
||||||
} else {
|
} else {
|
||||||
taskResult := taskSetupTunnel(args)
|
taskResult := taskSetupTunnel(args)
|
||||||
task.Result = sql.NullString{String: taskResult, Valid: true}
|
task.Result = sql.NullString{String: taskResult, Valid: true}
|
||||||
}
|
}
|
||||||
|
|
||||||
case "start_tunnel":
|
|
||||||
|
|
||||||
log.Println("Starting Cloudflare Tunnel...")
|
|
||||||
taskResult := taskStartTunnel()
|
|
||||||
task.Result = sql.NullString{String: taskResult, Valid: true}
|
|
||||||
|
|
||||||
case "stop_tunnel":
|
|
||||||
|
|
||||||
log.Println("Stopping Cloudflare Tunnel...")
|
|
||||||
taskResult := taskStopTunnel()
|
|
||||||
task.Result = sql.NullString{String: taskResult, Valid: true}
|
|
||||||
|
|
||||||
case "disable_tunnel":
|
|
||||||
|
|
||||||
log.Println("Disabling Cloudflare Tunnel...")
|
|
||||||
taskResult := taskDisableTunnel()
|
|
||||||
task.Result = sql.NullString{String: taskResult, Valid: true}
|
|
||||||
|
|
||||||
case "install_edgeapp":
|
case "install_edgeapp":
|
||||||
|
|
||||||
log.Println("Installing EdgeApp...")
|
log.Println("Installing EdgeApp...")
|
||||||
@@ -351,141 +328,19 @@ func ExecuteSchedules(tick int) {
|
|||||||
|
|
||||||
func taskSetupTunnel(args taskSetupTunnelArgs) string {
|
func taskSetupTunnel(args taskSetupTunnelArgs) string {
|
||||||
fmt.Println("Executing taskSetupTunnel")
|
fmt.Println("Executing taskSetupTunnel")
|
||||||
|
|
||||||
wsPath := utils.GetPath(utils.WsPath)
|
wsPath := utils.GetPath(utils.WsPath)
|
||||||
|
cmdargs := []string{"gen", "--name", args.NodeName, "--token", args.BootnodeToken, args.BootnodeAddress + ":8655", "--prefix", args.AssignedAddress}
|
||||||
|
utils.Exec(wsPath, "tinc-boot", cmdargs)
|
||||||
|
|
||||||
// Stop a the service if it is running
|
cmdargs = []string{"start", "tinc@dnet"}
|
||||||
system.StopService("cloudflared")
|
utils.Exec(wsPath, "systemctl", cmdargs)
|
||||||
|
|
||||||
// Uninstall the service if it is installed
|
cmdargs = []string{"enable", "tinc@dnet"}
|
||||||
system.RemoveTunnelService()
|
utils.Exec(wsPath, "systemctl", cmdargs)
|
||||||
|
|
||||||
fmt.Println("Creating cloudflared folder")
|
output := "OK" // Better check / logging of command execution result.
|
||||||
cmdargs := []string{"/home/system/.cloudflared"}
|
return output
|
||||||
utils.Exec(wsPath, "mkdir", cmdargs)
|
|
||||||
|
|
||||||
cmd := exec.Command("sh", "/home/system/components/edgeboxctl/scripts/cloudflared_login.sh")
|
|
||||||
stdout, err := cmd.StdoutPipe()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
scanner := bufio.NewScanner(stdout)
|
|
||||||
err = cmd.Start()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
url := ""
|
|
||||||
for scanner.Scan() {
|
|
||||||
fmt.Println(scanner.Text())
|
|
||||||
text := scanner.Text()
|
|
||||||
if strings.Contains(text, "https://") {
|
|
||||||
url = text
|
|
||||||
fmt.Println("Tunnel setup is requesting auth with URL: " + url)
|
|
||||||
status := "{\"status\": \"waiting\", \"login_link\": \"" + url + "\"}"
|
|
||||||
utils.WriteOption("TUNNEL_STATUS", status)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if scanner.Err() != nil {
|
|
||||||
cmd.Process.Kill()
|
|
||||||
cmd.Wait()
|
|
||||||
panic(scanner.Err())
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
fmt.Println("Running async")
|
|
||||||
cmd.Wait()
|
|
||||||
|
|
||||||
// Keep retrying to read cert.pem file until it is created
|
|
||||||
// When running as a service, the cert is saved to a different folder,
|
|
||||||
// so we check both :)
|
|
||||||
for {
|
|
||||||
_, err := os.Stat("/home/system/.cloudflared/cert.pem")
|
|
||||||
_, err2 := os.Stat("/root/.cloudflared/cert.pem")
|
|
||||||
if err == nil || err2 == nil {
|
|
||||||
fmt.Println("cert.pem file detected")
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
fmt.Println("Waiting for cert.pem file to be created")
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Tunnel auth setup finished without errors.")
|
|
||||||
status := "{\"status\": \"starting\", \"login_link\": \"" + url + "\"}"
|
|
||||||
utils.WriteOption("TUNNEL_STATUS", status)
|
|
||||||
|
|
||||||
// Remove old tunnel if it exists, and create from scratch
|
|
||||||
system.DeleteTunnel()
|
|
||||||
|
|
||||||
// Create new tunnel (destination config file is param)
|
|
||||||
system.CreateTunnel("/home/system/.cloudflared/config.yml")
|
|
||||||
|
|
||||||
fmt.Println("Creating DNS Routes for @ and *.")
|
|
||||||
cmd = exec.Command("cloudflared", "tunnel", "route", "dns", "-f" ,"edgebox", "*." + args.DomainName)
|
|
||||||
cmd.Start()
|
|
||||||
err = cmd.Wait()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
cmd = exec.Command("cloudflared", "tunnel", "route", "dns", "-f" ,"edgebox", args.DomainName)
|
|
||||||
cmd.Start()
|
|
||||||
err = cmd.Wait()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
domainNameInfo := args.DomainName
|
|
||||||
utils.WriteOption("DOMAIN_NAME", domainNameInfo)
|
|
||||||
|
|
||||||
// Install service with given config file
|
|
||||||
system.InstallTunnelService("/home/system/.cloudflared/config.yml")
|
|
||||||
|
|
||||||
// Start the service
|
|
||||||
system.StartService("cloudflared")
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("Tunnel auth setup finished with errors.")
|
|
||||||
status := "{\"status\": \"error\", \"login_link\": \"" + url + "\"}"
|
|
||||||
utils.WriteOption("TUNNEL_STATUS", status)
|
|
||||||
log.Fatal(err)
|
|
||||||
} else {
|
|
||||||
fmt.Println("Tunnel auth setup finished without errors.")
|
|
||||||
status := "{\"status\": \"connected\", \"login_link\": \"" + url + "\", \"domain\": \"" + args.DomainName + "\"}"
|
|
||||||
utils.WriteOption("TUNNEL_STATUS", status)
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("Finished running async")
|
|
||||||
}()
|
|
||||||
|
|
||||||
return "{\"url\": \"" + url + "\"}"
|
|
||||||
}
|
|
||||||
|
|
||||||
func taskStartTunnel() string {
|
|
||||||
fmt.Println("Executing taskStartTunnel")
|
|
||||||
system.StartService("cloudflared")
|
|
||||||
domainName := utils.ReadOption("DOMAIN_NAME")
|
|
||||||
status := "{\"status\": \"connected\", \"domain\": \"" + domainName + "\"}"
|
|
||||||
utils.WriteOption("TUNNEL_STATUS", status)
|
|
||||||
return "{\"status\": \"ok\"}"
|
|
||||||
}
|
|
||||||
|
|
||||||
func taskStopTunnel() string {
|
|
||||||
fmt.Println("Executing taskStopTunnel")
|
|
||||||
system.StopService("cloudflared")
|
|
||||||
domainName := utils.ReadOption("DOMAIN_NAME")
|
|
||||||
status := "{\"status\": \"stopped\", \"domain\": \"" + domainName + "\"}"
|
|
||||||
utils.WriteOption("TUNNEL_STATUS", status)
|
|
||||||
return "{\"status\": \"ok\"}"
|
|
||||||
}
|
|
||||||
|
|
||||||
func taskDisableTunnel() string {
|
|
||||||
fmt.Println("Executing taskDisableTunnel")
|
|
||||||
system.StopService("cloudflared")
|
|
||||||
system.DeleteTunnel()
|
|
||||||
system.RemoveTunnelService()
|
|
||||||
utils.DeleteOption("DOMAIN_NAME")
|
|
||||||
utils.DeleteOption("TUNNEL_STATUS")
|
|
||||||
return "{\"status\": \"ok\"}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func taskInstallEdgeApp(args taskInstallEdgeAppArgs) string {
|
func taskInstallEdgeApp(args taskInstallEdgeAppArgs) string {
|
||||||
|
|||||||
@@ -192,47 +192,3 @@ func WriteOption(optionKey string, optionValue string) {
|
|||||||
|
|
||||||
db.Close()
|
db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadOption : Reads a key value pair option from the api shared database
|
|
||||||
func ReadOption(optionKey string) string {
|
|
||||||
|
|
||||||
db, err := sql.Open("sqlite3", GetSQLiteDbConnectionDetails())
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
var optionValue string
|
|
||||||
|
|
||||||
err = db.QueryRow("SELECT value FROM option WHERE name = ?", optionKey).Scan(&optionValue)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
db.Close()
|
|
||||||
|
|
||||||
return optionValue
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteOption : Deletes a key value pair option from the api shared database
|
|
||||||
func DeleteOption(optionKey string) {
|
|
||||||
|
|
||||||
db, err := sql.Open("sqlite3", GetSQLiteDbConnectionDetails())
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
statement, err := db.Prepare("DELETE FROM option WHERE name = ?;") // Prepare SQL Statement
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = statement.Exec(optionKey) // Execute SQL Statement
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
db.Close()
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
echo "Starting script login"
|
|
||||||
cloudflared tunnel login 2>&1 | tee /home/system/components/edgeboxctl/scripts/output.log &
|
|
||||||
echo "sleeping 5 seconds"
|
|
||||||
sleep 5
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
echo "Starting script create"
|
|
||||||
# script -q -c "cloudflared tunnel login 2>&1 | tee /app/output.log" &
|
|
||||||
cloudflared tunnel create edgebox 2>&1 | tee /home/system/components/edgeboxctl/scripts/output.log
|
|
||||||
echo "sleeping 5 seconds"
|
|
||||||
sleep 5
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
echo "Starting script delete"
|
|
||||||
TUNNEL_ORIGIN_CERT=/home/system/.cloudflared/cert.pem
|
|
||||||
cloudflared tunnel delete edgebox 2>&1 | tee /home/system/components/edgeboxctl/scripts/output.log &
|
|
||||||
echo "sleeping 5 seconds"
|
|
||||||
sleep 5
|
|
||||||
Reference in New Issue
Block a user