From 645bfa17d3b4d4d290d4c7859981d71afca14485 Mon Sep 17 00:00:00 2001 From: eholtam <(none)> Date: Mon, 28 Jan 2019 23:00:22 -0600 Subject: [PATCH 1/4] Initial attempt at adding a script to run when UI quits --- .../Application Support/umad/Resources/umad | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/payload/Library/Application Support/umad/Resources/umad b/payload/Library/Application Support/umad/Resources/umad index 632c45e9..d404a95d 100755 --- a/payload/Library/Application Support/umad/Resources/umad +++ b/payload/Library/Application Support/umad/Resources/umad @@ -76,10 +76,12 @@ def button_understand(): umad.views['button.ok'].setEnabled_(True) -def check_mdm_status(umadupdate): +def check_mdm_status(umadupdate, script=None): '''Check MDM Status''' uamdm_enrolled = False mdm_enrolled = False + print script ####DEBUG REMOVE + print 'umadupdate: %s' % umadupdate ####DEBUG REMOVE # Check the OS and run our dep checks based on OS version if get_os_version() >= LooseVersion('10.13.4'): print 'Checking mdm status - modern' @@ -87,6 +89,9 @@ def check_mdm_status(umadupdate): print 'MDM enrolled device %s' % get_os_version() uamdm_enrolled = True if umadupdate: + if script is not None: + print 'UAMDM accepted. Running %s' % script + run_arbitrary_script(script) umad.quit() else: # Check if MDM is installed. @@ -362,6 +367,8 @@ def get_parsed_options(): o.add_option('--profileidentifier', default='B68ABF1E-70E2-43B0-8300-AE65F9AFA330', help=('Required: MDM profile identifier.')) + o.add_option('--scriptwhenuiquits', + help=('Optional: Script to run when UI exists.')) o.add_option('--subtitletext', default='A friendly reminder from your local IT team', help=('Required: Sub-title text.')) @@ -526,6 +533,17 @@ def update_umad_ui_uamdm(uamdm_p1, uamdm_p2, uamdm_p3): umad.views['field.depfailuresubtext'].setStringValue_(sysprefs_h2_text.decode('utf8')) +def run_arbitrary_script(script_path=None): + '''Run a provided script''' + if script_path: + if os.path.exists(script_path): + run = subprocess.Popen(script_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + output, err = run.communicate() + print output + else: + print "File {} was not found".format(filename) + + def main(): '''Main thread''' opts, _ = get_parsed_options() @@ -542,7 +560,7 @@ def main(): print 'WARN - Did not set mdm profile identifier!' # Check the OS and run our dep checks based on OS version - mdm_status = check_mdm_status(False) + mdm_status = check_mdm_status(False, opts.scriptwhenuiquits) uamdm_enrolled = mdm_status[0] mdm_enrolled = mdm_status[1] @@ -910,7 +928,7 @@ def main(): opts.depfailuresubtext.decode('utf8')) # Do one final MDM check to instantly update the UI for UAMDM - check_mdm_status(True) + check_mdm_status(True, opts.scriptwhenuiquits) umad.run() From 050a7eed58923a117a163270bab06b8707fed827 Mon Sep 17 00:00:00 2001 From: eholtam <(none)> Date: Mon, 28 Jan 2019 23:13:04 -0600 Subject: [PATCH 2/4] Moved script variable to a global to access w/o having to pass to functions. --- .../Application Support/umad/Resources/umad | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/payload/Library/Application Support/umad/Resources/umad b/payload/Library/Application Support/umad/Resources/umad index d404a95d..263b22d0 100755 --- a/payload/Library/Application Support/umad/Resources/umad +++ b/payload/Library/Application Support/umad/Resources/umad @@ -76,12 +76,10 @@ def button_understand(): umad.views['button.ok'].setEnabled_(True) -def check_mdm_status(umadupdate, script=None): +def check_mdm_status(umadupdate): '''Check MDM Status''' uamdm_enrolled = False mdm_enrolled = False - print script ####DEBUG REMOVE - print 'umadupdate: %s' % umadupdate ####DEBUG REMOVE # Check the OS and run our dep checks based on OS version if get_os_version() >= LooseVersion('10.13.4'): print 'Checking mdm status - modern' @@ -89,9 +87,9 @@ def check_mdm_status(umadupdate, script=None): print 'MDM enrolled device %s' % get_os_version() uamdm_enrolled = True if umadupdate: - if script is not None: - print 'UAMDM accepted. Running %s' % script - run_arbitrary_script(script) + if script_when_ui_quits is not None: + print 'UAMDM accepted. Running %s' % script_when_ui_quits + run_arbitrary_script(script_when_ui_quits) umad.quit() else: # Check if MDM is installed. @@ -535,7 +533,7 @@ def update_umad_ui_uamdm(uamdm_p1, uamdm_p2, uamdm_p3): def run_arbitrary_script(script_path=None): '''Run a provided script''' - if script_path: + if script_path is not None: if os.path.exists(script_path): run = subprocess.Popen(script_path, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, err = run.communicate() @@ -560,7 +558,7 @@ def main(): print 'WARN - Did not set mdm profile identifier!' # Check the OS and run our dep checks based on OS version - mdm_status = check_mdm_status(False, opts.scriptwhenuiquits) + mdm_status = check_mdm_status(False) uamdm_enrolled = mdm_status[0] mdm_enrolled = mdm_status[1] @@ -610,6 +608,8 @@ def main(): manualenroll_h1_text = opts.manualenrollh1text global manualenroll_h2_text manualenroll_h2_text = opts.manualenrollh2text + global script_when_ui_quits + script_when_ui_quits = opts.scriptwhenuiquits # Get the current username user_name, current_user_uid, _ = get_console_username_info() @@ -928,7 +928,7 @@ def main(): opts.depfailuresubtext.decode('utf8')) # Do one final MDM check to instantly update the UI for UAMDM - check_mdm_status(True, opts.scriptwhenuiquits) + check_mdm_status(True) umad.run() From 1e76db11485a9dd9e83d482be7c68ceda7fcbd4b Mon Sep 17 00:00:00 2001 From: eholtam <(none)> Date: Tue, 29 Jan 2019 09:27:54 -0600 Subject: [PATCH 3/4] Fixed variable for file not found. --- payload/Library/Application Support/umad/Resources/umad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payload/Library/Application Support/umad/Resources/umad b/payload/Library/Application Support/umad/Resources/umad index 263b22d0..9b6e068d 100755 --- a/payload/Library/Application Support/umad/Resources/umad +++ b/payload/Library/Application Support/umad/Resources/umad @@ -539,7 +539,7 @@ def run_arbitrary_script(script_path=None): output, err = run.communicate() print output else: - print "File {} was not found".format(filename) + print "File {} was not found".format(script_path) def main(): From ad993ac0c9d1266dd5044c94fe2898e2b3c72b84 Mon Sep 17 00:00:00 2001 From: eholtam <(none)> Date: Tue, 29 Jan 2019 09:30:33 -0600 Subject: [PATCH 4/4] Typo fixed to reverse meaning. --- payload/Library/Application Support/umad/Resources/umad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payload/Library/Application Support/umad/Resources/umad b/payload/Library/Application Support/umad/Resources/umad index 9b6e068d..7c38d108 100755 --- a/payload/Library/Application Support/umad/Resources/umad +++ b/payload/Library/Application Support/umad/Resources/umad @@ -366,7 +366,7 @@ def get_parsed_options(): default='B68ABF1E-70E2-43B0-8300-AE65F9AFA330', help=('Required: MDM profile identifier.')) o.add_option('--scriptwhenuiquits', - help=('Optional: Script to run when UI exists.')) + help=('Optional: Script to run when UI exits.')) o.add_option('--subtitletext', default='A friendly reminder from your local IT team', help=('Required: Sub-title text.'))