2014-04-07 06:02:12 -04:00
|
|
|
AdminController = require('./Features/ServerAdmin/AdminController')
|
2014-06-20 12:17:24 -04:00
|
|
|
ErrorController = require('./Features/Errors/ErrorController')
|
2014-04-08 09:34:03 -04:00
|
|
|
ProjectController = require("./Features/Project/ProjectController")
|
2014-02-12 05:23:40 -05:00
|
|
|
ProjectApiController = require("./Features/Project/ProjectApiController")
|
|
|
|
SpellingController = require('./Features/Spelling/SpellingController')
|
2014-03-27 13:00:41 -04:00
|
|
|
SecurityManager = require('./managers/SecurityManager')
|
2014-02-12 05:23:40 -05:00
|
|
|
AuthorizationManager = require('./Features/Security/AuthorizationManager')
|
|
|
|
EditorController = require("./Features/Editor/EditorController")
|
2014-11-06 06:53:59 -05:00
|
|
|
EditorRouter = require("./Features/Editor/EditorRouter")
|
2014-02-12 05:23:40 -05:00
|
|
|
Settings = require('settings-sharelatex')
|
|
|
|
TpdsController = require('./Features/ThirdPartyDataStore/TpdsController')
|
|
|
|
SubscriptionRouter = require './Features/Subscription/SubscriptionRouter'
|
|
|
|
UploadsRouter = require './Features/Uploads/UploadsRouter'
|
|
|
|
metrics = require('./infrastructure/Metrics')
|
|
|
|
ReferalController = require('./Features/Referal/ReferalController')
|
|
|
|
ReferalMiddleware = require('./Features/Referal/ReferalMiddleware')
|
|
|
|
AuthenticationController = require('./Features/Authentication/AuthenticationController')
|
|
|
|
TagsController = require("./Features/Tags/TagsController")
|
2014-11-06 07:20:45 -05:00
|
|
|
CollaboratorsRouter = require('./Features/Collaborators/CollaboratorsRouter')
|
2014-04-09 09:45:46 -04:00
|
|
|
UserInfoController = require('./Features/User/UserInfoController')
|
2014-04-10 12:29:46 -04:00
|
|
|
UserController = require("./Features/User/UserController")
|
2014-04-09 07:17:50 -04:00
|
|
|
UserPagesController = require('./Features/User/UserPagesController')
|
2014-02-12 05:23:40 -05:00
|
|
|
DocumentController = require('./Features/Documents/DocumentController')
|
|
|
|
CompileManager = require("./Features/Compile/CompileManager")
|
|
|
|
CompileController = require("./Features/Compile/CompileController")
|
|
|
|
HealthCheckController = require("./Features/HealthCheck/HealthCheckController")
|
|
|
|
ProjectDownloadsController = require "./Features/Downloads/ProjectDownloadsController"
|
2014-02-20 17:33:12 -05:00
|
|
|
FileStoreController = require("./Features/FileStore/FileStoreController")
|
2014-03-05 11:31:52 -05:00
|
|
|
TrackChangesController = require("./Features/TrackChanges/TrackChangesController")
|
2014-05-15 11:20:23 -04:00
|
|
|
PasswordResetRouter = require("./Features/PasswordReset/PasswordResetRouter")
|
2014-06-20 12:17:24 -04:00
|
|
|
StaticPagesRouter = require("./Features/StaticPages/StaticPagesRouter")
|
2014-07-08 05:08:38 -04:00
|
|
|
ChatController = require("./Features/Chat/ChatController")
|
2014-07-09 14:49:39 -04:00
|
|
|
BlogController = require("./Features/Blog/BlogController")
|
2014-07-30 10:44:03 -04:00
|
|
|
WikiController = require("./Features/Wiki/WikiController")
|
2014-09-08 09:19:24 -04:00
|
|
|
Modules = require "./infrastructure/Modules"
|
2015-02-04 10:05:26 -05:00
|
|
|
RateLimiterMiddlewear = require('./Features/Security/RateLimiterMiddlewear')
|
2015-03-09 10:09:09 -04:00
|
|
|
RealTimeProxyRouter = require('./Features/RealTimeProxy/RealTimeProxyRouter')
|
2015-08-13 17:50:39 -04:00
|
|
|
InactiveProjectController = require("./Features/InactiveData/InactiveProjectController")
|
2015-10-07 12:32:35 -04:00
|
|
|
ContactRouter = require("./Features/Contacts/ContactRouter")
|
2015-12-17 06:51:14 -05:00
|
|
|
ReferencesSearchController = require('./Features/ReferencesSearch/ReferencesSearchController')
|
2014-05-15 11:20:23 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
logger = require("logger-sharelatex")
|
2014-03-12 17:56:58 -04:00
|
|
|
_ = require("underscore")
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
module.exports = class Router
|
2015-06-30 09:38:32 -04:00
|
|
|
constructor: (webRouter, apiRouter)->
|
2015-04-15 06:14:38 -04:00
|
|
|
if !Settings.allowPublicAccess
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.all '*', AuthenticationController.requireGlobalLogin
|
2015-04-15 06:14:38 -04:00
|
|
|
|
2015-12-17 06:51:14 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/login', UserPagesController.loginPage
|
2015-04-15 06:14:38 -04:00
|
|
|
AuthenticationController.addEndpointToLoginWhitelist '/login'
|
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.post '/login', AuthenticationController.login
|
|
|
|
webRouter.get '/logout', UserController.logout
|
|
|
|
webRouter.get '/restricted', SecurityManager.restricted
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-03-19 10:22:48 -04:00
|
|
|
# Left as a placeholder for implementing a public register page
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/register', UserPagesController.registerPage
|
2015-04-15 06:14:38 -04:00
|
|
|
AuthenticationController.addEndpointToLoginWhitelist '/register'
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
|
|
|
|
EditorRouter.apply(webRouter, apiRouter)
|
|
|
|
CollaboratorsRouter.apply(webRouter, apiRouter)
|
|
|
|
SubscriptionRouter.apply(webRouter, apiRouter)
|
|
|
|
UploadsRouter.apply(webRouter, apiRouter)
|
|
|
|
PasswordResetRouter.apply(webRouter, apiRouter)
|
|
|
|
StaticPagesRouter.apply(webRouter, apiRouter)
|
|
|
|
RealTimeProxyRouter.apply(webRouter, apiRouter)
|
2015-10-07 12:32:35 -04:00
|
|
|
ContactRouter.apply(webRouter, apiRouter)
|
2015-12-17 06:51:14 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
Modules.applyRouter(webRouter, apiRouter)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2014-07-09 14:49:39 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
if Settings.enableSubscriptions
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/user/bonus', AuthenticationController.requireLogin(), ReferalMiddleware.getUserReferalId, ReferalController.bonus
|
2015-12-17 06:51:14 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/blog', BlogController.getIndexPage
|
|
|
|
webRouter.get '/blog/*', BlogController.getPage
|
2015-12-17 06:51:14 -05:00
|
|
|
|
2015-12-11 06:30:06 -05:00
|
|
|
webRouter.get '/user/activate', UserPagesController.activateAccountPage
|
2015-12-17 06:51:14 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/user/settings', AuthenticationController.requireLogin(), UserPagesController.settingsPage
|
|
|
|
webRouter.post '/user/settings', AuthenticationController.requireLogin(), UserController.updateUserSettings
|
|
|
|
webRouter.post '/user/password/update', AuthenticationController.requireLogin(), UserController.changePassword
|
2014-05-15 11:20:23 -04:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.delete '/user/newsletter/unsubscribe', AuthenticationController.requireLogin(), UserController.unsubscribe
|
|
|
|
webRouter.delete '/user', AuthenticationController.requireLogin(), UserController.deleteUser
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/user/auth_token', AuthenticationController.requireLogin(), AuthenticationController.getAuthToken
|
|
|
|
webRouter.get '/user/personal_info', AuthenticationController.requireLogin(allow_auth_token: true), UserInfoController.getLoggedInUsersPersonalInfo
|
|
|
|
apiRouter.get '/user/:user_id/personal_info', AuthenticationController.httpAuth, UserInfoController.getPersonalInfo
|
2014-06-10 17:26:43 -04:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/project', AuthenticationController.requireLogin(), ProjectController.projectListPage
|
|
|
|
webRouter.post '/project/new', AuthenticationController.requireLogin(), ProjectController.newProject
|
2014-04-28 12:47:47 -04:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/Project/:Project_id', RateLimiterMiddlewear.rateLimit({
|
2015-02-04 10:05:26 -05:00
|
|
|
endpointName: "open-project"
|
|
|
|
params: ["Project_id"]
|
|
|
|
maxRequests: 10
|
|
|
|
timeInterval: 60
|
|
|
|
}), SecurityManager.requestCanAccessProject, ProjectController.loadEditor
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/Project/:Project_id/file/:File_id', SecurityManager.requestCanAccessProject, FileStoreController.getFile
|
|
|
|
webRouter.post '/project/:Project_id/settings', SecurityManager.requestCanModifyProject, ProjectController.updateProjectSettings
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.post '/project/:Project_id/compile', SecurityManager.requestCanAccessProject, CompileController.compile
|
|
|
|
webRouter.get '/Project/:Project_id/output/output.pdf', SecurityManager.requestCanAccessProject, CompileController.downloadPdf
|
|
|
|
webRouter.get /^\/project\/([^\/]*)\/output\/(.*)$/,
|
2014-02-12 05:23:40 -05:00
|
|
|
((req, res, next) ->
|
|
|
|
params =
|
|
|
|
"Project_id": req.params[0]
|
|
|
|
"file": req.params[1]
|
|
|
|
req.params = params
|
|
|
|
next()
|
2014-03-27 13:00:41 -04:00
|
|
|
), SecurityManager.requestCanAccessProject, CompileController.getFileFromClsi
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.delete "/project/:Project_id/output", SecurityManager.requestCanAccessProject, CompileController.deleteAuxFiles
|
|
|
|
webRouter.get "/project/:Project_id/sync/code", SecurityManager.requestCanAccessProject, CompileController.proxySync
|
|
|
|
webRouter.get "/project/:Project_id/sync/pdf", SecurityManager.requestCanAccessProject, CompileController.proxySync
|
2015-09-10 11:41:48 -04:00
|
|
|
webRouter.get "/project/:Project_id/wordcount", SecurityManager.requestCanAccessProject, CompileController.wordCount
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.delete '/Project/:Project_id', SecurityManager.requestIsOwner, ProjectController.deleteProject
|
|
|
|
webRouter.post '/Project/:Project_id/restore', SecurityManager.requestIsOwner, ProjectController.restoreProject
|
|
|
|
webRouter.post '/Project/:Project_id/clone', SecurityManager.requestCanAccessProject, ProjectController.cloneProject
|
2014-04-28 12:47:47 -04:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.post '/project/:Project_id/rename', SecurityManager.requestIsOwner, ProjectController.renameProject
|
2014-03-05 11:31:52 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get "/project/:Project_id/updates", SecurityManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi
|
|
|
|
webRouter.get "/project/:Project_id/doc/:doc_id/diff", SecurityManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi
|
|
|
|
webRouter.post "/project/:Project_id/doc/:doc_id/version/:version_id/restore", SecurityManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/Project/:Project_id/download/zip', SecurityManager.requestCanAccessProject, ProjectDownloadsController.downloadProject
|
|
|
|
webRouter.get '/project/download/zip', SecurityManager.requestCanAccessMultipleProjects, ProjectDownloadsController.downloadMultipleProjects
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/tag', AuthenticationController.requireLogin(), TagsController.getAllTags
|
|
|
|
webRouter.post '/project/:project_id/tag', AuthenticationController.requireLogin(), TagsController.processTagsUpdate
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
# Deprecated in favour of /internal/project/:project_id but still used by versioning
|
|
|
|
apiRouter.get '/project/:project_id/details', AuthenticationController.httpAuth, ProjectApiController.getProjectDetails
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
# New 'stable' /internal API end points
|
|
|
|
apiRouter.get '/internal/project/:project_id', AuthenticationController.httpAuth, ProjectApiController.getProjectDetails
|
|
|
|
apiRouter.get '/internal/project/:Project_id/zip', AuthenticationController.httpAuth, ProjectDownloadsController.downloadProject
|
2015-07-08 08:29:10 -04:00
|
|
|
apiRouter.get '/internal/project/:project_id/compile/pdf', AuthenticationController.httpAuth, CompileController.compileAndDownloadPdf
|
|
|
|
|
2015-08-14 06:26:11 -04:00
|
|
|
apiRouter.post '/internal/deactivateOldProjects', AuthenticationController.httpAuth, InactiveProjectController.deactivateOldProjects
|
|
|
|
apiRouter.post '/internal/project/:project_id/deactivate', AuthenticationController.httpAuth, InactiveProjectController.deactivateProject
|
2015-08-13 17:50:39 -04:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get /^\/internal\/project\/([^\/]*)\/output\/(.*)$/,
|
|
|
|
((req, res, next) ->
|
|
|
|
params =
|
|
|
|
"Project_id": req.params[0]
|
|
|
|
"file": req.params[1]
|
|
|
|
req.params = params
|
|
|
|
next()
|
|
|
|
), AuthenticationController.httpAuth, CompileController.getFileFromClsi
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
apiRouter.get '/project/:Project_id/doc/:doc_id', AuthenticationController.httpAuth, DocumentController.getDocument
|
|
|
|
apiRouter.post '/project/:Project_id/doc/:doc_id', AuthenticationController.httpAuth, DocumentController.setDocument
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
apiRouter.post '/user/:user_id/update/*', AuthenticationController.httpAuth, TpdsController.mergeUpdate
|
|
|
|
apiRouter.delete '/user/:user_id/update/*', AuthenticationController.httpAuth, TpdsController.deleteUpdate
|
2015-12-17 06:51:14 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
apiRouter.post '/project/:project_id/contents/*', AuthenticationController.httpAuth, TpdsController.updateProjectContents
|
|
|
|
apiRouter.delete '/project/:project_id/contents/*', AuthenticationController.httpAuth, TpdsController.deleteProjectContents
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.post "/spelling/check", AuthenticationController.requireLogin(), SpellingController.proxyRequestToSpellingApi
|
|
|
|
webRouter.post "/spelling/learn", AuthenticationController.requireLogin(), SpellingController.proxyRequestToSpellingApi
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get "/project/:Project_id/messages", SecurityManager.requestCanAccessProject, ChatController.getMessages
|
|
|
|
webRouter.post "/project/:Project_id/messages", SecurityManager.requestCanAccessProject, ChatController.sendMessage
|
2015-12-17 06:51:14 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get /learn(\/.*)?/, WikiController.getPage
|
2014-07-08 05:08:38 -04:00
|
|
|
|
2015-12-17 06:51:14 -05:00
|
|
|
webRouter.post "/project/:Project_id/references", SecurityManager.requestCanAccessProject, ReferencesSearchController.indexFile
|
2015-12-18 11:00:24 -05:00
|
|
|
webRouter.get "/project/:Project_id/references/keys", SecurityManager.requestCanAccessProject, ReferencesSearchController.getKeys
|
2015-12-17 06:51:14 -05:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
#Admin Stuff
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/admin', SecurityManager.requestIsAdmin, AdminController.index
|
2015-09-16 07:17:58 -04:00
|
|
|
webRouter.get '/admin/user', SecurityManager.requestIsAdmin, (req, res)-> res.redirect("/admin/register") #this gets removed by admin-panel addon
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/admin/register', SecurityManager.requestIsAdmin, AdminController.registerNewUser
|
|
|
|
webRouter.post '/admin/register', SecurityManager.requestIsAdmin, UserController.register
|
|
|
|
webRouter.post '/admin/closeEditor', SecurityManager.requestIsAdmin, AdminController.closeEditor
|
|
|
|
webRouter.post '/admin/dissconectAllUsers', SecurityManager.requestIsAdmin, AdminController.dissconectAllUsers
|
|
|
|
webRouter.post '/admin/syncUserToSubscription', SecurityManager.requestIsAdmin, AdminController.syncUserToSubscription
|
|
|
|
webRouter.post '/admin/flushProjectToTpds', SecurityManager.requestIsAdmin, AdminController.flushProjectToTpds
|
|
|
|
webRouter.post '/admin/pollDropboxForUser', SecurityManager.requestIsAdmin, AdminController.pollDropboxForUser
|
|
|
|
webRouter.post '/admin/messages', SecurityManager.requestIsAdmin, AdminController.createMessage
|
|
|
|
webRouter.post '/admin/messages/clear', SecurityManager.requestIsAdmin, AdminController.clearMessages
|
|
|
|
|
|
|
|
apiRouter.get '/perfTest', (req,res)->
|
2014-02-12 05:23:40 -05:00
|
|
|
res.send("hello")
|
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
apiRouter.get '/status', (req,res)->
|
2014-02-12 05:23:40 -05:00
|
|
|
res.send("websharelatex is up")
|
2015-12-17 06:51:14 -05:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '/health_check', HealthCheckController.check
|
|
|
|
webRouter.get '/health_check/redis', HealthCheckController.checkRedis
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
apiRouter.get "/status/compiler/:Project_id", SecurityManager.requestCanAccessProject, (req, res) ->
|
2014-03-12 17:56:58 -04:00
|
|
|
sendRes = _.once (statusCode, message)->
|
|
|
|
res.writeHead statusCode
|
|
|
|
res.end message
|
2014-02-12 05:23:40 -05:00
|
|
|
CompileManager.compile req.params.Project_id, "test-compile", {}, () ->
|
2014-03-12 17:56:58 -04:00
|
|
|
sendRes 200, "Compiler returned in less than 10 seconds"
|
2014-02-12 05:23:40 -05:00
|
|
|
setTimeout (() ->
|
2014-03-12 17:56:58 -04:00
|
|
|
sendRes 500, "Compiler timed out"
|
2014-02-12 05:23:40 -05:00
|
|
|
), 10000
|
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
apiRouter.get "/ip", (req, res, next) ->
|
2014-06-25 06:06:04 -04:00
|
|
|
res.send({
|
|
|
|
ip: req.ip
|
|
|
|
ips: req.ips
|
|
|
|
headers: req.headers
|
|
|
|
})
|
2014-06-25 05:34:23 -04:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
apiRouter.get '/oops-express', (req, res, next) -> next(new Error("Test error"))
|
|
|
|
apiRouter.get '/oops-internal', (req, res, next) -> throw new Error("Test error")
|
|
|
|
apiRouter.get '/oops-mongo', (req, res, next) ->
|
2014-02-12 05:23:40 -05:00
|
|
|
require("./models/Project").Project.findOne {}, () ->
|
|
|
|
throw new Error("Test error")
|
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
apiRouter.get '/opps-small', (req, res, next)->
|
2014-09-18 09:37:23 -04:00
|
|
|
logger.err "test error occured"
|
|
|
|
res.send()
|
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.post '/error/client', (req, res, next) ->
|
2014-03-14 07:14:02 -04:00
|
|
|
logger.error err: req.body.error, meta: req.body.meta, "client side error"
|
2015-07-08 11:56:38 -04:00
|
|
|
res.sendStatus(204)
|
2014-03-14 07:14:02 -04:00
|
|
|
|
2015-06-30 09:38:32 -04:00
|
|
|
webRouter.get '*', ErrorController.notFound
|