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

This commit is contained in:
James Read 2024-07-04 00:34:07 +01:00 committed by GitHub
parent a1adc2a85d
commit fb6aaa52c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 56 additions and 9 deletions

View File

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

View File

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

View File

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

View File

@ -33,6 +33,9 @@
</ul> </ul>
<ul id = "supplemental-links"> <ul id = "supplemental-links">
<li title = "Diagnostics">
<a id = "showDiagnostics" href = "#Diagnostics">Diagnostics</a>
</li>
<li title = "Logs"> <li title = "Logs">
<a id = "showLogs" href = "#Logs">Logs</a> <a id = "showLogs" href = "#Logs">Logs</a>
</li> </li>
@ -60,6 +63,27 @@
</table> </table>
</section> </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 > <section id = "contentActions" title = "Actions" hidden >
<fieldset id = "root-group" title = "Actions"> <fieldset id = "root-group" title = "Actions">
<legend hidden>Actions</legend> <legend hidden>Actions</legend>

View File

@ -187,9 +187,18 @@ export function setupSectionNavigation (style) {
} }
document.getElementById('showActions').onclick = () => { showSection('Actions') } document.getElementById('showActions').onclick = () => { showSection('Actions') }
document.getElementById('showDiagnostics').onclick = () => {
refreshDiagnostics()
showSection('Diagnostics')
}
document.getElementById('showLogs').onclick = () => { showSection('Logs') } 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) { function marshalDashboardStructureToHtml (json) {
const nav = document.getElementById('navigation-links') const nav = document.getElementById('navigation-links')

View File

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