fix and move the steam api key to settings page

pull/492/head
Louis Lam 3 years ago
parent ae31eb6ba9
commit 20d59e5a13

@ -1,7 +0,0 @@
-- You should not modify if this have pushed to Github, unless it does serious wrong with the db.
BEGIN TRANSACTION;
ALTER TABLE monitor
ADD apikey VARCHAR(64) default '' not null;
COMMIT;

@ -46,7 +46,6 @@ class Database {
"patch-improve-performance.sql": true, "patch-improve-performance.sql": true,
"patch-2fa.sql": true, "patch-2fa.sql": true,
"patch-add-retry-interval-monitor.sql": true, "patch-add-retry-interval-monitor.sql": true,
"patch-add-apikey-monitor.sql": true,
"patch-incident-table.sql": true, "patch-incident-table.sql": true,
"patch-group-table.sql": true, "patch-group-table.sql": true,
"patch-monitor-push_token.sql": true, "patch-monitor-push_token.sql": true,
@ -54,7 +53,7 @@ class Database {
} }
/** /**
* The finally version should be 10 after merged tag feature * The final version should be 10 after merged tag feature
* @deprecated Use patchList for any new feature * @deprecated Use patchList for any new feature
*/ */
static latestVersion = 10; static latestVersion = 10;

@ -7,7 +7,7 @@ dayjs.extend(timezone);
const axios = require("axios"); const axios = require("axios");
const { Prometheus } = require("../prometheus"); const { Prometheus } = require("../prometheus");
const { debug, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util"); const { debug, UP, DOWN, PENDING, flipStatus, TimeLogger } = require("../../src/util");
const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom } = require("../util-server"); const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalClientInRoom, setting } = require("../util-server");
const { R } = require("redbean-node"); const { R } = require("redbean-node");
const { BeanModel } = require("redbean-node/dist/bean-model"); const { BeanModel } = require("redbean-node/dist/bean-model");
const { Notification } = require("../notification"); const { Notification } = require("../notification");
@ -292,26 +292,22 @@ class Monitor extends BeanModel {
}, },
params: { params: {
filter: filter, filter: filter,
key: this.apikey, key: await setting("steamAPIKey"),
} }
}); });
bean.msg = `${res.status} - ${res.statusText}`; if (res.data.response && res.data.response.servers && res.data.response.servers.length > 0) {
bean.ping = await ping(this.hostname); bean.status = UP;
bean.msg = res.data.response.servers[0].name;
let data = res.data;
// Convert to string for object/array try {
if (typeof data !== "string") { bean.ping = await ping(this.hostname);
data = JSON.stringify(data); } catch (_) { }
}
if (data.includes(`${this.hostname}:${this.port}`)) {
bean.msg += ", server is found";
bean.status = UP;
} else { } else {
throw new Error(bean.msg + ", but server is not found"); throw new Error("Server not found on Steam");
} }
} else { } else {
bean.msg = "Unknown Monitor Type"; bean.msg = "Unknown Monitor Type";
bean.status = PENDING; bean.status = PENDING;

@ -304,5 +304,5 @@ export default {
records: "records", records: "records",
"One record": "One record", "One record": "One record",
"Showing {from} to {to} of {count} records": "Showing {from} to {to} of {count} records", "Showing {from} to {to} of {count} records": "Showing {from} to {to} of {count} records",
steamApiKeyDescription: "For monitoring a Steam Gameserver you need a steam Web-API key. You can register your api key here: https://steamcommunity.com/dev", steamApiKeyDescription: "For monitoring a Steam Gameserver you need a steam Web-API key. You can register your api key here: ",
}; };

@ -67,18 +67,20 @@
</div> </div>
<!-- Hostname --> <!-- Hostname -->
<!-- TCP Port / Ping / DNS only --> <!-- TCP Port / Ping / DNS / Steam only -->
<div v-if="monitor.type === 'port' || monitor.type === 'ping' || monitor.type === 'dns' " class="my-3"> <div v-if="monitor.type === 'port' || monitor.type === 'ping' || monitor.type === 'dns' || monitor.type === 'steam'" class="my-3">
<label for="hostname" class="form-label">{{ $t("Hostname") }}</label> <label for="hostname" class="form-label">{{ $t("Hostname") }}</label>
<input id="hostname" v-model="monitor.hostname" type="text" class="form-control" :pattern="`${ipRegexPattern}|${hostnameRegexPattern}`" required> <input id="hostname" v-model="monitor.hostname" type="text" class="form-control" :pattern="`${ipRegexPattern}|${hostnameRegexPattern}`" required>
</div> </div>
<!-- For TCP Port Type --> <!-- Port -->
<div v-if="monitor.type === 'port'" class="my-3"> <!-- For TCP Port / Steam Type -->
<div v-if="monitor.type === 'port' || monitor.type === 'steam'" class="my-3">
<label for="port" class="form-label">{{ $t("Port") }}</label> <label for="port" class="form-label">{{ $t("Port") }}</label>
<input id="port" v-model="monitor.port" type="number" class="form-control" required min="0" max="65535" step="1"> <input id="port" v-model="monitor.port" type="number" class="form-control" required min="0" max="65535" step="1">
</div> </div>
<!-- DNS Resolver Server -->
<!-- For DNS Type --> <!-- For DNS Type -->
<template v-if="monitor.type === 'dns'"> <template v-if="monitor.type === 'dns'">
<div class="my-3"> <div class="my-3">

@ -119,6 +119,15 @@
</div> </div>
</div> </div>
<!-- Steam API Key -->
<div class="mb-4">
<label class="form-label" for="steamAPIKey">{{ $t("Steam API Key") }}</label>
<input id="steamAPIKey" v-model="settings.steamAPIKey" class="form-control" name="steamAPIKey">
<div class="form-text">
{{ $t("steamApiKeyDescription") }}<a href="https://steamcommunity.com/dev" target="_blank">https://steamcommunity.com/dev</a>
</div>
</div>
<!-- Monitor History --> <!-- Monitor History -->
<div class="mb-4"> <div class="mb-4">
<h4 class="mt-4">{{ $t("Monitor History") }}</h4> <h4 class="mt-4">{{ $t("Monitor History") }}</h4>
@ -128,6 +137,7 @@
</div> </div>
</div> </div>
<!-- Save Button -->
<div> <div>
<button class="btn btn-primary" type="submit"> <button class="btn btn-primary" type="submit">
{{ $t("Save") }} {{ $t("Save") }}

Loading…
Cancel
Save