Untitled diff

Created Diff never expires
2 removals
165 lines
62 additions
225 lines
var gpoFox = {
var gpoFox = {
basePath : "",
basePath : "",
//basePathLocked : "",
//basePathLocked : "",
defaultPath : "",
defaultPath : "",
lockedPath : "",
lockedPath : "",
reg : "",
reg : "",
prefService : "",
prefService : "",
updateDisabled : false,
updateDisabled : false,
//Disable Update button in Help menu
//Disable Update button in Help menu
disableUpdates : function(){
disableUpdates : function(){
if(gpoFox.updateDisabled){
if(gpoFox.updateDisabled){
var name = document.getElementById("checkForUpdates");
var name = document.getElementById("checkForUpdates");
name.disabled = true;
name.disabled = true;
}
}
},
},
//Read value from registry
//Read value from registry
readRegistryValue : function(value){
readRegistryValue : function(value){
switch (gpoFox.reg.getValueType(value)) {
switch (gpoFox.reg.getValueType(value)) {
case gpoFox.reg.TYPE_STRING:
case gpoFox.reg.TYPE_STRING:
return gpoFox.reg.readStringValue(value);
return gpoFox.reg.readStringValue(value);
case gpoFox.reg.TYPE_BINARY:
case gpoFox.reg.TYPE_BINARY:
return gpoFox.reg.readBinaryValue(value);
return gpoFox.reg.readBinaryValue(value);
case gpoFox.reg.TYPE_INT:
case gpoFox.reg.TYPE_INT:
return gpoFox.reg.readIntValue(value);
return gpoFox.reg.readIntValue(value);
case gpoFox.reg.TYPE_INT64:
case gpoFox.reg.TYPE_INT64:
return gpoFox.reg.readInt64Value(value);
return gpoFox.reg.readInt64Value(value);
}
}
// unknown type
// unknown type
return null;
return null;
},
},
//write value to FF preferences
//write value to FF preferences
writePrefValue : function(name,value,locked){
writePrefValue : function(name,value,locked){
if(locked){
if(locked){
return gpoFox.writeLockedPrefValue(name,value);
return gpoFox.writeLockedPrefValue(name,value);
}else{
}else{
return gpoFox.writeUserPrefValue(name,value);
return gpoFox.writeUserPrefValue(name,value);
}
}
return null;
return null;
},
},
//for writing a locked pref
//for writing a locked pref
writeLockedPrefValue : function(name,value){
writeLockedPrefValue : function(name,value){
var prefBranch = gpoFox.prefService.getDefaultBranch(name);
var prefBranch = gpoFox.prefService.getDefaultBranch(name);
switch (prefBranch.getPrefType("")) {
switch (prefBranch.getPrefType("")) {
case prefBranch.PREF_STRING:
case prefBranch.PREF_STRING:
prefBranch.setCharPref("", value);
prefBranch.setCharPref("", value);
prefBranch.lockPref("");
prefBranch.lockPref("");
return true;
return true;
case prefBranch.PREF_INT:
case prefBranch.PREF_INT:
prefBranch.setIntPref("", value);
prefBranch.setIntPref("", value);
prefBranch.lockPref("");
prefBranch.lockPref("");
return true;
return true;
case prefBranch.PREF_BOOL:
case prefBranch.PREF_BOOL:
if(name=="app.update.enabled" && value==false){
if(name=="app.update.enabled" && value==false){
gpoFox.updateDisabled=true;
gpoFox.updateDisabled=true;
}
}
prefBranch.setBoolPref("", value);
if ( value == "false" ){
prefBranch.setBoolPref("", false);
}else{
prefBranch.setBoolPref("", true);
}
prefBranch.lockPref("");
prefBranch.lockPref("");
return true;
return true;
default:
switch(gpoFox.getLocalType(value))
{
case "string":
if ( value == "false" ){
prefBranch.setBoolPref("", false);
}else{
prefBranch.setBoolPref("", true);
}
return true;
case "int":
prefBranch.setIntPref("", value);
return true;
case "bool":
prefBranch.setBoolPref("", false);
return true;
default:
return false;
}
}
}
return null;
return null;
},
},
//for writing a user pref
//for writing a user pref
writeUserPrefValue : function(name,value){
writeUserPrefValue : function(name,value){
var prefBranch = gpoFox.prefService.getBranch(name);
var prefBranch = gpoFox.prefService.getBranch(name);
switch (prefBranch.getPrefType("")) {
switch (prefBranch.getPrefType("")) {
case prefBranch.PREF_STRING:
case prefBranch.PREF_STRING:
prefBranch.setCharPref("", value);
prefBranch.setCharPref("", value);
return true;
return true;
case prefBranch.PREF_INT:
case prefBranch.PREF_INT:
prefBranch.setIntPref("", value);
prefBranch.setIntPref("", value);
return true;
return true;
case prefBranch.PREF_BOOL:
case prefBranch.PREF_BOOL:
prefBranch.setBoolPref("", value);
if ( value == "false" ){
prefBranch.setBoolPref("", false);
}else{
prefBranch.setBoolPref("", true);
}
return true;
return true;
default:
switch(gpoFox.getLocalType(value))
{
case "string":
prefBranch.setCharPref("", value);
return true;
case "int":
prefBranch.setIntPref("", value);
return true;
case "bool":
if ( value == "false" ){
prefBranch.setBoolPref("", false);
}else{
prefBranch.setBoolPref("", true);
}
return true;
default:
return false;
}
}
}
return null;
return null;
},
},
//Set a FF preference
//Set a FF preference
//will call setLockPref or setUserPref depending on if locked is set to true or false
//will call setLockPref or setUserPref depending on if locked is set to true or false
setPref : function(type,locked){
setPref : function(type,locked){
if(locked){
if(locked){
gpoFox.setLockPref(type);
gpoFox.setLockPref(type);
}
}
else{
else{
gpoFox.setUserPref(type);
gpoFox.setUserPref(type);
}
}
},
},
//set a FF locked preference
//set a FF locked preference
setLockPref : function(type){
setLockPref : function(type){
gpoFox.reg.open(type,gpoFox.basePath + "\\" + gpoFox.lockedPath,gpoFox.reg.ACCESS_READ);
gpoFox.reg.open(type,gpoFox.basePath + "\\" + gpoFox.lockedPath,gpoFox.reg.ACCESS_READ);
for (var i = 0; i < gpoFox.reg.valueCount; i++)
for (var i = 0; i < gpoFox.reg.valueCount; i++)
{
{
var prefName = gpoFox.reg.getValueName(i);
var prefName = gpoFox.reg.getValueName(i);
var FirefoxSetter = gpoFox.readRegistryValue(prefName);
var FirefoxSetter = gpoFox.readRegistryValue(prefName);
gpoFox.writePrefValue(prefName,FirefoxSetter,true);
gpoFox.writePrefValue(prefName,FirefoxSetter,true);
}
}
gpoFox.reg.close();
gpoFox.reg.close();
},
},
//set a FF user preference
//set a FF user preference
setUserPref : function(type){
setUserPref : function(type){
gpoFox.reg.open(type,gpoFox.basePath + "\\" + gpoFox.defaultPath,gpoFox.reg.ACCESS_READ);
gpoFox.reg.open(type,gpoFox.basePath + "\\" + gpoFox.defaultPath,gpoFox.reg.ACCESS_READ);
for (var i = 0; i < gpoFox.reg.valueCount; i++)
for (var i = 0; i < gpoFox.reg.valueCount; i++)
{
{
var prefName = gpoFox.reg.getValueName(i);
var prefName = gpoFox.reg.getValueName(i);
var FirefoxSetter = gpoFox.readRegistryValue(prefName);
var FirefoxSetter = gpoFox.readRegistryValue(prefName);
gpoFox.writePrefValue(prefName,FirefoxSetter,false);
gpoFox.writePrefValue(prefName,FirefoxSetter,false);
}
}
gpoFox.reg.close();
gpoFox.reg.close();
},
},
getLocalType : function(value){
var returnValue = "string";
if ( value == "true" || value == "false" ){
return "bool"
}else{
try{
if (value > -1 ){
return "int"
}
}catch(ex){}
}
return returnValue;
},
//Main function
//Main function
gpofirefox : function(){
gpofirefox : function(){
try {
try {
//set locked preferences from computer GPO
//set locked preferences from computer GPO
gpoFox.reg.open(gpoFox.reg.ROOT_KEY_LOCAL_MACHINE,gpoFox.basePath,gpoFox.reg.ACCESS_READ);
gpoFox.reg.open(gpoFox.reg.ROOT_KEY_LOCAL_MACHINE,gpoFox.basePath,gpoFox.reg.ACCESS_READ);
if(gpoFox.reg.hasChild(gpoFox.lockedPath)){
if(gpoFox.reg.hasChild(gpoFox.lockedPath)){
gpoFox.setPref(gpoFox.reg.ROOT_KEY_LOCAL_MACHINE,true);
gpoFox.setPref(gpoFox.reg.ROOT_KEY_LOCAL_MACHINE,true);
}
}
//set user preferences from computer GPO
//set user preferences from computer GPO
gpoFox.reg.open(gpoFox.reg.ROOT_KEY_LOCAL_MACHINE,gpoFox.basePath,gpoFox.reg.ACCESS_READ);
gpoFox.reg.open(gpoFox.reg.ROOT_KEY_LOCAL_MACHINE,gpoFox.basePath,gpoFox.reg.ACCESS_READ);
if(gpoFox.reg.hasChild(gpoFox.defaultPath)){
if(gpoFox.reg.hasChild(gpoFox.defaultPath)){
gpoFox.setPref(gpoFox.reg.ROOT_KEY_LOCAL_MACHINE,false);
gpoFox.setPref(gpoFox.reg.ROOT_KEY_LOCAL_MACHINE,false);
}
}
//set locked preferences from user GPO
//set locked preferences from user GPO
gpoFox.reg.open(gpoFox.reg.ROOT_KEY_CURRENT_USER,gpoFox.basePath,gpoFox.reg.ACCESS_READ);
gpoFox.reg.open(gpoFox.reg.ROOT_KEY_CURRENT_USER,gpoFox.basePath,gpoFox.reg.ACCESS_READ);
if(gpoFox.reg.hasChild(gpoFox.lockedPath)){
if(gpoFox.reg.hasChild(gpoFox.lockedPath)){
gpoFox.setPref(gpoFox.reg.ROOT_KEY_CURRENT_USER,true);
gpoFox.setPref(gpoFox.reg.ROOT_KEY_CURRENT_USER,true);
}
}
//set user preferences from user GPO
//set user preferences from user GPO
gpoFox.reg.open(gpoFox.reg.ROOT_KEY_CURRENT_USER,gpoFox.basePath,gpoFox.reg.ACCESS_READ);
gpoFox.reg.open(gpoFox.reg.ROOT_KEY_CURRENT_USER,gpoFox.basePath,gpoFox.reg.ACCESS_READ);
if(gpoFox.reg.hasChild(gpoFox.defaultPath)){
if(gpoFox.reg.hasChild(gpoFox.defaultPath)){
gpoFox.setPref(gpoFox.reg.ROOT_KEY_CURRENT_USER,false);
gpoFox.setPref(gpoFox.reg.ROOT_KEY_CURRENT_USER,false);
}
}
}catch(ex){}
}catch(ex){}
},
},
onLoad : function(){
onLoad : function(){
//Define path where to read registry
//Define path where to read registry
this.basePath = "Software\\Policies";
this.basePath = "Software\\Policies";
this.defaultPath = "Mozilla\\defaultPref";
this.defaultPath = "Mozilla\\defaultPref";
this.lockedPath = "Mozilla\\lockPref";
this.lockedPath = "Mozilla\\lockPref";
//load XPCOM component to read registry
//load XPCOM component to read registry
this.reg = Components.classes["@mozilla.org/windows-registry-key;1"].createInstance(Components.interfaces.nsIWindowsRegKey);
this.reg = Components.classes["@mozilla.org/windows-registry-key;1"].createInstance(Components.interfaces.nsIWindowsRegKey);
//load XPCOM component to read and write preferences
//load XPCOM component to read and write preferences
this.prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
this.prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
var helpMenu = document.getElementById("menu_HelpPopup");
var helpMenu = document.getElementById("menu_HelpPopup");
if (helpMenu)
if (helpMenu)
helpMenu.addEventListener("popupshowing", gpoFox.disableUpdates, false);
helpMenu.addEventListener("popupshowing", gpoFox.disableUpdates, false);
this.gpofirefox();
this.gpofirefox();
return;
return;
}
}
};
};
window.addEventListener("load",function(e){gpoFox.onLoad(e);},false);
window.addEventListener("load",function(e){gpoFox.onLoad(e);},false);