Add authentication support for ntfy

pull/1923/head
Rolf Bachmann 2 years ago
parent 9a8b484ee8
commit c4a2ce4e78

@ -8,12 +8,19 @@ class Ntfy extends NotificationProvider {
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully."; let okMsg = "Sent Successfully.";
try { try {
await axios.post(`${notification.ntfyserverurl}`, { let headers = {};
if (notification.ntfyusername.length > 0) {
headers = {
"Authorization": "Basic " + Buffer.from(notification.ntfyusername + ":" + notification.ntfypassword).toString("base64"),
};
}
let data = {
"topic": notification.ntfytopic, "topic": notification.ntfytopic,
"message": msg, "message": msg,
"priority": notification.ntfyPriority || 4, "priority": notification.ntfyPriority || 4,
"title": "Uptime-Kuma", "title": "Uptime-Kuma",
}); };
await axios.post(`${notification.ntfyserverurl}`, data, { headers: headers });
return okMsg; return okMsg;

@ -11,7 +11,18 @@
<input id="ntfy-server-url" v-model="$parent.notification.ntfyserverurl" type="text" class="form-control" required> <input id="ntfy-server-url" v-model="$parent.notification.ntfyserverurl" type="text" class="form-control" required>
</div> </div>
</div> </div>
<div class="mb-3">
<label for="ntfy-username" class="form-label">{{ $t("Username") }}</label>
<div class="input-group mb-3">
<input id="ntfy-username" v-model="$parent.notification.ntfyusername" type="text" class="form-control" required>
</div>
</div>
<div class="mb-3">
<label for="ntfy-password" class="form-label">{{ $t("Password") }}</label>
<div class="input-group mb-3">
<HiddenInput id="ntfy-password" v-model="$parent.notification.ntfypassword"></HiddenInput>
</div>
</div>
<div class="mb-3"> <div class="mb-3">
<label for="ntfy-priority" class="form-label">{{ $t("Priority") }}</label> <label for="ntfy-priority" class="form-label">{{ $t("Priority") }}</label>
<input id="ntfy-priority" v-model="$parent.notification.ntfyPriority" type="number" class="form-control" required min="1" max="5" step="1"> <input id="ntfy-priority" v-model="$parent.notification.ntfyPriority" type="number" class="form-control" required min="1" max="5" step="1">
@ -19,7 +30,12 @@
</template> </template>
<script> <script>
import HiddenInput from "../HiddenInput.vue";
export default { export default {
components: {
HiddenInput,
},
mounted() { mounted() {
if (typeof this.$parent.notification.ntfyPriority === "undefined") { if (typeof this.$parent.notification.ntfyPriority === "undefined") {
this.$parent.notification.ntfyserverurl = "https://ntfy.sh"; this.$parent.notification.ntfyserverurl = "https://ntfy.sh";

Loading…
Cancel
Save