Skip to content
Snippets Groups Projects
Unverified Commit 933ad2ae authored by meskio's avatar meskio :tent: Committed by Kali Kaneko
Browse files

[feat] reload firewall with SIGUSR1

- Resolves: riseup_vpn#46
parent f274ec2b
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ type Bitmask interface {
Version() (string, error)
StartVPN(provider string) error
StopVPN() error
ReloadFirewall() error
GetStatus() (string, error)
InstallHelpers() error
VPNCheck() (helpers bool, priviledge bool, err error)
......
......@@ -32,6 +32,12 @@ func (b *Bitmask) StopVPN() error {
return err
}
// ReloadFirewall restarts the firewall
func (b *Bitmask) ReloadFirewall() error {
_, err := b.send("vpn", "fw_reload")
return err
}
// GetStatus returns the VPN status
func (b *Bitmask) GetStatus() (string, error) {
res, err := b.send("vpn", "status")
......
......@@ -85,6 +85,7 @@ func initialize(conf *systrayConfig, bt *bmTray) {
}
defer b.Close()
go checkAndStartBitmask(b, notify, conf)
go listenSignals(b)
as := newAutostart(applicationName, getIconPath())
err = as.Enable()
......
// +build !windows
// Copyright (C) 2018 LEAP
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"os"
"os/signal"
"syscall"
"0xacab.org/leap/bitmask-systray/bitmask"
)
func listenSignals(bm bitmask.Bitmask) {
sigusrCh := make(chan os.Signal, 1)
signal.Notify(sigusrCh, syscall.SIGUSR1)
for range sigusrCh {
bm.ReloadFirewall()
}
}
// +build windows
// Copyright (C) 2018 LEAP
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"0xacab.org/leap/bitmask-systray/bitmask"
)
func listenSignals(bm bitmask.Bitmask) {
}
......@@ -82,6 +82,28 @@ func (b *Bitmask) StopVPN() error {
return b.launch.openvpnStop()
}
// ReloadFirewall restarts the firewall
func (b *Bitmask) ReloadFirewall() error {
err := b.launch.firewallStop()
if err != nil {
return err
}
status, err := b.GetStatus()
if err != nil {
return err
}
if status != Off {
gateways, err := b.bonafide.getGateways()
if err != nil {
return err
}
return b.launch.firewallStart(gateways)
}
return nil
}
// GetStatus returns the VPN status
func (b *Bitmask) GetStatus() (string, error) {
status, err := b.getOpenvpnState()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment