Created
January 24, 2012 21:53
-
-
Save acidprime/1672949 to your computer and use it in GitHub Desktop.
Simple Python Example for Generating 10.7 (Lion) 8021x .mobileconfig Profiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python -tt | |
__author__ = 'Zack Smith @acidprime' | |
__version__ = '0.1' | |
import sys | |
import getopt | |
from Cocoa import NSMutableDictionary | |
global debugEnabled | |
debugEnabled = True | |
def main(): | |
if(debugEnabled): print 'Processing Arguments: ', sys.argv[1:] | |
options, remainder = getopt.getopt(sys.argv[1:], 'w:u:p:', ['username=', | |
'password=', | |
'write=', | |
]) | |
for opt, arg in options: | |
if opt in ('-u', '--username'): | |
userName = arg | |
elif opt in ('-p', '--password'): | |
userPass = arg | |
elif opt in ('-w', '--write'): | |
saveFile = arg | |
# Hardcoded values for the moment | |
orgName = 'somecompany' | |
networkName = 'somenetwork' | |
mdmHost = 'com.apple.mdm.mute.wallcity.org' | |
payloadUUID = '81f55323-c1a2-47fd-aee3-7b8a93d31472' | |
_payloadUUID = '52f7d163-f2bb-4972-8a26-411355229cc5' | |
# Generate the profile | |
genLionProfile(userName, | |
userPass, | |
payloadUUID, | |
_payloadUUID, | |
networkName, | |
mdmHost, | |
orgName, | |
saveFile) | |
# Need to clean this up with defaults or a dict | |
def genLionProfile(userName, | |
userPass, | |
payloadUUID, | |
_payloadUUID, | |
networkName, | |
mdmHost, | |
orgName, | |
saveFile): | |
plist = NSMutableDictionary.alloc().init() | |
# EAPClientConfiguration | |
AcceptEAPTypes = [] | |
_AcceptEAPTypes = 25 | |
AcceptEAPTypes = [_AcceptEAPTypes] | |
tlsTrustedServerNames = [] | |
EAPClientConfiguration = {} | |
EAPClientConfiguration['AcceptEAPTypes'] = AcceptEAPTypes | |
EAPClientConfiguration['TTLSInnerAuthentication'] = 'MSCHAPv2' | |
EAPClientConfiguration['UserName'] = userName | |
EAPClientConfiguration['UserPassword'] = userPass | |
EAPClientConfiguration['tlsTrustedServerNames'] = tlsTrustedServerNames | |
# PayloadContent | |
PayloadContent = [] | |
_PayloadContent = {} | |
_PayloadContent['AuthenticationMethod'] = '' | |
_PayloadContent['EAPClientConfiguration'] = EAPClientConfiguration | |
_PayloadContent['EncryptionType'] = 'WPA' | |
_PayloadContent['HIDDEN_NETWORK'] = False | |
_PayloadContent['Interface'] = 'BuiltInWireless' | |
_PayloadContent['PayloadDisplayName'] = '%s-%s' % (networkName,userName) | |
_PayloadContent['PayloadEnabled'] = True | |
_PayloadContent['PayloadIdentifier'] = '%s.%s.alacarte.interfaces.%s' % (mdmHost,payloadUUID,_payloadUUID) | |
_PayloadContent['PayloadType'] = 'com.apple.wifi.managed' | |
_PayloadContent['PayloadUUID'] = _payloadUUID | |
_PayloadContent['PayloadVersion'] = 1 | |
_PayloadContent['SSID_STR'] = networkName | |
PayloadContent = [_PayloadContent] | |
plist['PayloadContent'] = PayloadContent | |
plist['PayloadDisplayName'] = 'WPA2' | |
plist['PayloadIdentifier'] = '%s.%s.alacarte' % (mdmHost,payloadUUID) | |
plist['PayloadOrganization'] = orgName | |
plist['PayloadRemovalDisallowed'] = False | |
plist['PayloadScope'] = 'User' | |
plist['PayloadType'] = 'Configuration' | |
plist['PayloadUUID'] = payloadUUID | |
plist['PayloadVersion'] = 1 | |
print plist | |
exportFile = saveFile | |
plist.writeToFile_atomically_(exportFile,True) | |
return exportFile | |
if __name__ == "__main__": | |
sys.exit(main()) |
Example Usage:
./profileGen.py -u zsmith -p 'd0gc4t' -w /tmp/foo.mobileconfig
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
File Generated: