|
@ -5,13 +5,13 @@ const server = http.createServer(app); |
|
|
const { Server } = require("socket.io"); |
|
|
const { Server } = require("socket.io"); |
|
|
const io = new Server(server); |
|
|
const io = new Server(server); |
|
|
const dayjs = require("dayjs"); |
|
|
const dayjs = require("dayjs"); |
|
|
const {R} = require("redbean-node"); |
|
|
const { R } = require("redbean-node"); |
|
|
const passwordHash = require('password-hash'); |
|
|
const passwordHash = require('password-hash'); |
|
|
const jwt = require('jsonwebtoken'); |
|
|
const jwt = require('jsonwebtoken'); |
|
|
const Monitor = require("./model/monitor"); |
|
|
const Monitor = require("./model/monitor"); |
|
|
const fs = require("fs"); |
|
|
const fs = require("fs"); |
|
|
const {getSettings} = require("./util-server"); |
|
|
const { getSettings } = require("./util-server"); |
|
|
const {Notification} = require("./notification") |
|
|
const { Notification } = require("./notification") |
|
|
const args = require('args-parser')(process.argv); |
|
|
const args = require('args-parser')(process.argv); |
|
|
|
|
|
|
|
|
console.log("args:") |
|
|
console.log("args:") |
|
@ -32,14 +32,14 @@ let needSetup = false; |
|
|
|
|
|
|
|
|
app.use('/', express.static("dist")); |
|
|
app.use('/', express.static("dist")); |
|
|
|
|
|
|
|
|
app.post('/test-webhook', function(request, response, next) { |
|
|
app.post('/test-webhook', function (request, response, next) { |
|
|
console.log("Test Webhook (application/json only)") |
|
|
console.log("Test Webhook (application/json only)") |
|
|
console.log("Content-Type: " + request.header("Content-Type")) |
|
|
console.log("Content-Type: " + request.header("Content-Type")) |
|
|
console.log(request.body) |
|
|
console.log(request.body) |
|
|
response.end(); |
|
|
response.end(); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
app.get('*', function(request, response, next) { |
|
|
app.get('*', function (request, response, next) { |
|
|
response.sendFile(process.cwd() + '/dist/index.html'); |
|
|
response.sendFile(process.cwd() + '/dist/index.html'); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -194,7 +194,7 @@ let needSetup = false; |
|
|
try { |
|
|
try { |
|
|
checkLogin(socket) |
|
|
checkLogin(socket) |
|
|
|
|
|
|
|
|
let bean = await R.findOne("monitor", " id = ? ", [ monitor.id ]) |
|
|
let bean = await R.findOne("monitor", " id = ? ", [monitor.id]) |
|
|
|
|
|
|
|
|
if (bean.user_id !== socket.userID) { |
|
|
if (bean.user_id !== socket.userID) { |
|
|
throw new Error("Permission denied.") |
|
|
throw new Error("Permission denied.") |
|
@ -332,7 +332,7 @@ let needSetup = false; |
|
|
try { |
|
|
try { |
|
|
checkLogin(socket) |
|
|
checkLogin(socket) |
|
|
|
|
|
|
|
|
if (! password.currentPassword) { |
|
|
if (!password.currentPassword) { |
|
|
throw new Error("Invalid new password") |
|
|
throw new Error("Invalid new password") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -471,7 +471,7 @@ async function checkOwner(userID, monitorID) { |
|
|
userID, |
|
|
userID, |
|
|
]) |
|
|
]) |
|
|
|
|
|
|
|
|
if (! row) { |
|
|
if (!row) { |
|
|
throw new Error("You do not own this monitor."); |
|
|
throw new Error("You do not own this monitor."); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -526,7 +526,7 @@ async function getMonitorJSONList(userID) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function checkLogin(socket) { |
|
|
function checkLogin(socket) { |
|
|
if (! socket.userID) { |
|
|
if (!socket.userID) { |
|
|
throw new Error("You are not logged in."); |
|
|
throw new Error("You are not logged in."); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -534,7 +534,7 @@ function checkLogin(socket) { |
|
|
async function initDatabase() { |
|
|
async function initDatabase() { |
|
|
const path = './data/kuma.db'; |
|
|
const path = './data/kuma.db'; |
|
|
|
|
|
|
|
|
if (! fs.existsSync(path)) { |
|
|
if (!fs.existsSync(path)) { |
|
|
console.log("Copy Database") |
|
|
console.log("Copy Database") |
|
|
fs.copyFileSync("./db/kuma.db", path); |
|
|
fs.copyFileSync("./db/kuma.db", path); |
|
|
} |
|
|
} |
|
@ -551,7 +551,7 @@ async function initDatabase() { |
|
|
"jwtSecret" |
|
|
"jwtSecret" |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
if (! jwtSecretBean) { |
|
|
if (!jwtSecretBean) { |
|
|
console.log("JWT secret is not found, generate one.") |
|
|
console.log("JWT secret is not found, generate one.") |
|
|
jwtSecretBean = R.dispense("setting") |
|
|
jwtSecretBean = R.dispense("setting") |
|
|
jwtSecretBean.key = "jwtSecret" |
|
|
jwtSecretBean.key = "jwtSecret" |
|
@ -638,7 +638,7 @@ async function sendHeartbeatList(socket, monitorID) { |
|
|
let result = []; |
|
|
let result = []; |
|
|
|
|
|
|
|
|
for (let bean of list) { |
|
|
for (let bean of list) { |
|
|
result.unshift(bean.toJSON()) |
|
|
result.unshift(bean.toJSON()) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
socket.emit("heartbeatList", monitorID, result) |
|
|
socket.emit("heartbeatList", monitorID, result) |
|
|