source: josm/trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControl.java@ 8339

Last change on this file since 8339 was 8339, checked in by stoecker, 9 years ago

fix #11409 - Remotecontrol on IPv6 and IPv4

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