mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 12:00:35 +03:00
add setting for disable auth
This commit is contained in:
parent
9f0be5f531
commit
c6a66fad79
3 changed files with 130 additions and 24 deletions
|
@ -1,25 +1,45 @@
|
||||||
console.log("Welcome to Uptime Kuma ")
|
console.log("Welcome to Uptime Kuma")
|
||||||
console.log("Importing libraries")
|
|
||||||
const express = require("express");
|
const { sleep, debug } = require("../src/util");
|
||||||
const http = require("http");
|
|
||||||
const { Server } = require("socket.io");
|
console.log("Importing Node libraries")
|
||||||
const dayjs = require("dayjs");
|
|
||||||
const { R } = require("redbean-node");
|
|
||||||
const jwt = require("jsonwebtoken");
|
|
||||||
const Monitor = require("./model/monitor");
|
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const { getSettings } = require("./util-server");
|
const http = require("http");
|
||||||
const { Notification } = require("./notification")
|
|
||||||
|
console.log("Importing 3rd-party libraries")
|
||||||
|
debug("Importing express");
|
||||||
|
const express = require("express");
|
||||||
|
debug("Importing socket.io");
|
||||||
|
const { Server } = require("socket.io");
|
||||||
|
debug("Importing dayjs");
|
||||||
|
const dayjs = require("dayjs");
|
||||||
|
debug("Importing redbean-node");
|
||||||
|
const { R } = require("redbean-node");
|
||||||
|
debug("Importing jsonwebtoken");
|
||||||
|
const jwt = require("jsonwebtoken");
|
||||||
|
debug("Importing http-graceful-shutdown");
|
||||||
const gracefulShutdown = require("http-graceful-shutdown");
|
const gracefulShutdown = require("http-graceful-shutdown");
|
||||||
const Database = require("./database");
|
debug("Importing prometheus-api-metrics");
|
||||||
const { sleep } = require("../src/util");
|
|
||||||
const args = require("args-parser")(process.argv);
|
|
||||||
const prometheusAPIMetrics = require("prometheus-api-metrics");
|
const prometheusAPIMetrics = require("prometheus-api-metrics");
|
||||||
|
|
||||||
|
console.log("Importing this project modules");
|
||||||
|
debug("Importing Monitor");
|
||||||
|
const Monitor = require("./model/monitor");
|
||||||
|
debug("Importing Settings");
|
||||||
|
const { getSettings, setSettings } = require("./util-server");
|
||||||
|
debug("Importing Notification");
|
||||||
|
const { Notification } = require("./notification");
|
||||||
|
debug("Importing Database");
|
||||||
|
const Database = require("./database");
|
||||||
|
|
||||||
const { basicAuth } = require("./auth");
|
const { basicAuth } = require("./auth");
|
||||||
const { login } = require("./auth");
|
const { login } = require("./auth");
|
||||||
const passwordHash = require("./password-hash");
|
const passwordHash = require("./password-hash");
|
||||||
|
|
||||||
|
const args = require("args-parser")(process.argv);
|
||||||
|
|
||||||
const version = require("../package.json").version;
|
const version = require("../package.json").version;
|
||||||
const hostname = args.host || "0.0.0.0"
|
const hostname = process.env.HOST || args.host || "0.0.0.0"
|
||||||
const port = parseInt(process.env.PORT || args.port || 3001);
|
const port = parseInt(process.env.PORT || args.port || 3001);
|
||||||
|
|
||||||
console.info("Version: " + version)
|
console.info("Version: " + version)
|
||||||
|
@ -405,13 +425,32 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("getSettings", async (type, callback) => {
|
socket.on("getSettings", async (callback) => {
|
||||||
try {
|
try {
|
||||||
checkLogin(socket)
|
checkLogin(socket)
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
ok: true,
|
ok: true,
|
||||||
data: await getSettings(type),
|
data: await getSettings("general"),
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
callback({
|
||||||
|
ok: false,
|
||||||
|
msg: e.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on("setSettings", async (data, callback) => {
|
||||||
|
try {
|
||||||
|
checkLogin(socket)
|
||||||
|
|
||||||
|
await setSettings("general", data)
|
||||||
|
|
||||||
|
callback({
|
||||||
|
ok: true,
|
||||||
|
msg: "Saved"
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -58,19 +58,44 @@ exports.setSetting = async function (key, value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.getSettings = async function (type) {
|
exports.getSettings = async function (type) {
|
||||||
let list = await R.getAll("SELECT * FROM setting WHERE `type` = ? ", [
|
let list = await R.getAll("SELECT `key`, `value` FROM setting WHERE `type` = ? ", [
|
||||||
type,
|
type,
|
||||||
])
|
])
|
||||||
|
|
||||||
let result = {};
|
let result = {};
|
||||||
|
|
||||||
for (let row of list) {
|
for (let row of list) {
|
||||||
result[row.key] = row.value;
|
result[row.key] = JSON.parse(row.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.setSettings = async function (type, data) {
|
||||||
|
let keyList = Object.keys(data);
|
||||||
|
|
||||||
|
let promiseList = [];
|
||||||
|
|
||||||
|
for (let key of keyList) {
|
||||||
|
let bean = await R.findOne("setting", " `key` = ? ", [
|
||||||
|
key
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (bean == null) {
|
||||||
|
bean = R.dispense("setting");
|
||||||
|
bean.type = type;
|
||||||
|
bean.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bean.type === type) {
|
||||||
|
bean.value = JSON.stringify(data[key]);
|
||||||
|
promiseList.push(R.store(bean))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all(promiseList);
|
||||||
|
}
|
||||||
|
|
||||||
// ssl-checker by @dyaa
|
// ssl-checker by @dyaa
|
||||||
// param: res - response object from axios
|
// param: res - response object from axios
|
||||||
// return an object containing the certificate information
|
// return an object containing the certificate information
|
||||||
|
|
|
@ -54,10 +54,12 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div>
|
<h2>Advanced</h2>
|
||||||
<button class="btn btn-danger" @click="$root.logout">
|
|
||||||
Logout
|
<div class="mb-3">
|
||||||
</button>
|
<button v-if="settings.disableAuth" class="btn btn-outline-primary me-1" @click="enableAuth">Enable Auth</button>
|
||||||
|
<button v-if="! settings.disableAuth" class="btn btn-primary me-1" @click="confirmDisableAuth">Disable Auth</button>
|
||||||
|
<button class="btn btn-danger me-1" @click="$root.logout">Logout</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -87,15 +89,23 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<NotificationDialog ref="notificationDialog" />
|
<NotificationDialog ref="notificationDialog" />
|
||||||
|
|
||||||
|
<Confirm ref="confirmDisableAuth" btn-style="btn-danger" yes-text="I understand, please disable" no-text="Leave" @yes="disableAuth">
|
||||||
|
<p>Are you sure want to <strong>disable auth</strong>?</p>
|
||||||
|
<p>It is for <strong>someone who have 3rd-party auth</strong> in front of Uptime Kuma such as Cloudflare Access.</p>
|
||||||
|
<p>Please use it carefully.</p>
|
||||||
|
</Confirm>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import Confirm from "../components/Confirm.vue";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import utc from "dayjs/plugin/utc"
|
import utc from "dayjs/plugin/utc"
|
||||||
import timezone from "dayjs/plugin/timezone"
|
import timezone from "dayjs/plugin/timezone"
|
||||||
import NotificationDialog from "../components/NotificationDialog.vue";
|
import NotificationDialog from "../components/NotificationDialog.vue";
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
|
|
||||||
import { timezoneList } from "../util-frontend";
|
import { timezoneList } from "../util-frontend";
|
||||||
import { useToast } from "vue-toastification"
|
import { useToast } from "vue-toastification"
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
|
@ -103,6 +113,7 @@ const toast = useToast()
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
NotificationDialog,
|
NotificationDialog,
|
||||||
|
Confirm,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -115,6 +126,9 @@ export default {
|
||||||
newPassword: "",
|
newPassword: "",
|
||||||
repeatNewPassword: "",
|
repeatNewPassword: "",
|
||||||
},
|
},
|
||||||
|
settings: {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -124,7 +138,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
|
this.loadSettings();
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -148,6 +162,34 @@ export default {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
loadSettings() {
|
||||||
|
this.$root.getSocket().emit("getSettings", (res) => {
|
||||||
|
this.settings = res.data;
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
saveSettings() {
|
||||||
|
this.$root.getSocket().emit("setSettings", this.settings, (res) => {
|
||||||
|
this.$root.toastRes(res);
|
||||||
|
this.loadSettings();
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
confirmDisableAuth() {
|
||||||
|
this.$refs.confirmDisableAuth.show();
|
||||||
|
},
|
||||||
|
|
||||||
|
disableAuth() {
|
||||||
|
this.settings.disableAuth = true;
|
||||||
|
this.saveSettings();
|
||||||
|
},
|
||||||
|
|
||||||
|
enableAuth() {
|
||||||
|
this.settings.disableAuth = false;
|
||||||
|
this.saveSettings();
|
||||||
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue