Skip to content

Commit

Permalink
feat: host domain login & refactor: calc utils
Browse files Browse the repository at this point in the history
  • Loading branch information
zyyzyykk committed Jan 31, 2025
1 parent 509f12c commit 282ff5d
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 15 deletions.
7 changes: 4 additions & 3 deletions front/terminal/src/components/ConnectSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ import ToolTip from './ToolTip.vue';
import { getPureUrl } from '@/utils/UrlUtil';
import { HomeFilled, Paperclip, User, Lock, DocumentCopy, View, Hide, Edit, Finished, Switch, ArrowDown, Key } from '@element-plus/icons-vue';
import i18n from "@/locales/i18n";
import { isIP, isFQDN } from '@/utils/IPUtil';
export default {
name:'ConnectSetting',
Expand Down Expand Up @@ -156,9 +157,8 @@ export default {
// 校验参数
const verifyParams = () => {
err_msg.value = '';
// 验证IP地址
const ipRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
if (!ipRegex.test(setInfo.value.server_ip)) {
// 验证IP地址/域名
if (!(isIP(setInfo.value.server_ip) || isFQDN(setInfo.value.server_ip))) {
err_msg.value = i18n.global.t("主机IP地址无效");
return false;
}
Expand Down Expand Up @@ -208,6 +208,7 @@ export default {
if(!props.sshOptions[option].authType) setInfo.value.authType = 0;
setInfo.value = {...setInfo.value, ...props.sshOptions[option]};
isForbidInput.value = true;
err_msg.value = '';
}
// 保存
else if(optionBlockType.value == 1)
Expand Down
12 changes: 6 additions & 6 deletions front/terminal/src/components/FileAttr.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
<div class="kk-flex">
<div class="form-width" >{{ $t('修改时间') }}:</div>
<div>
{{ formatDate(fileInfo.attributes.mtime) }}
{{ calcDate(fileInfo.attributes.mtime) }}
</div>
</div>
<div class="kk-flex">
<div class="form-width" >{{ $t('访问时间') }}:</div>
<div>
{{ formatDate(fileInfo.attributes.atime) }}
{{ calcDate(fileInfo.attributes.atime) }}
</div>
</div>
<div class="kk-border" ></div>
Expand Down Expand Up @@ -102,12 +102,12 @@
import { ref } from 'vue';
import $ from 'jquery';
import { http_base_url } from '@/env/BaseUrl';
import { formatDate } from '@/utils/FormatDate';
import { calcPriority } from '@/utils/CalcPriority';
import { calcDate } from '@/components/calc/CalcDate';
import { calcPriority } from '@/components/calc/CalcPriority';
import { ElMessage } from 'element-plus';
import useClipboard from "vue-clipboard3";
import { DocumentCopy, Refresh, Edit } from '@element-plus/icons-vue';
import { calcSize } from '@/utils/CalcSize';
import { calcSize } from '@/components/calc/CalcSize';
import { escapeItem, escapePath } from '@/utils/StringUtil';
import ToolTip from './ToolTip.vue';
import PermissionsEdit from './PermissionsEdit.vue';
Expand Down Expand Up @@ -295,7 +295,7 @@ export default {
reset,
fileDir,
rename,
formatDate,
calcDate,
calcPriority,
calcSize,
doCopy,
Expand Down
4 changes: 2 additions & 2 deletions front/terminal/src/components/FileBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ import { ElMessage } from 'element-plus';
import { http_base_url } from '@/env/BaseUrl';
import { Refresh, Fold, Download, Upload, DocumentAdd, FolderAdd, Link } from '@element-plus/icons-vue';
import { escapeItem, escapePath } from '@/utils/StringUtil';
import { isZipFile } from '@/utils/FileSuffix';
import { getChmodValue } from '@/utils/CalcPriority';
import { isZipFile } from '@/components/preview/FileSuffix';
import { getChmodValue } from '@/components/calc/CalcPriority';
import { getUrlParams } from "@/utils/UrlUtil";
import ToolTip from './ToolTip.vue';
Expand Down
2 changes: 1 addition & 1 deletion front/terminal/src/components/PermissionsEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

<script>
import { ref } from 'vue';
import { getPermissionInfo } from '@/utils/CalcPriority';
import { getPermissionInfo } from '@/components/calc/CalcPriority';
// 引入文件图标组件
import FileIcons from 'file-icons-vue';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import i18n from "@/locales/i18n";

// 将时间戳转为 2024年1月22日,20:40:38 格式
export const formatDate = (time) => {
export const calcDate = (time) => {
if(!time) return "";
let date = new Date(time*1000);
let year = date.getFullYear();
Expand All @@ -22,4 +22,4 @@ export const formatDate = (time) => {
else dateArr = [month, day, year];

return dateArr[0] + i18n.global.t("年") + dateArr[1] + i18n.global.t("月") + dateArr[2] + i18n.global.t("日,") + hour + ":" + min + ":" + seconds;
};
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion front/terminal/src/components/preview/TxtPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import AceEditor from './AceEditor';
import $ from 'jquery';
import useClipboard from "vue-clipboard3";
import { ElMessage } from 'element-plus';
import { previewFileInfo } from '@/utils/FileSuffix';
import { previewFileInfo } from '@/components/preview/FileSuffix';
import { changeStr2 } from '@/utils/StringUtil';
import { getUrlParams } from "@/utils/UrlUtil";
import { detectEncoding, encodeStrToArray, decodeArrayToStr } from "@/components/preview/EncodeUtil";
Expand Down
103 changes: 103 additions & 0 deletions front/terminal/src/utils/IPUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 校验IP地址是否合法
const IPv4SegmentFormat = '(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])';
const IPv4AddressFormat = `(${IPv4SegmentFormat}[.]){3}${IPv4SegmentFormat}`;
const IPv4AddressRegExp = new RegExp(`^${IPv4AddressFormat}$`);

const IPv6SegmentFormat = '(?:[0-9a-fA-F]{1,4})';
const IPv6AddressRegExp = new RegExp('^(' +
`(?:${IPv6SegmentFormat}:){7}(?:${IPv6SegmentFormat}|:)|` +
`(?:${IPv6SegmentFormat}:){6}(?:${IPv4AddressFormat}|:${IPv6SegmentFormat}|:)|` +
`(?:${IPv6SegmentFormat}:){5}(?::${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,2}|:)|` +
`(?:${IPv6SegmentFormat}:){4}(?:(:${IPv6SegmentFormat}){0,1}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,3}|:)|` +
`(?:${IPv6SegmentFormat}:){3}(?:(:${IPv6SegmentFormat}){0,2}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,4}|:)|` +
`(?:${IPv6SegmentFormat}:){2}(?:(:${IPv6SegmentFormat}){0,3}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,5}|:)|` +
`(?:${IPv6SegmentFormat}:){1}(?:(:${IPv6SegmentFormat}){0,4}:${IPv4AddressFormat}|(:${IPv6SegmentFormat}){1,6}|:)|` +
`(?::((?::${IPv6SegmentFormat}){0,5}:${IPv4AddressFormat}|(?::${IPv6SegmentFormat}){1,7}|:))` +
')(%[0-9a-zA-Z-.:]{1,})?$');

export function isIP(str, version = '4') {
version = String(version);
if (!version) {
return isIP(str, 4) || isIP(str, 6);
}
if (version === '4') {
return IPv4AddressRegExp.test(str);
}
if (version === '6') {
return IPv6AddressRegExp.test(str);
}
return false;
}

// 校验域名是否合法
const options = {
require_tld: true,
allow_underscores: false,
allow_trailing_dot: false,
allow_numeric_tld: false,
allow_wildcard: false,
ignore_max_length: false,
};

export function isFQDN(str) {

/* Remove the optional trailing dot before checking validity */
if (options.allow_trailing_dot && str[str.length - 1] === '.') {
str = str.substring(0, str.length - 1);
}

/* Remove the optional wildcard before checking validity */
if (options.allow_wildcard === true && str.indexOf('*.') === 0) {
str = str.substring(2);
}

const parts = str.split('.');
const tld = parts[parts.length - 1];

if (options.require_tld) {
// disallow fqdns without tld
if (parts.length < 2) {
return false;
}

if (!options.allow_numeric_tld && !/^([a-z\u00A1-\u00A8\u00AA-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}|xn[a-z0-9-]{2,})$/i.test(tld)) {
return false;
}

// disallow spaces
if (/\s/.test(tld)) {
return false;
}
}

// reject numeric TLDs
if (!options.allow_numeric_tld && /^\d+$/.test(tld)) {
return false;
}

return parts.every((part) => {
if (part.length > 63 && !options.ignore_max_length) {
return false;
}

if (!/^[a-z_\u00a1-\uffff0-9-]+$/i.test(part)) {
return false;
}

// disallow full-width chars
if (/[\uff01-\uff5e]/.test(part)) {
return false;
}

// disallow parts starting or ending with hyphen
if (/^-|-$/.test(part)) {
return false;
}

if (!options.allow_underscores && /_/.test(part)) {
return false;
}

return true;
});
}

0 comments on commit 282ff5d

Please sign in to comment.