mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-10-10 00:00:30 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7145d4ca07 | ||
|
|
9683a23fda | ||
|
|
5e182d84d0 | ||
|
|
9800e7e03d |
@@ -3,11 +3,12 @@ package cmd
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||
"github.com/1Panel-dev/1Panel/cmd/server/app"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"io"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -31,6 +32,10 @@ var initCmd = &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "初始化应用",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !isRoot() {
|
||||
fmt.Println("请使用 sudo 1pctl app init 或者切换到 root 用户")
|
||||
return nil
|
||||
}
|
||||
if len(args) > 0 {
|
||||
appKey = args[0]
|
||||
if len(args) > 1 {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -22,6 +24,10 @@ var resetMFACmd = &cobra.Command{
|
||||
Use: "mfa",
|
||||
Short: "取消 1Panel 两步验证",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !isRoot() {
|
||||
fmt.Println("请使用 sudo 1pctl reset mfa 或者切换到 root 用户")
|
||||
return nil
|
||||
}
|
||||
db, err := loadDBConn()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -34,6 +40,10 @@ var resetSSLCmd = &cobra.Command{
|
||||
Use: "https",
|
||||
Short: "取消 1Panel https 方式登录",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !isRoot() {
|
||||
fmt.Println("请使用 sudo 1pctl reset https 或者切换到 root 用户")
|
||||
return nil
|
||||
}
|
||||
db, err := loadDBConn()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -46,6 +56,10 @@ var resetEntranceCmd = &cobra.Command{
|
||||
Use: "entrance",
|
||||
Short: "取消 1Panel 安全入口",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !isRoot() {
|
||||
fmt.Println("请使用 sudo 1pctl reset entrance 或者切换到 root 用户")
|
||||
return nil
|
||||
}
|
||||
db, err := loadDBConn()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -58,6 +72,10 @@ var resetBindIpsCmd = &cobra.Command{
|
||||
Use: "ips",
|
||||
Short: "取消 1Panel 授权 IP 限制",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !isRoot() {
|
||||
fmt.Println("请使用 sudo 1pctl reset ips 或者切换到 root 用户")
|
||||
return nil
|
||||
}
|
||||
db, err := loadDBConn()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -70,6 +88,10 @@ var resetDomainCmd = &cobra.Command{
|
||||
Use: "domain",
|
||||
Short: "取消 1Panel 访问域名绑定",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !isRoot() {
|
||||
fmt.Println("请使用 sudo 1pctl reset domain 或者切换到 root 用户")
|
||||
return nil
|
||||
}
|
||||
db, err := loadDBConn()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -2,6 +2,7 @@ package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/user"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -61,3 +62,11 @@ func getSettingByKey(db *gorm.DB, key string) string {
|
||||
func setSettingByKey(db *gorm.DB, key, value string) 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",
|
||||
Short: "获取用户信息",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !isRoot() {
|
||||
fmt.Println("请使用 sudo 1pctl user-info 或者切换到 root 用户")
|
||||
return nil
|
||||
}
|
||||
db, err := loadDBConn()
|
||||
if err != nil {
|
||||
return fmt.Errorf("init my db conn failed, err: %v \n", err)
|
||||
|
||||
@@ -18,6 +18,10 @@ var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "获取系统版本信息",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !isRoot() {
|
||||
fmt.Println("请使用 sudo 1pctl version 或者切换到 root 用户")
|
||||
return nil
|
||||
}
|
||||
db, err := loadDBConn()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
}
|
||||
}
|
||||
&.is-active {
|
||||
background-color: var(--el-menu-item-bg-color-active);;
|
||||
background-color: var(--el-menu-item-bg-color-active);
|
||||
border: 2px solid $primary-color;
|
||||
|
||||
&::before {
|
||||
@@ -81,3 +81,7 @@
|
||||
padding: 4px 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.el-sub-menu__title {
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
@@ -374,9 +374,10 @@ const onLoadCurrentInfo = async () => {
|
||||
const res = await loadCurrentInfo(searchInfo.ioOption, searchInfo.netOption);
|
||||
currentInfo.value.timeSinceUptime = res.data.timeSinceUptime;
|
||||
|
||||
let timeInterval = Number(res.data.uptime - currentInfo.value.uptime) || 3;
|
||||
currentChartInfo.netBytesSent =
|
||||
res.data.netBytesSent - currentInfo.value.netBytesSent > 0
|
||||
? Number(((res.data.netBytesSent - currentInfo.value.netBytesSent) / 1024 / 3).toFixed(2))
|
||||
? Number(((res.data.netBytesSent - currentInfo.value.netBytesSent) / 1024 / timeInterval).toFixed(2))
|
||||
: 0;
|
||||
netBytesSents.value.push(currentChartInfo.netBytesSent);
|
||||
if (netBytesSents.value.length > 20) {
|
||||
@@ -385,7 +386,7 @@ const onLoadCurrentInfo = async () => {
|
||||
|
||||
currentChartInfo.netBytesRecv =
|
||||
res.data.netBytesRecv - currentInfo.value.netBytesRecv > 0
|
||||
? Number(((res.data.netBytesRecv - currentInfo.value.netBytesRecv) / 1024 / 3).toFixed(2))
|
||||
? Number(((res.data.netBytesRecv - currentInfo.value.netBytesRecv) / 1024 / timeInterval).toFixed(2))
|
||||
: 0;
|
||||
netBytesRecvs.value.push(currentChartInfo.netBytesRecv);
|
||||
if (netBytesRecvs.value.length > 20) {
|
||||
@@ -394,7 +395,7 @@ const onLoadCurrentInfo = async () => {
|
||||
|
||||
currentChartInfo.ioReadBytes =
|
||||
res.data.ioReadBytes - currentInfo.value.ioReadBytes > 0
|
||||
? Number(((res.data.ioReadBytes - currentInfo.value.ioReadBytes) / 1024 / 1024 / 3).toFixed(2))
|
||||
? Number(((res.data.ioReadBytes - currentInfo.value.ioReadBytes) / 1024 / 1024 / timeInterval).toFixed(2))
|
||||
: 0;
|
||||
ioReadBytes.value.push(currentChartInfo.ioReadBytes);
|
||||
if (ioReadBytes.value.length > 20) {
|
||||
@@ -403,17 +404,17 @@ const onLoadCurrentInfo = async () => {
|
||||
|
||||
currentChartInfo.ioWriteBytes =
|
||||
res.data.ioWriteBytes - currentInfo.value.ioWriteBytes > 0
|
||||
? Number(((res.data.ioWriteBytes - currentInfo.value.ioWriteBytes) / 1024 / 1024 / 3).toFixed(2))
|
||||
? Number(((res.data.ioWriteBytes - currentInfo.value.ioWriteBytes) / 1024 / 1024 / timeInterval).toFixed(2))
|
||||
: 0;
|
||||
ioWriteBytes.value.push(currentChartInfo.ioWriteBytes);
|
||||
if (ioWriteBytes.value.length > 20) {
|
||||
ioWriteBytes.value.splice(0, 1);
|
||||
}
|
||||
currentChartInfo.ioCount = Math.round(Number((res.data.ioCount - currentInfo.value.ioCount) / 3));
|
||||
currentChartInfo.ioCount = Math.round(Number((res.data.ioCount - currentInfo.value.ioCount) / timeInterval));
|
||||
let ioReadTime = res.data.ioReadTime - currentInfo.value.ioReadTime;
|
||||
let ioWriteTime = res.data.ioWriteTime - currentInfo.value.ioWriteTime;
|
||||
let ioChoose = ioReadTime > ioWriteTime ? ioReadTime : ioWriteTime;
|
||||
currentChartInfo.ioTime = Math.round(Number(ioChoose / 3));
|
||||
currentChartInfo.ioTime = Math.round(Number(ioChoose / timeInterval));
|
||||
|
||||
timeIODatas.value.push(dateFormatForSecond(res.data.shotTime));
|
||||
if (timeIODatas.value.length > 20) {
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
@search="search"
|
||||
:data="data"
|
||||
>
|
||||
<el-table-column type="selection" :selectable="selectable" fix />
|
||||
<el-table-column type="selection" fix />
|
||||
<el-table-column :label="$t('commons.table.protocol')" :min-width="90" prop="protocol" />
|
||||
<el-table-column :label="$t('commons.table.port')" :min-width="120" prop="port" />
|
||||
<el-table-column :label="$t('commons.table.status')" :min-width="120">
|
||||
@@ -87,7 +87,6 @@
|
||||
<template #default="{ row }">
|
||||
<el-button
|
||||
v-if="row.strategy === 'accept'"
|
||||
:disabled="row.appName === '1panel'"
|
||||
@click="onChangeStatus(row, 'drop')"
|
||||
link
|
||||
type="success"
|
||||
@@ -303,28 +302,18 @@ const onDelete = async (row: Host.RuleInfo | null) => {
|
||||
});
|
||||
};
|
||||
|
||||
function selectable(row) {
|
||||
return row.appName !== '1panel';
|
||||
}
|
||||
|
||||
const buttons = [
|
||||
{
|
||||
label: i18n.global.t('commons.button.edit'),
|
||||
click: (row: Host.RulePort) => {
|
||||
onOpenDialog('edit', row);
|
||||
},
|
||||
disabled: (row: any) => {
|
||||
return row.appName === '1panel';
|
||||
},
|
||||
},
|
||||
{
|
||||
label: i18n.global.t('commons.button.delete'),
|
||||
click: (row: Host.RuleInfo) => {
|
||||
onDelete(row);
|
||||
},
|
||||
disabled: (row: any) => {
|
||||
return row.appName === '1panel';
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user