Child: [r6] (diff)

Download this file

server.java    81 lines (67 with data), 2.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* 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);
}
}