index.tmpl 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>EdgeVPN</title>
  8. <meta name="description" content="Edgevpn dashboard">
  9. <meta name="keywords" content="edgevpn,dashboard">
  10. <script src="/js/apexcharts.min.js"></script>
  11. <script src="/js/alpine-magic-helpers.min.js" defer></script>
  12. <script src="/js/alpine.min.js" defer></script>
  13. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
  14. <style>
  15. .bg-black-alt {
  16. background:#191919;
  17. }
  18. .text-black-alt {
  19. color:#191919;
  20. }
  21. .border-black-alt {
  22. border-color: #191919;
  23. }
  24. .string { color: green; }
  25. .number { color: darkorange; }
  26. .boolean { color: blue; }
  27. .null { color: magenta; }
  28. .key { color: red; }
  29. #checkbox:checked + label .switch-ball{
  30. background-color: white;
  31. transform: translateX(24px);
  32. transition: transform 0.3s linear;
  33. }
  34. </style>
  35. <script src="/js/tailwind.min.js"></script>
  36. <script>
  37. tailwind.config = {
  38. darkMode: 'class',
  39. theme: {
  40. extend: {
  41. colors: {
  42. clifford: '#da373d',
  43. }
  44. }
  45. }
  46. }
  47. </script>
  48. </head>
  49. <body class="font-sans leading-normal tracking-normal"
  50. x-data="{page: location.hash, 'darkMode': false }"
  51. @hashchange.window="page = location.hash"
  52. x-init="
  53. darkMode = JSON.parse(localStorage.getItem('darkMode'));
  54. $watch('darkMode', value => localStorage.setItem('darkMode', JSON.stringify(value)))"
  55. x-bind:class="darkMode === true ? 'dark bg-black-alt': 'bg-white'"
  56. >
  57. <nav id="header" class="bg-slate-100 dark:bg-gray-900 fixed w-full z-10 top-0 shadow">
  58. <div class="w-full container mx-auto flex flex-wrap items-center mt-0 pt-3 pb-3 md:pb-0">
  59. <div class="w-1/2 pl-2 md:pl-0 align-text-bottom">
  60. <a class="text-gray-100 text-base xl:text-xl no-underline hover:no-underline font-bold align-top" href="#">
  61. <img src="/images/logo.png" class="object-scale-down float-left h-7 w-7"> <span class="pl-4 pt-1 md:pb-0 text-md text-slate-700 dark:text-slate-100"> EdgeVPN </span>
  62. </a>
  63. </div>
  64. <div class="w-1/2 pr-0">
  65. <div class="flex relative inline-block float-right">
  66. <!-- Dark/Light mode button-->
  67. <div >
  68. <div>
  69. <div class="dark:text-gray-100">
  70. <div class="flex items-center justify-center space-x-2">
  71. <span class="text-sm text-gray-800 dark:text-gray-500 p-2">Light</span>
  72. <label for="toggle"
  73. class="flex items-center h-5 p-1 duration-300 ease-in-out bg-gray-300 rounded-full cursor-pointer w-9 dark:bg-gray-600">
  74. <div
  75. class="w-4 h-4 duration-300 ease-in-out transform bg-white rounded-full shadow-md toggle-dot dark:translate-x-3">
  76. </div>
  77. </label>
  78. <span class="text-sm text-gray-400 dark:text-white p-2">Dark</span>
  79. <input id="toggle" type="checkbox" class="hidden" :value="darkMode" @change="darkMode = !darkMode" />
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. <!-- END Dark/Light mode button-->
  85. <div class="block lg:hidden pr-4">
  86. <button id="nav-toggle" class="flex items-center px-3 py-2 border rounded text-gray-500 border-gray-600 hover:text-gray-100 hover:border-teal-500 appearance-none focus:outline-none">
  87. <svg class="fill-current h-3 w-3" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><title>Menu</title><path d="M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z"/></svg>
  88. </button>
  89. </div>
  90. </div>
  91. </div>
  92. <div class="w-full flex-grow lg:flex lg:items-center lg:w-auto hidden lg:block mt-2 lg:mt-0 bg-white-300 dark:bg-gray-900 z-20" id="nav-content">
  93. <ul class="list-reset lg:flex flex-1 items-center px-4 md:px-0">
  94. {{ $opts:= dict "name" "Home" "page" "" "icon" "fa-home" }}
  95. {{ template "menu_entry" $opts}}
  96. {{ $opts:= dict "name" "Nodes" "page" "#nodes" "icon" "fa-server" }}
  97. {{ template "menu_entry" $opts}}
  98. {{ $opts:= dict "name" "DNS" "page" "#dns" "icon" "fa-globe" }}
  99. {{ template "menu_entry" $opts}}
  100. {{ $opts:= dict "name" "Blockchain" "page" "#blockchain" "icon" "fa-dice-d20" }}
  101. {{ template "menu_entry" $opts}}
  102. {{ $opts:= dict "name" "Services" "page" "#services" "icon" "fa-ethernet" }}
  103. {{ template "menu_entry" $opts}}
  104. {{ $opts:= dict "name" "Peers" "page" "#peers" "icon" "fa-users" }}
  105. {{ template "menu_entry" $opts}}
  106. </ul>
  107. <div class="relative pull-right pl-4 pr-4 md:pr-0">
  108. </div>
  109. </div>
  110. </div>
  111. </nav>
  112. <!-- Nodes Container-->
  113. <div class="container w-full mx-auto pt-20" x-show="page === '#nodes'">
  114. {{ $opts:= dict "text" "Machines API Documentation " "url" "https://mudler.github.io/edgevpn/docs/getting-started/api/#apimachines"}}
  115. {{ template "readme_badge" $opts}}
  116. {{ $opts:= dict "delete" "d.Address" "condition" "x-bind:class=\"d.Online ? 'bg-lime-100 dark:bg-lime-800' : 'bg-stone-200 dark:bg-stone-800'\"" "title" "Nodes" "func" "machines" "fields" ( list "Address" "PeerID" "Hostname" "OS" "Architecture" "Version") "struct" (list "d.Address" "d.PeerID" "d.Hostname" "d.OS" "d.Arch" "d.Version")}}
  117. {{ template "table" $opts}}
  118. </div>
  119. <!--END Node Container-->
  120. <!-- Blockchain Container-->
  121. <div class="container w-full mx-auto pt-20" x-show="page === '#blockchain'">
  122. <div class="w-full px-4 md:px-0 md:mt-8 mb-16 text-gray-800 leading-normal">
  123. <div class="w-full mt-12 p-3 dark:bg-gray-900 bg-white-100 border dark:border-gray-800 rounded shadow"
  124. x-data="blockchain()"
  125. x-init="$interval(updateItems, 5500)"
  126. >
  127. <div class="border-b border-gray-800 p-3">
  128. <h5 class="font-bold uppercase text-gray-600">Blockchain </h5>
  129. <h5 class="font-bold uppercase text-gray-600">
  130. <span class="mt-1 text-xs px-2 py-1 font-semibold leading-tight text-slate-700 bg-slate-100 rounded-full dark:bg-slate-700 dark:text-slate-100"><i class="fa-solid fa-hashtag fa-fw mr-3"></i> <span x-text="blockchain.Index"></span> </span>
  131. <span class="mt-1 text-xs px-2 py-1 font-semibold leading-tight text-slate-700 bg-slate-100 rounded-full dark:bg-slate-700 dark:text-slate-100"><i class="fa-solid fa-clock fa-fw mr-3"></i> <span x-text="blockchain.Timestamp"></span> </span>
  132. <span class="mt-1 text-xs px-2 py-1 font-semibold leading-tight text-slate-700 bg-slate-100 rounded-full dark:bg-slate-700 dark:text-slate-100"><i class="fa-solid fa-dice-d20 fa-fw mr-3"></i> <span x-text="blockchain.Hash"></span> </span>
  133. <span class="mt-1 text-xs px-2 py-1 font-semibold leading-tight text-slate-700 bg-slate-100 rounded-full dark:bg-slate-700 dark:text-slate-100"><i class="fa-solid fa-link fa-fw mr-3"></i> <span x-text="blockchain.PrevHash"></span> </span>
  134. </div>
  135. <section class="flex justify-center mt-10">
  136. <div class="bg-white-300 py-1 w-11/12 rounded border-b-4 border-red-400 flex dark:text-white">
  137. <pre class="overflow-auto"><code class="overflow-auto" x-html="syntaxHighlight(JSON.stringify(blockchain, null, 2))"></code></pre>
  138. </div>
  139. </section>
  140. </div>
  141. </div>
  142. </div>
  143. <!--END Blockchain Container-->
  144. <!-- DNS Container-->
  145. <div class="container w-full mx-auto pt-20" x-show="page === '#dns'">
  146. {{ $opts:= dict "text" "DNS Documentation " "url" "https://mudler.github.io/edgevpn/docs/concepts/overview/dns/"}}
  147. {{ template "readme_badge" $opts}}
  148. {{ $opts:= dict "delete" "d.Regex" "title" "DNS" "func" "dns" "fields" ( list "Regex" "Records") "struct" (list "d.Regex" "JSON.stringify(d.Records)")}}
  149. {{ template "table" $opts}}
  150. </div>
  151. <!--END DNS Container-->
  152. <!-- Services Container-->
  153. <div class="container w-full mx-auto pt-20" x-show="page === '#services'">
  154. {{ $opts:= dict "text" "Tunnelling Documentation " "url" "https://mudler.github.io/edgevpn/docs/concepts/overview/services/"}}
  155. {{ template "readme_badge" $opts}}
  156. {{ $opts:= dict "title" "TCP Tunnels" "func" "services" "fields" ( list "Name" "PeerID") "struct" (list "d.Name" "d.PeerID")}}
  157. {{ template "table" $opts}}
  158. <hr class="border-b-2 border-gray-600 my-8 mx-4">
  159. {{ $opts:= dict "text" "Files Documentation " "url" "https://mudler.github.io/edgevpn/docs/concepts/overview/files/"}}
  160. {{ template "readme_badge" $opts}}
  161. {{ $opts:= dict "title" "Files" "func" "files" "fields" ( list "Name" "PeerID") "struct" (list "d.Name" "d.PeerID")}}
  162. {{ template "table" $opts}}
  163. </div>
  164. <!--END Services Container-->
  165. <!-- Peers Container-->
  166. <div class="container w-full mx-auto pt-20" x-show="page === '#peers'">
  167. {{ $opts:= dict "title" "Nodes" "func" "nodes" "fields" ( list "PeerID" "Online" ) "struct" (list "d.ID" "d.Online")}}
  168. {{ template "table" $opts}}
  169. <hr class="border-b-2 border-gray-600 my-8 mx-4">
  170. {{ $opts:= dict "title" "Peer store" "func" "peerstore" "fields" ( list "PeerID" ) "struct" (list "d.ID")}}
  171. {{ template "table" $opts}}
  172. </div>
  173. </div>
  174. <!--END Peers Container-->
  175. <!-- Index Container-->
  176. <div class="container w-full mx-auto pt-20" x-show="page === ''">
  177. <div class="w-full px-4 md:px-0 md:mt-8 mb-16 text-gray-800 leading-normal"
  178. x-data="summary()"
  179. x-init="$interval(updateItems, 1500); initChart()"
  180. >
  181. <!--Summary Content-->
  182. <div class="flex flex-wrap">
  183. {{ $opts:= dict "name" "VPN Nodes" "color" "bg-emerald-600" "icon" "fas fa-network-wired" "field" "summary.Machines"}}
  184. {{ template "metric_card" $opts}}
  185. {{ $opts:= dict "name" "P2P peers" "color" "bg-cyan-600" "icon" "fa-solid fa-circle-nodes" "field" "summary.Peers"}}
  186. {{ template "metric_card" $opts}}
  187. {{ $opts:= dict "name" "Files" "color" "bg-yellow-600" "icon" "fa-solid fa-box-archive" "field" "summary.Files"}}
  188. {{ template "metric_card" $opts}}
  189. {{ $opts:= dict "name" "Users" "color" "bg-pink-600" "icon" "fas fa-users" "field" "summary.Users"}}
  190. {{ template "metric_card" $opts}}
  191. {{ $opts:= dict "name" "Blockchain index" "color" "bg-indigo-600" "icon" "fas fa-dice-d20" "field" "summary.BlockChain"}}
  192. {{ template "metric_card" $opts}}
  193. {{ $opts:= dict "name" "Services" "color" "bg-sky-600" "icon" "fa-solid fa-car-tunnel" "field" "summary.Services"}}
  194. {{ template "metric_card" $opts}}
  195. {{ $opts:= dict "name" "Total downloaded" "color" "bg-cyan-600" "icon" "fas fa-download" "field" "bytesToSize(metrics.TotalIn)"}}
  196. {{ template "metric_card" $opts}}
  197. <div class="w-full md:w-1/2 xl:w-1/3 p-3 text-gray-800 ">
  198. <div class="dark:bg-gray-900 rounded shadow dark:border-gray-600 border-b-4 ">
  199. <div class="bg-white-200 dark:bg-gray-900 p-3">
  200. <h5 class="font-bold float-left uppercase text-gray-400">
  201. <span class="rounded p-1 bg-teal-600"><i class="fa-duotone fa-right-left fa-fw fa-inverse"></i></span>
  202. Bandwidth
  203. </h5>
  204. <h5 class="font-bold uppercase float-right text-gray-600">
  205. <span class="rounded p-1 bg-cyan-600"><i class="fas fa-arrow-down fa-fw fa-inverse"></i></span>
  206. <span x-text="bytesToSize(metrics.RateIn)"></span>
  207. <span class="rounded p-1 bg-amber-600"><i class="fas fa-arrow-up fa-fw fa-inverse"></i></span>
  208. <span x-text="bytesToSize(metrics.RateOut)"></span>
  209. </h5>
  210. </div>
  211. <br>
  212. <div class=" relative mt-1 ">
  213. <!-- Network stat Card-->
  214. <div class="dark:bg-gray-900 bg-white-100 rounded shadow p-2">
  215. <div class="flex flex-row items-center">
  216. <div class="flex-1 text-right md:text-center">
  217. <div x-ref="chart"></div>
  218. </div>
  219. </div>
  220. </div>
  221. <!--/Network stat Card-->
  222. </div>
  223. </div>
  224. </div>
  225. {{ $opts:= dict "name" "Total uploaded" "color" "bg-amber-600" "icon" "fas fa-upload" "field" "bytesToSize(metrics.TotalOut)"}}
  226. {{ template "metric_card" $opts}}
  227. <!--Divider-->
  228. <hr class="border-b-2 border-gray-600 my-8 mx-4">
  229. {{ $opts:= dict "title" "Connected users" "func" "users" "fields" ( list "PeerID" "Time") "struct" (list "d.PeerID" "d.Timestamp")}}
  230. {{ template "table" $opts}}
  231. <!--/ Summary Content-->
  232. </div>
  233. </div>
  234. <!--END Index /container-->
  235. <footer class="dark:bg-gray-900 border-t dark:border-gray-400 shadow">
  236. <div class="container max-w-md mx-auto flex py-8">
  237. <div class="w-full mx-auto flex flex-wrap">
  238. <div class="flex w-full md:w-1/2 ">
  239. <div class="px-8">
  240. <h3 class="font-bold font-bold dark:text-gray-100">About</h3>
  241. <p class="py-4 text-gray-600 text-sm">
  242. <strong>EdgeVPN</strong> by <a href="https://github.com/mudler/edgevpn">Ettore Di Giacinto</a>.<br>
  243. License <a href="https://github.com/mudler/edgevpn/blob/master/LICENSE">
  244. Apache v2</a>. <br>
  245. Logo originally made by <a href="https://www.flaticon.com/authors/uniconlabs" title="Uniconlabs">Uniconlabs</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a>
  246. </p>
  247. </div>
  248. </div>
  249. <div class="flex w-full md:w-1/2">
  250. <div class="px-8">
  251. <h3 class="font-bold font-bold dark:text-gray-100">Links</h3>
  252. <ul class="list-reset items-center text-sm pt-3">
  253. <li>
  254. <a class="inline-block text-gray-600 no-underline hover:text-black dark:hover:text-gray-100 hover:text-underline py-1" href="https://github.com/mudler/edgevpn" target=_blank><i class="fa-brands fa-github-alt fa-fw mr-3"></i>Github</a>
  255. </li>
  256. <li>
  257. <a class="inline-block text-gray-600 no-underline hover:text-black dark:hover:text-gray-100 hover:text-underline py-1" href="https://mudler.github.io/edgevpn/docs" target=_blank><i class="fas fa-book fa-fw mr-3"></i>Documentation</a>
  258. </li>
  259. <li>
  260. <a class="inline-block text-gray-600 no-underline hover:text-black dark:hover:text-gray-100 hover:text-underline py-1" href="https://github.com/mudler/edgevpn/issues/new" target=_blank><i class="fas fa-bug fa-fw mr-3"></i>Report issue</a>
  261. </li>
  262. </ul>
  263. </div>
  264. </div>
  265. </div>
  266. </div>
  267. </footer>
  268. <script>
  269. function bytesToSize(bytes, decimals = 2) {
  270. if (bytes === 0) return '0 Bytes';
  271. const k = 1024;
  272. const dm = decimals < 0 ? 0 : decimals;
  273. const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  274. const i = Math.floor(Math.log(bytes) / Math.log(k));
  275. var s = sizes[i]
  276. if (!sizes[i]) {
  277. s = "B"
  278. }
  279. return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + s;
  280. }
  281. function scaleSize(bytes, scale = 1, decimals = 2) {
  282. if (bytes === 0) return '0';
  283. const k = 1024;
  284. const dm = decimals < 0 ? 0 : decimals;
  285. //const i = Math.floor(Math.log(bytes) / Math.log(k));
  286. //console.log(i)
  287. return parseFloat((bytes / Math.pow(k, scale)).toFixed(dm));
  288. }
  289. const range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step));
  290. function calcPages(n, total, size) {
  291. start = 1;
  292. if (n > 5 ){
  293. start = n - 5
  294. }
  295. end = Math.ceil(total / size);
  296. if (end - n > 5 ){
  297. end = n + 5
  298. // Math.ceil(this.total / this.size) - 10
  299. }
  300. return range(start, end ,1)
  301. }
  302. function filter(obj, key) {
  303. const start = obj.pageNumber * obj.size,
  304. end = start + obj.size;
  305. if (obj.search === "") {
  306. obj.total = obj.data.length;
  307. return obj.data.slice(start, end);
  308. }
  309. //Return the total results of the filters
  310. obj.total = obj.data.filter((item) => {
  311. return item[key]
  312. .toLowerCase()
  313. .includes(obj.search.toLowerCase());
  314. }).length;
  315. //Return the filtered data
  316. return obj.data
  317. .filter((item) => {
  318. return item[key]
  319. .toLowerCase()
  320. .includes(obj.search.toLowerCase());
  321. })
  322. .slice(start, end);
  323. }
  324. function endRes(obj) {
  325. let resultsOnPage = (obj.pageNumber + 1) * obj.size;
  326. if (resultsOnPage <= obj.total) {
  327. return resultsOnPage;
  328. }
  329. return obj.total;
  330. }
  331. function sortData(key, order = "asc") {
  332. return function innerSort(a, b) {
  333. if (!a.hasOwnProperty(key) || !b.hasOwnProperty(key)) {
  334. return 0;
  335. }
  336. const varA = typeof a[key] === "string" ? a[key].toUpperCase() : a[key];
  337. const varB = typeof b[key] === "string" ? b[key].toUpperCase() : b[key];
  338. let comparison = 0;
  339. if (varA > varB) {
  340. comparison = 1;
  341. } else if (varA < varB) {
  342. comparison = -1;
  343. }
  344. return order === "desc" ? comparison * -1 : comparison;
  345. }
  346. }
  347. {{ $opts:= dict "endpoint" "machines" "func" "machines" "sort" "Address" "delete" "machines"}}
  348. {{ template "table_js" $opts}}
  349. {{ $opts:= dict "endpoint" "peerstore" "func" "peerstore" "sort" "ID"}}
  350. {{ template "table_js" $opts}}
  351. {{ $opts:= dict "endpoint" "nodes" "func" "nodes" "sort" "ID"}}
  352. {{ template "table_js" $opts}}
  353. {{ $opts:= dict "endpoint" "users" "func" "users" "sort" "ID"}}
  354. {{ template "table_js" $opts}}
  355. {{ $opts:= dict "endpoint" "dns" "func" "dns" "sort" "Regex" "delete" "dns"}}
  356. {{ template "table_js" $opts}}
  357. {{ $opts:= dict "endpoint" "services" "func" "services" "sort" "Name"}}
  358. {{ template "table_js" $opts}}
  359. {{ $opts:= dict "endpoint" "files" "func" "files" "sort" "Name"}}
  360. {{ template "table_js" $opts}}
  361. function blockchain(){
  362. return {
  363. blockchain: {},
  364. updateItems() {
  365. fetch('/api/blockchain')
  366. .then(response => response.json())
  367. .then(data => this.blockchain = data )
  368. }
  369. };
  370. }
  371. function syntaxHighlight(json) {
  372. json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  373. return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
  374. var cls = 'number';
  375. if (/^"/.test(match)) {
  376. if (/:$/.test(match)) {
  377. cls = 'key';
  378. } else {
  379. cls = 'string';
  380. }
  381. } else if (/true|false/.test(match)) {
  382. cls = 'boolean';
  383. } else if (/null/.test(match)) {
  384. cls = 'null';
  385. }
  386. return '<span class="' + cls + '">' + match + '</span>';
  387. });
  388. }
  389. function summary(){
  390. return {
  391. summary: {},
  392. chart: null,
  393. metrics: {},
  394. initChart() {
  395. this.chart = new ApexCharts(this.$refs.chart, {
  396. chart: {
  397. type: 'area',
  398. height: 80,
  399. sparkline: {
  400. enabled: true
  401. },
  402. dropShadow: {
  403. enabled: true,
  404. top: 1,
  405. left: 1,
  406. blur: 2,
  407. opacity: 0.2,
  408. }
  409. },
  410. dataLabels: {
  411. enabled: false,
  412. },
  413. series: [
  414. {
  415. name: "Download",
  416. data: [],
  417. },
  418. {
  419. name: "Upload",
  420. data: [],
  421. },
  422. ],
  423. stroke: {
  424. curve: 'smooth'
  425. },
  426. markers: {
  427. size: 0
  428. },
  429. grid: {
  430. padding: {
  431. top: 20,
  432. bottom: 10,
  433. }
  434. },
  435. colors: ['#247BA0', '#FF1654' ],
  436. noData: {
  437. text: "Loading...",
  438. },
  439. xaxis: {
  440. labels: {
  441. show: false,
  442. },
  443. },
  444. tooltip: {
  445. x: {
  446. show: false
  447. },
  448. y: {
  449. formatter: function(value, { series, seriesIndex, dataPointIndex, w }) {
  450. return value + ' KB/s'
  451. }
  452. }
  453. }
  454. })
  455. this.chart.render()
  456. },
  457. updateItems() {
  458. fetch('/api/summary')
  459. .then(response => response.json())
  460. .then(data => this.summary = data )
  461. fetch('/api/metrics')
  462. .then(response => response.json())
  463. .then(data => {
  464. this.metrics = data;
  465. this.chart.appendData([{ data: [ scaleSize(data.RateIn) ] }, { data: [ scaleSize(data.RateOut) ] } ]);
  466. } )
  467. }
  468. };
  469. }
  470. /*Toggle dropdown list*/
  471. /*https://gist.github.com/slavapas/593e8e50cf4cc16ac972afcbad4f70c8*/
  472. var navMenuDiv = document.getElementById("nav-content");
  473. var navMenu = document.getElementById("nav-toggle");
  474. document.onclick = check;
  475. function check(e){
  476. var target = (e && e.target) || (event && event.srcElement);
  477. //Nav Menu
  478. if (!checkParent(target, navMenuDiv)) {
  479. // click NOT on the menu
  480. if (checkParent(target, navMenu)) {
  481. // click on the link
  482. if (navMenuDiv.classList.contains("hidden")) {
  483. navMenuDiv.classList.remove("hidden");
  484. } else {navMenuDiv.classList.add("hidden");}
  485. } else {
  486. // click both outside link and outside menu, hide menu
  487. navMenuDiv.classList.add("hidden");
  488. }
  489. }
  490. }
  491. function checkParent(t, elm) {
  492. while(t.parentNode) {
  493. if( t == elm ) {return true;}
  494. t = t.parentNode;
  495. }
  496. return false;
  497. }
  498. </script>
  499. </body>
  500. </html>