Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion agent/app/dto/setting.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dto

type SettingInfo struct {
SystemIP string `json:"systemIP"`
DockerSockPath string `json:"dockerSockPath"`
SystemVersion string `json:"systemVersion"`

Expand Down
6 changes: 3 additions & 3 deletions agent/app/repo/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewIMonitorRepo() IMonitorRepo {

func (u *MonitorRepo) GetBase(opts ...DBOption) ([]model.MonitorBase, error) {
var data []model.MonitorBase
db := global.DB
db := global.MonitorDB
for _, opt := range opts {
db = opt(db)
}
Expand All @@ -37,7 +37,7 @@ func (u *MonitorRepo) GetBase(opts ...DBOption) ([]model.MonitorBase, error) {
}
func (u *MonitorRepo) GetIO(opts ...DBOption) ([]model.MonitorIO, error) {
var data []model.MonitorIO
db := global.DB
db := global.MonitorDB
for _, opt := range opts {
db = opt(db)
}
Expand All @@ -46,7 +46,7 @@ func (u *MonitorRepo) GetIO(opts ...DBOption) ([]model.MonitorIO, error) {
}
func (u *MonitorRepo) GetNetwork(opts ...DBOption) ([]model.MonitorNetwork, error) {
var data []model.MonitorNetwork
db := global.DB
db := global.MonitorDB
for _, opt := range opts {
db = opt(db)
}
Expand Down
30 changes: 29 additions & 1 deletion agent/app/service/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/1Panel-dev/1Panel/agent/app/repo"
"github.com/1Panel-dev/1Panel/agent/buserr"
"github.com/1Panel-dev/1Panel/agent/constant"

"github.com/1Panel-dev/1Panel/agent/app/dto"
"github.com/1Panel-dev/1Panel/agent/app/model"
Expand Down Expand Up @@ -82,7 +83,7 @@ func (m *MonitorService) LoadMonitorData(req dto.MonitorSearch) ([]dto.MonitorDa
data = append(data, itemData)
}
if req.Param == "all" || req.Param == "network" {
bases, err := monitorRepo.GetIO(repo.WithByName(req.Info), repo.WithByCreatedAt(req.StartTime, req.EndTime))
bases, err := monitorRepo.GetNetwork(repo.WithByName(req.Info), repo.WithByCreatedAt(req.StartTime, req.EndTime))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -119,6 +120,33 @@ func (m *MonitorService) LoadSetting() (*dto.MonitorSetting, error) {
}

func (m *MonitorService) UpdateSetting(key, value string) error {
switch key {
case "MonitorStatus":
if value == constant.StatusEnable && global.MonitorCronID == 0 {
interval, err := settingRepo.Get(settingRepo.WithByKey("MonitorInterval"))
if err != nil {
return err
}
if err := StartMonitor(false, interval.Value); err != nil {
return err
}
}
if value == constant.StatusDisable && global.MonitorCronID != 0 {
monitorCancel()
global.Cron.Remove(cron.EntryID(global.MonitorCronID))
global.MonitorCronID = 0
}
case "MonitorInterval":
status, err := settingRepo.Get(settingRepo.WithByKey("MonitorStatus"))
if err != nil {
return err
}
if status.Value == constant.StatusEnable && global.MonitorCronID != 0 {
if err := StartMonitor(true, value); err != nil {
return err
}
}
}
return settingRepo.Update(key, value)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good overall with no apparent issues, irregularities or optimizations to suggest. It appears to be well-defined and follows Go's idioms and conventions effectively.

However, in future maintenance and improvement projects you could consider:

  • Adding more comprehensive tests especially around the update functionality
  • Implementing proper error handling for various parts of the operations that can throw errors

In general though, I'm happy to see these changes have been made; it would've taken many hours just to go through this entire file line-by-line before implementing any sort of review or suggestions!

Expand Down
1 change: 0 additions & 1 deletion agent/app/service/snapshot_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ func loadDbConn(snap *snapHelper, targetDir string, req dto.SnapshotCreate) erro
}
}

_ = snap.snapAgentDB.Model(&model.Setting{}).Where("key = ?", "SystemIP").Updates(map[string]interface{}{"value": ""}).Error
_ = snap.snapAgentDB.Where("id = ?", snap.SnapID).Delete(&model.Snapshot{}).Error

return nil
Expand Down
2 changes: 1 addition & 1 deletion agent/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Run() {
if err := global.DB.Where("key = ?", "MonitorStatus").Find(&status).Error; err != nil {
global.LOG.Errorf("load monitor status from db failed, err: %v", err)
}
if status.Value == "enable" {
if status.Value == "Enable" {
if err := global.DB.Where("key = ?", "MonitorInterval").Find(&interval).Error; err != nil {
global.LOG.Errorf("load monitor interval from db failed, err: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions agent/init/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func InitAgentDB() {
migrations.UpdateAppTag,
migrations.UpdateApp,
migrations.AddOllamaModel,
migrations.UpdateSettingStatus,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
Expand Down
16 changes: 13 additions & 3 deletions agent/init/migration/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ var InitSetting = &gormigrate.Migration{
if err := tx.Create(&model.Setting{Key: "EncryptKey", Value: global.CONF.Base.EncryptKey}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "DockerSockPath", Value: "unix:///var/run/docker.sock"}).Error; err != nil {
return err
}
Expand Down Expand Up @@ -275,3 +272,16 @@ var AddOllamaModel = &gormigrate.Migration{
return nil
},
}

var UpdateSettingStatus = &gormigrate.Migration{
ID: "20250227-update-setting-status",
Migrate: func(tx *gorm.DB) error {
if err := tx.Model(model.Setting{}).Where("value = ?", "enable").Update("value", constant.StatusEnable).Error; err != nil {
return err
}
if err := tx.Model(model.Setting{}).Where("value = ?", "disable").Update("value", constant.StatusDisable).Error; err != nil {
return err
}
return nil
},
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed the given code snippet, which appears to be related to database migrations. The primary concerns are:

  1. Consistency: In some cases, I observed that there could be inconsistencies between the Create() call of multiple migration models based on key-value pairs.

  2. Security Concerns: There doesn't seem to include secure storage practices like using encrypted keys where appropriate and hashing them for password management if necessary.

As it is, the code seems to meet the minimum requirements but lacks robust validation checks, additional security practices, and proper testing across different environments or scenarios.

For more comprehensive checks, you might consider implementing static analysis tools and performing a thorough unit test suite.

Remember that this check-up is aimed at identifying potential errors without considering their implications fully since the scope here was limited to detecting structural issues rather than functional ones.

1 change: 1 addition & 0 deletions core/app/dto/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type SettingInfo struct {
Theme string `json:"theme"`
MenuTabs string `json:"menuTabs"`
Language string `json:"language"`
SystemIP string `json:"systemIP"`

ServerPort string `json:"serverPort"`
SSL string `json:"ssl"`
Expand Down
1 change: 1 addition & 0 deletions core/init/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func Init() {
migrations.RemoveLocalBackup,
migrations.AddMFAInterval,
migrations.UpdateXpackHideMemu,
migrations.AddSystemIP,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
Expand Down
10 changes: 10 additions & 0 deletions core/init/migration/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,13 @@ var UpdateXpackHideMemu = &gormigrate.Migration{
return nil
},
}

var AddSystemIP = &gormigrate.Migration{
ID: "20250227-add-system-ip",
Migrate: func(tx *gorm.DB) error {
if err := tx.Create(&model.Setting{Key: "SystemIP", Value: ""}).Error; err != nil {
return err
}
return nil
},
}
6 changes: 6 additions & 0 deletions frontend/src/views/ai/model/conn/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ import i18n from '@/lang';
import { ElForm } from 'element-plus';
import { getSettingInfo } from '@/api/modules/setting';
import { getBindDomain } from '@/api/modules/ai';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();

const loading = ref(false);

Expand Down Expand Up @@ -104,6 +106,10 @@ const handleClose = () => {
};

const loadSystemIP = async () => {
if (globalStore.currentNode !== 'local') {
form.systemIP = globalStore.currentNode || i18n.global.t('database.localIP');
return;
}
const res = await getSettingInfo();
form.systemIP = res.data.systemIP || i18n.global.t('database.localIP');
};
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/views/database/mysql/conn/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ import { getAppConnInfo } from '@/api/modules/app';
import { MsgSuccess } from '@/utils/message';
import { getRandomStr } from '@/utils/util';
import { getSettingInfo } from '@/api/modules/setting';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();

const loading = ref(false);

Expand Down Expand Up @@ -179,6 +181,10 @@ const loadAccess = async () => {
};

const loadSystemIP = async () => {
if (globalStore.currentNode !== 'local') {
form.systemIP = globalStore.currentNode || i18n.global.t('database.localIP');
return;
}
const res = await getSettingInfo();
form.systemIP = res.data.systemIP || i18n.global.t('database.localIP');
};
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/views/database/postgresql/conn/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ import { getAppConnInfo } from '@/api/modules/app';
import { MsgSuccess } from '@/utils/message';
import { getRandomStr } from '@/utils/util';
import { getSettingInfo } from '@/api/modules/setting';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();

const loading = ref(false);

Expand Down Expand Up @@ -179,6 +181,10 @@ const loadAccess = async () => {
};

const loadSystemIP = async () => {
if (globalStore.currentNode !== 'local') {
form.systemIP = globalStore.currentNode || i18n.global.t('database.localIP');
return;
}
const res = await getSettingInfo();
form.systemIP = res.data.systemIP || i18n.global.t('database.localIP');
};
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/views/database/redis/conn/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ import { getAppConnInfo } from '@/api/modules/app';
import { MsgSuccess } from '@/utils/message';
import { getRandomStr } from '@/utils/util';
import { getSettingInfo } from '@/api/modules/setting';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();

const loading = ref(false);

Expand Down Expand Up @@ -181,6 +183,10 @@ const loadPassword = async () => {
};

const loadSystemIP = async () => {
if (globalStore.currentNode !== 'local') {
form.systemIP = globalStore.currentNode || i18n.global.t('database.localIP');
return;
}
const res = await getSettingInfo();
form.systemIP = res.data.systemIP || i18n.global.t('database.localIP');
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/home/app/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<template #header-r>
<el-popover placement="left" :width="226" trigger="click">
<el-input size="small" v-model="filter" clearable @input="loadOption()" />
<el-table :show-header="false" :data="options" max-height="500px">
<el-table :show-header="false" :data="options" max-height="150px">
<el-table-column prop="key" width="120" show-overflow-tooltip />
<el-table-column prop="name">
<template #default="{ row }">
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/host/file-management/recycle-bin/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{ $t('file.reduce') }}
</el-button>
<el-form-item :label="$t('file.fileRecycleBin')">
<el-switch v-model="status" active-value="enable" inactive-value="disable" @change="changeStatus" />
<el-switch v-model="status" active-value="Enable" inactive-value="Disable" @change="changeStatus" />
</el-form-item>
</div>
<ComplexTable
Expand Down Expand Up @@ -78,7 +78,7 @@ const em = defineEmits(['close']);
const selects = ref([]);
const loading = ref(false);
const files = ref([]);
const status = ref('enable');
const status = ref('Enable');

const paginationConfig = reactive({
cacheSizeKey: 'recycle-page-size',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/host/firewall/status/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
size="small"
class="ml-2"
inactive-value="Disable"
active-value="enable"
active-value="Enable"
@change="onPingOperate"
v-model="onPing"
/>
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/views/host/monitor/setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<el-switch
@change="onSaveStatus"
v-model="form.monitorStatus"
active-value="enable"
inactive-value="disable"
active-value="Enable"
inactive-value="Disable"
/>
</el-form-item>
<el-form-item :label="$t('monitor.storeDays')" prop="monitorStoreDays">
Expand Down Expand Up @@ -72,7 +72,7 @@ import { MsgSuccess } from '@/utils/message';

const loading = ref();
const form = reactive({
monitorStatus: 'disable',
monitorStatus: 'Disable',
monitorStoreDays: 30,
monitorInterval: 1,
defaultNetwork: '',
Expand All @@ -88,7 +88,8 @@ const search = async () => {
form.monitorStatus = res.data.monitorStatus;
form.monitorInterval = Number(res.data.monitorInterval);
form.monitorStoreDays = Number(res.data.monitorStoreDays);
form.defaultNetwork = res.data.defaultNetwork;
form.defaultNetwork =
res.data.defaultNetwork === 'all' ? i18n.global.t('commons.table.all') : res.data.defaultNetwork;
};

const onSaveStatus = async () => {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/views/login/components/login-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<el-form-item prop="password" class="w-full">
<el-input
type="password"
show-password
v-model.trim="loginForm.password"
class="w-full"
size="large"
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/views/setting/panel/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,27 @@
</span>
</el-form-item>

<el-form-item
v-if="globalStore.currentNode === 'local'"
:label="$t('setting.systemIP')"
prop="systemIP"
>
<el-input disabled v-if="form.systemIP" v-model="form.systemIP">
<template #append>
<el-button @click="onChangeSystemIP" icon="Setting">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
<el-input disabled v-if="!form.systemIP" v-model="unset">
<template #append>
<el-button @click="onChangeSystemIP" icon="Setting">
{{ $t('commons.button.set') }}
</el-button>
</template>
</el-input>
</el-form-item>

<el-form-item :label="$t('setting.proxy')" prop="proxyShow">
<el-input disabled v-model="form.proxyShow">
<template #append>
Expand Down Expand Up @@ -174,6 +195,7 @@
<Password ref="passwordRef" />
<UserName ref="userNameRef" />
<PanelName ref="panelNameRef" @search="search()" />
<SystemIP ref="systemIPRef" @search="search()" />
<Proxy ref="proxyRef" @search="search()" />
<ApiInterface ref="apiInterfaceRef" @search="search()" />
<Timeout ref="timeoutRef" @search="search()" />
Expand All @@ -196,6 +218,7 @@ import Password from '@/views/setting/panel/password/index.vue';
import UserName from '@/views/setting/panel/username/index.vue';
import Timeout from '@/views/setting/panel/timeout/index.vue';
import PanelName from '@/views/setting/panel/name/index.vue';
import SystemIP from '@/views/setting/panel/systemip/index.vue';
import Proxy from '@/views/setting/panel/proxy/index.vue';
import HideMenu from '@/views/setting/panel/hidemenu/index.vue';
import { storeToRefs } from 'pinia';
Expand Down Expand Up @@ -233,6 +256,7 @@ const form = reactive({
language: '',
complexityVerification: '',
developerMode: '',
systemIP: '',

proxyShow: '',
proxyUrl: '',
Expand All @@ -256,6 +280,7 @@ const show = ref();
const userNameRef = ref();
const passwordRef = ref();
const panelNameRef = ref();
const systemIPRef = ref();
const proxyRef = ref();
const timeoutRef = ref();
const hideMenuRef = ref();
Expand Down Expand Up @@ -299,6 +324,7 @@ const search = async () => {
form.ipWhiteList = res.data.ipWhiteList;
form.apiKeyValidityTime = res.data.apiKeyValidityTime;
form.hideMenu = res.data.hideMenu;
form.systemIP = res.data.systemIP;

if (isMasterProductPro.value) {
const xpackRes = await getXpackSetting();
Expand Down Expand Up @@ -328,6 +354,9 @@ const onChangeTitle = () => {
const onChangeTimeout = () => {
timeoutRef.value.acceptParams({ sessionTimeout: form.sessionTimeout });
};
const onChangeSystemIP = () => {
systemIPRef.value.acceptParams({ systemIP: form.systemIP });
};
const onChangeProxy = () => {
proxyRef.value.acceptParams({
url: form.proxyUrl,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code does not appear to contain any inconsistencies, errors, or inefficiencies. It seems well-integrated with all the components it references, including a show variable which holds whether the entire setting panel is visible.

One suggestion for improving UI presentation would be ensuring consistency across inputs, such as using CSS classes like "error" for error messages to improve user experience:

.error {
  border-color: red;
}

For example:

<el-input type="text" class="error" placeholder="Enter text" v-model.trim="form.email"></el-input>

<template #append>
  <el-message icon="warning-circle" description="Error message here" />
</template>

This could also potentially be done more programmatically by defining reusable component templates that encapsulate common styling properties and applying them based on element types and states. For example:

<label><p>Please enter name</p></label>
<p-error>Not Validated!</p-error>

<input type="text">
<p>* This field is required.</p>
<p>This value should match pattern 'pattern-value'.</p>
<p style="color:red">Value exceeds maximum length of 'max-len'.</p>

Other than these stylistic improvements in front-end design, there doesn't seem to be anything inherently problematic within the provided code snippet itself. The structure appears to adhere closely to Vue.js best practices and conventions.

Expand Down
Loading
Loading