mirror of
https://github.com/safing/portmaster
synced 2025-04-22 11:59:09 +00:00
* Move portbase into monorepo * Add new simple module mgr * [WIP] Switch to new simple module mgr * Add StateMgr and more worker variants * [WIP] Switch more modules * [WIP] Switch more modules * [WIP] swtich more modules * [WIP] switch all SPN modules * [WIP] switch all service modules * [WIP] Convert all workers to the new module system * [WIP] add new task system to module manager * [WIP] Add second take for scheduling workers * [WIP] Add FIXME for bugs in new scheduler * [WIP] Add minor improvements to scheduler * [WIP] Add new worker scheduler * [WIP] Fix more bug related to new module system * [WIP] Fix start handing of the new module system * [WIP] Improve startup process * [WIP] Fix minor issues * [WIP] Fix missing subsystem in settings * [WIP] Initialize managers in constructor * [WIP] Move module event initialization to constrictors * [WIP] Fix setting for enabling and disabling the SPN module * [WIP] Move API registeration into module construction * [WIP] Update states mgr for all modules * [WIP] Add CmdLine operation support * Add state helper methods to module group and instance * Add notification and module status handling to status package * Fix starting issues * Remove pilot widget and update security lock to new status data * Remove debug logs * Improve http server shutdown * Add workaround for cleanly shutting down firewall+netquery * Improve logging * Add syncing states with notifications for new module system * Improve starting, stopping, shutdown; resolve FIXMEs/TODOs * [WIP] Fix most unit tests * Review new module system and fix minor issues * Push shutdown and restart events again via API * Set sleep mode via interface * Update example/template module * [WIP] Fix spn/cabin unit test * Remove deprecated UI elements * Make log output more similar for the logging transition phase * Switch spn hub and observer cmds to new module system * Fix log sources * Make worker mgr less error prone * Fix tests and minor issues * Fix observation hub * Improve shutdown and restart handling * Split up big connection.go source file * Move varint and dsd packages to structures repo * Improve expansion test * Fix linter warnings * Fix interception module on windows * Fix linter errors --------- Co-authored-by: Vladimir Stoilov <vladimir@safing.io>
141 lines
3.4 KiB
Go
141 lines
3.4 KiB
Go
package broadcasts
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/safing/portmaster/base/config"
|
|
"github.com/safing/portmaster/service/intel/geoip"
|
|
"github.com/safing/portmaster/service/netenv"
|
|
"github.com/safing/portmaster/service/updates"
|
|
"github.com/safing/portmaster/spn/access"
|
|
"github.com/safing/portmaster/spn/access/account"
|
|
"github.com/safing/portmaster/spn/captain"
|
|
)
|
|
|
|
var portmasterStarted = time.Now()
|
|
|
|
func collectData() interface{} {
|
|
data := make(map[string]interface{})
|
|
|
|
// Get data about versions.
|
|
versions := updates.GetSimpleVersions()
|
|
data["Updates"] = versions
|
|
data["Version"] = versions.Build.Version
|
|
numericVersion, err := MakeNumericVersion(versions.Build.Version)
|
|
if err != nil {
|
|
data["NumericVersion"] = &DataError{
|
|
Error: err,
|
|
}
|
|
} else {
|
|
data["NumericVersion"] = numericVersion
|
|
}
|
|
|
|
// Get data about install.
|
|
installInfo, err := GetInstallInfo()
|
|
if err != nil {
|
|
data["Install"] = &DataError{
|
|
Error: err,
|
|
}
|
|
} else {
|
|
data["Install"] = installInfo
|
|
}
|
|
|
|
// Get global configuration.
|
|
data["Config"] = config.GetActiveConfigValues()
|
|
|
|
// Get data about device location.
|
|
locs, ok := netenv.GetInternetLocation()
|
|
if ok && locs.Best().LocationOrNil() != nil {
|
|
loc := locs.Best()
|
|
data["Location"] = &Location{
|
|
Country: loc.Location.Country.Code,
|
|
Coordinates: loc.Location.Coordinates,
|
|
ASN: loc.Location.AutonomousSystemNumber,
|
|
ASOrg: loc.Location.AutonomousSystemOrganization,
|
|
Source: loc.Source,
|
|
SourceAccuracy: loc.SourceAccuracy,
|
|
}
|
|
}
|
|
|
|
// Get data about SPN status.
|
|
data["SPN"] = captain.GetSPNStatus()
|
|
|
|
// Get data about account.
|
|
userRecord, err := access.GetUser()
|
|
if err != nil {
|
|
data["Account"] = &DataError{
|
|
Error: err,
|
|
}
|
|
} else {
|
|
account := &Account{
|
|
UserRecord: userRecord,
|
|
Active: userRecord.MayUse(""),
|
|
UpToDate: userRecord.Meta().Modified > time.Now().Add(-7*24*time.Hour).Unix(),
|
|
}
|
|
// Only add feature IDs when account is active.
|
|
if account.Active {
|
|
account.FeatureIDs = userRecord.CurrentPlan.FeatureIDs
|
|
}
|
|
data["Account"] = account
|
|
}
|
|
|
|
// Time running.
|
|
data["UptimeHours"] = int(time.Since(portmasterStarted).Hours())
|
|
|
|
// Get current time and date.
|
|
now := time.Now()
|
|
data["Current"] = &Current{
|
|
UnixTime: now.Unix(),
|
|
UTC: makeDateTimeInfo(now.UTC()),
|
|
Local: makeDateTimeInfo(now),
|
|
}
|
|
|
|
return data
|
|
}
|
|
|
|
// Location holds location matching data.
|
|
type Location struct {
|
|
Country string
|
|
Coordinates geoip.Coordinates
|
|
ASN uint
|
|
ASOrg string
|
|
Source netenv.DeviceLocationSource
|
|
SourceAccuracy int
|
|
}
|
|
|
|
// Account holds SPN account matching data.
|
|
type Account struct {
|
|
*access.UserRecord
|
|
Active bool
|
|
UpToDate bool
|
|
FeatureIDs []account.FeatureID
|
|
}
|
|
|
|
// DataError represents an error getting some matching data.
|
|
type DataError struct {
|
|
Error error
|
|
}
|
|
|
|
// Current holds current date and time data.
|
|
type Current struct {
|
|
UnixTime int64
|
|
UTC *DateTime
|
|
Local *DateTime
|
|
}
|
|
|
|
// DateTime holds date and time data in different formats.
|
|
type DateTime struct {
|
|
NumericDateTime int64
|
|
NumericDate int64
|
|
NumericTime int64
|
|
}
|
|
|
|
func makeDateTimeInfo(t time.Time) *DateTime {
|
|
info := &DateTime{}
|
|
info.NumericDateTime, _ = strconv.ParseInt(t.Format("20060102150405"), 10, 64)
|
|
info.NumericDate, _ = strconv.ParseInt(t.Format("20060102"), 10, 64)
|
|
info.NumericTime, _ = strconv.ParseInt(t.Format("150405"), 10, 64)
|
|
|
|
return info
|
|
}
|