diff --git a/.gitignore b/.gitignore index 0e82613dfd..d4a8b4210e 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ client/cmd/translationsreport/translationsreport client/cmd/translationsreport/worksheets server/cmd/dexadm/dexadm server/cmd/geogame/geogame +client/cmd/bisonw/bwlog.zip diff --git a/client/app/config.go b/client/app/config.go index f2aadbc687..89634c3bed 100644 --- a/client/app/config.go +++ b/client/app/config.go @@ -185,17 +185,18 @@ func (cfg *Config) Web(c *core.Core, mm *mm.MarketMaker, log dex.Logger, utc boo } return &webserver.Config{ - Core: c, - MarketMaker: mmCore, - Addr: cfg.WebAddr, - CustomSiteDir: cfg.SiteDir, - Logger: log, - UTC: utc, - CertFile: certFile, - KeyFile: keyFile, - NoEmbed: cfg.NoEmbedSite, - HttpProf: cfg.HTTPProfile, - Language: cfg.Language, + Core: c, + MarketMaker: mmCore, + Addr: cfg.WebAddr, + CustomSiteDir: cfg.SiteDir, + Logger: log, + UTC: utc, + CertFile: certFile, + KeyFile: keyFile, + NoEmbed: cfg.NoEmbedSite, + HttpProf: cfg.HTTPProfile, + Language: cfg.Language, + MainLogFilePath: cfg.LogPath, } } diff --git a/client/webserver/api.go b/client/webserver/api.go index 23bb0067fe..376486c39b 100644 --- a/client/webserver/api.go +++ b/client/webserver/api.go @@ -4,11 +4,14 @@ package webserver import ( + "archive/zip" "encoding/hex" "encoding/json" "errors" "fmt" + "io" "net/http" + "os" "time" "decred.org/dcrdex/client/asset" @@ -2040,6 +2043,34 @@ func (s *WebServer) apiTakeAction(w http.ResponseWriter, r *http.Request) { writeJSON(w, simpleAck()) } +// apiExportAppLogs zips the application log and sends it back to the browser. +func (s *WebServer) apiExportAppLogs(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Disposition", "attachment; filename=bwlog.zip") + w.Header().Set("Content-Type", "application/octet-stream; type=zip") + w.WriteHeader(http.StatusOK) + + zipWriter := zip.NewWriter(w) + defer zipWriter.Close() + + lf, err := os.Open(s.mainLogFilePath) + if err != nil { + log.Errorf("error opening bisonw log file: %v", err) + return + } + defer lf.Close() + + iow, err := zipWriter.Create("bwlog.txt") // only 1 file in zip header + if err != nil { + log.Errorf("error creating an io.Writer: %v", err) + return + } + + if _, err := io.Copy(iow, lf); err != nil { + log.Errorf("error copying bisonw log to zip writer: %v", err) + return + } +} + func (s *WebServer) redeemGameCode(w http.ResponseWriter, r *http.Request) { var form struct { Code dex.Bytes `json:"code"` diff --git a/client/webserver/locales/en-us.go b/client/webserver/locales/en-us.go index 8d15eef0cc..5f089c1ad8 100644 --- a/client/webserver/locales/en-us.go +++ b/client/webserver/locales/en-us.go @@ -679,4 +679,5 @@ var EnUS = map[string]*intl.Translation{ "Wallet Balances": {T: "Wallet Balances"}, "Placements": {T: "Placements"}, "delete_bot": {T: "Delete Bot"}, + "export_logs": {T: "Export Logs"}, } diff --git a/client/webserver/site/src/css/icons.scss b/client/webserver/site/src/css/icons.scss index 098e4a42e6..d25d7b963c 100644 --- a/client/webserver/site/src/css/icons.scss +++ b/client/webserver/site/src/css/icons.scss @@ -155,6 +155,12 @@ display: inline-block; } +.ico-wide-headed-down-arrow::before { + content: "\e919"; + display: inline-block; + transform: rotate(270deg); +} + .ico-arrowup::before { content: "\e90c"; display: inline-block; diff --git a/client/webserver/site/src/html/settings.tmpl b/client/webserver/site/src/html/settings.tmpl index e99927a64b..e939bd92ec 100644 --- a/client/webserver/site/src/html/settings.tmpl +++ b/client/webserver/site/src/html/settings.tmpl @@ -76,6 +76,9 @@

[[[seed_implore_msg]]]

+
+ [[[export_logs]]] +
diff --git a/client/webserver/site/src/js/settings.ts b/client/webserver/site/src/js/settings.ts index 5f973de5de..84c5c5cf3e 100644 --- a/client/webserver/site/src/js/settings.ts +++ b/client/webserver/site/src/js/settings.ts @@ -161,6 +161,8 @@ export default class SettingsPage extends BasePage { }) forms.bind(page.exportSeedAuth, page.exportSeedSubmit, () => this.submitExportSeedReq()) + Doc.bind(page.exportLogs, 'click', () => this.exportLogs()) + Doc.bind(page.gameCodeLink, 'click', () => this.showForm(page.gameCodeForm)) Doc.bind(page.gameCodeSubmit, 'click', () => this.submitGameCode()) @@ -461,6 +463,12 @@ export default class SettingsPage extends BasePage { Doc.show(form) } + async exportLogs () { + const url = new URL(window.location.href) + url.pathname = '/api/exportapplog' + window.open(url.toString()) + } + async submitGameCode () { const page = this.page Doc.hide(page.gameCodeErr) diff --git a/client/webserver/webserver.go b/client/webserver/webserver.go index 1ea09fa6fe..2da9a79162 100644 --- a/client/webserver/webserver.go +++ b/client/webserver/webserver.go @@ -238,8 +238,9 @@ type Config struct { // should be used by default since site files from older distributions may // be present on the disk. When NoEmbed is true, this also implies reloading // and execution of html templates on each request. - NoEmbed bool - HttpProf bool + NoEmbed bool + HttpProf bool + MainLogFilePath string } type valStamp struct { @@ -270,7 +271,8 @@ type WebServer struct { bondBufMtx sync.Mutex bondBuf map[uint32]valStamp - useDEXBranding bool + useDEXBranding bool + mainLogFilePath string } // New is the constructor for a new WebServer. CustomSiteDir in the Config can @@ -392,6 +394,7 @@ func New(cfg *Config) (*WebServer, error) { cachedPasswords: make(map[string]*cachedPassword), bondBuf: map[uint32]valStamp{}, useDEXBranding: useDEXBranding, + mainLogFilePath: cfg.MainLogFilePath, } s.lang.Store(lang) @@ -556,6 +559,7 @@ func New(cfg *Config) (*WebServer, error) { apiAuth.Post("/txhistory", s.apiTxHistory) apiAuth.Post("/takeaction", s.apiTakeAction) apiAuth.Post("/redeemgamecode", s.redeemGameCode) + apiAuth.Get("/exportapplog", s.apiExportAppLogs) apiAuth.Post("/stakestatus", s.apiStakeStatus) apiAuth.Post("/setvsp", s.apiSetVSP)