mirror of
https://github.com/safing/portmaster
synced 2025-09-01 10:09:11 +00:00
Implement review feedback
This commit is contained in:
parent
ed00e1fe83
commit
fa3f873c31
7 changed files with 64 additions and 28 deletions
|
@ -78,7 +78,7 @@ func notifyDisableDNSCache() {
|
|||
|
||||
func notifyRebootRequired() {
|
||||
(¬ifications.Notification{
|
||||
EventID: "interception:©windows-dnscache-reboot-required",
|
||||
EventID: "interception:windows-dnscache-reboot-required",
|
||||
Message: "Please restart your system to complete Portmaster integration.",
|
||||
Type: notifications.Warning,
|
||||
}).Save()
|
||||
|
|
|
@ -38,7 +38,9 @@ import (
|
|||
|
||||
const noReasonOptionKey = ""
|
||||
|
||||
var deciders = []func(context.Context, *network.Connection, packet.Packet) bool{
|
||||
type deciderFn func(context.Context, *network.Connection, packet.Packet) bool
|
||||
|
||||
var deciders = []deciderFn{
|
||||
checkPortmasterConnection,
|
||||
checkSelfCommunication,
|
||||
checkConnectionType,
|
||||
|
@ -152,7 +154,7 @@ func checkSelfCommunication(ctx context.Context, conn *network.Connection, pkt p
|
|||
if err != nil {
|
||||
log.Tracer(ctx).Warningf("filter: failed to find load local peer process with PID %d: %s", otherPid, err)
|
||||
} else if otherProcess.Pid == conn.Process().Pid {
|
||||
conn.Accept("connection to self", noReasonOptionKey)
|
||||
conn.Accept("process internal connection", noReasonOptionKey)
|
||||
conn.Internal = true
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -227,11 +227,8 @@ func setCaptivePortal(portalURL *url.URL) {
|
|||
|
||||
// notify
|
||||
cleanUpPortalNotification()
|
||||
// TODO: add "open" button
|
||||
captivePortalNotification = notifications.Notify(¬ifications.Notification{
|
||||
EventID: fmt.Sprintf(
|
||||
"netenv:captive-portal:%s", captivePortal.Domain,
|
||||
),
|
||||
EventID: "netenv:captive-portal",
|
||||
Type: notifications.Info,
|
||||
Title: "Captive Portal",
|
||||
Category: "Core",
|
||||
|
@ -239,6 +236,7 @@ func setCaptivePortal(portalURL *url.URL) {
|
|||
"Portmaster detected a captive portal at %s",
|
||||
captivePortal.Domain,
|
||||
),
|
||||
EventData: captivePortal,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -122,11 +122,12 @@ func CleanProcessStorage(activePIDs map[int]struct{}) {
|
|||
}
|
||||
|
||||
// Process is inactive, start deletion process
|
||||
lastSeen := p.GetLastSeen()
|
||||
switch {
|
||||
case p.LastSeen == 0:
|
||||
// add last
|
||||
p.LastSeen = time.Now().Unix()
|
||||
case p.LastSeen > threshold:
|
||||
case lastSeen == 0:
|
||||
// add last seen timestamp
|
||||
p.SetLastSeen(time.Now().Unix())
|
||||
case lastSeen > threshold:
|
||||
// within keep period
|
||||
default:
|
||||
// delete now
|
||||
|
|
|
@ -59,9 +59,29 @@ type Process struct {
|
|||
|
||||
// Profile returns the assigned layered profile.
|
||||
func (p *Process) Profile() *profile.LayeredProfile {
|
||||
if p == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return p.profile
|
||||
}
|
||||
|
||||
// GetLastSeen returns the unix timestamp when the process was last seen.
|
||||
func (p *Process) GetLastSeen() int64 {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
return p.LastSeen
|
||||
}
|
||||
|
||||
// SetLastSeen sets the unix timestamp when the process was last seen.
|
||||
func (p *Process) SetLastSeen(lastSeen int64) {
|
||||
p.Lock()
|
||||
defer p.Unlock()
|
||||
|
||||
p.LastSeen = lastSeen
|
||||
}
|
||||
|
||||
// Strings returns a string representation of process.
|
||||
func (p *Process) String() string {
|
||||
if p == nil {
|
||||
|
|
|
@ -97,7 +97,8 @@ func GetProfile(source profileSource, id, linkedPath string) (
|
|||
// Process profiles coming directly from the database.
|
||||
// As we don't use any caching, these will be new objects.
|
||||
|
||||
// Mark the profile as being saved internally in order to bypass checks.
|
||||
// Mark the profile as being saved internally in order to not trigger an
|
||||
// update after saving it to the database.
|
||||
profile.internalSave = true
|
||||
|
||||
// Add a layeredProfile to local profiles.
|
||||
|
|
|
@ -63,7 +63,6 @@ func NewLayeredProfile(localProfile *Profile) *LayeredProfile {
|
|||
localProfile: localProfile,
|
||||
layers: make([]*Profile, 0, len(localProfile.LinkedProfiles)+1),
|
||||
LayerIDs: make([]string, 0, len(localProfile.LinkedProfiles)+1),
|
||||
RevisionCounter: 0,
|
||||
validityFlag: abool.NewBool(true),
|
||||
globalValidityFlag: config.NewValidityFlag(),
|
||||
securityLevel: &securityLevelVal,
|
||||
|
@ -361,21 +360,26 @@ func (lp *LayeredProfile) wrapSecurityLevelOption(configKey string, globalConfig
|
|||
}
|
||||
|
||||
func (lp *LayeredProfile) wrapBoolOption(configKey string, globalConfig config.BoolOption) config.BoolOption {
|
||||
valid := no
|
||||
revCnt := lp.RevisionCounter
|
||||
var value bool
|
||||
var refreshLock sync.Mutex
|
||||
|
||||
return func() bool {
|
||||
if !valid.IsSet() {
|
||||
valid = lp.getValidityFlag()
|
||||
refreshLock.Lock()
|
||||
defer refreshLock.Unlock()
|
||||
|
||||
// Check if we need to refresh the value.
|
||||
if revCnt != lp.RevisionCounter {
|
||||
revCnt = lp.RevisionCounter
|
||||
|
||||
// Go through all layers to find an active value.
|
||||
found := false
|
||||
layerLoop:
|
||||
for _, layer := range lp.layers {
|
||||
layerValue, ok := layer.configPerspective.GetAsBool(configKey)
|
||||
if ok {
|
||||
found = true
|
||||
value = layerValue
|
||||
break layerLoop
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
|
@ -388,21 +392,26 @@ func (lp *LayeredProfile) wrapBoolOption(configKey string, globalConfig config.B
|
|||
}
|
||||
|
||||
func (lp *LayeredProfile) wrapIntOption(configKey string, globalConfig config.IntOption) config.IntOption {
|
||||
valid := no
|
||||
revCnt := lp.RevisionCounter
|
||||
var value int64
|
||||
var refreshLock sync.Mutex
|
||||
|
||||
return func() int64 {
|
||||
if !valid.IsSet() {
|
||||
valid = lp.getValidityFlag()
|
||||
refreshLock.Lock()
|
||||
defer refreshLock.Unlock()
|
||||
|
||||
// Check if we need to refresh the value.
|
||||
if revCnt != lp.RevisionCounter {
|
||||
revCnt = lp.RevisionCounter
|
||||
|
||||
// Go through all layers to find an active value.
|
||||
found := false
|
||||
layerLoop:
|
||||
for _, layer := range lp.layers {
|
||||
layerValue, ok := layer.configPerspective.GetAsInt(configKey)
|
||||
if ok {
|
||||
found = true
|
||||
value = layerValue
|
||||
break layerLoop
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
|
@ -432,21 +441,26 @@ func (lp *LayeredProfile) GetProfileSource(configKey string) string {
|
|||
For later:
|
||||
|
||||
func (lp *LayeredProfile) wrapStringOption(configKey string, globalConfig config.StringOption) config.StringOption {
|
||||
valid := no
|
||||
revCnt := lp.RevisionCounter
|
||||
var value string
|
||||
var refreshLock sync.Mutex
|
||||
|
||||
return func() string {
|
||||
if !valid.IsSet() {
|
||||
valid = lp.getValidityFlag()
|
||||
refreshLock.Lock()
|
||||
defer refreshLock.Unlock()
|
||||
|
||||
// Check if we need to refresh the value.
|
||||
if revCnt != lp.RevisionCounter {
|
||||
revCnt = lp.RevisionCounter
|
||||
|
||||
// Go through all layers to find an active value.
|
||||
found := false
|
||||
layerLoop:
|
||||
for _, layer := range lp.layers {
|
||||
layerValue, ok := layer.configPerspective.GetAsString(configKey)
|
||||
if ok {
|
||||
found = true
|
||||
value = layerValue
|
||||
break layerLoop
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
|
|
Loading…
Add table
Reference in a new issue