overleaf/services/web/app/coffee/router.coffee

225 lines
11 KiB
CoffeeScript
Raw Normal View History

AdminController = require('./Features/ServerAdmin/AdminController')
2014-06-20 12:17:24 -04:00
ErrorController = require('./Features/Errors/ErrorController')
ProjectController = require("./Features/Project/ProjectController")
2014-02-12 05:23:40 -05:00
ProjectApiController = require("./Features/Project/ProjectApiController")
SpellingController = require('./Features/Spelling/SpellingController')
SecurityManager = require('./managers/SecurityManager')
2014-02-12 05:23:40 -05:00
AuthorizationManager = require('./Features/Security/AuthorizationManager')
EditorController = require("./Features/Editor/EditorController")
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')
TemplatesRouter = require('./Features/Templates/TemplatesRouter')
2014-02-12 05:23:40 -05:00
AuthenticationController = require('./Features/Authentication/AuthenticationController')
TagsController = require("./Features/Tags/TagsController")
CollaboratorsRouter = require('./Features/Collaborators/CollaboratorsRouter')
UserInfoController = require('./Features/User/UserInfoController')
UserController = require("./Features/User/UserController")
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"
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")
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-08-13 12:26:18 -04:00
DropboxRouter = require "./Features/Dropbox/DropboxRouter"
dropboxHandler = require "./Features/Dropbox/DropboxHandler"
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')
2014-05-15 11:20:23 -04:00
2014-02-12 05:23:40 -05:00
logger = require("logger-sharelatex")
_ = require("underscore")
2014-02-12 05:23:40 -05:00
httpAuth = require('express').basicAuth (user, pass)->
isValid = Settings.httpAuthUsers[user] == pass
if !isValid
logger.err user:user, pass:pass, "invalid login details"
return isValid
module.exports = class Router
2015-02-05 11:37:37 -05:00
constructor: (app)->
2014-02-12 05:23:40 -05:00
app.use(app.router)
app.get '/login', UserPagesController.loginPage
2014-02-12 05:23:40 -05:00
app.post '/login', AuthenticationController.login
app.get '/logout', UserController.logout
app.get '/restricted', SecurityManager.restricted
2014-02-12 05:23:40 -05:00
app.get '/register', UserPagesController.registerPage
app.post '/register', UserController.register
2014-02-12 05:23:40 -05:00
EditorRouter.apply(app, httpAuth)
CollaboratorsRouter.apply(app)
2014-02-12 05:23:40 -05:00
SubscriptionRouter.apply(app)
UploadsRouter.apply(app)
2014-05-15 11:20:23 -04:00
PasswordResetRouter.apply(app)
2014-06-20 12:17:24 -04:00
StaticPagesRouter.apply(app)
TemplatesRouter.apply(app)
2014-08-13 12:26:18 -04:00
DropboxRouter.apply(app)
2014-09-08 09:19:24 -04:00
Modules.applyRouter(app)
2014-02-12 05:23:40 -05:00
2014-07-10 09:53:53 -04:00
app.get '/blog', BlogController.getIndexPage
2014-07-09 14:49:39 -04:00
app.get '/blog/*', BlogController.getPage
2014-02-12 05:23:40 -05:00
if Settings.enableSubscriptions
app.get '/user/bonus', AuthenticationController.requireLogin(), ReferalMiddleware.getUserReferalId, ReferalController.bonus
app.get '/user/settings', AuthenticationController.requireLogin(), UserPagesController.settingsPage
app.post '/user/settings', AuthenticationController.requireLogin(), UserController.updateUserSettings
app.post '/user/password/update', AuthenticationController.requireLogin(), UserController.changePassword
2014-05-15 11:20:23 -04:00
app.del '/user/newsletter/unsubscribe', AuthenticationController.requireLogin(), UserController.unsubscribe
app.del '/user', AuthenticationController.requireLogin(), UserController.deleteUser
2014-02-12 05:23:40 -05:00
app.get '/user/auth_token', AuthenticationController.requireLogin(), AuthenticationController.getAuthToken
app.get '/user/personal_info', AuthenticationController.requireLogin(allow_auth_token: true), UserInfoController.getLoggedInUsersPersonalInfo
app.get '/user/:user_id/personal_info', httpAuth, UserInfoController.getPersonalInfo
app.get '/project', AuthenticationController.requireLogin(), ProjectController.projectListPage
app.post '/project/new', AuthenticationController.requireLogin(), ProjectController.newProject
2014-04-28 12:47:47 -04:00
2015-02-04 10:05:26 -05:00
app.get '/Project/:Project_id', RateLimiterMiddlewear.rateLimit({
endpointName: "open-project"
params: ["Project_id"]
maxRequests: 10
timeInterval: 60
}), SecurityManager.requestCanAccessProject, ProjectController.loadEditor
app.get '/Project/:Project_id/file/:File_id', SecurityManager.requestCanAccessProject, FileStoreController.getFile
2014-02-12 05:23:40 -05:00
2014-06-25 08:51:02 -04:00
app.post '/project/:Project_id/settings', SecurityManager.requestCanModifyProject, ProjectController.updateProjectSettings
app.post '/project/:Project_id/compile', SecurityManager.requestCanAccessProject, CompileController.compile
app.get '/Project/:Project_id/output/output.pdf', SecurityManager.requestCanAccessProject, CompileController.downloadPdf
2014-02-12 05:23:40 -05:00
app.get /^\/project\/([^\/]*)\/output\/(.*)$/,
((req, res, next) ->
params =
"Project_id": req.params[0]
"file": req.params[1]
req.params = params
next()
), SecurityManager.requestCanAccessProject, CompileController.getFileFromClsi
app.del "/project/:Project_id/output", SecurityManager.requestCanAccessProject, CompileController.deleteAuxFiles
2014-04-08 11:49:21 -04:00
app.get "/project/:Project_id/sync/code", SecurityManager.requestCanAccessProject, CompileController.proxySync
app.get "/project/:Project_id/sync/pdf", SecurityManager.requestCanAccessProject, CompileController.proxySync
app.del '/Project/:Project_id', SecurityManager.requestIsOwner, ProjectController.deleteProject
app.post '/Project/:Project_id/restore', SecurityManager.requestIsOwner, ProjectController.restoreProject
app.post '/Project/:Project_id/clone', SecurityManager.requestCanAccessProject, ProjectController.cloneProject
2014-02-12 05:23:40 -05:00
2014-04-28 12:47:47 -04:00
app.post '/project/:Project_id/rename', SecurityManager.requestIsOwner, ProjectController.renameProject
app.get "/project/:Project_id/updates", SecurityManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi
app.get "/project/:Project_id/doc/:doc_id/diff", SecurityManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi
app.post "/project/:Project_id/doc/:doc_id/version/:version_id/restore", SecurityManager.requestCanAccessProject, TrackChangesController.proxyToTrackChangesApi
2014-03-05 11:31:52 -05:00
app.get '/Project/:Project_id/download/zip', SecurityManager.requestCanAccessProject, ProjectDownloadsController.downloadProject
app.get '/project/download/zip', SecurityManager.requestCanAccessMultipleProjects, ProjectDownloadsController.downloadMultipleProjects
2014-02-12 05:23:40 -05:00
app.get '/tag', AuthenticationController.requireLogin(), TagsController.getAllTags
app.post '/project/:project_id/tag', AuthenticationController.requireLogin(), TagsController.processTagsUpdate
app.get '/project/:project_id/details', httpAuth, ProjectApiController.getProjectDetails
app.get '/internal/project/:Project_id/zip', httpAuth, ProjectDownloadsController.downloadProject
app.get '/internal/project/:project_id/compile/pdf', httpAuth, CompileController.compileAndDownloadPdf
app.get '/project/:Project_id/doc/:doc_id', httpAuth, DocumentController.getDocument
app.post '/project/:Project_id/doc/:doc_id', httpAuth, DocumentController.setDocument
app.ignoreCsrf('post', '/project/:Project_id/doc/:doc_id')
app.post '/user/:user_id/update/*', httpAuth, TpdsController.mergeUpdate
2014-02-12 05:23:40 -05:00
app.del '/user/:user_id/update/*', httpAuth, TpdsController.deleteUpdate
app.ignoreCsrf('post', '/user/:user_id/update/*')
app.ignoreCsrf('delete', '/user/:user_id/update/*')
app.post '/project/:project_id/contents/*', httpAuth, TpdsController.updateProjectContents
app.del '/project/:project_id/contents/*', httpAuth, TpdsController.deleteProjectContents
app.ignoreCsrf('post', '/project/:project_id/contents/*')
app.ignoreCsrf('delete', '/project/:project_id/contents/*')
2014-02-12 05:23:40 -05:00
app.post "/spelling/check", AuthenticationController.requireLogin(), SpellingController.proxyRequestToSpellingApi
app.post "/spelling/learn", AuthenticationController.requireLogin(), SpellingController.proxyRequestToSpellingApi
2014-07-14 17:11:41 -04:00
app.get "/project/:Project_id/messages", SecurityManager.requestCanAccessProject, ChatController.getMessages
app.post "/project/:Project_id/messages", SecurityManager.requestCanAccessProject, ChatController.sendMessage
2014-07-30 10:44:03 -04:00
app.get /learn(\/.*)?/, WikiController.getPage
2014-02-12 05:23:40 -05:00
#Admin Stuff
app.get '/admin', SecurityManager.requestIsAdmin, AdminController.index
app.post '/admin/closeEditor', SecurityManager.requestIsAdmin, AdminController.closeEditor
app.post '/admin/dissconectAllUsers', SecurityManager.requestIsAdmin, AdminController.dissconectAllUsers
app.post '/admin/syncUserToSubscription', SecurityManager.requestIsAdmin, AdminController.syncUserToSubscription
app.post '/admin/flushProjectToTpds', SecurityManager.requestIsAdmin, AdminController.flushProjectToTpds
app.post '/admin/pollDropboxForUser', SecurityManager.requestIsAdmin, AdminController.pollDropboxForUser
2014-07-24 08:24:08 -04:00
app.post '/admin/messages', SecurityManager.requestIsAdmin, AdminController.createMessage
app.post '/admin/messages/clear', SecurityManager.requestIsAdmin, AdminController.clearMessages
2014-02-12 05:23:40 -05:00
app.get '/perfTest', (req,res)->
res.send("hello")
req.session.destroy()
app.get '/status', (req,res)->
res.send("websharelatex is up")
req.session.destroy()
app.get '/health_check', HealthCheckController.check
2014-11-19 18:18:20 -05:00
app.get '/health_check/redis', HealthCheckController.checkRedis
2014-02-12 05:23:40 -05:00
app.get "/status/compiler/:Project_id", SecurityManager.requestCanAccessProject, (req, res) ->
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", {}, () ->
sendRes 200, "Compiler returned in less than 10 seconds"
2014-02-12 05:23:40 -05:00
setTimeout (() ->
sendRes 500, "Compiler timed out"
2014-02-12 05:23:40 -05:00
), 10000
req.session.destroy()
app.get '/test', (req, res) ->
res.render "tests",
2014-04-07 15:46:58 -04:00
privilegeLevel: "owner"
2014-02-12 05:23:40 -05:00
project:
name: "test"
date: Date.now()
layout: false
userCanSeeDropbox: true
languages: []
app.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-02-12 05:23:40 -05:00
app.get '/oops-express', (req, res, next) -> next(new Error("Test error"))
app.get '/oops-internal', (req, res, next) -> throw new Error("Test error")
app.get '/oops-mongo', (req, res, next) ->
require("./models/Project").Project.findOne {}, () ->
throw new Error("Test error")
2014-09-18 09:37:23 -04:00
app.get '/opps-small', (req, res, next)->
logger.err "test error occured"
res.send()
app.post '/error/client', (req, res, next) ->
logger.error err: req.body.error, meta: req.body.meta, "client side error"
res.send(204)
2014-06-20 12:17:24 -04:00
app.get '*', ErrorController.notFound