Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client/webserver: Download log files from UI button. #3129

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 12 additions & 11 deletions client/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
31 changes: 31 additions & 0 deletions client/webserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"`
Expand Down
1 change: 1 addition & 0 deletions client/webserver/locales/en-us.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}
6 changes: 6 additions & 0 deletions client/webserver/site/src/css/icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions client/webserver/site/src/html/settings.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
<p class="grey">[[[seed_implore_msg]]]</p>
<button id="exportSeed" class="fs15">[[[View Application Seed]]]</button>
</div>
<div id="exportLogs" class="py-3 mb-3 border-bottom pointer hoverbg">
<span class="ico-wide-headed-down-arrow"></span> [[[export_logs]]]
</div>
<div id="gameCodeLink" class="py-3 mb-3 border-bottom pointer hoverbg">
<span class="ico-ticket"></span> [[[Redeem game code]]]
</div>
Expand Down
12 changes: 12 additions & 0 deletions client/webserver/site/src/js/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -461,6 +463,16 @@ export default class SettingsPage extends BasePage {
Doc.show(form)
}

async exportLogs () {
console.log('exportLogs->')

const url = new URL(window.location.href)
url.pathname = '/api/exportapplog'
window.open(url.toString())

console.log('exportLogs<-')
}

async submitGameCode () {
const page = this.page
Doc.hide(page.gameCodeErr)
Expand Down
10 changes: 7 additions & 3 deletions client/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
Loading