Skip to content

Commit

Permalink
Merge 274e533 into 430a53e
Browse files Browse the repository at this point in the history
  • Loading branch information
hellais committed Dec 2, 2019
2 parents 430a53e + 274e533 commit 0bfd3f0
Show file tree
Hide file tree
Showing 26 changed files with 302 additions and 284 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/dist
/ooni.cov
/coverage.txt
*.njson
.DS_Store
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ services:
- docker
env:
- OS_NAME: linux
before_script:
- go get golang.org/x/tools/cmd/cover
- go get github.com/mattn/goveralls
script:
- ./build.sh _travis-${TRAVIS_OS_NAME}
- $GOPATH/bin/goveralls -coverprofile=coverage.cov -service=travis-ci
- ./scripts/travis_test.sh
5 changes: 3 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ elif [ "$1" = "release" ]; then
elif [ "$1" = "_travis-linux" ]; then
set -x
$0 linux
# TODO -race does not work on alpine. See: https://travis-ci.org/ooni/probe-cli/builds/619631256#L962
docker run -v `pwd`:/oonibuild -w /oonibuild -t oonibuild \
go test -v -coverprofile=ooni.cov ./...
go test -v -coverprofile=coverage.cov -coverpkg=./... ./...

elif [ "$1" = "_travis-osx" ]; then
set -x
Expand All @@ -60,7 +61,7 @@ elif [ "$1" = "_travis-osx" ]; then
brew upgrade
brew install measurement-kit
$0 macos
go test -v -coverprofile=ooni.cov ./...
go test -v -race -coverprofile=coverage.cov -coverpkg=./... ./...

elif [ "$1" = "help" ]; then
echo "Usage: $0 linux | macos | release | windows"
Expand Down
156 changes: 153 additions & 3 deletions internal/cli/onboard/onboard.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,164 @@
package onboard

import (
"errors"
"fmt"

"github.com/alecthomas/kingpin"
"github.com/apex/log"
"github.com/fatih/color"
ooni "github.com/ooni/probe-cli"
"github.com/ooni/probe-cli/config"
"github.com/ooni/probe-cli/internal/cli/root"
"github.com/ooni/probe-cli/internal/onboard"
"github.com/ooni/probe-cli/internal/output"
"github.com/pkg/errors"
"gopkg.in/AlecAivazis/survey.v1"
)

// Onboarding start the interactive onboarding procedure
func Onboarding(config *config.Config) error {
output.SectionTitle("What is OONI Probe?")

fmt.Println()
output.Paragraph("Your tool for detecting internet censorship!")
fmt.Println()
output.Paragraph("OONI Probe checks whether your provider blocks access to sites and services. Run OONI Probe to collect evidence of internet censorship and to measure your network performance.")
fmt.Println()
output.PressEnterToContinue("Press 'Enter' to continue...")

output.SectionTitle("Heads Up")
fmt.Println()
output.Bullet("Anyone monitoring your internet activity (such as your government or ISP) may be able to see that you are running OONI Probe.")
fmt.Println()
output.Bullet("The network data you will collect will automatically be published (unless you opt-out in the settings).")
fmt.Println()
output.Bullet("You may test objectionable sites.")
fmt.Println()
output.Bullet("Read the documentation to learn more.")
fmt.Println()
output.PressEnterToContinue("Press 'Enter' to continue...")

output.SectionTitle("Pop Quiz!")
output.Paragraph("")
answer := ""
quiz1 := &survey.Select{
Message: "Anyone monitoring my internet activity may be able to see that I am running OONI Probe.",
Options: []string{"true", "false"},
Default: "true",
}
survey.AskOne(quiz1, &answer, nil)
if answer != "true" {
output.Paragraph(color.RedString("Actually..."))
output.Paragraph("OONI Probe is not a privacy tool. Therefore, anyone monitoring your internet activity may be able to see which software you are running.")
} else {
output.Paragraph(color.BlueString("Good job!"))
}
answer = ""
quiz2 := &survey.Select{
Message: "The network data I will collect will automatically be published (unless I opt-out in the settings).",
Options: []string{"true", "false"},
Default: "true",
}
survey.AskOne(quiz2, &answer, nil)
if answer != "true" {
output.Paragraph(color.RedString("Actually..."))
output.Paragraph("The network data you will collect will automatically be published to increase transparency of internet censorship (unless you opt-out in the settings).")
} else {
output.Paragraph(color.BlueString("Well done!"))
}

changeDefaults := false
prompt := &survey.Confirm{
Message: "Do you want to change the default settings?",
Default: false,
}
survey.AskOne(prompt, &changeDefaults, nil)

settings := struct {
IncludeIP bool
IncludeNetwork bool
IncludeCountry bool
UploadResults bool
SendCrashReports bool
}{}
settings.IncludeIP = false
settings.IncludeNetwork = true
settings.IncludeCountry = true
settings.UploadResults = true
settings.SendCrashReports = true

if changeDefaults == true {
var qs = []*survey.Question{
{
Name: "IncludeIP",
Prompt: &survey.Confirm{Message: "Should we include your IP?"},
},
{
Name: "IncludeNetwork",
Prompt: &survey.Confirm{
Message: "Can we include your network name?",
Default: true,
},
},
{
Name: "IncludeCountry",
Prompt: &survey.Confirm{
Message: "Can we include your country name?",
Default: true,
},
},
{
Name: "UploadResults",
Prompt: &survey.Confirm{
Message: "Can we upload your results?",
Default: true,
},
},
{
Name: "SendCrashReports",
Prompt: &survey.Confirm{
Message: "Can we send crash reports to OONI?",
Default: true,
},
},
}

err := survey.Ask(qs, &settings)
if err != nil {
log.WithError(err).Error("there was an error in parsing your responses")
return err
}
}

config.Lock()
config.InformedConsent = true
config.Sharing.IncludeCountry = settings.IncludeCountry
config.Advanced.SendCrashReports = settings.SendCrashReports
config.Sharing.IncludeIP = settings.IncludeIP
config.Sharing.IncludeASN = settings.IncludeNetwork
config.Sharing.UploadResults = settings.UploadResults
config.Unlock()

if err := config.Write(); err != nil {
log.WithError(err).Error("failed to write config file")
return err
}
return nil
}

// MaybeOnboarding will run the onboarding process only if the informed consent
// config option is set to false
func MaybeOnboarding(c *ooni.Context) error {
if c.Config.InformedConsent == false {
if c.IsBatch == true {
return errors.New("cannot run onboarding in batch mode")
}
if err := Onboarding(c.Config); err != nil {
return errors.Wrap(err, "onboarding")
}
}
return nil
}

func init() {
cmd := root.Command("onboard", "Starts the onboarding process")

Expand All @@ -35,6 +185,6 @@ func init() {
return errors.New("cannot do onboarding in batch mode")
}

return onboard.Onboarding(ctx.Config)
return Onboarding(ctx.Config)
})
}
10 changes: 5 additions & 5 deletions internal/cli/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"github.com/apex/log"
"github.com/fatih/color"
ooni "github.com/ooni/probe-cli"
"github.com/ooni/probe-cli/internal/cli/onboard"
"github.com/ooni/probe-cli/internal/cli/root"
"github.com/ooni/probe-cli/internal/database"
"github.com/ooni/probe-cli/nettests"
"github.com/ooni/probe-cli/nettests/groups"
)

func runNettestGroup(tg string, ctx *ooni.Context, network *database.Network) error {
group, ok := groups.NettestGroups[tg]
group, ok := nettests.NettestGroups[tg]
if !ok {
log.Errorf("No test group named %s", tg)
return errors.New("invalid test group name")
Expand Down Expand Up @@ -50,7 +50,7 @@ func init() {
var ctx *ooni.Context
var network *database.Network

for name := range groups.NettestGroups {
for name := range nettests.NettestGroups {
nettestGroupNamesBlue = append(nettestGroupNamesBlue, color.BlueString(name))
}

Expand All @@ -66,7 +66,7 @@ func init() {
return err
}

if err = ctx.MaybeOnboarding(); err != nil {
if err = onboard.MaybeOnboarding(ctx); err != nil {
log.WithError(err).Error("failed to perform onboarding")
return err
}
Expand Down Expand Up @@ -129,7 +129,7 @@ func init() {
allCmd := cmd.Command("all", "").Default()
allCmd.Action(func(_ *kingpin.ParseContext) error {
log.Infof("Running %s tests", color.BlueString("all"))
for tg := range groups.NettestGroups {
for tg := range nettests.NettestGroups {
if err := runNettestGroup(tg, ctx, network); err != nil {
log.WithError(err).Errorf("failed to run %s", tg)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/database/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"
"time"

"github.com/ooni/probe-cli/internal/shutil"
"github.com/ooni/probe-cli/utils/shutil"
"github.com/pkg/errors"
"upper.io/db.v3/lib/sqlbuilder"
)
Expand Down
8 changes: 4 additions & 4 deletions internal/log/handlers/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/apex/log"
"github.com/fatih/color"
colorable "github.com/mattn/go-colorable"
"github.com/ooni/probe-cli/internal/util"
"github.com/ooni/probe-cli/utils"
)

// Default handler outputting to stderr.
Expand Down Expand Up @@ -67,7 +67,7 @@ func logSectionTitle(w io.Writer, f log.Fields) error {

title := f.Get("title").(string)
fmt.Fprintf(w, "┏"+strings.Repeat("━", colWidth+2)+"┓\n")
fmt.Fprintf(w, "┃ %s ┃\n", util.RightPad(title, colWidth))
fmt.Fprintf(w, "┃ %s ┃\n", utils.RightPad(title, colWidth))
fmt.Fprintf(w, "┗"+strings.Repeat("━", colWidth+2)+"┛\n")
return nil
}
Expand All @@ -84,7 +84,7 @@ func logTable(w io.Writer, f log.Fields) error {
continue
}
line := fmt.Sprintf("%s: %s", color.Sprint(name), f.Get(name))
lineLength := util.EscapeAwareRuneCountInString(line)
lineLength := utils.EscapeAwareRuneCountInString(line)
lines = append(lines, line)
if colWidth < lineLength {
colWidth = lineLength
Expand All @@ -94,7 +94,7 @@ func logTable(w io.Writer, f log.Fields) error {
fmt.Fprintf(w, "┏"+strings.Repeat("━", colWidth+2)+"┓\n")
for _, line := range lines {
fmt.Fprintf(w, "┃ %s ┃\n",
util.RightPad(line, colWidth),
utils.RightPad(line, colWidth),
)
}
fmt.Fprintf(w, "┗"+strings.Repeat("━", colWidth+2)+"┛\n")
Expand Down
26 changes: 13 additions & 13 deletions internal/log/handlers/cli/measurements.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/apex/log"
"github.com/ooni/probe-cli/internal/util"
"github.com/ooni/probe-cli/utils"
)

func statusIcon(ok bool) string {
Expand All @@ -35,7 +35,7 @@ func logTestKeys(w io.Writer, testKeys string) error {
}
for _, line := range testKeysLines {
fmt.Fprintf(w, fmt.Sprintf("│ %s │\n",
util.RightPad(line, colWidth*2)))
utils.RightPad(line, colWidth*2)))
}
return nil
}
Expand Down Expand Up @@ -71,22 +71,22 @@ func logMeasurementItem(w io.Writer, f log.Fields) error {
failureStr := fmt.Sprintf("success: %s", statusIcon(!isFailed))

fmt.Fprintf(w, fmt.Sprintf("│ %s │\n",
util.RightPad(
utils.RightPad(
fmt.Sprintf("#%d", rID), colWidth*2)))

if url != "" {
fmt.Fprintf(w, fmt.Sprintf("│ %s │\n",
util.RightPad(
utils.RightPad(
fmt.Sprintf("%s (%s)", url, urlCategoryCode), colWidth*2)))
}

fmt.Fprintf(w, fmt.Sprintf("│ %s %s│\n",
util.RightPad(testName, colWidth),
util.RightPad(anomalyStr, colWidth)))
utils.RightPad(testName, colWidth),
utils.RightPad(anomalyStr, colWidth)))

fmt.Fprintf(w, fmt.Sprintf("│ %s %s│\n",
util.RightPad(failureStr, colWidth),
util.RightPad(uploadStr, colWidth)))
utils.RightPad(failureStr, colWidth),
utils.RightPad(uploadStr, colWidth)))

if testKeys != "" {
if err := logTestKeys(w, testKeys); err != nil {
Expand Down Expand Up @@ -116,15 +116,15 @@ func logMeasurementSummary(w io.Writer, f log.Fields) error {
networkName := f.Get("network_name").(string)

fmt.Fprintf(w, " │ %s │\n",
util.RightPad(startTime.Format(time.RFC822), (colWidth+3)*3),
utils.RightPad(startTime.Format(time.RFC822), (colWidth+3)*3),
)
fmt.Fprintf(w, " │ %s │\n",
util.RightPad(fmt.Sprintf("AS%d, %s (%s)", asn, networkName, countryCode), (colWidth+3)*3),
utils.RightPad(fmt.Sprintf("AS%d, %s (%s)", asn, networkName, countryCode), (colWidth+3)*3),
)
fmt.Fprintf(w, " │ %s %s %s │\n",
util.RightPad(fmt.Sprintf("%.2fs", totalRuntime), colWidth),
util.RightPad(fmt.Sprintf("%d/%d anmls", anomalyCount, totalCount), colWidth),
util.RightPad(fmt.Sprintf("⬆ %s ⬇ %s", formatSize(dataUp), formatSize(dataDown)), colWidth+4))
utils.RightPad(fmt.Sprintf("%.2fs", totalRuntime), colWidth),
utils.RightPad(fmt.Sprintf("%d/%d anmls", anomalyCount, totalCount), colWidth),
utils.RightPad(fmt.Sprintf("⬆ %s ⬇ %s", formatSize(dataUp), formatSize(dataDown)), colWidth+4))
fmt.Fprintf(w, " └────────────────────────────────────────────────┘\n")

return nil
Expand Down
Loading

0 comments on commit 0bfd3f0

Please sign in to comment.