From bea32af5d45702e5608d347bf2bf6314d899f2e0 Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Sat, 12 Jan 2019 18:18:23 +0100 Subject: [feat] Reorganize code Let's use a more structured folder system: https://github.com/golang-standards/project-layout - Resolves: #99 --- .gitignore | 5 +- Makefile | 30 +-- autostart.go | 16 -- bitmask/bitmask.go | 30 --- bitmask/darwin.go | 23 -- bitmask/unix.go | 23 -- bitmask/windows.go | 21 -- bitmaskd.go | 42 ---- bitmaskd/events.go | 50 ---- bitmaskd/main.go | 163 ------------ bitmaskd/vpn.go | 98 -------- catalog.go | 370 ---------------------------- cmd/bitmask-vpn/catalog.go | 369 +++++++++++++++++++++++++++ cmd/bitmask-vpn/main.go | 76 ++++++ config.go | 90 ------- locales/bn/messages.gotext.json | 66 +++-- locales/en-GB/messages.gotext.json | 66 +++-- locales/en-US/messages.gotext.json | 70 +++--- locales/es-ES/messages.gotext.json | 66 +++-- locales/es/messages.gotext.json | 66 +++-- locales/fr/messages.gotext.json | 66 +++-- locales/lt/messages.gotext.json | 66 +++-- locales/nl/messages.gotext.json | 66 +++-- locales/pt-BR/messages.gotext.json | 66 +++-- main.go | 156 ------------ notificator.go | 164 ------------ pid.go | 99 -------- pid_test.go | 21 -- pkg/bitmask/autostart.go | 32 +++ pkg/bitmask/bitmask.go | 30 +++ pkg/bitmask/bitmaskd.go | 44 ++++ pkg/bitmask/standalone.go | 74 ++++++ pkg/bitmaskd/events.go | 50 ++++ pkg/bitmaskd/main.go | 163 ++++++++++++ pkg/bitmaskd/vpn.go | 98 ++++++++ pkg/config/darwin.go | 24 ++ pkg/config/logger.go | 31 +++ pkg/config/unix.go | 24 ++ pkg/config/windows.go | 22 ++ pkg/standalone/bonafide.go | 311 +++++++++++++++++++++++ pkg/standalone/bonafide_integration_test.go | 58 +++++ pkg/standalone/bonafide_test.go | 100 ++++++++ pkg/standalone/launcher.go | 97 ++++++++ pkg/standalone/launcher_linux.go | 139 +++++++++++ pkg/standalone/main.go | 80 ++++++ pkg/standalone/status.go | 91 +++++++ pkg/standalone/testdata/cert | 54 ++++ pkg/standalone/testdata/eip-service.json | 113 +++++++++ pkg/standalone/vpn.go | 156 ++++++++++++ pkg/systray/config.go | 97 ++++++++ pkg/systray/notificator.go | 164 ++++++++++++ pkg/systray/pid.go | 99 ++++++++ pkg/systray/pid_test.go | 21 ++ pkg/systray/run.go | 103 ++++++++ pkg/systray/signal_unix.go | 34 +++ pkg/systray/signal_windows.go | 24 ++ pkg/systray/systray.go | 257 +++++++++++++++++++ signal_unix.go | 34 --- signal_windows.go | 24 -- standalone.go | 72 ------ standalone/bonafide.go | 311 ----------------------- standalone/bonafide_integration_test.go | 58 ----- standalone/bonafide_test.go | 100 -------- standalone/launcher.go | 97 -------- standalone/launcher_linux.go | 139 ----------- standalone/main.go | 80 ------ standalone/status.go | 91 ------- standalone/testdata/cert | 54 ---- standalone/testdata/eip-service.json | 113 --------- standalone/vpn.go | 156 ------------ systray.go | 255 ------------------- tools/transifex/Makefile | 8 + tools/transifex/main.go | 124 ++++++++++ tools/transifex/messages.json | 28 +++ transifex/Makefile | 8 - transifex/main.go | 124 ---------- transifex/messages.json | 28 --- 77 files changed, 3477 insertions(+), 3461 deletions(-) delete mode 100644 autostart.go delete mode 100644 bitmask/bitmask.go delete mode 100644 bitmask/darwin.go delete mode 100644 bitmask/unix.go delete mode 100644 bitmask/windows.go delete mode 100644 bitmaskd.go delete mode 100644 bitmaskd/events.go delete mode 100644 bitmaskd/main.go delete mode 100644 bitmaskd/vpn.go delete mode 100644 catalog.go create mode 100644 cmd/bitmask-vpn/catalog.go create mode 100644 cmd/bitmask-vpn/main.go delete mode 100644 config.go delete mode 100644 main.go delete mode 100644 notificator.go delete mode 100644 pid.go delete mode 100644 pid_test.go create mode 100644 pkg/bitmask/autostart.go create mode 100644 pkg/bitmask/bitmask.go create mode 100644 pkg/bitmask/bitmaskd.go create mode 100644 pkg/bitmask/standalone.go create mode 100644 pkg/bitmaskd/events.go create mode 100644 pkg/bitmaskd/main.go create mode 100644 pkg/bitmaskd/vpn.go create mode 100644 pkg/config/darwin.go create mode 100644 pkg/config/logger.go create mode 100644 pkg/config/unix.go create mode 100644 pkg/config/windows.go create mode 100644 pkg/standalone/bonafide.go create mode 100644 pkg/standalone/bonafide_integration_test.go create mode 100644 pkg/standalone/bonafide_test.go create mode 100644 pkg/standalone/launcher.go create mode 100644 pkg/standalone/launcher_linux.go create mode 100644 pkg/standalone/main.go create mode 100644 pkg/standalone/status.go create mode 100644 pkg/standalone/testdata/cert create mode 100644 pkg/standalone/testdata/eip-service.json create mode 100644 pkg/standalone/vpn.go create mode 100644 pkg/systray/config.go create mode 100644 pkg/systray/notificator.go create mode 100644 pkg/systray/pid.go create mode 100644 pkg/systray/pid_test.go create mode 100644 pkg/systray/run.go create mode 100644 pkg/systray/signal_unix.go create mode 100644 pkg/systray/signal_windows.go create mode 100644 pkg/systray/systray.go delete mode 100644 signal_unix.go delete mode 100644 signal_windows.go delete mode 100644 standalone.go delete mode 100644 standalone/bonafide.go delete mode 100644 standalone/bonafide_integration_test.go delete mode 100644 standalone/bonafide_test.go delete mode 100644 standalone/launcher.go delete mode 100644 standalone/launcher_linux.go delete mode 100644 standalone/main.go delete mode 100644 standalone/status.go delete mode 100644 standalone/testdata/cert delete mode 100644 standalone/testdata/eip-service.json delete mode 100644 standalone/vpn.go delete mode 100644 systray.go create mode 100644 tools/transifex/Makefile create mode 100644 tools/transifex/main.go create mode 100644 tools/transifex/messages.json delete mode 100644 transifex/Makefile delete mode 100644 transifex/main.go delete mode 100644 transifex/messages.json diff --git a/.gitignore b/.gitignore index e6c1776..42a41b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -bitmask-systray +/bitmask-vpn +cmd/bitmask-vpn/bitmask-vpn locales/*/out.gotext.json .*.swp *.exe -transifex/transifex +tools/transifex/transifex diff --git a/Makefile b/Makefile index 5d3847b..f03f5eb 100644 --- a/Makefile +++ b/Makefile @@ -8,27 +8,29 @@ get: go get -tags $(TAGS) ./... go get -tags "$(TAGS) bitmaskd" ./... -build: - go build -tags $(TAGS) -ldflags "-X main.version=`git describe --tags`" +build: $(foreach path,$(wildcard cmd/*),build_$(patsubst cmd/%,%,$(path))) + +build_%: + go build -tags $(TAGS) -ldflags "-X main.version=`git describe --tags`" -o $* ./cmd/$* test: go test -tags "integration $(TAGS)" ./... build_bitmaskd: - go build -tags "$(TAGS) bitmaskd" -ldflags "-X main.version=`git describe --tags`" + go build -tags "$(TAGS) bitmaskd" -ldflags "-X main.version=`git describe --tags`" ./cmd/* build_win: - powershell -Command '$$version=git describe --tags; go build -ldflags "-H windowsgui -X main.version=$$version"' + powershell -Command '$$version=git describe --tags; go build -ldflags "-H windowsgui -X main.version=$$version" ./cmd/*' clean: make -C icon clean - rm bitmask-systray + rm bitmask-vpn icon: make -C icon get_deps: - sudo apt install libgtk-3-dev libappindicator3-dev golang pkg-config + sudo apt install libgtk-3-dev libappindicator3-dev golang pkg-config LANGS ?= $(foreach path,$(wildcard locales/*),$(patsubst locales/%,%,$(path))) @@ -36,17 +38,17 @@ empty := space := $(empty) $(empty) lang_list := $(subst $(space),,$(foreach lang,$(LANGS),$(lang),)) -locales: $(foreach lang,$(LANGS),get_$(lang)) catalog.go +locales: $(foreach lang,$(LANGS),get_$(lang)) cmd/bitmask-vpn/catalog.go generate_locales: $(foreach lang,$(LANGS),locales/$(lang)/out.gotext.json) - make -C transifex + make -C tools/transifex -locales/%/out.gotext.json: systray.go notificator.go - gotext update -lang=$* +locales/%/out.gotext.json: pkg/systray/systray.go pkg/systray/notificator.go pkg/bitmask/standalone.go pkg/bitmask/bitmaskd.go + gotext update -lang=$* ./pkg/systray ./pkg/bitmask -catalog.go: $(foreach lang,$(LANGS),locales/$(lang)/messages.gotext.json) - gotext update -lang=$(lang_list) -out catalog.go +cmd/bitmask-vpn/catalog.go: $(foreach lang,$(LANGS),locales/$(lang)/messages.gotext.json) + gotext update -lang=$(lang_list) -out cmd/bitmask-vpn/catalog.go ./pkg/systray ./pkg/bitmask get_%: - make -C transifex build - curl -L -X GET --user "api:${API_TOKEN}" "https://www.transifex.com/api/2/project/bitmask/resource/RiseupVPN/translation/${subst -,_,$*}/?file" | transifex/transifex t2g locales/$*/ + make -C tools/transifex build + curl -L -X GET --user "api:${API_TOKEN}" "https://www.transifex.com/api/2/project/bitmask/resource/RiseupVPN/translation/${subst -,_,$*}/?file" | tools/transifex/transifex t2g locales/$*/ diff --git a/autostart.go b/autostart.go deleted file mode 100644 index 62f30cc..0000000 --- a/autostart.go +++ /dev/null @@ -1,16 +0,0 @@ -package main - -type autostart interface { - Disable() error - Enable() error -} - -type dummyAutostart struct{} - -func (a *dummyAutostart) Disable() error { - return nil -} - -func (a *dummyAutostart) Enable() error { - return nil -} diff --git a/bitmask/bitmask.go b/bitmask/bitmask.go deleted file mode 100644 index a7aabaa..0000000 --- a/bitmask/bitmask.go +++ /dev/null @@ -1,30 +0,0 @@ -// 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 . - -package bitmask - -type Bitmask interface { - GetStatusCh() <-chan string - Close() - Version() (string, error) - StartVPN(provider string) error - StopVPN() error - ReloadFirewall() error - GetStatus() (string, error) - InstallHelpers() error - VPNCheck() (helpers bool, priviledge bool, err error) - ListGateways(provider string) ([]string, error) - UseGateway(name string) error -} diff --git a/bitmask/darwin.go b/bitmask/darwin.go deleted file mode 100644 index b71271e..0000000 --- a/bitmask/darwin.go +++ /dev/null @@ -1,23 +0,0 @@ -// +build darwin -// 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 . - -package bitmask - -import ( - "os" -) - -var ConfigPath = os.Getenv("HOME") + "/Library/Preferences/leap" diff --git a/bitmask/unix.go b/bitmask/unix.go deleted file mode 100644 index d276556..0000000 --- a/bitmask/unix.go +++ /dev/null @@ -1,23 +0,0 @@ -// +build !windows,!darwin -// 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 . - -package bitmask - -import ( - "os" -) - -var ConfigPath = os.Getenv("HOME") + "/.config/leap" diff --git a/bitmask/windows.go b/bitmask/windows.go deleted file mode 100644 index 221d75b..0000000 --- a/bitmask/windows.go +++ /dev/null @@ -1,21 +0,0 @@ -// +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 . - -package bitmask - -import "os" - -var ConfigPath = os.Getenv("LOCALAPPDATA") + "\\leap" diff --git a/bitmaskd.go b/bitmaskd.go deleted file mode 100644 index ace9ee7..0000000 --- a/bitmaskd.go +++ /dev/null @@ -1,42 +0,0 @@ -// +build bitmaskd -// 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 . - -package main - -import ( - "errors" - "log" - - "0xacab.org/leap/bitmask-systray/bitmask" - bitmaskd "0xacab.org/leap/bitmask-systray/bitmaskd" -) - -const ( - notRunning = `Is bitmaskd running? Start bitmask and try again.` -) - -func initBitmask() (bitmask.Bitmask, error) { - b, err := bitmaskd.Init() - if err != nil { - log.Printf("An error ocurred starting bitmaskd: %v", err) - err = errors.New(printer.Sprintf(notRunning)) - } - return b, err -} - -func newAutostart(appName string, iconPath string) autostart { - return &dummyAutostart{} -} diff --git a/bitmaskd/events.go b/bitmaskd/events.go deleted file mode 100644 index e97804c..0000000 --- a/bitmaskd/events.go +++ /dev/null @@ -1,50 +0,0 @@ -// 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 . - -package bitmask - -import ( - "log" - "net/http" -) - -const ( - statusEvent = "VPN_STATUS_CHANGED" -) - -func (b *Bitmask) eventsHandler() { - b.send("events", "register", statusEvent) - client := &http.Client{ - Timeout: 0, - } - for { - resJSON, err := send(b.apiToken, client, "events", "poll") - res, ok := resJSON.([]interface{}) - if err != nil || !ok || len(res) < 1 { - continue - } - event, ok := res[0].(string) - if !ok || event != statusEvent { - continue - } - - status, err := b.GetStatus() - if err != nil { - log.Printf("Error receiving status: %v", err) - continue - } - b.statusCh <- status - } -} diff --git a/bitmaskd/main.go b/bitmaskd/main.go deleted file mode 100644 index 2ff2268..0000000 --- a/bitmaskd/main.go +++ /dev/null @@ -1,163 +0,0 @@ -// 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 . - -package bitmask - -import ( - "bytes" - "encoding/json" - "errors" - "io/ioutil" - "log" - "net/http" - "path" - "time" - - "0xacab.org/leap/bitmask-systray/bitmask" -) - -const ( - timeout = time.Second * 15 - url = "http://localhost:7070/API/" - headerAuth = "X-Bitmask-Auth" -) - -// Bitmask holds the bitmask client data -type Bitmask struct { - client *http.Client - apiToken string - statusCh chan string -} - -// Init the connection to bitmask -func Init() (*Bitmask, error) { - statusCh := make(chan string) - client := &http.Client{ - Timeout: timeout, - } - - err := waitForBitmaskd() - if err != nil { - return nil, err - } - - apiToken, err := getToken() - if err != nil { - return nil, err - } - - b := Bitmask{client, apiToken, statusCh} - go b.eventsHandler() - return &b, nil -} - -// GetStatusCh returns a channel that will recieve VPN status changes -func (b *Bitmask) GetStatusCh() <-chan string { - return b.statusCh -} - -// Close the connection to bitmask -func (b *Bitmask) Close() { - _, err := b.send("core", "stop") - if err != nil { - log.Printf("Got an error stopping bitmaskd: %v", err) - } -} - -// Version gets the bitmask version string -func (b *Bitmask) Version() (string, error) { - res, err := b.send("core", "version") - if err != nil { - return "", err - } - return res["version_core"].(string), nil -} - -func waitForBitmaskd() error { - var err error - for i := 0; i < 30; i++ { - resp, err := http.Post(url, "", nil) - if err == nil { - resp.Body.Close() - return nil - } - log.Printf("Bitmask is not ready (iteration %d): %v", i, err) - time.Sleep(1 * time.Second) - } - return err -} - -func (b *Bitmask) send(parts ...interface{}) (map[string]interface{}, error) { - resJSON, err := send(b.apiToken, b.client, parts...) - if err != nil { - return nil, err - } - result, ok := resJSON.(map[string]interface{}) - if !ok { - return nil, errors.New("Not valid response") - } - return result, nil -} - -func send(apiToken string, client *http.Client, parts ...interface{}) (interface{}, error) { - apiSection, _ := parts[0].(string) - reqBody, err := json.Marshal(parts[1:]) - if err != nil { - return nil, err - } - req, err := http.NewRequest("POST", url+apiSection, bytes.NewReader(reqBody)) - if err != nil { - return nil, err - } - req.Header.Add(headerAuth, apiToken) - - resp, err := client.Do(req) - if err != nil { - return nil, err - } - defer resp.Body.Close() - - resJSON, err := ioutil.ReadAll(resp.Body) - if err != nil { - return nil, err - } - return parseResponse(resJSON) -} - -func parseResponse(resJSON []byte) (interface{}, error) { - var response struct { - Result interface{} - Error string - } - err := json.Unmarshal(resJSON, &response) - if response.Error != "" { - return nil, errors.New(response.Error) - } - return response.Result, err -} - -func getToken() (string, error) { - var err error - path := path.Join(bitmask.ConfigPath, "authtoken") - for i := 0; i < 30; i++ { - b, err := ioutil.ReadFile(path) - if err == nil { - return string(b), nil - } - log.Printf("Auth token is not ready (iteration %d): %v", i, err) - time.Sleep(1 * time.Second) - } - return "", err -} diff --git a/bitmaskd/vpn.go b/bitmaskd/vpn.go deleted file mode 100644 index cfbe7df..0000000 --- a/bitmaskd/vpn.go +++ /dev/null @@ -1,98 +0,0 @@ -// 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 . - -package bitmask - -import ( - "errors" - "log" -) - -// StartVPN for provider -func (b *Bitmask) StartVPN(provider string) error { - _, err := b.send("vpn", "start", provider) - return err -} - -// StopVPN or cancel -func (b *Bitmask) StopVPN() error { - _, err := b.send("vpn", "stop") - 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") - if err != nil { - return "", err - } - return res["status"].(string), nil -} - -// InstallHelpers into the system -func (b *Bitmask) InstallHelpers() error { - _, err := b.send("vpn", "install") - return err -} - -// 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) { - res, err := b.send("vpn", "check", "") - if err != nil { - return false, false, err - } - installed, ok := res["installed"].(bool) - if !ok { - log.Printf("Unexpected value for installed on 'vpn check': %v", res) - return false, false, errors.New("Invalid response format") - } - privcheck, ok := res["privcheck"].(bool) - if !ok { - log.Printf("Unexpected value for privcheck on 'vpn check': %v", res) - return installed, false, errors.New("Invalid response format") - } - return installed, privcheck, nil -} - -// ListGateways return the names of the gateways -func (b *Bitmask) ListGateways(provider string) ([]string, error) { - res, err := b.send("vpn", "list") - if err != nil { - return nil, err - } - - names := []string{} - locations, ok := res[provider].([]interface{}) - if !ok { - return nil, errors.New("Can't read the locations for provider " + provider) - } - for i := range locations { - loc := locations[i].(map[string]interface{}) - names = append(names, loc["name"].(string)) - } - return names, nil -} - -// UseGateway selects name as the default gateway -func (b *Bitmask) UseGateway(name string) error { - _, err := b.send("vpn", "locations", name) - return err -} diff --git a/catalog.go b/catalog.go deleted file mode 100644 index a9f00b6..0000000 --- a/catalog.go +++ /dev/null @@ -1,370 +0,0 @@ -// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. - -package main - -import ( - "golang.org/x/text/language" - "golang.org/x/text/message" - "golang.org/x/text/message/catalog" -) - -type dictionary struct { - index []uint32 - data string -} - -func (d *dictionary) Lookup(key string) (data string, ok bool) { - p := messageKeyToIndex[key] - start, end := d.index[p], d.index[p+1] - if start == end { - return "", false - } - return d.data[start:end], true -} - -func init() { - dict := map[string]catalog.Dictionary{ - "bn": &dictionary{index: bnIndex, data: bnData}, - "en_GB": &dictionary{index: en_GBIndex, data: en_GBData}, - "en_US": &dictionary{index: en_USIndex, data: en_USData}, - "es": &dictionary{index: esIndex, data: esData}, - "es_ES": &dictionary{index: es_ESIndex, data: es_ESData}, - "fr": &dictionary{index: frIndex, data: frData}, - "lt": &dictionary{index: ltIndex, data: ltData}, - "nl": &dictionary{index: nlIndex, data: nlData}, - "pt_BR": &dictionary{index: pt_BRIndex, data: pt_BRData}, - } - fallback := language.MustParse("en-US") - cat, err := catalog.NewFromMap(dict, catalog.Fallback(fallback)) - if err != nil { - panic(err) - } - message.DefaultCatalog = cat -} - -var messageKeyToIndex = map[string]int{ - "%[1]s is an easy, fast, and secure VPN service from riseup.net. %[1]s does not require a user account, keep logs, or track you in any way.\n\t \nThis service is paid for entirely by donations from users like you. Please donate at https://riseup.net/vpn/donate.\n\t\t\nBy using this application, you agree to the Terms of Service available at https://riseup.net/tos. This service is provide as-is, without any warranty, and is intended for people who work to make the world a better place.\n\n\n%[1]v version: %[2]s": 2, - "%s blocking internet": 25, - "%s off": 20, - "%s on": 19, - "About": 3, - "About...": 15, - "An error has ocurred initializing %s: %v": 9, - "Can't connect to %s: %v": 7, - "Cancel": 21, - "Checking status...": 10, - "Connecting to %s": 22, - "Could not find a polkit authentication agent. Please run one and try again.": 5, - "Donate": 1, - "Donate...": 14, - "Error starting VPN": 8, - "Help...": 13, - "Initialization error": 4, - "Missing authentication agent": 6, - "Quit": 16, - "Retry": 24, - "Route traffic through": 17, - "Stopping %s": 23, - "The %s service is expensive to run. Because we don't want to store personal information about you, there is no accounts or billing for this service. But if you want the service to continue, donate at least $5 each month.\n\t\nDo you want to donate now?": 0, - "Turn off": 12, - "Turn on": 11, - "Use %s %v gateway": 18, -} - -var bnIndex = []uint32{ // 27 elements - 0x00000000, 0x000000fd, 0x00000110, 0x0000030c, - 0x00000325, 0x00000348, 0x00000394, 0x000003e2, - 0x00000400, 0x00000450, 0x0000047f, 0x000004c6, - 0x000004da, 0x000004ee, 0x00000507, 0x0000051d, - 0x00000539, 0x00000546, 0x00000586, 0x0000059e, - 0x000005b1, 0x000005c4, 0x000005d4, 0x00000614, - 0x00000637, 0x0000066a, 0x000006b2, -} // Size: 132 bytes - -const bnData string = "" + // Size: 1714 bytes - "\x02The %[1]s service is expensive to run. Because we don't want to stor" + - "e personal information about you, there is no accounts or billing for th" + - "is service. But if you want the service to continue, donate at least $5 " + - "each month.\x0a\x09\x0aDo you want to donate now?\x02অনুদান\x02%[1]s is " + - "an easy, fast, and secure VPN service from riseup.net. %[1]s does not re" + - "quire a user account, keep logs, or track you in any way.\x0a\x09 " + - "\x0aThis service is paid for entirely by donations from users like you. " + - "Please donate at https://riseup.net/vpn/donate.\x0a\x09\x09\x0aBy using " + - "this application, you agree to the Terms of Service available at https:/" + - "/riseup.net/tos. This service is provide as-is, without any warranty, an" + - "d is intended for people who work to make the world a better place.\x0a" + - "\x0a\x0a%[1]v version: %[2]s\x02সম্পর্কে\x02সূচনা ত্রুটি\x02Could not fi" + - "nd a polkit authentication agent. Please run one and try again.\x02প্রমা" + - "ণীকরণ এজেন্ট অনুপস্থিত\x02Can't connect to %[1]s: %[2]v\x02ভিপিএন চালু" + - " করতে ত্রুটি হয়েছে\x02An error has ocurred initializing %[1]s: %[2]v\x02" + - "অবস্থা পরিক্ষা করা হচ্ছে ...\x02চালু কর\x02বন্ধ কর\x02সাহায্য...\x02অন" + - "ুদান...\x02সম্পর্কে...\x02বন্ধ\x02ট্রাফিক এর মাধ্যমে যাবে\x02Use %[1]s" + - " %[2]v gateway\x02%[1]s চালু\x02%[1]s বন্ধ\x02বাতিল\x02%[1]s এর সাথে সংয" + - "ুক্ত হচ্ছে\x02%[1]s বন্ধ হচ্ছে\x02পূনরায় চেষ্টা করুন\x02%[1]s ইন্টারনে" + - "ট প্রতিরোধ করছে" - -var en_GBIndex = []uint32{ // 27 elements - 0x00000000, 0x000000ff, 0x00000106, 0x00000302, - 0x00000308, 0x0000031d, 0x00000369, 0x00000386, - 0x000003a4, 0x000003b7, 0x000003e7, 0x000003fa, - 0x00000402, 0x0000040b, 0x00000413, 0x0000041d, - 0x00000426, 0x0000042b, 0x00000441, 0x00000459, - 0x00000462, 0x0000046c, 0x00000473, 0x00000487, - 0x00000496, 0x0000049c, 0x000004b4, -} // Size: 132 bytes - -const en_GBData string = "" + // Size: 1204 bytes - "\x02The %[1]s service is expensive to run. Because we don't want to stor" + - "e personal information about you, there is no accounts or billing for th" + - "is service. But if you want the service to continue, donate at least US$" + - "5 each month.\x0a\x09\x0aDo you want to donate now?\x02Donate\x02%[1]s i" + - "s an easy, fast, and secure VPN service from riseup.net. %[1]s does not " + - "require a user account, keep logs, or track you in any way.\x0a\x09 " + - "\x0aThis service is paid for entirely by donations from users like you. " + - "Please donate at https://riseup.net/vpn/donate.\x0a\x09\x09\x0aBy using " + - "this application, you agree to the Terms of Service available at https:/" + - "/riseup.net/tos. This service is provide as-is, without any warranty, an" + - "d is intended for people who work to make the world a better place.\x0a" + - "\x0a\x0a%[1]v version: %[2]s\x02About\x02Initialisation error\x02Could n" + - "ot find a Polkit authentication agent. Please run one and try again.\x02" + - "Missing authentication agent\x02Can't connect to %[1]s: %[2]v\x02Error s" + - "tarting VPN\x02An error has occurred initialising %[1]s: %[2]v\x02Checki" + - "ng status...\x02Turn on\x02Turn off\x02Help...\x02Donate...\x02About..." + - "\x02Quit\x02Route traffic through\x02Use %[1]s %[2]v gateway\x02%[1]s on" + - "\x02%[1]s off\x02Cancel\x02Connecting to %[1]s\x02Stopping %[1]s\x02Retr" + - "y\x02%[1]s blocking Internet" - -var en_USIndex = []uint32{ // 27 elements - 0x00000000, 0x000000fd, 0x00000104, 0x00000300, - 0x00000306, 0x0000031b, 0x00000367, 0x00000384, - 0x000003a2, 0x000003b5, 0x000003e4, 0x000003f7, - 0x000003ff, 0x00000408, 0x00000410, 0x0000041a, - 0x00000423, 0x00000428, 0x0000043e, 0x00000456, - 0x0000045f, 0x00000469, 0x00000470, 0x00000484, - 0x00000493, 0x00000499, 0x000004b1, -} // Size: 132 bytes - -const en_USData string = "" + // Size: 1201 bytes - "\x02The %[1]s service is expensive to run. Because we don't want to stor" + - "e personal information about you, there is no accounts or billing for th" + - "is service. But if you want the service to continue, donate at least $5 " + - "each month.\x0a\x09\x0aDo you want to donate now?\x02Donate\x02%[1]s is " + - "an easy, fast, and secure VPN service from riseup.net. %[1]s does not re" + - "quire a user account, keep logs, or track you in any way.\x0a\x09 " + - "\x0aThis service is paid for entirely by donations from users like you. " + - "Please donate at https://riseup.net/vpn/donate.\x0a\x09\x09\x0aBy using " + - "this application, you agree to the Terms of Service available at https:/" + - "/riseup.net/tos. This service is provide as-is, without any warranty, an" + - "d is intended for people who work to make the world a better place.\x0a" + - "\x0a\x0a%[1]v version: %[2]s\x02About\x02Initialization error\x02Could n" + - "ot find a polkit authentication agent. Please run one and try again.\x02" + - "Missing authentication agent\x02Can't connect to %[1]s: %[2]v\x02Error s" + - "tarting VPN\x02An error has ocurred initializing %[1]s: %[2]v\x02Checkin" + - "g status...\x02Turn on\x02Turn off\x02Help...\x02Donate...\x02About..." + - "\x02Quit\x02Route traffic through\x02Use %[1]s %[2]v gateway\x02%[1]s on" + - "\x02%[1]s off\x02Cancel\x02Connecting to %[1]s\x02Stopping %[1]s\x02Retr" + - "y\x02%[1]s blocking internet" - -var esIndex = []uint32{ // 27 elements - 0x00000000, 0x000000ec, 0x000000f1, 0x00000332, - 0x0000033c, 0x00000355, 0x000003bc, 0x000003de, - 0x00000401, 0x00000419, 0x00000449, 0x00000462, - 0x0000046b, 0x00000472, 0x0000047b, 0x00000483, - 0x00000490, 0x00000497, 0x000004aa, 0x000004cb, - 0x000004db, 0x000004e9, 0x000004f2, 0x00000506, - 0x0000051e, 0x00000529, 0x00000543, -} // Size: 132 bytes - -const esData string = "" + // Size: 1347 bytes - "\x02El servicio %[1]s es caro de mantener. Como no queremos guardar ning" + - "una información personal tuya, no hay cuentas ni servicio de facturación" + - ". Si quieres que este servicio continúe, dona al menos $5 cada mes.\x0a" + - "\x09\x0a¿Quieres donar ahora?\x02Dona\x02%[1]s es un servicio de VPN fác" + - "il, rápido, y seguro de riseup.net. %[1]s no requiere una cuenta de usua" + - "rio, no mantiene registros, ni te rastrea de ninguna manera.\x0a\x09 " + - "\x0aEste servicio se paga en su totalidad por donaciones de usuarios com" + - "o tú. Por favor dona ingresando a https://riseup.net/vpn/donate.\x0a\x09" + - "\x09\x0aAl usar ésta aplicación, acuerdas con los Términos del Servicio " + - "disponibles en https://riseup.net/tos. Este servicio es provisto como vi" + - "ene, sin garantía alguna, y está destinado a gente que trabaja para hace" + - "r del mundo un lugar mejor.\x0a\x0a\x0aVersión de %[1]v: %[2]s\x02Acerca" + - " de\x02Error de inicialización\x02No se pudo encontrar ningún agente de " + - "autenticacion de polkit. Por favor lanza uno y prueba de nuevo.\x02Falta" + - " un agente de autenticación\x02No puedo conectar con %[1]s: %[2]v\x02Err" + - "or arrancando la VPN\x02Un error ha ocurrido inicializando %[1]s: %[2]v" + - "\x02Comprobando el estado...\x02Encender\x02Apagar\x02Ayuda...\x02Dona.." + - ".\x02Acerca de...\x02Cerrar\x02Salir a través de\x02Usa la salida de %[1" + - "]s por %[2]v\x02%[1]s encendida\x02%[1]s apagada\x02Cancelar\x02Connecta" + - "ndo a %[1]s\x02Desconnectando de %[1]s\x02Reintentar\x02%[1]s bloqueando" + - " internet" - -var es_ESIndex = []uint32{ // 27 elements - 0x00000000, 0x000000ec, 0x000000f2, 0x00000343, - 0x0000034d, 0x00000366, 0x000003c7, 0x000003e6, - 0x0000040a, 0x0000041e, 0x0000044e, 0x00000464, - 0x0000046c, 0x00000477, 0x00000480, 0x00000489, - 0x00000496, 0x0000049c, 0x000004ba, 0x000004da, - 0x000004e9, 0x000004fb, 0x00000504, 0x00000517, - 0x00000528, 0x00000533, 0x0000054d, -} // Size: 132 bytes - -const es_ESData string = "" + // Size: 1357 bytes - "\x02Correr el servicio %[1]s es caro. Porque no queremos almacenar infor" + - "mación personal acerca tuyo, no hay cuentas o tarifas por este servicio." + - " Pero si quieres que el mismo continúe, dona la menos USD 5 por mes.\x0a" + - "\x09\x0a¿Quieres donar ahora?\x02Donar\x02%[1]s es un servicio de VPN fá" + - "cil, rápido y seguro de riseup.net. %[1]s no requiere una cuenta de usua" + - "rio, no mantiene bitácoras, o te rastrea de cualquier manera.\x0a\x09 " + - " \x0aEl costo de este servicio está cubierto por completo por donaciones" + - " de usuarios como tú. Por favor dona a https://riseup.net/vpn/donate." + - "\x0a\x09\x09\x0aAl usar esta aplicación, estás de acuerdo con los Términ" + - "os del Servicio disponibles en https://riseup.net/tos. Este servicio se " + - "provee como está, sin ninguna garantía, y está apuntado a personas que t" + - "rabajan para hacer del mundo un mejor lugar.\x0a\x0a\x0aVersión de %[1]v" + - ": %[2]s\x02Acerca de\x02Error de inicialización\x02No se pudo encontrar " + - "un agente de autenticación polkit. Por favor corre uno e intenta de nuev" + - "o.\x02Falta agente de autenticación\x02No se puede conectar a %[1]s: %[2" + - "]v\x02Error iniciando VPN\x02Ha ocurrido un error inicializando %[1]s: %" + - "[2]v\x02Comprobando estado...\x02Activar\x02Desactivar\x02Ayuda...\x02Do" + - "nar...\x02Acerca de...\x02Salir\x02Enrutar tráfico a través de\x02Usar r" + - "uta de salida %[1]s %[2]v\x02%[1]s activada\x02%[1]s desactivada\x02Canc" + - "elar\x02Conectando a %[1]s\x02Deteniendo %[1]s\x02Reintentar\x02%[1]s bl" + - "oqueando Internet" - -var frIndex = []uint32{ // 27 elements - 0x00000000, 0x00000154, 0x00000161, 0x000003d5, - 0x000003df, 0x000003f9, 0x0000045b, 0x00000487, - 0x000004b4, 0x000004d0, 0x00000513, 0x00000531, - 0x00000539, 0x00000545, 0x0000054d, 0x0000055d, - 0x0000056a, 0x00000572, 0x0000058a, 0x000005ae, - 0x000005c0, 0x000005d6, 0x000005de, 0x000005f1, - 0x00000601, 0x0000060a, 0x00000620, -} // Size: 132 bytes - -const frData string = "" + // Size: 1568 bytes - "\x02L’exploitation du service %[1]s coûte cher. Dans la mesure où ne nou" + - "s voulons enregistrer aucun renseignement personnel à votre sujet, il n’" + - "y ni compte ni facturation pour ce service. Mais si vous souhaitez toute" + - "fois que le service continue, faites un don d’au moins 5\u00a0$ mensuell" + - "ement\x0a\x09\x0aSouhaitez-vous faire un don maintenant\u2009?\x02Faire " + - "un don\x02%[1]s est un service de RPV simple, rapide et sécurisé offert " + - "par riseup.net. %[1]s ne demande pas de compte utilisateur, ne conserve " + - "pas de journaux, ni ne vous suit à la trace d’aucune façon.\x0a\x09 " + - "\x0aCe service est entièrement financé par les dons d’utilisateurs comme" + - " vous. Veuillez faire un don à https://riseup.net/vpn/donate.\x0a\x09" + - "\x09\x0aEn utilisant cette application, vous acceptez les conditions gén" + - "érales d’utilisation qui se trouvent sur https://riseup.net/tos. Ce ser" + - "vice est fourni tel quel, sans aucune garantie, et s’adresse aux personn" + - "es qui œuvrent à rendre le monde meilleur.\x0a\x0a\x0a%[1]v version " + - "\u00a0: %[2]s\x02À propos\x02Erreur d’initialisation\x02Impossible de tr" + - "ouver un agent d’authentification polkit. Veuillez en exécuter un et res" + - "sayer.\x02L’agent d’authentification est manquant\x02Impossible de se co" + - "nnecter à %[1]s\u00a0: %[2]v\x02Erreur du démarrage du RPV\x02Une erreur" + - " est survenue lors de l'initialisation de %[1]s\u00a0: %[2]v\x02Vérifica" + - "tion de l’état…\x02Activer\x02Désactiver\x02Aide…\x02Faire un don…\x02À " + - "propos…\x02Quitter\x02Acheminer le trafic par\x02Utiliser la passerelle " + - "%[1]s %[2]v\x0a\x02%[1]s est activé\x02%[1]s est désactivé\x02Annuler" + - "\x02Connexion à %[1]s\x02Arrêt de %[1]s\x02Ressayer\x02%[1]s bloque Inte" + - "rnet" - -var ltIndex = []uint32{ // 27 elements - 0x00000000, 0x0000013d, 0x00000146, 0x00000392, - 0x00000397, 0x000003aa, 0x00000411, 0x00000436, - 0x0000045f, 0x00000477, 0x000004a0, 0x000004b5, - 0x000004be, 0x000004c8, 0x000004d3, 0x000004df, - 0x000004e7, 0x000004ef, 0x0000050c, 0x00000531, - 0x00000540, 0x00000550, 0x0000055b, 0x00000571, - 0x00000580, 0x00000592, 0x000005ac, -} // Size: 132 bytes - -const ltData string = "" + // Size: 1452 bytes - "\x02%[1]s paslaugą brangiai kainuoja išlaikyti. Kadangi nenorime saugoti" + - " jūsų asmeninės informacijos, todėl nėra jokių paskyrų ar apmokestinimo " + - "už šią paslaugą. Tačiau, jei norite, kad paslauga būtų teikiama ir tolia" + - "u, paaukokite kiekvieną mėnesį bent po $5 (JAV dolerius).\x0a\x09\x0aAr " + - "norite paaukoti dabar?\x02Paaukoti\x02%[1]s yra lengva naudoti, greita i" + - "r saugi VPN paslauga iš riseup.net. %[1]s nereikalauja naudotojo paskyro" + - "s, nesaugo žurnalų ir jokiu kitu būdu jūsų neseka.\x0a\x09 \x0aŠi pas" + - "lauga yra apmokama tik iš, tokių pačių naudotojų kaip jūs, paaukojimų. P" + - "rašome paaukokite, adresu https://riseup.net/vpn/donate.\x0a\x09\x09\x0a" + - "Naudodami šią programą, sutinkate su Naudojimosi Sąlygomis, kurias galit" + - "e rasti adresu https://riseup.net/tos. Ši paslauga yra teikiama esamu pa" + - "vidalu, be jokių garantijų ir yra skirta žmonėms, kurie dirba, kad padar" + - "ytų pasaulį geresnį.\x0a\x0a\x0a%[1]v versija: %[2]s\x02Apie\x02Inicijav" + - "imo klaida\x02Nepavyko rasti politikos rinkinio tapatybės nustatymo agen" + - "to. Paleiskite jį ir bandykite dar kartą.\x02Trūksta tapatybės nustatymo" + - " agento\x02Nepavyksta prisijungti prie %[1]s: %[2]v\x02Klaida paleidžian" + - "t VPN\x02Inicijuojant %[1]s, įvyko klaida: %[2]v\x02Tikrinama būsena..." + - "\x02Įjungti\x02Išjungti\x02Pagalba...\x02Paaukoti...\x02Apie...\x02Išeit" + - "i\x02Siųsti duomenų srautą per\x02Naudoti %[1]s %[2]v tinklų sietuvą\x02" + - "%[1]s įjungta\x02%[1]s išjungta\x02Atsisakyti\x02Jungiamasi prie %[1]s" + - "\x02Stabdoma %[1]s\x02Bandyti iš naujo\x02%[1]s blokuoja internetą" - -var nlIndex = []uint32{ // 27 elements - 0x00000000, 0x0000010c, 0x00000114, 0x00000356, - 0x0000035b, 0x0000036d, 0x000003bc, 0x000003d9, - 0x000003fd, 0x0000041f, 0x00000468, 0x0000047e, - 0x0000048a, 0x00000497, 0x0000049f, 0x000004aa, - 0x000004b2, 0x000004ba, 0x000004cd, 0x000004e9, - 0x000004f3, 0x000004fd, 0x00000507, 0x0000051b, - 0x00000531, 0x00000542, 0x0000055f, -} // Size: 132 bytes - -const nlData string = "" + // Size: 1375 bytes - "\x02De %[1]s dienst is kostbaar om te onderhouden. Omdat we geen persoon" + - "lijke informatie over u willen bijhouden, zijn er geen accounts of betal" + - "ingen voor deze dienst. Om deze dienst in leven te houden, overweeg ten " + - "minste €4 per maand te schenken.\x0a\x09\x0aWilt u nu doneren?\x02Donere" + - "n\x02%[1]s is een gemakkelijke, snelle, en veilige VPN-dienst van riseup" + - ".net. %[1]s vereist geen gebruikersaccount, houdt geen logboek bij en vo" + - "lgt u niet op wat voor manier dan ook.\x0a\x09\x0aDeze dienst wordt voll" + - "edig gefinancierd door donaties van gebruikers zoals u. Overweeg bij te " + - "dragen op https://riseup.net/vpn/donate.\x0a\x09\x09\x0aDoor deze applic" + - "atie te gebruiken gaat u akkoord met onze gebruikersvoorwaarden die besc" + - "hikbaar zijn op https://riseup.net/tos. Deze dienst wordt geleverd zonde" + - "r enige garantie, en is bedoeld voor mensen die werken aan een betere we" + - "reld.\x0a\x0a\x0a%[1]v versie: %[2]s\x02Over\x02Initialisatiefout\x02Kan" + - " geen polkit authenticatieagent vinden. Voer er een uit en probeer opnie" + - "uw.\x02Authenticatieagent ontbreekt\x02Kan niet verbinden met %[1]s: %[2" + - "]v\x02Fout bij het opstarten van de VPN\x02Er heeft zich een fout voorge" + - "daan bij het initialiseren van %[1]s: %[2]v\x02Status controleren...\x02" + - "Inschakelen\x02Uitschakelen\x02Hulp...\x02Doneren...\x02Over...\x02Stopp" + - "en\x02Stuur verkeer door\x02Gebruik %[1]s %[2]v gateway\x02%[1]s aan\x02" + - "%[1]s uit\x02Annuleren\x02Verbinden met %[1]s\x02%[1]s aan het stoppen" + - "\x02Opnieuw proberen\x02%[1]s blokkeert het internet" - -var pt_BRIndex = []uint32{ // 27 elements - 0x00000000, 0x00000134, 0x00000147, 0x0000039f, - 0x000003a5, 0x000003bd, 0x0000042e, 0x00000459, - 0x00000483, 0x00000499, 0x000004cc, 0x000004e2, - 0x000004e8, 0x000004f1, 0x000004fa, 0x00000510, - 0x00000519, 0x0000051e, 0x0000053c, 0x0000055a, - 0x0000056d, 0x00000583, 0x0000058c, 0x0000059f, - 0x000005ad, 0x000005be, 0x000005e0, -} // Size: 132 bytes - -const pt_BRData string = "" + // Size: 1504 bytes - "\x02O serviço %[1]s tem um custo para ser mantido. Como não queremos gua" + - "rdar suas informações pessoais, não temos contas de usuário e não cobram" + - "os por este serviço. Mas se você quiser que este serviço continue, faça " + - "uma doação de ao menos $5 dólares por mês.\x0a\x0aVocê quer fazer uma do" + - "ação agora?\x02Fazer uma doação\x02%[1]s é um serviço de VPN fácil, rápi" + - "do e seguro mantido por riseup.net. %[1]s não precisa de uma conta de u" + - "suário, não mantém logs, e não te rastreia de forma alguma.\x0a\x0aO ser" + - "viço é financiado inteiramente através de doações de pessoas como você. " + - "Por favor faça uma doação acessando https://riseup.net/vpn/donate.\x0a" + - "\x0aAo usar este aplicativo, você concorda com os Termos de Serviço disp" + - "oníveis em https://riseup.net/tos. Este serviço é provido \x22no estado" + - "\x22, sem nenhuma garantia, e é direcionado a pessoas que trabalham para" + - " tornar o mundo um lugar melhor.\x0a\x0a\x0a%[1]v versão: %[2]s\x02Sobre" + - "\x02Erro na inicialização\x02Não foi possível encontrar um agente de aut" + - "enticação polkit. Por favor, execute um agente e tente novamente.\x02Um " + - "agente de autenticação está faltando\x02Não é possível conectar a %[1]s:" + - " %[2]v\x02Erro ao iniciar a VPN\x02Um erro ocorreu na inicialização de %" + - "[1]s: %[2]v\x02Verificando estado...\x02Ligar\x02Desligar\x02Ajuda..." + - "\x02Fazer uma doação...\x02Sobre...\x02Sair\x02Rotear o tráfego através " + - "de\x02Usar o gateway %[2]v de %[1]s\x02%[1]s está ligada\x02%[1]s está d" + - "esligada\x02Cancelar\x02Conectando a %[1]s\x02Parando %[1]s\x02Tentar no" + - "vamente\x02%[1]s está bloqueando a Internet" - - // Total table size 13910 bytes (13KiB); checksum: 87E5E801 diff --git a/cmd/bitmask-vpn/catalog.go b/cmd/bitmask-vpn/catalog.go new file mode 100644 index 0000000..55142e8 --- /dev/null +++ b/cmd/bitmask-vpn/catalog.go @@ -0,0 +1,369 @@ +// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. + +package main + +import ( + "golang.org/x/text/language" + "golang.org/x/text/message" + "golang.org/x/text/message/catalog" +) + +type dictionary struct { + index []uint32 + data string +} + +func (d *dictionary) Lookup(key string) (data string, ok bool) { + p := messageKeyToIndex[key] + start, end := d.index[p], d.index[p+1] + if start == end { + return "", false + } + return d.data[start:end], true +} + +func init() { + dict := map[string]catalog.Dictionary{ + "bn": &dictionary{index: bnIndex, data: bnData}, + "en_GB": &dictionary{index: en_GBIndex, data: en_GBData}, + "en_US": &dictionary{index: en_USIndex, data: en_USData}, + "es": &dictionary{index: esIndex, data: esData}, + "es_ES": &dictionary{index: es_ESIndex, data: es_ESData}, + "fr": &dictionary{index: frIndex, data: frData}, + "lt": &dictionary{index: ltIndex, data: ltData}, + "nl": &dictionary{index: nlIndex, data: nlData}, + "pt_BR": &dictionary{index: pt_BRIndex, data: pt_BRData}, + } + fallback := language.MustParse("en-US") + cat, err := catalog.NewFromMap(dict, catalog.Fallback(fallback)) + if err != nil { + panic(err) + } + message.DefaultCatalog = cat +} + +var messageKeyToIndex = map[string]int{ + "%[1]s is an easy, fast, and secure VPN service from riseup.net. %[1]s does not require a user account, keep logs, or track you in any way.\n\t \nThis service is paid for entirely by donations from users like you. Please donate at https://riseup.net/vpn/donate.\n\t\t\nBy using this application, you agree to the Terms of Service available at https://riseup.net/tos. This service is provide as-is, without any warranty, and is intended for people who work to make the world a better place.\n\n\n%[1]v version: %[2]s": 2, + "%s blocking internet": 24, + "%s off": 19, + "%s on": 18, + "About": 3, + "About...": 14, + "An error has ocurred initializing the VPN: %v": 25, + "Can't connect to %s: %v": 7, + "Cancel": 20, + "Checking status...": 9, + "Connecting to %s": 21, + "Could not find a polkit authentication agent. Please run one and try again.": 5, + "Donate": 1, + "Donate...": 13, + "Error starting VPN": 8, + "Help...": 12, + "Initialization error": 4, + "Missing authentication agent": 6, + "Quit": 15, + "Retry": 23, + "Route traffic through": 16, + "Stopping %s": 22, + "The %s service is expensive to run. Because we don't want to store personal information about you, there is no accounts or billing for this service. But if you want the service to continue, donate at least $5 each month.\n\t\nDo you want to donate now?": 0, + "Turn off": 11, + "Turn on": 10, + "Use %s %v gateway": 17, +} + +var bnIndex = []uint32{ // 27 elements + 0x00000000, 0x000000fd, 0x00000110, 0x0000030c, + 0x00000325, 0x00000348, 0x00000394, 0x000003e2, + 0x00000400, 0x00000450, 0x00000497, 0x000004ab, + 0x000004bf, 0x000004d8, 0x000004ee, 0x0000050a, + 0x00000517, 0x00000557, 0x0000056f, 0x00000582, + 0x00000595, 0x000005a5, 0x000005e5, 0x00000608, + 0x0000063b, 0x00000683, 0x000006b0, +} // Size: 132 bytes + +const bnData string = "" + // Size: 1712 bytes + "\x02The %[1]s service is expensive to run. Because we don't want to stor" + + "e personal information about you, there is no accounts or billing for th" + + "is service. But if you want the service to continue, donate at least $5 " + + "each month.\x0a\x09\x0aDo you want to donate now?\x02অনুদান\x02%[1]s is " + + "an easy, fast, and secure VPN service from riseup.net. %[1]s does not re" + + "quire a user account, keep logs, or track you in any way.\x0a\x09 " + + "\x0aThis service is paid for entirely by donations from users like you. " + + "Please donate at https://riseup.net/vpn/donate.\x0a\x09\x09\x0aBy using " + + "this application, you agree to the Terms of Service available at https:/" + + "/riseup.net/tos. This service is provide as-is, without any warranty, an" + + "d is intended for people who work to make the world a better place.\x0a" + + "\x0a\x0a%[1]v version: %[2]s\x02সম্পর্কে\x02সূচনা ত্রুটি\x02Could not fi" + + "nd a polkit authentication agent. Please run one and try again.\x02প্রমা" + + "ণীকরণ এজেন্ট অনুপস্থিত\x02Can't connect to %[1]s: %[2]v\x02ভিপিএন চালু" + + " করতে ত্রুটি হয়েছে\x02অবস্থা পরিক্ষা করা হচ্ছে ...\x02চালু কর\x02বন্ধ কর" + + "\x02সাহায্য...\x02অনুদান...\x02সম্পর্কে...\x02বন্ধ\x02ট্রাফিক এর মাধ্যমে" + + " যাবে\x02Use %[1]s %[2]v gateway\x02%[1]s চালু\x02%[1]s বন্ধ\x02বাতিল" + + "\x02%[1]s এর সাথে সংযুক্ত হচ্ছে\x02%[1]s বন্ধ হচ্ছে\x02পূনরায় চেষ্টা করু" + + "ন\x02%[1]s ইন্টারনেট প্রতিরোধ করছে\x02An error has ocurred initializin" + + "g VPN: %[1]v" + +var en_GBIndex = []uint32{ // 27 elements + 0x00000000, 0x000000ff, 0x00000106, 0x00000302, + 0x00000308, 0x0000031d, 0x00000369, 0x00000386, + 0x000003a4, 0x000003b7, 0x000003ca, 0x000003d2, + 0x000003db, 0x000003e3, 0x000003ed, 0x000003f6, + 0x000003fb, 0x00000411, 0x00000429, 0x00000432, + 0x0000043c, 0x00000443, 0x00000457, 0x00000466, + 0x0000046c, 0x00000484, 0x000004b2, +} // Size: 132 bytes + +const en_GBData string = "" + // Size: 1202 bytes + "\x02The %[1]s service is expensive to run. Because we don't want to stor" + + "e personal information about you, there is no accounts or billing for th" + + "is service. But if you want the service to continue, donate at least US$" + + "5 each month.\x0a\x09\x0aDo you want to donate now?\x02Donate\x02%[1]s i" + + "s an easy, fast, and secure VPN service from riseup.net. %[1]s does not " + + "require a user account, keep logs, or track you in any way.\x0a\x09 " + + "\x0aThis service is paid for entirely by donations from users like you. " + + "Please donate at https://riseup.net/vpn/donate.\x0a\x09\x09\x0aBy using " + + "this application, you agree to the Terms of Service available at https:/" + + "/riseup.net/tos. This service is provide as-is, without any warranty, an" + + "d is intended for people who work to make the world a better place.\x0a" + + "\x0a\x0a%[1]v version: %[2]s\x02About\x02Initialisation error\x02Could n" + + "ot find a Polkit authentication agent. Please run one and try again.\x02" + + "Missing authentication agent\x02Can't connect to %[1]s: %[2]v\x02Error s" + + "tarting VPN\x02Checking status...\x02Turn on\x02Turn off\x02Help...\x02D" + + "onate...\x02About...\x02Quit\x02Route traffic through\x02Use %[1]s %[2]v" + + " gateway\x02%[1]s on\x02%[1]s off\x02Cancel\x02Connecting to %[1]s\x02St" + + "opping %[1]s\x02Retry\x02%[1]s blocking Internet\x02An error has occurre" + + "d initialising VPN: %[1]v" + +var en_USIndex = []uint32{ // 27 elements + 0x00000000, 0x000000fd, 0x00000104, 0x00000300, + 0x00000306, 0x0000031b, 0x00000367, 0x00000384, + 0x000003a2, 0x000003b5, 0x000003c8, 0x000003d0, + 0x000003d9, 0x000003e1, 0x000003eb, 0x000003f4, + 0x000003f9, 0x0000040f, 0x00000427, 0x00000430, + 0x0000043a, 0x00000441, 0x00000455, 0x00000464, + 0x0000046a, 0x00000482, 0x000004af, +} // Size: 132 bytes + +const en_USData string = "" + // Size: 1199 bytes + "\x02The %[1]s service is expensive to run. Because we don't want to stor" + + "e personal information about you, there is no accounts or billing for th" + + "is service. But if you want the service to continue, donate at least $5 " + + "each month.\x0a\x09\x0aDo you want to donate now?\x02Donate\x02%[1]s is " + + "an easy, fast, and secure VPN service from riseup.net. %[1]s does not re" + + "quire a user account, keep logs, or track you in any way.\x0a\x09 " + + "\x0aThis service is paid for entirely by donations from users like you. " + + "Please donate at https://riseup.net/vpn/donate.\x0a\x09\x09\x0aBy using " + + "this application, you agree to the Terms of Service available at https:/" + + "/riseup.net/tos. This service is provide as-is, without any warranty, an" + + "d is intended for people who work to make the world a better place.\x0a" + + "\x0a\x0a%[1]v version: %[2]s\x02About\x02Initialization error\x02Could n" + + "ot find a polkit authentication agent. Please run one and try again.\x02" + + "Missing authentication agent\x02Can't connect to %[1]s: %[2]v\x02Error s" + + "tarting VPN\x02Checking status...\x02Turn on\x02Turn off\x02Help...\x02D" + + "onate...\x02About...\x02Quit\x02Route traffic through\x02Use %[1]s %[2]v" + + " gateway\x02%[1]s on\x02%[1]s off\x02Cancel\x02Connecting to %[1]s\x02St" + + "opping %[1]s\x02Retry\x02%[1]s blocking internet\x02An error has ocurred" + + " initializing VPN: %[1]v" + +var esIndex = []uint32{ // 27 elements + 0x00000000, 0x000000ec, 0x000000f1, 0x00000332, + 0x0000033c, 0x00000355, 0x000003bc, 0x000003de, + 0x00000401, 0x00000419, 0x00000432, 0x0000043b, + 0x00000442, 0x0000044b, 0x00000453, 0x00000460, + 0x00000467, 0x0000047a, 0x0000049b, 0x000004ab, + 0x000004b9, 0x000004c2, 0x000004d6, 0x000004ee, + 0x000004f9, 0x00000513, 0x00000541, +} // Size: 132 bytes + +const esData string = "" + // Size: 1345 bytes + "\x02El servicio %[1]s es caro de mantener. Como no queremos guardar ning" + + "una información personal tuya, no hay cuentas ni servicio de facturación" + + ". Si quieres que este servicio continúe, dona al menos $5 cada mes.\x0a" + + "\x09\x0a¿Quieres donar ahora?\x02Dona\x02%[1]s es un servicio de VPN fác" + + "il, rápido, y seguro de riseup.net. %[1]s no requiere una cuenta de usua" + + "rio, no mantiene registros, ni te rastrea de ninguna manera.\x0a\x09 " + + "\x0aEste servicio se paga en su totalidad por donaciones de usuarios com" + + "o tú. Por favor dona ingresando a https://riseup.net/vpn/donate.\x0a\x09" + + "\x09\x0aAl usar ésta aplicación, acuerdas con los Términos del Servicio " + + "disponibles en https://riseup.net/tos. Este servicio es provisto como vi" + + "ene, sin garantía alguna, y está destinado a gente que trabaja para hace" + + "r del mundo un lugar mejor.\x0a\x0a\x0aVersión de %[1]v: %[2]s\x02Acerca" + + " de\x02Error de inicialización\x02No se pudo encontrar ningún agente de " + + "autenticacion de polkit. Por favor lanza uno y prueba de nuevo.\x02Falta" + + " un agente de autenticación\x02No puedo conectar con %[1]s: %[2]v\x02Err" + + "or arrancando la VPN\x02Comprobando el estado...\x02Encender\x02Apagar" + + "\x02Ayuda...\x02Dona...\x02Acerca de...\x02Cerrar\x02Salir a través de" + + "\x02Usa la salida de %[1]s por %[2]v\x02%[1]s encendida\x02%[1]s apagada" + + "\x02Cancelar\x02Connectando a %[1]s\x02Desconnectando de %[1]s\x02Reinte" + + "ntar\x02%[1]s bloqueando internet\x02Un error ha ocurrido inicializando " + + "VPN: %[1]v" + +var es_ESIndex = []uint32{ // 27 elements + 0x00000000, 0x000000ec, 0x000000f2, 0x00000343, + 0x0000034d, 0x00000366, 0x000003c7, 0x000003e6, + 0x0000040a, 0x0000041e, 0x00000434, 0x0000043c, + 0x00000447, 0x00000450, 0x00000459, 0x00000466, + 0x0000046c, 0x0000048a, 0x000004aa, 0x000004b9, + 0x000004cb, 0x000004d4, 0x000004e7, 0x000004f8, + 0x00000503, 0x0000051d, 0x0000054b, +} // Size: 132 bytes + +const es_ESData string = "" + // Size: 1355 bytes + "\x02Correr el servicio %[1]s es caro. Porque no queremos almacenar infor" + + "mación personal acerca tuyo, no hay cuentas o tarifas por este servicio." + + " Pero si quieres que el mismo continúe, dona la menos USD 5 por mes.\x0a" + + "\x09\x0a¿Quieres donar ahora?\x02Donar\x02%[1]s es un servicio de VPN fá" + + "cil, rápido y seguro de riseup.net. %[1]s no requiere una cuenta de usua" + + "rio, no mantiene bitácoras, o te rastrea de cualquier manera.\x0a\x09 " + + " \x0aEl costo de este servicio está cubierto por completo por donaciones" + + " de usuarios como tú. Por favor dona a https://riseup.net/vpn/donate." + + "\x0a\x09\x09\x0aAl usar esta aplicación, estás de acuerdo con los Términ" + + "os del Servicio disponibles en https://riseup.net/tos. Este servicio se " + + "provee como está, sin ninguna garantía, y está apuntado a personas que t" + + "rabajan para hacer del mundo un mejor lugar.\x0a\x0a\x0aVersión de %[1]v" + + ": %[2]s\x02Acerca de\x02Error de inicialización\x02No se pudo encontrar " + + "un agente de autenticación polkit. Por favor corre uno e intenta de nuev" + + "o.\x02Falta agente de autenticación\x02No se puede conectar a %[1]s: %[2" + + "]v\x02Error iniciando VPN\x02Comprobando estado...\x02Activar\x02Desacti" + + "var\x02Ayuda...\x02Donar...\x02Acerca de...\x02Salir\x02Enrutar tráfico " + + "a través de\x02Usar ruta de salida %[1]s %[2]v\x02%[1]s activada\x02%[1]" + + "s desactivada\x02Cancelar\x02Conectando a %[1]s\x02Deteniendo %[1]s\x02R" + + "eintentar\x02%[1]s bloqueando Internet\x02Ha ocurrido un error inicializ" + + "ando VPN: %[1]v" + +var frIndex = []uint32{ // 27 elements + 0x00000000, 0x00000154, 0x00000161, 0x000003d5, + 0x000003df, 0x000003f9, 0x0000045b, 0x00000487, + 0x000004b4, 0x000004d0, 0x000004ee, 0x000004f6, + 0x00000502, 0x0000050a, 0x0000051a, 0x00000527, + 0x0000052f, 0x00000547, 0x0000056b, 0x0000057d, + 0x00000593, 0x0000059b, 0x000005ae, 0x000005be, + 0x000005c7, 0x000005dd, 0x0000061c, +} // Size: 132 bytes + +const frData string = "" + // Size: 1564 bytes + "\x02L’exploitation du service %[1]s coûte cher. Dans la mesure où ne nou" + + "s voulons enregistrer aucun renseignement personnel à votre sujet, il n’" + + "y ni compte ni facturation pour ce service. Mais si vous souhaitez toute" + + "fois que le service continue, faites un don d’au moins 5\u00a0$ mensuell" + + "ement\x0a\x09\x0aSouhaitez-vous faire un don maintenant\u2009?\x02Faire " + + "un don\x02%[1]s est un service de RPV simple, rapide et sécurisé offert " + + "par riseup.net. %[1]s ne demande pas de compte utilisateur, ne conserve " + + "pas de journaux, ni ne vous suit à la trace d’aucune façon.\x0a\x09 " + + "\x0aCe service est entièrement financé par les dons d’utilisateurs comme" + + " vous. Veuillez faire un don à https://riseup.net/vpn/donate.\x0a\x09" + + "\x09\x0aEn utilisant cette application, vous acceptez les conditions gén" + + "érales d’utilisation qui se trouvent sur https://riseup.net/tos. Ce ser" + + "vice est fourni tel quel, sans aucune garantie, et s’adresse aux personn" + + "es qui œuvrent à rendre le monde meilleur.\x0a\x0a\x0a%[1]v version " + + "\u00a0: %[2]s\x02À propos\x02Erreur d’initialisation\x02Impossible de tr" + + "ouver un agent d’authentification polkit. Veuillez en exécuter un et res" + + "sayer.\x02L’agent d’authentification est manquant\x02Impossible de se co" + + "nnecter à %[1]s\u00a0: %[2]v\x02Erreur du démarrage du RPV\x02Vérificati" + + "on de l’état…\x02Activer\x02Désactiver\x02Aide…\x02Faire un don…\x02À pr" + + "opos…\x02Quitter\x02Acheminer le trafic par\x02Utiliser la passerelle %[" + + "1]s %[2]v\x0a\x02%[1]s est activé\x02%[1]s est désactivé\x02Annuler\x02C" + + "onnexion à %[1]s\x02Arrêt de %[1]s\x02Ressayer\x02%[1]s bloque Internet" + + "\x02Une erreur est survenue lors de l'initialisation de VPN: %[1]v" + +var ltIndex = []uint32{ // 27 elements + 0x00000000, 0x0000013d, 0x00000146, 0x00000392, + 0x00000397, 0x000003aa, 0x00000411, 0x00000436, + 0x0000045f, 0x00000477, 0x0000048c, 0x00000495, + 0x0000049f, 0x000004aa, 0x000004b6, 0x000004be, + 0x000004c6, 0x000004e3, 0x00000508, 0x00000517, + 0x00000527, 0x00000532, 0x00000548, 0x00000557, + 0x00000569, 0x00000583, 0x000005aa, +} // Size: 132 bytes + +const ltData string = "" + // Size: 1450 bytes + "\x02%[1]s paslaugą brangiai kainuoja išlaikyti. Kadangi nenorime saugoti" + + " jūsų asmeninės informacijos, todėl nėra jokių paskyrų ar apmokestinimo " + + "už šią paslaugą. Tačiau, jei norite, kad paslauga būtų teikiama ir tolia" + + "u, paaukokite kiekvieną mėnesį bent po $5 (JAV dolerius).\x0a\x09\x0aAr " + + "norite paaukoti dabar?\x02Paaukoti\x02%[1]s yra lengva naudoti, greita i" + + "r saugi VPN paslauga iš riseup.net. %[1]s nereikalauja naudotojo paskyro" + + "s, nesaugo žurnalų ir jokiu kitu būdu jūsų neseka.\x0a\x09 \x0aŠi pas" + + "lauga yra apmokama tik iš, tokių pačių naudotojų kaip jūs, paaukojimų. P" + + "rašome paaukokite, adresu https://riseup.net/vpn/donate.\x0a\x09\x09\x0a" + + "Naudodami šią programą, sutinkate su Naudojimosi Sąlygomis, kurias galit" + + "e rasti adresu https://riseup.net/tos. Ši paslauga yra teikiama esamu pa" + + "vidalu, be jokių garantijų ir yra skirta žmonėms, kurie dirba, kad padar" + + "ytų pasaulį geresnį.\x0a\x0a\x0a%[1]v versija: %[2]s\x02Apie\x02Inicijav" + + "imo klaida\x02Nepavyko rasti politikos rinkinio tapatybės nustatymo agen" + + "to. Paleiskite jį ir bandykite dar kartą.\x02Trūksta tapatybės nustatymo" + + " agento\x02Nepavyksta prisijungti prie %[1]s: %[2]v\x02Klaida paleidžian" + + "t VPN\x02Tikrinama būsena...\x02Įjungti\x02Išjungti\x02Pagalba...\x02Paa" + + "ukoti...\x02Apie...\x02Išeiti\x02Siųsti duomenų srautą per\x02Naudoti %[" + + "1]s %[2]v tinklų sietuvą\x02%[1]s įjungta\x02%[1]s išjungta\x02Atsisakyt" + + "i\x02Jungiamasi prie %[1]s\x02Stabdoma %[1]s\x02Bandyti iš naujo\x02%[1]" + + "s blokuoja internetą\x02Inicijuojant VPN, įvyko klaida: %[1]v" + +var nlIndex = []uint32{ // 27 elements + 0x00000000, 0x0000010c, 0x00000114, 0x00000356, + 0x0000035b, 0x0000036d, 0x000003bc, 0x000003d9, + 0x000003fd, 0x0000041f, 0x00000435, 0x00000441, + 0x0000044e, 0x00000456, 0x00000461, 0x00000469, + 0x00000471, 0x00000484, 0x000004a0, 0x000004aa, + 0x000004b4, 0x000004be, 0x000004d2, 0x000004e8, + 0x000004f9, 0x00000516, 0x0000055d, +} // Size: 132 bytes + +const nlData string = "" + // Size: 1373 bytes + "\x02De %[1]s dienst is kostbaar om te onderhouden. Omdat we geen persoon" + + "lijke informatie over u willen bijhouden, zijn er geen accounts of betal" + + "ingen voor deze dienst. Om deze dienst in leven te houden, overweeg ten " + + "minste €4 per maand te schenken.\x0a\x09\x0aWilt u nu doneren?\x02Donere" + + "n\x02%[1]s is een gemakkelijke, snelle, en veilige VPN-dienst van riseup" + + ".net. %[1]s vereist geen gebruikersaccount, houdt geen logboek bij en vo" + + "lgt u niet op wat voor manier dan ook.\x0a\x09\x0aDeze dienst wordt voll" + + "edig gefinancierd door donaties van gebruikers zoals u. Overweeg bij te " + + "dragen op https://riseup.net/vpn/donate.\x0a\x09\x09\x0aDoor deze applic" + + "atie te gebruiken gaat u akkoord met onze gebruikersvoorwaarden die besc" + + "hikbaar zijn op https://riseup.net/tos. Deze dienst wordt geleverd zonde" + + "r enige garantie, en is bedoeld voor mensen die werken aan een betere we" + + "reld.\x0a\x0a\x0a%[1]v versie: %[2]s\x02Over\x02Initialisatiefout\x02Kan" + + " geen polkit authenticatieagent vinden. Voer er een uit en probeer opnie" + + "uw.\x02Authenticatieagent ontbreekt\x02Kan niet verbinden met %[1]s: %[2" + + "]v\x02Fout bij het opstarten van de VPN\x02Status controleren...\x02Insc" + + "hakelen\x02Uitschakelen\x02Hulp...\x02Doneren...\x02Over...\x02Stoppen" + + "\x02Stuur verkeer door\x02Gebruik %[1]s %[2]v gateway\x02%[1]s aan\x02%[" + + "1]s uit\x02Annuleren\x02Verbinden met %[1]s\x02%[1]s aan het stoppen\x02" + + "Opnieuw proberen\x02%[1]s blokkeert het internet\x02Er heeft zich een fo" + + "ut voorgedaan bij het initialiseren van VPN: %[1]v" + +var pt_BRIndex = []uint32{ // 27 elements + 0x00000000, 0x00000134, 0x00000147, 0x0000039f, + 0x000003a5, 0x000003bd, 0x0000042e, 0x00000459, + 0x00000483, 0x00000499, 0x000004af, 0x000004b5, + 0x000004be, 0x000004c7, 0x000004dd, 0x000004e6, + 0x000004eb, 0x00000509, 0x00000527, 0x0000053a, + 0x00000550, 0x00000559, 0x0000056c, 0x0000057a, + 0x0000058b, 0x000005ad, 0x000005de, +} // Size: 132 bytes + +const pt_BRData string = "" + // Size: 1502 bytes + "\x02O serviço %[1]s tem um custo para ser mantido. Como não queremos gua" + + "rdar suas informações pessoais, não temos contas de usuário e não cobram" + + "os por este serviço. Mas se você quiser que este serviço continue, faça " + + "uma doação de ao menos $5 dólares por mês.\x0a\x0aVocê quer fazer uma do" + + "ação agora?\x02Fazer uma doação\x02%[1]s é um serviço de VPN fácil, rápi" + + "do e seguro mantido por riseup.net. %[1]s não precisa de uma conta de u" + + "suário, não mantém logs, e não te rastreia de forma alguma.\x0a\x0aO ser" + + "viço é financiado inteiramente através de doações de pessoas como você. " + + "Por favor faça uma doação acessando https://riseup.net/vpn/donate.\x0a" + + "\x0aAo usar este aplicativo, você concorda com os Termos de Serviço disp" + + "oníveis em https://riseup.net/tos. Este serviço é provido \x22no estado" + + "\x22, sem nenhuma garantia, e é direcionado a pessoas que trabalham para" + + " tornar o mundo um lugar melhor.\x0a\x0a\x0a%[1]v versão: %[2]s\x02Sobre" + + "\x02Erro na inicialização\x02Não foi possível encontrar um agente de aut" + + "enticação polkit. Por favor, execute um agente e tente novamente.\x02Um " + + "agente de autenticação está faltando\x02Não é possível conectar a %[1]s:" + + " %[2]v\x02Erro ao iniciar a VPN\x02Verificando estado...\x02Ligar\x02Des" + + "ligar\x02Ajuda...\x02Fazer uma doação...\x02Sobre...\x02Sair\x02Rotear o" + + " tráfego através de\x02Usar o gateway %[2]v de %[1]s\x02%[1]s está ligad" + + "a\x02%[1]s está desligada\x02Cancelar\x02Conectando a %[1]s\x02Parando %" + + "[1]s\x02Tentar novamente\x02%[1]s está bloqueando a Internet\x02Um erro " + + "ocorreu na inicialização de VPN: %[1]v" + + // Total table size 13890 bytes (13KiB); checksum: 25F68812 diff --git a/cmd/bitmask-vpn/main.go b/cmd/bitmask-vpn/main.go new file mode 100644 index 0000000..fb3fd1f --- /dev/null +++ b/cmd/bitmask-vpn/main.go @@ -0,0 +1,76 @@ +// 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 . + +package main + +import ( + "flag" + "fmt" + "log" + "os" + "path" + "runtime" + + "0xacab.org/leap/bitmask-systray/pkg/config" + "0xacab.org/leap/bitmask-systray/pkg/systray" + "github.com/jmshal/go-locale" + "golang.org/x/text/message" +) + +const ( + provider = "riseup.net" + applicationName = "RiseupVPN" + logFile = "systray.log" +) + +var version string + +func main() { + // on OSX sometimes the systray doesn't work (bitmask-systray#52) + // locking the main thread into an OS thread fixes the problem + runtime.LockOSThread() + + logger, err := config.ConfigureLogger(path.Join(config.Path, logFile)) + if err != nil { + log.Println("Can't configure logger: ", err) + } else { + defer logger.Close() + } + + conf := systray.ParseConfig() + + flag.BoolVar(&conf.SelectGateway, "select-gateway", false, "Enable gateway selection") + versionFlag := flag.Bool("version", false, "Version of the bitmask-systray") + flag.Parse() + if *versionFlag { + fmt.Println(version) + os.Exit(0) + } + + conf.Provider = provider + conf.ApplicationName = applicationName + conf.Version = version + conf.Printer = initPrinter() + systray.Run(conf) +} + +func initPrinter() *message.Printer { + locale, err := go_locale.DetectLocale() + if err != nil { + log.Println("Error detecting the system locale: ", err) + } + + return message.NewPrinter(message.MatchLanguage(locale, "en")) +} diff --git a/config.go b/config.go deleted file mode 100644 index 4eb5dd3..0000000 --- a/config.go +++ /dev/null @@ -1,90 +0,0 @@ -// 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 . - -package main - -import ( - "encoding/json" - "os" - "path" - "time" - - "0xacab.org/leap/bitmask-systray/bitmask" -) - -const ( - oneDay = time.Hour * 24 - oneMonth = oneDay * 30 -) - -var ( - configPath = path.Join(bitmask.ConfigPath, "systray.json") -) - -type systrayConfig struct { - LastNotification time.Time - Donated time.Time - SelectGateway bool - UserStoppedVPN bool -} - -func parseConfig() *systrayConfig { - var conf systrayConfig - - f, err := os.Open(configPath) - if err != nil { - conf.save() - return &conf - } - defer f.Close() - - dec := json.NewDecoder(f) - err = dec.Decode(&conf) - return &conf -} - -func (c *systrayConfig) setUserStoppedVPN(vpnStopped bool) error { - c.UserStoppedVPN = vpnStopped - return c.save() -} - -func (c *systrayConfig) hasDonated() bool { - return c.Donated.Add(oneMonth).After(time.Now()) -} - -func (c *systrayConfig) needsNotification() bool { - return !c.hasDonated() && c.LastNotification.Add(oneDay).Before(time.Now()) -} - -func (c *systrayConfig) setNotification() error { - c.LastNotification = time.Now() - return c.save() -} - -func (c *systrayConfig) setDonated() error { - c.Donated = time.Now() - return c.save() -} - -func (c *systrayConfig) save() error { - f, err := os.Create(configPath) - if err != nil { - return err - } - defer f.Close() - - enc := json.NewEncoder(f) - return enc.Encode(c) -} diff --git a/locales/bn/messages.gotext.json b/locales/bn/messages.gotext.json index a2f063f..9bcbb29 100644 --- a/locales/bn/messages.gotext.json +++ b/locales/bn/messages.gotext.json @@ -1,6 +1,24 @@ { "language": "bn", "messages": [ + { + "id": [ + "errorMsg", + "An error has ocurred initializing the VPN: {Err}" + ], + "message": "An error has ocurred initializing the VPN: {Err}", + "translation": "An error has ocurred initializing VPN: {Err}", + "placeholders": [ + { + "id": "Err", + "string": "%[1]v", + "type": "error", + "underlyingType": "interface{Error() string}", + "argNum": 1, + "expr": "err" + } + ] + }, { "id": [ "donationText", @@ -15,7 +33,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" } ] }, @@ -38,7 +56,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName", @@ -46,7 +64,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName_1", @@ -54,7 +72,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Version", @@ -103,7 +121,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Err", @@ -120,32 +138,6 @@ "message": "Error starting VPN", "translation": "ভিপিএন চালু করতে ত্রুটি হয়েছে" }, - { - "id": [ - "errorMsg", - "An error has ocurred initializing {ApplicationName}: {Err}" - ], - "message": "An error has ocurred initializing {ApplicationName}: {Err}", - "translation": "An error has ocurred initializing {ApplicationName}: {Err}", - "placeholders": [ - { - "id": "ApplicationName", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "applicationName" - }, - { - "id": "Err", - "string": "%[2]v", - "type": "error", - "underlyingType": "interface{Error() string}", - "argNum": 2, - "expr": "err" - } - ] - }, { "id": "Checking status...", "message": "Checking status...", @@ -197,7 +189,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" }, { "id": "City", @@ -220,7 +212,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -235,7 +227,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -255,7 +247,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -270,7 +262,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -290,7 +282,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] } diff --git a/locales/en-GB/messages.gotext.json b/locales/en-GB/messages.gotext.json index e7e4edf..b4cacaa 100644 --- a/locales/en-GB/messages.gotext.json +++ b/locales/en-GB/messages.gotext.json @@ -1,6 +1,24 @@ { "language": "en-GB", "messages": [ + { + "id": [ + "errorMsg", + "An error has ocurred initializing the VPN: {Err}" + ], + "message": "An error has ocurred initializing the VPN: {Err}", + "translation": "An error has occurred initialising VPN: {Err}", + "placeholders": [ + { + "id": "Err", + "string": "%[1]v", + "type": "error", + "underlyingType": "interface{Error() string}", + "argNum": 1, + "expr": "err" + } + ] + }, { "id": [ "donationText", @@ -15,7 +33,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" } ] }, @@ -38,7 +56,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName", @@ -46,7 +64,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName_1", @@ -54,7 +72,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Version", @@ -103,7 +121,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Err", @@ -120,32 +138,6 @@ "message": "Error starting VPN", "translation": "Error starting VPN" }, - { - "id": [ - "errorMsg", - "An error has ocurred initializing {ApplicationName}: {Err}" - ], - "message": "An error has ocurred initializing {ApplicationName}: {Err}", - "translation": "An error has occurred initialising {ApplicationName}: {Err}", - "placeholders": [ - { - "id": "ApplicationName", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "applicationName" - }, - { - "id": "Err", - "string": "%[2]v", - "type": "error", - "underlyingType": "interface{Error() string}", - "argNum": 2, - "expr": "err" - } - ] - }, { "id": "Checking status...", "message": "Checking status...", @@ -197,7 +189,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" }, { "id": "City", @@ -220,7 +212,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -235,7 +227,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -255,7 +247,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -270,7 +262,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -290,7 +282,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] } diff --git a/locales/en-US/messages.gotext.json b/locales/en-US/messages.gotext.json index f1d2084..d8e72cc 100644 --- a/locales/en-US/messages.gotext.json +++ b/locales/en-US/messages.gotext.json @@ -1,6 +1,26 @@ { "language": "en-US", "messages": [ + { + "id": [ + "errorMsg", + "An error has ocurred initializing the VPN: {Err}" + ], + "message": "An error has ocurred initializing the VPN: {Err}", + "translation": "An error has ocurred initializing VPN: {Err}", + "translatorComment": "Copied from source.", + "placeholders": [ + { + "id": "Err", + "string": "%[1]v", + "type": "error", + "underlyingType": "interface{Error() string}", + "argNum": 1, + "expr": "err" + } + ], + "fuzzy": true + }, { "id": [ "donationText", @@ -16,7 +36,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" } ], "fuzzy": true @@ -43,7 +63,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName", @@ -51,7 +71,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName_1", @@ -59,7 +79,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Version", @@ -118,7 +138,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Err", @@ -138,34 +158,6 @@ "translatorComment": "Copied from source.", "fuzzy": true }, - { - "id": [ - "errorMsg", - "An error has ocurred initializing {ApplicationName}: {Err}" - ], - "message": "An error has ocurred initializing {ApplicationName}: {Err}", - "translation": "An error has ocurred initializing {ApplicationName}: {Err}", - "translatorComment": "Copied from source.", - "placeholders": [ - { - "id": "ApplicationName", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "applicationName" - }, - { - "id": "Err", - "string": "%[2]v", - "type": "error", - "underlyingType": "interface{Error() string}", - "argNum": 2, - "expr": "err" - } - ], - "fuzzy": true - }, { "id": "Checking status...", "message": "Checking status...", @@ -224,7 +216,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" }, { "id": "City", @@ -249,7 +241,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ], "fuzzy": true @@ -266,7 +258,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ], "fuzzy": true @@ -288,7 +280,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ], "fuzzy": true @@ -305,7 +297,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ], "fuzzy": true @@ -327,7 +319,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ], "fuzzy": true diff --git a/locales/es-ES/messages.gotext.json b/locales/es-ES/messages.gotext.json index 28122b8..0cf3e1e 100644 --- a/locales/es-ES/messages.gotext.json +++ b/locales/es-ES/messages.gotext.json @@ -1,6 +1,24 @@ { "language": "es-ES", "messages": [ + { + "id": [ + "errorMsg", + "An error has ocurred initializing the VPN: {Err}" + ], + "message": "An error has ocurred initializing the VPN: {Err}", + "translation": "Ha ocurrido un error inicializando VPN: {Err}", + "placeholders": [ + { + "id": "Err", + "string": "%[1]v", + "type": "error", + "underlyingType": "interface{Error() string}", + "argNum": 1, + "expr": "err" + } + ] + }, { "id": [ "donationText", @@ -15,7 +33,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" } ] }, @@ -38,7 +56,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName", @@ -46,7 +64,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName_1", @@ -54,7 +72,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Version", @@ -103,7 +121,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Err", @@ -120,32 +138,6 @@ "message": "Error starting VPN", "translation": "Error iniciando VPN" }, - { - "id": [ - "errorMsg", - "An error has ocurred initializing {ApplicationName}: {Err}" - ], - "message": "An error has ocurred initializing {ApplicationName}: {Err}", - "translation": "Ha ocurrido un error inicializando {ApplicationName}: {Err}", - "placeholders": [ - { - "id": "ApplicationName", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "applicationName" - }, - { - "id": "Err", - "string": "%[2]v", - "type": "error", - "underlyingType": "interface{Error() string}", - "argNum": 2, - "expr": "err" - } - ] - }, { "id": "Checking status...", "message": "Checking status...", @@ -197,7 +189,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" }, { "id": "City", @@ -220,7 +212,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -235,7 +227,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -255,7 +247,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -270,7 +262,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -290,7 +282,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] } diff --git a/locales/es/messages.gotext.json b/locales/es/messages.gotext.json index 606134d..dc4f16f 100644 --- a/locales/es/messages.gotext.json +++ b/locales/es/messages.gotext.json @@ -1,6 +1,24 @@ { "language": "es", "messages": [ + { + "id": [ + "errorMsg", + "An error has ocurred initializing the VPN: {Err}" + ], + "message": "An error has ocurred initializing the VPN: {Err}", + "translation": "Un error ha ocurrido inicializando VPN: {Err}", + "placeholders": [ + { + "id": "Err", + "string": "%[1]v", + "type": "error", + "underlyingType": "interface{Error() string}", + "argNum": 1, + "expr": "err" + } + ] + }, { "id": [ "donationText", @@ -15,7 +33,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" } ] }, @@ -38,7 +56,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName", @@ -46,7 +64,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName_1", @@ -54,7 +72,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Version", @@ -103,7 +121,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Err", @@ -120,32 +138,6 @@ "message": "Error starting VPN", "translation": "Error arrancando la VPN" }, - { - "id": [ - "errorMsg", - "An error has ocurred initializing {ApplicationName}: {Err}" - ], - "message": "An error has ocurred initializing {ApplicationName}: {Err}", - "translation": "Un error ha ocurrido inicializando {ApplicationName}: {Err}", - "placeholders": [ - { - "id": "ApplicationName", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "applicationName" - }, - { - "id": "Err", - "string": "%[2]v", - "type": "error", - "underlyingType": "interface{Error() string}", - "argNum": 2, - "expr": "err" - } - ] - }, { "id": "Checking status...", "message": "Checking status...", @@ -197,7 +189,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" }, { "id": "City", @@ -220,7 +212,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -235,7 +227,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -255,7 +247,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -270,7 +262,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -290,7 +282,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] } diff --git a/locales/fr/messages.gotext.json b/locales/fr/messages.gotext.json index 7acdd75..718898d 100644 --- a/locales/fr/messages.gotext.json +++ b/locales/fr/messages.gotext.json @@ -1,6 +1,24 @@ { "language": "fr", "messages": [ + { + "id": [ + "errorMsg", + "An error has ocurred initializing the VPN: {Err}" + ], + "message": "An error has ocurred initializing the VPN: {Err}", + "translation": "Une erreur est survenue lors de l'initialisation de VPN: {Err}", + "placeholders": [ + { + "id": "Err", + "string": "%[1]v", + "type": "error", + "underlyingType": "interface{Error() string}", + "argNum": 1, + "expr": "err" + } + ] + }, { "id": [ "donationText", @@ -15,7 +33,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" } ] }, @@ -38,7 +56,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName", @@ -46,7 +64,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName_1", @@ -54,7 +72,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Version", @@ -103,7 +121,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Err", @@ -120,32 +138,6 @@ "message": "Error starting VPN", "translation": "Erreur du démarrage du RPV" }, - { - "id": [ - "errorMsg", - "An error has ocurred initializing {ApplicationName}: {Err}" - ], - "message": "An error has ocurred initializing {ApplicationName}: {Err}", - "translation": "Une erreur est survenue lors de l'initialisation de {ApplicationName} : {Err}", - "placeholders": [ - { - "id": "ApplicationName", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "applicationName" - }, - { - "id": "Err", - "string": "%[2]v", - "type": "error", - "underlyingType": "interface{Error() string}", - "argNum": 2, - "expr": "err" - } - ] - }, { "id": "Checking status...", "message": "Checking status...", @@ -197,7 +189,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" }, { "id": "City", @@ -220,7 +212,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -235,7 +227,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -255,7 +247,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -270,7 +262,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -290,7 +282,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] } diff --git a/locales/lt/messages.gotext.json b/locales/lt/messages.gotext.json index aac9c46..601ba13 100644 --- a/locales/lt/messages.gotext.json +++ b/locales/lt/messages.gotext.json @@ -1,6 +1,24 @@ { "language": "lt", "messages": [ + { + "id": [ + "errorMsg", + "An error has ocurred initializing the VPN: {Err}" + ], + "message": "An error has ocurred initializing the VPN: {Err}", + "translation": "Inicijuojant VPN, įvyko klaida: {Err}", + "placeholders": [ + { + "id": "Err", + "string": "%[1]v", + "type": "error", + "underlyingType": "interface{Error() string}", + "argNum": 1, + "expr": "err" + } + ] + }, { "id": [ "donationText", @@ -15,7 +33,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" } ] }, @@ -38,7 +56,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName", @@ -46,7 +64,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName_1", @@ -54,7 +72,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Version", @@ -103,7 +121,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Err", @@ -120,32 +138,6 @@ "message": "Error starting VPN", "translation": "Klaida paleidžiant VPN" }, - { - "id": [ - "errorMsg", - "An error has ocurred initializing {ApplicationName}: {Err}" - ], - "message": "An error has ocurred initializing {ApplicationName}: {Err}", - "translation": "Inicijuojant {ApplicationName}, įvyko klaida: {Err}", - "placeholders": [ - { - "id": "ApplicationName", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "applicationName" - }, - { - "id": "Err", - "string": "%[2]v", - "type": "error", - "underlyingType": "interface{Error() string}", - "argNum": 2, - "expr": "err" - } - ] - }, { "id": "Checking status...", "message": "Checking status...", @@ -197,7 +189,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" }, { "id": "City", @@ -220,7 +212,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -235,7 +227,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -255,7 +247,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -270,7 +262,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -290,7 +282,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] } diff --git a/locales/nl/messages.gotext.json b/locales/nl/messages.gotext.json index cadc77c..296f77e 100644 --- a/locales/nl/messages.gotext.json +++ b/locales/nl/messages.gotext.json @@ -1,6 +1,24 @@ { "language": "nl", "messages": [ + { + "id": [ + "errorMsg", + "An error has ocurred initializing the VPN: {Err}" + ], + "message": "An error has ocurred initializing the VPN: {Err}", + "translation": "Er heeft zich een fout voorgedaan bij het initialiseren van VPN: {Err}", + "placeholders": [ + { + "id": "Err", + "string": "%[1]v", + "type": "error", + "underlyingType": "interface{Error() string}", + "argNum": 1, + "expr": "err" + } + ] + }, { "id": [ "donationText", @@ -15,7 +33,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" } ] }, @@ -38,7 +56,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName", @@ -46,7 +64,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName_1", @@ -54,7 +72,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Version", @@ -103,7 +121,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Err", @@ -120,32 +138,6 @@ "message": "Error starting VPN", "translation": "Fout bij het opstarten van de VPN" }, - { - "id": [ - "errorMsg", - "An error has ocurred initializing {ApplicationName}: {Err}" - ], - "message": "An error has ocurred initializing {ApplicationName}: {Err}", - "translation": "Er heeft zich een fout voorgedaan bij het initialiseren van {ApplicationName}: {Err}", - "placeholders": [ - { - "id": "ApplicationName", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "applicationName" - }, - { - "id": "Err", - "string": "%[2]v", - "type": "error", - "underlyingType": "interface{Error() string}", - "argNum": 2, - "expr": "err" - } - ] - }, { "id": "Checking status...", "message": "Checking status...", @@ -197,7 +189,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" }, { "id": "City", @@ -220,7 +212,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -235,7 +227,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -255,7 +247,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -270,7 +262,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -290,7 +282,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] } diff --git a/locales/pt-BR/messages.gotext.json b/locales/pt-BR/messages.gotext.json index cd879f0..b83033c 100644 --- a/locales/pt-BR/messages.gotext.json +++ b/locales/pt-BR/messages.gotext.json @@ -1,6 +1,24 @@ { "language": "pt-BR", "messages": [ + { + "id": [ + "errorMsg", + "An error has ocurred initializing the VPN: {Err}" + ], + "message": "An error has ocurred initializing the VPN: {Err}", + "translation": "Um erro ocorreu na inicialização de VPN: {Err}", + "placeholders": [ + { + "id": "Err", + "string": "%[1]v", + "type": "error", + "underlyingType": "interface{Error() string}", + "argNum": 1, + "expr": "err" + } + ] + }, { "id": [ "donationText", @@ -15,7 +33,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" } ] }, @@ -38,7 +56,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName", @@ -46,7 +64,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "ApplicationName_1", @@ -54,7 +72,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Version", @@ -103,7 +121,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "n.conf.ApplicationName" }, { "id": "Err", @@ -120,32 +138,6 @@ "message": "Error starting VPN", "translation": "Erro ao iniciar a VPN" }, - { - "id": [ - "errorMsg", - "An error has ocurred initializing {ApplicationName}: {Err}" - ], - "message": "An error has ocurred initializing {ApplicationName}: {Err}", - "translation": "Um erro ocorreu na inicialização de {ApplicationName}: {Err}", - "placeholders": [ - { - "id": "ApplicationName", - "string": "%[1]s", - "type": "string", - "underlyingType": "string", - "argNum": 1, - "expr": "applicationName" - }, - { - "id": "Err", - "string": "%[2]v", - "type": "error", - "underlyingType": "interface{Error() string}", - "argNum": 2, - "expr": "err" - } - ] - }, { "id": "Checking status...", "message": "Checking status...", @@ -197,7 +189,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" }, { "id": "City", @@ -220,7 +212,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -235,7 +227,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -255,7 +247,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -270,7 +262,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] }, @@ -290,7 +282,7 @@ "type": "string", "underlyingType": "string", "argNum": 1, - "expr": "applicationName" + "expr": "bt.conf.ApplicationName" } ] } diff --git a/main.go b/main.go deleted file mode 100644 index 2683a88..0000000 --- a/main.go +++ /dev/null @@ -1,156 +0,0 @@ -// 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 . - -package main - -import ( - "flag" - "fmt" - "io" - "log" - "os" - "path" - "runtime" - - "0xacab.org/leap/bitmask-systray/bitmask" - "github.com/jmshal/go-locale" - "golang.org/x/text/message" -) - -const ( - provider = "riseup.net" - applicationName = "RiseupVPN" -) - -var version string -var printer *message.Printer - -func main() { - // on OSX sometimes the systray doesn't work (bitmask-systray#52) - // locking the main thread into an OS thread fixes the problem - runtime.LockOSThread() - - logger, err := configureLogger() - if err != nil { - log.Println("Can't configure logger: ", err) - } else { - defer logger.Close() - } - - conf := parseConfig() - initPrinter() - - flag.BoolVar(&conf.SelectGateway, "select-gateway", false, "Enable gateway selection") - versionFlag := flag.Bool("version", false, "Version of the bitmask-systray") - flag.Parse() - if *versionFlag { - fmt.Println(version) - os.Exit(0) - } - - bt := bmTray{conf: conf} - go initialize(conf, &bt) - bt.start() -} - -func initialize(conf *systrayConfig, bt *bmTray) { - if _, err := os.Stat(bitmask.ConfigPath); os.IsNotExist(err) { - os.MkdirAll(bitmask.ConfigPath, os.ModePerm) - } - - err := acquirePID() - if err != nil { - log.Fatal(err) - } - defer releasePID() - - notify := newNotificator(conf) - - b, err := initBitmask() - if err != nil { - notify.initFailure(err) - return - } - defer b.Close() - go checkAndStartBitmask(b, notify, conf) - go listenSignals(b) - - as := newAutostart(applicationName, getIconPath()) - err = as.Enable() - if err != nil { - log.Printf("Error enabling autostart: %v", err) - } - bt.loop(b, notify, as) -} - -func checkAndStartBitmask(b bitmask.Bitmask, notify *notificator, conf *systrayConfig) { - err := checkAndInstallHelpers(b, notify) - if err != nil { - log.Printf("Is bitmask running? %v", err) - os.Exit(1) - } - err = maybeStartVPN(b, conf) - if err != nil { - log.Println("Error starting VPN: ", err) - notify.errorStartingVPN(err) - } -} - -func checkAndInstallHelpers(b bitmask.Bitmask, notify *notificator) error { - helpers, priviledge, err := b.VPNCheck() - if (err != nil && err.Error() == "nopolkit") || (err == nil && !priviledge) { - log.Printf("No polkit found") - notify.authAgent() - } else if err != nil { - log.Printf("Error checking vpn: %v", err) - notify.errorStartingVPN(err) - return err - } - - if !helpers { - err = b.InstallHelpers() - if err != nil { - log.Println("Error installing helpers: ", err) - } - } - return nil -} - -func maybeStartVPN(b bitmask.Bitmask, conf *systrayConfig) error { - if conf.UserStoppedVPN { - return nil - } - - err := b.StartVPN(provider) - conf.setUserStoppedVPN(false) - return err -} - -func configureLogger() (io.Closer, error) { - logFile, err := os.OpenFile(path.Join(bitmask.ConfigPath, "systray.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) - if err == nil { - log.SetOutput(io.MultiWriter(logFile, os.Stderr)) - } - return logFile, err -} - -func initPrinter() { - locale, err := go_locale.DetectLocale() - if err != nil { - log.Println("Error detecting the system locale: ", err) - } - - printer = message.NewPrinter(message.MatchLanguage(locale, "en")) -} diff --git a/notificator.go b/notificator.go deleted file mode 100644 index c2988be..0000000 --- a/notificator.go +++ /dev/null @@ -1,164 +0,0 @@ -// 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 . - -package main - -import ( - "io/ioutil" - "os" - "path" - "runtime" - "time" - - "0xacab.org/leap/go-dialog" - "github.com/skratchdot/open-golang/open" -) - -const ( - donationText = `The %s service is expensive to run. Because we don't want to store personal information about you, there is no accounts or billing for this service. But if you want the service to continue, donate at least $5 each month. - -Do you want to donate now?` - aboutText = `%[1]s is an easy, fast, and secure VPN service from riseup.net. %[1]s does not require a user account, keep logs, or track you in any way. - -This service is paid for entirely by donations from users like you. Please donate at https://riseup.net/vpn/donate. - -By using this application, you agree to the Terms of Service available at https://riseup.net/tos. This service is provide as-is, without any warranty, and is intended for people who work to make the world a better place. - - -%[1]v version: %[2]s` - missingAuthAgent = `Could not find a polkit authentication agent. Please run one and try again.` - errorStartingVPN = `Can't connect to %s: %v` - svgFileName = "riseupvpn.svg" -) - -type notificator struct { - conf *systrayConfig -} - -func newNotificator(conf *systrayConfig) *notificator { - n := notificator{conf} - go n.donations() - return &n -} - -func (n *notificator) donations() { - for { - time.Sleep(time.Hour) - if n.conf.needsNotification() { - letsDonate := dialog.Message(printer.Sprintf(donationText, applicationName)). - Title(printer.Sprintf("Donate")). - Icon(getIconPath()). - YesNo() - n.conf.setNotification() - if letsDonate { - open.Run("https://riseup.net/vpn/donate") - n.conf.setDonated() - } - } - } -} - -func (n *notificator) about(version string) { - if version == "" && os.Getenv("SNAP") != "" { - _version, err := ioutil.ReadFile(os.Getenv("SNAP") + "/snap/version.txt") - if err == nil { - version = string(_version) - } - } - dialog.Message(printer.Sprintf(aboutText, applicationName, version)). - Title(printer.Sprintf("About")). - Icon(getIconPath()). - Info() -} - -func (n *notificator) initFailure(err error) { - dialog.Message(err.Error()). - Title(printer.Sprintf("Initialization error")). - Icon(getIconPath()). - Error() -} - -func (n *notificator) authAgent() { - dialog.Message(printer.Sprintf(missingAuthAgent)). - Title(printer.Sprintf("Missing authentication agent")). - Icon(getIconPath()). - Error() -} - -func (n *notificator) errorStartingVPN(err error) { - dialog.Message(printer.Sprintf(errorStartingVPN, applicationName, err)). - Title(printer.Sprintf("Error starting VPN")). - Icon(getIconPath()). - Error() -} - -func getIconPath() string { - gopath := os.Getenv("GOPATH") - if gopath == "" { - gopath = path.Join(os.Getenv("HOME"), "go") - } - - if runtime.GOOS == "windows" { - icoPath := `C:\Program Files\RiseupVPN\riseupvpn.ico` - if fileExist(icoPath) { - return icoPath - } - icoPath = path.Join(gopath, "src", "0xacab.org", "leap", "riseup_vpn", "assets", "riseupvpn.ico") - if fileExist(icoPath) { - return icoPath - } - return "" - } - - if runtime.GOOS == "darwin" { - icnsPath := "/Applications/RiseupVPN.app/Contents/Resources/app.icns" - if fileExist(icnsPath) { - return icnsPath - } - icnsPath = path.Join(gopath, "src", "0xacab.org", "leap", "riseup_vpn", "assets", "riseupvpn.icns") - if fileExist(icnsPath) { - return icnsPath - } - return "" - } - - snapPath := os.Getenv("SNAP") - if snapPath != "" { - return snapPath + "/snap/gui/riseupvpn.svg" - } - - wd, _ := os.Getwd() - svgPath := path.Join(wd, svgFileName) - if fileExist(svgPath) { - return svgPath - } - - svgPath = "/usr/share/riseupvpn/riseupvpn.svg" - if fileExist(svgPath) { - return svgPath - } - - svgPath = path.Join(gopath, "src", "0xacab.org", "leap", "bitmask-systray", svgFileName) - if fileExist(svgPath) { - return svgPath - } - - return "" -} - -func fileExist(filePath string) bool { - _, err := os.Stat(filePath) - return err == nil -} diff --git a/pid.go b/pid.go deleted file mode 100644 index 2c283ac..0000000 --- a/pid.go +++ /dev/null @@ -1,99 +0,0 @@ -package main - -import ( - "fmt" - "io/ioutil" - "log" - "os" - "path/filepath" - "strconv" - "strings" - "syscall" - - "0xacab.org/leap/bitmask-systray/bitmask" - "github.com/mitchellh/go-ps" -) - -var pidFile = filepath.Join(bitmask.ConfigPath, "systray.pid") - -func acquirePID() error { - pid := syscall.Getpid() - current, err := getPID() - if err != nil { - return err - } - - if current != pid && pidRunning(current) { - return fmt.Errorf("Another systray is running with pid: %d", current) - } - - return setPID(pid) -} - -func releasePID() error { - pid := syscall.Getpid() - current, err := getPID() - if err != nil { - return err - } - if current != 0 && current != pid { - return fmt.Errorf("Can't release pid file, is not own by this process") - } - - if current == pid { - return os.Remove(pidFile) - } - return nil -} - -func getPID() (int, error) { - _, err := os.Stat(pidFile) - if os.IsNotExist(err) { - return 0, nil - } - if err != nil { - return 0, err - } - - file, err := os.Open(pidFile) - if err != nil { - return 0, err - } - defer file.Close() - - b, err := ioutil.ReadAll(file) - if err != nil { - return 0, err - } - if len(b) == 0 { - return 0, nil - } - return strconv.Atoi(string(b)) -} - -func setPID(pid int) error { - file, err := os.Create(pidFile) - if err != nil { - return err - } - defer file.Close() - - _, err = file.WriteString(fmt.Sprintf("%d", pid)) - return err -} - -func pidRunning(pid int) bool { - if pid == 0 { - return false - } - proc, err := ps.FindProcess(pid) - if err != nil { - log.Printf("An error ocurred finding process: %v", err) - return false - } - if proc == nil { - return false - } - log.Printf("There is a running process with the pid %d and executable: %s", pid, proc.Executable()) - return strings.Contains(os.Args[0], proc.Executable()) -} diff --git a/pid_test.go b/pid_test.go deleted file mode 100644 index 2c92641..0000000 --- a/pid_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package main - -import ( - "syscall" - "testing" -) - -const ( - invalidPid = 345678 -) - -func TestPidRunning(t *testing.T) { - pid := syscall.Getpid() - if !pidRunning(pid) { - t.Errorf("pid %v is not running", pid) - } - - if pidRunning(invalidPid) { - t.Errorf("pid %v is running", invalidPid) - } -} diff --git a/pkg/bitmask/autostart.go b/pkg/bitmask/autostart.go new file mode 100644 index 0000000..ebab428 --- /dev/null +++ b/pkg/bitmask/autostart.go @@ -0,0 +1,32 @@ +// 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 . + +package bitmask + +// Autostart holds the functions to enable and disable the application autostart +type Autostart interface { + Disable() error + Enable() error +} + +type dummyAutostart struct{} + +func (a *dummyAutostart) Disable() error { + return nil +} + +func (a *dummyAutostart) Enable() error { + return nil +} diff --git a/pkg/bitmask/bitmask.go b/pkg/bitmask/bitmask.go new file mode 100644 index 0000000..a7aabaa --- /dev/null +++ b/pkg/bitmask/bitmask.go @@ -0,0 +1,30 @@ +// 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 . + +package bitmask + +type Bitmask interface { + GetStatusCh() <-chan string + Close() + Version() (string, error) + StartVPN(provider string) error + StopVPN() error + ReloadFirewall() error + GetStatus() (string, error) + InstallHelpers() error + VPNCheck() (helpers bool, priviledge bool, err error) + ListGateways(provider string) ([]string, error) + UseGateway(name string) error +} diff --git a/pkg/bitmask/bitmaskd.go b/pkg/bitmask/bitmaskd.go new file mode 100644 index 0000000..ad4da31 --- /dev/null +++ b/pkg/bitmask/bitmaskd.go @@ -0,0 +1,44 @@ +// +build bitmaskd +// 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 . + +package bitmask + +import ( + "errors" + "log" + + "0xacab.org/leap/bitmask-systray/pkg/bitmaskd" + "golang.org/x/text/message" +) + +const ( + notRunning = `Is bitmaskd running? Start bitmask and try again.` +) + +// Init bitmask +func Init(printer *message.Printer) (Bitmask, error) { + b, err := bitmaskd.Init() + if err != nil { + log.Printf("An error ocurred starting bitmaskd: %v", err) + err = errors.New(printer.Sprintf(notRunning)) + } + return b, err +} + +// NewAutostart creates a handler for the autostart of your platform +func NewAutostart(appName string, iconPath string) Autostart { + return &dummyAutostart{} +} diff --git a/pkg/bitmask/standalone.go b/pkg/bitmask/standalone.go new file mode 100644 index 0000000..f3f7602 --- /dev/null +++ b/pkg/bitmask/standalone.go @@ -0,0 +1,74 @@ +// +build !bitmaskd +// 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 . + +package bitmask + +import ( + "errors" + "fmt" + "log" + "os" + "path/filepath" + "regexp" + + "0xacab.org/leap/bitmask-systray/pkg/standalone" + pmautostart "github.com/ProtonMail/go-autostart" + "golang.org/x/text/message" +) + +const ( + errorMsg = `An error has ocurred initializing the VPN: %v` +) + +// Init bitmask +func Init(printer *message.Printer) (Bitmask, error) { + b, err := standalone.Init() + if err != nil { + log.Printf("An error ocurred starting standalone bitmask: %v", err) + err = errors.New(printer.Sprintf(errorMsg, err)) + } + return b, err +} + +// NewAutostart creates a handler for the autostart of your platform +func NewAutostart(appName string, iconPath string) Autostart { + exec := os.Args + if os.Getenv("SNAP") != "" { + re := regexp.MustCompile("/snap/([^/]*)/") + match := re.FindStringSubmatch(os.Args[0]) + if len(match) > 1 { + snapName := match[1] + exec = []string{fmt.Sprintf("/snap/bin/%s.launcher", snapName)} + } else { + log.Printf("Snap binary has unknown path: %v", os.Args[0]) + } + } + + if exec[0][:2] == "./" || exec[0][:2] == ".\\" { + var err error + exec[0], err = filepath.Abs(exec[0]) + if err != nil { + log.Printf("Error making the path absolute directory: %v", err) + } + } + + return &pmautostart.App{ + Name: appName, + Exec: exec, + DisplayName: appName, + Icon: iconPath, + } +} diff --git a/pkg/bitmaskd/events.go b/pkg/bitmaskd/events.go new file mode 100644 index 0000000..3c8bb2c --- /dev/null +++ b/pkg/bitmaskd/events.go @@ -0,0 +1,50 @@ +// 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 . + +package bitmaskd + +import ( + "log" + "net/http" +) + +const ( + statusEvent = "VPN_STATUS_CHANGED" +) + +func (b *Bitmask) eventsHandler() { + b.send("events", "register", statusEvent) + client := &http.Client{ + Timeout: 0, + } + for { + resJSON, err := send(b.apiToken, client, "events", "poll") + res, ok := resJSON.([]interface{}) + if err != nil || !ok || len(res) < 1 { + continue + } + event, ok := res[0].(string) + if !ok || event != statusEvent { + continue + } + + status, err := b.GetStatus() + if err != nil { + log.Printf("Error receiving status: %v", err) + continue + } + b.statusCh <- status + } +} diff --git a/pkg/bitmaskd/main.go b/pkg/bitmaskd/main.go new file mode 100644 index 0000000..f2ca650 --- /dev/null +++ b/pkg/bitmaskd/main.go @@ -0,0 +1,163 @@ +// 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 . + +package bitmaskd + +import ( + "bytes" + "encoding/json" + "errors" + "io/ioutil" + "log" + "net/http" + "path" + "time" + + "0xacab.org/leap/bitmask-systray/pkg/config" +) + +const ( + timeout = time.Second * 15 + url = "http://localhost:7070/API/" + headerAuth = "X-Bitmask-Auth" +) + +// Bitmask holds the bitmask client data +type Bitmask struct { + client *http.Client + apiToken string + statusCh chan string +} + +// Init the connection to bitmask +func Init() (*Bitmask, error) { + statusCh := make(chan string) + client := &http.Client{ + Timeout: timeout, + } + + err := waitForBitmaskd() + if err != nil { + return nil, err + } + + apiToken, err := getToken() + if err != nil { + return nil, err + } + + b := Bitmask{client, apiToken, statusCh} + go b.eventsHandler() + return &b, nil +} + +// GetStatusCh returns a channel that will recieve VPN status changes +func (b *Bitmask) GetStatusCh() <-chan string { + return b.statusCh +} + +// Close the connection to bitmask +func (b *Bitmask) Close() { + _, err := b.send("core", "stop") + if err != nil { + log.Printf("Got an error stopping bitmaskd: %v", err) + } +} + +// Version gets the bitmask version string +func (b *Bitmask) Version() (string, error) { + res, err := b.send("core", "version") + if err != nil { + return "", err + } + return res["version_core"].(string), nil +} + +func waitForBitmaskd() error { + var err error + for i := 0; i < 30; i++ { + resp, err := http.Post(url, "", nil) + if err == nil { + resp.Body.Close() + return nil + } + log.Printf("Bitmask is not ready (iteration %d): %v", i, err) + time.Sleep(1 * time.Second) + } + return err +} + +func (b *Bitmask) send(parts ...interface{}) (map[string]interface{}, error) { + resJSON, err := send(b.apiToken, b.client, parts...) + if err != nil { + return nil, err + } + result, ok := resJSON.(map[string]interface{}) + if !ok { + return nil, errors.New("Not valid response") + } + return result, nil +} + +func send(apiToken string, client *http.Client, parts ...interface{}) (interface{}, error) { + apiSection, _ := parts[0].(string) + reqBody, err := json.Marshal(parts[1:]) + if err != nil { + return nil, err + } + req, err := http.NewRequest("POST", url+apiSection, bytes.NewReader(reqBody)) + if err != nil { + return nil, err + } + req.Header.Add(headerAuth, apiToken) + + resp, err := client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + resJSON, err := ioutil.ReadAll(resp.Body) + if err != nil { + return nil, err + } + return parseResponse(resJSON) +} + +func parseResponse(resJSON []byte) (interface{}, error) { + var response struct { + Result interface{} + Error string + } + err := json.Unmarshal(resJSON, &response) + if response.Error != "" { + return nil, errors.New(response.Error) + } + return response.Result, err +} + +func getToken() (string, error) { + var err error + path := path.Join(config.Path, "authtoken") + for i := 0; i < 30; i++ { + b, err := ioutil.ReadFile(path) + if err == nil { + return string(b), nil + } + log.Printf("Auth token is not ready (iteration %d): %v", i, err) + time.Sleep(1 * time.Second) + } + return "", err +} diff --git a/pkg/bitmaskd/vpn.go b/pkg/bitmaskd/vpn.go new file mode 100644 index 0000000..48ce7dd --- /dev/null +++ b/pkg/bitmaskd/vpn.go @@ -0,0 +1,98 @@ +// 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 . + +package bitmaskd + +import ( + "errors" + "log" +) + +// StartVPN for provider +func (b *Bitmask) StartVPN(provider string) error { + _, err := b.send("vpn", "start", provider) + return err +} + +// StopVPN or cancel +func (b *Bitmask) StopVPN() error { + _, err := b.send("vpn", "stop") + 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") + if err != nil { + return "", err + } + return res["status"].(string), nil +} + +// InstallHelpers into the system +func (b *Bitmask) InstallHelpers() error { + _, err := b.send("vpn", "install") + return err +} + +// 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) { + res, err := b.send("vpn", "check", "") + if err != nil { + return false, false, err + } + installed, ok := res["installed"].(bool) + if !ok { + log.Printf("Unexpected value for installed on 'vpn check': %v", res) + return false, false, errors.New("Invalid response format") + } + privcheck, ok := res["privcheck"].(bool) + if !ok { + log.Printf("Unexpected value for privcheck on 'vpn check': %v", res) + return installed, false, errors.New("Invalid response format") + } + return installed, privcheck, nil +} + +// ListGateways return the names of the gateways +func (b *Bitmask) ListGateways(provider string) ([]string, error) { + res, err := b.send("vpn", "list") + if err != nil { + return nil, err + } + + names := []string{} + locations, ok := res[provider].([]interface{}) + if !ok { + return nil, errors.New("Can't read the locations for provider " + provider) + } + for i := range locations { + loc := locations[i].(map[string]interface{}) + names = append(names, loc["name"].(string)) + } + return names, nil +} + +// UseGateway selects name as the default gateway +func (b *Bitmask) UseGateway(name string) error { + _, err := b.send("vpn", "locations", name) + return err +} diff --git a/pkg/config/darwin.go b/pkg/config/darwin.go new file mode 100644 index 0000000..123060c --- /dev/null +++ b/pkg/config/darwin.go @@ -0,0 +1,24 @@ +// +build darwin +// 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 . + +package config + +import ( + "os" +) + +// Path for the config files +var Path = os.Getenv("HOME") + "/Library/Preferences/leap" diff --git a/pkg/config/logger.go b/pkg/config/logger.go new file mode 100644 index 0000000..09d96b7 --- /dev/null +++ b/pkg/config/logger.go @@ -0,0 +1,31 @@ +// 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 . + +package config + +import ( + "io" + "log" + "os" +) + +//ConfigureLogger to write logs into a file as well as the stderr +func ConfigureLogger(logPath string) (io.Closer, error) { + logFile, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + if err == nil { + log.SetOutput(io.MultiWriter(logFile, os.Stderr)) + } + return logFile, err +} diff --git a/pkg/config/unix.go b/pkg/config/unix.go new file mode 100644 index 0000000..7425f5b --- /dev/null +++ b/pkg/config/unix.go @@ -0,0 +1,24 @@ +// +build !windows,!darwin +// 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 . + +package config + +import ( + "os" +) + +// Path for the config files +var Path = os.Getenv("HOME") + "/.config/leap" diff --git a/pkg/config/windows.go b/pkg/config/windows.go new file mode 100644 index 0000000..8977842 --- /dev/null +++ b/pkg/config/windows.go @@ -0,0 +1,22 @@ +// +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 . + +package config + +import "os" + +// Path for the config files +var Path = os.Getenv("LOCALAPPDATA") + "\\leap" diff --git a/pkg/standalone/bonafide.go b/pkg/standalone/bonafide.go new file mode 100644 index 0000000..c4d588e --- /dev/null +++ b/pkg/standalone/bonafide.go @@ -0,0 +1,311 @@ +// 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 . + +package standalone + +import ( + "crypto/tls" + "crypto/x509" + "encoding/json" + "fmt" + "io" + "io/ioutil" + "log" + "math/rand" + "net/http" + "sort" + "strconv" + "strings" + "time" +) + +const ( + certAPI = "https://api.black.riseup.net/1/cert" + eipAPI = "https://api.black.riseup.net/1/config/eip-service.json" + geolocationAPI = "https://api.black.riseup.net:9001/json" + secondsPerHour = 60 * 60 +) + +var ( + caCert = []byte(`-----BEGIN CERTIFICATE----- +MIIFjTCCA3WgAwIBAgIBATANBgkqhkiG9w0BAQ0FADBZMRgwFgYDVQQKDA9SaXNl +dXAgTmV0d29ya3MxGzAZBgNVBAsMEmh0dHBzOi8vcmlzZXVwLm5ldDEgMB4GA1UE +AwwXUmlzZXVwIE5ldHdvcmtzIFJvb3QgQ0EwHhcNMTQwNDI4MDAwMDAwWhcNMjQw +NDI4MDAwMDAwWjBZMRgwFgYDVQQKDA9SaXNldXAgTmV0d29ya3MxGzAZBgNVBAsM +Emh0dHBzOi8vcmlzZXVwLm5ldDEgMB4GA1UEAwwXUmlzZXVwIE5ldHdvcmtzIFJv +b3QgQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC76J4ciMJ8Sg0m +TP7DF2DT9zNe0Csk4myoMFC57rfJeqsAlJCv1XMzBmXrw8wq/9z7XHv6n/0sWU7a +7cF2hLR33ktjwODlx7vorU39/lXLndo492ZBhXQtG1INMShyv+nlmzO6GT7ESfNE +LliFitEzwIegpMqxCIHXFuobGSCWF4N0qLHkq/SYUMoOJ96O3hmPSl1kFDRMtWXY +iw1SEKjUvpyDJpVs3NGxeLCaA7bAWhDY5s5Yb2fA1o8ICAqhowurowJpW7n5ZuLK +5VNTlNy6nZpkjt1QycYvNycffyPOFm/Q/RKDlvnorJIrihPkyniV3YY5cGgP+Qkx +HUOT0uLA6LHtzfiyaOqkXwc4b0ZcQD5Vbf6Prd20Ppt6ei0zazkUPwxld3hgyw58 +m/4UIjG3PInWTNf293GngK2Bnz8Qx9e/6TueMSAn/3JBLem56E0WtmbLVjvko+LF +PM5xA+m0BmuSJtrD1MUCXMhqYTtiOvgLBlUm5zkNxALzG+cXB28k6XikXt6MRG7q +hzIPG38zwkooM55yy5i1YfcIi5NjMH6A+t4IJxxwb67MSb6UFOwg5kFokdONZcwj +shczHdG9gLKSBIvrKa03Nd3W2dF9hMbRu//STcQxOailDBQCnXXfAATj9pYzdY4k +ha8VCAREGAKTDAex9oXf1yRuktES4QIDAQABo2AwXjAdBgNVHQ4EFgQUC4tdmLVu +f9hwfK4AGliaet5KkcgwDgYDVR0PAQH/BAQDAgIEMAwGA1UdEwQFMAMBAf8wHwYD +VR0jBBgwFoAUC4tdmLVuf9hwfK4AGliaet5KkcgwDQYJKoZIhvcNAQENBQADggIB +AGzL+GRnYu99zFoy0bXJKOGCF5XUXP/3gIXPRDqQf5g7Cu/jYMID9dB3No4Zmf7v +qHjiSXiS8jx1j/6/Luk6PpFbT7QYm4QLs1f4BlfZOti2KE8r7KRDPIecUsUXW6P/ +3GJAVYH/+7OjA39za9AieM7+H5BELGccGrM5wfl7JeEz8in+V2ZWDzHQO4hMkiTQ +4ZckuaL201F68YpiItBNnJ9N5nHr1MRiGyApHmLXY/wvlrOpclh95qn+lG6/2jk7 +3AmihLOKYMlPwPakJg4PYczm3icFLgTpjV5sq2md9bRyAg3oPGfAuWHmKj2Ikqch +Td5CHKGxEEWbGUWEMP0s1A/JHWiCbDigc4Cfxhy56CWG4q0tYtnc2GMw8OAUO6Wf +Xu5pYKNkzKSEtT/MrNJt44tTZWbKV/Pi/N2Fx36my7TgTUj7g3xcE9eF4JV2H/sg +tsK3pwE0FEqGnT4qMFbixQmc8bGyuakr23wjMvfO7eZUxBuWYR2SkcP26sozF9PF +tGhbZHQVGZUTVPyvwahMUEhbPGVerOW0IYpxkm0x/eaWdTc4vPpf/rIlgbAjarnJ +UN9SaWRlWKSdP4haujnzCoJbM7dU9bjvlGZNyXEekgeT0W2qFeGGp+yyUWw8tNsp +0BuC1b7uW/bBn/xKm319wXVDvBgZgcktMolak39V7DVO +-----END CERTIFICATE-----`) +) + +type bonafide struct { + client httpClient + tzOffsetHours int + eip *eipService + defaultGateway string +} + +type httpClient interface { + Post(url, contentType string, body io.Reader) (resp *http.Response, err error) +} + +type eipService struct { + Gateways []gateway + Locations map[string]struct { + CountryCode string + Hemisphere string + Name string + Timezone string + } + OpenvpnConfiguration map[string]interface{} `json:"openvpn_configuration"` +} + +type gateway struct { + Capabilities struct { + Ports []string + Protocols []string + } + Host string + IPAddress string `json:"ip_address"` + Location string +} + +type gatewayDistance struct { + gateway gateway + distance int +} + +type geoLocation struct { + IPAddress string `json:"ip"` + Country string `json:"cc"` + City string `json:"city"` + Latitude float64 `json:"lat"` + Longitude float64 `json:"lon"` + SortedGateways []string `json:"gateways"` +} + +func newBonafide() *bonafide { + certs := x509.NewCertPool() + certs.AppendCertsFromPEM(caCert) + client := &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + RootCAs: certs, + }, + }, + } + _, tzOffsetSeconds := time.Now().Zone() + tzOffsetHours := tzOffsetSeconds / secondsPerHour + + return &bonafide{ + client: client, + tzOffsetHours: tzOffsetHours, + eip: nil, + defaultGateway: "", + } +} + +func (b *bonafide) getCertPem() ([]byte, error) { + resp, err := b.client.Post(certAPI, "", nil) + if err != nil { + return nil, err + } + defer resp.Body.Close() + if resp.StatusCode != 200 { + return nil, fmt.Errorf("get vpn cert has failed with status: %s", resp.Status) + } + + return ioutil.ReadAll(resp.Body) +} + +func (b *bonafide) getGateways() ([]gateway, error) { + if b.eip == nil { + err := b.fetchEipJSON() + if err != nil { + return nil, err + } + } + + return b.eip.Gateways, nil +} + +func (b *bonafide) setDefaultGateway(name string) { + b.defaultGateway = name + b.sortGateways() +} + +func (b *bonafide) getOpenvpnArgs() ([]string, error) { + if b.eip == nil { + err := b.fetchEipJSON() + if err != nil { + return nil, err + } + } + + args := []string{} + for arg, value := range b.eip.OpenvpnConfiguration { + switch v := value.(type) { + case string: + args = append(args, "--"+arg) + args = append(args, strings.Split(v, " ")...) + case bool: + if v { + args = append(args, "--"+arg) + } + default: + log.Printf("Unknown openvpn argument type: %s - %v", arg, value) + } + } + return args, nil +} + +func (b *bonafide) fetchGeolocation() ([]string, error) { + resp, err := b.client.Post(geolocationAPI, "", nil) + if err != nil { + return nil, err + } + defer resp.Body.Close() + if resp.StatusCode != 200 { + return nil, fmt.Errorf("get geolocation failed with status: %s", resp.Status) + } + + geo := &geoLocation{} + dataJSON, err := ioutil.ReadAll(resp.Body) + err = json.Unmarshal(dataJSON, &geo) + if err != nil { + _ = fmt.Errorf("get vpn cert has failed with status: %s", resp.Status) + return nil, err + } + + return geo.SortedGateways, nil + +} + +func (b *bonafide) fetchEipJSON() error { + resp, err := b.client.Post(eipAPI, "", nil) + if err != nil { + return err + } + defer resp.Body.Close() + if resp.StatusCode != 200 { + return fmt.Errorf("get eip json has failed with status: %s", resp.Status) + } + + var eip eipService + decoder := json.NewDecoder(resp.Body) + err = decoder.Decode(&eip) + if err != nil { + return err + } + + b.eip = &eip + b.sortGateways() + return nil +} + +func (b *bonafide) sortGatewaysByGeolocation(geolocatedGateways []string) []gatewayDistance { + gws := []gatewayDistance{} + + for i, host := range geolocatedGateways { + for _, gw := range b.eip.Gateways { + if gw.Host == host { + gws = append(gws, gatewayDistance{gw, i}) + } + } + } + return gws +} + +func (b *bonafide) sortGatewaysByTimezone() []gatewayDistance { + gws := []gatewayDistance{} + + for _, gw := range b.eip.Gateways { + distance := 13 + if gw.Location == b.defaultGateway { + distance = -1 + } else { + gwOffset, err := strconv.Atoi(b.eip.Locations[gw.Location].Timezone) + if err != nil { + log.Printf("Error sorting gateways: %v", err) + } else { + distance = tzDistance(b.tzOffsetHours, gwOffset) + } + } + gws = append(gws, gatewayDistance{gw, distance}) + } + rand.Seed(time.Now().UnixNano()) + cmp := func(i, j int) bool { + if gws[i].distance == gws[j].distance { + return rand.Intn(2) == 1 + } + return gws[i].distance < gws[j].distance + } + sort.Slice(gws, cmp) + return gws +} + +func (b *bonafide) sortGateways() { + gws := []gatewayDistance{} + + geolocatedGateways, _ := b.fetchGeolocation() + + if len(geolocatedGateways) > 0 { + gws = b.sortGatewaysByGeolocation(geolocatedGateways) + } else { + log.Printf("Falling back to timezone heuristic for gateway selection") + gws = b.sortGatewaysByTimezone() + } + + for i, gw := range gws { + b.eip.Gateways[i] = gw.gateway + } +} + +func tzDistance(offset1, offset2 int) int { + abs := func(x int) int { + if x < 0 { + return -x + } + return x + } + distance := abs(offset1 - offset2) + if distance > 12 { + distance = 24 - distance + } + return distance +} diff --git a/pkg/standalone/bonafide_integration_test.go b/pkg/standalone/bonafide_integration_test.go new file mode 100644 index 0000000..5beb8aa --- /dev/null +++ b/pkg/standalone/bonafide_integration_test.go @@ -0,0 +1,58 @@ +// +build integration +// 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 . + +package standalone + +import ( + "bytes" + "testing" +) + +var ( + privateKeyHeader = []byte("-----BEGIN RSA PRIVATE KEY-----") + certHeader = []byte("-----BEGIN CERTIFICATE-----") +) + +func TestIntegrationGetCert(t *testing.T) { + b := newBonafide() + cert, err := b.getCertPem() + if err != nil { + t.Fatal("getCert returned an error: ", err) + } + + if !bytes.Contains(cert, privateKeyHeader) { + t.Errorf("No private key present: \n%q", cert) + } + + if !bytes.Contains(cert, certHeader) { + t.Errorf("No cert present: \n%q", cert) + } +} + +func TestGetGateways(t *testing.T) { + b := newBonafide() + gateways, err := b.getGateways() + if err != nil { + t.Fatal("getGateways returned an error: ", err) + } + + for _, gw := range gateways { + if gw.IPAddress == "5.79.86.180" { + return + } + } + t.Errorf("5.79.86.180 not in the list") +} diff --git a/pkg/standalone/bonafide_test.go b/pkg/standalone/bonafide_test.go new file mode 100644 index 0000000..7bfcaa0 --- /dev/null +++ b/pkg/standalone/bonafide_test.go @@ -0,0 +1,100 @@ +// 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 . + +package standalone + +import ( + "io" + "io/ioutil" + "net/http" + "os" + "reflect" + "testing" +) + +const ( + certPath = "testdata/cert" + eipPath = "testdata/eip-service.json" +) + +type client struct { + path string +} + +func (c client) Post(url, contentType string, body io.Reader) (resp *http.Response, err error) { + f, err := os.Open(c.path) + return &http.Response{ + Body: f, + StatusCode: 200, + }, err +} + +func TestGetCert(t *testing.T) { + b := bonafide{client: client{certPath}} + cert, err := b.getCertPem() + if err != nil { + t.Fatal("getCert returned an error: ", err) + } + + f, err := os.Open(certPath) + if err != nil { + t.Fatal("Can't open ", certPath, ": ", err) + } + defer f.Close() + + certData, err := ioutil.ReadAll(f) + if err != nil { + t.Fatal("Can't read all: ", err) + } + if !reflect.DeepEqual(certData, cert) { + t.Errorf("cert doesn't match") + } +} + +func TestGatewayTzLocation(t *testing.T) { + // tzOffset -> location + values := map[int]string{ + -12: "c", + -10: "a", + -5: "a", + -3: "a", + -1: "b", + 0: "b", + 2: "b", + 5: "c", + 8: "c", + 12: "c", + } + + for tzOffset, location := range values { + b := bonafide{ + client: client{eipPath}, + tzOffsetHours: tzOffset, + } + gateways, err := b.getGateways() + if err != nil { + t.Errorf("getGateways returned an error: %v", err) + continue + } + if len(gateways) < 4 { + t.Errorf("Wrong number of gateways: %d", len(gateways)) + continue + + } + if gateways[0].Location != location { + t.Errorf("Wrong location for tz %d: %s, expected: %s", tzOffset, gateways[0].Location, location) + } + } +} diff --git a/pkg/standalone/launcher.go b/pkg/standalone/launcher.go new file mode 100644 index 0000000..4dc4761 --- /dev/null +++ b/pkg/standalone/launcher.go @@ -0,0 +1,97 @@ +// +build !linux +// 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 . + +package standalone + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "io/ioutil" + "net/http" +) + +const ( + helperAddr = "http://localhost:7171" +) + +type launcher struct { +} + +func newLauncher() (*launcher, error) { + return &launcher{}, nil +} + +func (l *launcher) close() error { + return nil +} + +func (l *launcher) openvpnStart(flags ...string) error { + byteFlags, err := json.Marshal(flags) + if err != nil { + return err + } + return l.send("/openvpn/start", byteFlags) +} + +func (l *launcher) openvpnStop() error { + return l.send("/openvpn/stop", nil) +} + +func (l *launcher) firewallStart(gateways []gateway) error { + ipList := make([]string, len(gateways)) + for i, gw := range gateways { + ipList[i] = gw.IPAddress + } + byteIPs, err := json.Marshal(ipList) + if err != nil { + return err + } + return l.send("/firewall/start", byteIPs) +} + +func (l *launcher) firewallStop() error { + return l.send("/firewall/stop", nil) +} + +func (l *launcher) firewallIsUp() bool { + res, err := http.Post(helperAddr+"/firewall/isup", "", nil) + if err != nil { + return false + } + defer res.Body.Close() + + return res.StatusCode == http.StatusOK +} + +func (l *launcher) send(path string, body []byte) error { + var reader io.Reader + if body != nil { + reader = bytes.NewReader(body) + } + res, err := http.Post(helperAddr+path, "", reader) + if err != nil { + return err + } + defer res.Body.Close() + + resErr, err := ioutil.ReadAll(res.Body) + if len(resErr) > 0 { + return fmt.Errorf("Helper returned an error: %q", resErr) + } + return err +} diff --git a/pkg/standalone/launcher_linux.go b/pkg/standalone/launcher_linux.go new file mode 100644 index 0000000..672eb1f --- /dev/null +++ b/pkg/standalone/launcher_linux.go @@ -0,0 +1,139 @@ +// +build linux +// 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 . + +package standalone + +import ( + "errors" + "log" + "os" + "os/exec" +) + +const ( + systemOpenvpnPath = "/usr/sbin/openvpn" + snapOpenvpnPath = "/snap/bin/riseup-vpn.openvpn" +) + +var bitmaskRootPaths = []string{ + "/usr/sbin/bitmask-root", + "/usr/local/sbin/bitmask-root", +} + +type launcher struct { + openvpnCh chan []string +} + +func newLauncher() (*launcher, error) { + l := launcher{make(chan []string, 1)} + go l.openvpnRunner() + return &l, nil +} + +func (l *launcher) close() error { + return nil +} + +func (l *launcher) openvpnStart(flags ...string) error { + log.Println("openvpn start: ", flags) + arg := []string{"openvpn", "start", getOpenvpnPath()} + arg = append(arg, flags...) + l.openvpnCh <- arg + return nil +} + +func (l *launcher) openvpnStop() error { + l.openvpnCh <- nil + log.Println("openvpn stop") + return runBitmaskRoot("openvpn", "stop") +} + +func (l *launcher) firewallStart(gateways []gateway) error { + log.Println("firewall start") + arg := []string{"firewall", "start"} + for _, gw := range gateways { + arg = append(arg, gw.IPAddress) + } + return runBitmaskRoot(arg...) +} + +func (l *launcher) firewallStop() error { + log.Println("firewall stop") + return runBitmaskRoot("firewall", "stop") +} + +func (l *launcher) firewallIsUp() bool { + err := runBitmaskRoot("firewall", "isup") + return err == nil +} + +func (l *launcher) openvpnRunner(arg ...string) { + running := false + runOpenvpn := func(arg []string) { + for running { + err := runBitmaskRoot(arg...) + if err != nil { + log.Printf("An error ocurred running openvpn: %v", err) + } + } + } + + for arg := range l.openvpnCh { + if arg == nil { + running = false + } else { + running = true + go runOpenvpn(arg) + } + } +} + +func runBitmaskRoot(arg ...string) error { + bitmaskRoot, err := bitmaskRootPath() + if err != nil { + return err + } + arg = append([]string{bitmaskRoot}, arg...) + + cmd := exec.Command("pkexec", arg...) + err = cmd.Run() + if err != nil { + return err + } + return nil +} + +func bitmaskRootPath() (string, error) { + if os.Getenv("SNAP") != "" { + path := "/snap/bin/riseup-vpn.bitmask-root" + if _, err := os.Stat(path); !os.IsNotExist(err) { + return path, nil + } + } + for _, path := range bitmaskRootPaths { + if _, err := os.Stat(path); !os.IsNotExist(err) { + return path, nil + } + } + return "", errors.New("No bitmask-root found") +} + +func getOpenvpnPath() string { + if os.Getenv("SNAP") != "" { + return snapOpenvpnPath + } + return systemOpenvpnPath +} diff --git a/pkg/standalone/main.go b/pkg/standalone/main.go new file mode 100644 index 0000000..f7e1976 --- /dev/null +++ b/pkg/standalone/main.go @@ -0,0 +1,80 @@ +// 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 . + +package standalone + +import ( + "io/ioutil" + "log" + "os" + + "github.com/apparentlymart/go-openvpn-mgmt/openvpn" +) + +// Bitmask holds the bitmask client data +type Bitmask struct { + tempdir string + statusCh chan string + managementClient *openvpn.MgmtClient + bonafide *bonafide + launch *launcher +} + +// Init the connection to bitmask +func Init() (*Bitmask, error) { + statusCh := make(chan string, 10) + tempdir, err := ioutil.TempDir("", "leap-") + if err != nil { + return nil, err + } + bonafide := newBonafide() + launch, err := newLauncher() + if err != nil { + return nil, err + } + b := Bitmask{tempdir, statusCh, nil, bonafide, launch} + + err = b.StopVPN() + if err != nil { + return nil, err + } + err = ioutil.WriteFile(b.getCaCertPath(), caCert, 0600) + + go b.openvpnManagement() + return &b, err +} + +// GetStatusCh returns a channel that will recieve VPN status changes +func (b *Bitmask) GetStatusCh() <-chan string { + return b.statusCh +} + +// Close the connection to bitmask +func (b *Bitmask) Close() { + b.StopVPN() + err := b.launch.close() + if err != nil { + log.Printf("There was an error closing the launcher: %v", err) + } + err = os.RemoveAll(b.tempdir) + if err != nil { + log.Printf("There was an error removing temp dir: %v", err) + } +} + +// Version gets the bitmask version string +func (b *Bitmask) Version() (string, error) { + return "", nil +} diff --git a/pkg/standalone/status.go b/pkg/standalone/status.go new file mode 100644 index 0000000..42c4687 --- /dev/null +++ b/pkg/standalone/status.go @@ -0,0 +1,91 @@ +// 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 . + +package standalone + +import ( + "fmt" + "log" + + "github.com/apparentlymart/go-openvpn-mgmt/openvpn" +) + +const ( + On = "on" + Off = "off" + Starting = "starting" + Stopping = "stopping" + Failed = "failed" +) + +var statusNames = map[string]string{ + "CONNECTING": Starting, + "WAIT": Starting, + "AUTH": Starting, + "GET_CONFIG": Starting, + "ASSIGN_IP": Starting, + "ADD_ROUTES": Starting, + "CONNECTED": On, + "RECONNECTING": Starting, + "EXITING": Stopping, + "OFF": Off, + "FAILED": Off, +} + +func (b *Bitmask) openvpnManagement() { + // TODO: we should warn the user on ListenAndServe errors + newConnection := func(conn openvpn.IncomingConn) { + eventCh := make(chan openvpn.Event, 10) + log.Println("New connection into the management") + b.managementClient = conn.Open(eventCh) + b.managementClient.SetStateEvents(true) + b.eventHandler(eventCh) + } + log.Fatal(openvpn.ListenAndServe( + fmt.Sprintf("%s:%s", openvpnManagementAddr, openvpnManagementPort), + openvpn.IncomingConnHandlerFunc(newConnection), + )) +} + +func (b *Bitmask) eventHandler(eventCh <-chan openvpn.Event) { + // TODO: we are reporing only openvpn status, missing firewall status + for event := range eventCh { + log.Printf("Event: %v", event) + stateEvent, ok := event.(*openvpn.StateEvent) + if !ok { + continue + } + status, ok := statusNames[stateEvent.NewState()] + if ok { + b.statusCh <- status + } + } + b.statusCh <- Off +} + +func (b *Bitmask) getOpenvpnState() (string, error) { + if b.managementClient == nil { + return "", fmt.Errorf("No management connected") + } + stateEvent, err := b.managementClient.LatestState() + if err != nil { + return "", err + } + status, ok := statusNames[stateEvent.NewState()] + if !ok { + return "", fmt.Errorf("Unkonw status") + } + return status, nil +} diff --git a/pkg/standalone/testdata/cert b/pkg/standalone/testdata/cert new file mode 100644 index 0000000..4968b3f --- /dev/null +++ b/pkg/standalone/testdata/cert @@ -0,0 +1,54 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpQIBAAKCAQEA3TQAmZs9U6e1xqQqVWkb132AGXdaO97bsXPOrrKUp63hKeXD +2OQbmG96H3COi0uubVFQT1cAmpuym2COtgahQlnv42p0u2CYsBqfrCHw3iSK7nf6 +Q8RaG2oUIvlQj5m4DUk1wfRBgG5z0pN2HwFWmgheoT0RnOelTO3vcLCaSJA6PF4M +Wehg5ScXi9wr0vibKsANpqab3oUxcHEYcNcKfJKRnXryJx6ctLrRp1WPv3JAXLnn +oUtQ00S0dSHrLED5yPwGFV08q4bkv54qFai2cPO8ITReC6BpvrilBzOjT6fjCmzm +6MCwBot7aRHYcWJgfp7H2b2S7T2qhnC4c2u6mwIDAQABAoIBAFue83SsOS2SNJdv +Xd18qLyLzeg+aFCOET8h8YSokSwWuEGLWqBWcxujaNjm3RPTKA89c9848RYY0VTM +HLBGdLqv183BRVJrQzMGBAbfFA5e4nC9nxo8lPnv6SFHVNf12qceILcSPaM9nJmm +3HEhM8afGtr8GXR8+hmwH9H0RCMzXIjO1//WrY3nfOP8LRuQpSnnhsfZRyngWhot +xsJlDP5plFNw7J/PDLtbjnbOXOktv0fhhq7aWR+A+0s0627r7Tidk1YoNwusYJeB +uKrzNW1+c7Z9xl2yvMQ6+0Wry7A5YUVYP/BakYb/f/skB4ox/zz8vcWeQ4ShZ7m6 +LwPN0ckCgYEA+9wjSBbOlksath3QrJywikD1sQYFOdNrINTBFQnuipKOYKLJNhQM +OzKHY1OiO7G6FcEvz9gKYMpMyMOs8TsISyKPNOXLpnwpgIUx6WRo6qxgEuyWLpBb +Q3Kodl1a/q51dw56pPDEATKjSB1CjXXzm717m5FimH5csPKj9SzrGecCgYEA4Nbb +QML1Jh9cu7TvlK3WqbAFJa4Mx/0+OQ+5xlhbs/ygn3/AZiSsPWdNK11XJ25jgGJw +AucXr/kHgwJX23kFpCYB3zZE0Vh/hOqk/KlUFmptuADIDOAVst0v8MqBLZpZessN +TXph5VBT6P51Oz/ZLC67uno02R1vUhDMB5VCyy0CgYEAoriZuuuxUXz4pw0gU0Vw +8gICOvsuySuFHVMX5GXkTnddsaW65kuRk3WT72KLgJHVLlUAdQKZwesyLMvvonOH +ajPL3ltRdiDmF3j2xFnxRx1TfSaJ6U+vBya/HKo4Li+9CMy8BHDh0fxLbj4pT4gT +el2zzNDjqK6LaG976t24j6UCgYEAyTD5uRW7cIWX4Y+i4xQ7hlQwBuucHEkMKNtd +jZL7XC+vO4qBi+U9CyUo9KjtmCc7emKbgL1xgNICWsT6ATZmSeCIxEg3hG0Ajtu5 +Dy4mRHiv/XsViA/s2sT6ZSmQNlJrx2lzWeUtPJmIvHEWThJwLw0Sh2dbavzf5DuL +ly2FO3ECgYEA5AKnPQo45I+abEA/zKHsKHCqBPEbIaZpJJTaiInrsLiGJf+WzN4N +zr/VAzvY+v0X5RgZmROY5ZLPVf2fTeVNzU5WzoB78hHOI67YI2Sbq7jZlatOgX4z +Ur2BQdT0bW6VINYpDLUvS4goW5p0nQbGItdk69yyef1v3NDbCJ/Sg+Q= +-----END RSA PRIVATE KEY----- +-----BEGIN CERTIFICATE----- +MIIEnDCCAoSgAwIBAgIRAJzr5xxPLgDD+drzU+5p8cgwDQYJKoZIhvcNAQELBQAw +dTEYMBYGA1UECgwPUmlzZXVwIE5ldHdvcmtzMRswGQYDVQQLDBJodHRwczovL3Jp +c2V1cC5uZXQxPDA6BgNVBAMMM1Jpc2V1cCBOZXR3b3JrcyBSb290IENBIChjbGll +bnQgY2VydGlmaWNhdGVzIG9ubHkhKTAeFw0xODEwMjMwMDAwMDBaFw0xOTAxMjMw +MDAwMDBaMC0xKzApBgNVBAMMIlVOTElNSVRFRDVmbzdsMmxiY3g0OWR5ZzR5MWY4 +YXN3YXcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDdNACZmz1Tp7XG +pCpVaRvXfYAZd1o73tuxc86uspSnreEp5cPY5BuYb3ofcI6LS65tUVBPVwCam7Kb +YI62BqFCWe/janS7YJiwGp+sIfDeJIrud/pDxFobahQi+VCPmbgNSTXB9EGAbnPS +k3YfAVaaCF6hPRGc56VM7e9wsJpIkDo8XgxZ6GDlJxeL3CvS+JsqwA2mppvehTFw +cRhw1wp8kpGdevInHpy0utGnVY+/ckBcueehS1DTRLR1IessQPnI/AYVXTyrhuS/ +nioVqLZw87whNF4LoGm+uKUHM6NPp+MKbObowLAGi3tpEdhxYmB+nsfZvZLtPaqG +cLhza7qbAgMBAAGjbzBtMB0GA1UdDgQWBBRwXpI96PjilFPrkK+CHUPia++ISTAL +BgNVHQ8EBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwIwCQYDVR0TBAIwADAfBgNV +HSMEGDAWgBQX9BvV5SoBAU1rol02CikJlmWARjANBgkqhkiG9w0BAQsFAAOCAgEA +ryNFLixuicVRepocY2lTSY0cpG0eRmLuYJGupk9KeiLA5YEFzl4ZfXJLi+9UHoUR +Bgfe6QYLBb77nO24CoeiMJQw6s593ctMLiMU++fjew31gNp6aA9DmvbLd+fNuLyO +XObRtGw99M37cyf3ZS2SEbTBr4NBp/r3OCyUYsxPYKOzEkr9kNYa8ZZSI960i7/R +/aiq2qemQaOQHTlmrhcBuARJoRVVlLnn2zgLSVm6ptbFLNtAk0lWriUT/WlRmn8j +Cyn/JOuo/1wtrK1dHkaXr8bkEq1oFQzcwMN85hrZKWU0BCehELZtiUg8grqaX/sf +/jaXD61FEqWjIXeGqY/K6ruosZCw2R8sQYzTuQNHMjxmx+J3pch7dMmJPbmA3HW2 +nA7yVp51SX8iZ26zb40S7GG6RNesU+BZxz05XVLt1GwyLx/uNxS4rFpKAT/+ifWG +3Y1j1lMqBxx6RbuqiM1TWqU7Xtzu3hf8ytP5qP7kudXn1TyNtpZCIrzbTXbLnYiD +nH4ZQEWGyAKBOz41eOcG6EXn0TznSGE593ueXBeFnsym7i9MjoOWNGaJ7UbkipfX +FzxirlY5IRkWnmHCL0wGUg6YGnZ1OQ8VBBGb/dBPRMDwA7zWvoM7+3yDLR3aRaLH +mTQzNzu3jy6CRdlpIUcPRcgbniySip1jJrHRYBui+9w= +-----END CERTIFICATE----- diff --git a/pkg/standalone/testdata/eip-service.json b/pkg/standalone/testdata/eip-service.json new file mode 100644 index 0000000..d5f2413 --- /dev/null +++ b/pkg/standalone/testdata/eip-service.json @@ -0,0 +1,113 @@ +{ + "gateways": [ + { + "capabilities": { + "adblock": false, + "filter_dns": false, + "limited": false, + "ports": [ + "443" + ], + "protocols": [ + "tcp" + ], + "transport": [ + "openvpn" + ], + "user_ips": false + }, + "host": "1.example.com", + "ip_address": "1.1.1.1", + "location": "a" + }, + { + "capabilities": { + "adblock": false, + "filter_dns": false, + "limited": false, + "ports": [ + "443" + ], + "protocols": [ + "tcp" + ], + "transport": [ + "openvpn" + ], + "user_ips": false + }, + "host": "2.example.com", + "ip_address": "2.2.2.2", + "location": "b" + }, + { + "capabilities": { + "adblock": false, + "filter_dns": false, + "limited": false, + "ports": [ + "443" + ], + "protocols": [ + "tcp" + ], + "transport": [ + "openvpn" + ], + "user_ips": false + }, + "host": "3.example.com", + "ip_address": "3.3.3.3", + "location": "b" + }, + { + "capabilities": { + "adblock": false, + "filter_dns": false, + "limited": false, + "ports": [ + "443" + ], + "protocols": [ + "tcp" + ], + "transport": [ + "openvpn" + ], + "user_ips": false + }, + "host": "4.example.com", + "ip_address": "4.4.4.4", + "location": "c" + } + ], + "locations": { + "a": { + "country_code": "AA", + "hemisphere": "N", + "name": "a", + "timezone": "-5" + }, + "b": { + "country_code": "BB", + "hemisphere": "S", + "name": "b", + "timezone": "+1" + }, + "c": { + "country_code": "CC", + "hemisphere": "N", + "name": "c", + "timezone": "+8" + } + }, + "openvpn_configuration": { + "auth": "SHA1", + "cipher": "AES-128-CBC", + "keepalive": "10 30", + "tls-cipher": "DHE-RSA-AES128-SHA", + "tun-ipv6": true + }, + "serial": 1, + "version": 1 +} diff --git a/pkg/standalone/vpn.go b/pkg/standalone/vpn.go new file mode 100644 index 0000000..941d444 --- /dev/null +++ b/pkg/standalone/vpn.go @@ -0,0 +1,156 @@ +// 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 . + +package standalone + +import ( + "io/ioutil" + "os" + "path" +) + +const ( + openvpnManagementAddr = "127.0.0.1" + openvpnManagementPort = "6061" +) + +// StartVPN for provider +func (b *Bitmask) StartVPN(provider string) error { + gateways, err := b.bonafide.getGateways() + if err != nil { + return err + } + certPemPath, err := b.getCert() + if err != nil { + return err + } + + err = b.launch.firewallStart(gateways) + if err != nil { + return err + } + + arg, err := b.bonafide.getOpenvpnArgs() + if err != nil { + return err + } + for _, gw := range gateways { + arg = append(arg, "--remote", gw.IPAddress, "443", "tcp4") + } + arg = append(arg, + "--verb", "1", + "--management-client", + "--management", openvpnManagementAddr, openvpnManagementPort, + "--ca", b.getCaCertPath(), + "--cert", certPemPath, + "--key", certPemPath) + return b.launch.openvpnStart(arg...) +} + +func (b *Bitmask) getCert() (certPath string, err error) { + certPath = b.getCertPemPath() + + if _, err := os.Stat(certPath); os.IsNotExist(err) { + cert, err := b.bonafide.getCertPem() + if err != nil { + return "", err + } + err = ioutil.WriteFile(certPath, cert, 0600) + } + + return certPath, err +} + +// StopVPN or cancel +func (b *Bitmask) StopVPN() error { + err := b.launch.firewallStop() + if err != nil { + return err + } + 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() + if err != nil { + status = Off + } + if status == Off && b.launch.firewallIsUp() { + return Failed, nil + } + return status, nil +} + +// InstallHelpers into the system +func (b *Bitmask) InstallHelpers() error { + // TODO + return nil +} + +// 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 +} + +// ListGateways return the names of the gateways +func (b *Bitmask) ListGateways(provider string) ([]string, error) { + gateways, err := b.bonafide.getGateways() + if err != nil { + return nil, err + } + gatewayNames := make([]string, len(gateways)) + for i, gw := range gateways { + gatewayNames[i] = gw.Location + } + return gatewayNames, nil +} + +// UseGateway selects name as the default gateway +func (b *Bitmask) UseGateway(name string) error { + b.bonafide.setDefaultGateway(name) + return nil +} + +func (b *Bitmask) getCertPemPath() string { + return path.Join(b.tempdir, "openvpn.pem") +} + +func (b *Bitmask) getCaCertPath() string { + return path.Join(b.tempdir, "cacert.pem") +} diff --git a/pkg/systray/config.go b/pkg/systray/config.go new file mode 100644 index 0000000..75a7a8a --- /dev/null +++ b/pkg/systray/config.go @@ -0,0 +1,97 @@ +// 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 . + +package systray + +import ( + "encoding/json" + "os" + "path" + "time" + + "0xacab.org/leap/bitmask-systray/pkg/config" + "golang.org/x/text/message" +) + +const ( + oneDay = time.Hour * 24 + oneMonth = oneDay * 30 +) + +var ( + configPath = path.Join(config.Path, "systray.json") +) + +// SystrayConfig holds the configuration of the systray +type SystrayConfig struct { + LastNotification time.Time + Donated time.Time + SelectGateway bool + UserStoppedVPN bool + Provider string `json:"-"` + ApplicationName string `json:"-"` + Version string `json:"-"` + Printer *message.Printer `json:"-"` +} + +// ParseConfig reads the configuration from the configuration file +func ParseConfig() *SystrayConfig { + var conf SystrayConfig + + f, err := os.Open(configPath) + if err != nil { + conf.save() + return &conf + } + defer f.Close() + + dec := json.NewDecoder(f) + err = dec.Decode(&conf) + return &conf +} + +func (c *SystrayConfig) setUserStoppedVPN(vpnStopped bool) error { + c.UserStoppedVPN = vpnStopped + return c.save() +} + +func (c *SystrayConfig) hasDonated() bool { + return c.Donated.Add(oneMonth).After(time.Now()) +} + +func (c *SystrayConfig) needsNotification() bool { + return !c.hasDonated() && c.LastNotification.Add(oneDay).Before(time.Now()) +} + +func (c *SystrayConfig) setNotification() error { + c.LastNotification = time.Now() + return c.save() +} + +func (c *SystrayConfig) setDonated() error { + c.Donated = time.Now() + return c.save() +} + +func (c *SystrayConfig) save() error { + f, err := os.Create(configPath) + if err != nil { + return err + } + defer f.Close() + + enc := json.NewEncoder(f) + return enc.Encode(c) +} diff --git a/pkg/systray/notificator.go b/pkg/systray/notificator.go new file mode 100644 index 0000000..e23b9d1 --- /dev/null +++ b/pkg/systray/notificator.go @@ -0,0 +1,164 @@ +// 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 . + +package systray + +import ( + "io/ioutil" + "os" + "path" + "runtime" + "time" + + "0xacab.org/leap/go-dialog" + "github.com/skratchdot/open-golang/open" +) + +const ( + donationText = `The %s service is expensive to run. Because we don't want to store personal information about you, there is no accounts or billing for this service. But if you want the service to continue, donate at least $5 each month. + +Do you want to donate now?` + aboutText = `%[1]s is an easy, fast, and secure VPN service from riseup.net. %[1]s does not require a user account, keep logs, or track you in any way. + +This service is paid for entirely by donations from users like you. Please donate at https://riseup.net/vpn/donate. + +By using this application, you agree to the Terms of Service available at https://riseup.net/tos. This service is provide as-is, without any warranty, and is intended for people who work to make the world a better place. + + +%[1]v version: %[2]s` + missingAuthAgent = `Could not find a polkit authentication agent. Please run one and try again.` + errorStartingVPN = `Can't connect to %s: %v` + svgFileName = "riseupvpn.svg" +) + +type notificator struct { + conf *SystrayConfig +} + +func newNotificator(conf *SystrayConfig) *notificator { + n := notificator{conf} + go n.donations() + return &n +} + +func (n *notificator) donations() { + for { + time.Sleep(time.Hour) + if n.conf.needsNotification() { + letsDonate := dialog.Message(n.conf.Printer.Sprintf(donationText, n.conf.ApplicationName)). + Title(n.conf.Printer.Sprintf("Donate")). + Icon(getIconPath()). + YesNo() + n.conf.setNotification() + if letsDonate { + open.Run("https://riseup.net/vpn/donate") + n.conf.setDonated() + } + } + } +} + +func (n *notificator) about(version string) { + if version == "" && os.Getenv("SNAP") != "" { + _version, err := ioutil.ReadFile(os.Getenv("SNAP") + "/snap/version.txt") + if err == nil { + version = string(_version) + } + } + dialog.Message(n.conf.Printer.Sprintf(aboutText, n.conf.ApplicationName, version)). + Title(n.conf.Printer.Sprintf("About")). + Icon(getIconPath()). + Info() +} + +func (n *notificator) initFailure(err error) { + dialog.Message(err.Error()). + Title(n.conf.Printer.Sprintf("Initialization error")). + Icon(getIconPath()). + Error() +} + +func (n *notificator) authAgent() { + dialog.Message(n.conf.Printer.Sprintf(missingAuthAgent)). + Title(n.conf.Printer.Sprintf("Missing authentication agent")). + Icon(getIconPath()). + Error() +} + +func (n *notificator) errorStartingVPN(err error) { + dialog.Message(n.conf.Printer.Sprintf(errorStartingVPN, n.conf.ApplicationName, err)). + Title(n.conf.Printer.Sprintf("Error starting VPN")). + Icon(getIconPath()). + Error() +} + +func getIconPath() string { + gopath := os.Getenv("GOPATH") + if gopath == "" { + gopath = path.Join(os.Getenv("HOME"), "go") + } + + if runtime.GOOS == "windows" { + icoPath := `C:\Program Files\RiseupVPN\riseupvpn.ico` + if fileExist(icoPath) { + return icoPath + } + icoPath = path.Join(gopath, "src", "0xacab.org", "leap", "riseup_vpn", "assets", "riseupvpn.ico") + if fileExist(icoPath) { + return icoPath + } + return "" + } + + if runtime.GOOS == "darwin" { + icnsPath := "/Applications/RiseupVPN.app/Contents/Resources/app.icns" + if fileExist(icnsPath) { + return icnsPath + } + icnsPath = path.Join(gopath, "src", "0xacab.org", "leap", "riseup_vpn", "assets", "riseupvpn.icns") + if fileExist(icnsPath) { + return icnsPath + } + return "" + } + + snapPath := os.Getenv("SNAP") + if snapPath != "" { + return snapPath + "/snap/gui/riseupvpn.svg" + } + + wd, _ := os.Getwd() + svgPath := path.Join(wd, svgFileName) + if fileExist(svgPath) { + return svgPath + } + + svgPath = "/usr/share/riseupvpn/riseupvpn.svg" + if fileExist(svgPath) { + return svgPath + } + + svgPath = path.Join(gopath, "src", "0xacab.org", "leap", "bitmask-systray", svgFileName) + if fileExist(svgPath) { + return svgPath + } + + return "" +} + +func fileExist(filePath string) bool { + _, err := os.Stat(filePath) + return err == nil +} diff --git a/pkg/systray/pid.go b/pkg/systray/pid.go new file mode 100644 index 0000000..6a1b32c --- /dev/null +++ b/pkg/systray/pid.go @@ -0,0 +1,99 @@ +package systray + +import ( + "fmt" + "io/ioutil" + "log" + "os" + "path/filepath" + "strconv" + "strings" + "syscall" + + "0xacab.org/leap/bitmask-systray/pkg/config" + "github.com/mitchellh/go-ps" +) + +var pidFile = filepath.Join(config.Path, "systray.pid") + +func acquirePID() error { + pid := syscall.Getpid() + current, err := getPID() + if err != nil { + return err + } + + if current != pid && pidRunning(current) { + return fmt.Errorf("Another systray is running with pid: %d", current) + } + + return setPID(pid) +} + +func releasePID() error { + pid := syscall.Getpid() + current, err := getPID() + if err != nil { + return err + } + if current != 0 && current != pid { + return fmt.Errorf("Can't release pid file, is not own by this process") + } + + if current == pid { + return os.Remove(pidFile) + } + return nil +} + +func getPID() (int, error) { + _, err := os.Stat(pidFile) + if os.IsNotExist(err) { + return 0, nil + } + if err != nil { + return 0, err + } + + file, err := os.Open(pidFile) + if err != nil { + return 0, err + } + defer file.Close() + + b, err := ioutil.ReadAll(file) + if err != nil { + return 0, err + } + if len(b) == 0 { + return 0, nil + } + return strconv.Atoi(string(b)) +} + +func setPID(pid int) error { + file, err := os.Create(pidFile) + if err != nil { + return err + } + defer file.Close() + + _, err = file.WriteString(fmt.Sprintf("%d", pid)) + return err +} + +func pidRunning(pid int) bool { + if pid == 0 { + return false + } + proc, err := ps.FindProcess(pid) + if err != nil { + log.Printf("An error ocurred finding process: %v", err) + return false + } + if proc == nil { + return false + } + log.Printf("There is a running process with the pid %d and executable: %s", pid, proc.Executable()) + return strings.Contains(os.Args[0], proc.Executable()) +} diff --git a/pkg/systray/pid_test.go b/pkg/systray/pid_test.go new file mode 100644 index 0000000..dda8384 --- /dev/null +++ b/pkg/systray/pid_test.go @@ -0,0 +1,21 @@ +package systray + +import ( + "syscall" + "testing" +) + +const ( + invalidPid = 345678 +) + +func TestPidRunning(t *testing.T) { + pid := syscall.Getpid() + if !pidRunning(pid) { + t.Errorf("pid %v is not running", pid) + } + + if pidRunning(invalidPid) { + t.Errorf("pid %v is running", invalidPid) + } +} diff --git a/pkg/systray/run.go b/pkg/systray/run.go new file mode 100644 index 0000000..0457ed4 --- /dev/null +++ b/pkg/systray/run.go @@ -0,0 +1,103 @@ +// 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 . + +package systray + +import ( + "log" + "os" + + "0xacab.org/leap/bitmask-systray/pkg/bitmask" + "0xacab.org/leap/bitmask-systray/pkg/config" +) + +func Run(conf *SystrayConfig) { + bt := bmTray{conf: conf} + go initialize(conf, &bt) + bt.start() +} + +func initialize(conf *SystrayConfig, bt *bmTray) { + if _, err := os.Stat(config.Path); os.IsNotExist(err) { + os.MkdirAll(config.Path, os.ModePerm) + } + + err := acquirePID() + if err != nil { + log.Fatal(err) + } + defer releasePID() + + notify := newNotificator(conf) + + b, err := bitmask.Init(conf.Printer) + if err != nil { + notify.initFailure(err) + return + } + defer b.Close() + go checkAndStartBitmask(b, notify, conf) + go listenSignals(b) + + as := bitmask.NewAutostart(conf.ApplicationName, getIconPath()) + err = as.Enable() + if err != nil { + log.Printf("Error enabling autostart: %v", err) + } + bt.loop(b, notify, as) +} + +func checkAndStartBitmask(b bitmask.Bitmask, notify *notificator, conf *SystrayConfig) { + err := checkAndInstallHelpers(b, notify) + if err != nil { + log.Printf("Is bitmask running? %v", err) + os.Exit(1) + } + err = maybeStartVPN(b, conf) + if err != nil { + log.Println("Error starting VPN: ", err) + notify.errorStartingVPN(err) + } +} + +func checkAndInstallHelpers(b bitmask.Bitmask, notify *notificator) error { + helpers, priviledge, err := b.VPNCheck() + if (err != nil && err.Error() == "nopolkit") || (err == nil && !priviledge) { + log.Printf("No polkit found") + notify.authAgent() + } else if err != nil { + log.Printf("Error checking vpn: %v", err) + notify.errorStartingVPN(err) + return err + } + + if !helpers { + err = b.InstallHelpers() + if err != nil { + log.Println("Error installing helpers: ", err) + } + } + return nil +} + +func maybeStartVPN(b bitmask.Bitmask, conf *SystrayConfig) error { + if conf.UserStoppedVPN { + return nil + } + + err := b.StartVPN(conf.Provider) + conf.setUserStoppedVPN(false) + return err +} diff --git a/pkg/systray/signal_unix.go b/pkg/systray/signal_unix.go new file mode 100644 index 0000000..06b59ae --- /dev/null +++ b/pkg/systray/signal_unix.go @@ -0,0 +1,34 @@ +// +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 . + +package systray + +import ( + "os" + "os/signal" + "syscall" + + "0xacab.org/leap/bitmask-systray/pkg/bitmask" +) + +func listenSignals(bm bitmask.Bitmask) { + sigusrCh := make(chan os.Signal, 1) + signal.Notify(sigusrCh, syscall.SIGUSR1) + + for range sigusrCh { + bm.ReloadFirewall() + } +} diff --git a/pkg/systray/signal_windows.go b/pkg/systray/signal_windows.go new file mode 100644 index 0000000..f96212c --- /dev/null +++ b/pkg/systray/signal_windows.go @@ -0,0 +1,24 @@ +// +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 . + +package systray + +import ( + "0xacab.org/leap/bitmask-systray/pkg/bitmask" +) + +func listenSignals(bm bitmask.Bitmask) { +} diff --git a/pkg/systray/systray.go b/pkg/systray/systray.go new file mode 100644 index 0000000..3505958 --- /dev/null +++ b/pkg/systray/systray.go @@ -0,0 +1,257 @@ +// 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 . + +package systray + +import ( + "fmt" + "log" + "os" + "os/signal" + "time" + + "0xacab.org/leap/bitmask-systray/icon" + "0xacab.org/leap/bitmask-systray/pkg/bitmask" + "github.com/getlantern/systray" + "github.com/skratchdot/open-golang/open" +) + +type bmTray struct { + bm bitmask.Bitmask + conf *SystrayConfig + notify *notificator + waitCh chan bool + mStatus *systray.MenuItem + mTurnOn *systray.MenuItem + mTurnOff *systray.MenuItem + mHelp *systray.MenuItem + mDonate *systray.MenuItem + mAbout *systray.MenuItem + mQuit *systray.MenuItem + activeGateway *gatewayTray + autostart bitmask.Autostart +} + +type gatewayTray struct { + menuItem *systray.MenuItem + name string +} + +func (bt *bmTray) start() { + // XXX this removes the snap error message, but produces an invisible icon. + // https://0xacab.org/leap/riseup_vpn/issues/44 + // os.Setenv("TMPDIR", "/var/tmp") + systray.Run(bt.onReady, bt.onExit) +} + +func (bt *bmTray) onExit() { + log.Println("Closing systray") +} + +func (bt *bmTray) onReady() { + printer := bt.conf.Printer + systray.SetIcon(icon.Off) + + bt.mStatus = systray.AddMenuItem(printer.Sprintf("Checking status..."), "") + bt.mStatus.Disable() + bt.mTurnOn = systray.AddMenuItem(printer.Sprintf("Turn on"), "") + bt.mTurnOn.Hide() + bt.mTurnOff = systray.AddMenuItem(printer.Sprintf("Turn off"), "") + bt.mTurnOff.Hide() + systray.AddSeparator() + + if bt.conf.SelectGateway { + bt.addGateways() + } + + bt.mHelp = systray.AddMenuItem(printer.Sprintf("Help..."), "") + bt.mDonate = systray.AddMenuItem(printer.Sprintf("Donate..."), "") + bt.mAbout = systray.AddMenuItem(printer.Sprintf("About..."), "") + systray.AddSeparator() + + bt.mQuit = systray.AddMenuItem(printer.Sprintf("Quit"), "") +} + +func (bt *bmTray) loop(bm bitmask.Bitmask, notify *notificator, as bitmask.Autostart) { + bt.bm = bm + bt.notify = notify + bt.autostart = as + + signalCh := make(chan os.Signal, 1) + signal.Notify(signalCh, os.Interrupt) + + ch := bt.bm.GetStatusCh() + if status, err := bt.bm.GetStatus(); err != nil { + log.Printf("Error getting status: %v", err) + } else { + bt.changeStatus(status) + } + + for { + select { + case status := <-ch: + log.Println("status: " + status) + bt.changeStatus(status) + + case <-bt.mTurnOn.ClickedCh: + log.Println("on") + bt.changeStatus("starting") + bt.bm.StartVPN(bt.conf.Provider) + bt.conf.setUserStoppedVPN(false) + case <-bt.mTurnOff.ClickedCh: + log.Println("off") + bt.changeStatus("stopping") + bt.bm.StopVPN() + bt.conf.setUserStoppedVPN(true) + + case <-bt.mHelp.ClickedCh: + open.Run("https://riseup.net/vpn/support") + case <-bt.mDonate.ClickedCh: + bt.conf.setDonated() + open.Run("https://riseup.net/vpn/donate") + case <-bt.mAbout.ClickedCh: + bitmaskVersion, err := bt.bm.Version() + versionStr := bt.conf.Version + if err != nil { + log.Printf("Error getting version: %v", err) + } else if bitmaskVersion != "" { + versionStr = fmt.Sprintf("%s (bitmaskd %s)", bt.conf.Version, bitmaskVersion) + } + bt.notify.about(versionStr) + + case <-bt.mQuit.ClickedCh: + err := bt.autostart.Disable() + if err != nil { + log.Printf("Error disabling autostart: %v", err) + } + systray.Quit() + return + case <-signalCh: + systray.Quit() + return + + case <-time.After(5 * time.Second): + if status, err := bt.bm.GetStatus(); err != nil { + log.Printf("Error getting status: %v", err) + } else { + bt.changeStatus(status) + } + } + } +} + +func (bt *bmTray) addGateways() { + gatewayList, err := bt.bm.ListGateways(bt.conf.Provider) + if err != nil { + log.Printf("Gateway initialization error: %v", err) + return + } + + mGateway := systray.AddMenuItem(bt.conf.Printer.Sprintf("Route traffic through"), "") + mGateway.Disable() + for i, city := range gatewayList { + menuItem := systray.AddMenuItem(city, bt.conf.Printer.Sprintf("Use %s %v gateway", bt.conf.ApplicationName, city)) + gateway := gatewayTray{menuItem, city} + + if i == 0 { + menuItem.Check() + menuItem.SetTitle("*" + city) + bt.activeGateway = &gateway + } else { + menuItem.Uncheck() + } + + go func(gateway gatewayTray) { + for { + <-menuItem.ClickedCh + gateway.menuItem.SetTitle("*" + gateway.name) + gateway.menuItem.Check() + + bt.activeGateway.menuItem.Uncheck() + bt.activeGateway.menuItem.SetTitle(bt.activeGateway.name) + bt.activeGateway = &gateway + + bt.bm.UseGateway(gateway.name) + } + }(gateway) + } + + systray.AddSeparator() +} + +func (bt *bmTray) changeStatus(status string) { + printer := bt.conf.Printer + if bt.waitCh != nil { + bt.waitCh <- true + bt.waitCh = nil + } + + var statusStr string + switch status { + case "on": + systray.SetIcon(icon.On) + bt.mTurnOff.SetTitle(printer.Sprintf("Turn off")) + statusStr = printer.Sprintf("%s on", bt.conf.ApplicationName) + bt.mTurnOn.Hide() + bt.mTurnOff.Show() + + case "off": + systray.SetIcon(icon.Off) + bt.mTurnOn.SetTitle(printer.Sprintf("Turn on")) + statusStr = printer.Sprintf("%s off", bt.conf.ApplicationName) + bt.mTurnOn.Show() + bt.mTurnOff.Hide() + + case "starting": + bt.waitCh = make(chan bool) + go bt.waitIcon() + bt.mTurnOff.SetTitle(printer.Sprintf("Cancel")) + statusStr = printer.Sprintf("Connecting to %s", bt.conf.ApplicationName) + bt.mTurnOn.Hide() + bt.mTurnOff.Show() + + case "stopping": + bt.waitCh = make(chan bool) + go bt.waitIcon() + statusStr = printer.Sprintf("Stopping %s", bt.conf.ApplicationName) + bt.mTurnOn.Hide() + bt.mTurnOff.Hide() + + case "failed": + systray.SetIcon(icon.Blocked) + bt.mTurnOn.SetTitle(printer.Sprintf("Retry")) + bt.mTurnOff.SetTitle(printer.Sprintf("Turn off")) + statusStr = printer.Sprintf("%s blocking internet", bt.conf.ApplicationName) + bt.mTurnOn.Show() + bt.mTurnOff.Show() + } + + systray.SetTooltip(statusStr) + bt.mStatus.SetTitle(statusStr) +} + +func (bt *bmTray) waitIcon() { + icons := [][]byte{icon.Wait0, icon.Wait1, icon.Wait2, icon.Wait3} + for i := 0; true; i = (i + 1) % 4 { + systray.SetIcon(icons[i]) + + select { + case <-bt.waitCh: + return + case <-time.After(time.Millisecond * 500): + continue + } + } +} diff --git a/signal_unix.go b/signal_unix.go deleted file mode 100644 index 37b3908..0000000 --- a/signal_unix.go +++ /dev/null @@ -1,34 +0,0 @@ -// +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 . - -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() - } -} diff --git a/signal_windows.go b/signal_windows.go deleted file mode 100644 index 7e0eb3d..0000000 --- a/signal_windows.go +++ /dev/null @@ -1,24 +0,0 @@ -// +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 . - -package main - -import ( - "0xacab.org/leap/bitmask-systray/bitmask" -) - -func listenSignals(bm bitmask.Bitmask) { -} diff --git a/standalone.go b/standalone.go deleted file mode 100644 index 0808da6..0000000 --- a/standalone.go +++ /dev/null @@ -1,72 +0,0 @@ -// +build !bitmaskd -// 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 . - -package main - -import ( - "errors" - "fmt" - "log" - "os" - "path/filepath" - "regexp" - - "0xacab.org/leap/bitmask-systray/bitmask" - standalone "0xacab.org/leap/bitmask-systray/standalone" - pmautostart "github.com/ProtonMail/go-autostart" -) - -const ( - errorMsg = `An error has ocurred initializing %s: %v` -) - -func initBitmask() (bitmask.Bitmask, error) { - b, err := standalone.Init() - if err != nil { - log.Printf("An error ocurred starting standalone bitmask: %v", err) - err = errors.New(printer.Sprintf(errorMsg, applicationName, err)) - } - return b, err -} - -func newAutostart(appName string, iconPath string) autostart { - exec := os.Args - if os.Getenv("SNAP") != "" { - re := regexp.MustCompile("/snap/([^/]*)/") - match := re.FindStringSubmatch(os.Args[0]) - if len(match) > 1 { - snapName := match[1] - exec = []string{fmt.Sprintf("/snap/bin/%s.launcher", snapName)} - } else { - log.Printf("Snap binary has unknown path: %v", os.Args[0]) - } - } - - if exec[0][:2] == "./" || exec[0][:2] == ".\\" { - var err error - exec[0], err = filepath.Abs(exec[0]) - if err != nil { - log.Printf("Error making the path absolute directory: %v", err) - } - } - - return &pmautostart.App{ - Name: appName, - Exec: exec, - DisplayName: appName, - Icon: iconPath, - } -} diff --git a/standalone/bonafide.go b/standalone/bonafide.go deleted file mode 100644 index 92c1011..0000000 --- a/standalone/bonafide.go +++ /dev/null @@ -1,311 +0,0 @@ -// 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 . - -package bitmask - -import ( - "crypto/tls" - "crypto/x509" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "log" - "math/rand" - "net/http" - "sort" - "strconv" - "strings" - "time" -) - -const ( - certAPI = "https://api.black.riseup.net/1/cert" - eipAPI = "https://api.black.riseup.net/1/config/eip-service.json" - geolocationAPI = "https://api.black.riseup.net:9001/json" - secondsPerHour = 60 * 60 -) - -var ( - caCert = []byte(`-----BEGIN CERTIFICATE----- -MIIFjTCCA3WgAwIBAgIBATANBgkqhkiG9w0BAQ0FADBZMRgwFgYDVQQKDA9SaXNl -dXAgTmV0d29ya3MxGzAZBgNVBAsMEmh0dHBzOi8vcmlzZXVwLm5ldDEgMB4GA1UE -AwwXUmlzZXVwIE5ldHdvcmtzIFJvb3QgQ0EwHhcNMTQwNDI4MDAwMDAwWhcNMjQw -NDI4MDAwMDAwWjBZMRgwFgYDVQQKDA9SaXNldXAgTmV0d29ya3MxGzAZBgNVBAsM -Emh0dHBzOi8vcmlzZXVwLm5ldDEgMB4GA1UEAwwXUmlzZXVwIE5ldHdvcmtzIFJv -b3QgQ0EwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQC76J4ciMJ8Sg0m -TP7DF2DT9zNe0Csk4myoMFC57rfJeqsAlJCv1XMzBmXrw8wq/9z7XHv6n/0sWU7a -7cF2hLR33ktjwODlx7vorU39/lXLndo492ZBhXQtG1INMShyv+nlmzO6GT7ESfNE -LliFitEzwIegpMqxCIHXFuobGSCWF4N0qLHkq/SYUMoOJ96O3hmPSl1kFDRMtWXY -iw1SEKjUvpyDJpVs3NGxeLCaA7bAWhDY5s5Yb2fA1o8ICAqhowurowJpW7n5ZuLK -5VNTlNy6nZpkjt1QycYvNycffyPOFm/Q/RKDlvnorJIrihPkyniV3YY5cGgP+Qkx -HUOT0uLA6LHtzfiyaOqkXwc4b0ZcQD5Vbf6Prd20Ppt6ei0zazkUPwxld3hgyw58 -m/4UIjG3PInWTNf293GngK2Bnz8Qx9e/6TueMSAn/3JBLem56E0WtmbLVjvko+LF -PM5xA+m0BmuSJtrD1MUCXMhqYTtiOvgLBlUm5zkNxALzG+cXB28k6XikXt6MRG7q -hzIPG38zwkooM55yy5i1YfcIi5NjMH6A+t4IJxxwb67MSb6UFOwg5kFokdONZcwj -shczHdG9gLKSBIvrKa03Nd3W2dF9hMbRu//STcQxOailDBQCnXXfAATj9pYzdY4k -ha8VCAREGAKTDAex9oXf1yRuktES4QIDAQABo2AwXjAdBgNVHQ4EFgQUC4tdmLVu -f9hwfK4AGliaet5KkcgwDgYDVR0PAQH/BAQDAgIEMAwGA1UdEwQFMAMBAf8wHwYD -VR0jBBgwFoAUC4tdmLVuf9hwfK4AGliaet5KkcgwDQYJKoZIhvcNAQENBQADggIB -AGzL+GRnYu99zFoy0bXJKOGCF5XUXP/3gIXPRDqQf5g7Cu/jYMID9dB3No4Zmf7v -qHjiSXiS8jx1j/6/Luk6PpFbT7QYm4QLs1f4BlfZOti2KE8r7KRDPIecUsUXW6P/ -3GJAVYH/+7OjA39za9AieM7+H5BELGccGrM5wfl7JeEz8in+V2ZWDzHQO4hMkiTQ -4ZckuaL201F68YpiItBNnJ9N5nHr1MRiGyApHmLXY/wvlrOpclh95qn+lG6/2jk7 -3AmihLOKYMlPwPakJg4PYczm3icFLgTpjV5sq2md9bRyAg3oPGfAuWHmKj2Ikqch -Td5CHKGxEEWbGUWEMP0s1A/JHWiCbDigc4Cfxhy56CWG4q0tYtnc2GMw8OAUO6Wf -Xu5pYKNkzKSEtT/MrNJt44tTZWbKV/Pi/N2Fx36my7TgTUj7g3xcE9eF4JV2H/sg -tsK3pwE0FEqGnT4qMFbixQmc8bGyuakr23wjMvfO7eZUxBuWYR2SkcP26sozF9PF -tGhbZHQVGZUTVPyvwahMUEhbPGVerOW0IYpxkm0x/eaWdTc4vPpf/rIlgbAjarnJ -UN9SaWRlWKSdP4haujnzCoJbM7dU9bjvlGZNyXEekgeT0W2qFeGGp+yyUWw8tNsp -0BuC1b7uW/bBn/xKm319wXVDvBgZgcktMolak39V7DVO ------END CERTIFICATE-----`) -) - -type bonafide struct { - client httpClient - tzOffsetHours int - eip *eipService - defaultGateway string -} - -type httpClient interface { - Post(url, contentType string, body io.Reader) (resp *http.Response, err error) -} - -type eipService struct { - Gateways []gateway - Locations map[string]struct { - CountryCode string - Hemisphere string - Name string - Timezone string - } - OpenvpnConfiguration map[string]interface{} `json:"openvpn_configuration"` -} - -type gateway struct { - Capabilities struct { - Ports []string - Protocols []string - } - Host string - IPAddress string `json:"ip_address"` - Location string -} - -type gatewayDistance struct { - gateway gateway - distance int -} - -type geoLocation struct { - IPAddress string `json:"ip"` - Country string `json:"cc"` - City string `json:"city"` - Latitude float64 `json:"lat"` - Longitude float64 `json:"lon"` - SortedGateways []string `json:"gateways"` -} - -func newBonafide() *bonafide { - certs := x509.NewCertPool() - certs.AppendCertsFromPEM(caCert) - client := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ - RootCAs: certs, - }, - }, - } - _, tzOffsetSeconds := time.Now().Zone() - tzOffsetHours := tzOffsetSeconds / secondsPerHour - - return &bonafide{ - client: client, - tzOffsetHours: tzOffsetHours, - eip: nil, - defaultGateway: "", - } -} - -func (b *bonafide) getCertPem() ([]byte, error) { - resp, err := b.client.Post(certAPI, "", nil) - if err != nil { - return nil, err - } - defer resp.Body.Close() - if resp.StatusCode != 200 { - return nil, fmt.Errorf("get vpn cert has failed with status: %s", resp.Status) - } - - return ioutil.ReadAll(resp.Body) -} - -func (b *bonafide) getGateways() ([]gateway, error) { - if b.eip == nil { - err := b.fetchEipJSON() - if err != nil { - return nil, err - } - } - - return b.eip.Gateways, nil -} - -func (b *bonafide) setDefaultGateway(name string) { - b.defaultGateway = name - b.sortGateways() -} - -func (b *bonafide) getOpenvpnArgs() ([]string, error) { - if b.eip == nil { - err := b.fetchEipJSON() - if err != nil { - return nil, err - } - } - - args := []string{} - for arg, value := range b.eip.OpenvpnConfiguration { - switch v := value.(type) { - case string: - args = append(args, "--"+arg) - args = append(args, strings.Split(v, " ")...) - case bool: - if v { - args = append(args, "--"+arg) - } - default: - log.Printf("Unknown openvpn argument type: %s - %v", arg, value) - } - } - return args, nil -} - -func (b *bonafide) fetchGeolocation() ([]string, error) { - resp, err := b.client.Post(geolocationAPI, "", nil) - if err != nil { - return nil, err - } - defer resp.Body.Close() - if resp.StatusCode != 200 { - return nil, fmt.Errorf("get geolocation failed with status: %s", resp.Status) - } - - geo := &geoLocation{} - dataJSON, err := ioutil.ReadAll(resp.Body) - err = json.Unmarshal(dataJSON, &geo) - if err != nil { - _ = fmt.Errorf("get vpn cert has failed with status: %s", resp.Status) - return nil, err - } - - return geo.SortedGateways, nil - -} - -func (b *bonafide) fetchEipJSON() error { - resp, err := b.client.Post(eipAPI, "", nil) - if err != nil { - return err - } - defer resp.Body.Close() - if resp.StatusCode != 200 { - return fmt.Errorf("get eip json has failed with status: %s", resp.Status) - } - - var eip eipService - decoder := json.NewDecoder(resp.Body) - err = decoder.Decode(&eip) - if err != nil { - return err - } - - b.eip = &eip - b.sortGateways() - return nil -} - -func (b *bonafide) sortGatewaysByGeolocation(geolocatedGateways []string) []gatewayDistance { - gws := []gatewayDistance{} - - for i, host := range geolocatedGateways { - for _, gw := range b.eip.Gateways { - if gw.Host == host { - gws = append(gws, gatewayDistance{gw, i}) - } - } - } - return gws -} - -func (b *bonafide) sortGatewaysByTimezone() []gatewayDistance { - gws := []gatewayDistance{} - - for _, gw := range b.eip.Gateways { - distance := 13 - if gw.Location == b.defaultGateway { - distance = -1 - } else { - gwOffset, err := strconv.Atoi(b.eip.Locations[gw.Location].Timezone) - if err != nil { - log.Printf("Error sorting gateways: %v", err) - } else { - distance = tzDistance(b.tzOffsetHours, gwOffset) - } - } - gws = append(gws, gatewayDistance{gw, distance}) - } - rand.Seed(time.Now().UnixNano()) - cmp := func(i, j int) bool { - if gws[i].distance == gws[j].distance { - return rand.Intn(2) == 1 - } - return gws[i].distance < gws[j].distance - } - sort.Slice(gws, cmp) - return gws -} - -func (b *bonafide) sortGateways() { - gws := []gatewayDistance{} - - geolocatedGateways, _ := b.fetchGeolocation() - - if len(geolocatedGateways) > 0 { - gws = b.sortGatewaysByGeolocation(geolocatedGateways) - } else { - log.Printf("Falling back to timezone heuristic for gateway selection") - gws = b.sortGatewaysByTimezone() - } - - for i, gw := range gws { - b.eip.Gateways[i] = gw.gateway - } -} - -func tzDistance(offset1, offset2 int) int { - abs := func(x int) int { - if x < 0 { - return -x - } - return x - } - distance := abs(offset1 - offset2) - if distance > 12 { - distance = 24 - distance - } - return distance -} diff --git a/standalone/bonafide_integration_test.go b/standalone/bonafide_integration_test.go deleted file mode 100644 index f162eb5..0000000 --- a/standalone/bonafide_integration_test.go +++ /dev/null @@ -1,58 +0,0 @@ -// +build integration -// 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 . - -package bitmask - -import ( - "bytes" - "testing" -) - -var ( - privateKeyHeader = []byte("-----BEGIN RSA PRIVATE KEY-----") - certHeader = []byte("-----BEGIN CERTIFICATE-----") -) - -func TestIntegrationGetCert(t *testing.T) { - b := newBonafide() - cert, err := b.getCertPem() - if err != nil { - t.Fatal("getCert returned an error: ", err) - } - - if !bytes.Contains(cert, privateKeyHeader) { - t.Errorf("No private key present: \n%q", cert) - } - - if !bytes.Contains(cert, certHeader) { - t.Errorf("No cert present: \n%q", cert) - } -} - -func TestGetGateways(t *testing.T) { - b := newBonafide() - gateways, err := b.getGateways() - if err != nil { - t.Fatal("getGateways returned an error: ", err) - } - - for _, gw := range gateways { - if gw.IPAddress == "5.79.86.180" { - return - } - } - t.Errorf("5.79.86.180 not in the list") -} diff --git a/standalone/bonafide_test.go b/standalone/bonafide_test.go deleted file mode 100644 index a659e46..0000000 --- a/standalone/bonafide_test.go +++ /dev/null @@ -1,100 +0,0 @@ -// 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 . - -package bitmask - -import ( - "io" - "io/ioutil" - "net/http" - "os" - "reflect" - "testing" -) - -const ( - certPath = "testdata/cert" - eipPath = "testdata/eip-service.json" -) - -type client struct { - path string -} - -func (c client) Post(url, contentType string, body io.Reader) (resp *http.Response, err error) { - f, err := os.Open(c.path) - return &http.Response{ - Body: f, - StatusCode: 200, - }, err -} - -func TestGetCert(t *testing.T) { - b := bonafide{client: client{certPath}} - cert, err := b.getCertPem() - if err != nil { - t.Fatal("getCert returned an error: ", err) - } - - f, err := os.Open(certPath) - if err != nil { - t.Fatal("Can't open ", certPath, ": ", err) - } - defer f.Close() - - certData, err := ioutil.ReadAll(f) - if err != nil { - t.Fatal("Can't read all: ", err) - } - if !reflect.DeepEqual(certData, cert) { - t.Errorf("cert doesn't match") - } -} - -func TestGatewayTzLocation(t *testing.T) { - // tzOffset -> location - values := map[int]string{ - -12: "c", - -10: "a", - -5: "a", - -3: "a", - -1: "b", - 0: "b", - 2: "b", - 5: "c", - 8: "c", - 12: "c", - } - - for tzOffset, location := range values { - b := bonafide{ - client: client{eipPath}, - tzOffsetHours: tzOffset, - } - gateways, err := b.getGateways() - if err != nil { - t.Errorf("getGateways returned an error: %v", err) - continue - } - if len(gateways) < 4 { - t.Errorf("Wrong number of gateways: %d", len(gateways)) - continue - - } - if gateways[0].Location != location { - t.Errorf("Wrong location for tz %d: %s, expected: %s", tzOffset, gateways[0].Location, location) - } - } -} diff --git a/standalone/launcher.go b/standalone/launcher.go deleted file mode 100644 index 0a95dd1..0000000 --- a/standalone/launcher.go +++ /dev/null @@ -1,97 +0,0 @@ -// +build !linux -// 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 . - -package bitmask - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - "io/ioutil" - "net/http" -) - -const ( - helperAddr = "http://localhost:7171" -) - -type launcher struct { -} - -func newLauncher() (*launcher, error) { - return &launcher{}, nil -} - -func (l *launcher) close() error { - return nil -} - -func (l *launcher) openvpnStart(flags ...string) error { - byteFlags, err := json.Marshal(flags) - if err != nil { - return err - } - return l.send("/openvpn/start", byteFlags) -} - -func (l *launcher) openvpnStop() error { - return l.send("/openvpn/stop", nil) -} - -func (l *launcher) firewallStart(gateways []gateway) error { - ipList := make([]string, len(gateways)) - for i, gw := range gateways { - ipList[i] = gw.IPAddress - } - byteIPs, err := json.Marshal(ipList) - if err != nil { - return err - } - return l.send("/firewall/start", byteIPs) -} - -func (l *launcher) firewallStop() error { - return l.send("/firewall/stop", nil) -} - -func (l *launcher) firewallIsUp() bool { - res, err := http.Post(helperAddr+"/firewall/isup", "", nil) - if err != nil { - return false - } - defer res.Body.Close() - - return res.StatusCode == http.StatusOK -} - -func (l *launcher) send(path string, body []byte) error { - var reader io.Reader - if body != nil { - reader = bytes.NewReader(body) - } - res, err := http.Post(helperAddr+path, "", reader) - if err != nil { - return err - } - defer res.Body.Close() - - resErr, err := ioutil.ReadAll(res.Body) - if len(resErr) > 0 { - return fmt.Errorf("Helper returned an error: %q", resErr) - } - return err -} diff --git a/standalone/launcher_linux.go b/standalone/launcher_linux.go deleted file mode 100644 index 5266fa1..0000000 --- a/standalone/launcher_linux.go +++ /dev/null @@ -1,139 +0,0 @@ -// +build linux -// 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 . - -package bitmask - -import ( - "errors" - "log" - "os" - "os/exec" -) - -const ( - systemOpenvpnPath = "/usr/sbin/openvpn" - snapOpenvpnPath = "/snap/bin/riseup-vpn.openvpn" -) - -var bitmaskRootPaths = []string{ - "/usr/sbin/bitmask-root", - "/usr/local/sbin/bitmask-root", -} - -type launcher struct { - openvpnCh chan []string -} - -func newLauncher() (*launcher, error) { - l := launcher{make(chan []string, 1)} - go l.openvpnRunner() - return &l, nil -} - -func (l *launcher) close() error { - return nil -} - -func (l *launcher) openvpnStart(flags ...string) error { - log.Println("openvpn start: ", flags) - arg := []string{"openvpn", "start", getOpenvpnPath()} - arg = append(arg, flags...) - l.openvpnCh <- arg - return nil -} - -func (l *launcher) openvpnStop() error { - l.openvpnCh <- nil - log.Println("openvpn stop") - return runBitmaskRoot("openvpn", "stop") -} - -func (l *launcher) firewallStart(gateways []gateway) error { - log.Println("firewall start") - arg := []string{"firewall", "start"} - for _, gw := range gateways { - arg = append(arg, gw.IPAddress) - } - return runBitmaskRoot(arg...) -} - -func (l *launcher) firewallStop() error { - log.Println("firewall stop") - return runBitmaskRoot("firewall", "stop") -} - -func (l *launcher) firewallIsUp() bool { - err := runBitmaskRoot("firewall", "isup") - return err == nil -} - -func (l *launcher) openvpnRunner(arg ...string) { - running := false - runOpenvpn := func(arg []string) { - for running { - err := runBitmaskRoot(arg...) - if err != nil { - log.Printf("An error ocurred running openvpn: %v", err) - } - } - } - - for arg := range l.openvpnCh { - if arg == nil { - running = false - } else { - running = true - go runOpenvpn(arg) - } - } -} - -func runBitmaskRoot(arg ...string) error { - bitmaskRoot, err := bitmaskRootPath() - if err != nil { - return err - } - arg = append([]string{bitmaskRoot}, arg...) - - cmd := exec.Command("pkexec", arg...) - err = cmd.Run() - if err != nil { - return err - } - return nil -} - -func bitmaskRootPath() (string, error) { - if os.Getenv("SNAP") != "" { - path := "/snap/bin/riseup-vpn.bitmask-root" - if _, err := os.Stat(path); !os.IsNotExist(err) { - return path, nil - } - } - for _, path := range bitmaskRootPaths { - if _, err := os.Stat(path); !os.IsNotExist(err) { - return path, nil - } - } - return "", errors.New("No bitmask-root found") -} - -func getOpenvpnPath() string { - if os.Getenv("SNAP") != "" { - return snapOpenvpnPath - } - return systemOpenvpnPath -} diff --git a/standalone/main.go b/standalone/main.go deleted file mode 100644 index 8f697c0..0000000 --- a/standalone/main.go +++ /dev/null @@ -1,80 +0,0 @@ -// 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 . - -package bitmask - -import ( - "io/ioutil" - "log" - "os" - - "github.com/apparentlymart/go-openvpn-mgmt/openvpn" -) - -// Bitmask holds the bitmask client data -type Bitmask struct { - tempdir string - statusCh chan string - managementClient *openvpn.MgmtClient - bonafide *bonafide - launch *launcher -} - -// Init the connection to bitmask -func Init() (*Bitmask, error) { - statusCh := make(chan string, 10) - tempdir, err := ioutil.TempDir("", "leap-") - if err != nil { - return nil, err - } - bonafide := newBonafide() - launch, err := newLauncher() - if err != nil { - return nil, err - } - b := Bitmask{tempdir, statusCh, nil, bonafide, launch} - - err = b.StopVPN() - if err != nil { - return nil, err - } - err = ioutil.WriteFile(b.getCaCertPath(), caCert, 0600) - - go b.openvpnManagement() - return &b, err -} - -// GetStatusCh returns a channel that will recieve VPN status changes -func (b *Bitmask) GetStatusCh() <-chan string { - return b.statusCh -} - -// Close the connection to bitmask -func (b *Bitmask) Close() { - b.StopVPN() - err := b.launch.close() - if err != nil { - log.Printf("There was an error closing the launcher: %v", err) - } - err = os.RemoveAll(b.tempdir) - if err != nil { - log.Printf("There was an error removing temp dir: %v", err) - } -} - -// Version gets the bitmask version string -func (b *Bitmask) Version() (string, error) { - return "", nil -} diff --git a/standalone/status.go b/standalone/status.go deleted file mode 100644 index 5a1ee3d..0000000 --- a/standalone/status.go +++ /dev/null @@ -1,91 +0,0 @@ -// 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 . - -package bitmask - -import ( - "fmt" - "log" - - "github.com/apparentlymart/go-openvpn-mgmt/openvpn" -) - -const ( - On = "on" - Off = "off" - Starting = "starting" - Stopping = "stopping" - Failed = "failed" -) - -var statusNames = map[string]string{ - "CONNECTING": Starting, - "WAIT": Starting, - "AUTH": Starting, - "GET_CONFIG": Starting, - "ASSIGN_IP": Starting, - "ADD_ROUTES": Starting, - "CONNECTED": On, - "RECONNECTING": Starting, - "EXITING": Stopping, - "OFF": Off, - "FAILED": Off, -} - -func (b *Bitmask) openvpnManagement() { - // TODO: we should warn the user on ListenAndServe errors - newConnection := func(conn openvpn.IncomingConn) { - eventCh := make(chan openvpn.Event, 10) - log.Println("New connection into the management") - b.managementClient = conn.Open(eventCh) - b.managementClient.SetStateEvents(true) - b.eventHandler(eventCh) - } - log.Fatal(openvpn.ListenAndServe( - fmt.Sprintf("%s:%s", openvpnManagementAddr, openvpnManagementPort), - openvpn.IncomingConnHandlerFunc(newConnection), - )) -} - -func (b *Bitmask) eventHandler(eventCh <-chan openvpn.Event) { - // TODO: we are reporing only openvpn status, missing firewall status - for event := range eventCh { - log.Printf("Event: %v", event) - stateEvent, ok := event.(*openvpn.StateEvent) - if !ok { - continue - } - status, ok := statusNames[stateEvent.NewState()] - if ok { - b.statusCh <- status - } - } - b.statusCh <- Off -} - -func (b *Bitmask) getOpenvpnState() (string, error) { - if b.managementClient == nil { - return "", fmt.Errorf("No management connected") - } - stateEvent, err := b.managementClient.LatestState() - if err != nil { - return "", err - } - status, ok := statusNames[stateEvent.NewState()] - if !ok { - return "", fmt.Errorf("Unkonw status") - } - return status, nil -} diff --git a/standalone/testdata/cert b/standalone/testdata/cert deleted file mode 100644 index 4968b3f..0000000 --- a/standalone/testdata/cert +++ /dev/null @@ -1,54 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpQIBAAKCAQEA3TQAmZs9U6e1xqQqVWkb132AGXdaO97bsXPOrrKUp63hKeXD -2OQbmG96H3COi0uubVFQT1cAmpuym2COtgahQlnv42p0u2CYsBqfrCHw3iSK7nf6 -Q8RaG2oUIvlQj5m4DUk1wfRBgG5z0pN2HwFWmgheoT0RnOelTO3vcLCaSJA6PF4M -Wehg5ScXi9wr0vibKsANpqab3oUxcHEYcNcKfJKRnXryJx6ctLrRp1WPv3JAXLnn -oUtQ00S0dSHrLED5yPwGFV08q4bkv54qFai2cPO8ITReC6BpvrilBzOjT6fjCmzm -6MCwBot7aRHYcWJgfp7H2b2S7T2qhnC4c2u6mwIDAQABAoIBAFue83SsOS2SNJdv -Xd18qLyLzeg+aFCOET8h8YSokSwWuEGLWqBWcxujaNjm3RPTKA89c9848RYY0VTM -HLBGdLqv183BRVJrQzMGBAbfFA5e4nC9nxo8lPnv6SFHVNf12qceILcSPaM9nJmm -3HEhM8afGtr8GXR8+hmwH9H0RCMzXIjO1//WrY3nfOP8LRuQpSnnhsfZRyngWhot -xsJlDP5plFNw7J/PDLtbjnbOXOktv0fhhq7aWR+A+0s0627r7Tidk1YoNwusYJeB -uKrzNW1+c7Z9xl2yvMQ6+0Wry7A5YUVYP/BakYb/f/skB4ox/zz8vcWeQ4ShZ7m6 -LwPN0ckCgYEA+9wjSBbOlksath3QrJywikD1sQYFOdNrINTBFQnuipKOYKLJNhQM -OzKHY1OiO7G6FcEvz9gKYMpMyMOs8TsISyKPNOXLpnwpgIUx6WRo6qxgEuyWLpBb -Q3Kodl1a/q51dw56pPDEATKjSB1CjXXzm717m5FimH5csPKj9SzrGecCgYEA4Nbb -QML1Jh9cu7TvlK3WqbAFJa4Mx/0+OQ+5xlhbs/ygn3/AZiSsPWdNK11XJ25jgGJw -AucXr/kHgwJX23kFpCYB3zZE0Vh/hOqk/KlUFmptuADIDOAVst0v8MqBLZpZessN -TXph5VBT6P51Oz/ZLC67uno02R1vUhDMB5VCyy0CgYEAoriZuuuxUXz4pw0gU0Vw -8gICOvsuySuFHVMX5GXkTnddsaW65kuRk3WT72KLgJHVLlUAdQKZwesyLMvvonOH -ajPL3ltRdiDmF3j2xFnxRx1TfSaJ6U+vBya/HKo4Li+9CMy8BHDh0fxLbj4pT4gT -el2zzNDjqK6LaG976t24j6UCgYEAyTD5uRW7cIWX4Y+i4xQ7hlQwBuucHEkMKNtd -jZL7XC+vO4qBi+U9CyUo9KjtmCc7emKbgL1xgNICWsT6ATZmSeCIxEg3hG0Ajtu5 -Dy4mRHiv/XsViA/s2sT6ZSmQNlJrx2lzWeUtPJmIvHEWThJwLw0Sh2dbavzf5DuL -ly2FO3ECgYEA5AKnPQo45I+abEA/zKHsKHCqBPEbIaZpJJTaiInrsLiGJf+WzN4N -zr/VAzvY+v0X5RgZmROY5ZLPVf2fTeVNzU5WzoB78hHOI67YI2Sbq7jZlatOgX4z -Ur2BQdT0bW6VINYpDLUvS4goW5p0nQbGItdk69yyef1v3NDbCJ/Sg+Q= ------END RSA PRIVATE KEY----- ------BEGIN CERTIFICATE----- -MIIEnDCCAoSgAwIBAgIRAJzr5xxPLgDD+drzU+5p8cgwDQYJKoZIhvcNAQELBQAw -dTEYMBYGA1UECgwPUmlzZXVwIE5ldHdvcmtzMRswGQYDVQQLDBJodHRwczovL3Jp -c2V1cC5uZXQxPDA6BgNVBAMMM1Jpc2V1cCBOZXR3b3JrcyBSb290IENBIChjbGll -bnQgY2VydGlmaWNhdGVzIG9ubHkhKTAeFw0xODEwMjMwMDAwMDBaFw0xOTAxMjMw -MDAwMDBaMC0xKzApBgNVBAMMIlVOTElNSVRFRDVmbzdsMmxiY3g0OWR5ZzR5MWY4 -YXN3YXcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDdNACZmz1Tp7XG -pCpVaRvXfYAZd1o73tuxc86uspSnreEp5cPY5BuYb3ofcI6LS65tUVBPVwCam7Kb -YI62BqFCWe/janS7YJiwGp+sIfDeJIrud/pDxFobahQi+VCPmbgNSTXB9EGAbnPS -k3YfAVaaCF6hPRGc56VM7e9wsJpIkDo8XgxZ6GDlJxeL3CvS+JsqwA2mppvehTFw -cRhw1wp8kpGdevInHpy0utGnVY+/ckBcueehS1DTRLR1IessQPnI/AYVXTyrhuS/ -nioVqLZw87whNF4LoGm+uKUHM6NPp+MKbObowLAGi3tpEdhxYmB+nsfZvZLtPaqG -cLhza7qbAgMBAAGjbzBtMB0GA1UdDgQWBBRwXpI96PjilFPrkK+CHUPia++ISTAL -BgNVHQ8EBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwIwCQYDVR0TBAIwADAfBgNV -HSMEGDAWgBQX9BvV5SoBAU1rol02CikJlmWARjANBgkqhkiG9w0BAQsFAAOCAgEA -ryNFLixuicVRepocY2lTSY0cpG0eRmLuYJGupk9KeiLA5YEFzl4ZfXJLi+9UHoUR -Bgfe6QYLBb77nO24CoeiMJQw6s593ctMLiMU++fjew31gNp6aA9DmvbLd+fNuLyO -XObRtGw99M37cyf3ZS2SEbTBr4NBp/r3OCyUYsxPYKOzEkr9kNYa8ZZSI960i7/R -/aiq2qemQaOQHTlmrhcBuARJoRVVlLnn2zgLSVm6ptbFLNtAk0lWriUT/WlRmn8j -Cyn/JOuo/1wtrK1dHkaXr8bkEq1oFQzcwMN85hrZKWU0BCehELZtiUg8grqaX/sf -/jaXD61FEqWjIXeGqY/K6ruosZCw2R8sQYzTuQNHMjxmx+J3pch7dMmJPbmA3HW2 -nA7yVp51SX8iZ26zb40S7GG6RNesU+BZxz05XVLt1GwyLx/uNxS4rFpKAT/+ifWG -3Y1j1lMqBxx6RbuqiM1TWqU7Xtzu3hf8ytP5qP7kudXn1TyNtpZCIrzbTXbLnYiD -nH4ZQEWGyAKBOz41eOcG6EXn0TznSGE593ueXBeFnsym7i9MjoOWNGaJ7UbkipfX -FzxirlY5IRkWnmHCL0wGUg6YGnZ1OQ8VBBGb/dBPRMDwA7zWvoM7+3yDLR3aRaLH -mTQzNzu3jy6CRdlpIUcPRcgbniySip1jJrHRYBui+9w= ------END CERTIFICATE----- diff --git a/standalone/testdata/eip-service.json b/standalone/testdata/eip-service.json deleted file mode 100644 index d5f2413..0000000 --- a/standalone/testdata/eip-service.json +++ /dev/null @@ -1,113 +0,0 @@ -{ - "gateways": [ - { - "capabilities": { - "adblock": false, - "filter_dns": false, - "limited": false, - "ports": [ - "443" - ], - "protocols": [ - "tcp" - ], - "transport": [ - "openvpn" - ], - "user_ips": false - }, - "host": "1.example.com", - "ip_address": "1.1.1.1", - "location": "a" - }, - { - "capabilities": { - "adblock": false, - "filter_dns": false, - "limited": false, - "ports": [ - "443" - ], - "protocols": [ - "tcp" - ], - "transport": [ - "openvpn" - ], - "user_ips": false - }, - "host": "2.example.com", - "ip_address": "2.2.2.2", - "location": "b" - }, - { - "capabilities": { - "adblock": false, - "filter_dns": false, - "limited": false, - "ports": [ - "443" - ], - "protocols": [ - "tcp" - ], - "transport": [ - "openvpn" - ], - "user_ips": false - }, - "host": "3.example.com", - "ip_address": "3.3.3.3", - "location": "b" - }, - { - "capabilities": { - "adblock": false, - "filter_dns": false, - "limited": false, - "ports": [ - "443" - ], - "protocols": [ - "tcp" - ], - "transport": [ - "openvpn" - ], - "user_ips": false - }, - "host": "4.example.com", - "ip_address": "4.4.4.4", - "location": "c" - } - ], - "locations": { - "a": { - "country_code": "AA", - "hemisphere": "N", - "name": "a", - "timezone": "-5" - }, - "b": { - "country_code": "BB", - "hemisphere": "S", - "name": "b", - "timezone": "+1" - }, - "c": { - "country_code": "CC", - "hemisphere": "N", - "name": "c", - "timezone": "+8" - } - }, - "openvpn_configuration": { - "auth": "SHA1", - "cipher": "AES-128-CBC", - "keepalive": "10 30", - "tls-cipher": "DHE-RSA-AES128-SHA", - "tun-ipv6": true - }, - "serial": 1, - "version": 1 -} diff --git a/standalone/vpn.go b/standalone/vpn.go deleted file mode 100644 index c3b2693..0000000 --- a/standalone/vpn.go +++ /dev/null @@ -1,156 +0,0 @@ -// 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 . - -package bitmask - -import ( - "io/ioutil" - "os" - "path" -) - -const ( - openvpnManagementAddr = "127.0.0.1" - openvpnManagementPort = "6061" -) - -// StartVPN for provider -func (b *Bitmask) StartVPN(provider string) error { - gateways, err := b.bonafide.getGateways() - if err != nil { - return err - } - certPemPath, err := b.getCert() - if err != nil { - return err - } - - err = b.launch.firewallStart(gateways) - if err != nil { - return err - } - - arg, err := b.bonafide.getOpenvpnArgs() - if err != nil { - return err - } - for _, gw := range gateways { - arg = append(arg, "--remote", gw.IPAddress, "443", "tcp4") - } - arg = append(arg, - "--verb", "1", - "--management-client", - "--management", openvpnManagementAddr, openvpnManagementPort, - "--ca", b.getCaCertPath(), - "--cert", certPemPath, - "--key", certPemPath) - return b.launch.openvpnStart(arg...) -} - -func (b *Bitmask) getCert() (certPath string, err error) { - certPath = b.getCertPemPath() - - if _, err := os.Stat(certPath); os.IsNotExist(err) { - cert, err := b.bonafide.getCertPem() - if err != nil { - return "", err - } - err = ioutil.WriteFile(certPath, cert, 0600) - } - - return certPath, err -} - -// StopVPN or cancel -func (b *Bitmask) StopVPN() error { - err := b.launch.firewallStop() - if err != nil { - return err - } - 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() - if err != nil { - status = Off - } - if status == Off && b.launch.firewallIsUp() { - return Failed, nil - } - return status, nil -} - -// InstallHelpers into the system -func (b *Bitmask) InstallHelpers() error { - // TODO - return nil -} - -// 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 -} - -// ListGateways return the names of the gateways -func (b *Bitmask) ListGateways(provider string) ([]string, error) { - gateways, err := b.bonafide.getGateways() - if err != nil { - return nil, err - } - gatewayNames := make([]string, len(gateways)) - for i, gw := range gateways { - gatewayNames[i] = gw.Location - } - return gatewayNames, nil -} - -// UseGateway selects name as the default gateway -func (b *Bitmask) UseGateway(name string) error { - b.bonafide.setDefaultGateway(name) - return nil -} - -func (b *Bitmask) getCertPemPath() string { - return path.Join(b.tempdir, "openvpn.pem") -} - -func (b *Bitmask) getCaCertPath() string { - return path.Join(b.tempdir, "cacert.pem") -} diff --git a/systray.go b/systray.go deleted file mode 100644 index c6c75e4..0000000 --- a/systray.go +++ /dev/null @@ -1,255 +0,0 @@ -// 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 . - -package main - -import ( - "fmt" - "log" - "os" - "os/signal" - "time" - - "0xacab.org/leap/bitmask-systray/bitmask" - "0xacab.org/leap/bitmask-systray/icon" - "github.com/getlantern/systray" - "github.com/skratchdot/open-golang/open" -) - -type bmTray struct { - bm bitmask.Bitmask - conf *systrayConfig - notify *notificator - waitCh chan bool - mStatus *systray.MenuItem - mTurnOn *systray.MenuItem - mTurnOff *systray.MenuItem - mHelp *systray.MenuItem - mDonate *systray.MenuItem - mAbout *systray.MenuItem - mQuit *systray.MenuItem - activeGateway *gatewayTray - autostart autostart -} - -type gatewayTray struct { - menuItem *systray.MenuItem - name string -} - -func (bt *bmTray) start() { - // XXX this removes the snap error message, but produces an invisible icon. - // https://0xacab.org/leap/riseup_vpn/issues/44 - // os.Setenv("TMPDIR", "/var/tmp") - systray.Run(bt.onReady, bt.onExit) -} - -func (bt *bmTray) onExit() { - log.Println("Closing systray") -} - -func (bt *bmTray) onReady() { - systray.SetIcon(icon.Off) - - bt.mStatus = systray.AddMenuItem(printer.Sprintf("Checking status..."), "") - bt.mStatus.Disable() - bt.mTurnOn = systray.AddMenuItem(printer.Sprintf("Turn on"), "") - bt.mTurnOn.Hide() - bt.mTurnOff = systray.AddMenuItem(printer.Sprintf("Turn off"), "") - bt.mTurnOff.Hide() - systray.AddSeparator() - - if bt.conf.SelectGateway { - bt.addGateways() - } - - bt.mHelp = systray.AddMenuItem(printer.Sprintf("Help..."), "") - bt.mDonate = systray.AddMenuItem(printer.Sprintf("Donate..."), "") - bt.mAbout = systray.AddMenuItem(printer.Sprintf("About..."), "") - systray.AddSeparator() - - bt.mQuit = systray.AddMenuItem(printer.Sprintf("Quit"), "") -} - -func (bt *bmTray) loop(bm bitmask.Bitmask, notify *notificator, as autostart) { - bt.bm = bm - bt.notify = notify - bt.autostart = as - - signalCh := make(chan os.Signal, 1) - signal.Notify(signalCh, os.Interrupt) - - ch := bt.bm.GetStatusCh() - if status, err := bt.bm.GetStatus(); err != nil { - log.Printf("Error getting status: %v", err) - } else { - bt.changeStatus(status) - } - - for { - select { - case status := <-ch: - log.Println("status: " + status) - bt.changeStatus(status) - - case <-bt.mTurnOn.ClickedCh: - log.Println("on") - bt.changeStatus("starting") - bt.bm.StartVPN(provider) - bt.conf.setUserStoppedVPN(false) - case <-bt.mTurnOff.ClickedCh: - log.Println("off") - bt.changeStatus("stopping") - bt.bm.StopVPN() - bt.conf.setUserStoppedVPN(true) - - case <-bt.mHelp.ClickedCh: - open.Run("https://riseup.net/vpn/support") - case <-bt.mDonate.ClickedCh: - bt.conf.setDonated() - open.Run("https://riseup.net/vpn/donate") - case <-bt.mAbout.ClickedCh: - bitmaskVersion, err := bt.bm.Version() - versionStr := version - if err != nil { - log.Printf("Error getting version: %v", err) - } else if bitmaskVersion != "" { - versionStr = fmt.Sprintf("%s (bitmaskd %s)", version, bitmaskVersion) - } - bt.notify.about(versionStr) - - case <-bt.mQuit.ClickedCh: - err := bt.autostart.Disable() - if err != nil { - log.Printf("Error disabling autostart: %v", err) - } - systray.Quit() - return - case <-signalCh: - systray.Quit() - return - - case <-time.After(5 * time.Second): - if status, err := bt.bm.GetStatus(); err != nil { - log.Printf("Error getting status: %v", err) - } else { - bt.changeStatus(status) - } - } - } -} - -func (bt *bmTray) addGateways() { - gatewayList, err := bt.bm.ListGateways(provider) - if err != nil { - log.Printf("Gateway initialization error: %v", err) - return - } - - mGateway := systray.AddMenuItem(printer.Sprintf("Route traffic through"), "") - mGateway.Disable() - for i, city := range gatewayList { - menuItem := systray.AddMenuItem(city, printer.Sprintf("Use %s %v gateway", applicationName, city)) - gateway := gatewayTray{menuItem, city} - - if i == 0 { - menuItem.Check() - menuItem.SetTitle("*" + city) - bt.activeGateway = &gateway - } else { - menuItem.Uncheck() - } - - go func(gateway gatewayTray) { - for { - <-menuItem.ClickedCh - gateway.menuItem.SetTitle("*" + gateway.name) - gateway.menuItem.Check() - - bt.activeGateway.menuItem.Uncheck() - bt.activeGateway.menuItem.SetTitle(bt.activeGateway.name) - bt.activeGateway = &gateway - - bt.bm.UseGateway(gateway.name) - } - }(gateway) - } - - systray.AddSeparator() -} - -func (bt *bmTray) changeStatus(status string) { - if bt.waitCh != nil { - bt.waitCh <- true - bt.waitCh = nil - } - - var statusStr string - switch status { - case "on": - systray.SetIcon(icon.On) - bt.mTurnOff.SetTitle(printer.Sprintf("Turn off")) - statusStr = printer.Sprintf("%s on", applicationName) - bt.mTurnOn.Hide() - bt.mTurnOff.Show() - - case "off": - systray.SetIcon(icon.Off) - bt.mTurnOn.SetTitle(printer.Sprintf("Turn on")) - statusStr = printer.Sprintf("%s off", applicationName) - bt.mTurnOn.Show() - bt.mTurnOff.Hide() - - case "starting": - bt.waitCh = make(chan bool) - go bt.waitIcon() - bt.mTurnOff.SetTitle(printer.Sprintf("Cancel")) - statusStr = printer.Sprintf("Connecting to %s", applicationName) - bt.mTurnOn.Hide() - bt.mTurnOff.Show() - - case "stopping": - bt.waitCh = make(chan bool) - go bt.waitIcon() - statusStr = printer.Sprintf("Stopping %s", applicationName) - bt.mTurnOn.Hide() - bt.mTurnOff.Hide() - - case "failed": - systray.SetIcon(icon.Blocked) - bt.mTurnOn.SetTitle(printer.Sprintf("Retry")) - bt.mTurnOff.SetTitle(printer.Sprintf("Turn off")) - statusStr = printer.Sprintf("%s blocking internet", applicationName) - bt.mTurnOn.Show() - bt.mTurnOff.Show() - } - - systray.SetTooltip(statusStr) - bt.mStatus.SetTitle(statusStr) -} - -func (bt *bmTray) waitIcon() { - icons := [][]byte{icon.Wait0, icon.Wait1, icon.Wait2, icon.Wait3} - for i := 0; true; i = (i + 1) % 4 { - systray.SetIcon(icons[i]) - - select { - case <-bt.waitCh: - return - case <-time.After(time.Millisecond * 500): - continue - } - } -} diff --git a/tools/transifex/Makefile b/tools/transifex/Makefile new file mode 100644 index 0000000..bf5bf2b --- /dev/null +++ b/tools/transifex/Makefile @@ -0,0 +1,8 @@ + +all: build generate_json + +build: + go build + +generate_json: + ./transifex g2t ../../locales/en-US/out.gotext.json messages.json diff --git a/tools/transifex/main.go b/tools/transifex/main.go new file mode 100644 index 0000000..37bae97 --- /dev/null +++ b/tools/transifex/main.go @@ -0,0 +1,124 @@ +package main + +import ( + "encoding/json" + "fmt" + "os" + "path" + + "golang.org/x/text/message/pipeline" +) + +const ( + outGotext = "out.gotext.json" + messagesGotext = "messages.gotext.json" +) + +type transifex map[string]string + +func main() { + if len(os.Args) < 2 { + panic("g2t or t2g should be passed as argument") + } + + switch os.Args[1] { + case "g2t": + g2t(func(m pipeline.Message) string { return m.Message.Msg }) + case "lang2t": + g2t(func(m pipeline.Message) string { return m.Translation.Msg }) + case "t2g": + t2g() + default: + panic("g2t or t2g should be passed as argument") + } +} + +func g2t(getMessage func(pipeline.Message) string) { + if len(os.Args) < 4 { + panic(fmt.Sprintf("usage: %s g2t inFile outFile", os.Args[0])) + } + + inF, err := os.Open(os.Args[2]) + if err != nil { + panic(fmt.Sprintf("Can't open input file %s: %v", os.Args[2], err)) + } + outF, err := os.Create(os.Args[3]) + if err != nil { + panic(fmt.Sprintf("Can't open output file %s: %v", os.Args[3], err)) + } + + toTransifex(inF, outF, getMessage) +} + +func t2g() { + if len(os.Args) < 3 { + panic(fmt.Sprintf("usage: %s t2g localeFolder", os.Args[0])) + } + + origF, err := os.Open(path.Join(os.Args[2], outGotext)) + if err != nil { + panic(fmt.Sprintf("Can't open file %s/%s: %v", os.Args[3], outGotext, err)) + } + outF, err := os.Create(path.Join(os.Args[2], messagesGotext)) + if err != nil { + panic(fmt.Sprintf("Can't open output file %s/%v: %v", os.Args[3], messagesGotext, err)) + } + toGotext(origF, os.Stdin, outF) +} + +func toTransifex(inF, outF *os.File, getMessage func(pipeline.Message) string) { + messages := pipeline.Messages{} + dec := json.NewDecoder(inF) + err := dec.Decode(&messages) + if err != nil { + panic(fmt.Sprintf("An error ocurred decoding json: %v", err)) + } + + transfx := make(transifex) + for _, m := range messages.Messages { + transfx[m.ID[0]] = getMessage(m) + } + enc := json.NewEncoder(outF) + enc.SetIndent("", " ") + err = enc.Encode(transfx) + if err != nil { + panic(fmt.Sprintf("An error ocurred encoding json: %v", err)) + } +} + +func toGotext(origF, inF, outF *os.File) { + transfx := make(transifex) + dec := json.NewDecoder(inF) + err := dec.Decode(&transfx) + if err != nil { + panic(fmt.Sprintf("An error ocurred decoding json: %v", err)) + } + + messages := pipeline.Messages{} + dec = json.NewDecoder(origF) + err = dec.Decode(&messages) + if err != nil { + panic(fmt.Sprintf("An error ocurred decoding orig json: %v", err)) + } + + for k, v := range transfx { + found := false + for i, m := range messages.Messages { + if m.ID[0] == k { + messages.Messages[i].Translation.Msg = v + found = true + break + } + } + if !found { + fmt.Printf("The original document doesn't have id: %s\n", k) + } + } + + enc := json.NewEncoder(outF) + enc.SetIndent("", " ") + err = enc.Encode(messages) + if err != nil { + panic(fmt.Sprintf("An error ocurred encoding json: %v", err)) + } +} diff --git a/tools/transifex/messages.json b/tools/transifex/messages.json new file mode 100644 index 0000000..40a4145 --- /dev/null +++ b/tools/transifex/messages.json @@ -0,0 +1,28 @@ +{ + "About": "About", + "About...": "About...", + "Cancel": "Cancel", + "Checking status...": "Checking status...", + "Connecting to {ApplicationName}": "Connecting to {ApplicationName}", + "Donate": "Donate", + "Donate...": "Donate...", + "Error starting VPN": "Error starting VPN", + "Help...": "Help...", + "Initialization error": "Initialization error", + "Missing authentication agent": "Missing authentication agent", + "Quit": "Quit", + "Retry": "Retry", + "Route traffic through": "Route traffic through", + "Stopping {ApplicationName}": "Stopping {ApplicationName}", + "Turn off": "Turn off", + "Turn on": "Turn on", + "Use {ApplicationName} {City} gateway": "Use {ApplicationName} {City} gateway", + "aboutText": "{ApplicationName} is an easy, fast, and secure VPN service from riseup.net. {ApplicationName} does not require a user account, keep logs, or track you in any way.\n\t \nThis service is paid for entirely by donations from users like you. Please donate at https://riseup.net/vpn/donate.\n\t\t\nBy using this application, you agree to the Terms of Service available at https://riseup.net/tos. This service is provide as-is, without any warranty, and is intended for people who work to make the world a better place.\n\n\n{ApplicationName_1} version: {Version}", + "donationText": "The {ApplicationName} service is expensive to run. Because we don't want to store personal information about you, there is no accounts or billing for this service. But if you want the service to continue, donate at least $5 each month.\n\t\nDo you want to donate now?", + "errorMsg": "An error has ocurred initializing the VPN: {Err}", + "errorStartingVPN": "Can't connect to {ApplicationName}: {Err}", + "missingAuthAgent": "Could not find a polkit authentication agent. Please run one and try again.", + "{ApplicationName} blocking internet": "{ApplicationName} blocking internet", + "{ApplicationName} off": "{ApplicationName} off", + "{ApplicationName} on": "{ApplicationName} on" +} diff --git a/transifex/Makefile b/transifex/Makefile deleted file mode 100644 index aad1d3e..0000000 --- a/transifex/Makefile +++ /dev/null @@ -1,8 +0,0 @@ - -all: build generate_json - -build: - go build - -generate_json: - ./transifex g2t ../locales/en-US/out.gotext.json messages.json diff --git a/transifex/main.go b/transifex/main.go deleted file mode 100644 index 37bae97..0000000 --- a/transifex/main.go +++ /dev/null @@ -1,124 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "os" - "path" - - "golang.org/x/text/message/pipeline" -) - -const ( - outGotext = "out.gotext.json" - messagesGotext = "messages.gotext.json" -) - -type transifex map[string]string - -func main() { - if len(os.Args) < 2 { - panic("g2t or t2g should be passed as argument") - } - - switch os.Args[1] { - case "g2t": - g2t(func(m pipeline.Message) string { return m.Message.Msg }) - case "lang2t": - g2t(func(m pipeline.Message) string { return m.Translation.Msg }) - case "t2g": - t2g() - default: - panic("g2t or t2g should be passed as argument") - } -} - -func g2t(getMessage func(pipeline.Message) string) { - if len(os.Args) < 4 { - panic(fmt.Sprintf("usage: %s g2t inFile outFile", os.Args[0])) - } - - inF, err := os.Open(os.Args[2]) - if err != nil { - panic(fmt.Sprintf("Can't open input file %s: %v", os.Args[2], err)) - } - outF, err := os.Create(os.Args[3]) - if err != nil { - panic(fmt.Sprintf("Can't open output file %s: %v", os.Args[3], err)) - } - - toTransifex(inF, outF, getMessage) -} - -func t2g() { - if len(os.Args) < 3 { - panic(fmt.Sprintf("usage: %s t2g localeFolder", os.Args[0])) - } - - origF, err := os.Open(path.Join(os.Args[2], outGotext)) - if err != nil { - panic(fmt.Sprintf("Can't open file %s/%s: %v", os.Args[3], outGotext, err)) - } - outF, err := os.Create(path.Join(os.Args[2], messagesGotext)) - if err != nil { - panic(fmt.Sprintf("Can't open output file %s/%v: %v", os.Args[3], messagesGotext, err)) - } - toGotext(origF, os.Stdin, outF) -} - -func toTransifex(inF, outF *os.File, getMessage func(pipeline.Message) string) { - messages := pipeline.Messages{} - dec := json.NewDecoder(inF) - err := dec.Decode(&messages) - if err != nil { - panic(fmt.Sprintf("An error ocurred decoding json: %v", err)) - } - - transfx := make(transifex) - for _, m := range messages.Messages { - transfx[m.ID[0]] = getMessage(m) - } - enc := json.NewEncoder(outF) - enc.SetIndent("", " ") - err = enc.Encode(transfx) - if err != nil { - panic(fmt.Sprintf("An error ocurred encoding json: %v", err)) - } -} - -func toGotext(origF, inF, outF *os.File) { - transfx := make(transifex) - dec := json.NewDecoder(inF) - err := dec.Decode(&transfx) - if err != nil { - panic(fmt.Sprintf("An error ocurred decoding json: %v", err)) - } - - messages := pipeline.Messages{} - dec = json.NewDecoder(origF) - err = dec.Decode(&messages) - if err != nil { - panic(fmt.Sprintf("An error ocurred decoding orig json: %v", err)) - } - - for k, v := range transfx { - found := false - for i, m := range messages.Messages { - if m.ID[0] == k { - messages.Messages[i].Translation.Msg = v - found = true - break - } - } - if !found { - fmt.Printf("The original document doesn't have id: %s\n", k) - } - } - - enc := json.NewEncoder(outF) - enc.SetIndent("", " ") - err = enc.Encode(messages) - if err != nil { - panic(fmt.Sprintf("An error ocurred encoding json: %v", err)) - } -} diff --git a/transifex/messages.json b/transifex/messages.json deleted file mode 100644 index 19610a8..0000000 --- a/transifex/messages.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "About": "About", - "About...": "About...", - "Cancel": "Cancel", - "Checking status...": "Checking status...", - "Connecting to {ApplicationName}": "Connecting to {ApplicationName}", - "Donate": "Donate", - "Donate...": "Donate...", - "Error starting VPN": "Error starting VPN", - "Help...": "Help...", - "Initialization error": "Initialization error", - "Missing authentication agent": "Missing authentication agent", - "Quit": "Quit", - "Retry": "Retry", - "Route traffic through": "Route traffic through", - "Stopping {ApplicationName}": "Stopping {ApplicationName}", - "Turn off": "Turn off", - "Turn on": "Turn on", - "Use {ApplicationName} {City} gateway": "Use {ApplicationName} {City} gateway", - "aboutText": "{ApplicationName} is an easy, fast, and secure VPN service from riseup.net. {ApplicationName} does not require a user account, keep logs, or track you in any way.\n\t \nThis service is paid for entirely by donations from users like you. Please donate at https://riseup.net/vpn/donate.\n\t\t\nBy using this application, you agree to the Terms of Service available at https://riseup.net/tos. This service is provide as-is, without any warranty, and is intended for people who work to make the world a better place.\n\n\n{ApplicationName_1} version: {Version}", - "donationText": "The {ApplicationName} service is expensive to run. Because we don't want to store personal information about you, there is no accounts or billing for this service. But if you want the service to continue, donate at least $5 each month.\n\t\nDo you want to donate now?", - "errorMsg": "An error has ocurred initializing {ApplicationName}: {Err}", - "errorStartingVPN": "Can't connect to {ApplicationName}: {Err}", - "missingAuthAgent": "Could not find a polkit authentication agent. Please run one and try again.", - "{ApplicationName} blocking internet": "{ApplicationName} blocking internet", - "{ApplicationName} off": "{ApplicationName} off", - "{ApplicationName} on": "{ApplicationName} on" -} -- cgit v1.2.3