Explorar el Código

feature: New diagnostics page, showing SSH keys found. (#344)

James Read hace 2 años
padre
commit
fb6aaa52c7

+ 5 - 0
internal/httpservers/webuiServer.go

@@ -29,6 +29,8 @@ type webUISettings struct {
 	PageTitle              string
 	SectionNavigationStyle string
 	DefaultIconForBack     string
+	SshFoundKey            string
+	SshFoundConfig         string
 }
 
 func findWebuiDir() string {
@@ -111,8 +113,11 @@ func generateWebUISettings(w http.ResponseWriter, r *http.Request) {
 		PageTitle:              cfg.PageTitle,
 		SectionNavigationStyle: cfg.SectionNavigationStyle,
 		DefaultIconForBack:     cfg.DefaultIconForBack,
+		SshFoundKey:            installationinfo.Runtime.SshFoundKey,
+		SshFoundConfig:         installationinfo.Runtime.SshFoundConfig,
 	})
 
+	w.Header().Add("Content-Type", "application/json")
 	_, err := w.Write([]byte(jsonRet))
 
 	if err != nil {

+ 13 - 6
internal/installationinfo/runtimeinfo.go

@@ -18,7 +18,8 @@ type runtimeInfo struct {
 	LastBrowserUserAgent string
 	User                 string
 	Uid                  string
-	FoundSshKey          string
+	SshFoundKey          string
+	SshFoundConfig       string
 	AvailableVersion     string
 }
 
@@ -29,20 +30,26 @@ var Runtime = &runtimeInfo{
 	OSReleasePrettyName: getOsReleasePrettyName(),
 	User:                os.Getenv("USER"),
 	Uid:                 os.Getenv("UID"),
+	SshFoundKey:         searchForSshKey(),
+	SshFoundConfig:      searchForSshConfig(),
 }
 
-func refreshRuntimeInfo() {
-	Runtime.FoundSshKey = searchForSshKey()
+func searchForSshKey() string {
+	return searchForHomeFile(".ssh/id_rsa")
 }
 
-func searchForSshKey() string {
-	path, _ := filepath.Abs(path.Join(os.Getenv("HOME"), ".ssh/id_rsa"))
+func searchForSshConfig() string {
+	return searchForHomeFile(".ssh/config")
+}
+
+func searchForHomeFile(file string) string {
+	path, _ := filepath.Abs(path.Join(os.Getenv("HOME"), file))
 
 	if _, err := os.Stat(path); err == nil {
 		return path
 	}
 
-	return "none-found at " + path
+	return "not found at " + path
 }
 
 func isInContainer() bool {

+ 0 - 2
internal/installationinfo/sosreport.go

@@ -43,8 +43,6 @@ func configToSosreport(cfg *config.Config) *sosReportConfig {
 }
 
 func GetSosReport() string {
-	refreshRuntimeInfo()
-
 	ret := ""
 
 	ret += "### SOSREPORT START (copy all text to SOSREPORT END)\n"

+ 24 - 0
webui.dev/index.html

@@ -33,6 +33,9 @@
 				</ul>
 
 				<ul id = "supplemental-links">
+					<li title = "Diagnostics">
+						<a id = "showDiagnostics" href = "#Diagnostics">Diagnostics</a>
+					</li>
 					<li title = "Logs">
 						<a id = "showLogs" href = "#Logs">Logs</a>
 					</li>
@@ -60,6 +63,27 @@
 				</table>
 			</section>
 
+			<section id = "contentDiagnostics" title = "Diagnostics" hidden>
+				<h2>Diagnostics</h2>
+				<div id = "diagnostics" class = "ta-left">
+					<p><strong>Note:</strong> Diagnostics are only generated on OliveTin startup - they are not updated in real-time or when you refresh this page. They are intended as a "quick reference" to help you.</p>
+					<p>If you are having problems with OliveTin and want to raise a support request, please don't take a screenshot or copy text from this page, but instead it is highly recommended to include a <a href = "https://docs.olivetin.app/sosreport.html">sosreport</a> which is more detailed, and makes it easier to help you.</p>
+					<table>
+						<tbody>
+							<th colspan = "0">SSH</th>
+							<tr>
+								<td>Found Key</td>
+								<td id = "diagnostics-sshfoundkey">?</td>
+							</tr>
+
+							<tr>
+								<td>Found Config</td>
+								<td id = "diagnostics-sshfoundconfig">?</td>
+						</tbody>
+					</table>
+				</div>
+			</section>
+
 			<section id = "contentActions" title = "Actions" hidden >
 				<fieldset id = "root-group" title = "Actions">
 					<legend hidden>Actions</legend>

+ 9 - 0
webui.dev/js/marshaller.js

@@ -187,9 +187,18 @@ export function setupSectionNavigation (style) {
   }
 
   document.getElementById('showActions').onclick = () => { showSection('Actions') }
+  document.getElementById('showDiagnostics').onclick = () => {
+    refreshDiagnostics()
+    showSection('Diagnostics')
+  }
   document.getElementById('showLogs').onclick = () => { showSection('Logs') }
 }
 
+function refreshDiagnostics () {
+  document.getElementById('diagnostics-sshfoundkey').innerHTML = window.settings.SshFoundKey
+  document.getElementById('diagnostics-sshfoundconfig').innerHTML = window.settings.SshFoundConfig
+}
+
 function marshalDashboardStructureToHtml (json) {
   const nav = document.getElementById('navigation-links')
 

+ 4 - 0
webui.dev/style.css

@@ -483,6 +483,10 @@ div.display {
   padding: 1em;
 }
 
+.ta-left {
+  text-align: left;
+}
+
 .xterm {
   padding: 1em;
 }