mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-24 07:14:04 +00:00
Compare commits
19 commits
77b4bba3ce
...
66676f7e75
Author | SHA1 | Date | |
---|---|---|---|
|
66676f7e75 | ||
|
46d8744fa4 | ||
|
7d8dc55dbe | ||
|
aff6a5bf7f | ||
|
821a70f2f3 | ||
|
144794b770 | ||
|
60271ffa0b | ||
|
bb7c098aec | ||
|
f6e7da67fd | ||
|
47fed3eb99 | ||
|
722ac84f99 | ||
|
af45fa844e | ||
|
8fa40d02aa | ||
|
4cb9406a2e | ||
|
a50209b6c8 | ||
|
1ceb8e98d6 | ||
|
be461a0efd | ||
|
deaec80cb0 | ||
|
6412514cae |
10 changed files with 178 additions and 9 deletions
15
db/knex_migrations/2023-09-13-1047-locale-on-statuspage.js
Normal file
15
db/knex_migrations/2023-09-13-1047-locale-on-statuspage.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
exports.up = function (knex) {
|
||||||
|
return knex.schema
|
||||||
|
.alterTable("status_page", function (table) {
|
||||||
|
table.boolean("show_locale_selector").notNullable().defaultTo(false);
|
||||||
|
table.string("default_locale").nullable().defaultTo("");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.down = function (knex) {
|
||||||
|
return knex.schema
|
||||||
|
.alterTable("status_page", function (table) {
|
||||||
|
table.dropColumn("default_locale");
|
||||||
|
table.dropColumn("show_locale_selector");
|
||||||
|
});
|
||||||
|
};
|
|
@ -27,7 +27,6 @@ RUN mkdir ./data
|
||||||
# ⭐ Main Image
|
# ⭐ Main Image
|
||||||
############################################
|
############################################
|
||||||
FROM $BASE_IMAGE AS release
|
FROM $BASE_IMAGE AS release
|
||||||
USER node
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
LABEL org.opencontainers.image.source="https://github.com/louislam/uptime-kuma"
|
LABEL org.opencontainers.image.source="https://github.com/louislam/uptime-kuma"
|
||||||
|
@ -46,6 +45,7 @@ CMD ["node", "server/server.js"]
|
||||||
# Rootless Image
|
# Rootless Image
|
||||||
############################################
|
############################################
|
||||||
FROM release AS rootless
|
FROM release AS rootless
|
||||||
|
USER node
|
||||||
|
|
||||||
############################################
|
############################################
|
||||||
# Mark as Nightly
|
# Mark as Nightly
|
||||||
|
|
|
@ -9,6 +9,7 @@ const mysql = require("mysql2/promise");
|
||||||
const { Settings } = require("./settings");
|
const { Settings } = require("./settings");
|
||||||
const { UptimeCalculator } = require("./uptime-calculator");
|
const { UptimeCalculator } = require("./uptime-calculator");
|
||||||
const dayjs = require("dayjs");
|
const dayjs = require("dayjs");
|
||||||
|
const { SimpleMigrationServer } = require("./utils/simple-migration-server");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database & App Data Folder
|
* Database & App Data Folder
|
||||||
|
@ -382,9 +383,11 @@ class Database {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Patch the database
|
* Patch the database
|
||||||
|
* @param {number} port Start the migration server for aggregate tables on this port if provided
|
||||||
|
* @param {string} hostname Start the migration server for aggregate tables on this hostname if provided
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async patch() {
|
static async patch(port = undefined, hostname = undefined) {
|
||||||
// Still need to keep this for old versions of Uptime Kuma
|
// Still need to keep this for old versions of Uptime Kuma
|
||||||
if (Database.dbConfig.type === "sqlite") {
|
if (Database.dbConfig.type === "sqlite") {
|
||||||
await this.patchSqlite();
|
await this.patchSqlite();
|
||||||
|
@ -409,7 +412,7 @@ class Database {
|
||||||
await R.exec("PRAGMA foreign_keys = ON");
|
await R.exec("PRAGMA foreign_keys = ON");
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.migrateAggregateTable();
|
await this.migrateAggregateTable(port, hostname);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Allow missing patch files for downgrade or testing pr.
|
// Allow missing patch files for downgrade or testing pr.
|
||||||
|
@ -735,9 +738,11 @@ class Database {
|
||||||
* Normally, it should be in transaction, but UptimeCalculator wasn't designed to be in transaction before that.
|
* Normally, it should be in transaction, but UptimeCalculator wasn't designed to be in transaction before that.
|
||||||
* I don't want to heavily modify the UptimeCalculator, so it is not in transaction.
|
* I don't want to heavily modify the UptimeCalculator, so it is not in transaction.
|
||||||
* Run `npm run reset-migrate-aggregate-table-state` to reset, in case the migration is interrupted.
|
* Run `npm run reset-migrate-aggregate-table-state` to reset, in case the migration is interrupted.
|
||||||
|
* @param {number} port Start the migration server on this port if provided
|
||||||
|
* @param {string} hostname Start the migration server on this hostname if provided
|
||||||
* @returns {Promise<void>}
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
static async migrateAggregateTable() {
|
static async migrateAggregateTable(port, hostname = undefined) {
|
||||||
log.debug("db", "Enter Migrate Aggregate Table function");
|
log.debug("db", "Enter Migrate Aggregate Table function");
|
||||||
|
|
||||||
// Add a setting for 2.0.0-dev users to skip this migration
|
// Add a setting for 2.0.0-dev users to skip this migration
|
||||||
|
@ -758,6 +763,18 @@ class Database {
|
||||||
throw new Error("Aggregate table migration is already in progress");
|
throw new Error("Aggregate table migration is already in progress");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start migration server for displaying the migration status
|
||||||
|
* @type {SimpleMigrationServer}
|
||||||
|
*/
|
||||||
|
let migrationServer;
|
||||||
|
let msg;
|
||||||
|
|
||||||
|
if (port) {
|
||||||
|
migrationServer = new SimpleMigrationServer();
|
||||||
|
await migrationServer.start(port, hostname);
|
||||||
|
}
|
||||||
|
|
||||||
await Settings.set("migrateAggregateTableState", "migrating");
|
await Settings.set("migrateAggregateTableState", "migrating");
|
||||||
|
|
||||||
log.info("db", "Migrating Aggregate Table");
|
log.info("db", "Migrating Aggregate Table");
|
||||||
|
@ -777,6 +794,7 @@ class Database {
|
||||||
let count = countResult.count;
|
let count = countResult.count;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
log.warn("db", `Aggregate table ${table} is not empty, migration will not be started (Maybe you were using 2.0.0-dev?)`);
|
log.warn("db", `Aggregate table ${table} is not empty, migration will not be started (Maybe you were using 2.0.0-dev?)`);
|
||||||
|
await migrationServer?.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -811,7 +829,9 @@ class Database {
|
||||||
`, [ monitor.monitor_id, date.date ]);
|
`, [ monitor.monitor_id, date.date ]);
|
||||||
|
|
||||||
if (heartbeats.length > 0) {
|
if (heartbeats.length > 0) {
|
||||||
log.info("db", `[DON'T STOP] Migrating monitor data ${monitor.monitor_id} - ${date.date} [${progressPercent.toFixed(2)}%][${i}/${monitors.length}]`);
|
msg = `[DON'T STOP] Migrating monitor data ${monitor.monitor_id} - ${date.date} [${progressPercent.toFixed(2)}%][${i}/${monitors.length}]`;
|
||||||
|
log.info("db", msg);
|
||||||
|
migrationServer?.update(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let heartbeat of heartbeats) {
|
for (let heartbeat of heartbeats) {
|
||||||
|
@ -829,9 +849,13 @@ class Database {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Database.clearHeartbeatData(true);
|
msg = "Clearing non-important heartbeats";
|
||||||
|
log.info("db", msg);
|
||||||
|
migrationServer?.update(msg);
|
||||||
|
|
||||||
|
await Database.clearHeartbeatData(true);
|
||||||
await Settings.set("migrateAggregateTableState", "migrated");
|
await Settings.set("migrateAggregateTableState", "migrated");
|
||||||
|
await migrationServer?.stop();
|
||||||
|
|
||||||
if (monitors.length > 0) {
|
if (monitors.length > 0) {
|
||||||
log.info("db", "Aggregate Table Migration Completed");
|
log.info("db", "Aggregate Table Migration Completed");
|
||||||
|
|
|
@ -403,6 +403,8 @@ class StatusPage extends BeanModel {
|
||||||
autoRefreshInterval: this.autoRefreshInterval,
|
autoRefreshInterval: this.autoRefreshInterval,
|
||||||
published: !!this.published,
|
published: !!this.published,
|
||||||
showTags: !!this.show_tags,
|
showTags: !!this.show_tags,
|
||||||
|
showLocaleSelector: !!this.show_locale_selector,
|
||||||
|
defaultLocale: this.default_locale,
|
||||||
domainNameList: this.getDomainNameList(),
|
domainNameList: this.getDomainNameList(),
|
||||||
customCSS: this.custom_css,
|
customCSS: this.custom_css,
|
||||||
footerText: this.footer_text,
|
footerText: this.footer_text,
|
||||||
|
@ -427,6 +429,8 @@ class StatusPage extends BeanModel {
|
||||||
theme: this.theme,
|
theme: this.theme,
|
||||||
published: !!this.published,
|
published: !!this.published,
|
||||||
showTags: !!this.show_tags,
|
showTags: !!this.show_tags,
|
||||||
|
showLocaleSelector: !!this.show_locale_selector,
|
||||||
|
defaultLocale: this.default_locale,
|
||||||
customCSS: this.custom_css,
|
customCSS: this.custom_css,
|
||||||
footerText: this.footer_text,
|
footerText: this.footer_text,
|
||||||
showPoweredBy: !!this.show_powered_by,
|
showPoweredBy: !!this.show_powered_by,
|
||||||
|
|
|
@ -1716,7 +1716,7 @@ async function initDatabase(testMode = false) {
|
||||||
log.info("server", "Connected to the database");
|
log.info("server", "Connected to the database");
|
||||||
|
|
||||||
// Patch the database
|
// Patch the database
|
||||||
await Database.patch();
|
await Database.patch(port, hostname);
|
||||||
|
|
||||||
let jwtSecretBean = await R.findOne("setting", " `key` = ? ", [
|
let jwtSecretBean = await R.findOne("setting", " `key` = ? ", [
|
||||||
"jwtSecret",
|
"jwtSecret",
|
||||||
|
|
|
@ -160,6 +160,8 @@ module.exports.statusPageSocketHandler = (socket) => {
|
||||||
//statusPage.published = ;
|
//statusPage.published = ;
|
||||||
//statusPage.search_engine_index = ;
|
//statusPage.search_engine_index = ;
|
||||||
statusPage.show_tags = config.showTags;
|
statusPage.show_tags = config.showTags;
|
||||||
|
statusPage.show_locale_selector = config.showLocaleSelector;
|
||||||
|
statusPage.default_locale = config.defaultLocale;
|
||||||
//statusPage.password = null;
|
//statusPage.password = null;
|
||||||
statusPage.footer_text = config.footerText;
|
statusPage.footer_text = config.footerText;
|
||||||
statusPage.custom_css = config.customCSS;
|
statusPage.custom_css = config.customCSS;
|
||||||
|
|
84
server/utils/simple-migration-server.js
Normal file
84
server/utils/simple-migration-server.js
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
const express = require("express");
|
||||||
|
const http = require("node:http");
|
||||||
|
const { log } = require("../../src/util");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SimpleMigrationServer
|
||||||
|
* For displaying the migration status of the server
|
||||||
|
* Also, it is used to let Docker healthcheck know the status of the server, as the main server is not started yet, healthcheck will think the server is down incorrectly.
|
||||||
|
*/
|
||||||
|
class SimpleMigrationServer {
|
||||||
|
/**
|
||||||
|
* Express app instance
|
||||||
|
* @type {?Express}
|
||||||
|
*/
|
||||||
|
app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server instance
|
||||||
|
* @type {?Server}
|
||||||
|
*/
|
||||||
|
server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Response object
|
||||||
|
* @type {?Response}
|
||||||
|
*/
|
||||||
|
response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the server
|
||||||
|
* @param {number} port Port
|
||||||
|
* @param {string} hostname Hostname
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
start(port, hostname) {
|
||||||
|
this.app = express();
|
||||||
|
this.server = http.createServer(this.app);
|
||||||
|
|
||||||
|
this.app.get("/", (req, res) => {
|
||||||
|
res.set("Content-Type", "text/plain");
|
||||||
|
res.write("Migration is in progress, listening message...\n");
|
||||||
|
if (this.response) {
|
||||||
|
this.response.write("Disconnected\n");
|
||||||
|
this.response.end();
|
||||||
|
}
|
||||||
|
this.response = res;
|
||||||
|
// never ending response
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.server.listen(port, hostname, () => {
|
||||||
|
if (hostname) {
|
||||||
|
log.info("migration", `Migration server is running on http://${hostname}:${port}`);
|
||||||
|
} else {
|
||||||
|
log.info("migration", `Migration server is running on http://localhost:${port}`);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the message
|
||||||
|
* @param {string} msg Message to update
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
update(msg) {
|
||||||
|
this.response?.write(msg + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stop the server
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async stop() {
|
||||||
|
this.response?.write("Finished, please refresh this page.\n");
|
||||||
|
this.response?.end();
|
||||||
|
await this.server?.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
SimpleMigrationServer,
|
||||||
|
};
|
|
@ -301,6 +301,8 @@
|
||||||
"Switch to Light Theme": "Switch to Light Theme",
|
"Switch to Light Theme": "Switch to Light Theme",
|
||||||
"Switch to Dark Theme": "Switch to Dark Theme",
|
"Switch to Dark Theme": "Switch to Dark Theme",
|
||||||
"Show Tags": "Show Tags",
|
"Show Tags": "Show Tags",
|
||||||
|
"Show Locale Selector": "Show Locale Selector",
|
||||||
|
"Default Locale": "Default Locale",
|
||||||
"Hide Tags": "Hide Tags",
|
"Hide Tags": "Hide Tags",
|
||||||
"Description": "Description",
|
"Description": "Description",
|
||||||
"No monitors available.": "No monitors available.",
|
"No monitors available.": "No monitors available.",
|
||||||
|
|
|
@ -33,6 +33,17 @@ export default {
|
||||||
this.$i18n.locale = lang;
|
this.$i18n.locale = lang;
|
||||||
localStorage.locale = lang;
|
localStorage.locale = lang;
|
||||||
setPageLocale();
|
setPageLocale();
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Change the language for the current page (no localstore set)
|
||||||
|
* @param {string} lang Code of language to switch to.
|
||||||
|
* @returns {Promise<void>}
|
||||||
|
*/
|
||||||
|
async changeCurrentPageLang(lang) {
|
||||||
|
let message = (await langModules["../lang/" + lang + ".json"]()).default;
|
||||||
|
this.$i18n.setLocaleMessage(lang, message);
|
||||||
|
this.$i18n.locale = lang;
|
||||||
|
setPageLocale();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -56,6 +56,18 @@
|
||||||
<label class="form-check-label" for="showTags">{{ $t("Show Tags") }}</label>
|
<label class="form-check-label" for="showTags">{{ $t("Show Tags") }}</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="my-3 form-check form-switch">
|
||||||
|
<input id="showLocaleSelector" v-model="config.showLocaleSelector" class="form-check-input" type="checkbox">
|
||||||
|
<label class="form-check-label" for="showLocaleSelector">{{ $t("Show Locale Selector") }}</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="my-3">
|
||||||
|
<label for="defaultLocale" class="form-label">{{ $t("Default Locale") }}</label>
|
||||||
|
<select id="defaultLocale" v-model="config.defaultLocale" class="form-select">
|
||||||
|
<option v-for="locale in $i18n.availableLocales" :key="locale" :value="locale" :text="$i18n.messages[locale].languageName"></option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Show Powered By -->
|
<!-- Show Powered By -->
|
||||||
<div class="my-3 form-check form-switch">
|
<div class="my-3 form-check form-switch">
|
||||||
<input id="show-powered-by" v-model="config.showPoweredBy" class="form-check-input" type="checkbox" data-testid="show-powered-by-checkbox">
|
<input id="show-powered-by" v-model="config.showPoweredBy" class="form-check-input" type="checkbox" data-testid="show-powered-by-checkbox">
|
||||||
|
@ -128,7 +140,7 @@
|
||||||
|
|
||||||
<!-- Main Status Page -->
|
<!-- Main Status Page -->
|
||||||
<div :class="{ edit: enableEditMode}" class="main">
|
<div :class="{ edit: enableEditMode}" class="main">
|
||||||
<!-- Logo & Title -->
|
<!-- Logo, Title & Language -->
|
||||||
<h1 class="mb-4 title-flex">
|
<h1 class="mb-4 title-flex">
|
||||||
<!-- Logo -->
|
<!-- Logo -->
|
||||||
<span class="logo-wrapper" @click="showImageCropUploadMethod">
|
<span class="logo-wrapper" @click="showImageCropUploadMethod">
|
||||||
|
@ -151,7 +163,14 @@
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Title -->
|
<!-- Title -->
|
||||||
<Editable v-model="config.title" tag="span" :contenteditable="editMode" :noNL="true" />
|
<Editable v-model="config.title" class="title" tag="span" :contenteditable="editMode" :noNL="true" />
|
||||||
|
|
||||||
|
<!-- Locale Selector -->
|
||||||
|
<span class="language-selector">
|
||||||
|
<select v-model="$root.language" class="form-select">
|
||||||
|
<option v-for="locale in $i18n.availableLocales" :key="locale" :value="locale" :text="$i18n.messages[locale].languageName"></option>
|
||||||
|
</select>
|
||||||
|
</span>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<!-- Admin functions -->
|
<!-- Admin functions -->
|
||||||
|
@ -715,6 +734,10 @@ export default {
|
||||||
this.maintenanceList = res.data.maintenanceList;
|
this.maintenanceList = res.data.maintenanceList;
|
||||||
this.$root.publicGroupList = res.data.publicGroupList;
|
this.$root.publicGroupList = res.data.publicGroupList;
|
||||||
|
|
||||||
|
if (!localStorage.locale && this.config.defaultLocale) {
|
||||||
|
this.$root.changeCurrentPageLang(this.config.defaultLocale);
|
||||||
|
}
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
|
|
||||||
// Configure auto-refresh loop
|
// Configure auto-refresh loop
|
||||||
|
@ -1143,6 +1166,10 @@ footer {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
flex-grow: 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.logo-wrapper {
|
.logo-wrapper {
|
||||||
|
|
Loading…
Reference in a new issue