Skip to main content
Question

Flashback - disable Java for all users script


Forum|alt.badge.img+12

If you want to disable Java for all users in Safari and Firefox (from what I have seen it doesn't appear to target Chrome) you can run the following script.

Here is the pretty uncommented version:

1#!/bin/bash
2
3ff_users=()
4os_version=$(sw_vers -productVersion)
5
6while read -r -d $''; do
7 ff_users+=("$REPLY")
8done < <(mdfind -name pluginreg.dat -0)
9
10for dat_file in "${ff_users[@]}"; do
11 username=$(stat -f "%Su" "${dat_file}")
12 if [[ ${os_version%.*} == 10.7 ]]; then
13 { rm "${dat_file}" && awk 'BEGIN{FS=OFS=":"}/JavaAppletPlugin/{count=3}count&&!--count&&($3==1||$3==5){$3--}1' > "${dat_file}"; } < "${dat_file}"
14 else
15 { rm "${dat_file}" && awk 'BEGIN{FS=OFS=":"}/JavaPlugin/{count=3}count&&!--count&&($3==1||$3==5){$3--}1' > "${dat_file}"; } < "${dat_file}"
16 fi
17 chown "${username}" "${dat_file}"
18done
19
20for user in /Users/*; do
21 if [[ -e "${user}"/Library/Preferences ]]; then
22 defaults write "${user}"/Library/Preferences/com.apple.Safari WebKitJavaEnabled -bool FALSE
23 defaults write "${user}"/Library/Preferences/com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaEnabled -bool FALSE
24 chown "${user##*/}" "${user}"/Library/Preferences/com.apple.Safari.plist
25 fi
26done

And here is the nasty one for those of you who want to know what is going on:

1#!/bin/bash
2
3ff_users=()
4os_version=$(sw_vers -productVersion)
5
6# find all users with a Firefox profile and pluginreg.dat file within it using mdfind as suggested by Christoph von Gabler-Sahm (cvgs on jamf nation)
7
8while read -r -d $''; do
9 ff_users+=("$REPLY")
10done < <(mdfind -name pluginreg.dat -0)
11
12# here is the find version
13# while read -r -d $''; do
14# ff_users+=("$REPLY")
15# done < <(find /Users -name pluginreg.dat -print0 2> /dev/null
16
17
18# now we are going to disable java in Firefox
19# for this we are going to use awk to modify the list of pluginreg.dat files in the ff_users array
20# if statement checks for 10.7 as the relevent line is named JavaAppletPlugin in 10.7 with FF 11.0
21# else use JavaPlugin as found in 10.6
22
23for dat_file in "${ff_users[@]}"; do
24 username=$(stat -f "%Su" "${dat_file}")
25 if [[ ${os_version%.*} == 10.7 ]]; then
26 { rm "${dat_file}" && awk 'BEGIN{FS=OFS=":"}/JavaAppletPlugin/{count=3}count&&!--count&&($3==1||$3==5){$3--}1' > "${dat_file}"; } < "${dat_file}"
27 else
28 { rm "${dat_file}" && awk 'BEGIN{FS=OFS=":"}/JavaPlugin/{count=3}count&&!--count&&($3==1||$3==5){$3--}1' > "${dat_file}"; } < "${dat_file}"
29 fi
30 chown "${username}" "${dat_file}"
31done
32
33# disable Java in Firefox
34# after poking around in Firefox's sqlite files I went googling and found this post by Clay Caviness
35# https://plus.google.com/109088229817689076273/posts/7yH5QGJhuyN
36# I didn't know enough AWK to make that happen in a bash script but after a few tries 'mute' in #awk got it right for me
37
38# awk 'BEGIN{FS=OFS=":"}/JavaAppletPlugin/{p=3}p&&!--p&&($3==1||$3==5){$3--}1'
39
40# we can edit in-place with a little trick I orginally saw here
41# http://www.unix.com/shell-programming-scripting/35591-sed-awk-inplace-inline-edit.html
42
43
44# disable Java in Safari for all users
45
46for user in /Users/*; do
47 if [[ -e "${user}"/Library/Preferences ]]; then
48 defaults write "${user}"/Library/Preferences/com.apple.Safari WebKitJavaEnabled -bool FALSE
49 defaults write "${user}"/Library/Preferences/com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaEnabled -bool FALSE
50 chown "${user##*/}" "${user}"/Library/Preferences/com.apple.Safari.plist
51 fi
52done

5 replies

Forum|alt.badge.img+12
  • Author
  • Contributor
  • 312 replies
  • April 9, 2012

For an explanation on the awk basically what it does is

set the field seperators to :
search for the Java line we want
assign variable count=3
count down from 3
now if the third field =1 or the third field =5 subtract 1


RobertHammen
Forum|alt.badge.img+28
  • Esteemed Contributor
  • 1027 replies
  • April 11, 2012

Haven't had time to dig into it, but both your extension attribute and this disable script fail on pre-10.5 machines. Not a huge concern since the handful of ones I have are legacy servers, not user-facing, and I know not officially supported by later versions of the jamf binary.

Here's the error from the policy log:

Script Result: /private/tmp/disableJavaSafariFirefox.sh: line 7: syntax error near unexpected token `"$REPLY"'
/private/tmp/disableJavaSafariFirefox.sh: line 7: ` ff_users+=("$REPLY")'


Forum|alt.badge.img+12
  • Author
  • Contributor
  • 312 replies
  • April 11, 2012

@RobertHammen yea I don't have any 10.5.x machines anymore so I didn't bother checking for compatibility....sorry for not mentioning that.


Forum|alt.badge.img+12
  • Author
  • Contributor
  • 312 replies
  • April 12, 2012

RUN SOFTWARE UPDATE

https://support.apple.com/kb/HT5242


Forum|alt.badge.img+3
  • New Contributor
  • 8 replies
  • May 1, 2012

Could be done Globally with —
defaults write /Library/Preferences/com.apple.Safari WebKitJavaEnabled -bool false
defaults write /Library/Preferences/com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaEnabled -bool false

Might be an idea to set the defaults for new users too somehow in the User Template. This would definitely be possible with Safari, setting the defaults in FireFox is more difficult, but not impossible.

So set specifically in the User Template with
defaults write /System/Library/User Template/English.lproj/Library/Preferences/com.apple.Safari WebKitJavaEnabled -bool false
defaults write /System/Library/User Template/English.lproj/Library/Preferences/com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2JavaEnabled -bool false


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings