harbour-server 0.1.0: schermata parametri server (schema status/1)

Prima release dell'app Sailfish: schermata unica con CPU, memoria, disco,
container, backup, servizi, SSH, aggiornamenti e VPN, letti da un endpoint
read-only /v1/status. Soglie giallo/rosso, aggiornamento ogni 60 s,
copertina, impostazioni con indirizzo e token.
This commit is contained in:
Carlo Baratto committed 2026-10-28 09:12:45 +01:00
commit 24e1f3b376
20 files changed
+1112

No files matched your search

+79
View File
@@ -0,0 +1,79 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import "../components"
// Un parametro in una card: titolo a sinistra, valore a destra, riga di
// dettaglio e barra opzionale. level: 0 = ok, 1 = attenzione, 2 = critico.
Rectangle {
id: card
property string title
property string value
property string detail
property real progress: -1
property int level: 0
function levelColor() {
if (level === 2) return "#e53935"
if (level === 1) return "#ffb300"
return "#43a047"
}
width: parent ? parent.width : 0
height: content.height + 2 * Theme.paddingMedium
radius: Theme.paddingSmall
color: Theme.rgba(Theme.highlightBackgroundColor, 0.08)
Column {
id: content
x: Theme.paddingMedium
y: Theme.paddingMedium
width: parent.width - 2 * Theme.paddingMedium
spacing: Theme.paddingSmall / 2
Row {
width: parent.width
Label {
text: card.title
font.pixelSize: Theme.fontSizeSmall
color: Theme.secondaryColor
width: parent.width * 0.55
truncationMode: TruncationMode.Fade
}
Label {
text: card.value
font.pixelSize: Theme.fontSizeMedium
color: card.level === 0 ? Theme.primaryColor : card.levelColor()
horizontalAlignment: Text.AlignRight
width: parent.width * 0.45
truncationMode: TruncationMode.Fade
}
}
Label {
text: card.detail
visible: card.detail !== ""
font.pixelSize: Theme.fontSizeExtraSmall
color: Theme.secondaryColor
width: parent.width
wrapMode: Text.WordWrap
}
Rectangle {
visible: card.progress >= 0
width: parent.width
height: 4
radius: 2
color: Theme.rgba(Theme.primaryColor, 0.15)
Rectangle {
width: parent.width * Math.max(0, Math.min(100, card.progress)) / 100
height: parent.height
radius: 2
color: card.levelColor()
}
}
}
}
+52
View File
@@ -0,0 +1,52 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
CoverBackground {
id: cover
// Guardie: quando lo snapshot non è ancora arrivato i campi mancano e in
// JS leggere una proprietà di undefined solleva un'eccezione.
function num(v, fallback) {
return (v === undefined || v === null) ? fallback : v
}
Column {
anchors.centerIn: parent
width: parent.width - 2 * Theme.paddingLarge
spacing: Theme.paddingSmall
Label {
text: "Server"
font.pixelSize: Theme.fontSizeSmall
color: Theme.secondaryColor
anchors.horizontalCenter: parent.horizontalCenter
}
Label {
text: statusClient.error !== "" ? "—" : statusClient.fmtNum(num(statusClient.data.cpu ? statusClient.data.cpu.percent : undefined, -1), 0) + " %"
font.pixelSize: Theme.fontSizeExtraLarge
anchors.horizontalCenter: parent.horizontalCenter
}
Label {
text: "CPU"
font.pixelSize: Theme.fontSizeExtraSmall
color: Theme.secondaryColor
anchors.horizontalCenter: parent.horizontalCenter
}
Label {
text: statusClient.fetchedAt !== "" ? statusClient.fetchedAt : ""
font.pixelSize: Theme.fontSizeExtraSmall
color: Theme.secondaryColor
anchors.horizontalCenter: parent.horizontalCenter
}
}
CoverActionList {
CoverAction {
iconSource: "image://theme/icon-cover-refresh"
onTriggered: statusClient.refresh()
}
}
}
+10
View File
@@ -0,0 +1,10 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import "pages"
ApplicationWindow {
objectName: "applicationWindow"
initialPage: Component { StatusPage { } }
cover: Qt.resolvedUrl("cover/CoverPage.qml")
allowedOrientations: defaultAllowedOrientations
}
+79
View File
@@ -0,0 +1,79 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: page
Column {
anchors.fill: parent
spacing: Theme.paddingMedium
PageHeader {
title: qsTr("Impostazioni")
}
TextField {
id: urlField
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Theme.paddingLarge
anchors.rightMargin: Theme.paddingLarge
label: qsTr("Indirizzo del server")
placeholderText: "http://192.168.3.21:8792"
text: appSettings.baseUrl
inputMethodHints: Qt.ImhUrlCharactersOnly | Qt.ImhNoPredictiveText
}
TextField {
id: tokenField
anchors.left: parent.left
anchors.right: parent.right
anchors.leftMargin: Theme.paddingLarge
anchors.rightMargin: Theme.paddingLarge
label: qsTr("Token")
placeholderText: qsTr("incolla il token del server")
text: appSettings.token
echoMode: TextInput.Password
inputMethodHints: Qt.ImhNoPredictiveText | Qt.ImhNoAutoUppercase
}
Label {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
font.pixelSize: Theme.fontSizeExtraSmall
color: Theme.secondaryColor
wrapMode: Text.WordWrap
text: qsTr("Il token è il contenuto di ~/.config/statusd/token sul server. " +
"Fuori casa serve la VPN attiva: la porta 8792 è chiusa su Internet.")
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Salva e verifica")
onClicked: {
appSettings.save(urlField.text, tokenField.text)
statusClient.refresh()
}
}
Label {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
visible: statusClient.error !== ""
text: statusClient.error
font.pixelSize: Theme.fontSizeSmall
color: "#e53935"
wrapMode: Text.WordWrap
}
Label {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
visible: statusClient.error === "" && statusClient.fetchedAt !== ""
text: qsTr("Risposta ricevuta alle ") + statusClient.fetchedAt
font.pixelSize: Theme.fontSizeSmall
color: "#43a047"
wrapMode: Text.WordWrap
}
}
}
+231
View File
@@ -0,0 +1,231 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
import "../components"
Page {
id: page
// ── Letture difensive dello snapshot ──────────────────────────────────
// Il JSON arriva da un altro processo: ogni campo può mancare. In JS
// leggere una proprietà di undefined solleva un'eccezione, quindi si
// passa sempre da queste funzioni.
function cpuPct() { var d = statusClient.data; return (d && d.cpu && d.cpu.percent !== undefined) ? d.cpu.percent : -1 }
function cpuTemp() { var d = statusClient.data; return (d && d.cpu && d.cpu.temp_c !== undefined) ? d.cpu.temp_c : -1 }
function cpuCores() { var d = statusClient.data; return (d && d.cpu && d.cpu.cores !== undefined) ? d.cpu.cores : 0 }
function memPercent() { var d = statusClient.data; return (d && d.memory && d.memory.percent !== undefined) ? d.memory.percent : -1 }
function memText() {
var d = statusClient.data
if (!d || !d.memory) return ""
return statusClient.fmtBytes(d.memory.used_bytes) + " / " + statusClient.fmtBytes(d.memory.total_bytes)
}
function swapPercent() {
var d = statusClient.data
if (!d || !d.memory || !d.memory.swap_total_bytes) return 0
return 100 * d.memory.swap_used_bytes / d.memory.swap_total_bytes
}
function disk() { var d = statusClient.data; return (d && d.disks && d.disks.length > 0) ? d.disks[0] : null }
function diskPct() { var x = disk(); return x ? x.percent : -1 }
function diskText() { var x = disk(); return x ? statusClient.fmtBytes(x.used_bytes) + " / " + statusClient.fmtBytes(x.total_bytes) : "" }
function containers() { var d = statusClient.data; return (d && d.containers && d.containers.running) ? d.containers.running : [] }
function containersBad() {
var list = containers(), n = 0, i
for (i = 0; i < list.length; i++) if (!list[i].ok) n++
return n
}
function containersText() {
var list = containers(), names = [], i
for (i = 0; i < list.length; i++) names.push(list[i].name)
return names.join(", ")
}
function backupAge() { var d = statusClient.data; return (d && d.backups && d.backups.age_hours !== null && d.backups.age_hours !== undefined) ? d.backups.age_hours : -1 }
function backupResult() { var d = statusClient.data; return (d && d.backups && d.backups.result) ? d.backups.result : "" }
function backupLevel() {
if (backupResult() === "") return 1
if (backupResult() !== "success") return 2
var age = backupAge()
if (age < 0) return 1
if (age > 72) return 2
if (age > 36) return 1
return 0
}
function failedServices() { var d = statusClient.data; return (d && d.services && d.services.failed) ? d.services.failed.length : 0 }
function sshFailed() { var d = statusClient.data; return (d && d.access && d.access.ssh_failed_24h !== undefined) ? d.access.ssh_failed_24h : 0 }
function updatesTotal() { var d = statusClient.data; return (d && d.updates && d.updates.total !== undefined) ? d.updates.total : 0 }
function updatesSecurity() { var d = statusClient.data; return (d && d.updates && d.updates.security !== undefined) ? d.updates.security : 0 }
function vpnText() {
var d = statusClient.data
if (!d || !d.net || !d.net.interfaces || d.net.interfaces.length === 0) return "nessuna"
return d.net.interfaces.join(", ")
}
function hostText() {
var d = statusClient.data
if (!d || !d.host) return ""
var s = d.host.hostname
if (d.host.uptime_s) s = s + " · attivo da " + statusClient.fmtUptime(d.host.uptime_s)
return s
}
function levelFor(percent, warn, bad) {
if (percent < 0) return 0
if (percent >= bad) return 2
if (percent >= warn) return 1
return 0
}
SilicaFlickable {
anchors.fill: parent
contentHeight: column.height + Theme.paddingLarge
PullDownMenu {
MenuItem {
text: qsTr("Aggiorna")
onClicked: statusClient.refresh()
}
MenuItem {
text: qsTr("Impostazioni")
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
}
}
Column {
id: column
width: parent.width
spacing: Theme.paddingMedium
PageHeader { title: qsTr("Stato server") }
Label {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
text: hostText()
visible: text !== ""
font.pixelSize: Theme.fontSizeExtraSmall
color: Theme.secondaryColor
truncationMode: TruncationMode.Fade
}
// Nessun server configurato: un solo comando, nel menu.
Label {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
visible: !statusClient.configured
text: qsTr("Nessun server configurato. Menu in alto → Impostazioni.")
font.pixelSize: Theme.fontSizeSmall
color: Theme.highlightColor
wrapMode: Text.WordWrap
}
// Errore visibile: senza questo la schermata resta vuota e muta.
Label {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
visible: statusClient.error !== ""
text: statusClient.error
font.pixelSize: Theme.fontSizeSmall
color: "#e53935"
wrapMode: Text.WordWrap
}
MetricCard {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
title: qsTr("CPU")
value: cpuPct() < 0 ? "—" : statusClient.fmtNum(cpuPct(), 0) + " %"
detail: (cpuTemp() >= 0 ? statusClient.fmtNum(cpuTemp(), 0) + " °C · " : "") + cpuCores() + " core"
progress: cpuPct()
level: levelFor(cpuPct(), 85, 95)
}
MetricCard {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
title: qsTr("Memoria")
value: memPercent() < 0 ? "—" : statusClient.fmtNum(memPercent(), 0) + " %"
detail: memText() + " · swap " + statusClient.fmtNum(swapPercent(), 0) + " %"
progress: memPercent()
level: Math.max(levelFor(memPercent(), 85, 95), levelFor(swapPercent(), 80, 95))
}
MetricCard {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
title: qsTr("Disco") + (disk() ? " " + disk().mount : "")
value: diskPct() < 0 ? "—" : statusClient.fmtNum(diskPct(), 0) + " %"
detail: diskText()
progress: diskPct()
level: levelFor(diskPct(), 85, 95)
}
MetricCard {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
title: qsTr("Container")
value: containers().length + " " + qsTr("attivi")
detail: containersText()
progress: -1
level: containersBad() > 0 ? 2 : 0
}
MetricCard {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
title: qsTr("Backup")
value: backupAge() < 0 ? "—" : statusClient.fmtAge(backupAge())
detail: backupResult() === "" ? qsTr("nessun dato") : "borg · " + backupResult()
progress: -1
level: backupLevel()
}
MetricCard {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
title: qsTr("Servizi")
value: failedServices() === 0 ? qsTr("tutti attivi") : failedServices() + " " + qsTr("in errore")
detail: ""
progress: -1
level: failedServices() > 0 ? 2 : 0
}
MetricCard {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
title: qsTr("SSH")
value: sshFailed() + " " + qsTr("tentativi")
detail: qsTr("password fallite nelle ultime 24 h")
progress: -1
level: sshFailed() >= 200 ? 2 : (sshFailed() >= 50 ? 1 : 0)
}
MetricCard {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
title: qsTr("Aggiornamenti")
value: updatesTotal() === 0 ? qsTr("nessuno") : String(updatesTotal())
detail: qsTr("di cui di sicurezza: ") + updatesSecurity()
progress: -1
level: updatesSecurity() > 0 ? 1 : 0
}
MetricCard {
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
title: qsTr("VPN")
value: vpnText()
detail: statusClient.fetchedAt !== "" ? qsTr("aggiornato alle ") + statusClient.fetchedAt : ""
progress: -1
level: vpnText() === qsTr("nessuna") ? 2 : 0
}
}
VerticalScrollDecorator { }
}
// Aggiornamento automatico: lo snapshot sul server è rigenerato ogni 60 s.
Timer {
interval: 60000
running: true
repeat: true
onTriggered: statusClient.refresh()
}
Component.onCompleted: statusClient.refresh()
}