mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-03-14 13:24:47 +00:00
Compare commits
No commits in common. "6bade1fe812ef642589145d84ba96ab4955c38e4" and "e44ec55edae18fdfa3da09787dcd6f887dd05226" have entirely different histories.
6bade1fe81
...
e44ec55eda
7 changed files with 11 additions and 97 deletions
2
.github/workflows/auto-test.yml
vendored
2
.github/workflows/auto-test.yml
vendored
|
@ -78,7 +78,7 @@ jobs:
|
||||||
|
|
||||||
e2e-test:
|
e2e-test:
|
||||||
needs: [ ]
|
needs: [ ]
|
||||||
runs-on: ubuntu-24.04-arm
|
runs-on: ARM64
|
||||||
steps:
|
steps:
|
||||||
- run: git config --global core.autocrlf false # Mainly for Windows
|
- run: git config --global core.autocrlf false # Mainly for Windows
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
const googleAnalytics = require("./google-analytics");
|
|
||||||
const umamiAnalytics = require("./umami-analytics");
|
|
||||||
const plausibleAnalytics = require("./plausible-analytics");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string that represents the javascript that is required to insert the selected Analytics' script
|
|
||||||
* into a webpage.
|
|
||||||
* @param {typeof import("../model/status_page").StatusPage} statusPage Status page populate HTML with
|
|
||||||
* @returns {string} HTML script tags to inject into page
|
|
||||||
*/
|
|
||||||
function getAnalyticsScript(statusPage) {
|
|
||||||
switch (statusPage.analyticsType) {
|
|
||||||
case "google":
|
|
||||||
return googleAnalytics.getGoogleAnalyticsScript(statusPage.analyticsId);
|
|
||||||
case "umami":
|
|
||||||
return umamiAnalytics.getUmamiAnalyticsScript(statusPage.analyticsDomainUrl, statusPage.analyticsId);
|
|
||||||
case "plausible":
|
|
||||||
return plausibleAnalytics.getPlausibleAnalyticsScript(statusPage.analyticsDomainUrl, statusPage.analyticsId);
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function that checks wether the selected analytics has been configured properly
|
|
||||||
* @param {typeof import("../model/status_page").StatusPage} statusPage Status page populate HTML with
|
|
||||||
* @returns {boolean} Boolean defining if the analytics config is valid
|
|
||||||
*/
|
|
||||||
function isValidAnalyticsConfig(statusPage) {
|
|
||||||
switch (statusPage.analyticsType) {
|
|
||||||
case "google":
|
|
||||||
return statusPage.analyticsId != null;
|
|
||||||
case "umami":
|
|
||||||
case "plausible":
|
|
||||||
return statusPage.analyticsId != null && statusPage.analyticsDomainUrl != null;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getAnalyticsScript,
|
|
||||||
isValidAnalyticsConfig
|
|
||||||
};
|
|
|
@ -1,36 +0,0 @@
|
||||||
const jsesc = require("jsesc");
|
|
||||||
const { escape } = require("html-escaper");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a string that represents the javascript that is required to insert the Plausible Analytics script
|
|
||||||
* into a webpage.
|
|
||||||
* @param {string} plausibleDomainUrl Domain name with tld to use with the Plausible Analytics script.
|
|
||||||
* @param {string} domainsToMonitor Domains to track seperated by a ',' to add Plausible Analytics script.
|
|
||||||
* @returns {string} HTML script tags to inject into page
|
|
||||||
*/
|
|
||||||
function getPlausibleAnalyticsScript(plausibleDomainUrl, domainsToMonitor) {
|
|
||||||
let escapedDomainUrlJS = jsesc(plausibleDomainUrl, { isScriptContext: true });
|
|
||||||
let escapedWebsiteIdJS = jsesc(domainsToMonitor, { isScriptContext: true });
|
|
||||||
|
|
||||||
if (escapedDomainUrlJS) {
|
|
||||||
escapedDomainUrlJS = escapedDomainUrlJS.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (escapedWebsiteIdJS) {
|
|
||||||
escapedWebsiteIdJS = escapedWebsiteIdJS.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escape the domain url for use in an HTML attribute.
|
|
||||||
let escapedDomainUrlHTMLAttribute = escape(escapedDomainUrlJS);
|
|
||||||
|
|
||||||
// Escape the website id for use in an HTML attribute.
|
|
||||||
let escapedWebsiteIdHTMLAttribute = escape(escapedWebsiteIdJS);
|
|
||||||
|
|
||||||
return `
|
|
||||||
<script defer src="https://${escapedDomainUrlHTMLAttribute}/js/script.js" data-domain="${escapedWebsiteIdHTMLAttribute}"></script>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getPlausibleAnalyticsScript
|
|
||||||
};
|
|
|
@ -3,7 +3,8 @@ const { R } = require("redbean-node");
|
||||||
const cheerio = require("cheerio");
|
const cheerio = require("cheerio");
|
||||||
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
const { UptimeKumaServer } = require("../uptime-kuma-server");
|
||||||
const jsesc = require("jsesc");
|
const jsesc = require("jsesc");
|
||||||
const analytics = require("../analytics/analytics");
|
const googleAnalytics = require("../google-analytics");
|
||||||
|
const umamiAnalytics = require("../umami-analytics");
|
||||||
const { marked } = require("marked");
|
const { marked } = require("marked");
|
||||||
const { Feed } = require("feed");
|
const { Feed } = require("feed");
|
||||||
const config = require("../config");
|
const config = require("../config");
|
||||||
|
@ -120,9 +121,14 @@ class StatusPage extends BeanModel {
|
||||||
|
|
||||||
const head = $("head");
|
const head = $("head");
|
||||||
|
|
||||||
if (analytics.isValidAnalyticsConfig(statusPage)) {
|
if (statusPage.analyticsType === "google" && statusPage.analyticsId) {
|
||||||
let escapedAnalyticsScript = analytics.getAnalyticsScript(statusPage);
|
let escapedGoogleAnalyticsScript = googleAnalytics.getGoogleAnalyticsScript(statusPage.analyticsId);
|
||||||
head.append($(escapedAnalyticsScript));
|
head.append($(escapedGoogleAnalyticsScript));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (statusPage.analyticsType === "umami" && statusPage.analyticsDomainUrl && statusPage.analyticsId) {
|
||||||
|
let escapedUmamiAnalyticsScript = umamiAnalytics.getUmamiAnalyticsScript(statusPage.analyticsDomainUrl, statusPage.analyticsId);
|
||||||
|
head.append($(escapedUmamiAnalyticsScript));
|
||||||
}
|
}
|
||||||
|
|
||||||
// OG Meta Tags
|
// OG Meta Tags
|
||||||
|
|
|
@ -20,8 +20,6 @@ test.describe("Status Page", () => {
|
||||||
const googleAnalyticsId = "G-123";
|
const googleAnalyticsId = "G-123";
|
||||||
const umamiAnalyticsDomainUrl = "example.com";
|
const umamiAnalyticsDomainUrl = "example.com";
|
||||||
const umamiAnalyticsWebsiteId = "606487e2-bc25-45f9-9132-fa8b065aad46";
|
const umamiAnalyticsWebsiteId = "606487e2-bc25-45f9-9132-fa8b065aad46";
|
||||||
const plausibleAnalyticsDomainUrl = "example.com";
|
|
||||||
const plausibleAnalyticsDomainsUrls = "one.com,two.com";
|
|
||||||
const customCss = "body { background: rgb(0, 128, 128) !important; }";
|
const customCss = "body { background: rgb(0, 128, 128) !important; }";
|
||||||
const descriptionText = "This is an example status page.";
|
const descriptionText = "This is an example status page.";
|
||||||
const incidentTitle = "Example Outage Incident";
|
const incidentTitle = "Example Outage Incident";
|
||||||
|
@ -134,16 +132,6 @@ test.describe("Status Page", () => {
|
||||||
|
|
||||||
expect(await page.locator("head").innerHTML()).toContain(umamiAnalyticsDomainUrl);
|
expect(await page.locator("head").innerHTML()).toContain(umamiAnalyticsDomainUrl);
|
||||||
expect(await page.locator("head").innerHTML()).toContain(umamiAnalyticsWebsiteId);
|
expect(await page.locator("head").innerHTML()).toContain(umamiAnalyticsWebsiteId);
|
||||||
|
|
||||||
await page.getByTestId("edit-button").click();
|
|
||||||
// Fill in plausible analytics after editing
|
|
||||||
await page.getByTestId("analytics-type-select").selectOption("plausible");
|
|
||||||
await page.getByTestId("analytics-domain-url-input").fill(plausibleAnalyticsDomainUrl);
|
|
||||||
await page.getByTestId("analytics-id-input").fill(plausibleAnalyticsDomainsUrls);
|
|
||||||
await page.getByTestId("save-button").click();
|
|
||||||
await screenshot(testInfo, page);
|
|
||||||
expect(await page.locator("head").innerHTML()).toContain(plausibleAnalyticsDomainUrl);
|
|
||||||
expect(await page.locator("head").innerHTML()).toContain(plausibleAnalyticsDomainsUrls);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// @todo Test certificate expiry
|
// @todo Test certificate expiry
|
||||||
|
|
Loading…
Add table
Reference in a new issue