Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #21 from mattkasun/develop
Browse files Browse the repository at this point in the history
key copying and node display
  • Loading branch information
mattkasun authored Oct 30, 2021
2 parents 9af632d + bc09d1e commit 4caac98
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
7 changes: 4 additions & 3 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,16 @@ func NodeHealth(c *gin.Context) {
var nodeHealth NodeStatus
for _, node := range nodes {
nodeHealth.Mac = node.MacAddress
nodeHealth.Network = node.Network
lastupdate := time.Now().Sub(time.Unix(node.LastCheckIn, 0))
if lastupdate.Minutes() > 15.0 {
nodeHealth.Status = "Dead: Node last checked in more than 15 minutes ago"
nodeHealth.Status = "Error: Node last checked in more than 15 minutes ago: "
nodeHealth.Color = "w3-deep-orange"
} else if lastupdate.Minutes() > 5.0 {
nodeHealth.Status = "Warning: Node last checked in more than 5 minutes ago"
nodeHealth.Status = "Warning: Node last checked in more than 5 minutes ago: "
nodeHealth.Color = "w3-khaki"
} else {
nodeHealth.Status = "Healthy: Node checked in within the last 5 minutes"
nodeHealth.Status = "Healthy: Node checked in within the last 5 minutes: "
nodeHealth.Color = "w3-teal"
}
response = append(response, nodeHealth)
Expand Down
8 changes: 4 additions & 4 deletions html/keys.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
<input class="net-key" type=hidden name="net" value="">
<button class="w3-ripple" type=submit> <span class="material-icons-outlined">delete</span> Delete Key</button>
</form>
<button class="w3-ripple" onclick="copyText('accesskey');"><span class="material-icons">content_copy</span> Copy Access Key </button>
<input id="accesskey" type="text" value={{.Value}} ><br>
<button class="w3-ripple" onclick="copyText('token');"><span class="material-icons">content_copy</span> Copy Access Token </button><br>
<textarea id="token" rows="8" cols="40" >{{.AccessString}}</textarea ><br>
<button class="w3-ripple" onclick="copyText('accesskey{{.Name}}');"><span class="material-icons">content_copy</span> Copy Access Key </button>
<input id="accesskey{{.Name}}" type="text" value={{.Value}} ><br>
<button class="w3-ripple" onclick="copyText('token{{.Name}}');"><span class="material-icons">content_copy</span> Copy Access Token </button><br>
<textarea id="token{{.Name}}" rows="8" cols="40" >{{.AccessString}}</textarea ><br>
<label>Uses</label>
<input type="text" placeholder={{.Uses}} disabled><br>
</fieldset>
Expand Down
10 changes: 5 additions & 5 deletions html/nodes.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{{ define "Nodes" }}
<div id="Nodes" class="w3-content w3-white tab" style="display=none">
{{range .Nodes}}
<p><button id="button{{.MacAddress}}" class="net {{.Network}} All w3-lightgrey" onclick="expand('node{{.MacAddress}}');">{{.Name}}@{{.Network}} {{.Endpoint}} {{.Address}}</button></p>
<p><button id="button{{.MacAddress}}{{.Network}}" class="net {{.Network}} All w3-lightgrey" onclick="expand('node{{.MacAddress}}{{.Network}}');">{{.Name}}@{{.Network}} {{.Endpoint}} {{.Address}}</button></p>
{{template "NodeDetails" .}}
{{end}}
</div>
{{end}}

{{define "NodeDetails"}}
<div class="w3-content net {{.Network}} w3-hide" id='node{{.MacAddress}}'>
<div class="w3-content net {{.Network}} w3-hide" id='node{{.MacAddress}}{{.Network}}'>
<fieldset>
<legend>{{.Name }}</legend>
<form action="/edit_node" method=POST>
<form action="/edit_node" method=POST style=display:inline>
<input type=hidden name="network" value='{{.Network}}'>
<input type=hidden name="mac" value='{{.MacAddress}}'>
<label>Public IP</label>
<input type="text" placeholder={{.Endpoint}} disabled><br>
<label>Subnet</label>
<input type="text" placeholder={{.Address}} disabled><br>
<label>Status: </label><label id="node_status{{.MacAddress}}">...Checking...</label><br>
<label>Status: </label><label id="node_status{{.MacAddress}}{{.Network}}">...Checking...</label><label> {{printTimestamp .LastCheckIn}} </label><br>
<button type=submit class="w3-button">Edit</button><br>
</form>
<form action="delete_node" method=POST>
<form action="delete_node" method=POST style=display:inline>
<input type=hidden name="net" value='{{.Network}}'>
<input type=hidden name="mac" value='{{.MacAddress}}'>
<button type=submit class="w3-button" onclick="alert('Are you sure you want to delete node {{.Name}} from Network {{.Network}}?')" >Delete</button>
Expand Down
13 changes: 7 additions & 6 deletions html/script.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

function setUp(tabName, message) {
setVisibility(tabName);
getNodeStatus();
nodeStatus = window.setInterval(getNodeStatus, 30000);
if (message != "") {
alert(message)
Expand Down Expand Up @@ -128,12 +129,12 @@
}
const nodes = JSON.parse(this.responseText);
nodes.forEach((element, index, array) => {
document.getElementById("node_status"+element.Mac).innerHTML=element.Status;
document.getElementById("button"+element.Mac).classList.remove("w3-lightgrey")
document.getElementById("button"+element.Mac).classList.remove("w3-deep-orange")
document.getElementById("button"+element.Mac).classList.remove("w3-khaki")
document.getElementById("button"+element.Mac).classList.remove("w3-teal")
document.getElementById("button"+element.Mac).classList.add(element.Color)
document.getElementById("node_status"+element.Mac+element.Network).innerHTML=element.Status;
document.getElementById("button"+element.Mac+element.Network).classList.remove("w3-lightgrey")
document.getElementById("button"+element.Mac+element.Network).classList.remove("w3-deep-orange")
document.getElementById("button"+element.Mac+element.Network).classList.remove("w3-khaki")
document.getElementById("button"+element.Mac+element.Network).classList.remove("w3-teal")
document.getElementById("button"+element.Mac+element.Network).classList.add(element.Color)
});
}
xHttp.send();
Expand Down
3 changes: 0 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ func WrapRelayNetwork(network string, data models.Node) map[string]interface{} {

func AuthRequired(c *gin.Context) {
session := sessions.Default(c)
options := session.Options

fmt.Println("checking authorization\n", options)
fmt.Printf("type %v value %s\n", options, options)
loggedIn := session.Get("loggedIn")
fmt.Println("loggedIn status: ", loggedIn)
if loggedIn != true {
Expand Down
7 changes: 4 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
)

type NodeStatus struct {
Mac string
Status string
Color string
Mac string
Network string
Status string
Color string
}

type Relay struct {
Expand Down

0 comments on commit 4caac98

Please sign in to comment.