mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-23 03:55:56 +00:00
Detect URLs in monitor descriptions
This commit is contained in:
parent
7dc6191b0a
commit
0796c4353d
1 changed files with 28 additions and 1 deletions
|
@ -9,7 +9,7 @@
|
||||||
<div>{{ monitor.id }}</div>
|
<div>{{ monitor.id }}</div>
|
||||||
</div>
|
</div>
|
||||||
</h1>
|
</h1>
|
||||||
<p v-if="monitor.description">{{ monitor.description }}</p>
|
<p v-if="monitor.description" v-html="processedDescription"></p>
|
||||||
<div class="d-flex">
|
<div class="d-flex">
|
||||||
<div class="tags">
|
<div class="tags">
|
||||||
<Tag v-for="tag in monitor.tags" :key="tag.id" :item="tag" :size="'sm'" />
|
<Tag v-for="tag in monitor.tags" :key="tag.id" :item="tag" :size="'sm'" />
|
||||||
|
@ -399,6 +399,19 @@ export default {
|
||||||
|
|
||||||
screenshotURL() {
|
screenshotURL() {
|
||||||
return getResBaseURL() + this.monitor.screenshot + "?time=" + this.cacheTime;
|
return getResBaseURL() + this.monitor.screenshot + "?time=" + this.cacheTime;
|
||||||
|
},
|
||||||
|
|
||||||
|
processedDescription() {
|
||||||
|
if (!this.monitor.description) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const urlPattern = /(\b(?:https?|ftp|file|smb|ssh|telnet|ldap|git):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi;
|
||||||
|
const processed = this.monitor.description.replace(
|
||||||
|
urlPattern,
|
||||||
|
url => `<a href="${this.escapeHtml(url)}" target="_blank" rel="noopener noreferrer">${this.escapeHtml(url)}</a>`
|
||||||
|
);
|
||||||
|
return processed;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -656,6 +669,20 @@ export default {
|
||||||
.replace("https://example.com/api/push/key?status=up&msg=OK&ping=", this.pushURL);
|
.replace("https://example.com/api/push/key?status=up&msg=OK&ping=", this.pushURL);
|
||||||
this.pushMonitor.code = code;
|
this.pushMonitor.code = code;
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape HTML
|
||||||
|
* @param {string} unsafe Unsafe string
|
||||||
|
* @returns {string} Safe string
|
||||||
|
*/
|
||||||
|
escapeHtml(unsafe) {
|
||||||
|
return unsafe
|
||||||
|
.replace(/&/g, "&")
|
||||||
|
.replace(/</g, "<")
|
||||||
|
.replace(/>/g, ">")
|
||||||
|
.replace(/"/g, """)
|
||||||
|
.replace(/'/g, "'");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue