Fix: SettingsController in install.sh aktualisiert (rmmagent[general] Parsing)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package collector
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -59,3 +61,69 @@ func CollectUptime() int64 {
|
||||
}
|
||||
return uptime
|
||||
}
|
||||
|
||||
// LicenseInfo fuer OPNsense Business Edition
|
||||
type LicenseInfo struct {
|
||||
IsBusinessEdition bool `json:"is_business_edition"`
|
||||
ProductName string `json:"product_name,omitempty"`
|
||||
Subscription string `json:"subscription,omitempty"`
|
||||
ValidTo string `json:"valid_to,omitempty"`
|
||||
DaysRemaining int `json:"days_remaining,omitempty"`
|
||||
}
|
||||
|
||||
func CollectLicense() *LicenseInfo {
|
||||
// core version file lesen
|
||||
coreData, err := os.ReadFile("/usr/local/opnsense/version/core")
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var core map[string]interface{}
|
||||
if err := json.Unmarshal(coreData, &core); err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
productID, _ := core["product_id"].(string)
|
||||
coreName, _ := core["CORE_NAME"].(string)
|
||||
|
||||
isBusiness := productID == "opnsense-business" || coreName == "opnsense-business"
|
||||
if !isBusiness {
|
||||
return &LicenseInfo{IsBusinessEdition: false, ProductName: "OPNsense Community"}
|
||||
}
|
||||
|
||||
info := &LicenseInfo{
|
||||
IsBusinessEdition: true,
|
||||
ProductName: "OPNsense Business Edition",
|
||||
}
|
||||
|
||||
// Lizenz-Ablauf lesen
|
||||
licData, err := os.ReadFile("/usr/local/opnsense/version/core.license")
|
||||
if err == nil {
|
||||
var lic map[string]string
|
||||
if json.Unmarshal(licData, &lic) == nil {
|
||||
if validTo, ok := lic["valid_to"]; ok {
|
||||
info.ValidTo = validTo
|
||||
if t, err := time.Parse("2006-01-02", validTo); err == nil {
|
||||
days := int(time.Until(t).Hours() / 24)
|
||||
info.DaysRemaining = days
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Subscription-Code aus config.xml lesen
|
||||
out, err := exec.Command("/usr/local/bin/php", "-r", `
|
||||
$c = simplexml_load_file("/conf/config.xml");
|
||||
if (isset($c->system->firmware->subscription)) {
|
||||
echo (string)$c->system->firmware->subscription;
|
||||
}
|
||||
`).Output()
|
||||
if err == nil {
|
||||
sub := strings.TrimSpace(string(out))
|
||||
if sub != "" {
|
||||
info.Subscription = sub
|
||||
}
|
||||
}
|
||||
|
||||
return info
|
||||
}
|
||||
|
||||
@@ -23,8 +23,28 @@ func CollectServices() []ServiceInfo {
|
||||
return tryServiceList()
|
||||
}
|
||||
|
||||
// FreeBSD boot/init scripts that run once and are not real services
|
||||
var ignoredServices = map[string]bool{
|
||||
"bgfsck": true, "cleanvar": true, "cleartmp": true, "devmatch": true,
|
||||
"dmesg": true, "gptboot": true, "hostid": true, "hostid_save": true,
|
||||
"kldxref": true, "mixer": true, "motd": true, "netif": true,
|
||||
"newsyslog": true, "os-release": true, "rctl": true, "resolv": true,
|
||||
"savecore": true, "utx": true, "var_run": true, "virecover": true,
|
||||
"adjkerntz": true, "automount": true, "automountd": true, "autounmountd": true,
|
||||
"cron": true, "devd": true, "dhclient": true, "fsck": true,
|
||||
"growfs": true, "iovctl": true, "ip6addrctl": true, "ipsec": true,
|
||||
"kld": true, "ldconfig": true, "linux": true, "local": true,
|
||||
"localpkg": true, "lockd": true, "mdconfig": true, "mdconfig2": true,
|
||||
"mountcritlocal": true, "mountcritremote": true, "mountlate": true,
|
||||
"msgs": true, "nsswitch": true, "ntpdate": true, "pf": true,
|
||||
"pflog": true, "powerd": true, "random": true, "root": true,
|
||||
"routing": true, "securelevel": true, "serial": true, "statd": true,
|
||||
"swap": true, "swaplate": true, "syscons": true, "sysctl": true,
|
||||
"tmp": true, "ugidfw": true, "zfs": true, "zvol": true,
|
||||
}
|
||||
|
||||
func tryPluginctl() []ServiceInfo {
|
||||
out, err := exec.Command("pluginctl", "-s").Output()
|
||||
out, err := exec.Command("/usr/local/sbin/pluginctl", "-s").Output()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -32,7 +52,7 @@ func tryPluginctl() []ServiceInfo {
|
||||
var services []ServiceInfo
|
||||
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
|
||||
name := strings.TrimSpace(line)
|
||||
if name == "" {
|
||||
if name == "" || ignoredServices[name] {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -125,6 +125,7 @@ func sendHeartbeat(c *client.Client, agentID string) error {
|
||||
plugins := collector.CollectPlugins()
|
||||
updates := collector.CollectUpdates()
|
||||
cronJobs := collector.CollectCron()
|
||||
license := collector.CollectLicense()
|
||||
|
||||
req := map[string]interface{}{
|
||||
"agent_id": agentID,
|
||||
@@ -164,6 +165,7 @@ func sendHeartbeat(c *client.Client, agentID string) error {
|
||||
"plugins": plugins,
|
||||
"updates": updates,
|
||||
"cron_jobs": cronJobs,
|
||||
"license": license,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user