2012-11-02 14:16:15 +01:00
var path = require ( 'path' ) ;
var eejs = require ( 'ep_etherpad-lite/node/eejs' ) ;
2012-11-06 17:35:52 +01:00
var settings = require ( 'ep_etherpad-lite/node/utils/Settings' ) ;
2012-11-02 14:16:15 +01:00
var installer = require ( 'ep_etherpad-lite/static/js/pluginfw/installer' ) ;
2012-11-02 16:21:12 +01:00
var hooks = require ( "ep_etherpad-lite/static/js/pluginfw/hooks" ) ;
2012-11-02 14:16:15 +01:00
var fs = require ( 'fs' ) ;
exports . expressCreateServer = function ( hook _name , args , cb ) {
args . app . get ( '/admin/settings' , function ( req , res ) {
var render _args = {
settings : "" ,
search _results : { } ,
errors : [ ]
} ;
res . send ( eejs . require ( "ep_etherpad-lite/templates/admin/settings.html" , render _args ) ) ;
} ) ;
}
exports . socketio = function ( hook _name , args , cb ) {
var io = args . io . of ( "/settings" ) ;
io . on ( 'connection' , function ( socket ) {
2014-11-18 15:12:02 +01:00
2014-11-18 15:56:40 +01:00
console . warn ( "The middleware now handles auth but I'm not convinced SocketIO is being responsible enough here so this needs reviewing before hitting master" ) ;
// if (!socket.handshake.session || !socket.handshake.session.user || !socket.handshake.session.user.is_admin) return;
2012-11-02 14:16:15 +01:00
socket . on ( "load" , function ( query ) {
fs . readFile ( 'settings.json' , 'utf8' , function ( err , data ) {
if ( err ) {
return console . log ( err ) ;
}
else
{
socket . emit ( "settings" , { results : data } ) ;
}
} ) ;
} ) ;
2012-11-02 16:10:01 +01:00
socket . on ( "saveSettings" , function ( settings ) {
fs . writeFile ( 'settings.json' , settings , function ( err ) {
if ( err ) throw err ;
socket . emit ( "saveprogress" , "saved" ) ;
2012-11-02 14:16:15 +01:00
} ) ;
} ) ;
2012-11-02 16:21:12 +01:00
socket . on ( "restartServer" , function ( ) {
console . log ( "Admin request to restart server through a socket on /admin/settings" ) ;
2012-11-06 17:35:52 +01:00
settings . reloadSettings ( ) ;
2012-11-02 16:21:12 +01:00
hooks . aCallAll ( "restartServer" , { } , function ( ) { } ) ;
2012-11-02 14:16:15 +01:00
} ) ;
2012-11-02 16:21:12 +01:00
2012-11-02 14:16:15 +01:00
} ) ;
}