mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 08:19:15 +08:00
parent
7b1566f4ac
commit
4d2ca1f3a0
@ -3,11 +3,12 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||||
"github.com/1Panel-dev/1Panel/cmd/server/app"
|
"github.com/1Panel-dev/1Panel/cmd/server/app"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -31,6 +32,10 @@ var initCmd = &cobra.Command{
|
|||||||
Use: "init",
|
Use: "init",
|
||||||
Short: "初始化应用",
|
Short: "初始化应用",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if !isRoot() {
|
||||||
|
fmt.Println("请使用 sudo 1pctl app init 或者切换到 root 用户")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
appKey = args[0]
|
appKey = args[0]
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,6 +24,10 @@ var resetMFACmd = &cobra.Command{
|
|||||||
Use: "mfa",
|
Use: "mfa",
|
||||||
Short: "取消 1Panel 两步验证",
|
Short: "取消 1Panel 两步验证",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if !isRoot() {
|
||||||
|
fmt.Println("请使用 sudo 1pctl reset mfa 或者切换到 root 用户")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
db, err := loadDBConn()
|
db, err := loadDBConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -34,6 +40,10 @@ var resetSSLCmd = &cobra.Command{
|
|||||||
Use: "https",
|
Use: "https",
|
||||||
Short: "取消 1Panel https 方式登录",
|
Short: "取消 1Panel https 方式登录",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if !isRoot() {
|
||||||
|
fmt.Println("请使用 sudo 1pctl reset https 或者切换到 root 用户")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
db, err := loadDBConn()
|
db, err := loadDBConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -46,6 +56,10 @@ var resetEntranceCmd = &cobra.Command{
|
|||||||
Use: "entrance",
|
Use: "entrance",
|
||||||
Short: "取消 1Panel 安全入口",
|
Short: "取消 1Panel 安全入口",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if !isRoot() {
|
||||||
|
fmt.Println("请使用 sudo 1pctl reset entrance 或者切换到 root 用户")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
db, err := loadDBConn()
|
db, err := loadDBConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -58,6 +72,10 @@ var resetBindIpsCmd = &cobra.Command{
|
|||||||
Use: "ips",
|
Use: "ips",
|
||||||
Short: "取消 1Panel 授权 IP 限制",
|
Short: "取消 1Panel 授权 IP 限制",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if !isRoot() {
|
||||||
|
fmt.Println("请使用 sudo 1pctl reset ips 或者切换到 root 用户")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
db, err := loadDBConn()
|
db, err := loadDBConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -70,6 +88,10 @@ var resetDomainCmd = &cobra.Command{
|
|||||||
Use: "domain",
|
Use: "domain",
|
||||||
Short: "取消 1Panel 访问域名绑定",
|
Short: "取消 1Panel 访问域名绑定",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if !isRoot() {
|
||||||
|
fmt.Println("请使用 sudo 1pctl reset domain 或者切换到 root 用户")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
db, err := loadDBConn()
|
db, err := loadDBConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -2,6 +2,7 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os/user"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -61,3 +62,11 @@ func getSettingByKey(db *gorm.DB, key string) string {
|
|||||||
func setSettingByKey(db *gorm.DB, key, value string) error {
|
func setSettingByKey(db *gorm.DB, key, value string) error {
|
||||||
return db.Model(&setting{}).Where("key = ?", key).Updates(map[string]interface{}{"value": value}).Error
|
return db.Model(&setting{}).Where("key = ?", key).Updates(map[string]interface{}{"value": value}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isRoot() bool {
|
||||||
|
currentUser, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return currentUser.Uid == "0"
|
||||||
|
}
|
||||||
|
@ -16,6 +16,10 @@ var userinfoCmd = &cobra.Command{
|
|||||||
Use: "user-info",
|
Use: "user-info",
|
||||||
Short: "获取用户信息",
|
Short: "获取用户信息",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if !isRoot() {
|
||||||
|
fmt.Println("请使用 sudo 1pctl user-info 或者切换到 root 用户")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
db, err := loadDBConn()
|
db, err := loadDBConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("init my db conn failed, err: %v \n", err)
|
return fmt.Errorf("init my db conn failed, err: %v \n", err)
|
||||||
|
@ -18,6 +18,10 @@ var versionCmd = &cobra.Command{
|
|||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "获取系统版本信息",
|
Short: "获取系统版本信息",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
if !isRoot() {
|
||||||
|
fmt.Println("请使用 sudo 1pctl version 或者切换到 root 用户")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
db, err := loadDBConn()
|
db, err := loadDBConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user