summaryrefslogtreecommitdiff
path: root/pkg/standalone
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2019-06-12 19:04:51 +0200
committerRuben Pollan <meskio@sindominio.net>2019-06-13 11:51:32 +0200
commit56d79a60679ba3783dcb5dd1ebe69436c5e5af7c (patch)
treecf391b54bff6a0bc54a8de958444fd968f60ed2b /pkg/standalone
parentbce7470262385baca771feee90e48e0c2e3616c6 (diff)
[feat] check if polkit is running and launch it if possible
- Resolves: #141
Diffstat (limited to 'pkg/standalone')
-rw-r--r--pkg/standalone/launcher.go4
-rw-r--r--pkg/standalone/launcher_linux.go78
-rw-r--r--pkg/standalone/vpn.go3
3 files changed, 83 insertions, 2 deletions
diff --git a/pkg/standalone/launcher.go b/pkg/standalone/launcher.go
index 4dc4761..16ea8b0 100644
--- a/pkg/standalone/launcher.go
+++ b/pkg/standalone/launcher.go
@@ -40,6 +40,10 @@ func (l *launcher) close() error {
return nil
}
+func (l *launcher) check() (helpers bool, priviledge bool, err error) {
+ return true, true, nil
+}
+
func (l *launcher) openvpnStart(flags ...string) error {
byteFlags, err := json.Marshal(flags)
if err != nil {
diff --git a/pkg/standalone/launcher_linux.go b/pkg/standalone/launcher_linux.go
index 1bbf4d1..e678de4 100644
--- a/pkg/standalone/launcher_linux.go
+++ b/pkg/standalone/launcher_linux.go
@@ -21,8 +21,10 @@ import (
"log"
"os"
"os/exec"
+ "strings"
"0xacab.org/leap/bitmask-vpn/pkg/config"
+ "github.com/mitchellh/go-ps"
)
const (
@@ -50,6 +52,82 @@ func (l *launcher) close() error {
return nil
}
+func (l *launcher) check() (helpers bool, priviledge bool, err error) {
+
+ isRunning, err := isPolkitRunning()
+ if err != nil {
+ return
+ }
+ if !isRunning {
+ polkitPath := getPolkitPath()
+ if polkitPath == "" {
+ return true, false, nil
+ }
+ cmd := exec.Command("setsid", polkitPath)
+ err = cmd.Start()
+ if err != nil {
+ return
+ }
+ isRunning, err = isPolkitRunning()
+ return true, isRunning, err
+ }
+
+ return true, true, nil
+}
+
+func isPolkitRunning() (bool, error) {
+ var polkitProcNames = [...]string{
+ "polkit-gnome-authentication-agent-1",
+ "polkit-kde-authentication-agent-1",
+ "polkit-mate-authentication-agent-1",
+ "lxpolkit",
+ "lxsession",
+ "gnome-shell",
+ "gnome-flashback",
+ "fingerprint-polkit-agent",
+ "xfce-polkit",
+ }
+
+ processes, err := ps.Processes()
+ if err != nil {
+ return false, err
+ }
+
+ for _, proc := range processes {
+ executable := proc.Executable()
+ for _, name := range polkitProcNames {
+ if strings.Contains(executable, name) {
+ return true, nil
+ }
+ }
+ }
+ return false, nil
+}
+
+func getPolkitPath() string {
+ var polkitPaths = [...]string{
+ "/usr/bin/lxpolkit",
+ "/usr/bin/lxqt-policykit-agent",
+ "/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1",
+ "/usr/lib/x86_64-linux-gnu/polkit-mate/polkit-mate-authentication-agent-1",
+ "/usr/lib/mate-polkit/polkit-mate-authentication-agent-1",
+ "/usr/lib/x86_64-linux-gnu/libexec/polkit-kde-authentication-agent-1",
+ "/usr/lib/kde4/libexec/polkit-kde-authentication-agent-1",
+ // now we get weird
+ "/usr/libexec/policykit-1-pantheon/pantheon-agent-polkit",
+ "/usr/lib/polkit-1-dde/dde-polkit-agent",
+ // do you know some we"re still missing? :)
+ }
+
+ for _, polkit := range polkitPaths {
+ _, err := os.Stat(polkit)
+ if err == nil {
+ return polkit
+ }
+ }
+ return ""
+}
+
func (l *launcher) openvpnStart(flags ...string) error {
log.Println("openvpn start: ", flags)
arg := []string{"openvpn", "start", getOpenvpnPath()}
diff --git a/pkg/standalone/vpn.go b/pkg/standalone/vpn.go
index 941d444..b858ee0 100644
--- a/pkg/standalone/vpn.go
+++ b/pkg/standalone/vpn.go
@@ -124,8 +124,7 @@ func (b *Bitmask) InstallHelpers() error {
// VPNCheck returns if the helpers are installed and up to date and if polkit is running
func (b *Bitmask) VPNCheck() (helpers bool, priviledge bool, err error) {
- // TODO
- return true, true, nil
+ return b.launch.check()
}
// ListGateways return the names of the gateways