Skip to content

Commit

Permalink
v1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
plutobell committed Aug 13, 2021
1 parent 429bbbd commit 7b90295
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

**2021-08-13**

* v1.3.2 :
* Added automatic version detection and prompting
* v1.3.1 :
* Added csrf protection
* Adjusted some details
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @Author: github.com/plutobell
# @Creation: 2020-08-10
# @Last modification: 2021-08-13
# @Version: 1.3.1
# @Version: 1.3.2

PROGRAM = pi-dashboard-go
OUTPUT = build
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
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.3.1
Pi Dashboard Go version: 1.3.2
Project address: https://github.com/plutobell/pi-dashboard-go

Usage: Pi Dashboard Go [-auth USR:PSW] [-disk Paths] [-help]
Expand Down
28 changes: 24 additions & 4 deletions assets/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @Author: github.com/plutobell
// @Creation: 2020-08-01
// @Last modification: 2021-08-13
// @Version: 1.3.1
// @Version: 1.3.2

window.oncontextmenu=function(){return false;}
window.onkeydown = window.onkeyup = window.onkeypress = function (event) {
Expand Down Expand Up @@ -493,7 +493,7 @@ $("#reboot").click(function(){
window.alert("Fail");
$("#loading").show();
unScroll();
});
});
});

$("#shutdown").click(function(){
Expand All @@ -508,7 +508,7 @@ $("#shutdown").click(function(){
window.alert("Fail");
$("#loading").show();
unScroll();
});
});
});

$("#dropcaches").click(function(){
Expand All @@ -523,7 +523,27 @@ $("#dropcaches").click(function(){
window.alert("Fail");
// $("#loading").show();
// unScroll();
});
});
});

// Check New Version
$(document).ready(function(){
$.ajaxSetup(csrfAddToAjaxHeader());
$.post('/api/operation?action=checknewversion', function(data){
if (data.new_version != "" && data.new_version_url != "") {
$("#new-url").attr("href", data.new_version_url);
$("#new-version").attr("title", "v" + data.new_version);
$("#new-box").show(1000);
} else {
$("#new-box").hide(1000);
$("#new-url").attr("href", "javascript:void(0);");
$("#new-version").attr("title", "New Version");
}
}).fail(function() {
$("#new-box").hide(1000);
$("#new-url").attr("href", "javascript:void(0);");
$("#new-version").attr("title", "New Version");
});
});


Expand Down
2 changes: 1 addition & 1 deletion assets/login.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@
@Author: github.com/plutobell
@Creation: 2020-08-01
@Last modification: 2021-08-13
@Version: 1.3.1 -->
@Version: 1.3.2 -->
</body>
</html>
3 changes: 2 additions & 1 deletion assets/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
<li id="reboot"><img src="assets/btns/reboot.png" width="29px" height="29px" alt="Reboot Device" title="Reboot Device" /></li>
<li id="shutdown"><img src="assets/btns/shutdown.png" width="30px" height="30px" alt="Shutdown Device" title="Shutdown Device" /></li>
<li id="dropcaches"><img src="assets/btns/clean.png" width="30px" height="30px" alt="Drop Caches" title="Drop Caches" /></li>
<li id="new-box" style="display: none;"><a id="new-url" target="_blank" href="javascript:void(0);"><img id="new-version" src="assets/btns/new.png" width="30px" height="30px" alt="New Version" title="New Version" /></a></li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -392,6 +393,6 @@
@Author: github.com/plutobell
@Creation: 2020-08-01
@Last modification: 2021-08-13
@Version: 1.3.1 -->
@Version: 1.3.2 -->
</body>
</html>
2 changes: 1 addition & 1 deletion device.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @Author: github.com/plutobell
// @Creation: 2020-08-01
// @Last modification: 2021-08-13
// @Version: 1.3.1
// @Version: 1.3.2

package main

Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @Author: github.com/plutobell
// @Creation: 2020-08-01
// @Last modification: 2021-08-13
// @Version: 1.3.1
// @Version: 1.3.2

package main

Expand All @@ -18,10 +18,12 @@ import (
)

const (
//PROJECT 项目地址
PROJECT string = "https://github.com/plutobell/pi-dashboard-go"
//AUTHOR 作者信息
AUTHOR string = "github:plutobell"
//VERSION 版本信息
VERSION string = "1.3.1"
VERSION string = "1.3.2"
//USERNAME 默认用户
USERNAME string = "pi"
//PASSWORD 默认密码
Expand Down Expand Up @@ -77,7 +79,7 @@ func main() {
}
if version {
fmt.Println("Pi Dashboard Go " + VERSION)
fmt.Println("Project address: https://github.com/plutobell/pi-dashboard-go")
fmt.Println("Project address: " + PROJECT)
return
}
netDevs, err := Popen("cat /proc/net/dev")
Expand Down
64 changes: 59 additions & 5 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @Author: github.com/plutobell
// @Creation: 2020-08-01
// @Last modification: 2021-08-13
// @Version: 1.3.1
// @Version: 1.3.2

package main

Expand All @@ -13,6 +13,7 @@ import (
"fmt"
"io"
"io/fs"
"io/ioutil"
"math/rand"
"net/http"
"os"
Expand Down Expand Up @@ -248,17 +249,31 @@ func API(c echo.Context) error {
"status": true,
}

switch operate := c.QueryParam("action"); {
case operate == "reboot":
switch operation := c.QueryParam("action"); {
case operation == "reboot":
go Popen("reboot")
return c.JSON(http.StatusOK, status)
case operate == "shutdown":
case operation == "shutdown":
go Popen("shutdown -h now")
return c.JSON(http.StatusOK, status)
case operate == "dropcaches":
case operation == "dropcaches":
go Popen("echo 3 > /proc/sys/vm/drop_caches")
return c.JSON(http.StatusOK, status)
case operation == "checknewversion":
nowVersion, _ := getLatestVersionFromGitHub()
result := make(map[string]string)
if nowVersion > VERSION {
result["new_version"] = nowVersion
result["new_version_url"] = PROJECT + "/releases/tag/v" + nowVersion
} else {
result["new_version"] = ""
result["new_version_url"] = ""
}

return c.JSON(http.StatusOK, result)

}

}

status := map[string]string{
Expand Down Expand Up @@ -306,3 +321,42 @@ func getRandomString(len int) string {

return string(result)
}

func getLatestVersionFromGitHub() (nowVersion string, downloadURL []string) {
url := "https://api.github.com/repos/plutobell/pi-dashboard-go/releases/latest"

resp, err := http.Get(url)
if err != nil {
panic(err)
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}

result := make(map[string]interface{})
err = json.Unmarshal(body, &result)
if err != nil {
panic(err)
}

for key, value := range result {
if key == "tag_name" {
nowVersion = value.(string)[1:]
}
if key == "assets" {
assets := value.([]interface{})
for _, architecture := range assets {
for key, value := range architecture.(map[string]interface{}) {
if key == "browser_download_url" {
downloadURL = append(downloadURL, value.(string))
}
}
}
}
}

return nowVersion, downloadURL
}
8 changes: 8 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,11 @@ func Test_getRandomString(t *testing.T) {
t.Error("Fail")
}
}

func Test_getLatestVersionFromGitHub(t *testing.T) {
if nowVersion, downloadURL := getLatestVersionFromGitHub(); nowVersion != "" && len(downloadURL) > 0 {
t.Log("Pass")
} else {
t.Error("Fail")
}
}

0 comments on commit 7b90295

Please sign in to comment.