Browse Source

:art: Add summary page

Ettore Di Giacinto 3 years ago
parent
commit
33d896626a
7 changed files with 243 additions and 56 deletions
  1. 12 0
      api/api.go
  2. 3 2
      api/public/blockchain.html
  3. 3 2
      api/public/files.html
  4. 67 48
      api/public/index.html
  5. 152 0
      api/public/machines.html
  6. 3 2
      api/public/services.html
  7. 3 2
      api/public/users.html

+ 12 - 0
api/api.go

@@ -37,6 +37,18 @@ func API(l string, ledger *blockchain.Ledger) error {
 		return c.JSON(http.StatusOK, list)
 		return c.JSON(http.StatusOK, list)
 	})
 	})
 
 
+	ec.GET("/api/summary", func(c echo.Context) error {
+		files := len(ledger.CurrentData()[edgevpn.FilesLedgerKey])
+		machines := len(ledger.CurrentData()[edgevpn.MachinesLedgerKey])
+		users := len(ledger.CurrentData()[edgevpn.UsersLedgerKey])
+		services := len(ledger.CurrentData()[edgevpn.ServicesLedgerKey])
+		blockchain := len(ledger.BlockChain())
+
+		return c.JSON(http.StatusOK, struct {
+			Files, Machines, Users, Services, BlockChain int
+		}{files, machines, users, services, blockchain})
+	})
+
 	ec.GET("/api/machines", func(c echo.Context) error {
 	ec.GET("/api/machines", func(c echo.Context) error {
 		list := []*types.Machine{}
 		list := []*types.Machine{}
 		for _, v := range ledger.CurrentData()[edgevpn.MachinesLedgerKey] {
 		for _, v := range ledger.CurrentData()[edgevpn.MachinesLedgerKey] {

+ 3 - 2
api/public/blockchain.html

@@ -24,7 +24,8 @@
     <div class="navbar-brand">
     <div class="navbar-brand">
       <a class="navbar-item" href="/">
       <a class="navbar-item" href="/">
       <!--  <img src="/images/logo.png" width="112" height="28"> 
       <!--  <img src="/images/logo.png" width="112" height="28"> 
-      <i class="fas fa-ship"></i>&nbsp;--> EdgeVPN
+      <i class="fas fa-ship"></i>&nbsp;-->
+      <i class="fas fa-tachometer-alt"></i>&nbsp; EdgeVPN
       </a>
       </a>
   
   
       <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
       <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
@@ -35,7 +36,7 @@
     </div>
     </div>
     <div class="navbar-menu">
     <div class="navbar-menu">
       <div class="navbar-start">
       <div class="navbar-start">
-        <a class="navbar-item" href="/index.html">
+        <a class="navbar-item" href="/machines.html">
           <i class="fas fa-server"></i>&nbsp;
           <i class="fas fa-server"></i>&nbsp;
           Machines
           Machines
         </a>
         </a>

+ 3 - 2
api/public/files.html

@@ -25,7 +25,8 @@
     <div class="navbar-brand">
     <div class="navbar-brand">
       <a class="navbar-item" href="/">
       <a class="navbar-item" href="/">
       <!--  <img src="/images/logo.png" width="112" height="28"> 
       <!--  <img src="/images/logo.png" width="112" height="28"> 
-      <i class="fas fa-ship"></i>&nbsp;--> EdgeVPN
+      <i class="fas fa-ship"></i>&nbsp;-->
+      <i class="fas fa-tachometer-alt"></i>&nbsp; EdgeVPN
       </a>
       </a>
   
   
       <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
       <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
@@ -36,7 +37,7 @@
     </div>
     </div>
     <div class="navbar-menu">
     <div class="navbar-menu">
       <div class="navbar-start">
       <div class="navbar-start">
-        <a class="navbar-item" href="/index.html">
+        <a class="navbar-item" href="/machines.html">
           <i class="fas fa-server"></i>&nbsp;
           <i class="fas fa-server"></i>&nbsp;
           Machines
           Machines
         </a>
         </a>

+ 67 - 48
api/public/index.html

@@ -17,7 +17,7 @@
 
 
 <link rel="stylesheet" type="text/css" href="/css/style.css">
 <link rel="stylesheet" type="text/css" href="/css/style.css">
 
 
-<title>EdgeVPN - Machines index</title>
+<title>EdgeVPN - Dashboard</title>
 </head>
 </head>
 
 
 <body>
 <body>
@@ -25,7 +25,8 @@
     <div class="navbar-brand">
     <div class="navbar-brand">
       <a class="navbar-item" href="/">
       <a class="navbar-item" href="/">
       <!--  <img src="/images/logo.png" width="112" height="28"> 
       <!--  <img src="/images/logo.png" width="112" height="28"> 
-      <i class="fas fa-ship"></i>&nbsp;--> EdgeVPN
+      <i class="fas fa-ship"></i>&nbsp;-->
+      <i class="fas fa-tachometer-alt"></i>&nbsp; EdgeVPN
       </a>
       </a>
   
   
       <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
       <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
@@ -36,7 +37,7 @@
     </div>
     </div>
     <div class="navbar-menu">
     <div class="navbar-menu">
       <div class="navbar-start">
       <div class="navbar-start">
-        <a class="navbar-item" href="/index.html">
+        <a class="navbar-item" href="/machines.html">
           <i class="fas fa-server"></i>&nbsp;
           <i class="fas fa-server"></i>&nbsp;
           Machines
           Machines
         </a>
         </a>
@@ -76,10 +77,10 @@
       <div class="hero-body">
       <div class="hero-body">
         <div class="container">
         <div class="container">
           <h1 class="title">
           <h1 class="title">
-            <i class="fas fa-server"></i> Connected Machines
+            <i class="fas fa-tachometer-alt"></i> Dashboard
           </h1>
           </h1>
           <h2 class="subtitle">
           <h2 class="subtitle">
-            Accessible via api at <a href="/api/machines" target=_blank><code> /api/machines </code></a>
+            Accessible via api at <a href="/api/summary" target=_blank><code> /api/summary </code></a>
           </h2>
           </h2>
         </div>
         </div>
       </div>
       </div>
@@ -87,56 +88,74 @@
     <section class="section">
     <section class="section">
         <div class="container">
         <div class="container">
 
 
+          <div class="tile is-ancestor has-text-centered">
+            <div class="tile is-parent">
+                <article class="tile is-child box">
+                    <p class="title" id="machines"></p>
+                    <p class="subtitle"><i class="fas fa-server"></i> Machines</p>
+                </article>
+            </div>
+            <div class="tile is-parent">
+                <article class="tile is-child box">
+                    <p class="title" id="services"></p>
+                    <p class="subtitle"><i class="fas fa-project-diagram"></i> Services</p>
+                </article>
+            </div>
+            <div class="tile is-parent">
+                <article class="tile is-child box">
+                    <p class="title" id="files"></p>
+                    <p class="subtitle"><i class="fas fa-file-upload"></i> Files</p>
+                </article>
+            </div>
+            <div class="tile is-parent">
+                <article class="tile is-child box">
+                    <p class="title" id="users"></p>
+                    <p class="subtitle"><i class="fas fa-user-clock"></i> Users</p>
+                </article>
+            </div>
+            <div class="tile is-parent">
+              <article class="tile is-child box">
+                  <p class="title" id="blockchain"></p>
+                  <p class="subtitle"><i class="fas fa-dice-d20"></i> Blockchain index</p>
+              </article>
+          </div>
+        </div>
+  
         </div>
         </div>
     </section>
     </section>
 
 
 
 
-    <div class="container">
-        <table  data-toggle="table"
-          data-search="true"
-          data-show-columns="true"
-          id="table"  >
-          <thead>
-        
-          <tr>
-              <th ><abbr title="ip">Address</abbr></th>
-              <th ><abbr title="peer">PeerID</abbr></th>
-              <th  >Hostname</th>
-              <th ><abbr title="OS">OS</abbr></th>
-              <th><abbr title="Arch">Architecture</abbr></th>
-              <th><abbr title="Version">Version</abbr></th>
-
-            </tr>
-          </thead>
-        </table> 
-      </div>
+ 
       
       
         <script type="text/javascript">
         <script type="text/javascript">
             $(document).ready(function() {
             $(document).ready(function() {
-                var table = $('#table').DataTable( {
-                    "processing": true,
-                    "ajax": {
-                        "url": "/api/machines",
-                        "type": "GET",
-                        "dataSrc": '',
-                    },
-                    'language':{ 
-                      "loadingRecords": "",
-                      "processing": ""
-                    },
-                    "columns": [
-                        { "data": "Address" },
-                        { "data": "PeerID" },
-                        { "data": "Hostname" },
-                        { "data": "OS" },
-                        { "data": "Arch" },
-                        { "data": "Version" },
-                    ],
-                } );
-
-                setInterval( function () {
-                    table.ajax.reload();
-                }, 5000 ); // 5 s
+
+              sync = function() {
+                $.ajax({
+                    url: "/api/summary",
+                    type: "GET",
+                    cache: false,
+                    async: true,
+
+                    dataType: "json",
+                    success: function (response) {
+                        // response is JSON
+                        $('#services').html(response.Services);
+                        $('#users').html(response.Users);
+                        $('#files').html(response.Files);
+                        $('#machines').html(response.Machines);
+                        $('#blockchain').html(response.BlockChain);
+
+                    }
+                });
+              }
+
+              sync()
+
+              setInterval( function () {
+               sync()
+              }, 5000 ); // 5 s
+
             } );
             } );
         </script>
         </script>
         <footer class="footer">
         <footer class="footer">

+ 152 - 0
api/public/machines.html

@@ -0,0 +1,152 @@
+<html>
+<head>
+  <link rel="preconnect" href="https://fonts.googleapis.com">
+  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
+  <link href="https://fonts.googleapis.com/css2?family=Duru+Sans&family=Hammersmith+One&family=Lato&family=Nunito&family=Nunito+Sans:wght@400;600&family=Zen+Kurenaido&display=swap" rel="stylesheet"> 
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.1/css/bulma.css" />
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" integrity="sha512-+4zCK9k+qNFUR5X+cKL9EIR+ZOhtIloNl9GIKS57V1MyNsYpYcUrUeQc9vNfzsWfV28IaLL3i96P9sdNyeRssA==" crossorigin="anonymous" />
+
+<!-- datatables -->
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> 
+
+<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.css">
+
+<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.js"></script>
+
+<script src="/js/dt.js"></script> 
+
+<link rel="stylesheet" type="text/css" href="/css/style.css">
+
+<title>EdgeVPN - Machines index</title>
+</head>
+
+<body>
+  <nav class="navbar is-dark is-spaced has-shadow" role="navigation" aria-label="main navigation">
+    <div class="navbar-brand">
+      <a class="navbar-item" href="/">
+      <!--  <img src="/images/logo.png" width="112" height="28"> 
+      <i class="fas fa-ship"></i>&nbsp;-->
+      <i class="fas fa-tachometer-alt"></i>&nbsp; EdgeVPN
+      </a>
+  
+      <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
+        <span aria-hidden="true"></span>
+        <span aria-hidden="true"></span>
+        <span aria-hidden="true"></span>
+      </a>
+    </div>
+    <div class="navbar-menu">
+      <div class="navbar-start">
+        <a class="navbar-item" href="/machines.html">
+          <i class="fas fa-server"></i>&nbsp;
+          Machines
+        </a>
+        <a class="navbar-item" href="/services.html">
+          <i class="fas fa-project-diagram"></i>&nbsp;
+          Services
+        </a>
+        <a class="navbar-item" href="/files.html">
+          <i class="fas fa-file-upload"></i>&nbsp;
+          Files
+        </a>
+        <a class="navbar-item" href="/users.html">
+          <i class="fas fa-user-clock"></i>&nbsp;
+          Users
+        </a>
+        <a class="navbar-item" href="/blockchain.html">
+          <i class="fas fa-dice-d20"></i>&nbsp;
+          Blockchain
+        </a>
+      </div>
+      <div class="navbar-end">
+        <div class="navbar-item">
+          <div class="buttons">
+            <a class="button is-link" href="https://github.com/mudler/edgevpn" target=_blank>
+             <strong><i class="fab fa-github-alt"></i> GitHub</strong>
+            </a>
+            <a class="button is-light" href="https://github.com/mudler/edgevpn/issues/new" target=_blank>
+             <i class="fas fa-bug"></i>&nbsp; Report issue
+            </a>
+          </div>
+        </div>
+      </div>
+    </div>
+  </nav>
+
+    <section class="hero">
+      <div class="hero-body">
+        <div class="container">
+          <h1 class="title">
+            <i class="fas fa-server"></i> Connected Machines
+          </h1>
+          <h2 class="subtitle">
+            Accessible via api at <a href="/api/machines" target=_blank><code> /api/machines </code></a>
+          </h2>
+        </div>
+      </div>
+    </section>
+    <section class="section">
+        <div class="container">
+
+        </div>
+    </section>
+
+
+    <div class="container">
+        <table  data-toggle="table"
+          data-search="true"
+          data-show-columns="true"
+          id="table"  >
+          <thead>
+        
+          <tr>
+              <th ><abbr title="ip">Address</abbr></th>
+              <th ><abbr title="peer">PeerID</abbr></th>
+              <th  >Hostname</th>
+              <th ><abbr title="OS">OS</abbr></th>
+              <th><abbr title="Arch">Architecture</abbr></th>
+              <th><abbr title="Version">Version</abbr></th>
+
+            </tr>
+          </thead>
+        </table> 
+      </div>
+      
+        <script type="text/javascript">
+            $(document).ready(function() {
+                var table = $('#table').DataTable( {
+                    "processing": true,
+                    "ajax": {
+                        "url": "/api/machines",
+                        "type": "GET",
+                        "dataSrc": '',
+                    },
+                    'language':{ 
+                      "loadingRecords": "",
+                      "processing": ""
+                    },
+                    "columns": [
+                        { "data": "Address" },
+                        { "data": "PeerID" },
+                        { "data": "Hostname" },
+                        { "data": "OS" },
+                        { "data": "Arch" },
+                        { "data": "Version" },
+                    ],
+                } );
+
+                setInterval( function () {
+                    table.ajax.reload();
+                }, 5000 ); // 5 s
+            } );
+        </script>
+        <footer class="footer">
+          <div class="content has-text-centered">
+            <p>
+              <strong>EdgeVPN</strong> by <a href="https://github.com/mudler/edgevpn">Ettore Di Giacinto</a>. The source code is licensed
+              <a href="https://github.com/mudler/edgevpn/blob/master/LICENSE">GPLv3</a>.
+            </p>
+          </div>
+        </footer>  
+    </body>
+</html>

+ 3 - 2
api/public/services.html

@@ -25,7 +25,8 @@
     <div class="navbar-brand">
     <div class="navbar-brand">
       <a class="navbar-item" href="/">
       <a class="navbar-item" href="/">
       <!--  <img src="/images/logo.png" width="112" height="28"> 
       <!--  <img src="/images/logo.png" width="112" height="28"> 
-      <i class="fas fa-ship"></i>&nbsp;--> EdgeVPN
+      <i class="fas fa-ship"></i>&nbsp;-->
+      <i class="fas fa-tachometer-alt"></i>&nbsp; EdgeVPN
       </a>
       </a>
   
   
       <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
       <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
@@ -36,7 +37,7 @@
     </div>
     </div>
     <div class="navbar-menu">
     <div class="navbar-menu">
       <div class="navbar-start">
       <div class="navbar-start">
-        <a class="navbar-item" href="/index.html">
+        <a class="navbar-item" href="/machines.html">
           <i class="fas fa-server"></i>&nbsp;
           <i class="fas fa-server"></i>&nbsp;
           Machines
           Machines
         </a>
         </a>

+ 3 - 2
api/public/users.html

@@ -25,7 +25,8 @@
     <div class="navbar-brand">
     <div class="navbar-brand">
       <a class="navbar-item" href="/">
       <a class="navbar-item" href="/">
       <!--  <img src="/images/logo.png" width="112" height="28"> 
       <!--  <img src="/images/logo.png" width="112" height="28"> 
-      <i class="fas fa-ship"></i>&nbsp;--> EdgeVPN
+      <i class="fas fa-ship"></i>&nbsp;-->
+      <i class="fas fa-tachometer-alt"></i>&nbsp; EdgeVPN
       </a>
       </a>
   
   
       <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
       <a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
@@ -36,7 +37,7 @@
     </div>
     </div>
     <div class="navbar-menu">
     <div class="navbar-menu">
       <div class="navbar-start">
       <div class="navbar-start">
-        <a class="navbar-item" href="/index.html">
+        <a class="navbar-item" href="/machines.html">
           <i class="fas fa-server"></i>&nbsp;
           <i class="fas fa-server"></i>&nbsp;
           Machines
           Machines
         </a>
         </a>