1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.remotecontrol;
|
---|
3 |
|
---|
4 | import java.io.File;
|
---|
5 | import java.net.InetAddress;
|
---|
6 | import java.net.UnknownHostException;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import org.openstreetmap.josm.data.preferences.BooleanProperty;
|
---|
10 | import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * Manager class for remote control operations.
|
---|
14 | *
|
---|
15 | * IMPORTANT! increment the minor version on compatible API extensions
|
---|
16 | * and increment the major version and set minor to 0 on incompatible changes.
|
---|
17 | */
|
---|
18 | public class RemoteControl {
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * If the remote control feature is enabled or disabled. If disabled,
|
---|
22 | * it should not start the server.
|
---|
23 | */
|
---|
24 | public static final BooleanProperty PROP_REMOTECONTROL_ENABLED = new BooleanProperty("remotecontrol.enabled", false);
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * If the remote control feature is enabled or disabled for HTTPS. If disabled,
|
---|
28 | * only HTTP access will be available.
|
---|
29 | * @since 7335
|
---|
30 | */
|
---|
31 | public static final BooleanProperty PROP_REMOTECONTROL_HTTPS_ENABLED = new BooleanProperty(
|
---|
32 | "remotecontrol.https.enabled", false);
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * RemoteControl HTTP protocol version. Change minor number for compatible
|
---|
36 | * interface extensions. Change major number in case of incompatible
|
---|
37 | * changes.
|
---|
38 | */
|
---|
39 | static final int protocolMajorVersion = 1;
|
---|
40 | static final int protocolMinorVersion = 7;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Starts the remote control server
|
---|
44 | */
|
---|
45 | public static void start() {
|
---|
46 | RemoteControlHttpServer.restartRemoteControlHttpServer();
|
---|
47 | RemoteControlHttpsServer.restartRemoteControlHttpsServer();
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Stops the remote control server
|
---|
52 | * @since 5861
|
---|
53 | */
|
---|
54 | public static void stop() {
|
---|
55 | RemoteControlHttpServer.stopRemoteControlHttpServer();
|
---|
56 | RemoteControlHttpsServer.stopRemoteControlHttpsServer();
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Adds external request handler.
|
---|
61 | * Can be used by plugins that want to use remote control.
|
---|
62 | *
|
---|
63 | * @param command The command name.
|
---|
64 | * @param handlerClass The additional request handler.
|
---|
65 | */
|
---|
66 | public void addRequestHandler(String command, Class<? extends RequestHandler> handlerClass) {
|
---|
67 | RequestProcessor.addRequestHandlerClass(command, handlerClass);
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Returns the remote control directory.
|
---|
72 | * @return The remote control directory
|
---|
73 | * @since 7335
|
---|
74 | */
|
---|
75 | public static String getRemoteControlDir() {
|
---|
76 | return new File(Main.pref.getUserDataDirectory(), "remotecontrol").getAbsolutePath();
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Returns the inet address used for remote control.
|
---|
81 | * @return the inet address used for remote control
|
---|
82 | * @throws UnknownHostException if the local host name could not be resolved into an address.
|
---|
83 | * @since 7800
|
---|
84 | */
|
---|
85 | public static InetAddress getInetAddress() throws UnknownHostException {
|
---|
86 | // Return an address to the loopback interface by default
|
---|
87 | return InetAddress.getByName(Main.pref.get("remote.control.host", null));
|
---|
88 | }
|
---|
89 | }
|
---|