forked from Silverfish/proton-bridge
chore: merge release/perth_narrows into devel
This commit is contained in:
@ -115,7 +115,7 @@ func (f *frontendCLI) showAccountAddressInfo(user bridge.UserInfo, address strin
|
||||
f.Println("")
|
||||
}
|
||||
|
||||
func (f *frontendCLI) loginAccount(c *ishell.Context) { //nolint:funlen
|
||||
func (f *frontendCLI) loginAccount(c *ishell.Context) {
|
||||
f.ShowPrompt(false)
|
||||
defer f.ShowPrompt(true)
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ type frontendCLI struct {
|
||||
}
|
||||
|
||||
// New returns a new CLI frontend configured with the given options.
|
||||
func New(bridge *bridge.Bridge, restarter *restarter.Restarter, eventCh <-chan events.Event) *frontendCLI { //nolint:funlen,revive
|
||||
func New(bridge *bridge.Bridge, restarter *restarter.Restarter, eventCh <-chan events.Event) *frontendCLI { //nolint:revive
|
||||
fe := &frontendCLI{
|
||||
Shell: ishell.New(),
|
||||
bridge: bridge,
|
||||
@ -138,12 +138,16 @@ func New(bridge *bridge.Bridge, restarter *restarter.Restarter, eventCh <-chan e
|
||||
fe.AddCmd(configureCmd)
|
||||
|
||||
// TLS commands.
|
||||
exportTLSCmd := &ishell.Cmd{
|
||||
Name: "export-tls",
|
||||
fe.AddCmd(&ishell.Cmd{
|
||||
Name: "export-tls-cert",
|
||||
Help: "Export the TLS certificate used by the Bridge",
|
||||
Func: fe.exportTLSCerts,
|
||||
}
|
||||
fe.AddCmd(exportTLSCmd)
|
||||
})
|
||||
fe.AddCmd(&ishell.Cmd{
|
||||
Name: "import-tls-cert",
|
||||
Help: "Import a TLS certificate to be used by the Bridge",
|
||||
Func: fe.importTLSCerts,
|
||||
})
|
||||
|
||||
// All mail visibility commands.
|
||||
allMailCmd := &ishell.Cmd{
|
||||
@ -280,7 +284,7 @@ func New(bridge *bridge.Bridge, restarter *restarter.Restarter, eventCh <-chan e
|
||||
return fe
|
||||
}
|
||||
|
||||
func (f *frontendCLI) watchEvents(eventCh <-chan events.Event) { // nolint:funlen
|
||||
func (f *frontendCLI) watchEvents(eventCh <-chan events.Event) { // nolint:gocyclo
|
||||
// GODT-1949: Better error events.
|
||||
for _, err := range f.bridge.GetErrors() {
|
||||
switch {
|
||||
@ -289,12 +293,6 @@ func (f *frontendCLI) watchEvents(eventCh <-chan events.Event) { // nolint:funle
|
||||
|
||||
case errors.Is(err, bridge.ErrVaultInsecure):
|
||||
f.notifyCredentialsError()
|
||||
|
||||
case errors.Is(err, bridge.ErrServeIMAP):
|
||||
f.Println("IMAP server error:", err)
|
||||
|
||||
case errors.Is(err, bridge.ErrServeSMTP):
|
||||
f.Println("SMTP server error:", err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -306,6 +304,12 @@ func (f *frontendCLI) watchEvents(eventCh <-chan events.Event) { // nolint:funle
|
||||
case events.ConnStatusDown:
|
||||
f.notifyInternetOff()
|
||||
|
||||
case events.IMAPServerError:
|
||||
f.Println("IMAP server error:", event.Error)
|
||||
|
||||
case events.SMTPServerError:
|
||||
f.Println("SMTP server error:", event.Error)
|
||||
|
||||
case events.UserDeauth:
|
||||
user, err := f.bridge.GetUserInfo(event.UserID)
|
||||
if err != nil {
|
||||
@ -331,6 +335,17 @@ func (f *frontendCLI) watchEvents(eventCh <-chan events.Event) { // nolint:funle
|
||||
f.Printf("* bad-event synchronize\n")
|
||||
f.Printf("* bad-event logout\n\n")
|
||||
|
||||
case events.IMAPLoginFailed:
|
||||
f.Printf("An IMAP login attempt failed for user %v\n", event.Username)
|
||||
|
||||
case events.UserAddressEnabled:
|
||||
user, err := f.bridge.GetUserInfo(event.UserID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
f.Printf("An address for %s was enabled. You may need to reconfigure your email client.\n", user.Username)
|
||||
|
||||
case events.UserAddressUpdated:
|
||||
user, err := f.bridge.GetUserInfo(event.UserID)
|
||||
if err != nil {
|
||||
@ -339,8 +354,21 @@ func (f *frontendCLI) watchEvents(eventCh <-chan events.Event) { // nolint:funle
|
||||
|
||||
f.Printf("Address changed for %s. You may need to reconfigure your email client.\n", user.Username)
|
||||
|
||||
case events.UserAddressDisabled:
|
||||
user, err := f.bridge.GetUserInfo(event.UserID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
f.Printf("An address for %s was disabled. You may need to reconfigure your email client.\n", user.Username)
|
||||
|
||||
case events.UserAddressDeleted:
|
||||
f.notifyLogout(event.Email)
|
||||
user, err := f.bridge.GetUserInfo(event.UserID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
f.Printf("An address for %s was disabled. You may need to reconfigure your email client.\n", user.Username)
|
||||
|
||||
case events.SyncStarted:
|
||||
user, err := f.bridge.GetUserInfo(event.UserID)
|
||||
|
||||
@ -226,6 +226,27 @@ func (f *frontendCLI) exportTLSCerts(c *ishell.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *frontendCLI) importTLSCerts(c *ishell.Context) {
|
||||
certPath := f.readStringInAttempts("Enter the path to the cert.pem file", c.ReadLine, f.isFile)
|
||||
if certPath == "" {
|
||||
f.printAndLogError(errors.New("failed to get cert path"))
|
||||
return
|
||||
}
|
||||
|
||||
keyPath := f.readStringInAttempts("Enter the path to the key.pem file", c.ReadLine, f.isFile)
|
||||
if keyPath == "" {
|
||||
f.printAndLogError(errors.New("failed to get key path"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := f.bridge.SetBridgeTLSCertPath(certPath, keyPath); err != nil {
|
||||
f.printAndLogError(err)
|
||||
return
|
||||
}
|
||||
|
||||
f.Println("TLS certificate imported. Restart Bridge to use it.")
|
||||
}
|
||||
|
||||
func (f *frontendCLI) isPortFree(port string) bool {
|
||||
port = strings.ReplaceAll(port, ":", "")
|
||||
if port == "" {
|
||||
@ -252,3 +273,12 @@ func (f *frontendCLI) isCacheLocationUsable(location string) bool {
|
||||
|
||||
return stat.IsDir()
|
||||
}
|
||||
|
||||
func (f *frontendCLI) isFile(location string) bool {
|
||||
stat, err := os.Stat(location)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return !stat.IsDir()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user