Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
plutobell committed Apr 4, 2021
1 parent 19ed9a7 commit d265d34
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 89 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog #

**2021-04-05**

* v1.1.0 :
* Replace go.rice with go embed
* Fix the bug of program error when unable to get cpu model
* Added new command line parameter: interval
* Added a different header image for non-Raspberry Pi devices

**2021-03-31**

* v1.0.10 :
Expand Down
24 changes: 6 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# @Description: Golang implementation of pi-dashboard
# @Author: github.com/plutobell
# @Creation: 2020-08-10
# @Last modify: 2021-03-31
# @Version: 1.0.10
# @Last modify: 2021-04-05
# @Version: 1.1.0

PROGRAM = pi-dashboard-go
OUTPUT = build
GOOS = linux
OS_NAME = $(shell uname -o)

build: clean vet rice-box.go main.go server.go device.go device_test.go go.mod go.sum
build: clean vet main.go server.go device.go device_test.go go.mod go.sum
@echo "-> Building"

@echo "-> 1 Building the "${PROGRAM}_${GOOS}_armv5_32
Expand All @@ -24,10 +24,10 @@ build: clean vet rice-box.go main.go server.go device.go device_test.go go.mod

@echo "-> 4 Building the "${PROGRAM}_${GOOS}_armv5_64
@GOOS=${GOOS} GOARCH=arm64 GOARM=5 go build -trimpath -ldflags "-s -w" -o ./${OUTPUT}/${PROGRAM}_${GOOS}_armv5_64

@echo "-> 5 Building the "${PROGRAM}_${GOOS}_armv6_64
@GOOS=${GOOS} GOARCH=arm64 GOARM=6 go build -trimpath -ldflags "-s -w" -o ./${OUTPUT}/${PROGRAM}_${GOOS}_armv6_64

@echo "-> 6 Building the "${PROGRAM}_${GOOS}_armv7_64
@GOOS=${GOOS} GOARCH=arm64 GOARM=7 go build -trimpath -ldflags "-s -w" -o ./${OUTPUT}/${PROGRAM}_${GOOS}_armv7_64

Expand Down Expand Up @@ -57,20 +57,8 @@ test:

clean:
@echo "-> Cleaning"
@rm -rf rice-box.go
@rm -rf ./build
@echo "-> Complete"

rice-box.go:
@echo "-> Generate rice-box.go"
ifeq ($(OS_NAME), GNU/Linux)
@apt install golang-rice -y > /dev/null 2> /dev/null
else
@go get github.com/GeertJohan/go.rice > /dev/null 2> /dev/null
@go get github.com/GeertJohan/go.rice/rice > /dev/null 2> /dev/null
endif
@rice embed-go
@echo "-> Complete"

help:
@echo "-> Commands: build | run | test | vet | clean | help"
@echo "-> Commands: build | run | vet | test | clean | help"
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ chmod +x pi-dashboard-go
**Pi Dashboard Go** can be configured via command line parameters:

```
Pi Dashboard Go version: 1.0.0
Pi Dashboard Go version: 1.1.0
Project address: https://github.com/plutobell/pi-dashboard-go
Usage: Pi Dashboard Go [-help] [-version] [-port port] [-title title] [-net net] [-disk disk] [-auth usr:psw]
Usage: Pi Dashboard Go [-help] [-version] [-port port] [-title title] [-net net] [-disk disk] [-auth usr:psw] [-interval interval]
Options:
-auth string
Expand All @@ -46,6 +46,8 @@ Options:
specify the disk (default "/")
-help
this help
-interval string
specify the update interval in seconds (default "1")
-net string
specify the network device (default "lo")
-port string
Expand All @@ -54,19 +56,15 @@ Options:
specify the website title (default "Pi Dashboard Go")
-version
show version and exit
```



## Thanks

* **[Pi Dashboard](https://github.com/spoonysonny/pi-dashboard)**

* **[echo](https://github.com/labstack/echo)**

* **[go.rice](https://github.com/GeertJohan/go.rice)**
* **[Golang](https://golang.org/)**
* **[echo](https://github.com/labstack/echo)**



Expand Down
6 changes: 3 additions & 3 deletions assets/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// @Description: Golang implementation of pi-dashboard
// @Author: github.com/plutobell
// @Creation: 2020-08-01
// @Last modify: 2021-03-31
// @Version: 1.0.10
// @Last modify: 2021-04-05
// @Version: 1.1.0

window.oncontextmenu=function(){return false;}
window.onkeydown = window.onkeyup = window.onkeypress = function () {
Expand Down Expand Up @@ -434,7 +434,7 @@ $(document).ready(function() {

}

}, 1000);
}, (parseInt($("#interval").text()) * 1000) );
}
)

Expand Down
Binary file added assets/devices/linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
7 changes: 4 additions & 3 deletions assets/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
<div class="container">
<div class="row">
<div class="col-md-3">
<div style="text-align: center; padding: 20px 0;"><img src="assets/devices/raspberry-pi.png" /></div>
<div style="text-align: center; padding: 20px 0;"><img src="assets/devices/{{.device_photo}}" /></div>
<div style="background-color: #E5E6E4; padding: 5px; border-radius: 3px;">
<div class="text-center" style="margin:10px; padding: 10px 0 10px 0; border-radius: 3px;"><div id="pimodel" style="font-size: 90%; font-weight: bolder; text-shadow: 0 1px 0 #fff;">{{.model}}</div></div>
<div class="text-center" style="margin:20px; padding: 10px 0 10px 0; background-color:#ADF6B1; border-radius: 3px;"><div class="label">IP</div><div id="hostip" style="font-size: 150%; font-weight: bolder;">{{.ip}}</div></div>
Expand Down Expand Up @@ -382,13 +382,14 @@
<div class="rect5"></div>
</div>
</div>
<span id="interval" style="display: none;">{{.interval}}</span>
<script src="assets/dashboard.js"></script>
<!--
@Program : Pi Dashboard Go (https://github.com/plutobell/pi-dashboard-go)
@Description: Golang implementation of pi-dashboard
@Author: github.com/plutobell
@Creation: 2020-08-01
@Last modify: 2021-03-31
@Version: 1.0.10 -->
@Last modify: 2021-04-05
@Version: 1.1.0 -->
</body>
</html>
25 changes: 20 additions & 5 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// @Description: Golang implementation of pi-dashboard
// @Author: github.com/plutobell
// @Creation: 2020-08-01
// @Last modify: 2021-03-31
// @Version: 1.0.10
// @Last modify: 2021-04-05
// @Version: 1.1.0

package main

Expand Down Expand Up @@ -108,19 +108,34 @@ func Device() map[string]string {
cpuTemperature, _ := strconv.Atoi(device["cpu_temperature"])
device["uptime"] = resolveTime(device["uptime"])
device["hostname"] = strings.Replace(strings.Replace(device["hostname"], " ", "", -1), "\n", "", -1)
device["system"] = strings.Replace(strings.Replace(strings.Split(device["system"], "\"")[1], " GNU/Linux ", " ", -1), "\"", "", -1)
if strings.Contains(device["system"], "\"") {
device["system"] = strings.Replace(strings.Replace(strings.Split(device["system"], "\"")[1], " GNU/Linux ", " ", -1), "\"", "", -1)
} else {
device["system"] = "NaN"
}

if arch == "arm" {
device["cpu_temperature"] = strconv.FormatFloat(float64(cpuTemperature)/1000, 'f', 1, 64)
if strings.Contains(device["model"], ":") {
device["model"] = strings.Split(device["model"], ":")[1]
} else {
device["model"] = ""
device["model"] = "NaN"
}
} else {
device["cpu_temperature"] = "NaN"
device["model"] = "Linux Computer"
device["cpu_model_name"] = strings.Trim(strings.Split(device["cpu_model_name"], ":")[1], " ")
if strings.Contains(device["cpu_model_name"], ":") {
device["cpu_model_name"] = strings.Trim(strings.Split(device["cpu_model_name"], ":")[1], " ")
} else {
device["cpu_model_name"] = "NaN"
}
}
if strings.Contains(strings.ToLower(device["model"]), "raspberry") {
device["device_photo"] = "raspberry.png"
} else {
device["device_photo"] = "linux.png"
}

device["login_user_count"] = strings.Split(device["login_user_count"], "=")[1]
device["ip"] = strings.Split(device["ip"], "/")[0]
device["now_time"] = time.Now().Format("2006-01-02 15:04:05")
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module pi-dashboard-go

go 1.15
go 1.16

require (
github.com/GeertJohan/go.rice v1.0.2
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/labstack/echo/v4 v4.1.17
)
22 changes: 4 additions & 18 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
github.com/GeertJohan/go.incremental v1.0.0 h1:7AH+pY1XUgQE4Y1HcXYaMqAI0m9yrFqo/jt0CW30vsg=
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voiMLQ=
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
github.com/GeertJohan/go.rice v1.0.2 h1:PtRw+Tg3oa3HYwiDBZyvOJ8LdIyf6lAovJJtr7YOAYk=
github.com/GeertJohan/go.rice v1.0.2/go.mod h1:af5vUNlDNkCjOZeSGFgIJxDje9qdjsO6hshx0gTmZt4=
github.com/akavel/rsrc v0.8.0 h1:zjWn7ukO9Kc5Q62DOJCcxGpXC18RawVtYAGdz2aLlfw=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
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/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/labstack/echo v1.4.4 h1:1bEiBNeGSUKxcPDGfZ/7IgdhJJZx8wV/pICJh4W2NJI=
github.com/labstack/echo v3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
github.com/labstack/echo/v4 v4.1.17 h1:PQIBaRplyRy3OjwILGkPg89JRtH2x5bssi59G2EL3fo=
github.com/labstack/echo/v4 v4.1.17/go.mod h1:Tn2yRQL/UclUalpb5rPdXDevbkJ+lp/2svdyFBg6CHQ=
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
Expand All @@ -27,12 +14,10 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229 h1:E2B8qYyeSgv5MXpmzZXRNp8IAQ4vjxIjhpAf5hv/tAg=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
github.com/nkovacs/streamquote v1.0.0 h1:PmVIV08Zlx2lZK5fFZlMZ04eHcDTIFJCv/5/0twVUow=
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
Expand Down Expand Up @@ -60,4 +45,5 @@ golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
54 changes: 43 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// @Description: Golang implementation of pi-dashboard
// @Author: github.com/plutobell
// @Creation: 2020-08-01
// @Last modify: 2021-03-31
// @Version: 1.0.10
// @Last modify: 2021-04-05
// @Version: 1.1.0

package main

Expand All @@ -12,14 +12,16 @@ import (
"fmt"
"log"
"os"
"strconv"
"strings"
"unicode"
)

const (
//AUTHOR 作者信息
AUTHOR string = "github:plutobell"
//VERSION 版本信息
VERSION string = "1.0.10"
VERSION string = "1.1.0"
//USERNAME 默认用户
USERNAME string = "pi"
//PASSWORD 默认密码
Expand All @@ -29,16 +31,18 @@ const (
var (
help bool
version bool
//Port 端口
// Port 端口
Port string
//Title 网站标题
// Title 网站标题
Title string
//Net 网卡名称
// Net 网卡名称
Net string
//Disk 硬盘路径
// Disk 硬盘路径
Disk string
//Auth 用户名和密码
// Auth 用户名和密码
Auth string
// Interval 页面更新间隔
Interval string
)

func init() {
Expand All @@ -49,6 +53,7 @@ func init() {
flag.StringVar(&Net, "net", "lo", "specify the network device")
flag.StringVar(&Disk, "disk", "/", "specify the disk")
flag.StringVar(&Auth, "auth", USERNAME+":"+PASSWORD, "specify username and password")
flag.StringVar(&Interval, "interval", "1", "specify the update interval in seconds")

flag.Usage = usage
}
Expand All @@ -61,13 +66,14 @@ func main() {
return
}
if version {
fmt.Println("Pi Dashboard Go " + VERSION)
fmt.Println("Pi Dashboard Go " + VERSION)
fmt.Println("Project address: https://github.com/plutobell/pi-dashboard-go")
return
}
netDevs, err := Popen("cat /proc/net/dev")
if err != nil {
log.Fatal(err)
return
}
if !strings.Contains(netDevs, Net+":") {
fmt.Println("Network card does not exist")
Expand All @@ -76,6 +82,7 @@ func main() {
diskLists, err := Popen("blkid")
if err != nil {
log.Fatal(err)
return
}
if Disk != "/" {
if !strings.Contains(diskLists, Disk+":") {
Expand All @@ -101,14 +108,39 @@ func main() {
return
}

isDigit := true
for _, r := range Interval {
if !unicode.IsDigit(rune(r)) {
isDigit = false
break
}
}
if !isDigit {
fmt.Println("Interval parameter value is invalid")
return
}

IntervalInt, err := strconv.Atoi(Interval)
if err != nil {
log.Fatal(err)
return
}
if IntervalInt > 900 {
fmt.Println("Interval is too long")
return
} else if IntervalInt < 0 {
fmt.Println("Interval should be no less than 0")
return
}

Server()
}

func usage() {
fmt.Fprintf(os.Stderr, `Pi Dashboard Go version: %s
fmt.Fprintf(os.Stderr, `Pi Dashboard Go version: %s
Project address: https://github.com/plutobell/pi-dashboard-go
Usage: Pi Dashboard Go [-help] [-version] [-port port] [-title title] [-net net] [-disk disk] [-auth usr:psw]
Usage: Pi Dashboard Go [-help] [-version] [-port port] [-title title] [-net net] [-disk disk] [-auth usr:psw] [-interval interval]
Options:
`, VERSION)
Expand Down
Loading

0 comments on commit d265d34

Please sign in to comment.