Advertisement
jeffstrauss

Add Trusted Realms to Chrome and Firefox

Sep 4th, 2013
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.19 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Add trusted realms to Chrome and Firefox configs
  4. # 2013-09-03 @jestr
  5. #
  6. ### REPLACE "yourRealm" with your realm! ###
  7. #
  8. currentUser=`ls -l /dev/console | awk {' print $3 '}`
  9. prefExists=`cat /Users/$currentUser/Library/Application\ Support/Firefox/Profiles/*.default/prefs.js | grep "network.negotiate"`
  10. twPrefExists=`cat /Users/$currentUser/Library/Application\ Support/Firefox/Profiles/*.default/prefs.js | grep "network.negotiate" | grep "yourRealm"`
  11. isFirefoxRunning=`ps ax | grep "Firefox" | grep -v "+"`
  12. # Add realm to Chrome
  13. if [ ! -f /Users/"$currentUser"/Library/Preferences/com.google.Chrome.plist ]; then
  14.   touch /Users/"$currentUser"/Library/Preferences/com.google.Chrome.plist
  15. fi
  16. defaults write /Users/"$currentUser"/Library/Preferences/com.google.Chrome AuthServerWhitelist "yourRealm"
  17. chown "$currentUser":staff /Users/"$currentUser"/Library/Preferences/com.google.Chrome.plist
  18.  
  19. # Add/append realm to Firefox
  20. if [[ $isFirefoxRunning ]]; then
  21. osascript <<AppleScript
  22. tell application "Finder"
  23.   activate
  24.   display dialog "Firefox is currently running. Firefox must be quit and this policy must be reinitiated for your browsing sessions to be trusted." default button "OK"
  25. end tell
  26. AppleScript
  27. exit 1
  28. elif [[ $prefExists != "" && $twPrefExists == "" ]]; then
  29.   existingRealms=`cat /Users/$currentUser/Library/Application\ Support/Firefox/Profiles/*.default/prefs.js | grep "network.negotiate"| cut -d '"' -f 4`
  30.   updatedRealms="$existingRealms, yourRealm"
  31.   grep -v "network.negotiate" /Users/$currentUser/Library/Application\ Support/Firefox/Profiles/*.default/prefs.js > /tmp/tempKerbFile.js
  32.   echo 'user_pref("network.negotiate-auth.trusted-uris", "'$updatedRealms'");' >> /tmp/tempKerbFile.js
  33.   mv /tmp/tempKerbFile.js /Users/$currentUser/Library/Application\ Support/Firefox/Profiles/*.default/prefs.js
  34. elif [[ $prefExists == "" ]]; then
  35.   cat /Users/$currentUser/Library/Application\ Support/Firefox/Profiles/*.default/prefs.js > /tmp/tempKerbFile.js
  36.   echo 'user_pref("network.negotiate-auth.trusted-uris", "yourRealm");' >> /tmp/tempKerbFile.js
  37.   mv /tmp/tempKerbFile.js /Users/$currentUser/Library/Application\ Support/Firefox/Profiles/*.default/prefs.js
  38. else
  39. exit 0
  40. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement