Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
plutobell committed Aug 12, 2021
1 parent 7865387 commit 7f4988c
Show file tree
Hide file tree
Showing 16 changed files with 333 additions and 133 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog #

**2021-08-12**

* v1.3.0 :
* Adjusted routing structure
* Adjusted log formatting
* Added gzip compression
* Enhanced web security
* Login request changed to asynchronous
* Refactored part of the code
* Updated dependencies

**2021-08-10**

* v1.2.1 :
Expand Down
4 changes: 2 additions & 2 deletions Makefile
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-10
# @Last modify: 2021-08-10
# @Version: 1.2.1
# @Last modify: 2021-08-12
# @Version: 1.3.0

PROGRAM = pi-dashboard-go
OUTPUT = build
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@



![](./screenshot_view.png)
![](./screenshots/screenshot_view.png)

![](./screenshot_login.png)
![](./screenshots/screenshot_login.png)



Expand Down Expand Up @@ -38,7 +38,7 @@ chmod +x pi-dashboard-go
**Pi Dashboard Go** can be configured via command line parameters:

```bash
Pi Dashboard Go version: 1.2.1
Pi Dashboard Go version: 1.3.0
Project address: https://github.com/plutobell/pi-dashboard-go

Usage: Pi Dashboard Go [-auth USR:PSW] [-disk Paths] [-help]
Expand Down
42 changes: 42 additions & 0 deletions assets/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// @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-08-12
// @Version: 1.3.0

window.oncontextmenu=function(){return false;}

$("form").keyup(function(event){
if(event.keyCode == 13){
$("#login-btn").trigger("click");
}
});

$("#login-btn").click(function(){
$("#login-btn").attr("disabled", true);
var username = $("#username").val();
var password = $("#password").val();
var json = {
"username": username,
"password": password,
};
if (username == "" || password == "") {
$("#login-tips").text("Username or password is empty")
$("#login-btn").attr("disabled", false);
} else {
$.post('/api/login', JSON.stringify(json), function(result){
if (result.status == true) {
$("#login-tips").text("")
$(window).attr('location','/');
} else if (result.status == false) {
$("#login-tips").text("Wrong credentialss")
$("#login-btn").attr("disabled", false);
}
}).fail(function() {
$("#login-tips").text("Unknown error")
$("#login-btn").attr("disabled", false);
});
}

});
15 changes: 8 additions & 7 deletions assets/login.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,17 @@
</div>
<div class="col-md-4" style="padding: 5%;">
<div style="text-align: center; width: 100%;margin-bottom: 20px;"><img src="assets/devices/{{.device_photo}}" /></div>
<form action="/login" method="POST">
<form>
<div class="form-group">
<input type="text" class="form-control box-radius" name="username" placeholder="Username" value="{{.login_username}}" required>
<input type="text" class="form-control box-radius" id="username" name="username" placeholder="Username" required>
</div>
<div class="form-group">
<input type="password" class="form-control box-radius" name="password" placeholder="Password" value="{{.login_password}}" required>
<input type="password" class="form-control box-radius" id="password" name="password" placeholder="Password" required>
</div>
<button type="submit" class="btn btn-default box-radius" style="width: 100%;">Sign in</button>
<button type="button" id="login-btn" class="btn btn-default" style="width: 100%;">Sign in</button>
</form>
<div style="color: #D6264F; text-align: center; margin-top: 20px;">
<strong>{{.login_tips}}</strong>
<strong id="login-tips"></strong>
</div>
<p class="pull-left" style="margin-top: 20px;">Powered by <a target="_blank" href="https://ojoll.com/archives/86/" style="color:#D6264F;"><strong>Pi Dashboard Go</strong></a> v{{.version}}, <a target="_blank" href="https://ojoll.com" style="color:#D6264F;">北及</a> all rights reserved. <span style="color:#eaece5;";">{{.go_version}}</span>
</p>
Expand All @@ -188,12 +188,13 @@
</div>
</div>
</div>
<script src="assets/login.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-08-10
@Version: 1.2.1 -->
@Last modify: 2021-08-12
@Version: 1.3.0 -->
</body>
</html>
34 changes: 25 additions & 9 deletions assets/dashboard.js → assets/view.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-08-10
// @Version: 1.2.1
// @Last modify: 2021-08-12
// @Version: 1.3.0

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

setInterval(function() {
$.getJSON('?ajax=true', function(data){
$.post('api/device', function(data){
$("#loading").hide();
removeUnScroll();

Expand Down Expand Up @@ -450,9 +450,25 @@ function removeUnScroll() {
}


$("#logout").click(function(){
$("#logout").attr("disabled", true);
$.post('/api/logout', function(result){
if (result.status == true) {
$("#logout").attr("disabled", false);
$(window).attr('location','/login');
} else {
$("#logout").attr("disabled", false);
window.alert("Sign out failed");
}
}).fail(function() {
$("#login").attr("disabled", false);
window.alert("Sign out failed");
});
});

$("#reboot").click(function(){
$.getJSON('?operate=reboot', function(data){
if (data.status == "ok") {
$.post('/api/operation?action=reboot', function(data){
if (data.status == true) {
window.alert("OK")
$("#loading").show();
unScroll();
Expand All @@ -465,8 +481,8 @@ $("#reboot").click(function(){
});

$("#shutdown").click(function(){
$.getJSON('?operate=shutdown', function(data){
if (data.status == "ok") {
$.post('/api/operation?action=shutdown', function(data){
if (data.status == true) {
window.alert("OK");
$("#loading").show();
unScroll();
Expand All @@ -479,8 +495,8 @@ $("#shutdown").click(function(){
});

$("#dropcaches").click(function(){
$.getJSON('?operate=dropcaches', function(data){
if (data.status == "ok") {
$.post('/api/operation?action=dropcaches', function(data){ //$.getJSON()
if (data.status == true) {
window.alert("OK");
// $("#loading").show();
// unScroll();
Expand Down
8 changes: 4 additions & 4 deletions assets/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<!-- <li><a target="_blank" href="#">Blog</a></li> -->
<li><a href="/?logout=true">Sign out</a></li>
<li><a href="#" id="logout">Sign out</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">About <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
Expand Down Expand Up @@ -385,13 +385,13 @@
</div>
</div>
<span id="interval" style="display: none;">{{.interval}}</span>
<script src="assets/dashboard.js"></script>
<script src="assets/view.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-08-10
@Version: 1.2.1 -->
@Last modify: 2021-08-12
@Version: 1.3.0 -->
</body>
</html>
30 changes: 27 additions & 3 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-08-10
// @Version: 1.2.1
// @Last modify: 2021-08-12
// @Version: 1.3.0

package main

Expand Down Expand Up @@ -52,6 +52,21 @@ func Popen(command string) (string, error) {

//Device 函数获取设备信息
func Device() map[string]string {
//piCpuModelInfo Raspberry Pi CPU型号信息
piCpuModelInfo := map[string]string{
"Raspberry Pi 4 Model B": "BCM2711",
"Raspberry Pi 3 Model B+": "BCM2837B0",
"Raspberry Pi 3 Model B": "BCM2837/A0/B0",
"Raspberry Pi 2 Model B": "BCM2836/7",
"Raspberry Pi Model B+": "BCM2835",
"Raspberry Pi Model B": "BCM2835",
"Raspberry Pi 3 Model A+": "BCM2837B0",
"Raspberry Pi Model A+": "BCM2835",
"Raspberry Pi Zero WH": "BCM2835",
"Raspberry Pi Zero W": "BCM2835",
"Raspberry Pi Zero": "BCM2835",
}

//Command 命令列表
device := make(map[string]string)
var command map[string]string = map[string]string{
Expand All @@ -65,8 +80,8 @@ func Device() map[string]string {
"system": "cat /etc/os-release | grep PRETTY_NAME=",
"arch": "arch",
"uname": "uname -a",
"cpu_revision": "cat /proc/cpuinfo | grep Revision | awk '{ print $3}'",
"model": "cat /proc/cpuinfo | grep -i Model |sort -u |head -1",
"cpu_revision": "cat /proc/cpuinfo | grep Revision | awk '{ print $3}'",
"cpu_model_name": "lscpu | grep 'Model name' | awk '{ print $3}'",
"cpu_cores": "lscpu | grep 'CPU(s):' | awk '{ print $2}'",
"cpu_status": "top -bn1 | grep -w '%Cpu(s):' | awk '{ print $2,$4,$6,$8,$10,$12,$14,$16}'",
Expand Down Expand Up @@ -122,6 +137,15 @@ func Device() map[string]string {
} else {
device["model"] = "NaN"
}

for key, value := range piCpuModelInfo {
if strings.Contains(device["model"], key) {
device["cpu_revision"] = device["cpu_model_name"]
device["cpu_model_name"] = value
break
}
}

} else {
device["cpu_temperature"] = "NaN"
device["model"] = "Linux Computer"
Expand Down
17 changes: 0 additions & 17 deletions device_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"net/http"
"testing"
)

Expand Down Expand Up @@ -34,19 +33,3 @@ func Test_bytesRound(t *testing.T) {
t.Error("Fail")
}
}

func Test_getFileSystem(t *testing.T) {
if _, ok := getFileSystem(false).(http.FileSystem); ok {
t.Log("Pass")
} else {
t.Error("Fail")
}
}

func Test_getRandomString(t *testing.T) {
if res := getRandomString(16); len(res) == 16 {
t.Log("Pass")
} else {
t.Error("Fail")
}
}
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ require (
github.com/gorilla/sessions v1.2.1
github.com/labstack/echo-contrib v0.11.0
github.com/labstack/echo/v4 v4.5.0
github.com/mattn/go-isatty v0.0.13 // indirect
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 // indirect
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
)
20 changes: 14 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
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/mattn/go-isatty v0.0.13 h1:qdl+GuBjcsKKDco5BsxPJlId98mSWNKqYA+Co0SC1yA=
github.com/mattn/go-isatty v0.0.13/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
Expand Down Expand Up @@ -322,8 +323,9 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -360,8 +362,9 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -399,18 +402,23 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57 h1:F5Gozwx4I1xtr/sr/8CFbb57iKi3297KFs0QDbGN60A=
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
Loading

0 comments on commit 7f4988c

Please sign in to comment.