Skip to content

Commit f854ec5

Browse files
committed
feat: add very simple check to disable the button if hostname is not a domain name
1 parent 51d52e8 commit f854ec5

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/pages/EditMonitor.vue

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@
681681
</div>
682682

683683
<div v-if="monitor.type === 'http' || monitor.type === 'keyword' || monitor.type === 'json-query' " class="my-3 form-check">
684-
<input id="domain-expiry-notification" v-model="monitor.domainExpiryNotification" class="form-check-input" type="checkbox">
684+
<input id="domain-expiry-notification" v-model="monitor.domainExpiryNotification" class="form-check-input" type="checkbox" :disabled="!urlIsDomain">
685685
<label class="form-check-label" for="domain-expiry-notification">
686686
{{ $t("Domain Name Expiry Notification") }}
687687
</label>
@@ -1206,6 +1206,7 @@ const monitorDefaults = {
12061206
ignoreTls: false,
12071207
upsideDown: false,
12081208
expiryNotification: false,
1209+
domainExpiryNotification: true,
12091210
maxredirects: 10,
12101211
accepted_statuscodes: [ "200-299" ],
12111212
dns_resolve_type: "A",
@@ -1558,6 +1559,20 @@ message HealthCheckResponse {
15581559
conditionVariables() {
15591560
return this.$root.monitorTypeList[this.monitor.type]?.conditionVariables || [];
15601561
},
1562+
1563+
urlIsDomain() {
1564+
if (!this.monitor.url) {
1565+
return false;
1566+
}
1567+
try {
1568+
const url = new URL(this.monitor.url);
1569+
const tld = url.hostname.split(".").pop();
1570+
// Very simple check : if the tld contains a letter, it is a domain, if not, it is an IP
1571+
return /[a-zA-Z]/.test(tld);
1572+
} catch {
1573+
return false;
1574+
}
1575+
}
15611576
},
15621577
watch: {
15631578
"$root.proxyList"() {
@@ -1939,6 +1954,10 @@ message HealthCheckResponse {
19391954
this.monitor.url = this.monitor.url.trim();
19401955
}
19411956
1957+
if (this.monitor.domainExpiryNotification) {
1958+
this.monitor.domainExpiryNotification = this.urlIsDomain;
1959+
}
1960+
19421961
let createdNewParent = false;
19431962
19441963
if (this.draftGroupName && this.monitor.parent === -1) {

0 commit comments

Comments
 (0)