2020-02-06 20:42:46 -05:00
|
|
|
package firewall
|
|
|
|
|
|
|
|
|
|
import (
|
2020-04-19 18:13:48 +00:00
|
|
|
"context"
|
2020-02-06 20:42:46 -05:00
|
|
|
"net"
|
|
|
|
|
|
|
|
|
|
"github.com/qdm12/golibs/command"
|
|
|
|
|
"github.com/qdm12/golibs/logging"
|
|
|
|
|
"github.com/qdm12/private-internet-access-docker/internal/models"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Configurator allows to change firewall rules and modify network routes
|
|
|
|
|
type Configurator interface {
|
2020-04-19 18:13:48 +00:00
|
|
|
Version(ctx context.Context) (string, error)
|
|
|
|
|
AcceptAll(ctx context.Context) error
|
|
|
|
|
Clear(ctx context.Context) error
|
|
|
|
|
BlockAll(ctx context.Context) error
|
|
|
|
|
CreateGeneralRules(ctx context.Context) error
|
|
|
|
|
CreateVPNRules(ctx context.Context, dev models.VPNDevice, defaultInterface string, connections []models.OpenVPNConnection) error
|
|
|
|
|
CreateLocalSubnetsRules(ctx context.Context, subnet net.IPNet, extraSubnets []net.IPNet, defaultInterface string) error
|
|
|
|
|
AllowInputTrafficOnPort(ctx context.Context, device models.VPNDevice, port uint16) error
|
|
|
|
|
AllowAnyIncomingOnPort(ctx context.Context, port uint16) error
|
2020-02-06 20:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type configurator struct {
|
2020-04-12 08:55:13 -04:00
|
|
|
commander command.Commander
|
|
|
|
|
logger logging.Logger
|
2020-02-06 20:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewConfigurator creates a new Configurator instance
|
2020-04-12 08:55:13 -04:00
|
|
|
func NewConfigurator(logger logging.Logger) Configurator {
|
2020-02-06 20:42:46 -05:00
|
|
|
return &configurator{
|
2020-04-12 08:55:13 -04:00
|
|
|
commander: command.NewCommander(),
|
2020-04-12 19:07:19 +00:00
|
|
|
logger: logger.WithPrefix("firewall configurator: "),
|
2020-02-06 20:42:46 -05:00
|
|
|
}
|
|
|
|
|
}
|