marek 1 mēnesi atpakaļ
vecāks
revīzija
e2deda7a61

+ 3 - 2
routes/include/main.js

@@ -5,6 +5,7 @@ const eta = new Eta({ views: "./templates" })
 
 import Meteostanica from '../../utils/meteostanica'
 import editEnvVariable from '../../utils/editEnvVariable'
+import getWifiIPv4 from '../../utils/getWifiIPv4'
 
 export default (langName, lang) => new Elysia()
   .get('/', ({ set }) => {
@@ -15,7 +16,7 @@ export default (langName, lang) => new Elysia()
   })
   .get('/settings', ({ set }) => {
     set.headers['content-type'] = 'text/html; charset=utf8'
-    return eta.render(`${langName}/settings`, { postDataEnabled: process.env.POST_DATA_ENABLED, cloudURL: process.env.BACKEND_URL })
+    return eta.render(`${langName}/settings`, { wifiIPv4: getWifiIPv4(), postDataEnabled: process.env.POST_DATA_ENABLED, cloudURL: process.env.BACKEND_URL })
   })
   .post('/settings', async ({ body, set, redirect }) => {
     const postDataEnabled = body?.postDataEnabled
@@ -26,7 +27,7 @@ export default (langName, lang) => new Elysia()
 
     if (!cloudURL) {
       set.headers['content-type'] = 'text/html; charset=utf8'
-      return eta.render(`${langName}/settings`, { lang, error: `noCloudURL` })
+      return eta.render(`${langName}/settings`, { wifiIPv4: getWifiIPv4(), lang, error: `noCloudURL` })
     }
     
     await editEnvVariable(`POST_DATA_ENABLED`, postDataEnabled ?? "false")

+ 12 - 1
templates/en/partials/topbar.eta

@@ -17,6 +17,17 @@
     </svg>
 ` %>
 
+<% const ipIcon = `
+    <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+        <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
+            <rect width="6" height="6" x="16" y="16" rx="1" />
+            <rect width="6" height="6" x="2" y="16" rx="1" />
+            <rect width="6" height="6" x="9" y="2" rx="1" />
+            <path d="M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3m-7-4V8" />
+        </g>
+    </svg>
+` %>
+
 <% const homeIcon = `
     <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
         <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
@@ -58,7 +69,7 @@
     <p><%~ timeIcon %> <span id="topbarTime"><%= date.toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', second: 'numeric', hour12: true }) %></span></p>
     
     <p><%~ dateIcon %> <span id="topbarDate"><%= date.toLocaleDateString('en-US', { weekday: "long", year: "numeric", month: "long", day: "numeric" }) %></span></p>
-    
+        
     <div class="end">
         <a role="button" href="/"><%~ skFlag %></a>
         <a role="button" href="/en"><%~ homeIcon %></a>

+ 13 - 0
templates/en/settings.eta

@@ -2,6 +2,17 @@
 
 <%~ include("/en/partials/topbar") %>
 
+<% const ipIcon = `
+    <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+        <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
+            <rect width="6" height="6" x="16" y="16" rx="1" />
+            <rect width="6" height="6" x="2" y="16" rx="1" />
+            <rect width="6" height="6" x="9" y="2" rx="1" />
+            <path d="M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3m-7-4V8" />
+        </g>
+    </svg>
+` %>
+
 <h2>settings</h2>
 
 <% const errorValue = it.error?.split('.').reduce((a, b) => a[b], it.lang.settings?.errors)?.(it?.errorDetails) %>
@@ -12,6 +23,8 @@
     </div>
 <% } %>
 
+<p><%~ ipIcon %> <%= it.wifiIPv4 %></p>
+
 <form action="/en/settings" method="post">
     <div>
       <label for="postDataEnabled">post data</label>

+ 12 - 1
templates/sk/partials/topbar.eta

@@ -17,6 +17,17 @@
     </svg>
 ` %>
 
+<% const ipIcon = `
+    <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+        <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
+            <rect width="6" height="6" x="16" y="16" rx="1" />
+            <rect width="6" height="6" x="2" y="16" rx="1" />
+            <rect width="6" height="6" x="9" y="2" rx="1" />
+            <path d="M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3m-7-4V8" />
+        </g>
+    </svg>
+` %>
+
 <% const homeIcon = `
     <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
         <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
@@ -55,7 +66,7 @@
     <p><%~ timeIcon %> <span id="topbarTime"><%= date.toLocaleString('sk-SK', { hour: 'numeric', minute: 'numeric', second: 'numeric' }) %></span></p>
     
     <p><%~ dateIcon %> <span id="topbarDate"><%= date.toLocaleDateString('sk-SK', { weekday: "long", year: "numeric", month: "long", day: "numeric" }) %></span></p>
-    
+        
     <div class="end">
         <a role="button" href="/en"><%~ usFlag %></a>
         <a role="button" href="/"><%~ homeIcon %></a>

+ 13 - 0
templates/sk/settings.eta

@@ -2,6 +2,17 @@
 
 <%~ include("/sk/partials/topbar") %>
 
+<% const ipIcon = `
+    <svg class="icon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+        <g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2">
+            <rect width="6" height="6" x="16" y="16" rx="1" />
+            <rect width="6" height="6" x="2" y="16" rx="1" />
+            <rect width="6" height="6" x="9" y="2" rx="1" />
+            <path d="M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3m-7-4V8" />
+        </g>
+    </svg>
+` %>
+
 <h2>nastavenia</h2>
 
 <% const errorValue = it.error?.split('.').reduce((a, b) => a[b], it.lang.settings?.errors)?.(it?.errorDetails) %>
@@ -12,6 +23,8 @@
     </div>
 <% } %>
 
+<p><%~ ipIcon %> <%= it.wifiIPv4 %></p>
+
 <form action="/settings" method="post">
     <div>
       <label for="postDataEnabled">odosielať dáta</label>

+ 15 - 0
utils/getWifiIPv4.js

@@ -0,0 +1,15 @@
+import { networkInterfaces } from "node:os";
+
+export default () => {
+  const interfaces = networkInterfaces();
+
+  for (const name of Object.keys(interfaces)) {
+    if (!name.startsWith('wlan') && !name.startsWith('wlp')) continue
+      
+    for (const net of interfaces[name]) {
+        if (net.family !== "IPv4" || net.internal) continue
+        
+        return net.address;
+    }
+  }
+}