Skip to content

Instantly share code, notes, and snippets.

@caviv

caviv/firefoxfix.go

Created Mar 7, 2020
Embed
What would you like to do?
Add permissions to Firefox so domains will be able to send notifications in http and no need for https (work around)
package main
// This short script in go (golang) adds websites to the permissions.sqlite file
// of Firefox in order to allow domains with http to send notifications
// it is a work-around on installing SSL/TLS inside intranet inside the organizations
// (C) Cnaan Aviv https://www.cnaanaviv.com
import (
"fmt"
_ "receiver/firefoxfix/homedir"
"os"
"io/ioutil"
"log"
"strings"
"database/sql"
_ "github.com/mattn/go-sqlite3"
)
func main() {
//dir, err := homedir.Dir()
//if(err != nil) {
// fmt.Println(err)
//}
fmt.Println("Fixing firefox: (C) Cnaan Aviv")
fmt.Println("Searching Mozilla Directory")
appdata := os.Getenv("APPDATA")
fmt.Println("appdata is:", appdata)
if _, err := os.Stat(appdata); os.IsNotExist(err) {
fmt.Println("ERROR: appdata directory does not exists")
os.Exit(1)
}
fmt.Println("Searching Profiles")
profilesDir := appdata + "\\Mozilla\\Firefox\\Profiles"
fmt.Println("Profiles:", profilesDir)
if _, err := os.Stat(profilesDir); os.IsNotExist(err) {
fmt.Println("ERROR: no profiles directory")
os.Exit(1)
}
files, err := ioutil.ReadDir(profilesDir)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
var fullpath string
fmt.Println("Listing Profiles")
for _, f := range files {
fullpath = profilesDir + "\\" + f.Name()
fmt.Println(fullpath)
doPermissions(fullpath)
}
fmt.Println("SUCCESS")
}
func doPermissions(fullpath string) {
fmt.Println("Opening permissions.sqlite")
db, err := sql.Open("sqlite3", fullpath + "\\permissions.sqlite")
checkErr(err)
defer db.Close()
doSite("yourinternaldomain", db)
}
func doSite(site string, db *sql.DB) {
fmt.Println("Deleting ", site)
_, err := db.Exec("DELETE FROM moz_perms WHERE origin LIKE '%' + site + '%' AND type LIKE 'desktop-notification';")
checkErr(err)
fmt.Println("Adding ", site)
_, err = db.Exec("INSERT INTO moz_perms (origin, type, permission, expireType, expireTime, modificationTime) VALUES ('http://" + site + "', 'desktop-notification', 1, 0, 0, 1582749488145);")
checkErr(err)
}
func checkErr(err error, args ...string) {
if err != nil {
fmt.Println("Error")
fmt.Println("%q: %s", err, args)
}
}
@caviv

This comment has been minimized.

Copy link
Owner Author

@caviv caviv commented Mar 7, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.