summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/admin.go23
-rw-r--r--cmd/cmd.go20
-rw-r--r--cmd/mailer.go48
3 files changed, 91 insertions, 0 deletions
diff --git a/cmd/admin.go b/cmd/admin.go
index d503657250..8989ec2ebd 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -34,6 +34,7 @@ var (
subcmdRepoSyncReleases,
subcmdRegenerate,
subcmdAuth,
+ subcmdSendMail,
},
}
@@ -282,6 +283,28 @@ var (
Action: runAddOauth,
Flags: oauthCLIFlags,
}
+
+ subcmdSendMail = cli.Command{
+ Name: "sendmail",
+ Usage: "Send a message to all users",
+ Action: runSendMail,
+ Flags: []cli.Flag{
+ cli.StringFlag{
+ Name: "title",
+ Usage: `a title of a message`,
+ Value: "",
+ },
+ cli.StringFlag{
+ Name: "content",
+ Usage: "a content of a message",
+ Value: "",
+ },
+ cli.BoolFlag{
+ Name: "force,f",
+ Usage: "A flag to bypass a confirmation step",
+ },
+ },
+ }
)
func runChangePassword(c *cli.Context) error {
diff --git a/cmd/cmd.go b/cmd/cmd.go
index d05eb8b1a2..bb768cc159 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -9,6 +9,7 @@ package cmd
import (
"errors"
"fmt"
+ "strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/setting"
@@ -32,6 +33,25 @@ func argsSet(c *cli.Context, args ...string) error {
return nil
}
+// confirm waits for user input which confirms an action
+func confirm() (bool, error) {
+ var response string
+
+ _, err := fmt.Scanln(&response)
+ if err != nil {
+ return false, err
+ }
+
+ switch strings.ToLower(response) {
+ case "y", "yes":
+ return true, nil
+ case "n", "no":
+ return false, nil
+ default:
+ return false, errors.New(response + " isn't a correct confirmation string")
+ }
+}
+
func initDB() error {
return initDBDisableConsole(false)
}
diff --git a/cmd/mailer.go b/cmd/mailer.go
new file mode 100644
index 0000000000..a9a9048a5e
--- /dev/null
+++ b/cmd/mailer.go
@@ -0,0 +1,48 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package cmd
+
+import (
+ "fmt"
+ "net/http"
+
+ "code.gitea.io/gitea/modules/private"
+ "github.com/urfave/cli"
+)
+
+func runSendMail(c *cli.Context) error {
+ if err := argsSet(c, "title"); err != nil {
+ return err
+ }
+
+ subject := c.String("title")
+ confirmSkiped := c.Bool("force")
+ body := c.String("content")
+
+ if !confirmSkiped {
+ if len(body) == 0 {
+ fmt.Print("warning: Content is empty")
+ }
+
+ fmt.Print("Proceed with sending email? [Y/n] ")
+ isConfirmed, err := confirm()
+ if err != nil {
+ return err
+ } else if !isConfirmed {
+ fmt.Println("The mail was not sent")
+ return nil
+ }
+ }
+
+ status, message := private.SendEmail(subject, body, nil)
+ if status != http.StatusOK {
+ fmt.Printf("error: %s", message)
+ return nil
+ }
+
+ fmt.Printf("Succseded: %s", message)
+
+ return nil
+}