TeamViewer 11 and Munki
Heads up: this post is from 2016. The tools and versions it covers may have changed since.
So here we go again. Unfortunately my TeamViewer 10 post was incorrect and I did not test the deployment enough. Using those instructions you will have trouble putting the password on another system as well as issues with the helper. TeamViewer 11 is of course no exception. It seems TeamViewer doesn't seem to understand how deployable software should work and there continues to be no improvement to the software. After a lot of testing, I have been able to make it somewhat deployable.
Are you ready for this process? It is quite the doozy and unfortunately is not an ideal model for a software that is cross-platform and labeled as deployable and customizable. Let's begin by highlighting this process:
- Create com.TeamViewer8.Settings.plist with the settings we like initially such as the remote control password, settings password and turning off updates
- Install TeamViewer Host (Version 8)
- Install TeamViewer Host (Version 9)
- Run a post install script that will perform the following
- Unload the Launch Daemon for TeamViewer to run as a service
- Cleanup TeamViewer 8's folder as it is now just in applications as TeamViewerHost.app
- Convert the TeamViewer 9 Plist to XML so we can manipulate it
- Read in the TeamViewer 9 Plist as it is created by the setup
- Set some additional settings that may not have carried over from version 8
- Load the LaunchDaemon so the password is converted.
- Run a Preinstall script that will copy the newly converted password with "special" encryption to the new plist for version 11
- Install Version 11
- Run a post install script that will set the custom attribute for your custom module from the website and run the application before we apply customization of the Main Menu in the Menu Bar
- Finally, apply the MainMenuHost.NIB file that will remove the pieces we want from the menu that appears by clicking the menu bar item
This is obviously no easy process but thankfully we have Munki (or insert software deployment service here). With Munki, we will require that when we install TeamViewer 11 that 8 and 9 be installed first. So let's get started.
First we will install TeamViewer version 8 and utilize a pre install script. This will allow us to set our configuration settings before TeamViewer launches which will allow the unattended host password to be set. I have gone ahead and scripted it in python so go ahead and use the script below.
The script that was embedded here is no longer available.
Remember to get SecurityPasswordAES and OptionsPasswordAES you will need to do a manual install on a system and use OS X's built in defaults to read out these binary values. (Of course you will need to remove the spaces)
Now that we have TeamViewer 8 setup let's go ahead and get 9 ready for deployment with our script as well. Once imported into your repo you will want to go ahead and add the script below as a post install script:
#!/usr/bin/python'
'''This simple script will add some additional options
for TeamViewer 9 and convert our password from
the previous version to the new encryption method.
Joshua D. Miller - [email protected]. February 18, 2016
The Pennsylvania State University'''
import os
import sys
import plistlib
import subprocess
import shutil
def main():
'''This function will add addtional items
to the TeamViewer 9 PLIST and convert
the password'''
# Set LaunchDaemon Paths
tv_service = ('/Library/LaunchDaemons/'
'com.teamviewer.teamviewer_service.plist')
# Set TeamViewer 9 plist path
tv9_plist_path = ('/Library/Preferences/'
'com.teamviewer.teamviewer9.plist')
try:
# Unload LaunchDaemons if they are running
launch_process = subprocess.Popen(['/bin/launchctl',
'list'],'
stdout=subprocess.PIPE)
awk_process = subprocess.Popen(['/usr/bin/awk',
'{print $3}'],
stdout=subprocess.PIPE,
stdin=launch_process.stdout)
current_launchd_items = awk_process.communicate()[0]
if 'com.teamviewer.service' in current_launchd_items:
subprocess.check_output(['/bin/launchctl',
'unload',
tv_service],
stderr=subprocess.PIPE)
except StandardError as error:
print error
# Use plutil to convert plist to xml for manipulation'
subprocess.check_output(['/usr/bin/plutil',
'-convert',
'xml1',
tv9_plist_path],
stderr=subprocess.PIPE)
# Remove TeamViewer 8 Folder
if os.path.exists('/Applications/TeamViewer 8'):
shutil.rmtree('/Applications/TeamViewer 8')
# Set the Managers Data array so that users
# are not prompted. Granted this means that
# the machine will not be automaticaly added
# to a group but it keeps the installation silent
# Use the same method to obtain this as the
# passwords from version 8
managers_binary = ('Your binary for Managers from'
'TeamViewer 11 Here').decode('Hex')
# Now let's read the plist file and make some changes
try:
tv9_plist = plistlib.readPlist(tv9_plist_path)
# Allow access from Login Window
tv9_plist['ACFullAccessOnLoginScreen'] = 1
# Set who the computer is assigned to (Optional)
tv9_plist['Managers'] = plistlib.Data(managers_binary)
tv9_plist['Device_Auto_Assigned_To_Account'] = 1
tv9_plist['OwningManagerAccountName'] = 'Account Name'
tv9_plist['OwningManagerCompanyName'] = 'Account Company'
# Write plist with new values added
plistlib.writePlist(tv9_plist, tv9_plist_path)
except StandardError as error:
print error
sys.exit(1)
# Convert the plist back to binary
subprocess.check_output(['/usr/bin/plutil',
'-convert',
'binary1',
tv9_plist_path],
stderr=subprocess.PIPE)
try:
# Load LaunchDaemons to convert Password
subprocess.check_output(['/bin/launchctl',
'load',
tv_service],
stderr=subprocess.PIPE)
except StandardError as error:
print error
if __name__ == '__main__':
main()
Still following along? Good! Now we are going to finally install the version that we want. TeamViewer version 11. Once imported into the repository we will use a pre instal and post install script in order to achieve full deployability. Check below for those scripts:
TeamViewer 11 Pre Install Script
#!/usr/bin/python
'''This script will extract the permanent password from the
TeamViewer 9 PLIST file and place it in the 11 PLIST file.
Joshua D. Miller - [email protected] - Feburary 17, 2016
The Pennsylvania State University'''
import os
import sys
import subprocess
import time
from Foundation import CFPreferencesCopyAppValue
import plistlib
def main():
'''main function'''
# Set a wait time of 15 seconds to make sure the
# Password was converted before proceeding
time.sleep(15)
# Set LaunchDaemon Paths
tv_service = ('/Library/LaunchDaemons/'
'com.teamviewer.teamviewer_service.plist')
# TeamViewer 9 plist path
tv9_plist_path = ('/Library/Preferences/'
'com.teamviewer.teamviewer9.plist')
# TeamViewer 11 PLIST
tv11_plist_path = ('/Library/Preferences/'
'com.teamviewer.teamviewer.preferences.plist')
# TeamViewer Applications Path
try:
# Unload LaunchDaemons if they are running
launch_process = subprocess.Popen(['/bin/launchctl',
'list'],
stdout=subprocess.PIPE)
awk_process = subprocess.Popen(['/usr/bin/awk',
'{print $3}'],
stdout=subprocess.PIPE,
stdin=launch_process.stdout)
current_launchd_items = awk_process.communicate()[0]
if 'com.teamviewer.service' in current_launchd_items:
subprocess.check_output(['/bin/launchctl',
'unload',
tv_service],
stderr=subprocess.PIPE)
except StandardError as error:
print error
if os.path.isfile(tv9_plist_path):
try:
# Get Permanent Password from TeamViewer 9
hostpassword = CFPreferencesCopyAppValue('PermanentPassword',
'com.teamviewer'
'.teamviewer9')
pref_password = CFPreferencesCopyAppValue('OptionsPasswordAES',
'com.teamviewer'
'.teamviewer9')
managers_binary = ('Your binary for Managers from'
'TeamViewer 11 here').decode('Hex')
if os.path.isfile(tv11_plist_path):
subprocess.check_output(['/usr/bin/plutil',
'-convert',
'xml1',
tv11_plist_path],
stderr=subprocess.PIPE)
# Read PLIST from TeamVIewer 11
exist_tv_plist = plistlib.readPlist(tv11_plist_path)
# Set Password in TeamVIewer 11 PLIST
exist_tv_plist['PermanentPassword'] = hostpassword
# Set Preferences Password
exist_tv_plist['OptionsPasswordAES'] = pref_password
# Set Owning account to keep prompt from displaying
exist_tv_plist['Device_Auto_Assigned_To_Account'] = 1
exist_tv_plist['Managers'] = plistlib.Data(managers_binary)
exist_tv_plist['OwningManagerAccountName'] = 'Account Name'
exist_tv_plist['OwningManagerCompanyName'] = 'Account Company'
# Allow Login from Login Screen
exist_tv_plist['ACFullAccessOnLoginScreen'] = 1
# Turn off auto updates completely
exist_tv_plist['AutoUpdateMode'] = 3
exist_tv_plist['UpdateCheckInterval'] = -1
# Allow connections from LAN
exist_tv_plist['General_DirectLAN'] = 1
# Turn off initial screen
exist_tv_plist['HostInfoDialog'] = 0
plistlib.writePlist(exist_tv_plist, tv11_plist_path)
subprocess.check_output(['/usr/bin/plutil',
'-convert',
'binary1',
tv11_plist_path],
stderr=subprocess.PIPE)
else:
new_tv11_plist = dict(
# These are the same as above but we are creating
# the plist manually since it doesn't exist
InstalledBy='EDUC',
PermanentPassword=plistlib.Data(hostpassword),
OptionsPasswordAES=plistlib.Data(pref_password),
Device_Auto_Assigned_To_Account=1,
Managers=plistlib.Data(managers_binary),
OwningManagerAccountName='Account Name'
OwningManagerCompanyName='Account Company'
ACFullAccessOnLoginScreen=1,
AutoUpdateMode=3,
UpdateCheckInterval=-1,
General_DirectLAN=1,
HostInfoDialog=0,
)
plistlib.writePlist(new_tv11_plist, tv11_plist_path)
# Print Error if the password cannot be retrieved
except StandardError as error:
print error
sys.exit(1)
try:
# Load LaunchDaemons to convert Password
subprocess.check_output(['/bin/launchctl',
'load',
tv_service],
stderr=subprocess.PIPE)
except StandardError as error:
print error
if __name__ == '__main__':
main()
TeamViewer 11 Post Install Script
#!/usr/bin/python
'''Very simple script to run a simple
command to set our attribute to TeamViewer
so that customizations can be received such
as logo, text, etc.. Joshua D. Miller - [email protected]
February 18, 2016 - The Pennsylvania State University'''
import os
import signal
import subprocess
import time
def main():
'''main function'''
# Set TeamViewer Host Application
# path so we can apply the xattr
# This can be obtained from your
# custom download pkg in the name
tv_app_path = '/Applications/TeamViewerHost.app'
# TeamViewer Config ID
tv_conf_id = 'com.TeamViewer.ConfigurationId'
# Custom Attribute from custom pkg
attribute = 'Your ID Here (Usually starts with idc)'
subprocess.check_output(['/usr/bin/xattr',
'-w',
tv_conf_id,
attribute,
tv_app_path],
stderr=subprocess.PIPE)
try:
# Load TeamViewer App so that it launches before
# customization
tv_launch = subprocess.Popen(['/Applications/TeamVIewerHost.app'
'/Contents/MacOS/TeamViewerHost',
'-RunAsAgent',
'YES'],
preexec_fn=os.setsid,
stderr=subprocess.PIPE)
# Wait until the app fully launches before closing it
time.sleep(10)
# Kill the TeamViewer Host App so it can launch properly
# upon login
os.killpg(os.getpgid(tv_launch.pid), signal.SIGTERM)
except StandardError as error:
print error
if __name__ == '__main__':
main()
Now that we have all the scripts in place, Munki will install in order, version 8, version 9 and finally version 11. You could use this same process for version 10. The last step is to insert our special MainMenuHost.NIB file. Thanks to a GitHub project located at https://github.com/annidy/NibViwer I was able to look at the actual NIB file for TeamViewer and then export and modify it. To modify a NIB file you will need to use xCode however if you are lazy I have gone ahead and attached my modified NIB file to this post for your use. You can download it here. My file has removed the following from TeamViewer:
- Check for Updates
- Activate License
- TeamViewer Website
- Exit TeamViewer
Now that we have the file we would add this to a DMG like we did originally with version 8 and make this DMG an update for TeamViewer 11.
Finally the moment of truth - testing. My extensive testing with these scripts has shown when setup in Munki correctly that Munki will install all three versions of TeamViewer and the customization. Upon completion the user will log in and TeamViewer will launch properly and your password will work. One last tidbit of information I'd like to add is I always require logout to install TeamViewer just to be safe. I would suggest that you do as well.
As you can see this process is very lengthy and complex for a cross-platform deployable remote control solution. It is my belief that our college will probably begin exploring other options since the deployability of this software has not changed since version 8 and has only gotten worse. I have called in and complained to TeamViewer with each software release and they seem to reiterate the same answer. "Mac deployment just isn't important". For those of you using TeamViewer and this process I suggest you also call in and voice your concerns for this software's inability to be deployed correctly without some major work on Mac. It is my hope that they begin to change their stance and make the software a better solution for Mac. If you have questions on this process please be sure to drop me a line.