2022-08-18 18:54:21 +08:00
|
|
|
import http from '@/api';
|
2023-02-13 17:13:55 +08:00
|
|
|
import { ResPage } from '../interface';
|
|
|
|
import { Command } from '../interface/command';
|
2022-08-18 18:54:21 +08:00
|
|
|
import { Host } from '../interface/host';
|
2023-03-15 15:58:26 +08:00
|
|
|
import { Base64 } from 'js-base64';
|
|
|
|
import { deepCopy } from '@/utils/util';
|
2023-09-12 22:40:12 +08:00
|
|
|
import { TimeoutEnum } from '@/enums/http-enum';
|
2022-08-18 18:54:21 +08:00
|
|
|
|
2023-03-01 17:43:28 +08:00
|
|
|
export const searchHosts = (params: Host.SearchWithPage) => {
|
|
|
|
return http.post<ResPage<Host.Host>>(`/hosts/search`, params);
|
|
|
|
};
|
2022-09-01 16:52:58 +08:00
|
|
|
export const getHostTree = (params: Host.ReqSearch) => {
|
2023-03-01 17:43:28 +08:00
|
|
|
return http.post<Array<Host.HostTree>>(`/hosts/tree`, params);
|
2022-08-18 18:54:21 +08:00
|
|
|
};
|
|
|
|
export const addHost = (params: Host.HostOperate) => {
|
2023-03-15 15:58:26 +08:00
|
|
|
let reqest = deepCopy(params) as Host.HostOperate;
|
|
|
|
if (reqest.password) {
|
|
|
|
reqest.password = Base64.encode(reqest.password);
|
|
|
|
}
|
|
|
|
if (reqest.privateKey) {
|
|
|
|
reqest.privateKey = Base64.encode(reqest.privateKey);
|
|
|
|
}
|
|
|
|
return http.post<Host.HostOperate>(`/hosts`, reqest);
|
2022-08-18 18:54:21 +08:00
|
|
|
};
|
2023-01-03 14:37:17 +08:00
|
|
|
export const testByInfo = (params: Host.HostConnTest) => {
|
2023-03-15 15:58:26 +08:00
|
|
|
let reqest = deepCopy(params) as Host.HostOperate;
|
|
|
|
if (reqest.password) {
|
|
|
|
reqest.password = Base64.encode(reqest.password);
|
|
|
|
}
|
|
|
|
if (reqest.privateKey) {
|
|
|
|
reqest.privateKey = Base64.encode(reqest.privateKey);
|
|
|
|
}
|
|
|
|
return http.post<boolean>(`/hosts/test/byinfo`, reqest);
|
2023-01-03 14:37:17 +08:00
|
|
|
};
|
|
|
|
export const testByID = (id: number) => {
|
|
|
|
return http.post<boolean>(`/hosts/test/byid/${id}`);
|
2022-09-01 10:25:38 +08:00
|
|
|
};
|
2022-08-18 18:54:21 +08:00
|
|
|
export const editHost = (params: Host.HostOperate) => {
|
2023-03-15 15:58:26 +08:00
|
|
|
let reqest = deepCopy(params) as Host.HostOperate;
|
|
|
|
if (reqest.password) {
|
|
|
|
reqest.password = Base64.encode(reqest.password);
|
|
|
|
}
|
|
|
|
if (reqest.privateKey) {
|
|
|
|
reqest.privateKey = Base64.encode(reqest.privateKey);
|
|
|
|
}
|
|
|
|
return http.post(`/hosts/update`, reqest);
|
2022-08-18 18:54:21 +08:00
|
|
|
};
|
2023-03-01 17:43:28 +08:00
|
|
|
export const editHostGroup = (params: Host.GroupChange) => {
|
|
|
|
return http.post(`/hosts/update/group`, params);
|
|
|
|
};
|
|
|
|
export const deleteHost = (params: { ids: number[] }) => {
|
|
|
|
return http.post(`/hosts/del`, params);
|
2022-08-18 18:54:21 +08:00
|
|
|
};
|
2023-02-13 17:13:55 +08:00
|
|
|
|
|
|
|
// command
|
|
|
|
export const getCommandList = () => {
|
|
|
|
return http.get<Array<Command.CommandInfo>>(`/hosts/command`, {});
|
|
|
|
};
|
|
|
|
export const getCommandPage = (params: Command.CommandSearch) => {
|
|
|
|
return http.post<ResPage<Command.CommandInfo>>(`/hosts/command/search`, params);
|
|
|
|
};
|
|
|
|
export const addCommand = (params: Command.CommandOperate) => {
|
|
|
|
return http.post<Command.CommandOperate>(`/hosts/command`, params);
|
|
|
|
};
|
|
|
|
export const editCommand = (params: Command.CommandOperate) => {
|
|
|
|
return http.post(`/hosts/command/update`, params);
|
|
|
|
};
|
|
|
|
export const deleteCommand = (params: { ids: number[] }) => {
|
|
|
|
return http.post(`/hosts/command/del`, params);
|
|
|
|
};
|
2023-03-27 19:02:36 +08:00
|
|
|
|
|
|
|
// firewall
|
2023-03-30 16:07:28 +08:00
|
|
|
export const loadFireBaseInfo = () => {
|
|
|
|
return http.get<Host.FirewallBase>(`/hosts/firewall/base`);
|
|
|
|
};
|
2023-03-27 19:02:36 +08:00
|
|
|
export const searchFireRule = (params: Host.RuleSearch) => {
|
2023-09-12 22:40:12 +08:00
|
|
|
return http.post<ResPage<Host.RuleInfo>>(`/hosts/firewall/search`, params, TimeoutEnum.T_40S);
|
2023-03-27 19:02:36 +08:00
|
|
|
};
|
2023-03-30 16:07:28 +08:00
|
|
|
export const operateFire = (operation: string) => {
|
2023-09-12 22:40:12 +08:00
|
|
|
return http.post(`/hosts/firewall/operate`, { operation: operation }, TimeoutEnum.T_40S);
|
2023-03-30 16:07:28 +08:00
|
|
|
};
|
2023-03-27 19:02:36 +08:00
|
|
|
export const operatePortRule = (params: Host.RulePort) => {
|
2023-09-12 22:40:12 +08:00
|
|
|
return http.post<Host.RulePort>(`/hosts/firewall/port`, params, TimeoutEnum.T_40S);
|
2023-03-27 19:02:36 +08:00
|
|
|
};
|
|
|
|
export const operateIPRule = (params: Host.RuleIP) => {
|
2023-09-12 22:40:12 +08:00
|
|
|
return http.post<Host.RuleIP>(`/hosts/firewall/ip`, params, TimeoutEnum.T_40S);
|
2023-03-27 19:02:36 +08:00
|
|
|
};
|
2023-03-28 15:17:13 +08:00
|
|
|
export const updatePortRule = (params: Host.UpdatePortRule) => {
|
2023-09-12 22:40:12 +08:00
|
|
|
return http.post(`/hosts/firewall/update/port`, params, TimeoutEnum.T_40S);
|
2023-03-28 15:17:13 +08:00
|
|
|
};
|
|
|
|
export const updateAddrRule = (params: Host.UpdateAddrRule) => {
|
2023-09-12 22:40:12 +08:00
|
|
|
return http.post(`/hosts/firewall/update/addr`, params, TimeoutEnum.T_40S);
|
2023-03-28 15:17:13 +08:00
|
|
|
};
|
2023-08-15 22:48:11 +08:00
|
|
|
export const updateFirewallDescription = (params: Host.UpdateDescription) => {
|
|
|
|
return http.post(`/hosts/firewall/update/description`, params);
|
|
|
|
};
|
2023-03-28 15:17:13 +08:00
|
|
|
export const batchOperateRule = (params: Host.BatchRule) => {
|
2023-09-12 22:40:12 +08:00
|
|
|
return http.post(`/hosts/firewall/batch`, params, TimeoutEnum.T_60S);
|
2023-03-28 15:17:13 +08:00
|
|
|
};
|
2023-05-11 18:09:42 +08:00
|
|
|
|
|
|
|
// ssh
|
|
|
|
export const getSSHInfo = () => {
|
|
|
|
return http.post<Host.SSHInfo>(`/hosts/ssh/search`);
|
|
|
|
};
|
2023-08-02 16:47:30 +08:00
|
|
|
export const getSSHConf = () => {
|
|
|
|
return http.get<string>(`/hosts/ssh/conf`);
|
|
|
|
};
|
2023-05-17 18:45:48 +08:00
|
|
|
export const operateSSH = (operation: string) => {
|
|
|
|
return http.post(`/hosts/ssh/operate`, { operation: operation });
|
|
|
|
};
|
2023-05-11 18:09:42 +08:00
|
|
|
export const updateSSH = (key: string, value: string) => {
|
|
|
|
return http.post(`/hosts/ssh/update`, { key: key, value: value });
|
|
|
|
};
|
2023-05-17 14:45:48 +08:00
|
|
|
export const updateSSHByfile = (file: string) => {
|
|
|
|
return http.post(`/hosts/ssh/conffile/update`, { file: file });
|
|
|
|
};
|
2023-05-15 19:00:40 +08:00
|
|
|
export const generateSecret = (params: Host.SSHGenerate) => {
|
|
|
|
return http.post(`/hosts/ssh/generate`, params);
|
|
|
|
};
|
|
|
|
export const loadSecret = (mode: string) => {
|
|
|
|
return http.post<string>(`/hosts/ssh/secret`, { encryptionMode: mode });
|
2023-05-11 18:09:42 +08:00
|
|
|
};
|
2023-05-16 18:49:27 +08:00
|
|
|
export const loadSSHLogs = (params: Host.searchSSHLog) => {
|
|
|
|
return http.post<Host.sshLog>(`/hosts/ssh/log`, params);
|
|
|
|
};
|
2023-10-11 17:20:30 +08:00
|
|
|
export const loadAnalysis = (params: Host.analysisSSHLog) => {
|
|
|
|
return http.post<Host.logAnalysisRes>(`/hosts/ssh/log/analysis`, params, TimeoutEnum.T_40S);
|
2023-09-20 14:18:20 +08:00
|
|
|
};
|