Browse Source

:art: Add files to UI

Ettore Di Giacinto 4 years ago
parent
commit
70f8698e94
6 changed files with 177 additions and 8 deletions
  1. 10 0
      api/api.go
  2. 6 2
      api/public/blockchain.html
  3. 143 0
      api/public/files.html
  4. 6 2
      api/public/index.html
  5. 6 2
      api/public/services.html
  6. 6 2
      api/public/users.html

+ 10 - 0
api/api.go

@@ -27,6 +27,16 @@ func API(l string, ledger *blockchain.Ledger) error {
 	ec := echo.New()
 	ec := echo.New()
 	assetHandler := http.FileServer(getFileSystem())
 	assetHandler := http.FileServer(getFileSystem())
 
 
+	ec.GET("/api/files", func(c echo.Context) error {
+		list := []*types.File{}
+		for _, v := range ledger.CurrentData()[edgevpn.FilesLedgerKey] {
+			machine := &types.File{}
+			v.Unmarshal(machine)
+			list = append(list, machine)
+		}
+		return c.JSON(http.StatusOK, list)
+	})
+
 	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] {

+ 6 - 2
api/public/blockchain.html

@@ -23,8 +23,8 @@
   <nav class="navbar is-dark is-spaced has-shadow" role="navigation" aria-label="main navigation">
   <nav class="navbar is-dark is-spaced has-shadow" role="navigation" aria-label="main navigation">
     <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"> -->
-      <i class="fas fa-ship"></i>
+      <!--  <img src="/images/logo.png" width="112" height="28"> 
+      <i class="fas fa-ship"></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">
@@ -43,6 +43,10 @@
           <i class="fas fa-project-diagram"></i>&nbsp;
           <i class="fas fa-project-diagram"></i>&nbsp;
           Services
           Services
         </a>
         </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">
         <a class="navbar-item" href="/users.html">
           <i class="fas fa-user-clock"></i>&nbsp;
           <i class="fas fa-user-clock"></i>&nbsp;
           Users
           Users

+ 143 - 0
api/public/files.html

@@ -0,0 +1,143 @@
+<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 - Files 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;--> 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="/index.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-file-upload"></i> Served files
+          </h1>
+          <h2 class="subtitle">
+            Accessible via api at <a href="/api/files" target=_blank><code> /api/files </code></a><br>
+            Receive files by running <code>edgevpn file-receive --name "file_name" --path /dst/file </code>
+          </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">Name</abbr></th>
+              <th ><abbr title="peer">PeerID</abbr></th>
+
+            </tr>
+          </thead>
+        </table> 
+      </div>
+      
+        <script type="text/javascript">
+            $(document).ready(function() {
+                var table = $('#table').DataTable( {
+                    "processing": true,
+                    "ajax": {
+                        "url": "/api/files",
+                        "type": "GET",
+                        "dataSrc": '',
+                    },
+                    'language':{ 
+                      "loadingRecords": "",
+                      "processing": ""
+                    },
+                    "columns": [
+                        { "data": "Name" },
+                        { "data": "PeerID" },
+                    ],
+                } );
+
+                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>

+ 6 - 2
api/public/index.html

@@ -24,8 +24,8 @@
   <nav class="navbar is-dark is-spaced has-shadow" role="navigation" aria-label="main navigation">
   <nav class="navbar is-dark is-spaced has-shadow" role="navigation" aria-label="main navigation">
     <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"> -->
-      <i class="fas fa-ship"></i>
+      <!--  <img src="/images/logo.png" width="112" height="28"> 
+      <i class="fas fa-ship"></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">
@@ -44,6 +44,10 @@
           <i class="fas fa-project-diagram"></i>&nbsp;
           <i class="fas fa-project-diagram"></i>&nbsp;
           Services
           Services
         </a>
         </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">
         <a class="navbar-item" href="/users.html">
           <i class="fas fa-user-clock"></i>&nbsp;
           <i class="fas fa-user-clock"></i>&nbsp;
           Users
           Users

+ 6 - 2
api/public/services.html

@@ -24,8 +24,8 @@
   <nav class="navbar is-dark is-spaced has-shadow" role="navigation" aria-label="main navigation">
   <nav class="navbar is-dark is-spaced has-shadow" role="navigation" aria-label="main navigation">
     <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"> -->
-      <i class="fas fa-ship"></i>
+      <!--  <img src="/images/logo.png" width="112" height="28"> 
+      <i class="fas fa-ship"></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">
@@ -44,6 +44,10 @@
           <i class="fas fa-project-diagram"></i>&nbsp;
           <i class="fas fa-project-diagram"></i>&nbsp;
           Services
           Services
         </a>
         </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">
         <a class="navbar-item" href="/users.html">
           <i class="fas fa-user-clock"></i>&nbsp;
           <i class="fas fa-user-clock"></i>&nbsp;
           Users
           Users

+ 6 - 2
api/public/users.html

@@ -24,8 +24,8 @@
   <nav class="navbar is-dark is-spaced has-shadow" role="navigation" aria-label="main navigation">
   <nav class="navbar is-dark is-spaced has-shadow" role="navigation" aria-label="main navigation">
     <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"> -->
-      <i class="fas fa-ship"></i>
+      <!--  <img src="/images/logo.png" width="112" height="28"> 
+      <i class="fas fa-ship"></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">
@@ -44,6 +44,10 @@
           <i class="fas fa-project-diagram"></i>&nbsp;
           <i class="fas fa-project-diagram"></i>&nbsp;
           Services
           Services
         </a>
         </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">
         <a class="navbar-item" href="/users.html">
           <i class="fas fa-user-clock"></i>&nbsp;
           <i class="fas fa-user-clock"></i>&nbsp;
           Users
           Users