Skip to content

Commit e4fe1e5

Browse files
committed
Update version parsing
1 parent 2d26068 commit e4fe1e5

4 files changed

Lines changed: 80 additions & 11 deletions

File tree

backend/internal/web/handlers.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"math"
99
"net"
1010
"net/http"
11+
"os"
1112
"path/filepath"
1213
"strings"
1314
"time"
@@ -2205,8 +2206,11 @@ func (h *WebHandler) APIAbout(w http.ResponseWriter, r *http.Request) {
22052206
return
22062207
}
22072208

2209+
// Read version from package.json
2210+
version := h.getVersionFromPackageJSON()
2211+
22082212
response := map[string]interface{}{
2209-
"version": "0.14",
2213+
"version": version,
22102214
}
22112215

22122216
w.Header().Set("Content-Type", "application/json")
@@ -2396,3 +2400,31 @@ func (h *WebHandler) APINetworksDebug(w http.ResponseWriter, r *http.Request) {
23962400
}
23972401
}
23982402

2403+
// getVersionFromPackageJSON reads the version from package.json
2404+
func (h *WebHandler) getVersionFromPackageJSON() string {
2405+
// Try to read package.json from the project root
2406+
packageJSONPath := filepath.Join("..", "package.json")
2407+
2408+
// If that doesn't work, try relative to the binary location
2409+
if _, err := os.Stat(packageJSONPath); os.IsNotExist(err) {
2410+
packageJSONPath = "package.json"
2411+
}
2412+
2413+
data, err := os.ReadFile(packageJSONPath)
2414+
if err != nil {
2415+
log.Printf("Error reading package.json: %v", err)
2416+
return "unknown"
2417+
}
2418+
2419+
var packageInfo struct {
2420+
Version string `json:"version"`
2421+
}
2422+
2423+
if err := json.Unmarshal(data, &packageInfo); err != nil {
2424+
log.Printf("Error parsing package.json: %v", err)
2425+
return "unknown"
2426+
}
2427+
2428+
return packageInfo.Version
2429+
}
2430+

backend/static/js/devices.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function renderDeviceGrid(devices) {
5757
console.log('devices-container not found in renderDeviceGrid');
5858
return;
5959
}
60-
60+
6161
console.log('Devices length:', devices ? devices.length : 'null/undefined');
6262
if (!devices || devices.length === 0) {
6363
console.log('No devices found, showing empty message');
@@ -70,12 +70,35 @@ function renderDeviceGrid(devices) {
7070
`;
7171
return;
7272
}
73-
74-
console.log('Rendering', devices.length, 'devices');
73+
74+
// Filter out devices that have never been online
75+
// Only show devices that have been seen at least once (have LastSeenOnlineAt timestamp or are currently online/offline)
76+
const onlineDevices = devices.filter(device => {
77+
return device.LastSeenOnlineAt ||
78+
device.status === 'online' ||
79+
device.status === 'offline' ||
80+
device.status === 'idle';
81+
});
82+
83+
console.log('Filtered to', onlineDevices.length, 'devices that have been online (from', devices.length, 'total)');
84+
85+
if (onlineDevices.length === 0) {
86+
console.log('No online devices found, showing empty message');
87+
devicesContainer.innerHTML = `
88+
<div class="text-center py-8 text-gray-400">
89+
<i class="ti ti-router text-4xl mb-2 block"></i>
90+
<p>No devices have been seen online</p>
91+
<p class="text-sm text-gray-500">Start a network scan to discover devices</p>
92+
</div>
93+
`;
94+
return;
95+
}
96+
97+
console.log('Rendering', onlineDevices.length, 'online devices');
7598

7699
let gridHTML = '<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 gap-6">';
77-
78-
devices.forEach(device => {
100+
101+
onlineDevices.forEach(device => {
79102
// Count ports
80103
let openPorts = 0;
81104
let filteredPorts = 0;
@@ -154,7 +177,7 @@ function renderDeviceModal(device, screenshotsEnabled = false) {
154177
${device.mac ? `<div><span style="color: var(--text-muted);">MAC Address:</span> <span class="text-blue-400">${device.mac}</span></div>` : ''}
155178
${device.hostname ? `<div><span style="color: var(--text-muted);">Hostname:</span> <span style="color: var(--text-primary);">${device.hostname}</span></div>` : ''}
156179
<div><span style="color: var(--text-muted);">Status:</span> <span class="px-2 py-1 rounded text-xs ${getStatusBadgeColor(device.status)}">${device.status}</span></div>
157-
${device.LastSeen ? `<div><span style="color: var(--text-muted);">Last Seen:</span> <span style="color: var(--text-primary);">${formatLogTime(device.LastSeen)}</span></div>` : ''}
180+
${device.LastSeenOnlineAt ? `<div><span style="color: var(--text-muted);">Last Seen:</span> <span style="color: var(--text-primary);">${formatLogTime(device.LastSeenOnlineAt)}</span></div>` : ''}
158181
</div>
159182
</div>
160183

backend/static/js/main.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,30 @@ function loadAboutPage() {
115115
}
116116

117117
function showAboutModal() {
118+
// Fetch version from API first
119+
fetch('/api/about', { credentials: 'include' })
120+
.then(response => response.json())
121+
.then(data => {
122+
const version = data.version || 'unknown';
123+
displayAboutModal(version);
124+
})
125+
.catch(error => {
126+
console.error('Error fetching version:', error);
127+
displayAboutModal('unknown');
128+
});
129+
}
130+
131+
function displayAboutModal(version) {
118132
const aboutContent = `
119133
<div class="p-6 max-w-2xl mx-auto">
120134
<!-- Header -->
121135
<div class="text-center mb-6">
122-
<h1 class="text-3xl font-bold text-green-500 mb-3">
136+
<h1 class="text-3xl font-bold text-green-500 mb-3" style="font-family: 'Orbitron', monospace; font-weight: 800; letter-spacing: 0.5px;">
123137
<i class="ti ti-network mr-2"></i>reconYa
124138
</h1>
125139
<p class="text-lg text-gray-300 mb-3">Network Reconnaissance and Asset Discovery Tool</p>
126140
<div class="inline-block bg-green-500 text-black px-3 py-1 rounded text-sm font-semibold">
127-
Version 1.0.0
141+
v${version}
128142
</div>
129143
</div>
130144
@@ -183,7 +197,7 @@ function showAboutModal() {
183197
</div>
184198
</div>
185199
`;
186-
200+
187201
// Create and show modal
188202
const modalEl = document.getElementById('aboutModal');
189203
if (modalEl) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "reconya",
3-
"version": "0.18.1",
3+
"version": "0.21",
44
"description": "Network reconnaissance and asset discovery tool",
55
"main": "scripts/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)