示例#1
0
    def alertIfBlockingAppsRunning(self):
        apps_to_check = []
        for update_item in self._listofupdates:
            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:
            alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                    NSLocalizedString(u"Conflicting applications running", None),
                    NSLocalizedString(u"OK", None),
                    objc.nil,
                    objc.nil,
                    NSLocalizedString(u"You must quit the following applications before proceeding with installation:\n\n%s", None) % '\n'.join(running_apps))
            munki.log("MSU", "conflicting_apps", ','.join(running_apps))
            self._currentAlert = alert
            alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                self.mainWindowController.theWindow, self, self.blockingAppsRunningAlertDidEnd_returnCode_contextInfo_, objc.nil)
            return True
        else:
            return False
示例#2
0
 def logoutAlertDidEnd_returnCode_contextInfo_(self, alert, returncode,
                                               contextinfo):
     self._currentAlert = None
     if returncode == NSAlertDefaultReturn:
         if self.alertIfRunnningOnBattery():
             munki.log("user", "alerted_on_battery_power_and_cancelled")
             return
         NSLog("User chose to logout")
         munki.log("user", "install_with_logout")
         result = munki.logoutAndUpdate()
         if result:
             self.installSessionErrorAlert()
     elif returncode == NSAlertAlternateReturn:
         NSLog("User cancelled")
         munki.log("user", "cancelled")
     elif returncode == NSAlertOtherReturn:
         # dismiss the alert sheet now because we might display
         # another alert
         alert.window().orderOut_(self)
         if self.alertIfBlockingAppsRunning():
             return
         if self.alertIfRunnningOnBattery():
             munki.log("user", "alerted_on_battery_power_and_cancelled")
             return
         NSLog("User chose to update without logging out")
         munki.log("user", "install_without_logout")
         result = munki.justUpdate()
         if result:
             self.installSessionErrorAlert()
         else:
             self.managedsoftwareupdate_task = "installwithnologout"
             self.mainWindowController.theWindow.orderOut_(self)
             self.munkiStatusController.window.makeKeyAndOrderFront_(self)
             self.munkiStatusController.startMunkiStatusSession()
示例#3
0
 def logoutAlertDidEnd_returnCode_contextInfo_(
                                     self, alert, returncode, contextinfo):
     self._currentAlert = None
     if returncode == NSAlertDefaultReturn:
         if self.alertIfRunnningOnBattery():
             munki.log("user", "alerted_on_battery_power_and_cancelled")
             return
         NSLog("User chose to logout")
         munki.log("user", "install_with_logout")
         result = munki.logoutAndUpdate()
         if result:
             self.installSessionErrorAlert()
     elif returncode == NSAlertAlternateReturn:
         NSLog("User cancelled")
         munki.log("user", "cancelled")
     elif returncode == NSAlertOtherReturn:
         # dismiss the alert sheet now because we might display
         # another alert
         alert.window().orderOut_(self)
         if self.alertIfBlockingAppsRunning():
             return
         if self.alertIfRunnningOnBattery():
             munki.log("user", "alerted_on_battery_power_and_cancelled")
             return
         NSLog("User chose to update without logging out")
         munki.log("user", "install_without_logout")
         result = munki.justUpdate()
         if result:
             self.installSessionErrorAlert()
         else:
             self.managedsoftwareupdate_task = "installwithnologout"
             self.mainWindowController.theWindow.orderOut_(self)
             self.munkiStatusController.window.makeKeyAndOrderFront_(self)
             self.munkiStatusController.startMunkiStatusSession()
示例#4
0
 def confirmLaterAlertDidEnd_returnCode_contextInfo_(self, alert, returncode, contextinfo):
     self._currentAlert = None
     if returncode == 0:
         munki.log("user", "exit_later_clicked")
         NSApp.terminate_(self)
     else:
         pass
示例#5
0
 def laterBtnClicked(self):
     if munki.thereAreUpdatesToBeForcedSoon():
         deadline = munki.earliestForceInstallDate()
         time_til_logout = deadline.timeIntervalSinceNow()
         if time_til_logout > 0:
             deadline_str = munki.stringFromDate(deadline)
             formatString = NSLocalizedString(
                 (u"One or more updates must be installed by %s. A logout "
                 "may be forced if you wait too long to update."), None) 
             infoText = formatString % deadline_str
         else:
             infoText = NSLocalizedString(
                 (u"One or more mandatory updates are overdue for "
                 "installation. A logout will be forced soon."), None)
         alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                 NSLocalizedString(u"Manadatory Updates Pending", None),
                 NSLocalizedString(u"Show updates", None),
                 NSLocalizedString(u"Update later", None),
                 objc.nil,
                 infoText)
         self._currentAlert = alert
         alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
             self.mainWindowController.theWindow, self, 
             self.confirmLaterAlertDidEnd_returnCode_contextInfo_, objc.nil)
     else:
         munki.log("user", "exit_later_clicked")
         NSApp.terminate_(self)
示例#6
0
 def alertIfRunnningOnBattery(self):
     '''Returns True if we are running on battery and user clicks
     the Cancel button'''
     power_info = munki.getPowerInfo()
     if (power_info.get('PowerSource') == 'Battery Power'
         and power_info.get('BatteryCharge', 0) < 50):
         alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
             NSLocalizedString(
                 u"Your computer is not connected to a power source.", None),
             NSLocalizedString(u"Continue", None),
             NSLocalizedString(u"Cancel", None),
             objc.nil,
             NSLocalizedString(
                 (u"For best results, you should connect your computer to a "
                 "power source before updating. Are you sure you want to "
                 "continue the update?"), None))
         munki.log("MSU", "alert_on_battery_power")
         # making UI consistent with Apple Software Update...
         # set Cancel button to be activated by return key
         alert.buttons()[1].setKeyEquivalent_('\r')
         # set Continue button to be activated by Escape key
         alert.buttons()[0].setKeyEquivalent_(chr(27))
         buttonPressed = alert.runModal()
         if buttonPressed == NSAlertAlternateReturn:
             return True
     return False
示例#7
0
    def alertIfBlockingAppsRunning(self):
        apps_to_check = []
        for update_item in self._listofupdates:
            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:
            alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                NSLocalizedString(u"Conflicting applications running", None),
                NSLocalizedString(u"OK", None), objc.nil, objc.nil,
                NSLocalizedString(
                    u"You must quit the following applications before proceeding with installation:\n\n%s",
                    None) % '\n'.join(running_apps))
            munki.log("MSU", "conflicting_apps", ','.join(running_apps))
            self._currentAlert = alert
            alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
                self.mainWindowController.theWindow, self,
                self.blockingAppsRunningAlertDidEnd_returnCode_contextInfo_,
                objc.nil)
            return True
        else:
            return False
示例#8
0
 def confirmLaterAlertDidEnd_returnCode_contextInfo_(
         self, alert, returncode, contextinfo):
     self._currentAlert = None
     if returncode == 0:
         munki.log("user", "exit_later_clicked")
         NSApp.terminate_(self)
     else:
         pass
示例#9
0
 def forceLogoutWarningDidEnd_returnCode_contextInfo_(
         self, alert, returncode, contextinfo):
     self._currentAlert = None
     btn_pressed = self._force_warning_btns.get(returncode)
     if btn_pressed == self._force_warning_logout_btn:
         munki.log("user", "install_with_logout")
         result = munki.logoutAndUpdate()
     elif btn_pressed == self._force_warning_ok_btn:
         munki.log("user", "dismissed_forced_logout_warning")
示例#10
0
 def forceLogoutWarningDidEnd_returnCode_contextInfo_(
                                     self, alert, returncode, contextinfo):
     self._currentAlert = None
     btn_pressed = self._force_warning_btns.get(returncode)
     if btn_pressed == self._force_warning_logout_btn:
         munki.log("user", "install_with_logout")
         result = munki.logoutAndUpdate()
     elif btn_pressed == self._force_warning_ok_btn:
         munki.log("user", "dismissed_forced_logout_warning")
示例#11
0
 def quitAlertDidEnd_returnCode_contextInfo_(self, alert, returncode, contextinfo):
     if returncode == 1:
         munki.log("user", "quit")
         NSApp.terminate_(self)
     else:
         munki.log("user", "view_optional_software")
         self.update_view_controller.optionalSoftwareBtn.setHidden_(NO)
         self.buildOptionalInstallsData()
         self.mainWindowController.theTabView.selectNextTabViewItem_(self)
示例#12
0
 def installSessionErrorAlert(self):
     alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
             NSLocalizedString(u"Cannot start installation session", None),
             NSLocalizedString(u"Quit", None),
             objc.nil,
             objc.nil,
             NSLocalizedString(u"There is a configuration problem with the managed software installer. Could not start the install session. Contact your systems administrator.", None))
     munki.log("MSU", "cannot_start")
     alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
         self.mainWindowController.theWindow, self, self.quitAlertDidEnd_returnCode_contextInfo_, objc.nil)
示例#13
0
 def quitAlertDidEnd_returnCode_contextInfo_(self, alert, returncode,
                                             contextinfo):
     self._currentAlert = None
     if returncode == NSAlertDefaultReturn:
         munki.log("user", "quit")
         NSApp.terminate_(self)
     elif returncode == NSAlertAlternateReturn:
         munki.log("user", "view_optional_software")
         self.update_view_controller.optionalSoftwareBtn.setHidden_(NO)
         self.buildOptionalInstallsData()
         self.mainWindowController.theTabView.selectNextTabViewItem_(self)
示例#14
0
 def installSessionErrorAlert(self):
     alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
         NSLocalizedString(u"Cannot start installation session", None),
         NSLocalizedString(u"Quit", None), objc.nil, objc.nil,
         NSLocalizedString(
             u"There is a configuration problem with the managed software installer. Could not start the install session. Contact your systems administrator.",
             None))
     munki.log("MSU", "cannot_start")
     self._currentAlert = alert
     alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
         self.mainWindowController.theWindow, self,
         self.quitAlertDidEnd_returnCode_contextInfo_, objc.nil)
示例#15
0
 def forceLogoutWarningDidEnd_returnCode_contextInfo_(self, alert, returncode, contextinfo):
     self._currentAlert = None
     btn_pressed = self._force_warning_btns.get(returncode)
     if not btn_pressed:
         # sheet was dismissed via NSApp.endSheet()
         # and not via button press, so do nothing
         pass
     elif btn_pressed == self._force_warning_logout_btn:
         munki.log("user", "install_with_logout")
         result = munki.logoutAndUpdate()
     else:
         munki.log("user", "dismissed_forced_logout_warning")
示例#16
0
    def getAvailableUpdates(self):
        updatelist = []
        installinfo = munki.getInstallInfo()
        if installinfo:
            updatelist = installinfo.get("managed_installs", [])
            for update in updatelist:
                force_install_after_date = update.get('force_install_after_date')
                if force_install_after_date:
                    # insert installation deadline into description
                    local_date = munki.discardTimeZoneFromDate(force_install_after_date)
                    date_str = munki.stringFromDate(local_date)
                    forced_date_text = NSLocalizedString(u"This item must be installed by ", None)
                    description = update["description"]
                    # prepend deadline info to description. This will fail if the description is HTML...
                    update["description"] = forced_date_text + date_str + "\n\n" + description

            if installinfo.get("removals"):
                removallist = installinfo.get("removals")
                restartNeeded = False
                showRemovalDetail = munki.getRemovalDetailPrefs()
                for item in removallist:
                    if item.get("RestartAction") == "RequireRestart" or item.get("RestartAction") == "RecommendRestart":
                        restartNeeded = True
                    if showRemovalDetail:
                        item["display_name"] = ((item.get("display_name") or item.get("name", ""))
                                                + NSLocalizedString(u" (will be removed)", None))
                        item["description"] = NSLocalizedString(u"This item will be removed.", None)
                        updatelist.append(item)
                if not showRemovalDetail:
                    row = {}
                    row["display_name"] = NSLocalizedString(u"Software removals", None)
                    row["version"] = ""
                    row["description"] = NSLocalizedString(u"Scheduled removal of managed software.", None)
                    if restartNeeded:
                        row["RestartAction"] = "RequireRestart"
                    updatelist.append(row)

        if updatelist:
            self._listofupdates = updatelist
            self.enableUpdateNowBtn_(YES)
            #self.performSelector_withObject_afterDelay_("enableUpdateNowBtn:", YES, 4)
            self.getOptionalInstalls()
        else:
            appleupdates = munki.getAppleUpdates()
            if appleupdates:
                munki.log("MSU", "appleupdates")
                self._listofupdates = appleupdates.get("AppleUpdates", [])
                self.update_view_controller.updateNowBtn.setEnabled_(YES)
                self.update_view_controller.optionalSoftwareBtn.setHidden_(YES)
            else:
                self.update_view_controller.updateNowBtn.setEnabled_(NO)
                self.getOptionalInstalls()
示例#17
0
 def forceLogoutWarningDidEnd_returnCode_contextInfo_(
         self, alert, returncode, contextinfo):
     self._currentAlert = None
     btn_pressed = self._force_warning_btns.get(returncode)
     if not btn_pressed:
         # sheet was dismissed via NSApp.endSheet()
         # and not via button press, so do nothing
         pass
     elif btn_pressed == self._force_warning_logout_btn:
         munki.log("user", "install_with_logout")
         result = munki.logoutAndUpdate()
     else:
         munki.log("user", "dismissed_forced_logout_warning")
示例#18
0
    def getAvailableUpdates(self):
        updatelist = []
        installinfo = munki.getInstallInfo()
        if installinfo:
            updatelist = installinfo.get("managed_installs", [])
            if installinfo.get("removals"):
                removallist = installinfo.get("removals")
                restartNeeded = False
                showRemovalDetail = munki.getRemovalDetailPrefs()
                for item in removallist:
                    if item.get("RestartAction") == "RequireRestart" or item.get("RestartAction") == "RecommendRestart":
                        restartNeeded = True
                    if showRemovalDetail:
                        item["display_name"] = ((item.get("display_name") or item.get("name", ""))
                                                + NSLocalizedString(u" (will be removed)", None))
                        item["description"] = NSLocalizedString(u"This item will be removed.", None)
                        updatelist.append(item)
                if not showRemovalDetail:
                    row = {}
                    row["display_name"] = NSLocalizedString(u"Software removals", None)
                    row["version"] = ""
                    row["description"] = NSLocalizedString(u"Scheduled removal of managed software.", None)
                    if restartNeeded:
                        row["RestartAction"] = "RequireRestart"
                    updatelist.append(row)

        if updatelist:
            self._listofupdates = updatelist
            self.enableUpdateNowBtn_(YES)
            #self.performSelector_withObject_afterDelay_("enableUpdateNowBtn:", YES, 4)
            self.getOptionalInstalls()
        else:
            appleupdates = munki.getAppleUpdates()
            if appleupdates:
                munki.log("MSU", "appleupdates")
                self._listofupdates = appleupdates.get("AppleUpdates", [])
                self.update_view_controller.updateNowBtn.setEnabled_(YES)
                self.update_view_controller.optionalSoftwareBtn.setHidden_(YES)
            else:
                self.update_view_controller.updateNowBtn.setEnabled_(NO)
                self.getOptionalInstalls()
示例#19
0
    def forcedLogoutWarning(self, notification_obj):
        NSApp.activateIgnoringOtherApps_(True)
        info = notification_obj.userInfo()
        moreText = NSLocalizedString(
            (u"\nAll pending updates will be installed. Unsaved work will be "
            "lost.\nYou may avoid the forced logout by logging out now."), None)
        logout_time = None
        if info:
            logout_time = info.get('logout_time')
        elif munki.thereAreUpdatesToBeForcedSoon():
            logout_time = munki.earliestForceInstallDate()
        if not logout_time:
            return
        time_til_logout = int(logout_time.timeIntervalSinceNow() / 60)
        if time_til_logout > 55:
            deadline_str = munki.stringFromDate(logout_time)
            munki.log("user", "forced_logout_warning_initial")
            formatString = NSLocalizedString(
                    u"A logout will be forced at approximately %s.", None) 
            infoText = formatString % deadline_str + moreText
        elif time_til_logout > 0:
            munki.log("user", "forced_logout_warning_%s" % time_til_logout)
            formatString = NSLocalizedString(
                    u"A logout will be forced in less than %s minutes.", None) 
            infoText = formatString % time_til_logout + moreText
        else:
            munki.log("user", "forced_logout_warning_final")
            infoText = NSLocalizedString(
                (u"A logout will be forced in less than a minute.\nAll pending "
                "updates will be installed. Unsaved work will be lost."), None)

        # Set the OK button to default, unless less than 5 minutes to logout
        # in which case only the Logout button should be displayed.
        self._force_warning_logout_btn = NSLocalizedString(
            u"Log out and update now", None)
        self._force_warning_ok_btn = NSLocalizedString(u"OK", None)
        if time_til_logout > 5:
            self._force_warning_btns = {
                NSAlertDefaultReturn: self._force_warning_ok_btn,
                NSAlertAlternateReturn: self._force_warning_logout_btn,
            }
        else:
            self._force_warning_btns = {
                NSAlertDefaultReturn: self._force_warning_logout_btn,
                NSAlertAlternateReturn: objc.nil,
            }

        if self._currentAlert:
            NSApp.endSheet_(self._currentAlert.window())
            self._currentAlert = None
        alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
                    NSLocalizedString(
                        u"Forced Logout for Mandatory Install", None),
                    self._force_warning_btns[NSAlertDefaultReturn],
                    self._force_warning_btns[NSAlertAlternateReturn],
                    objc.nil,
                    infoText)
        self._currentAlert = alert
        alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
            self.mainWindowController.theWindow, self, self.forceLogoutWarningDidEnd_returnCode_contextInfo_, objc.nil)
示例#20
0
 def logoutAlertDidEnd_returnCode_contextInfo_(self, alert, returncode, contextinfo):
     if returncode == 0:
         NSLog("User cancelled")
         munki.log("user", "cancelled")
     elif returncode == 1:
         NSLog("User chose to log out")
         munki.log("user", "install_with_logout")
         result = munki.logoutAndUpdate()
         if result:
             self.installSessionErrorAlert()
     elif returncode == -1:
         # dismiss the alert sheet now because we might display
         # another alert
         alert.window().orderOut_(self)
         if self.alertIfBlockingAppsRunning():
             pass
         else:
             NSLog("User chose to update without logging out")
             munki.log("user", "install_without_logout")
             result = munki.justUpdate()
             if result:
                 self.installSessionErrorAlert()
             else:
                 self.managedsoftwareupdate_task = "installwithnologout"
                 self.mainWindowController.theWindow.orderOut_(self)
                 self.munkiStatusController.window.makeKeyAndOrderFront_(self)
                 self.munkiStatusController.startMunkiStatusSession()
示例#21
0
    def forcedLogoutWarning(self, notification_obj):
        NSApp.activateIgnoringOtherApps_(True)
        info = notification_obj.userInfo()
        moreText = NSLocalizedString(
            u"\nAll pending updates will be installed. Unsaved work will be lost.\nYou may avoid the forced logout by logging out now.",
            None)
        logout_time = None
        if info:
            logout_time = info.get('logout_time')
        elif munki.thereAreUpdatesToBeForcedSoon():
            logout_time = munki.earliestForceInstallDate()
        if not logout_time:
            return
        time_til_logout = int(logout_time.timeIntervalSinceNow() / 60)
        if time_til_logout > 55:
            deadline_str = munki.stringFromDate(logout_time)
            munki.log("user", "forced_logout_warning_initial")
            infoText = NSLocalizedString(
                u"A logout will be forced at approximately %s.",
                None) % deadline_str + moreText
        elif time_til_logout > 0:
            munki.log("user", "forced_logout_warning_%s" % time_til_logout)
            infoText = NSLocalizedString(
                u"A logout will be forced in less than %s minutes.",
                None) % time_til_logout + moreText
        else:
            munki.log("user", "forced_logout_warning_final")
            infoText = NSLocalizedString(
                u"A logout will be forced in less than a minute.\nAll pending updates will be installed. Unsaved work will be lost.",
                None)

        # Set the OK button to default, unless less than 5 minutes to logout
        # in which case only the Logout button should be displayed.
        self._force_warning_logout_btn = NSLocalizedString(
            u"Logout and update now", None)
        self._force_warning_ok_btn = NSLocalizedString(u"OK", None)
        if time_til_logout > 5:
            self._force_warning_btns = {
                NSAlertDefaultReturn: self._force_warning_ok_btn,
                NSAlertAlternateReturn: self._force_warning_logout_btn,
            }
        else:
            self._force_warning_btns = {
                NSAlertDefaultReturn: self._force_warning_logout_btn,
                NSAlertAlternateReturn: objc.nil,
            }

        if self._currentAlert:
            NSApp.endSheet_(self._currentAlert.window())
            self._currentAlert = None
        alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
            NSLocalizedString(u"Forced Logout for Mandatory Install", None),
            self._force_warning_btns[NSAlertDefaultReturn],
            self._force_warning_btns[NSAlertAlternateReturn], objc.nil,
            infoText)
        self._currentAlert = alert
        alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
            self.mainWindowController.theWindow, self,
            self.forceLogoutWarningDidEnd_returnCode_contextInfo_, objc.nil)
示例#22
0
 def alertIfRunnningOnBattery(self):
     power_info = munki.getPowerInfo()
     if (power_info.get('PowerSource') == 'Battery Power'
             and power_info.get('BatteryCharge', 0) < 50):
         alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
             NSLocalizedString(
                 u"Your computer is not connected to a power source.",
                 None), NSLocalizedString(u"Continue", None),
             NSLocalizedString(u"Cancel", None), objc.nil,
             NSLocalizedString(
                 u"For best results, you should connect your computer to a power source before updating. Are you sure you want to continue the update?",
                 None))
         munki.log("MSU", "alert_on_battery_power")
         # making UI consistent with Apple Software Update...
         # set Cancel button to be activated by return key
         alert.buttons()[1].setKeyEquivalent_('\r')
         # set Ccontinue button to be activated by Escape key
         alert.buttons()[0].setKeyEquivalent_(chr(27))
         buttonPressed = alert.runModal()
         if buttonPressed == NSAlertAlternateReturn:
             return True
     return False
示例#23
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()
示例#24
0
 def laterBtnClicked(self):
     if munki.thereAreUpdatesToBeForcedSoon():
         deadline = munki.earliestForceInstallDate()
         time_til_logout = deadline.timeIntervalSinceNow()
         if time_til_logout > 0:
             deadline_str = munki.stringFromDate(deadline)
             infoText = NSLocalizedString(
                 "One or more updates must be installed by %s. A logout may be forced if you wait too long to update.",
                 None) % deadline_str
         else:
             infoText = NSLocalizedString(
                 "One or more mandatory updates are overdue for installation. A logout will be forced soon.",
                 None)
         alert = NSAlert.alertWithMessageText_defaultButton_alternateButton_otherButton_informativeTextWithFormat_(
             NSLocalizedString(u"Manadatory Updates Pending", None),
             NSLocalizedString(u"Show updates", None),
             NSLocalizedString(u"Update later", None), objc.nil, infoText)
         self._currentAlert = alert
         alert.beginSheetModalForWindow_modalDelegate_didEndSelector_contextInfo_(
             self.mainWindowController.theWindow, self,
             self.confirmLaterAlertDidEnd_returnCode_contextInfo_, objc.nil)
     else:
         munki.log("user", "exit_later_clicked")
         NSApp.terminate_(self)
示例#25
0
 def quitAlertDidEnd_returnCode_contextInfo_(
                                     self, alert, returncode, contextinfo):
     self._currentAlert = None
     if returncode == NSAlertDefaultReturn:
         munki.log("user", "quit")
         NSApp.terminate_(self)
     elif returncode == NSAlertAlternateReturn:
         munki.log("user", "view_optional_software")
         self.update_view_controller.optionalSoftwareBtn.setHidden_(NO)
         self.buildOptionalInstallsData()
         self.mainWindowController.theTabView.selectNextTabViewItem_(self)
     elif returncode == NSAlertOtherReturn:
         munki.log("user", "refresh_clicked")
         self.checkForUpdates()
         return
示例#26
0
    def getAvailableUpdates(self):
        updatelist = []
        installinfo = munki.getInstallInfo()
        if installinfo:
            updatelist = installinfo.get("managed_installs", [])
            for update in updatelist:
                force_install_after_date = update.get(
                    'force_install_after_date')
                if force_install_after_date:
                    # insert installation deadline into description
                    local_date = munki.discardTimeZoneFromDate(
                        force_install_after_date)
                    date_str = munki.stringFromDate(local_date)
                    forced_date_text = NSLocalizedString(
                        u"This item must be installed by ", None)
                    description = update["description"]
                    # prepend deadline info to description. This will fail if the description is HTML...
                    update[
                        "description"] = forced_date_text + date_str + "\n\n" + description

            if installinfo.get("removals"):
                removallist = installinfo.get("removals")
                restartNeeded = False
                showRemovalDetail = munki.getRemovalDetailPrefs()
                for item in removallist:
                    if item.get(
                            "RestartAction") == "RequireRestart" or item.get(
                                "RestartAction") == "RecommendRestart":
                        restartNeeded = True
                    if showRemovalDetail:
                        item["display_name"] = (
                            (item.get("display_name") or item.get("name", ""))
                            + NSLocalizedString(u" (will be removed)", None))
                        item["description"] = NSLocalizedString(
                            u"This item will be removed.", None)
                        updatelist.append(item)
                if not showRemovalDetail:
                    row = {}
                    row["display_name"] = NSLocalizedString(
                        u"Software removals", None)
                    row["version"] = ""
                    row["description"] = NSLocalizedString(
                        u"Scheduled removal of managed software.", None)
                    if restartNeeded:
                        row["RestartAction"] = "RequireRestart"
                    updatelist.append(row)

        if updatelist:
            self._sortUpdateList(updatelist)
            self._listofupdates = updatelist
            self.enableUpdateNowBtn_(YES)
            #self.performSelector_withObject_afterDelay_("enableUpdateNowBtn:", YES, 4)
            self.getOptionalInstalls()
        else:
            appleupdates = munki.getAppleUpdates()
            if appleupdates:
                munki.log("MSU", "appleupdates")
                self._listofupdates = appleupdates.get("AppleUpdates", [])
                self.update_view_controller.updateNowBtn.setEnabled_(YES)
                self.update_view_controller.optionalSoftwareBtn.setHidden_(YES)
            else:
                self._listofupdates = []
                self.update_view_controller.updateNowBtn.setEnabled_(NO)
                self.getOptionalInstalls()
示例#27
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)
示例#28
0
 def optionalSoftwareBtnClicked_(self, sender):
     # switch to optional software pane
     munki.log("user", "view_optional_software")
     self.window_controller.theTabView.selectNextTabViewItem_(sender)
     NSApp.delegate().optional_view_controller.AddRemoveBtn.setEnabled_(NO)
示例#29
0
 def optionalSoftwareBtnClicked_(self, sender):
     # switch to optional software pane
     munki.log("user", "view_optional_software")
     self.window_controller.theTabView.selectNextTabViewItem_(sender)
     NSApp.delegate().optional_view_controller.AddRemoveBtn.setEnabled_(NO)
示例#30
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()
示例#31
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()
示例#32
0
 def laterBtnClicked_(self, sender):
     munki.log("user", "exit_later_clicked")
     NSApp.terminate_(self)
示例#33
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)
示例#34
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()