forked from fedwiki/wiki-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecurity.js
More file actions
94 lines (82 loc) · 2.11 KB
/
security.js
File metadata and controls
94 lines (82 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Federated Wiki : Node Server
*
* Copyright Ward Cunningham and other contributors
* Licensed under the MIT license.
* https://github.com/fedwiki/wiki-node-server/blob/master/LICENSE.txt
*/
// **security.js**
// Module for default site security.
//
// This module is not intented for use, but is here to catch a problem with
// configuration of security. It does not provide any authentication, but will
// allow the server to run read-only.
// #### Requires ####
import fs from 'node:fs'
// Export a function that generates security handler
// when called with options object.
export default (log, loga, argv) => {
const security = {}
// #### Private utility methods. ####
const user = ''
let owner = ''
// save the admin user, and location of the identity file
const { admin, id: idFile } = argv
// #### Public stuff ####
security.authenticate_session = () => {
;(req, res, next) => {
// not possible to login, so always false
req.isAuthenticated = () => false
return next()
}
}
// Retrieve owner infomation from identity file in status directory
security.retrieveOwner = cb => {
fs.exists(idFile, exists => {
if (exists) {
fs.readFile(idFile, (err, data) => {
if (err) return cb(err)
owner += data
cb()
})
} else {
owner = ''
cb()
}
})
}
// Return the owners name
security.getOwner = () => {
let ownerName
if (!owner.name) {
ownerName = ''
} else {
ownerName = owner.name
}
return ownerName
}
security.getUser = req => {
return ''
}
security.isAuthorized = req => {
// nobody is authorized - everything is read-only
// unless legacy support, when unclaimed sites can be editted.
if (owner == '') {
if (argv.security_legacy) {
return true
} else {
return false
}
} else {
return false
}
}
// Wiki server admin
security.isAdmin = () => {
return false
}
security.defineRoutes = (app, cors, updateOwner) => {
// default security does not have any routes
}
return security
}