Skip to content

Commit

Permalink
Return full html after blacklist was generated.
Browse files Browse the repository at this point in the history
Fix where generating the blacklist would appear not have done anything.

Note: previously using the browser reload button would overwrite the file with old content.
  • Loading branch information
publicarray committed Oct 22, 2018
1 parent af59b34 commit 4b75a70
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 7 additions & 5 deletions spk/dnscrypt-proxy/src/ui/cgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,16 +244,15 @@ func generateBlacklist () {
logError("Python could not be found or is not installed!")
}

var stdout, stderr bytes.Buffer
var stderr bytes.Buffer
cmd := exec.Command("python", rootDir+"/var/generate-domains-blacklist.py")
cmd.Dir = rootDir+"/var"
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err := cmd.Run()
stdout, err := cmd.Output()
if err != nil {
logError(err.Error() + string(stdout.Bytes()) + string(stderr.Bytes()))
logError(err.Error() + string(stdout) + string(stderr.Bytes()))
}
saveFile("blacklist", string(stdout.Bytes()))
saveFile("blacklist", string(stdout))
}

// Return HTML from layout.html.
Expand Down Expand Up @@ -334,6 +333,9 @@ func main() {
// return
} else if generateBlacklistStr != "" {
generateBlacklist()
if fileKey == "blacklist" {
renderHTML(fileKey, "File saved successfully!", "")
}
fmt.Print("Status: 200 OK\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n")
os.Exit(0)
}
Expand Down
9 changes: 6 additions & 3 deletions spk/dnscrypt-proxy/src/ui/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@

const updateBlacklist = document.querySelector('.dnscrypt-proxy .updateBlacklist')
updateBlacklist.addEventListener('submit', function(e) {
if (e.preventDefault) e.preventDefault()
toggleSpinner()
ajax('POST', 'generateBlacklist=true')
const urlParams = new URLSearchParams(window.location.search)
if (urlParams.get('file') !== 'blacklist') {
if (e.preventDefault) e.preventDefault()
toggleSpinner()
ajax('POST', 'generateBlacklist=true')
}
}, false)

</script>
Expand Down

0 comments on commit 4b75a70

Please sign in to comment.