mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-02 22:51:34 -06:00
update policies + chromium.
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
package chromium
|
||||
|
||||
// https://chromeenterprise.google/policies/
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"m1k1o/neko_rooms/internal/types"
|
||||
)
|
||||
|
||||
//go:embed policies.json
|
||||
var policiesJson string
|
||||
|
||||
func Generate(policies types.Policies) (string, error) {
|
||||
policiesTmpl := map[string]interface{}{}
|
||||
if err := json.Unmarshal([]byte(policiesJson), &policiesTmpl); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
//
|
||||
// Homepage
|
||||
//
|
||||
|
||||
if policies.Homepage != "" {
|
||||
policiesTmpl["HomepageLocation"] = policies.Homepage
|
||||
}
|
||||
|
||||
//
|
||||
// Extensions
|
||||
//
|
||||
|
||||
ExtensionInstallForcelist := []interface{}{}
|
||||
for _, e := range policies.Extensions {
|
||||
URL := e.URL
|
||||
if URL == "" {
|
||||
URL = "https://clients2.google.com/service/update2/crx"
|
||||
}
|
||||
|
||||
ExtensionInstallForcelist = append(
|
||||
ExtensionInstallForcelist,
|
||||
fmt.Sprintf("%s;%s", e.ID, URL),
|
||||
)
|
||||
}
|
||||
|
||||
ExtensionInstallWhitelist := []interface{}{}
|
||||
for _, e := range policies.Extensions {
|
||||
ExtensionInstallWhitelist = append(
|
||||
ExtensionInstallWhitelist,
|
||||
e.ID,
|
||||
)
|
||||
}
|
||||
|
||||
policiesTmpl["ExtensionInstallForcelist"] = ExtensionInstallForcelist
|
||||
policiesTmpl["ExtensionInstallWhitelist"] = ExtensionInstallWhitelist
|
||||
policiesTmpl["ExtensionInstallBlacklist"] = []interface{}{"*"}
|
||||
|
||||
//
|
||||
// Developer Tools
|
||||
//
|
||||
|
||||
if policies.DeveloperTools {
|
||||
// Allow usage of the Developer Tools
|
||||
policiesTmpl["DeveloperToolsAvailability"] = 1
|
||||
} else {
|
||||
// Disallow usage of the Developer Tools
|
||||
policiesTmpl["DeveloperToolsAvailability"] = 2
|
||||
}
|
||||
|
||||
//
|
||||
// Persistent Data
|
||||
//
|
||||
|
||||
if policies.PersistentData {
|
||||
// Allow all sites to set local data
|
||||
policiesTmpl["DefaultCookiesSetting"] = 1
|
||||
// Restore the last session
|
||||
policiesTmpl["RestoreOnStartup"] = 1
|
||||
} else {
|
||||
// Keep cookies for the duration of the session
|
||||
policiesTmpl["DefaultCookiesSetting"] = 4
|
||||
}
|
||||
|
||||
data, err := json.MarshalIndent(policiesTmpl, "", " ")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(data), nil
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"HomepageLocation": "",
|
||||
"AutoFillEnabled": false,
|
||||
"AutofillAddressEnabled": false,
|
||||
"AutofillCreditCardEnabled": false,
|
||||
"BrowserSignin": 0,
|
||||
"DefaultNotificationsSetting": 2,
|
||||
"DeveloperToolsAvailability": 2,
|
||||
"EditBookmarksEnabled": false,
|
||||
"FullscreenAllowed": true,
|
||||
"IncognitoModeAvailability": 1,
|
||||
"SyncDisabled": true,
|
||||
"AutoplayAllowed": true,
|
||||
"BrowserAddPersonEnabled": false,
|
||||
"BrowserGuestModeEnabled": false,
|
||||
"DefaultPopupsSetting": 2,
|
||||
"DownloadRestrictions": 3,
|
||||
"VideoCaptureAllowed": true,
|
||||
"AllowFileSelectionDialogs": false,
|
||||
"PromptForDownloadLocation": false,
|
||||
"BookmarkBarEnabled": false,
|
||||
"PasswordManagerEnabled": false,
|
||||
"URLBlacklist": [
|
||||
"file://*",
|
||||
"chrome://policy"
|
||||
],
|
||||
"ExtensionInstallForcelist": [
|
||||
"cjpalhdlnbpafiamejdnhcphjbkeiagm;https://clients2.google.com/service/update2/crx",
|
||||
"fjoaledfpmneenckfbpdfhkmimnjocfa;https://clients2.google.com/service/update2/crx"
|
||||
],
|
||||
"ExtensionInstallWhitelist": [
|
||||
"cjpalhdlnbpafiamejdnhcphjbkeiagm",
|
||||
"fjoaledfpmneenckfbpdfhkmimnjocfa"
|
||||
],
|
||||
"ExtensionInstallBlacklist": [
|
||||
"*"
|
||||
]
|
||||
}
|
||||
@@ -1,87 +1,74 @@
|
||||
package firefox
|
||||
|
||||
// https://github.com/mozilla/policy-templates/blob/master/README.md#homepage
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"m1k1o/neko_rooms/internal/types"
|
||||
)
|
||||
|
||||
type Settings struct {
|
||||
Bookmarks []string `json:"bookmarks"`
|
||||
Extensions map[string]string `json:"extensions"`
|
||||
DeveloperTools bool `json:"developer_tools"`
|
||||
}
|
||||
|
||||
//go:embed policies.json
|
||||
var policiesJson string
|
||||
|
||||
func Generate(settings Settings) (string, error) {
|
||||
policiesObj := struct {
|
||||
func Generate(policies types.Policies) (string, error) {
|
||||
policiesTmpl := struct {
|
||||
Policies map[string]interface{} `json:"policies"`
|
||||
}{}
|
||||
if err := json.Unmarshal([]byte(policiesJson), &policiesObj); err != nil {
|
||||
if err := json.Unmarshal([]byte(policiesJson), &policiesTmpl); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
//
|
||||
// Bookmarks
|
||||
// Homepage
|
||||
//
|
||||
|
||||
// Do not append
|
||||
//Bookmarks := policiesObj.Policies["Bookmarks"].([]interface{})
|
||||
Bookmarks := []interface{}{}
|
||||
|
||||
for _, URL := range settings.Bookmarks {
|
||||
title := URL
|
||||
|
||||
if u, err := url.Parse(URL); err == nil {
|
||||
title = u.Hostname()
|
||||
if policies.Homepage != "" {
|
||||
policiesTmpl.Policies["Homepage"] = map[string]interface{}{
|
||||
"URL": policies.Homepage,
|
||||
"StartPage": "homepage",
|
||||
}
|
||||
|
||||
Bookmarks = append(Bookmarks, map[string]interface{}{
|
||||
"Title": title,
|
||||
"URL": URL,
|
||||
//"Favicon": URL + "/favicon.ico",
|
||||
"Folder": "Pages",
|
||||
"Placement": "toolbar",
|
||||
})
|
||||
}
|
||||
|
||||
if len(settings.Bookmarks) > 0 {
|
||||
policiesObj.Policies["Bookmarks"] = Bookmarks
|
||||
}
|
||||
|
||||
//
|
||||
// Extensions
|
||||
//
|
||||
|
||||
// Do not append
|
||||
//Extensions := policiesObj.Policies["ExtensionSettings"].(map[string]interface{})
|
||||
Extensions := map[string]interface{}{}
|
||||
|
||||
// block all
|
||||
Extensions["*"] = map[string]interface{}{
|
||||
ExtensionSettings := map[string]interface{}{}
|
||||
ExtensionSettings["*"] = map[string]interface{}{
|
||||
"installation_mode": "blocked",
|
||||
}
|
||||
|
||||
for id, url := range settings.Extensions {
|
||||
Extensions[id] = map[string]interface{}{
|
||||
"install_url": url,
|
||||
for _, e := range policies.Extensions {
|
||||
ExtensionSettings[e.ID] = map[string]interface{}{
|
||||
"install_url": e.URL,
|
||||
"installation_mode": "force_installed",
|
||||
}
|
||||
}
|
||||
|
||||
if len(settings.Extensions) > 0 {
|
||||
policiesObj.Policies["ExtensionSettings"] = Extensions
|
||||
policiesTmpl.Policies["ExtensionSettings"] = ExtensionSettings
|
||||
|
||||
//
|
||||
// Developer Tools
|
||||
//
|
||||
|
||||
policiesTmpl.Policies["DisableDeveloperTools"] = !policies.DeveloperTools
|
||||
|
||||
//
|
||||
// Persistent Data
|
||||
//
|
||||
|
||||
if policies.PersistentData {
|
||||
Preferences := policiesTmpl.Policies["Preferences"].(map[string]interface{})
|
||||
Preferences["browser.urlbar.suggest.history"] = true
|
||||
Preferences["places.history.enabled"] = true
|
||||
policiesTmpl.Policies["Preferences"] = Preferences
|
||||
policiesTmpl.Policies["SanitizeOnShutdown"] = false
|
||||
} else {
|
||||
policiesTmpl.Policies["SanitizeOnShutdown"] = true
|
||||
}
|
||||
|
||||
//
|
||||
// DeveloperTools
|
||||
//
|
||||
|
||||
policiesObj.Policies["DisableDeveloperTools"] = settings.DeveloperTools
|
||||
|
||||
data, err := json.MarshalIndent(policiesObj, "", " ")
|
||||
data, err := json.MarshalIndent(policiesTmpl, "", " ")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -115,15 +115,6 @@
|
||||
"ui.key.menuAccessKeyFocuses": false
|
||||
},
|
||||
"PromptForDownloadLocation": false,
|
||||
"SanitizeOnShutdown": {
|
||||
"Cache": true,
|
||||
"Cookies": true,
|
||||
"Downloads": true,
|
||||
"FormData": true,
|
||||
"History": true,
|
||||
"OfflineApps": true,
|
||||
"Sessions": true,
|
||||
"SiteSettings": true
|
||||
}
|
||||
"SanitizeOnShutdown": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package types
|
||||
|
||||
type Policies struct {
|
||||
Homepage string `json:"homepage"`
|
||||
Extensions []Extension `json:"extensions"`
|
||||
DeveloperTools bool `json:"developer_tools"`
|
||||
PersistentData bool `json:"persistent_data"`
|
||||
}
|
||||
|
||||
type Extension struct {
|
||||
ID string `json:"id"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
Reference in New Issue
Block a user