/*
* Makes possible the web user interface. Allows users to control the program
* using a web browser.
*/
package webserver;
import definitions.Messages;
import definitions.definition;
import main.core;
import script.Plugin;
import script.log;
import utils.html;
import www.WebRequest;
import www.WebServer;
/**
*
* @author Nuno Brito, 9th of January 2013 in Darmstadt, Germany.
*/
public class server extends Plugin{
// title for this plugin
private final String id = "Web server";
@Override
public void startup(){
// add our node to the tree right after the "Tools" node is added
log.hooks.addAction(Messages.AddingTools, thisFile, "addNode");
startServer();
}
/**
* Add our toolbox node to the treeview.
*/
public void addNode(){
addTreeNode(id, "network-clouds.png", "main");
}
/** Start our instance */
public void startServer(){
String status = settings.read("status", "offline");
// if we are supposed to be offline, don't start the server
if(status.equals("offline")){
return;
}
// let's kickoff the server
WebServer server = new WebServer();
String portNumber = settings.read("port", definition.portDefault);
server.startServer(portNumber);
core.temp.put("server", server);
}
/**
* Save the settings to disk
* @param request
*/
public void save(WebRequest request){
// save the info from our template for future use
templateSave(request);
// Let's see if we need to start our server
startServer();
// all done
String message = html.h3("Settings saved!");
request.setAnswer(utils.html.redirect("/webserver/server", 2, message));
}
/**
* Show the main page for the server settings
* @param request the request from the end-user
*/
@Override
public void main(WebRequest request){
templateLoad("serverSettings.html", request);
}
}