mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-09-20 06:46:19 +08:00
deadcode: NewUTF8, utf8.Execute, utf8.Exit
This commit is contained in:
parent
951b47d583
commit
4d13c0251a
|
@ -2,48 +2,41 @@
|
|||
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
|
||||
"github.com/StackExchange/dnscontrol/v4/pkg/powershell/utils"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
// type utf8 struct {
|
||||
// upstream Middleware
|
||||
// wrapper string
|
||||
// }
|
||||
|
||||
func NewUTF8(upstream Middleware) (Middleware, error) {
|
||||
wrapper := "goUTF8" + utils.CreateRandomString(8)
|
||||
// func NewUTF8(upstream Middleware) (Middleware, error) {
|
||||
// wrapper := "goUTF8" + utils.CreateRandomString(8)
|
||||
|
||||
_, _, err := upstream.Execute(fmt.Sprintf(`function %s { process { if ($_) { [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($_)) } else { '' } } }`, wrapper))
|
||||
// _, _, err := upstream.Execute(fmt.Sprintf(`function %s { process { if ($_) { [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($_)) } else { '' } } }`, wrapper))
|
||||
|
||||
return &utf8{upstream, wrapper}, err
|
||||
}
|
||||
// return &utf8{upstream, wrapper}, err
|
||||
// }
|
||||
|
||||
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)
|
||||
// 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)
|
||||
|
||||
stdout, stderr, err := u.upstream.Execute(cmd)
|
||||
if err != nil {
|
||||
return stdout, stderr, err
|
||||
}
|
||||
// stdout, stderr, err := u.upstream.Execute(cmd)
|
||||
// if err != nil {
|
||||
// return stdout, stderr, err
|
||||
// }
|
||||
|
||||
decoded, err := base64.StdEncoding.DecodeString(stdout)
|
||||
if err != nil {
|
||||
return stdout, stderr, err
|
||||
}
|
||||
// decoded, err := base64.StdEncoding.DecodeString(stdout)
|
||||
// if err != nil {
|
||||
// return stdout, stderr, err
|
||||
// }
|
||||
|
||||
return string(decoded), stderr, nil
|
||||
}
|
||||
// return string(decoded), stderr, nil
|
||||
// }
|
||||
|
||||
func (u *utf8) Exit() {
|
||||
u.upstream.Exit()
|
||||
}
|
||||
// func (u *utf8) Exit() {
|
||||
// u.upstream.Exit()
|
||||
// }
|
||||
|
|
Loading…
Reference in a new issue