2021-12-07 13:31:39 +01:00
|
|
|
/*
|
|
|
|
GoToSocial
|
2021-12-20 18:42:19 +01:00
|
|
|
Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
|
2021-12-07 13:31:39 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero 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 Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/admin/account"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/admin/trans"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
func adminCommands() *cobra.Command {
|
|
|
|
adminCmd := &cobra.Command{
|
|
|
|
Use: "admin",
|
|
|
|
Short: "gotosocial admin-related tasks",
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
ADMIN ACCOUNT COMMANDS
|
|
|
|
*/
|
|
|
|
|
|
|
|
adminAccountCmd := &cobra.Command{
|
|
|
|
Use: "account",
|
|
|
|
Short: "admin commands related to accounts",
|
|
|
|
}
|
2022-05-30 14:41:24 +02:00
|
|
|
config.AddAdminAccount(adminAccountCmd)
|
2021-12-07 13:31:39 +01:00
|
|
|
|
|
|
|
adminAccountCreateCmd := &cobra.Command{
|
|
|
|
Use: "create",
|
|
|
|
Short: "create a new account",
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
2022-05-16 14:13:19 +02:00
|
|
|
return preRun(preRunArgs{cmd: cmd})
|
2021-12-07 13:31:39 +01:00
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return run(cmd.Context(), account.Create)
|
|
|
|
},
|
|
|
|
}
|
2022-05-30 14:41:24 +02:00
|
|
|
config.AddAdminAccountCreate(adminAccountCreateCmd)
|
2021-12-07 13:31:39 +01:00
|
|
|
adminAccountCmd.AddCommand(adminAccountCreateCmd)
|
|
|
|
|
|
|
|
adminAccountConfirmCmd := &cobra.Command{
|
|
|
|
Use: "confirm",
|
|
|
|
Short: "confirm an existing account manually, thereby skipping email confirmation",
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
2022-05-16 14:13:19 +02:00
|
|
|
return preRun(preRunArgs{cmd: cmd})
|
2021-12-07 13:31:39 +01:00
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return run(cmd.Context(), account.Confirm)
|
|
|
|
},
|
|
|
|
}
|
2022-05-30 14:41:24 +02:00
|
|
|
config.AddAdminAccount(adminAccountConfirmCmd)
|
2021-12-07 13:31:39 +01:00
|
|
|
adminAccountCmd.AddCommand(adminAccountConfirmCmd)
|
|
|
|
|
|
|
|
adminAccountPromoteCmd := &cobra.Command{
|
|
|
|
Use: "promote",
|
|
|
|
Short: "promote an account to admin",
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
2022-05-16 14:13:19 +02:00
|
|
|
return preRun(preRunArgs{cmd: cmd})
|
2021-12-07 13:31:39 +01:00
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return run(cmd.Context(), account.Promote)
|
|
|
|
},
|
|
|
|
}
|
2022-05-30 14:41:24 +02:00
|
|
|
config.AddAdminAccount(adminAccountPromoteCmd)
|
2021-12-07 13:31:39 +01:00
|
|
|
adminAccountCmd.AddCommand(adminAccountPromoteCmd)
|
|
|
|
|
|
|
|
adminAccountDemoteCmd := &cobra.Command{
|
|
|
|
Use: "demote",
|
|
|
|
Short: "demote an account from admin to normal user",
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
2022-05-16 14:13:19 +02:00
|
|
|
return preRun(preRunArgs{cmd: cmd})
|
2021-12-07 13:31:39 +01:00
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return run(cmd.Context(), account.Demote)
|
|
|
|
},
|
|
|
|
}
|
2022-05-30 14:41:24 +02:00
|
|
|
config.AddAdminAccount(adminAccountDemoteCmd)
|
2021-12-07 13:31:39 +01:00
|
|
|
adminAccountCmd.AddCommand(adminAccountDemoteCmd)
|
|
|
|
|
|
|
|
adminAccountDisableCmd := &cobra.Command{
|
|
|
|
Use: "disable",
|
|
|
|
Short: "prevent an account from signing in or posting etc, but don't delete anything",
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
2022-05-16 14:13:19 +02:00
|
|
|
return preRun(preRunArgs{cmd: cmd})
|
2021-12-07 13:31:39 +01:00
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return run(cmd.Context(), account.Disable)
|
|
|
|
},
|
|
|
|
}
|
2022-05-30 14:41:24 +02:00
|
|
|
config.AddAdminAccount(adminAccountDisableCmd)
|
2021-12-07 13:31:39 +01:00
|
|
|
adminAccountCmd.AddCommand(adminAccountDisableCmd)
|
|
|
|
|
|
|
|
adminAccountSuspendCmd := &cobra.Command{
|
|
|
|
Use: "suspend",
|
|
|
|
Short: "completely remove an account and all of its posts, media, etc",
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
2022-05-16 14:13:19 +02:00
|
|
|
return preRun(preRunArgs{cmd: cmd})
|
2021-12-07 13:31:39 +01:00
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return run(cmd.Context(), account.Suspend)
|
|
|
|
},
|
|
|
|
}
|
2022-05-30 14:41:24 +02:00
|
|
|
config.AddAdminAccount(adminAccountSuspendCmd)
|
2021-12-07 13:31:39 +01:00
|
|
|
adminAccountCmd.AddCommand(adminAccountSuspendCmd)
|
|
|
|
|
|
|
|
adminAccountPasswordCmd := &cobra.Command{
|
|
|
|
Use: "password",
|
|
|
|
Short: "set a new password for the given account",
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
2022-05-16 14:13:19 +02:00
|
|
|
return preRun(preRunArgs{cmd: cmd})
|
2021-12-07 13:31:39 +01:00
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return run(cmd.Context(), account.Password)
|
|
|
|
},
|
|
|
|
}
|
2022-05-30 14:41:24 +02:00
|
|
|
config.AddAdminAccount(adminAccountPasswordCmd)
|
|
|
|
config.AddAdminAccountPassword(adminAccountPasswordCmd)
|
2021-12-07 13:31:39 +01:00
|
|
|
adminAccountCmd.AddCommand(adminAccountPasswordCmd)
|
|
|
|
|
|
|
|
adminCmd.AddCommand(adminAccountCmd)
|
|
|
|
|
|
|
|
/*
|
|
|
|
ADMIN IMPORT/EXPORT COMMANDS
|
|
|
|
*/
|
|
|
|
|
|
|
|
adminExportCmd := &cobra.Command{
|
|
|
|
Use: "export",
|
|
|
|
Short: "export data from the database to file at the given path",
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
2022-05-16 14:13:19 +02:00
|
|
|
return preRun(preRunArgs{cmd: cmd})
|
2021-12-07 13:31:39 +01:00
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return run(cmd.Context(), trans.Export)
|
|
|
|
},
|
|
|
|
}
|
2022-05-30 14:41:24 +02:00
|
|
|
config.AddAdminTrans(adminExportCmd)
|
2021-12-07 13:31:39 +01:00
|
|
|
adminCmd.AddCommand(adminExportCmd)
|
|
|
|
|
|
|
|
adminImportCmd := &cobra.Command{
|
|
|
|
Use: "import",
|
|
|
|
Short: "import data from a file into the database",
|
|
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
2022-05-16 14:13:19 +02:00
|
|
|
return preRun(preRunArgs{cmd: cmd})
|
2021-12-07 13:31:39 +01:00
|
|
|
},
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
return run(cmd.Context(), trans.Import)
|
|
|
|
},
|
|
|
|
}
|
2022-05-30 14:41:24 +02:00
|
|
|
config.AddAdminTrans(adminImportCmd)
|
2021-12-07 13:31:39 +01:00
|
|
|
adminCmd.AddCommand(adminImportCmd)
|
|
|
|
|
|
|
|
return adminCmd
|
|
|
|
}
|