2014-05-08 06:33:46 -04:00
metrics = require ( " metrics-sharelatex " )
2014-02-12 05:23:40 -05:00
logger = require ( ' logger-sharelatex ' )
_ = require ( ' underscore ' )
2014-04-07 06:02:12 -04:00
User = require ( ' ../../models/User ' ) . User
Project = require ( ' ../../models/Project ' ) . Project
DocumentUpdaterHandler = require ( ' ../DocumentUpdater/DocumentUpdaterHandler ' )
2014-02-12 05:23:40 -05:00
Settings = require ( ' settings-sharelatex ' )
util = require ( ' util ' )
2014-04-07 06:02:12 -04:00
RecurlyWrapper = require ( ' ../Subscription/RecurlyWrapper ' )
SubscriptionHandler = require ( ' ../Subscription/SubscriptionHandler ' )
projectEntityHandler = require ( ' ../Project/ProjectEntityHandler ' )
2014-08-14 05:12:01 -04:00
TpdsUpdateSender = require ( " ../ThirdPartyDataStore/TpdsUpdateSender " )
2014-04-07 06:02:12 -04:00
EditorRealTimeController = require ( " ../Editor/EditorRealTimeController " )
2014-07-24 08:24:08 -04:00
SystemMessageManager = require ( " ../SystemMessages/SystemMessageManager " )
2014-02-12 05:23:40 -05:00
2014-05-08 06:33:46 -04:00
oneMinInMs = 60 * 1000
updateOpenConnetionsMetrics = ()->
metrics . gauge " open_connections.socketio " , require ( " ../../infrastructure/Server " ) . io ? . sockets ? . clients ( ) ? . length
metrics . gauge " open_connections.http " , _ . size ( require ( ' http ' ) . globalAgent ? . sockets )
metrics . gauge " open_connections.https " , _ . size ( require ( ' https ' ) . globalAgent ? . sockets )
setTimeout updateOpenConnetionsMetrics , oneMinInMs
setTimeout updateOpenConnetionsMetrics , oneMinInMs
2014-02-12 05:23:40 -05:00
module.exports = AdminController =
2014-07-24 08:24:08 -04:00
index : (req, res, next)=>
2014-02-12 05:23:40 -05:00
http = require ( ' http ' )
openSockets = { }
for url , agents of require ( ' http ' ) . globalAgent . sockets
openSockets [ " http:// #{ url } " ] = ( agent . _httpMessage . path for agent in agents )
for url , agents of require ( ' https ' ) . globalAgent . sockets
openSockets [ " https:// #{ url } " ] = ( agent . _httpMessage . path for agent in agents )
2014-07-24 08:24:08 -04:00
SystemMessageManager . getMessagesFromDB (error, systemMessages) ->
return next ( error ) if error ?
2015-03-19 10:22:48 -04:00
res . render ' admin/index ' ,
2014-07-24 08:24:08 -04:00
title: ' System Admin '
openSockets: openSockets
systemMessages: systemMessages
2015-03-19 10:22:48 -04:00
registerNewUser: (req, res, next) ->
res . render ' admin/register '
2014-02-12 05:23:40 -05:00
dissconectAllUsers: (req, res)=>
logger . warn " disconecting everyone "
EditorRealTimeController . emitToAll ' forceDisconnect ' , " Sorry, we are performing a quick update to the editor and need to close it down. Please refresh the page to continue. "
2015-07-08 11:56:38 -04:00
res . sendStatus ( 200 )
2014-02-12 05:23:40 -05:00
closeEditor : (req, res)->
logger . warn " closing editor "
Settings.editorIsOpen = req . body . isOpen
2015-07-08 11:56:38 -04:00
res . sendStatus ( 200 )
2014-02-12 05:23:40 -05:00
writeAllToMongo : (req, res)->
logger . log " writing all docs to mongo "
Settings.mongo.writeAll = true
DocumentUpdaterHandler . flushAllDocsToMongo ()->
logger . log " all docs have been saved to mongo "
res . send ( )
syncUserToSubscription: (req, res)->
{ user_id , subscription_id } = req . body
RecurlyWrapper . getSubscription subscription_id , { } , (err, subscription)->
User . findById user_id , (err, user)->
SubscriptionHandler . syncSubscriptionToUser subscription , user . _id , (err)->
logger . log user_id : user_id , subscription_id : subscription_id , " linked account to subscription "
res . send ( )
flushProjectToTpds: (req, res)->
projectEntityHandler . flushProjectToThirdPartyDataStore req . body . project_id , (err)->
2015-07-08 11:56:38 -04:00
res . sendStatus 200
2014-08-14 05:12:01 -04:00
pollDropboxForUser: (req, res)->
user_id = req . body . user_id
TpdsUpdateSender . pollDropboxForUser user_id , () ->
2015-07-08 11:56:38 -04:00
res . sendStatus 200
2014-07-24 08:24:08 -04:00
createMessage: (req, res, next) ->
SystemMessageManager . createMessage req . body . content , (error) ->
return next ( error ) if error ?
2015-07-08 11:56:38 -04:00
res . sendStatus 200
2014-07-24 08:24:08 -04:00
clearMessages: (req, res, next) ->
SystemMessageManager . clearMessages (error) ->
return next ( error ) if error ?
2015-07-08 11:56:38 -04:00
res . sendStatus 200