2018-06-25 16:31:44 +02:00
package onboard
import (
2019-12-02 14:15:50 +01:00
"fmt"
2018-09-17 16:16:56 +02:00
2018-06-25 16:31:44 +02:00
"github.com/alecthomas/kingpin"
2018-07-30 18:51:44 +02:00
"github.com/apex/log"
2019-12-02 14:15:50 +01:00
"github.com/fatih/color"
2018-06-25 16:31:44 +02:00
"github.com/ooni/probe-cli/internal/cli/root"
2020-11-13 16:58:14 +01:00
"github.com/ooni/probe-cli/internal/config"
2020-11-13 18:42:10 +01:00
"github.com/ooni/probe-cli/internal/ooni"
2019-12-02 14:15:50 +01:00
"github.com/ooni/probe-cli/internal/output"
"github.com/pkg/errors"
"gopkg.in/AlecAivazis/survey.v1"
2018-06-25 16:31:44 +02:00
)
2019-12-02 14:15:50 +01:00
// 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 ( )
2020-11-24 09:19:34 +01:00
err := output . PressEnterToContinue ( "Press 'Enter' to continue..." )
if err != nil {
return err
}
2019-12-02 14:15:50 +01:00
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 ( )
2020-11-24 09:19:34 +01:00
err = output . PressEnterToContinue ( "Press 'Enter' to continue..." )
if err != nil {
return err
}
2019-12-02 14:15:50 +01:00
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" ,
}
2020-11-24 09:19:34 +01:00
if err := survey . AskOne ( quiz1 , & answer , nil ) ; err != nil {
return err
}
2019-12-02 14:15:50 +01:00
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" ,
}
2020-11-24 09:19:34 +01:00
if err := survey . AskOne ( quiz2 , & answer , nil ) ; err != nil {
return err
}
2019-12-02 14:15:50 +01:00
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 ,
}
2020-11-24 09:19:34 +01:00
if err := survey . AskOne ( prompt , & changeDefaults , nil ) ; err != nil {
return err
}
2019-12-02 14:15:50 +01:00
settings := struct {
IncludeIP bool
IncludeNetwork bool
UploadResults bool
SendCrashReports bool
} { }
settings . IncludeIP = false
settings . IncludeNetwork = 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 : "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 ,
} ,
} ,
}
2020-11-24 09:19:34 +01:00
if err := survey . Ask ( qs , & settings ) ; err != nil {
2019-12-02 14:15:50 +01:00
log . WithError ( err ) . Error ( "there was an error in parsing your responses" )
return err
}
}
config . Lock ( )
config . InformedConsent = true
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
2020-11-13 19:01:06 +01:00
func MaybeOnboarding ( probe * ooni . Probe ) error {
2020-11-13 20:07:30 +01:00
if probe . Config ( ) . InformedConsent == false {
if probe . IsBatch ( ) == true {
2019-12-02 14:15:50 +01:00
return errors . New ( "cannot run onboarding in batch mode" )
}
2020-11-13 20:07:30 +01:00
if err := Onboarding ( probe . Config ( ) ) ; err != nil {
2019-12-02 14:15:50 +01:00
return errors . Wrap ( err , "onboarding" )
}
}
return nil
}
2018-06-25 16:31:44 +02:00
func init ( ) {
cmd := root . Command ( "onboard" , "Starts the onboarding process" )
2018-07-30 18:51:44 +02:00
yes := cmd . Flag ( "yes" , "Answer yes to all the onboarding questions." ) . Bool ( )
2018-06-25 16:31:44 +02:00
cmd . Action ( func ( _ * kingpin . ParseContext ) error {
2020-11-13 19:01:06 +01:00
probe , err := root . Init ( )
2018-06-25 17:09:10 +02:00
if err != nil {
return err
}
2018-07-30 18:51:44 +02:00
if * yes == true {
2020-11-13 20:07:30 +01:00
probe . Config ( ) . Lock ( )
probe . Config ( ) . InformedConsent = true
probe . Config ( ) . Unlock ( )
2018-07-30 18:51:44 +02:00
2020-11-13 20:07:30 +01:00
if err := probe . Config ( ) . Write ( ) ; err != nil {
2018-07-30 18:51:44 +02:00
log . WithError ( err ) . Error ( "failed to write config file" )
return err
}
return nil
}
2020-11-13 20:07:30 +01:00
if probe . IsBatch ( ) == true {
2018-09-17 16:16:56 +02:00
return errors . New ( "cannot do onboarding in batch mode" )
}
2018-07-30 18:51:44 +02:00
2020-11-13 20:07:30 +01:00
return Onboarding ( probe . Config ( ) )
2018-06-25 16:31:44 +02:00
} )
}