mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 09:58:32 +02:00
allow disabling authentication for server version, closes #1132
This commit is contained in:
parent
2823bf3488
commit
7fb22d41a0
@ -2,6 +2,9 @@
|
|||||||
# Instance name can be used to distinguish between different instances
|
# Instance name can be used to distinguish between different instances
|
||||||
instanceName=
|
instanceName=
|
||||||
|
|
||||||
|
# set to true to allow using Trilium without authentication (makes sense for server build only, desktop build doesn't need password)
|
||||||
|
noAuthentication=false
|
||||||
|
|
||||||
# Disable automatically generating desktop icon
|
# Disable automatically generating desktop icon
|
||||||
# noDesktopIcon=true
|
# noDesktopIcon=true
|
||||||
|
|
||||||
|
@ -6,12 +6,15 @@ const sqlInit = require('./sql_init');
|
|||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const passwordEncryptionService = require('./password_encryption');
|
const passwordEncryptionService = require('./password_encryption');
|
||||||
const optionService = require('./options');
|
const optionService = require('./options');
|
||||||
|
const config = require('./config');
|
||||||
|
|
||||||
|
const noAuthentication = config.General && config.General.noAuthentication === true;
|
||||||
|
|
||||||
function checkAuth(req, res, next) {
|
function checkAuth(req, res, next) {
|
||||||
if (!sqlInit.isDbInitialized()) {
|
if (!sqlInit.isDbInitialized()) {
|
||||||
res.redirect("setup");
|
res.redirect("setup");
|
||||||
}
|
}
|
||||||
else if (!req.session.loggedIn && !utils.isElectron()) {
|
else if (!req.session.loggedIn && !utils.isElectron() && !noAuthentication) {
|
||||||
res.redirect("login");
|
res.redirect("login");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -22,7 +25,7 @@ function checkAuth(req, res, next) {
|
|||||||
// for electron things which need network stuff
|
// for electron things which need network stuff
|
||||||
// currently we're doing that for file upload because handling form data seems to be difficult
|
// currently we're doing that for file upload because handling form data seems to be difficult
|
||||||
function checkApiAuthOrElectron(req, res, next) {
|
function checkApiAuthOrElectron(req, res, next) {
|
||||||
if (!req.session.loggedIn && !utils.isElectron()) {
|
if (!req.session.loggedIn && !utils.isElectron() && !noAuthentication) {
|
||||||
reject(req, res, "Not authorized");
|
reject(req, res, "Not authorized");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -31,7 +34,7 @@ function checkApiAuthOrElectron(req, res, next) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkApiAuth(req, res, next) {
|
function checkApiAuth(req, res, next) {
|
||||||
if (!req.session.loggedIn) {
|
if (!req.session.loggedIn && !noAuthentication) {
|
||||||
reject(req, res, "Not authorized");
|
reject(req, res, "Not authorized");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -3,6 +3,7 @@ const utils = require('./utils');
|
|||||||
const log = require('./log');
|
const log = require('./log');
|
||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const cls = require('./cls');
|
const cls = require('./cls');
|
||||||
|
const config = require('./config');
|
||||||
const syncMutexService = require('./sync_mutex');
|
const syncMutexService = require('./sync_mutex');
|
||||||
const protectedSessionService = require('./protected_session');
|
const protectedSessionService = require('./protected_session');
|
||||||
|
|
||||||
@ -12,7 +13,9 @@ function init(httpServer, sessionParser) {
|
|||||||
webSocketServer = new WebSocket.Server({
|
webSocketServer = new WebSocket.Server({
|
||||||
verifyClient: (info, done) => {
|
verifyClient: (info, done) => {
|
||||||
sessionParser(info.req, {}, () => {
|
sessionParser(info.req, {}, () => {
|
||||||
const allowed = utils.isElectron() || info.req.session.loggedIn;
|
const allowed = utils.isElectron()
|
||||||
|
|| info.req.session.loggedIn
|
||||||
|
|| (config.General && config.General.noAuthentication);
|
||||||
|
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
log.error("WebSocket connection not allowed because session is neither electron nor logged in.");
|
log.error("WebSocket connection not allowed because session is neither electron nor logged in.");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user