Skip to content

Commit eb65e27

Browse files
Merge commit from fork
restrict configuration in egg templating
2 parents c2de795 + 2bf1ee2 commit eb65e27

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

parser/helpers.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (f *ConfigurationFile) LookupConfigurationValue(cfr ConfigurationFileReplac
237237

238238
// Look for the key in the configuration file, and if found return that value to the
239239
// calling function.
240-
match, _, _, err := jsonparser.Get(f.configuration, path...)
240+
match, dataType, _, err := jsonparser.Get(f.configuration, path...)
241241
if err != nil {
242242
if err != jsonparser.KeyPathNotFoundError {
243243
return string(match), err
@@ -248,7 +248,12 @@ func (f *ConfigurationFile) LookupConfigurationValue(cfr ConfigurationFileReplac
248248
// If there is no key, keep the original value intact, that way it is obvious there
249249
// is a replace issue at play.
250250
return string(match), nil
251-
} else {
252-
return configMatchRegex.ReplaceAllString(cfr.ReplaceWith.String(), string(match)), nil
253251
}
252+
253+
// Only substitute scalar values, not whole objects or arrays.
254+
if dataType == jsonparser.Object || dataType == jsonparser.Array {
255+
return cfr.ReplaceWith.String(), nil
256+
}
257+
258+
return configMatchRegex.ReplaceAllString(cfr.ReplaceWith.String(), string(match)), nil
254259
}

parser/parser.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,28 @@ func (cfr *ConfigurationFileReplacement) UnmarshalJSON(data []byte) error {
188188
return nil
189189
}
190190

191+
type templatableConfig struct {
192+
Docker struct {
193+
Interface string `json:"interface"`
194+
Network struct {
195+
Interface string `json:"interface"`
196+
} `json:"network"`
197+
} `json:"docker"`
198+
}
199+
200+
func newTemplatableConfig(c *config.Configuration) templatableConfig {
201+
var t templatableConfig
202+
t.Docker.Interface = c.Docker.Network.Interface
203+
t.Docker.Network.Interface = c.Docker.Network.Interface
204+
return t
205+
}
206+
191207
// Parse parses a given configuration file and updates all the values within
192208
// as defined in the API response from the Panel.
193209
func (f *ConfigurationFile) Parse(file ufs.File) error {
194210
// log.WithField("path", path).WithField("parser", f.Parser.String()).Debug("parsing server configuration file")
195211

196-
// What the fuck is going on here?
197-
if mb, err := json.Marshal(config.Get()); err != nil {
212+
if mb, err := json.Marshal(newTemplatableConfig(config.Get())); err != nil {
198213
return err
199214
} else {
200215
f.configuration = mb

0 commit comments

Comments
 (0)