Skip to content
Permalink
Browse files Browse the repository at this point in the history
Filter openvpn configuration data
  • Loading branch information
zachhuff386 committed Sep 2, 2020
1 parent feeacca commit c0aeb15
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion service/profile/profile.go
Expand Up @@ -214,8 +214,43 @@ func (p *Profile) write() (pth string, err error) {

pth = filepath.Join(rootDir, p.Id)

data := ""
for _, line := range strings.Split(p.Data, "\n") {
trimLine := strings.TrimSpace(line)
trimLine = strings.Trim(trimLine, "#")
trimLine = strings.Trim(trimLine, "-")
trimLine = strings.Trim(trimLine, "_")
trimLine = strings.Trim(trimLine, ":")
trimLine = strings.Trim(trimLine, ";")
trimLine = strings.Trim(trimLine, "*")
trimLine = strings.Trim(trimLine, "%")
trimLine = strings.Trim(trimLine, "$")
trimLine = strings.Trim(trimLine, "+")
trimLine = strings.Trim(trimLine, "=")
trimLine = strings.Trim(trimLine, "~")
trimLine = strings.Trim(trimLine, "(")
trimLine = strings.Trim(trimLine, ")")
trimLine = strings.Trim(trimLine, "[")
trimLine = strings.Trim(trimLine, "]")
trimLine = strings.Trim(trimLine, "{")
trimLine = strings.Trim(trimLine, "}")

if strings.Contains(trimLine, "script-security") ||
strings.HasPrefix(trimLine, "log ") ||
strings.HasPrefix(trimLine, "up ") ||
strings.HasPrefix(trimLine, "down ") ||
strings.HasPrefix(trimLine, "route-pre-down ") ||
strings.HasPrefix(trimLine, "tls-verify ") ||
strings.HasPrefix(trimLine, "ipchange ") ||
strings.HasPrefix(trimLine, "route-up ") {

continue
}
data += line + "\n"
}

_ = os.Remove(pth)
err = ioutil.WriteFile(pth, []byte(p.Data), os.FileMode(0600))
err = ioutil.WriteFile(pth, []byte(data), os.FileMode(0600))
if err != nil {
err = &WriteError{
errors.Wrap(err, "profile: Failed to write profile"),
Expand Down

0 comments on commit c0aeb15

Please sign in to comment.