feat: modular logging + setup wizard
This commit is contained in:
37
server/extensions/authentication/azure.js
Normal file
37
server/extensions/authentication/azure.js
Normal file
@@ -0,0 +1,37 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Azure AD Account
|
||||
// ------------------------------------
|
||||
|
||||
const AzureAdOAuth2Strategy = require('passport-azure-ad-oauth2').Strategy
|
||||
|
||||
module.exports = {
|
||||
key: 'azure',
|
||||
title: 'Azure Active Directory',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret', 'callbackURL', 'resource', 'tenant'],
|
||||
init (passport, conf) {
|
||||
const jwt = require('jsonwebtoken')
|
||||
passport.use('azure_ad_oauth2',
|
||||
new AzureAdOAuth2Strategy({
|
||||
clientID: conf.clientId,
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL,
|
||||
resource: conf.resource,
|
||||
tenant: conf.tenant
|
||||
}, (accessToken, refreshToken, params, profile, cb) => {
|
||||
let waadProfile = jwt.decode(params.id_token)
|
||||
waadProfile.id = waadProfile.oid
|
||||
waadProfile.provider = 'azure'
|
||||
wiki.db.User.processProfile(waadProfile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
32
server/extensions/authentication/facebook.js
Normal file
32
server/extensions/authentication/facebook.js
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Facebook Account
|
||||
// ------------------------------------
|
||||
|
||||
const FacebookStrategy = require('passport-facebook').Strategy
|
||||
|
||||
module.exports = {
|
||||
key: 'facebook',
|
||||
title: 'Facebook',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret', 'callbackURL'],
|
||||
init (passport, conf) {
|
||||
passport.use('facebook',
|
||||
new FacebookStrategy({
|
||||
clientID: conf.clientId,
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL,
|
||||
profileFields: ['id', 'displayName', 'email']
|
||||
}, function (accessToken, refreshToken, profile, cb) {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
32
server/extensions/authentication/github.js
Normal file
32
server/extensions/authentication/github.js
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// GitHub Account
|
||||
// ------------------------------------
|
||||
|
||||
const GitHubStrategy = require('passport-github2').Strategy
|
||||
|
||||
module.exports = {
|
||||
key: 'github',
|
||||
title: 'GitHub',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret', 'callbackURL'],
|
||||
init (passport, conf) {
|
||||
passport.use('github',
|
||||
new GitHubStrategy({
|
||||
clientID: conf.clientId,
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL,
|
||||
scope: ['user:email']
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
31
server/extensions/authentication/google.js
Normal file
31
server/extensions/authentication/google.js
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Google ID Account
|
||||
// ------------------------------------
|
||||
|
||||
const GoogleStrategy = require('passport-google-oauth20').Strategy
|
||||
|
||||
module.exports = {
|
||||
key: 'google',
|
||||
title: 'Google ID',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret', 'callbackURL'],
|
||||
init (passport, conf) {
|
||||
passport.use('google',
|
||||
new GoogleStrategy({
|
||||
clientID: conf.clientId,
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
46
server/extensions/authentication/ldap.js
Normal file
46
server/extensions/authentication/ldap.js
Normal file
@@ -0,0 +1,46 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// LDAP Account
|
||||
// ------------------------------------
|
||||
|
||||
const LdapStrategy = require('passport-ldapauth').Strategy
|
||||
const fs = require('fs')
|
||||
|
||||
module.exports = {
|
||||
key: 'ldap',
|
||||
title: 'LDAP / Active Directory',
|
||||
useForm: true,
|
||||
props: ['url', 'bindDn', 'bindCredentials', 'searchBase', 'searchFilter', 'tlsEnabled', 'tlsCertPath'],
|
||||
init (passport, conf) {
|
||||
passport.use('ldapauth',
|
||||
new LdapStrategy({
|
||||
server: {
|
||||
url: conf.url,
|
||||
bindDn: conf.bindDn,
|
||||
bindCredentials: conf.bindCredentials,
|
||||
searchBase: conf.searchBase,
|
||||
searchFilter: conf.searchFilter,
|
||||
searchAttributes: ['displayName', 'name', 'cn', 'mail'],
|
||||
tlsOptions: (conf.tlsEnabled) ? {
|
||||
ca: [
|
||||
fs.readFileSync(conf.tlsCertPath)
|
||||
]
|
||||
} : {}
|
||||
},
|
||||
usernameField: 'email',
|
||||
passReqToCallback: false
|
||||
}, (profile, cb) => {
|
||||
profile.provider = 'ldap'
|
||||
profile.id = profile.dn
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
36
server/extensions/authentication/local.js
Normal file
36
server/extensions/authentication/local.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Local Account
|
||||
// ------------------------------------
|
||||
|
||||
const LocalStrategy = require('passport-local').Strategy
|
||||
|
||||
module.exports = {
|
||||
key: 'local',
|
||||
title: 'Local',
|
||||
useForm: true,
|
||||
props: [],
|
||||
init (passport, conf) {
|
||||
passport.use('local',
|
||||
new LocalStrategy({
|
||||
usernameField: 'email',
|
||||
passwordField: 'password'
|
||||
}, (uEmail, uPassword, done) => {
|
||||
wiki.db.User.findOne({ email: uEmail, provider: 'local' }).then((user) => {
|
||||
if (user) {
|
||||
return user.validatePassword(uPassword).then(() => {
|
||||
return done(null, user) || true
|
||||
}).catch((err) => {
|
||||
return done(err, null)
|
||||
})
|
||||
} else {
|
||||
return done(new Error('INVALID_LOGIN'), null)
|
||||
}
|
||||
}).catch((err) => {
|
||||
done(err, null)
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
31
server/extensions/authentication/microsoft.js
Normal file
31
server/extensions/authentication/microsoft.js
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Microsoft Account
|
||||
// ------------------------------------
|
||||
|
||||
const WindowsLiveStrategy = require('passport-windowslive').Strategy
|
||||
|
||||
module.exports = {
|
||||
key: 'microsoft',
|
||||
title: 'Microsoft Account',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret', 'callbackURL'],
|
||||
init (passport, conf) {
|
||||
passport.use('microsoft',
|
||||
new WindowsLiveStrategy({
|
||||
clientID: conf.clientId,
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL
|
||||
}, function (accessToken, refreshToken, profile, cb) {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
31
server/extensions/authentication/slack.js
Normal file
31
server/extensions/authentication/slack.js
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict'
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Slack Account
|
||||
// ------------------------------------
|
||||
|
||||
const SlackStrategy = require('passport-slack').Strategy
|
||||
|
||||
module.exports = {
|
||||
key: 'slack',
|
||||
title: 'Slack',
|
||||
useForm: false,
|
||||
props: ['clientId', 'clientSecret', 'callbackURL'],
|
||||
init (passport, conf) {
|
||||
passport.use('slack',
|
||||
new SlackStrategy({
|
||||
clientID: conf.clientId,
|
||||
clientSecret: conf.clientSecret,
|
||||
callbackURL: conf.callbackURL
|
||||
}, (accessToken, refreshToken, profile, cb) => {
|
||||
wiki.db.User.processProfile(profile).then((user) => {
|
||||
return cb(null, user) || true
|
||||
}).catch((err) => {
|
||||
return cb(err, null) || true
|
||||
})
|
||||
}
|
||||
))
|
||||
}
|
||||
}
|
32
server/extensions/logging/bugsnag.js
Normal file
32
server/extensions/logging/bugsnag.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const util = require('util')
|
||||
const winston = require('winston')
|
||||
const _ = require('lodash')
|
||||
|
||||
// ------------------------------------
|
||||
// Bugsnag
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'bugsnag',
|
||||
title: 'Bugsnag',
|
||||
props: ['key'],
|
||||
init (logger, conf) {
|
||||
let BugsnagLogger = winston.transports.BugsnagLogger = function (options) {
|
||||
this.name = 'bugsnagLogger'
|
||||
this.level = options.level || 'warn'
|
||||
this.bugsnag = require('bugsnag')
|
||||
this.bugsnag.register(options.key)
|
||||
}
|
||||
util.inherits(BugsnagLogger, winston.Transport)
|
||||
|
||||
BugsnagLogger.prototype.log = function (level, msg, meta, callback) {
|
||||
this.bugsnag.notify(new Error(msg), _.assignIn(meta, { severity: level }))
|
||||
callback(null, true)
|
||||
}
|
||||
|
||||
logger.add(BugsnagLogger, {
|
||||
level: 'warn',
|
||||
key: conf.key
|
||||
})
|
||||
}
|
||||
}
|
22
server/extensions/logging/console.js
Normal file
22
server/extensions/logging/console.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const winston = require('winston')
|
||||
|
||||
/* global wiki */
|
||||
|
||||
// ------------------------------------
|
||||
// Console
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'console',
|
||||
title: 'Console',
|
||||
props: [],
|
||||
init (logger, conf) {
|
||||
logger.add(winston.transports.Console, {
|
||||
level: wiki.config.logLevel,
|
||||
prettyPrint: true,
|
||||
colorize: true,
|
||||
silent: false,
|
||||
timestamp: true
|
||||
})
|
||||
}
|
||||
}
|
21
server/extensions/logging/loggly.js
Normal file
21
server/extensions/logging/loggly.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const winston = require('winston')
|
||||
|
||||
// ------------------------------------
|
||||
// Loggly
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'loggly',
|
||||
title: 'Loggly',
|
||||
props: ['token', 'subdomain'],
|
||||
init (logger, conf) {
|
||||
require('winston-loggly-bulk')
|
||||
logger.add(winston.transports.Loggly, {
|
||||
token: conf.token,
|
||||
subdomain: conf.subdomain,
|
||||
tags: ['wiki-js'],
|
||||
level: 'warn',
|
||||
json: true
|
||||
})
|
||||
}
|
||||
}
|
20
server/extensions/logging/papertrail.js
Normal file
20
server/extensions/logging/papertrail.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const winston = require('winston')
|
||||
|
||||
// ------------------------------------
|
||||
// Papertrail
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'papertrail',
|
||||
title: 'Papertrail',
|
||||
props: ['host', 'port'],
|
||||
init (logger, conf) {
|
||||
require('winston-papertrail').Papertrail // eslint-disable-line no-unused-expressions
|
||||
logger.add(winston.transports.Papertrail, {
|
||||
host: conf.host,
|
||||
port: conf.port,
|
||||
level: 'warn',
|
||||
program: 'wiki.js'
|
||||
})
|
||||
}
|
||||
}
|
32
server/extensions/logging/rollbar.js
Normal file
32
server/extensions/logging/rollbar.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const util = require('util')
|
||||
const winston = require('winston')
|
||||
const _ = require('lodash')
|
||||
|
||||
// ------------------------------------
|
||||
// Rollbar
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'rollbar',
|
||||
title: 'Rollbar',
|
||||
props: ['key'],
|
||||
init (logger, conf) {
|
||||
let RollbarLogger = winston.transports.RollbarLogger = function (options) {
|
||||
this.name = 'rollbarLogger'
|
||||
this.level = options.level || 'warn'
|
||||
this.rollbar = require('rollbar')
|
||||
this.rollbar.init(options.key)
|
||||
}
|
||||
util.inherits(RollbarLogger, winston.Transport)
|
||||
|
||||
RollbarLogger.prototype.log = function (level, msg, meta, callback) {
|
||||
this.rollbar.handleErrorWithPayloadData(new Error(msg), _.assignIn(meta, { level }))
|
||||
callback(null, true)
|
||||
}
|
||||
|
||||
logger.add(RollbarLogger, {
|
||||
level: 'warn',
|
||||
key: conf.key
|
||||
})
|
||||
}
|
||||
}
|
32
server/extensions/logging/sentry.js
Normal file
32
server/extensions/logging/sentry.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const util = require('util')
|
||||
const winston = require('winston')
|
||||
|
||||
// ------------------------------------
|
||||
// Sentry
|
||||
// ------------------------------------
|
||||
|
||||
module.exports = {
|
||||
key: 'sentry',
|
||||
title: 'Sentry',
|
||||
props: ['key'],
|
||||
init (logger, conf) {
|
||||
let SentryLogger = winston.transports.RollbarLogger = function (options) {
|
||||
this.name = 'sentryLogger'
|
||||
this.level = options.level || 'warn'
|
||||
this.raven = require('raven')
|
||||
this.raven.config(options.key).install()
|
||||
}
|
||||
util.inherits(SentryLogger, winston.Transport)
|
||||
|
||||
SentryLogger.prototype.log = function (level, msg, meta, callback) {
|
||||
level = (level === 'warn') ? 'warning' : level
|
||||
this.raven.captureMessage(msg, { level, extra: meta })
|
||||
callback(null, true)
|
||||
}
|
||||
|
||||
logger.add(SentryLogger, {
|
||||
level: 'warn',
|
||||
key: conf.key
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user