def initStatusSession(self):
        '''Initialize our status session'''
        self.setWindowLevel()
        consoleuser = munki.getconsoleuser()
        if consoleuser == None or consoleuser == u"loginwindow":
            self.displayBackdropWindow()
            # needed so the window can show over the loginwindow
            self.window.setCanBecomeVisibleWithoutLogin_(True)
            self.window.setLevel_(self.window_level)

        self.window.center()
        self.messageFld.setStringValue_(
            NSLocalizedString(u"Starting…", None))
        self.detailFld.setStringValue_(u"")
        self.stopBtn.setHidden_(False)
        self.stopBtn.setEnabled_(True)
        self.stopBtnState = 0
        if self.imageFld:
            theImage = NSImage.imageNamed_("MunkiStatus")
            self.imageFld.setImage_(theImage)
        if self.progressIndicator:
            self.progressIndicator.setMinValue_(0.0)
            self.progressIndicator.setMaxValue_(100.0)
            self.progressIndicator.setIndeterminate_(True)
            self.progressIndicator.setUsesThreadedAnimation_(True)
            self.progressIndicator.startAnimation_(self)
        self.window.orderFrontRegardless()
        self.registerForNotifications()
        # start our process monitor timer so we can be notified about
        # process failure
        self.timeout_counter = 6
        self.saw_process = False
        self.timer = (NSTimer.
            scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
                5.0, self, self.checkProcess, None, YES))
Example #2
0
 def applicationWillFinishLaunching_(self, sender):
     consoleuser = munki.getconsoleuser()
     if consoleuser == None or consoleuser == u"loginwindow":
         # don't show menu bar
         NSMenu.setMenuBarVisible_(NO)
         # make sure we're active
         NSApp.activateIgnoringOtherApps_(YES)
    def initStatusSession(self):
        '''Initialize our status session'''
        self.setWindowLevel()
        consoleuser = munki.getconsoleuser()
        if consoleuser == None or consoleuser == u"loginwindow":
            self.displayBackdropWindow()
            # needed so the window can show over the loginwindow
            self.window.setCanBecomeVisibleWithoutLogin_(True)
            self.window.setLevel_(self.window_level)

        self.window.center()
        self.messageFld.setStringValue_(
            NSLocalizedString(u"Starting…", None))
        self.detailFld.setStringValue_(u"")
        self.stopBtn.setHidden_(False)
        self.stopBtn.setEnabled_(True)
        self.stopBtnState = 0
        if self.imageFld:
            theImage = NSImage.imageNamed_("MunkiStatus")
            self.imageFld.setImage_(theImage)
        if self.progressIndicator:
            self.progressIndicator.setMinValue_(0.0)
            self.progressIndicator.setMaxValue_(100.0)
            self.progressIndicator.setIndeterminate_(True)
            self.progressIndicator.setUsesThreadedAnimation_(True)
            self.progressIndicator.startAnimation_(self)
        self.window.orderFrontRegardless()
        self.registerForNotifications()
        # start our process monitor timer so we can be notified about
        # process failure
        self.timeout_counter = 6
        self.saw_process = False
        self.timer = (NSTimer.
            scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_(
                5.0, self, self.checkProcess, None, YES))
Example #4
0
    def showLogWindow_(self, notification):
        '''Show the log window.'''

        if self.window.isVisible():
            # It's already open, just move it to front
            self.window.makeKeyAndOrderFront_(self)
            return

        consoleuser = munki.getconsoleuser()
        if consoleuser == None or consoleuser == u"loginwindow":
            self.window.setCanBecomeVisibleWithoutLogin_(True)
            self.window.setLevel_(self.getWindowLevel())

        screenRect = NSScreen.mainScreen().frame()
        windowRect = screenRect.copy()
        windowRect.origin.x = 100.0
        windowRect.origin.y = 200.0
        windowRect.size.width -= 200.0
        windowRect.size.height -= 300.0

        logfile = munki.pref('LogFile')
        self.pathControl.setURL_(NSURL.fileURLWithPath_(logfile))
        self.window.setTitle_(os.path.basename(logfile))
        self.window.setFrame_display_(windowRect, NO)
        self.window.makeKeyAndOrderFront_(self)
        self.watchLogFile_(logfile)

        # allow dragging from table view to outside of the app
        self.logView.setDraggingSourceOperationMask_forLocal_(
            NSDragOperationAll, NO)
Example #5
0
    def startMunkiStatusSession(self):
        NSLog(u"Managed Software Update.app PID: %s" % os.getpid())
        consoleuser = munki.getconsoleuser()
        if consoleuser == None or consoleuser == u"loginwindow":
            self.displayBackdropWindow()

        if self.window:
            if consoleuser == None or consoleuser == u"loginwindow":
                # needed so the window can show over the loginwindow
                self.window.setCanBecomeVisibleWithoutLogin_(True)
                self.window.setLevel_(NSScreenSaverWindowLevel - 1)
            self.window.center()
            self.messageFld.setStringValue_(
                NSLocalizedString(u"Starting…", None))
            self.detailFld.setStringValue_(u"")
            self.stopBtn.setHidden_(False)
            self.stopBtn.setEnabled_(True)
            self.stopBtnState = 0
            if self.imageFld:
                theImage = NSImage.imageNamed_("Managed Software Update")
                self.imageFld.setImage_(theImage)
            if self.progressIndicator:
                self.progressIndicator.setMinValue_(0.0)
                self.progressIndicator.setMaxValue_(100.0)
                self.progressIndicator.setIndeterminate_(True)
                self.progressIndicator.setUsesThreadedAnimation_(True)
                self.progressIndicator.startAnimation_(self)
            self.window.orderFrontRegardless()
            # start our message processing thread
            NSThread.detachNewThreadSelector_toTarget_withObject_(
                                                        self.handleSocket,
                                                        self,
                                                        None)

            self.session_started = True
Example #6
0
    def alertedToBlockingAppsRunning(self):
        '''Returns True if blocking_apps are running; alerts as a side-effect'''
        apps_to_check = []
        for update_item in MunkiItems.getUpdateList():
            if 'blocking_applications' in update_item:
                apps_to_check.extend(update_item['blocking_applications'])
            else:
                apps_to_check.extend(
                    [os.path.basename(item.get('path'))
                     for item in update_item.get('installs', [])
                     if item['type'] == 'application']
                )

        running_apps = munki.getRunningBlockingApps(apps_to_check)
        if running_apps:
            current_user = munki.getconsoleuser()
            other_users_apps = [item['display_name'] for item in running_apps
                                if item['user'] != current_user]
            my_apps = [item['display_name'] for item in running_apps
                       if item['user'] == current_user]
            msclog.log(
                "MSC", "conflicting_apps", ','.join(other_users_apps + my_apps))
            if other_users_apps:
                detailText = NSLocalizedString(
                    u"Other logged in users are using the following "
                    "applications. Try updating later when they are no longer "
                    "in use:\n\n%s",
                    u"Other Users Blocking Apps Running detail")
                alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                    NSLocalizedString(
                        u"Applications in use by others",
                        u"Other Users Blocking Apps Running title"),
                    NSLocalizedString(u"OK", u'OKButtonText'),
                    nil,
                    nil,
                    u"%@", detailText % u'\n'.join(set(other_users_apps))
                    )
            else:
                detailText = NSLocalizedString(
                    u"You must quit the following applications before "
                    "proceeding with installation or removal:\n\n%s",
                    u"Blocking Apps Running detail")
                alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                    NSLocalizedString(
                        u"Conflicting applications running",
                        u"Blocking Apps Running title"),
                    NSLocalizedString(u"OK", u"OK button title"),
                    nil,
                    nil,
                    u"%@", detailText % u'\n'.join(set(my_apps))
                    )
            alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                self.window, self,
                self.blockingAppsRunningAlertDidEnd_returnCode_contextInfo_,
                nil)
            return True
        else:
            return False
Example #7
0
    def alertedToBlockingAppsRunning(self):
        '''Returns True if blocking_apps are running; alerts as a side-effect'''
        apps_to_check = []
        for update_item in MunkiItems.getUpdateList():
            if 'blocking_applications' in update_item:
                apps_to_check.extend(update_item['blocking_applications'])
            else:
                apps_to_check.extend(
                    [os.path.basename(item.get('path'))
                     for item in update_item.get('installs', [])
                     if item['type'] == 'application']
                )

        running_apps = munki.getRunningBlockingApps(apps_to_check)
        if running_apps:
            current_user = munki.getconsoleuser()
            other_users_apps = [item['display_name'] for item in running_apps
                                if item['user'] != current_user]
            my_apps = [item['display_name'] for item in running_apps
                       if item['user'] == current_user]
            msclog.log(
                "MSC", "conflicting_apps", ','.join(other_users_apps + my_apps))
            if other_users_apps:
                detailText = NSLocalizedString(
                    u"Other logged in users are using the following "
                    "applications. Try updating later when they are no longer "
                    "in use:\n\n%s",
                    u"Other Users Blocking Apps Running detail")
                alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                    NSLocalizedString(
                        u"Applications in use by others",
                        u"Other Users Blocking Apps Running title"),
                    NSLocalizedString(u"OK", u'OKButtonText'),
                    nil,
                    nil,
                    u"%@", detailText % u'\n'.join(set(other_users_apps))
                    )
            else:
                detailText = NSLocalizedString(
                    u"You must quit the following applications before "
                    "proceeding with installation or removal:\n\n%s",
                    u"Blocking Apps Running detail")
                alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                    NSLocalizedString(
                        u"Conflicting applications running",
                        u"Blocking Apps Running title"),
                    NSLocalizedString(u"OK", u"OK button title"),
                    nil,
                    nil,
                    u"%@", detailText % u'\n'.join(set(my_apps))
                    )
            alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                self.window, self,
                self.blockingAppsRunningAlertDidEnd_returnCode_contextInfo_,
                nil)
            return True
        else:
            return False
Example #8
0
    def applicationWillFinishLaunching_(self, sender):
        '''NSApplicationDelegate method
        Sent by the default notification center immediately before the
        application object is initialized.'''

        # pylint: disable=no-self-use

        consoleuser = munki.getconsoleuser()
        if consoleuser == None or consoleuser == u"loginwindow":
            # don't show menu bar
            NSMenu.setMenuBarVisible_(NO)
            # make sure we're active
            NSApp.activateIgnoringOtherApps_(YES)
Example #9
0
    def applicationDidFinishLaunching_(self, sender):
        NSLog(u"Managed Software Update finished launching.")
        munki.log("MSU", "launched")

        runmode = NSUserDefaults.standardUserDefaults().stringForKey_("mode") or \
                  os.environ.get("ManagedSoftwareUpdateMode")
        if runmode:
            self.runmode = runmode
            NSLog("Runmode: %s" % runmode)

        # Prevent automatic relaunching at login on Lion 
        if NSApp.respondsToSelector_('disableRelaunchOnLogin'):
            NSApp.disableRelaunchOnLogin()

        consoleuser = munki.getconsoleuser()
        if consoleuser == None or consoleuser == u"loginwindow":
            # Status Window only
            NSMenu.setMenuBarVisible_(NO)
            self.munkiStatusController.startMunkiStatusSession()
        elif self.runmode == "MunkiStatus":
            self.munkiStatusController.startMunkiStatusSession()
        else:
            # user may have launched the app manually, or it may have
            # been launched by /usr/local/munki/managedsoftwareupdate
            # to display available updates
            lastcheck = NSDate.dateWithString_(munki.pref('LastCheckDate'))
            if not lastcheck or lastcheck.timeIntervalSinceNow() < -60:
                # it's been more than a minute since the last check
                self.checkForUpdates()
                return
            # do we have existing updates to display?
            if not self._listofupdates:
                self.getAvailableUpdates()
            if self._listofupdates:
                self.displayUpdatesWindow()
            else:
                # no updates available. Should we check for some?
                self.checkForUpdates()
Example #10
0
    def munkiStatusSessionEnded_(self, socketSessionResult):
        consoleuser = munki.getconsoleuser()
        if (self.runmode == "MunkiStatus" or consoleuser == None
            or consoleuser == u"loginwindow"):
            # Status Window only, so we should just quit
            munki.log("MSU", "exit_munkistatus")
            NSApp.terminate_(self)

        # The managedsoftwareupdate run will have changed state preferences
        # in ManagedInstalls.plist. Load the new values.
        munki.reload_prefs()

        alertMessageText = NSLocalizedString(u"Update check failed", None)
        if self.managedsoftwareupdate_task == "installwithnologout":
            alertMessageText = NSLocalizedString(u"Install session failed", None)

        if socketSessionResult == -1:
            # connection was dropped unexpectedly
            self.mainWindowController.theWindow.makeKeyAndOrderFront_(self)
            alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                alertMessageText,
                NSLocalizedString(u"Quit", None),
                objc.nil,
                objc.nil,
                NSLocalizedString(u"There is a configuration problem with the managed software installer. The process ended unexpectedly. Contact your systems administrator.", None))
            alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                self.mainWindowController.theWindow, self, self.quitAlertDidEnd_returnCode_contextInfo_, objc.nil)
            return

        elif socketSessionResult == -2:
            # socket timed out before connection
            self.mainWindowController.theWindow.makeKeyAndOrderFront_(self)
            alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                alertMessageText,
                NSLocalizedString(u"Quit", None),
                objc.nil,
                objc.nil,
                NSLocalizedString(u"There is a configuration problem with the managed software installer. Could not start the process. Contact your systems administrator.", None))
            alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                self.mainWindowController.theWindow, self, self.quitAlertDidEnd_returnCode_contextInfo_, objc.nil)
            return

        if self.managedsoftwareupdate_task == "installwithnologout":
            # we're done.
            munki.log("MSU", "exit_installwithnologout")
            NSApp.terminate_(self)

        elif self.managedsoftwareupdate_task == "manualcheck":
            self.managedsoftwareupdate_task = None
            self._listofupdates = []
            self.getAvailableUpdates()
            #NSLog(u"Building table of available updates.")
            self.buildUpdateTableData()
            if self._optionalInstalls:
                #NSLog(u"Building table of optional software.")
                self.buildOptionalInstallsData()
            #NSLog(u"Showing main window.")
            self.mainWindowController.theWindow.makeKeyAndOrderFront_(self)
            #NSLog(u"Main window was made key and ordered front")
            if self._listofupdates:
                return
            # no list of updates; let's check the LastCheckResult for more info
            lastCheckResult = munki.pref("LastCheckResult")
            if lastCheckResult == 0:
                munki.log("MSU", "no_updates")
                self.noUpdatesAlert()
            elif lastCheckResult == 1:
                NSApp.requestUserAttention_(NSCriticalRequest)
            elif lastCheckResult == -1:
                munki.log("MSU", "cant_update", "cannot contact server")
                alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                    NSLocalizedString(u"Cannot check for updates", None),
                    NSLocalizedString(u"Quit", None),
                    objc.nil,
                    objc.nil,
                    NSLocalizedString(u"Managed Software Update cannot contact the update server at this time.\nIf this situation continues, contact your systems administrator.", None))
                alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                    self.mainWindowController.theWindow, self, self.quitAlertDidEnd_returnCode_contextInfo_, objc.nil)
            elif lastCheckResult == -2:
                munki.log("MSU", "cant_update", "failed preflight")
                alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                    NSLocalizedString(u"Cannot check for updates", None),
                    NSLocalizedString(u"Quit",  None),
                    objc.nil,
                    objc.nil,
                    NSLocalizedString(u"Managed Software Update failed its preflight check.\nTry again later.", None))
                alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                    self.mainWindowController.theWindow, self, self.quitAlertDidEnd_returnCode_contextInfo_, objc.nil)
Example #11
0
    def applicationDidFinishLaunching_(self, sender):
        NSLog(u"Managed Software Update finished launching.")

        ver = NSBundle.mainBundle().infoDictionary().get(
            'CFBundleShortVersionString')
        NSLog("MSU GUI version: %s" % ver)
        munki.log("MSU", "launched", "VER=%s" % ver)

        runmode = NSUserDefaults.standardUserDefaults().stringForKey_("mode") or \
                  os.environ.get("ManagedSoftwareUpdateMode")
        if runmode:
            self.runmode = runmode
            NSLog("Runmode: %s" % runmode)

        # Prevent automatic relaunching at login on Lion
        if NSApp.respondsToSelector_('disableRelaunchOnLogin'):
            NSApp.disableRelaunchOnLogin()

        # register for notification messages so we can be told if available updates
        # change while we are open
        notification_center = NSDistributedNotificationCenter.defaultCenter()
        notification_center.addObserver_selector_name_object_suspensionBehavior_(
            self,
            self.updateAvailableUpdates,
            'com.googlecode.munki.ManagedSoftwareUpdate.update',
            None,
            NSNotificationSuspensionBehaviorDeliverImmediately)

        # register for notification messages so we can be told to
        # display a logout warning
        notification_center = NSDistributedNotificationCenter.defaultCenter()
        notification_center.addObserver_selector_name_object_suspensionBehavior_(
            self,
            self.forcedLogoutWarning,
            'com.googlecode.munki.ManagedSoftwareUpdate.logoutwarn',
            None,
            NSNotificationSuspensionBehaviorDeliverImmediately)

        consoleuser = munki.getconsoleuser()
        if consoleuser == None or consoleuser == u"loginwindow":
            # Status Window only
            NSMenu.setMenuBarVisible_(NO)
            self.munkiStatusController.startMunkiStatusSession()
        elif self.runmode == "MunkiStatus":
            self.munkiStatusController.startMunkiStatusSession()
        else:
            # user may have launched the app manually, or it may have
            # been launched by /usr/local/munki/managedsoftwareupdate
            # to display available updates
            if munki.thereAreUpdatesToBeForcedSoon(hours=2):
                # skip the check and just display the updates
                # by pretending the lastcheck is now
                lastcheck = NSDate.date()
            else:
                lastcheck = NSDate.dateWithString_(munki.pref('LastCheckDate'))
            if not lastcheck or lastcheck.timeIntervalSinceNow() < -60:
                # it's been more than a minute since the last check
                self.checkForUpdates()
                return
            # do we have existing updates to display?
            if not self._listofupdates:
                self.getAvailableUpdates()
            if self._listofupdates:
                self.displayUpdatesWindow()
            else:
                # no updates available. Should we check for some?
                self.checkForUpdates()
Example #12
0
    def applicationDidFinishLaunching_(self, sender):
        NSLog(u"Managed Software Update finished launching.")

        ver = NSBundle.mainBundle().infoDictionary().get(
            'CFBundleShortVersionString')
        NSLog("MSU GUI version: %s" % ver)
        munki.log("MSU", "launched", "VER=%s" % ver)

        runmode = NSUserDefaults.standardUserDefaults().stringForKey_("mode") or \
                  os.environ.get("ManagedSoftwareUpdateMode")
        if runmode:
            self.runmode = runmode
            NSLog("Runmode: %s" % runmode)

        # Prevent automatic relaunching at login on Lion
        if NSApp.respondsToSelector_('disableRelaunchOnLogin'):
            NSApp.disableRelaunchOnLogin()

        # register for notification messages so we can be told if available updates
        # change while we are open
        notification_center = NSDistributedNotificationCenter.defaultCenter()
        notification_center.addObserver_selector_name_object_suspensionBehavior_(
            self, self.updateAvailableUpdates,
            'com.googlecode.munki.ManagedSoftwareUpdate.update', None,
            NSNotificationSuspensionBehaviorDeliverImmediately)

        # register for notification messages so we can be told to
        # display a logout warning
        notification_center = NSDistributedNotificationCenter.defaultCenter()
        notification_center.addObserver_selector_name_object_suspensionBehavior_(
            self, self.forcedLogoutWarning,
            'com.googlecode.munki.ManagedSoftwareUpdate.logoutwarn', None,
            NSNotificationSuspensionBehaviorDeliverImmediately)

        consoleuser = munki.getconsoleuser()
        if consoleuser == None or consoleuser == u"loginwindow":
            # Status Window only
            NSMenu.setMenuBarVisible_(NO)
            self.munkiStatusController.startMunkiStatusSession()
        elif self.runmode == "MunkiStatus":
            self.munkiStatusController.startMunkiStatusSession()
        else:
            # user may have launched the app manually, or it may have
            # been launched by /usr/local/munki/managedsoftwareupdate
            # to display available updates
            if munki.thereAreUpdatesToBeForcedSoon(hours=2):
                # skip the check and just display the updates
                # by pretending the lastcheck is now
                lastcheck = NSDate.date()
            else:
                lastcheck = NSDate.dateWithString_(munki.pref('LastCheckDate'))
            if not lastcheck or lastcheck.timeIntervalSinceNow() < -60:
                # it's been more than a minute since the last check
                self.checkForUpdates()
                return
            # do we have existing updates to display?
            if not self._listofupdates:
                self.getAvailableUpdates()
            if self._listofupdates:
                self.displayUpdatesWindow()
            else:
                # no updates available. Should we check for some?
                self.checkForUpdates()
Example #13
0
    def munkiStatusSessionEnded_(self, socketSessionResult):
        consoleuser = munki.getconsoleuser()
        if (self.runmode == "MunkiStatus" or consoleuser == None
                or consoleuser == u"loginwindow"):
            # Status Window only, so we should just quit
            munki.log("MSU", "exit_munkistatus")
            # clear launch trigger file so we aren't immediately
            # relaunched by launchd
            munki.clearLaunchTrigger()
            NSApp.terminate_(self)

        # The managedsoftwareupdate run will have changed state preferences
        # in ManagedInstalls.plist. Load the new values.
        munki.reload_prefs()

        alertMessageText = NSLocalizedString(u"Update check failed", None)
        if self.managedsoftwareupdate_task == "installwithnologout":
            alertMessageText = NSLocalizedString(u"Install session failed",
                                                 None)

        if socketSessionResult == -1:
            # connection was dropped unexpectedly
            self.mainWindowController.theWindow.makeKeyAndOrderFront_(self)
            alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                alertMessageText, NSLocalizedString(u"Quit", None), objc.nil,
                objc.nil,
                NSLocalizedString(
                    u"There is a configuration problem with the managed software installer. The process ended unexpectedly. Contact your systems administrator.",
                    None))
            alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                self.mainWindowController.theWindow, self,
                self.quitAlertDidEnd_returnCode_contextInfo_, objc.nil)
            return

        elif socketSessionResult == -2:
            # socket timed out before connection
            self.mainWindowController.theWindow.makeKeyAndOrderFront_(self)
            alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                alertMessageText, NSLocalizedString(u"Quit", None), objc.nil,
                objc.nil,
                NSLocalizedString(
                    u"There is a configuration problem with the managed software installer. Could not start the process. Contact your systems administrator.",
                    None))
            alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                self.mainWindowController.theWindow, self,
                self.quitAlertDidEnd_returnCode_contextInfo_, objc.nil)
            return

        if self.managedsoftwareupdate_task == "installwithnologout":
            # we're done.
            munki.log("MSU", "exit_installwithnologout")
            NSApp.terminate_(self)

        elif self.managedsoftwareupdate_task == "manualcheck":
            self.managedsoftwareupdate_task = None
            self._listofupdates = []
            self.getAvailableUpdates()
            #NSLog(u"Building table of available updates.")
            self.buildUpdateTableData()
            if self._optionalInstalls:
                #NSLog(u"Building table of optional software.")
                self.buildOptionalInstallsData()
            #NSLog(u"Showing main window.")
            self.mainWindowController.theWindow.makeKeyAndOrderFront_(self)
            #NSLog(u"Main window was made key and ordered front")
            if self._listofupdates:
                return
            # no list of updates; let's check the LastCheckResult for more info
            lastCheckResult = munki.pref("LastCheckResult")
            if lastCheckResult == 0:
                munki.log("MSU", "no_updates")
                self.noUpdatesAlert()
            elif lastCheckResult == 1:
                NSApp.requestUserAttention_(NSCriticalRequest)
            elif lastCheckResult == -1:
                munki.log("MSU", "cant_update", "cannot contact server")
                alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                    NSLocalizedString(u"Cannot check for updates", None),
                    NSLocalizedString(u"Quit", None), objc.nil, objc.nil,
                    NSLocalizedString(
                        u"Managed Software Update cannot contact the update server at this time.\nIf this situation continues, contact your systems administrator.",
                        None))
                alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                    self.mainWindowController.theWindow, self,
                    self.quitAlertDidEnd_returnCode_contextInfo_, objc.nil)
            elif lastCheckResult == -2:
                munki.log("MSU", "cant_update", "failed preflight")
                alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                    NSLocalizedString(u"Cannot check for updates", None),
                    NSLocalizedString(u"Quit", None), objc.nil, objc.nil,
                    NSLocalizedString(
                        u"Managed Software Update failed its preflight check.\nTry again later.",
                        None))
                alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                    self.mainWindowController.theWindow, self,
                    self.quitAlertDidEnd_returnCode_contextInfo_, objc.nil)
Example #14
0
    def applicationDidFinishLaunching_(self, sender):
        NSLog(u"Managed Software Update finished launching.")

        ver = NSBundle.mainBundle().infoDictionary().get(
            'CFBundleShortVersionString')
        NSLog("MSU GUI version: %s" % ver)
        munki.log("MSU", "launched", "VER=%s" % ver)

        runmode = (NSUserDefaults.standardUserDefaults().stringForKey_("mode") 
                   or os.environ.get("ManagedSoftwareUpdateMode"))
        if runmode:
            self.runmode = runmode
            NSLog("Runmode: %s" % runmode)
        else:
            consoleuser = munki.getconsoleuser()
            if consoleuser == None or consoleuser == u"loginwindow":
                # we're at the loginwindow, so display MunkiStatus
                self.runmode = "MunkiStatus"

        # Prevent automatic relaunching at login on Lion
        if NSApp.respondsToSelector_('disableRelaunchOnLogin'):
            NSApp.disableRelaunchOnLogin()

        # register for notification messages so we can be told if available 
        # updates change while we are open
        notification_center = NSDistributedNotificationCenter.defaultCenter()
        notification_center.addObserver_selector_name_object_suspensionBehavior_(
            self,
            self.updateAvailableUpdates,
            'com.googlecode.munki.ManagedSoftwareUpdate.update',
            None,
            NSNotificationSuspensionBehaviorDeliverImmediately)

        # register for notification messages so we can be told to
        # display a logout warning
        notification_center = NSDistributedNotificationCenter.defaultCenter()
        notification_center.addObserver_selector_name_object_suspensionBehavior_(
            self,
            self.forcedLogoutWarning,
            'com.googlecode.munki.ManagedSoftwareUpdate.logoutwarn',
            None,
            NSNotificationSuspensionBehaviorDeliverImmediately)

        if self.runmode == "MunkiStatus":
            self.munkiStatusController.startMunkiStatusSession()
        else:
            # user may have launched the app manually, or it may have
            # been launched by /usr/local/munki/managedsoftwareupdate
            # to display available updates
            if munki.thereAreUpdatesToBeForcedSoon(hours=2):
                # skip the check and just display the updates
                # by pretending the lastcheck is now
                lastcheck = NSDate.date()
            else:
                lastcheck = NSDate.dateWithString_(munki.pref('LastCheckDate'))
            # if there is no lastcheck timestamp, check for updates.
            if not lastcheck:
                self.checkForUpdates()
                return

            # otherwise, only check for updates if the last check is over the
            # configured manualcheck cache age max.
            max_cache_age = (
                munki.pref('CheckResultsCacheSeconds') or
                DEFAULT_GUI_CACHE_AGE_SECS)
            if lastcheck.timeIntervalSinceNow() * -1 > int(max_cache_age):
                self.checkForUpdates()
                return

            # if needed, get updates from InstallInfo.
            if not self._listofupdates:
                self.getAvailableUpdates()
            # if updates exist, display them.
            if self._listofupdates:
                self.displayUpdatesWindow()
            else:
                # only check for updates if cache secs config is not defined.
                if munki.pref('CheckResultsCacheSeconds'):
                    self.mainWindowController.theWindow.makeKeyAndOrderFront_(
                        self)
                    self.noUpdatesAlert()
                else:
                    self.checkForUpdates()
Example #15
0
 def applicationWillFinishLaunching_(self, sender):
     consoleuser = munki.getconsoleuser()
     if consoleuser == None or consoleuser == u"loginwindow":
         # don't show menu bar
         NSMenu.setMenuBarVisible_(NO)