Merge branch 'develop' into revamp/verdicts

This commit is contained in:
Patrick Pacher 2024-03-20 09:37:29 +01:00 committed by GitHub
commit 67d0d11b81
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 101 additions and 43 deletions

View file

@ -2,6 +2,7 @@ package compat
import ( import (
"context" "context"
"errors"
"time" "time"
"github.com/tevino/abool" "github.com/tevino/abool"
@ -92,6 +93,9 @@ func selfcheckTaskFunc(ctx context.Context, task *modules.Task) error {
case err == nil: case err == nil:
// Successful. // Successful.
tracer.Debugf("compat: self-check successful") tracer.Debugf("compat: self-check successful")
case errors.Is(err, errSelfcheckSkipped):
// Skipped.
tracer.Debugf("compat: %s", err)
case issue == nil: case issue == nil:
// Internal error. // Internal error.
tracer.Warningf("compat: %s", err) tracer.Warningf("compat: %s", err)

View file

@ -3,6 +3,7 @@ package compat
import ( import (
"context" "context"
"encoding/hex" "encoding/hex"
"errors"
"fmt" "fmt"
"net" "net"
"strings" "strings"
@ -11,6 +12,7 @@ import (
"github.com/safing/portbase/log" "github.com/safing/portbase/log"
"github.com/safing/portbase/rng" "github.com/safing/portbase/rng"
"github.com/safing/portmaster/netenv"
"github.com/safing/portmaster/network/packet" "github.com/safing/portmaster/network/packet"
"github.com/safing/portmaster/resolver" "github.com/safing/portmaster/resolver"
) )
@ -36,12 +38,19 @@ var (
dnsCheckWaitDuration = 45 * time.Second dnsCheckWaitDuration = 45 * time.Second
dnsCheckAnswerLock sync.Mutex dnsCheckAnswerLock sync.Mutex
dnsCheckAnswer net.IP dnsCheckAnswer net.IP
errSelfcheckSkipped = errors.New("self-check skipped")
) )
func selfcheck(ctx context.Context) (issue *systemIssue, err error) { func selfcheck(ctx context.Context) (issue *systemIssue, err error) {
selfcheckLock.Lock() selfcheckLock.Lock()
defer selfcheckLock.Unlock() defer selfcheckLock.Unlock()
// Step 0: Check if self-check makes sense.
if !netenv.Online() {
return nil, fmt.Errorf("%w: device is offline or in limited network", errSelfcheckSkipped)
}
// Step 1: Check if the system integration sees a packet. // Step 1: Check if the system integration sees a packet.
// Empty recv channel. // Empty recv channel.

View file

@ -77,6 +77,7 @@ var (
"network-test.debian.org.", // Debian "network-test.debian.org.", // Debian
"204.pop-os.org.", // Pop OS "204.pop-os.org.", // Pop OS
"conncheck.opensuse.org.", // OpenSUSE "conncheck.opensuse.org.", // OpenSUSE
"ping.archlinux.org", // Arch
// There are probably a lot more domains for all the Linux Distro/DE Variants. Please raise issues and/or submit PRs! // There are probably a lot more domains for all the Linux Distro/DE Variants. Please raise issues and/or submit PRs!
// https://github.com/solus-project/budgie-desktop/issues/807 // https://github.com/solus-project/budgie-desktop/issues/807
// https://www.lguruprasad.in/blog/2015/07/21/enabling-captive-portal-detection-in-gnome-3-14-on-debian-jessie/ // https://www.lguruprasad.in/blog/2015/07/21/enabling-captive-portal-detection-in-gnome-3-14-on-debian-jessie/
@ -434,7 +435,7 @@ func checkOnlineStatus(ctx context.Context) {
ipv4, ipv6, err := GetAssignedAddresses() ipv4, ipv6, err := GetAssignedAddresses()
if err != nil { if err != nil {
log.Warningf("network: failed to get assigned network addresses: %s", err) log.Warningf("netenv: failed to get assigned network addresses: %s", err)
} else { } else {
var lan bool var lan bool

View file

@ -14,8 +14,8 @@ var (
25: "SMTP", 25: "SMTP",
43: "WHOIS", 43: "WHOIS",
53: "DNS", 53: "DNS",
67: "DHCP-SERVER", 67: "DHCP_SERVER",
68: "DHCP-CLIENT", 68: "DHCP_CLIENT",
69: "TFTP", 69: "TFTP",
80: "HTTP", 80: "HTTP",
110: "POP3", 110: "POP3",
@ -27,10 +27,10 @@ var (
389: "LDAP", 389: "LDAP",
443: "HTTPS", 443: "HTTPS",
445: "SMB", 445: "SMB",
587: "SMTP-ALT", 587: "SMTP_ALT",
465: "SMTP-SSL", 465: "SMTP_SSL",
993: "IMAP-SSL", 993: "IMAP_SSL",
995: "POP3-SSL", 995: "POP3_SSL",
} }
portNumbers = map[string]uint16{ portNumbers = map[string]uint16{
@ -42,7 +42,9 @@ var (
"WHOIS": 43, "WHOIS": 43,
"DNS": 53, "DNS": 53,
"DHCP-SERVER": 67, "DHCP-SERVER": 67,
"DHCP_SERVER": 67,
"DHCP-CLIENT": 68, "DHCP-CLIENT": 68,
"DHCP_CLIENT": 68,
"TFTP": 69, "TFTP": 69,
"HTTP": 80, "HTTP": 80,
"POP3": 110, "POP3": 110,
@ -55,9 +57,13 @@ var (
"HTTPS": 443, "HTTPS": 443,
"SMB": 445, "SMB": 445,
"SMTP-ALT": 587, "SMTP-ALT": 587,
"SMTP_ALT": 587,
"SMTP-SSL": 465, "SMTP-SSL": 465,
"SMTP_SSL": 465,
"IMAP-SSL": 993, "IMAP-SSL": 993,
"IMAP_SSL": 993,
"POP3-SSL": 995, "POP3-SSL": 995,
"POP3_SSL": 995,
} }
) )

View file

@ -77,7 +77,8 @@ func searchDirectory(directory string, binPath string) (iconPath string, err err
} }
return "", fmt.Errorf("failed to read directory %s: %w", directory, err) return "", fmt.Errorf("failed to read directory %s: %w", directory, err)
} }
fmt.Println(directory) // DEBUG:
// fmt.Println(directory)
var ( var (
bestMatch string bestMatch string

View file

@ -35,8 +35,9 @@ func GetIconAndName(ctx context.Context, binPath string, homeDir string) (icon *
} }
return &Icon{ return &Icon{
Type: IconTypeAPI, Type: IconTypeAPI,
Value: filename, Value: filename,
Source: IconSourceCore,
}, name, nil }, name, nil
} }
@ -63,29 +64,6 @@ func getIconAndNamefromRSS(ctx context.Context, binPath string) (png []byte, nam
// return true // return true
// }) // })
// Get first icon.
var (
icon *winres.Icon
iconErr error
)
rss.WalkType(winres.RT_GROUP_ICON, func(resID winres.Identifier, langID uint16, _ []byte) bool {
icon, iconErr = rss.GetIconTranslation(resID, langID)
return iconErr != nil
})
if iconErr != nil {
return nil, "", fmt.Errorf("failed to get icon: %w", err)
}
// Convert icon.
icoBuf := &bytes.Buffer{}
err = icon.SaveICO(icoBuf)
if err != nil {
return nil, "", fmt.Errorf("failed to save ico: %w", err)
}
png, err = ConvertICOtoPNG(icoBuf.Bytes())
if err != nil {
return nil, "", fmt.Errorf("failed to convert ico to png: %w", err)
}
// Get name from version record. // Get name from version record.
var ( var (
versionInfo *version.Info versionInfo *version.Info
@ -111,5 +89,31 @@ func getIconAndNamefromRSS(ctx context.Context, binPath string) (png []byte, nam
}) })
name = cleanFileDescription(name) name = cleanFileDescription(name)
// Get first icon.
var (
icon *winres.Icon
iconErr error
)
rss.WalkType(winres.RT_GROUP_ICON, func(resID winres.Identifier, langID uint16, _ []byte) bool {
icon, iconErr = rss.GetIconTranslation(resID, langID)
return iconErr != nil
})
if iconErr != nil {
return nil, name, fmt.Errorf("failed to get icon: %w", err)
}
if icon == nil {
return nil, name, errors.New("no icon in resources")
}
// Convert icon, if it exists.
icoBuf := &bytes.Buffer{}
err = icon.SaveICO(icoBuf)
if err != nil {
return nil, name, fmt.Errorf("failed to save ico: %w", err)
}
png, err = ConvertICOtoPNG(icoBuf.Bytes())
if err != nil {
return nil, name, fmt.Errorf("failed to convert ico to png: %w", err)
}
return png, name, nil return png, name, nil
} }

View file

@ -15,8 +15,9 @@ import (
// Icon describes an icon. // Icon describes an icon.
type Icon struct { type Icon struct {
Type IconType Type IconType
Value string Value string
Source IconSource
} }
// IconType describes the type of an Icon. // IconType describes the type of an Icon.
@ -38,16 +39,46 @@ func (t IconType) sortOrder() int {
case IconTypeFile: case IconTypeFile:
return 3 return 3
default: default:
return 100 return 9
} }
} }
// IconSource describes the source of an Icon.
type IconSource string
// Supported icon sources.
const (
IconSourceUser IconSource = "user"
IconSourceImport IconSource = "import"
IconSourceUI IconSource = "ui"
IconSourceCore IconSource = "core"
)
func (s IconSource) sortOrder() int {
switch s {
case IconSourceUser:
return 10
case IconSourceImport:
return 20
case IconSourceUI:
return 30
case IconSourceCore:
return 40
default:
return 90
}
}
func (icon Icon) sortOrder() int {
return icon.Source.sortOrder() + icon.Type.sortOrder()
}
// SortAndCompactIcons sorts and compacts a list of icons. // SortAndCompactIcons sorts and compacts a list of icons.
func SortAndCompactIcons(icons []Icon) []Icon { func SortAndCompactIcons(icons []Icon) []Icon {
// Sort. // Sort.
slices.SortFunc[[]Icon, Icon](icons, func(a, b Icon) int { slices.SortFunc[[]Icon, Icon](icons, func(a, b Icon) int {
aOrder := a.Type.sortOrder() aOrder := a.sortOrder()
bOrder := b.Type.sortOrder() bOrder := b.sortOrder()
switch { switch {
case aOrder != bOrder: case aOrder != bOrder:
@ -68,7 +99,7 @@ func SortAndCompactIcons(icons []Icon) []Icon {
} }
// GetIconAsDataURL returns the icon data as a data URL. // GetIconAsDataURL returns the icon data as a data URL.
func (icon *Icon) GetIconAsDataURL() (bloburl string, err error) { func (icon Icon) GetIconAsDataURL() (bloburl string, err error) {
switch icon.Type { switch icon.Type {
case IconTypeFile: case IconTypeFile:
return "", errors.New("getting icon from file is not supported") return "", errors.New("getting icon from file is not supported")

View file

@ -92,8 +92,9 @@ func LoadAndSaveIcon(ctx context.Context, iconPath string) (*Icon, error) {
return nil, fmt.Errorf("failed to import icon %s: %w", iconPath, err) return nil, fmt.Errorf("failed to import icon %s: %w", iconPath, err)
} }
return &Icon{ return &Icon{
Type: IconTypeAPI, Type: IconTypeAPI,
Value: filename, Value: filename,
Source: IconSourceCore,
}, nil }, nil
} }

View file

@ -420,8 +420,9 @@ func ImportProfile(r *ProfileImportRequest, requiredProfileSource profile.Profil
return nil, fmt.Errorf("%w: icon is invalid: %w", ErrImportFailed, err) return nil, fmt.Errorf("%w: icon is invalid: %w", ErrImportFailed, err)
} }
p.Icons = []binmeta.Icon{{ p.Icons = []binmeta.Icon{{
Type: binmeta.IconTypeAPI, Type: binmeta.IconTypeAPI,
Value: filename, Value: filename,
Source: binmeta.IconSourceImport,
}} }}
} }