Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
PUBLIC
/
surfer-okd
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 7af3d855
authored
6 years ago
by
Johannes Zellner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add webdav server for easier file access
1 parent
a7317b4b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
3 deletions
package-lock.json
package.json
server.js
src/auth.js
package-lock.json
View file @
7af3d85
This diff is collapsed.
Click to expand it.
package.json
View file @
7af3d85
...
...
@@ -45,7 +45,8 @@
"serve-index"
:
"^1.9.1"
,
"superagent"
:
"^1.7.2"
,
"underscore"
:
"^1.8.3"
,
"uuid"
:
"^3.2.1"
"uuid"
:
"^3.2.1"
,
"webdav-server"
:
"^2.4.6"
},
"devDependencies"
:
{
"expect.js"
:
"^0.3.1"
,
...
...
This diff is collapsed.
Click to expand it.
server.js
View file @
7af3d85
...
...
@@ -2,7 +2,6 @@
'use strict'
;
var
express
=
require
(
'express'
),
morgan
=
require
(
'morgan'
),
passport
=
require
(
'passport'
),
...
...
@@ -19,6 +18,7 @@ var express = require('express'),
mkdirp
=
require
(
'mkdirp'
),
auth
=
require
(
'./src/auth.js'
),
serveIndex
=
require
(
'serve-index'
),
webdav
=
require
(
'webdav-server'
).
v2
,
files
=
require
(
'./src/files.js'
)(
path
.
resolve
(
__dirname
,
process
.
argv
[
2
]
||
'files'
));
...
...
@@ -63,6 +63,15 @@ if (typeof config.folderListingEnabled === 'undefined') config.folderListingEnab
var
app
=
express
();
var
router
=
new
express
.
Router
();
var
webdavServer
=
new
webdav
.
WebDAVServer
({
requireAuthentification
:
true
,
httpAuthentication
:
new
webdav
.
HTTPBasicAuthentication
(
new
auth
.
WebdavUserManager
(),
'Cloudron Surfer'
)
});
webdavServer
.
setFileSystem
(
'/'
,
new
webdav
.
PhysicalFileSystem
(
ROOT_FOLDER
),
function
(
success
)
{
console
.
log
(
`Mounting
${
ROOT_FOLDER
}
as webdav resource`
,
success
);
});
var
multipart
=
multipart
({
maxFieldsSize
:
2
*
1024
,
limit
:
'512mb'
,
timeout
:
3
*
60
*
1000
});
router
.
post
(
'/api/login'
,
auth
.
login
);
...
...
@@ -78,6 +87,7 @@ router.get ('/api/healthcheck', function (req, res) { res.status(200).send();
app
.
use
(
morgan
(
'dev'
));
app
.
use
(
compression
());
app
.
use
(
webdav
.
extensions
.
express
(
'/webdav'
,
webdavServer
));
app
.
use
(
'/api'
,
bodyParser
.
json
());
app
.
use
(
'/api'
,
bodyParser
.
urlencoded
({
extended
:
false
,
limit
:
'100mb'
}));
app
.
use
(
'/api'
,
cookieParser
());
...
...
This diff is collapsed.
Click to expand it.
src/auth.js
View file @
7af3d85
...
...
@@ -9,7 +9,8 @@ var passport = require('passport'),
BearerStrategy
=
require
(
'passport-http-bearer'
).
Strategy
,
LdapStrategy
=
require
(
'passport-ldapjs'
).
Strategy
,
HttpError
=
require
(
'connect-lastmile'
).
HttpError
,
HttpSuccess
=
require
(
'connect-lastmile'
).
HttpSuccess
;
HttpSuccess
=
require
(
'connect-lastmile'
).
HttpSuccess
,
webdavErrors
=
require
(
'webdav-server'
).
v2
.
Errors
;
const
LOCAL_AUTH_FILE
=
path
.
resolve
(
process
.
env
.
LOCAL_AUTH_FILE
||
'./.users.json'
);
const
TOKENSTORE_FILE
=
path
.
resolve
(
process
.
env
.
TOKENSTORE_FILE
||
'./.tokens.json'
);
...
...
@@ -140,3 +141,39 @@ exports.logout = function (req, res, next) {
exports
.
getProfile
=
function
(
req
,
res
,
next
)
{
next
(
new
HttpSuccess
(
200
,
{
username
:
req
.
user
.
username
}));
};
// webdav usermanager
exports
.
WebdavUserManager
=
WebdavUserManager
;
// This implements the required interface only for the Basic Authentication for webdav-server
function
WebdavUserManager
()
{};
WebdavUserManager
.
prototype
.
getDefaultUser
=
function
(
callback
)
{
// this is only a dummy user, since we always require authentication
var
user
=
{
username
:
'DefaultUser'
,
password
:
null
,
isAdministrator
:
false
,
isDefaultUser
:
true
,
uid
:
'DefaultUser'
};
callback
(
user
);
};
WebdavUserManager
.
prototype
.
getUserByNamePassword
=
function
(
username
,
password
,
callback
)
{
var
users
=
safe
.
JSON
.
parse
(
safe
.
fs
.
readFileSync
(
LOCAL_AUTH_FILE
));
if
(
!
users
)
return
callback
(
webdavErrors
.
UserNotFound
);
if
(
!
users
[
username
])
return
callback
(
webdavErrors
.
UserNotFound
);
bcrypt
.
compare
(
password
,
users
[
username
].
passwordHash
,
function
(
error
,
valid
)
{
if
(
error
||
!
valid
)
return
callback
(
webdavErrors
.
UserNotFound
);
callback
(
null
,
{
username
:
username
,
isAdministrator
:
true
,
isDefaultUser
:
false
,
uid
:
username
});
});
};
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
Attach a file
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 post a comment