Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wiki-js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
wiki-js
Commits
c96e1c01
Commit
c96e1c01
authored
May 13, 2017
by
NGPixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: use of env vars anywhere in config files
parent
4da9c3d7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
42 deletions
+37
-42
config.docker.yml
config.docker.yml
+1
-3
data.yml
server/app/data.yml
+3
-4
auth.js
server/libs/auth.js
+8
-8
config.js
server/libs/config.js
+20
-20
auth.js
server/middlewares/auth.js
+5
-7
No files found.
config.docker.yml
View file @
c96e1c01
...
...
@@ -19,9 +19,8 @@ host: http://localhost
# ---------------------------------------------------------------------
# Port the main server should listen to (80 by default)
# ---------------------------------------------------------------------
# To use process.env.PORT, comment the line below:
# port: 80
port
:
$(PORT)
# ---------------------------------------------------------------------
# Data Directories
...
...
@@ -103,7 +102,6 @@ sessionSecret: 1234567890abcdefghijklmnopqrstuvxyz
# ---------------------------------------------------------------------
# Database Connection String
# ---------------------------------------------------------------------
# You can also use an ENV variable by using $ENV_VAR_NAME as the value
db
:
mongodb://mongo:27017/wiki
...
...
server/app/data.yml
View file @
c96e1c01
...
...
@@ -3,10 +3,6 @@
# This is reserved for system use!
# ---------------------------------
name
:
Wiki.js
capabilities
:
guest
:
true
rights
:
true
manyAuthProviders
:
true
defaults
:
config
:
title
:
Wiki
...
...
@@ -65,6 +61,9 @@ langs:
id
:
en
name
:
English
-
id
:
zh
name
:
Chinese - 普通话
-
id
:
fr
name
:
French - Français
-
...
...
server/libs/auth.js
View file @
c96e1c01
...
...
@@ -26,7 +26,7 @@ module.exports = function (passport) {
// Local Account
if
(
!
appdata
.
capabilities
.
manyAuthProviders
||
(
appconfig
.
auth
.
local
&&
appconfig
.
auth
.
local
.
enabled
)
)
{
if
(
appconfig
.
auth
.
local
&&
appconfig
.
auth
.
local
.
enabled
)
{
const
LocalStrategy
=
require
(
'passport-local'
).
Strategy
passport
.
use
(
'local'
,
new
LocalStrategy
({
...
...
@@ -53,7 +53,7 @@ module.exports = function (passport) {
// Google ID
if
(
app
data
.
capabilities
.
manyAuthProviders
&&
app
config
.
auth
.
google
&&
appconfig
.
auth
.
google
.
enabled
)
{
if
(
appconfig
.
auth
.
google
&&
appconfig
.
auth
.
google
.
enabled
)
{
const
GoogleStrategy
=
require
(
'passport-google-oauth20'
).
Strategy
passport
.
use
(
'google'
,
new
GoogleStrategy
({
...
...
@@ -73,7 +73,7 @@ module.exports = function (passport) {
// Microsoft Accounts
if
(
app
data
.
capabilities
.
manyAuthProviders
&&
app
config
.
auth
.
microsoft
&&
appconfig
.
auth
.
microsoft
.
enabled
)
{
if
(
appconfig
.
auth
.
microsoft
&&
appconfig
.
auth
.
microsoft
.
enabled
)
{
const
WindowsLiveStrategy
=
require
(
'passport-windowslive'
).
Strategy
passport
.
use
(
'windowslive'
,
new
WindowsLiveStrategy
({
...
...
@@ -93,7 +93,7 @@ module.exports = function (passport) {
// Facebook
if
(
app
data
.
capabilities
.
manyAuthProviders
&&
app
config
.
auth
.
facebook
&&
appconfig
.
auth
.
facebook
.
enabled
)
{
if
(
appconfig
.
auth
.
facebook
&&
appconfig
.
auth
.
facebook
.
enabled
)
{
const
FacebookStrategy
=
require
(
'passport-facebook'
).
Strategy
passport
.
use
(
'facebook'
,
new
FacebookStrategy
({
...
...
@@ -114,7 +114,7 @@ module.exports = function (passport) {
// GitHub
if
(
app
data
.
capabilities
.
manyAuthProviders
&&
app
config
.
auth
.
github
&&
appconfig
.
auth
.
github
.
enabled
)
{
if
(
appconfig
.
auth
.
github
&&
appconfig
.
auth
.
github
.
enabled
)
{
const
GitHubStrategy
=
require
(
'passport-github2'
).
Strategy
passport
.
use
(
'github'
,
new
GitHubStrategy
({
...
...
@@ -135,7 +135,7 @@ module.exports = function (passport) {
// Slack
if
(
app
data
.
capabilities
.
manyAuthProviders
&&
app
config
.
auth
.
slack
&&
appconfig
.
auth
.
slack
.
enabled
)
{
if
(
appconfig
.
auth
.
slack
&&
appconfig
.
auth
.
slack
.
enabled
)
{
const
SlackStrategy
=
require
(
'passport-slack'
).
Strategy
passport
.
use
(
'slack'
,
new
SlackStrategy
({
...
...
@@ -155,7 +155,7 @@ module.exports = function (passport) {
// LDAP
if
(
app
data
.
capabilities
.
manyAuthProviders
&&
app
config
.
auth
.
ldap
&&
appconfig
.
auth
.
ldap
.
enabled
)
{
if
(
appconfig
.
auth
.
ldap
&&
appconfig
.
auth
.
ldap
.
enabled
)
{
const
LdapStrategy
=
require
(
'passport-ldapauth'
).
Strategy
passport
.
use
(
'ldapauth'
,
new
LdapStrategy
({
...
...
@@ -189,7 +189,7 @@ module.exports = function (passport) {
// AZURE AD
if
(
app
data
.
capabilities
.
manyAuthProviders
&&
app
config
.
auth
.
azure
&&
appconfig
.
auth
.
azure
.
enabled
)
{
if
(
appconfig
.
auth
.
azure
&&
appconfig
.
auth
.
azure
.
enabled
)
{
const
AzureAdOAuth2Strategy
=
require
(
'passport-azure-ad-oauth2'
).
Strategy
const
jwt
=
require
(
'jsonwebtoken'
)
passport
.
use
(
'azure_ad_oauth2'
,
...
...
server/libs/config.js
View file @
c96e1c01
...
...
@@ -5,6 +5,15 @@ const yaml = require('js-yaml')
const
_
=
require
(
'lodash'
)
const
path
=
require
(
'path'
)
const
deepMap
=
(
obj
,
iterator
,
context
)
=>
{
return
_
.
transform
(
obj
,
(
result
,
val
,
key
)
=>
{
result
[
key
]
=
_
.
isObject
(
val
)
?
deepMap
(
val
,
iterator
,
context
)
:
iterator
.
call
(
context
,
val
,
key
,
obj
)
})
}
_
.
mixin
({
deepMap
})
/**
* Load Application Configuration
*
...
...
@@ -22,7 +31,9 @@ module.exports = (confPaths) => {
let
appdata
=
{}
try
{
appconfig
=
yaml
.
safeLoad
(
fs
.
readFileSync
(
confPaths
.
config
,
'utf8'
))
appconfig
=
yaml
.
safeLoad
(
_
.
deepMap
(
fs
.
readFileSync
(
confPaths
.
config
,
'utf8'
),
c
=>
{
return
_
.
replace
(
c
,
(
/
\$\([
A-Z0-9_
]
+
\)
/g
,
(
m
)
=>
{
return
process
.
env
[
m
]
}))
}))
appdata
=
yaml
.
safeLoad
(
fs
.
readFileSync
(
confPaths
.
data
,
'utf8'
))
appdata
.
regex
=
require
(
confPaths
.
dataRegex
)
}
catch
(
ex
)
{
...
...
@@ -34,32 +45,21 @@ module.exports = (confPaths) => {
appconfig
=
_
.
defaultsDeep
(
appconfig
,
appdata
.
defaults
.
config
)
//
Using ENV variables?
//
Check port
if
(
appconfig
.
port
<
1
)
{
appconfig
.
port
=
process
.
env
.
PORT
||
80
}
if
(
_
.
startsWith
(
appconfig
.
db
,
'$'
))
{
appconfig
.
db
=
process
.
env
[
appconfig
.
db
.
slice
(
1
)]
}
// List authentication strategies
if
(
appdata
.
capabilities
.
manyAuthProviders
)
{
appconfig
.
authStrategies
=
{
list
:
_
.
filter
(
appconfig
.
auth
,
[
'enabled'
,
true
]),
socialEnabled
:
(
_
.
chain
(
appconfig
.
auth
).
omit
(
'local'
).
filter
([
'enabled'
,
true
]).
value
().
length
>
0
)
}
if
(
appconfig
.
authStrategies
.
list
.
length
<
1
)
{
console
.
error
(
new
Error
(
'You must enable at least 1 authentication strategy!'
))
process
.
exit
(
1
)
}
}
else
{
appconfig
.
authStrategies
=
{
list
:
{
local
:
{
enabled
:
true
}
},
socialEnabled
:
false
}
appconfig
.
authStrategies
=
{
list
:
_
.
filter
(
appconfig
.
auth
,
[
'enabled'
,
true
]),
socialEnabled
:
(
_
.
chain
(
appconfig
.
auth
).
omit
(
'local'
).
filter
([
'enabled'
,
true
]).
value
().
length
>
0
)
}
if
(
appconfig
.
authStrategies
.
list
.
length
<
1
)
{
console
.
error
(
new
Error
(
'You must enable at least 1 authentication strategy!'
))
process
.
exit
(
1
)
}
return
{
...
...
server/middlewares/auth.js
View file @
c96e1c01
...
...
@@ -16,24 +16,22 @@ module.exports = (req, res, next) => {
// Is user authenticated ?
if
(
!
req
.
isAuthenticated
())
{
if
(
!
appdata
.
capabilities
.
guest
||
req
.
app
.
locals
.
appconfig
.
public
!==
true
)
{
if
(
req
.
app
.
locals
.
appconfig
.
public
!==
true
)
{
return
res
.
redirect
(
'/login'
)
}
else
{
req
.
user
=
rights
.
guest
res
.
locals
.
isGuest
=
true
}
}
else
if
(
appdata
.
capabilities
.
guest
)
{
}
else
{
res
.
locals
.
isGuest
=
false
}
// Check permissions
if
(
appdata
.
capabilities
.
rights
)
{
res
.
locals
.
rights
=
rights
.
check
(
req
)
res
.
locals
.
rights
=
rights
.
check
(
req
)
if
(
!
res
.
locals
.
rights
.
read
)
{
return
res
.
render
(
'error-forbidden'
)
}
if
(
!
res
.
locals
.
rights
.
read
)
{
return
res
.
render
(
'error-forbidden'
)
}
// Set i18n locale
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment