1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00
Files
stackexchange-dnscontrol/pkg/powershell/middleware/utf8.go

43 lines
1.3 KiB
Go
Raw Normal View History

2024-02-15 13:46:32 -05:00
// Copyright (c) 2017 Gorillalabs. All rights reserved.
package middleware
// utf8 implements a primitive middleware that encodes all outputs
// as base64 to prevent encoding issues between remote PowerShell
// shells and the receiver. Just setting $OutputEncoding does not
// work reliably enough, sadly.
// type utf8 struct {
// upstream Middleware
// wrapper string
// }
2024-02-15 13:46:32 -05:00
// func NewUTF8(upstream Middleware) (Middleware, error) {
// wrapper := "goUTF8" + utils.CreateRandomString(8)
2024-02-15 13:46:32 -05:00
// _, _, err := upstream.Execute(fmt.Sprintf(`function %s { process { if ($_) { [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($_)) } else { '' } } }`, wrapper))
2024-02-15 13:46:32 -05:00
// return &utf8{upstream, wrapper}, err
// }
2024-02-15 13:46:32 -05:00
// func (u *utf8) Execute(cmd string) (string, string, error) {
// // Out-String to concat all lines into a single line,
// // Write-Host to prevent line breaks at the "window width"
// cmd = fmt.Sprintf(`%s | Out-String | %s | Write-Host`, cmd, u.wrapper)
2024-02-15 13:46:32 -05:00
// stdout, stderr, err := u.upstream.Execute(cmd)
// if err != nil {
// return stdout, stderr, err
// }
2024-02-15 13:46:32 -05:00
// decoded, err := base64.StdEncoding.DecodeString(stdout)
// if err != nil {
// return stdout, stderr, err
// }
2024-02-15 13:46:32 -05:00
// return string(decoded), stderr, nil
// }
2024-02-15 13:46:32 -05:00
// func (u *utf8) Exit() {
// u.upstream.Exit()
// }