mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-02 22:51:34 -06:00
firefox policies parse.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package firefox
|
||||
|
||||
// https://github.com/mozilla/policy-templates/blob/master/README.md#homepage
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"m1k1o/neko_rooms/internal/types"
|
||||
)
|
||||
|
||||
func Parse(policiesJson string) (*types.Policies, error) {
|
||||
policies := types.Policies{}
|
||||
|
||||
policiesTmpl := struct {
|
||||
Policies map[string]interface{} `json:"policies"`
|
||||
}{}
|
||||
if err := json.Unmarshal([]byte(policiesJson), &policiesTmpl); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// empty file
|
||||
if policiesTmpl.Policies == nil {
|
||||
return &policies, nil
|
||||
}
|
||||
|
||||
//
|
||||
// Homepage
|
||||
//
|
||||
|
||||
if homepage, ok := policiesTmpl.Policies["Homepage"].(map[string]interface{}); ok {
|
||||
if url, ok := homepage["URL"]; ok {
|
||||
policies.Homepage = url.(string)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Extensions
|
||||
//
|
||||
|
||||
if extensions, ok := policiesTmpl.Policies["ExtensionSettings"]; ok {
|
||||
policies.Extensions = []types.Extension{}
|
||||
for id, val := range extensions.(map[string]interface{}) {
|
||||
if id == "*" {
|
||||
continue
|
||||
}
|
||||
|
||||
data := val.(map[string]interface{})
|
||||
url, _ := data["install_url"].(string)
|
||||
|
||||
policies.Extensions = append(
|
||||
policies.Extensions,
|
||||
types.Extension{
|
||||
ID: id,
|
||||
URL: url,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Developer Tools
|
||||
//
|
||||
|
||||
if val, ok := policiesTmpl.Policies["DisableDeveloperTools"]; ok {
|
||||
policies.DeveloperTools = !val.(bool)
|
||||
}
|
||||
|
||||
//
|
||||
// Persistent Data
|
||||
//
|
||||
|
||||
if val, ok := policiesTmpl.Policies["SanitizeOnShutdown"]; ok {
|
||||
policies.PersistentData = !val.(bool)
|
||||
}
|
||||
|
||||
return &policies, nil
|
||||
}
|
||||
Reference in New Issue
Block a user