gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

admin.go (6789B)


      1 // GoToSocial
      2 // Copyright (C) GoToSocial Authors admin@gotosocial.org
      3 // SPDX-License-Identifier: AGPL-3.0-or-later
      4 //
      5 // This program is free software: you can redistribute it and/or modify
      6 // it under the terms of the GNU Affero General Public License as published by
      7 // the Free Software Foundation, either version 3 of the License, or
      8 // (at your option) any later version.
      9 //
     10 // This program is distributed in the hope that it will be useful,
     11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 // GNU Affero General Public License for more details.
     14 //
     15 // You should have received a copy of the GNU Affero General Public License
     16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
     17 
     18 package main
     19 
     20 import (
     21 	"github.com/spf13/cobra"
     22 	"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/admin/account"
     23 	"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/admin/media/prune"
     24 	"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action/admin/trans"
     25 	"github.com/superseriousbusiness/gotosocial/internal/config"
     26 )
     27 
     28 func adminCommands() *cobra.Command {
     29 	adminCmd := &cobra.Command{
     30 		Use:   "admin",
     31 		Short: "gotosocial admin-related tasks",
     32 	}
     33 
     34 	/*
     35 	   ADMIN ACCOUNT COMMANDS
     36 	*/
     37 
     38 	adminAccountCmd := &cobra.Command{
     39 		Use:   "account",
     40 		Short: "admin commands related to local (this instance) accounts",
     41 	}
     42 	config.AddAdminAccount(adminAccountCmd)
     43 
     44 	adminAccountCreateCmd := &cobra.Command{
     45 		Use:   "create",
     46 		Short: "create a new local account",
     47 		PreRunE: func(cmd *cobra.Command, args []string) error {
     48 			return preRun(preRunArgs{cmd: cmd})
     49 		},
     50 		RunE: func(cmd *cobra.Command, args []string) error {
     51 			return run(cmd.Context(), account.Create)
     52 		},
     53 	}
     54 	config.AddAdminAccountCreate(adminAccountCreateCmd)
     55 	adminAccountCmd.AddCommand(adminAccountCreateCmd)
     56 
     57 	adminAccountListCmd := &cobra.Command{
     58 		Use:   "list",
     59 		Short: "list all existing local accounts",
     60 		PreRunE: func(cmd *cobra.Command, args []string) error {
     61 			return preRun(preRunArgs{cmd: cmd})
     62 		},
     63 		RunE: func(cmd *cobra.Command, args []string) error {
     64 			return run(cmd.Context(), account.List)
     65 		},
     66 	}
     67 	adminAccountCmd.AddCommand(adminAccountListCmd)
     68 
     69 	adminAccountConfirmCmd := &cobra.Command{
     70 		Use:   "confirm",
     71 		Short: "confirm an existing local account manually, thereby skipping email confirmation",
     72 		PreRunE: func(cmd *cobra.Command, args []string) error {
     73 			return preRun(preRunArgs{cmd: cmd})
     74 		},
     75 		RunE: func(cmd *cobra.Command, args []string) error {
     76 			return run(cmd.Context(), account.Confirm)
     77 		},
     78 	}
     79 	config.AddAdminAccount(adminAccountConfirmCmd)
     80 	adminAccountCmd.AddCommand(adminAccountConfirmCmd)
     81 
     82 	adminAccountPromoteCmd := &cobra.Command{
     83 		Use:   "promote",
     84 		Short: "promote a local account to admin",
     85 		PreRunE: func(cmd *cobra.Command, args []string) error {
     86 			return preRun(preRunArgs{cmd: cmd})
     87 		},
     88 		RunE: func(cmd *cobra.Command, args []string) error {
     89 			return run(cmd.Context(), account.Promote)
     90 		},
     91 	}
     92 	config.AddAdminAccount(adminAccountPromoteCmd)
     93 	adminAccountCmd.AddCommand(adminAccountPromoteCmd)
     94 
     95 	adminAccountDemoteCmd := &cobra.Command{
     96 		Use:   "demote",
     97 		Short: "demote a local account from admin to normal user",
     98 		PreRunE: func(cmd *cobra.Command, args []string) error {
     99 			return preRun(preRunArgs{cmd: cmd})
    100 		},
    101 		RunE: func(cmd *cobra.Command, args []string) error {
    102 			return run(cmd.Context(), account.Demote)
    103 		},
    104 	}
    105 	config.AddAdminAccount(adminAccountDemoteCmd)
    106 	adminAccountCmd.AddCommand(adminAccountDemoteCmd)
    107 
    108 	adminAccountDisableCmd := &cobra.Command{
    109 		Use:   "disable",
    110 		Short: "prevent a local account from signing in or posting etc, but don't delete anything",
    111 		PreRunE: func(cmd *cobra.Command, args []string) error {
    112 			return preRun(preRunArgs{cmd: cmd})
    113 		},
    114 		RunE: func(cmd *cobra.Command, args []string) error {
    115 			return run(cmd.Context(), account.Disable)
    116 		},
    117 	}
    118 	config.AddAdminAccount(adminAccountDisableCmd)
    119 	adminAccountCmd.AddCommand(adminAccountDisableCmd)
    120 
    121 	adminAccountPasswordCmd := &cobra.Command{
    122 		Use:   "password",
    123 		Short: "set a new password for the given local account",
    124 		PreRunE: func(cmd *cobra.Command, args []string) error {
    125 			return preRun(preRunArgs{cmd: cmd})
    126 		},
    127 		RunE: func(cmd *cobra.Command, args []string) error {
    128 			return run(cmd.Context(), account.Password)
    129 		},
    130 	}
    131 	config.AddAdminAccount(adminAccountPasswordCmd)
    132 	config.AddAdminAccountPassword(adminAccountPasswordCmd)
    133 	adminAccountCmd.AddCommand(adminAccountPasswordCmd)
    134 
    135 	adminCmd.AddCommand(adminAccountCmd)
    136 
    137 	/*
    138 	   ADMIN IMPORT/EXPORT COMMANDS
    139 	*/
    140 
    141 	adminExportCmd := &cobra.Command{
    142 		Use:   "export",
    143 		Short: "export data from the database to file at the given path",
    144 		PreRunE: func(cmd *cobra.Command, args []string) error {
    145 			return preRun(preRunArgs{cmd: cmd})
    146 		},
    147 		RunE: func(cmd *cobra.Command, args []string) error {
    148 			return run(cmd.Context(), trans.Export)
    149 		},
    150 	}
    151 	config.AddAdminTrans(adminExportCmd)
    152 	adminCmd.AddCommand(adminExportCmd)
    153 
    154 	adminImportCmd := &cobra.Command{
    155 		Use:   "import",
    156 		Short: "import data from a file into the database",
    157 		PreRunE: func(cmd *cobra.Command, args []string) error {
    158 			return preRun(preRunArgs{cmd: cmd})
    159 		},
    160 		RunE: func(cmd *cobra.Command, args []string) error {
    161 			return run(cmd.Context(), trans.Import)
    162 		},
    163 	}
    164 	config.AddAdminTrans(adminImportCmd)
    165 	adminCmd.AddCommand(adminImportCmd)
    166 
    167 	/*
    168 		ADMIN MEDIA COMMANDS
    169 	*/
    170 
    171 	adminMediaCmd := &cobra.Command{
    172 		Use:   "media",
    173 		Short: "admin commands related stored media attachments/emojis",
    174 	}
    175 
    176 	/*
    177 		ADMIN MEDIA PRUNE COMMANDS
    178 	*/
    179 	adminMediaPruneCmd := &cobra.Command{
    180 		Use:   "prune",
    181 		Short: "admin commands for pruning unused/orphaned media from storage",
    182 	}
    183 
    184 	adminMediaPruneOrphanedCmd := &cobra.Command{
    185 		Use:   "orphaned",
    186 		Short: "prune orphaned media from storage",
    187 		PreRunE: func(cmd *cobra.Command, args []string) error {
    188 			return preRun(preRunArgs{cmd: cmd})
    189 		},
    190 		RunE: func(cmd *cobra.Command, args []string) error {
    191 			return run(cmd.Context(), prune.Orphaned)
    192 		},
    193 	}
    194 	config.AddAdminMediaPrune(adminMediaPruneOrphanedCmd)
    195 	adminMediaPruneCmd.AddCommand(adminMediaPruneOrphanedCmd)
    196 
    197 	adminMediaPruneRemoteCmd := &cobra.Command{
    198 		Use:   "remote",
    199 		Short: "prune unused/stale remote media from storage, older than given number of days",
    200 		PreRunE: func(cmd *cobra.Command, args []string) error {
    201 			return preRun(preRunArgs{cmd: cmd})
    202 		},
    203 		RunE: func(cmd *cobra.Command, args []string) error {
    204 			return run(cmd.Context(), prune.Remote)
    205 		},
    206 	}
    207 	config.AddAdminMediaPrune(adminMediaPruneRemoteCmd)
    208 	adminMediaPruneCmd.AddCommand(adminMediaPruneRemoteCmd)
    209 
    210 	adminMediaCmd.AddCommand(adminMediaPruneCmd)
    211 
    212 	adminCmd.AddCommand(adminMediaCmd)
    213 
    214 	return adminCmd
    215 }