UI fixes RIVM-8

This commit is contained in:
Mihail Slobodyanuk 2022-12-08 14:32:56 +02:00
parent 7cee94e5cb
commit f84f0a5f19
5 changed files with 54 additions and 8 deletions

View file

@ -170,6 +170,7 @@ func run() int {
table.Append([]string{"IPv6 subnet:", resp.Subnet}) table.Append([]string{"IPv6 subnet:", resp.Subnet})
table.Append([]string{"Coordinates:", fmt.Sprintf("%v", resp.Coords)}) table.Append([]string{"Coordinates:", fmt.Sprintf("%v", resp.Coords)})
table.Append([]string{"Public key:", resp.PublicKey}) table.Append([]string{"Public key:", resp.PublicKey})
table.Append([]string{"Private key:", resp.PrivateKey})
table.Render() table.Render()
case "getpeers": case "getpeers":

View file

@ -11,6 +11,7 @@
<script> <script>
function setFieldValue(id, value){ function setFieldValue(id, value){
//console.log(`setFieldValue(${id}, ${value})`);
var field = document.getElementById(id); var field = document.getElementById(id);
field.innerHTML = value; field.innerHTML = value;
} }
@ -49,6 +50,7 @@
tb.deleteRow(row.rowIndex); tb.deleteRow(row.rowIndex);
tb.insertBefore(row, tr[i]); tb.insertBefore(row, tr[i]);
} }
} }
function openTab(element, tabName) { function openTab(element, tabName) {
@ -70,7 +72,7 @@
// Show the current tab, and add an "is-active" class to the button that opened the tab // Show the current tab, and add an "is-active" class to the button that opened the tab
document.getElementById(tabName).className = "tab here"; document.getElementById(tabName).className = "tab here";
element.parentElement.className = "tab is-active"; element.parentElement.className = "tab is-active";
refreshRecordsList(); //refreshRecordsList();
} }
function copy2clipboard(text){ function copy2clipboard(text){
@ -174,11 +176,11 @@
} }
function add_table(peerList) { function add_table(peerList) {
var peers = []; var peers = [];
//const countries = Object.keys(peerList); //const countries = Object.keys(peerList);
// get the reference for the body // get the reference for the body
var body = document.createElement("div"); var body = document.createElement("div");
// creates a <table> element and a <tbody> element // creates a <table> element and a <tbody> element
var tbl = document.createElement("table"); var tbl = document.createElement("table");
tbl.setAttribute('id', "peer_list"); tbl.setAttribute('id', "peer_list");
@ -229,7 +231,18 @@
return peers; return peers;
} }
function togglePrivKeyVisibility() {
if(this.classList.contains("fa-eye-slash")) {
this.classList.remove("fa-eye-slash");
this.classList.add("fa-eye");
document.getElementById("priv_key_visible").innerHTML = document.getElementById("priv_key").innerHTML;
} else {
this.classList.remove("fa-eye");
this.classList.add("fa-eye-slash");
document.getElementById("priv_key_visible").innerHTML = "••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••";
}
}
</script> </script>
<style> <style>
@ -248,7 +261,11 @@
.item { .item {
padding: 10px; padding: 10px;
/*border: 1px solid #5d656d;*/ /*border: 1px solid #5d656d;*/
}
.overflow-ellipsis {
overflow: hidden;
text-overflow: ellipsis;
} }
.column { .column {
@ -396,7 +413,29 @@
</div> </div>
<div class="tab here is-hidden" id="keys"> <div class="tab here is-hidden" id="keys">
<div class="column">
<div class="container-ip">
<div class="item">Public&nbsp;Key</div>
<div id="pub_key" class="item push-right overflow-ellipsis">Public Key</div>
<div class="item">
<a class="fas fa-copy" onclick="copy2clipboard(document.getElementById('pub_key').innerHTML);"/></a>
</div>
</div>
<div class="container-ip">
<div class="item">Private&nbsp;Key</div>
<div id="priv_key" class="is-hidden" ></div>
<div id="priv_key_visible" class="item push-right overflow-ellipsis">••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••</div>
<div class="item">
<a class="fas fa-light fa-eye-slash" onclick="(togglePrivKeyVisibility.bind(this))()"></a>
</div>
<div class="item">
<a class="fas fa-copy" onclick="copy2clipboard(document.getElementById('priv_key').innerHTML);"/></a>
</div>
</div>
</div>
</div> </div>

View file

@ -192,6 +192,8 @@ func get_self(w webview.WebView) {
//found ipv6 //found ipv6
fmt.Printf("IPv6: %s\n", res.IPAddress) fmt.Printf("IPv6: %s\n", res.IPAddress)
go setFieldValue(w, "ipv6", res.IPAddress) go setFieldValue(w, "ipv6", res.IPAddress)
go setFieldValue(w, "pub_key", res.PublicKey)
go setFieldValue(w, "priv_key", res.PrivateKey)
//found subnet //found subnet
fmt.Printf("Subnet: %s\n", res.Subnet) fmt.Printf("Subnet: %s\n", res.Subnet)
go setFieldValue(w, "subnet", res.Subnet) go setFieldValue(w, "subnet", res.Subnet)

View file

@ -12,6 +12,7 @@ type GetSelfResponse struct {
BuildName string `json:"build_name"` BuildName string `json:"build_name"`
BuildVersion string `json:"build_version"` BuildVersion string `json:"build_version"`
PublicKey string `json:"key"` PublicKey string `json:"key"`
PrivateKey string `json:"private_key"`
IPAddress string `json:"address"` IPAddress string `json:"address"`
Coords []uint64 `json:"coords"` Coords []uint64 `json:"coords"`
Subnet string `json:"subnet"` Subnet string `json:"subnet"`
@ -23,6 +24,7 @@ func (a *AdminSocket) getSelfHandler(req *GetSelfRequest, res *GetSelfResponse)
res.BuildName = version.BuildName() res.BuildName = version.BuildName()
res.BuildVersion = version.BuildVersion() res.BuildVersion = version.BuildVersion()
res.PublicKey = hex.EncodeToString(self.Key[:]) res.PublicKey = hex.EncodeToString(self.Key[:])
res.PrivateKey = hex.EncodeToString(self.PrivateKey[:])
res.IPAddress = a.core.Address().String() res.IPAddress = a.core.Address().String()
res.Subnet = snet.String() res.Subnet = snet.String()
res.Coords = self.Coords res.Coords = self.Coords

View file

@ -21,9 +21,10 @@ import (
) )
type SelfInfo struct { type SelfInfo struct {
Key ed25519.PublicKey Key ed25519.PublicKey
Root ed25519.PublicKey Root ed25519.PublicKey
Coords []uint64 PrivateKey ed25519.PrivateKey
Coords []uint64
} }
type PeerInfo struct { type PeerInfo struct {
@ -60,6 +61,7 @@ func (c *Core) GetSelf() SelfInfo {
var self SelfInfo var self SelfInfo
s := c.PacketConn.PacketConn.Debug.GetSelf() s := c.PacketConn.PacketConn.Debug.GetSelf()
self.Key = s.Key self.Key = s.Key
self.PrivateKey = c.secret
self.Root = s.Root self.Root = s.Root
self.Coords = s.Coords self.Coords = s.Coords
return self return self