source: josm/trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java@ 7337

Last change on this file since 7337 was 7335, checked in by Don-vip, 10 years ago

see #10230, see #10033 - big rework of HTTPS support for Remote Control:

  • HTTPS disabled by default, must be enabled in remote control preferences
  • Old certificate and private key removed from jar and Windows keystore if found, even if remote control disabled
  • New certificate generated at runtime with critical X509 extensions BasicConstraints (non-CA certificate), ExtendedKeyUsage (usage restriction for TLS server sessions)
  • New passwords generated at runtime (but stored in clear in user preferences)
  • Private key is no longer stored in Windows keystore (only certificate)
  • Property svn:eol-style set to native
File size: 8.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.Dimension;
8import java.awt.event.ActionEvent;
9import java.awt.event.KeyEvent;
10import java.lang.management.ManagementFactory;
11import java.util.ArrayList;
12import java.util.Arrays;
13import java.util.HashSet;
14import java.util.List;
15import java.util.ListIterator;
16import java.util.Map;
17import java.util.Map.Entry;
18import java.util.Set;
19
20import javax.swing.JScrollPane;
21
22import org.openstreetmap.josm.Main;
23import org.openstreetmap.josm.data.Preferences.Setting;
24import org.openstreetmap.josm.data.Version;
25import org.openstreetmap.josm.data.osm.DataSet;
26import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
27import org.openstreetmap.josm.gui.ExtendedDialog;
28import org.openstreetmap.josm.gui.widgets.JosmTextArea;
29import org.openstreetmap.josm.plugins.PluginHandler;
30import org.openstreetmap.josm.tools.BugReportExceptionHandler;
31import org.openstreetmap.josm.tools.OpenBrowser;
32import org.openstreetmap.josm.tools.PlatformHookUnixoid;
33import org.openstreetmap.josm.tools.Shortcut;
34import org.openstreetmap.josm.tools.Utils;
35
36/**
37 * @author xeen
38 *
39 * Opens a dialog with useful status information like version numbers for Java, JOSM and plugins
40 * Also includes preferences with stripped username and password
41 */
42public final class ShowStatusReportAction extends JosmAction {
43
44 /**
45 * Constructs a new {@code ShowStatusReportAction}
46 */
47 public ShowStatusReportAction() {
48 super(
49 tr("Show Status Report"),
50 "clock",
51 tr("Show status report with useful information that can be attached to bugs"),
52 Shortcut.registerShortcut("help:showstatusreport", tr("Help: {0}",
53 tr("Show Status Report")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false);
54
55 putValue("help", ht("/Action/ShowStatusReport"));
56 putValue("toolbar", "help/showstatusreport");
57 Main.toolbar.register(this);
58 }
59
60 private static void shortenParam(ListIterator<String> it, String[] param, String source, String target) {
61 if (source != null && target.length() < source.length() && param[1].startsWith(source)) {
62 it.set(param[0] + "=" + param[1].replace(source, target));
63 }
64 }
65
66 /**
67 * Replies the report header (software and system info)
68 * @return The report header (software and system info)
69 */
70 public static String getReportHeader() {
71 StringBuilder text = new StringBuilder();
72 text.append(Version.getInstance().getReleaseAttributes());
73 text.append("\n");
74 text.append("Identification: " + Version.getInstance().getAgentString());
75 text.append("\n");
76 text.append("Memory Usage: ");
77 text.append(Runtime.getRuntime().totalMemory()/1024/1024);
78 text.append(" MB / ");
79 text.append(Runtime.getRuntime().maxMemory()/1024/1024);
80 text.append(" MB (");
81 text.append(Runtime.getRuntime().freeMemory()/1024/1024);
82 text.append(" MB allocated, but free)");
83 text.append("\n");
84 text.append("Java version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + ", " + System.getProperty("java.vm.name"));
85 text.append("\n");
86 if (Main.platform.getClass() == PlatformHookUnixoid.class) {
87 // Add Java package details
88 String packageDetails = ((PlatformHookUnixoid) Main.platform).getJavaPackageDetails();
89 if (packageDetails != null) {
90 text.append("Java package: ");
91 text.append(packageDetails);
92 text.append("\n");
93 }
94 // Add WebStart package details if run from JNLP
95 if (Package.getPackage("javax.jnlp") != null) {
96 String webStartDetails = ((PlatformHookUnixoid) Main.platform).getWebStartPackageDetails();
97 if (webStartDetails != null) {
98 text.append("WebStart package: ");
99 text.append(webStartDetails);
100 text.append("\n");
101 }
102 }
103 }
104 try {
105 final String envJavaHome = System.getenv("JAVA_HOME");
106 final String envJavaHomeAlt = Main.isPlatformWindows() ? "%JAVA_HOME%" : "${JAVA_HOME}";
107 final String propJavaHome = System.getProperty("java.home");
108 final String propJavaHomeAlt = "<java.home>";
109 // Build a new list of VM parameters to modify it below if needed (default implementation returns an UnmodifiableList instance)
110 List<String> vmArguments = new ArrayList<>(ManagementFactory.getRuntimeMXBean().getInputArguments());
111 for (ListIterator<String> it = vmArguments.listIterator(); it.hasNext(); ) {
112 String value = it.next();
113 if (value.contains("=")) {
114 String[] param = value.split("=");
115 // Hide some parameters for privacy concerns
116 if (param[0].toLowerCase().startsWith("-dproxy")) {
117 it.set(param[0]+"=xxx");
118 // Shorten some parameters for readability concerns
119 } else {
120 shortenParam(it, param, envJavaHome, envJavaHomeAlt);
121 shortenParam(it, param, propJavaHome, propJavaHomeAlt);
122 }
123 }
124 }
125 if (!vmArguments.isEmpty()) {
126 text.append("VM arguments: "+ vmArguments.toString().replace("\\\\", "\\"));
127 text.append("\n");
128 }
129 } catch (SecurityException e) {
130 // Ignore exception
131 }
132 if (Main.commandLineArgs.length > 0) {
133 text.append("Program arguments: "+ Arrays.toString(Main.commandLineArgs));
134 text.append("\n");
135 }
136 if (Main.main != null) {
137 DataSet dataset = Main.main.getCurrentDataSet();
138 if (dataset != null) {
139 String result = DatasetConsistencyTest.runTests(dataset);
140 if (result.length() == 0) {
141 text.append("Dataset consistency test: No problems found\n");
142 } else {
143 text.append("\nDataset consistency test:\n"+result+"\n");
144 }
145 }
146 }
147 text.append("\n");
148 text.append(PluginHandler.getBugReportText());
149 text.append("\n");
150
151 return text.toString();
152 }
153
154 @Override
155 public void actionPerformed(ActionEvent e) {
156 StringBuilder text = new StringBuilder();
157 String reportHeader = getReportHeader();
158 text.append(reportHeader);
159 try {
160 Map<String, Setting<?>> settings = Main.pref.getAllSettings();
161 Set<String> keys = new HashSet<>(settings.keySet());
162 for (String key : keys) {
163 // Remove sensitive information from status report
164 if (key.startsWith("marker.show") || key.contains("username") || key.contains("password") || key.contains("access-token")) {
165 settings.remove(key);
166 }
167 }
168 for (Entry<String, Setting<?>> entry : settings.entrySet()) {
169 text.append(entry.getKey()).append("=").append(entry.getValue().getValue().toString()).append("\n");
170 }
171 } catch (Exception x) {
172 Main.error(x);
173 }
174
175 JosmTextArea ta = new JosmTextArea(text.toString());
176 ta.setWrapStyleWord(true);
177 ta.setLineWrap(true);
178 ta.setEditable(false);
179 JScrollPane sp = new JScrollPane(ta);
180
181 ExtendedDialog ed = new ExtendedDialog(Main.parent,
182 tr("Status Report"),
183 new String[] {tr("Copy to clipboard and close"), tr("Report bug"), tr("Close") });
184 ed.setButtonIcons(new String[] {"copy.png", "bug.png", "cancel.png" });
185 ed.setContent(sp, false);
186 ed.setMinimumSize(new Dimension(380, 200));
187 ed.setPreferredSize(new Dimension(700, Main.parent.getHeight()-50));
188
189 switch (ed.showDialog().getValue()) {
190 case 1: Utils.copyToClipboard(text.toString()); break;
191 case 2: OpenBrowser.displayUrl(BugReportExceptionHandler.getBugReportUrl(
192 Utils.strip(reportHeader)).toExternalForm()) ; break;
193 }
194 }
195}
Note: See TracBrowser for help on using the repository browser.