Ejemplo n.º 1
0
def update_and_restart(tempdir):
    import wx

    updater = os.path.join(os.getcwd(), "mac_updater.pyc")

    from Authorization import Authorization, kAuthorizationFlagDestroyRights
    auth = Authorization(destroyflags=(kAuthorizationFlagDestroyRights, ))
    try:
        python = sys.executable
        pipe = auth.executeWithPrivileges(python, updater, tempdir)

        output = pipe.read()

        if output.find("error") != -1:
            wx.MessageBox(
                _("Error while updating Digsby. Please restart and try again, or grab the latest version from digsby.com. Digsby will now shut down."
                  ))
            pipe.close()
            wx.GetApp().ExitMainLoop()
            return

        pipe.close()

        wx.MessageBox(_("Updated successfully. Digsby now needs to restart."))

        os.spawnv(os.P_NOWAIT, python, ["python", updater, "restart"])
        wx.GetApp().ExitMainLoop()

    except:
        wx.MessageBox(
            _("Unable to authenticate. Please restart and try again."))
Ejemplo n.º 2
0
def update_and_restart(tempdir):
    import wx

    updater = os.path.join(os.getcwd(), "mac_updater.pyc")

    from Authorization import Authorization, kAuthorizationFlagDestroyRights
    auth = Authorization(destroyflags=(kAuthorizationFlagDestroyRights,))
    try:
        python = sys.executable
        pipe = auth.executeWithPrivileges(python, updater, tempdir)

        output = pipe.read()

        if output.find("error") != -1:
            wx.MessageBox(_("Error while updating Digsby. Please restart and try again, or grab the latest version from digsby.com. Digsby will now shut down."))
            pipe.close()
            wx.GetApp().ExitMainLoop()
            return

        pipe.close()

        wx.MessageBox(_("Updated successfully. Digsby now needs to restart."))

        os.spawnv(os.P_NOWAIT, python, ["python", updater, "restart"])
        wx.GetApp().ExitMainLoop()

    except:
        wx.MessageBox(_("Unable to authenticate. Please restart and try again."))
Ejemplo n.º 3
0
def main():
    auth = Authorization(destroyflags=(kAuthorizationFlagDestroyRights,))
    fd, name = tempfile.mkstemp('.py')
    os.write(fd, AUTHORIZEDTOOL)
    os.close(fd)
    os.chmod(name, 0700)
    try:
        pipe = auth.executeWithPrivileges(name)
        sys.stdout.write(pipe.read())
        pipe.close()
    finally:
        os.unlink(name)
Ejemplo n.º 4
0
def main():
    auth = Authorization(destroyflags=(kAuthorizationFlagDestroyRights, ))
    fd, name = tempfile.mkstemp('.py')
    os.write(fd, AUTHORIZEDTOOL)
    os.close(fd)
    os.chmod(name, 0700)
    try:
        pipe = auth.executeWithPrivileges(name)
        sys.stdout.write(pipe.read())
        pipe.close()
    finally:
        os.unlink(name)
Ejemplo n.º 5
0
def do_it(scripts, links):
    import os, tempfile, traceback
    from Authorization import Authorization, kAuthorizationFlagDestroyRights
    r1, r2 = DEST_PATH, links
    bad = False
    for s, l in zip(scripts, links):
        if os.path.exists(l) and os.path.exists(os.path.realpath(l)):
            continue
        bad = True
        break
    if bad:
        ph, pp = os.environ.get('PYTHONHOME',
                                None), os.environ.get('PYTHONPATH', None)
        auth = Authorization(destroyflags=(kAuthorizationFlagDestroyRights, ))
        fd, name = tempfile.mkstemp('.py')
        os.write(fd, AUTHTOOL % (repr(scripts), repr(links)))
        os.close(fd)
        os.chmod(name, 0700)
        try:
            if pp:
                del os.environ['PYTHONPATH']
            if ph:
                del os.environ['PYTHONHOME']
            pipe = auth.executeWithPrivileges(name)
            try:
                sys.stdout.write(pipe.read())
            except:
                sys.stdout.write(pipe.read())  # Probably EINTR
            pipe.close()
        except:
            r1, r2 = None, traceback.format_exc()
        finally:
            os.unlink(name)
            if pp:
                os.environ['PYTHONPATH'] = pp
            if ph:
                os.environ['PYTHONHOME'] = ph

    return r1, r2
Ejemplo n.º 6
0
def do_it(scripts, links):
    import os, tempfile, traceback
    from Authorization import Authorization, kAuthorizationFlagDestroyRights
    r1, r2 = DEST_PATH, links
    bad = False
    for s, l in zip(scripts, links):
        if os.path.exists(l) and os.path.exists(os.path.realpath(l)):
            continue
        bad = True
        break
    if bad:
        ph, pp = os.environ.get('PYTHONHOME', None), os.environ.get('PYTHONPATH', None)
        auth = Authorization(destroyflags=(kAuthorizationFlagDestroyRights,))
        fd, name = tempfile.mkstemp('.py')
        os.write(fd, AUTHTOOL % (repr(scripts), repr(links)))
        os.close(fd)
        os.chmod(name, 0700)
        try:
            if pp:
                del os.environ['PYTHONPATH']
            if ph:
                del os.environ['PYTHONHOME']
            pipe = auth.executeWithPrivileges(name)
            try:
                sys.stdout.write(pipe.read())
            except:
                sys.stdout.write(pipe.read()) # Probably EINTR
            pipe.close()
        except:
            r1, r2 = None, traceback.format_exc()
        finally:
            os.unlink(name)
            if pp:
                os.environ['PYTHONPATH'] = pp
            if ph:
                os.environ['PYTHONHOME'] = ph

    return r1, r2
Ejemplo n.º 7
0
class MEMPController (NSWindowController):
    startButton = objc.IBOutlet()
    stopButton = objc.IBOutlet()
    startNginx = objc.IBOutlet()
    stopNginx = objc.IBOutlet()
    startMySQL = objc.IBOutlet()
    stopMySQL = objc.IBOutlet()
    startPHP = objc.IBOutlet()
    stopPHP = objc.IBOutlet()
    preferences = objc.IBOutlet()
    window = objc.IBOutlet()
	
    def init(self):
		self = super(MEMPController, self).initWithWindowNibName_("MainMenu")
		if self:
			self.path = "/Applications/MEMP/init/"
			self.auth = Authorization()
		return self
		
    @objc.IBAction
    def startServers_(self, sender):
		try:
			startScript = self.path + "start"
			self.auth.executeWithPrivileges(startScript)
			self.startButton.setHidden_(YES)
			self.stopButton.setHidden_(NO)
		except:
			pass
		
    @objc.IBAction
    def stopServers_(self, sender):
		try:
			stopScript = self.path + "stop"
			self.auth.executeWithPrivileges(stopScript)
			self.startButton.setHidden_(NO)
			self.stopButton.setHidden_(YES)
		except:
			pass
	
    @objc.IBAction
    def openPage_(self, sender):
		urlMEMP = NSURL.URLWithString_("http://localhost/MEMP/")
		workspace = NSWorkspace.sharedWorkspace().openURL_(urlMEMP)
	
    @objc.IBAction
    def startNginx_(self, sender):
		try:
			startNginx = self.path + "startNginx"
			self.auth.executeWithPrivileges(startNginx)
			self.startNginx.setHidden_(YES)
			self.stopNginx.setHidden_(NO)
		except:
			pass
	
    @objc.IBAction
    def stopNginx_(self, sender):
		try:		
			stopNginx = self.path + "stopNginx"
			self.auth.executeWithPrivileges(stopNginx)
			self.startNginx.setHidden_(NO)
			self.stopNginx.setHidden_(YES)
		except:
			pass

    @objc.IBAction
    def startMySQL_(self, sender):
		try:
			startMySQL = self.path + "startMySQL"
			self.auth.executeWithPrivileges(startMySQL)
			self.startMySQL.setHidden_(YES)
			self.stopMySQL.setHidden_(NO)
		except:
			pass
	
    @objc.IBAction
    def stopMySQL_(self, sender):
		try:
			stopMySQL = self.path + "stopMySQL"
			self.auth.executeWithPrivileges(stopMySQL)
			self.startMySQL.setHidden_(NO)
			self.stopMySQL.setHidden_(YES)
		except:
			pass

			
    @objc.IBAction
    def startPHP_(self, sender):
		try:		
			startPHP = self.path + "startPHP"
			self.auth.executeWithPrivileges(startPHP)
			self.startPHP.setHidden_(YES)
			self.stopPHP.setHidden_(NO)
		except:
			pass
	
    @objc.IBAction
    def stopPHP_(self, sender):
		try:
			stopPHP = self.path + "stopPHP"
			self.auth.executeWithPrivileges(stopPHP)
			self.startPHP.setHidden_(NO)
			self.stopPHP.setHidden_(YES)
		except:
			pass

    @objc.IBAction
    def preferences_(self, sender):
		PreferencesController.show()
	
    @objc.IBAction
    def showPreferencesWindow_(self, sender):
		self.preferencesController = PreferencesController.alloc().init()
		self.preferencesController.showWindow_(self)

    @objc.IBAction
    def exit_(self, sender):
		settings = NSUserDefaults.standardUserDefaults()
		stopMEMP = settings.boolForKey_("stop")
		
		if stopMEMP:
			self.stopServers_(self)

		NSApp().terminate_(self)

    def checkSettings(self):
		settings = NSUserDefaults.standardUserDefaults()

		startMEMP = settings.boolForKey_("start")
		if startMEMP:
			self.startServers_(self)
		
		openMEMP = settings.boolForKey_("open")
		if openMEMP:
			self.startServers_(self)
Ejemplo n.º 8
0
class MNPPController (NSWindowController):
    startButton = objc.IBOutlet()
    stopButton = objc.IBOutlet()
    startNginx = objc.IBOutlet()
    stopNginx = objc.IBOutlet()
    startMySQL = objc.IBOutlet()
    stopMySQL = objc.IBOutlet()
    startPHP = objc.IBOutlet()
    stopPHP = objc.IBOutlet()
    preferences = objc.IBOutlet()
    window = objc.IBOutlet()
	
    def init(self):
		self = super(MNPPController, self).initWithWindowNibName_("MainMenu")
		self.phpVersion = ""
		if self:
			self.path = "/Applications/MNPP/init/"
			self.auth = Authorization(destroyflags=(kAuthorizationFlagDestroyRights,))

		return self
		
    @objc.IBAction
    def startServers_(self, sender):
		try:
			self.checkPhpVersion()
			startScript = self.path + "start" + self.phpVersion
			
			self.auth.executeWithPrivileges(startScript)
			self.startButton.setHidden_(YES)
			self.stopButton.setHidden_(NO)
			self.startNginx.setHidden_(YES)
			self.stopNginx.setHidden_(NO)
			self.startMySQL.setHidden_(YES)
			self.stopMySQL.setHidden_(NO)
			self.startPHP.setHidden_(YES)
			self.stopPHP.setHidden_(NO)
		except:
			pass
		
    @objc.IBAction
    def stopServers_(self, sender):
		try:
			self.checkPhpVersion()
			stopScript = self.path + "stop" + self.phpVersion
			
			self.auth.executeWithPrivileges(stopScript)
			self.startButton.setHidden_(NO)
			self.stopButton.setHidden_(YES)
			self.startNginx.setHidden_(NO)
			self.stopNginx.setHidden_(YES)
			self.startMySQL.setHidden_(NO)
			self.stopMySQL.setHidden_(YES)
			self.startPHP.setHidden_(NO)
			self.stopPHP.setHidden_(YES)
		except:
			pass
	
    @objc.IBAction
    def openPage_(self, sender):
		urlMNPP = NSURL.URLWithString_("http://mnpp.local")
		workspace = NSWorkspace.sharedWorkspace().openURL_(urlMNPP)
	
    @objc.IBAction
    def startNginx_(self, sender):
		try:
			startNginx = self.path + "startNginx"
			self.auth.executeWithPrivileges(startNginx)
			self.startNginx.setHidden_(YES)
			self.stopNginx.setHidden_(NO)
		except:
			pass
	
    @objc.IBAction
    def stopNginx_(self, sender):
		try:		
			stopNginx = self.path + "stopNginx"
			self.auth.executeWithPrivileges(stopNginx)
			self.startNginx.setHidden_(NO)
			self.stopNginx.setHidden_(YES)
		except:
			pass

    @objc.IBAction
    def startMySQL_(self, sender):
		try:
			startMySQL = self.path + "startMySQL"
			print startMySQL
			self.auth.executeWithPrivileges(startMySQL)
			self.startMySQL.setHidden_(YES)
			self.stopMySQL.setHidden_(NO)
		except:
			pass
	
    @objc.IBAction
    def stopMySQL_(self, sender):
		try:
			stopMySQL = self.path + "stopMySQL"
			self.auth.executeWithPrivileges(stopMySQL)
			self.startMySQL.setHidden_(NO)
			self.stopMySQL.setHidden_(YES)
		except:
			pass

			
    @objc.IBAction
    def startPHP_(self, sender):
		try:
			self.checkPhpVersion()
			startPHP = self.path + "startPHP" + self.phpVersion
			print startPHP
			self.auth.executeWithPrivileges(startPHP)
			self.startPHP.setHidden_(YES)
			self.stopPHP.setHidden_(NO)
		except:
			pass
	
    @objc.IBAction
    def stopPHP_(self, sender):
		try:
			stopPHP = self.path + "stopPHP" + self.phpVersion
			print stopPHP
			self.auth.executeWithPrivileges(stopPHP)
			self.startPHP.setHidden_(NO)
			self.stopPHP.setHidden_(YES)
		except:
			pass

    @objc.IBAction
    def preferences_(self, sender):
		PreferencesController.show()
	
    @objc.IBAction
    def showPreferencesWindow_(self, sender):
		PreferencesController.show()
		#self.preferencesController = PreferencesController.alloc().init()
		#self.preferencesController.showWindow_(self)

    @objc.IBAction
    def exit_(self, sender):
		settings = NSUserDefaults.standardUserDefaults()
		stopMNPP = settings.boolForKey_("stop")
		
		if stopMNPP:
			self.stopServers_(self)

		NSApp().terminate_(self)

    def checkSettings(self):
		settings = NSUserDefaults.standardUserDefaults()

		startMNPP = settings.boolForKey_("start")
		if startMNPP:
			self.startServers_(self)
		
		openMNPP = settings.boolForKey_("open")
		if openMNPP:
			self.startServers_(self)

    def checkPhpVersion(self):
		settings = NSUserDefaults.standardUserDefaults()
		php53 = settings.boolForKey_("php53")
		php52 = settings.boolForKey_("php52")

		if php53:
			self.phpVersion = "53"
		else:
			self.phpVersion = "52"
Ejemplo n.º 9
0
class MNPPController(NSWindowController):
    startButton = objc.IBOutlet()
    stopButton = objc.IBOutlet()
    startNginx = objc.IBOutlet()
    stopNginx = objc.IBOutlet()
    startMySQL = objc.IBOutlet()
    stopMySQL = objc.IBOutlet()
    startPHP = objc.IBOutlet()
    stopPHP = objc.IBOutlet()
    preferences = objc.IBOutlet()
    window = objc.IBOutlet()

    def init(self):
        self = super(MNPPController, self).initWithWindowNibName_("MainMenu")
        if self:
            self.path = "/Applications/MNPP/init/"
            self.auth = Authorization()

        return self

    @objc.IBAction
    def startServers_(self, sender):
        try:
            startScript = self.path + "start"
            self.auth.executeWithPrivileges(startScript)
            self.startButton.setHidden_(YES)
            self.stopButton.setHidden_(NO)
            self.startNginx.setHidden_(YES)
            self.stopNginx.setHidden_(NO)
            self.startMySQL.setHidden_(YES)
            self.stopMySQL.setHidden_(NO)
            self.startPHP.setHidden_(YES)
            self.stopPHP.setHidden_(NO)
        except:
            pass

    @objc.IBAction
    def stopServers_(self, sender):
        try:
            stopScript = self.path + "stop"
            self.auth.executeWithPrivileges(stopScript)
            self.startButton.setHidden_(NO)
            self.stopButton.setHidden_(YES)
            self.startNginx.setHidden_(NO)
            self.stopNginx.setHidden_(YES)
            self.startMySQL.setHidden_(NO)
            self.stopMySQL.setHidden_(YES)
            self.startPHP.setHidden_(NO)
            self.stopPHP.setHidden_(YES)
        except:
            pass

    @objc.IBAction
    def openPage_(self, sender):
        urlMNPP = NSURL.URLWithString_("http://mnpp.astrata.local")
        workspace = NSWorkspace.sharedWorkspace().openURL_(urlMNPP)

    @objc.IBAction
    def startNginx_(self, sender):
        try:
            startNginx = self.path + "startNginx"
            self.auth.executeWithPrivileges(startNginx)
            self.startNginx.setHidden_(YES)
            self.stopNginx.setHidden_(NO)
        except:
            pass

    @objc.IBAction
    def stopNginx_(self, sender):
        try:
            stopNginx = self.path + "stopNginx"
            self.auth.executeWithPrivileges(stopNginx)
            self.startNginx.setHidden_(NO)
            self.stopNginx.setHidden_(YES)
        except:
            pass

    @objc.IBAction
    def startMySQL_(self, sender):
        try:
            startMySQL = self.path + "startMySQL"
            self.auth.executeWithPrivileges(startMySQL)
            self.startMySQL.setHidden_(YES)
            self.stopMySQL.setHidden_(NO)
        except:
            pass

    @objc.IBAction
    def stopMySQL_(self, sender):
        try:
            stopMySQL = self.path + "stopMySQL"
            self.auth.executeWithPrivileges(stopMySQL)
            self.startMySQL.setHidden_(NO)
            self.stopMySQL.setHidden_(YES)
        except:
            pass

    @objc.IBAction
    def startPHP_(self, sender):
        try:
            startPHP = self.path + "startPHP"
            self.auth.executeWithPrivileges(startPHP)
            self.startPHP.setHidden_(YES)
            self.stopPHP.setHidden_(NO)
        except:
            pass

    @objc.IBAction
    def stopPHP_(self, sender):
        try:
            stopPHP = self.path + "stopPHP"
            self.auth.executeWithPrivileges(stopPHP)
            self.startPHP.setHidden_(NO)
            self.stopPHP.setHidden_(YES)
        except:
            pass

    @objc.IBAction
    def preferences_(self, sender):
        PreferencesController.show()

    @objc.IBAction
    def showPreferencesWindow_(self, sender):
        self.preferencesController = PreferencesController.alloc().init()
        self.preferencesController.showWindow_(self)

    @objc.IBAction
    def exit_(self, sender):
        settings = NSUserDefaults.standardUserDefaults()
        stopMNPP = settings.boolForKey_("stop")

        if stopMNPP:
            self.stopServers_(self)

        NSApp().terminate_(self)

    def checkSettings(self):
        settings = NSUserDefaults.standardUserDefaults()

        startMNPP = settings.boolForKey_("start")
        if startMNPP:
            self.startServers_(self)

        openMNPP = settings.boolForKey_("open")
        if openMNPP:
            self.startServers_(self)
Ejemplo n.º 10
0
class MNPPController(NSWindowController):
    statusMenu = objc.IBOutlet()
    startButton = objc.IBOutlet()
    stopButton = objc.IBOutlet()
    startNginx = objc.IBOutlet()
    stopNginx = objc.IBOutlet()
    startMySQL = objc.IBOutlet()
    stopMySQL = objc.IBOutlet()
    startPHP = objc.IBOutlet()
    stopPHP = objc.IBOutlet()
    preferences = objc.IBOutlet()
    window = objc.IBOutlet()

    def init(self):
        self = super(MNPPController, self).initWithWindowNibName_("MainMenu")
        self.phpVersion = ""
        if self:
            self.path = "/Applications/MNPP/init/"
            self.auth = Authorization(
                destroyflags=(kAuthorizationFlagDestroyRights, ))

        self.appDelegate = NSApp.delegate()
        return self

    @objc.IBAction
    def startServers_(self, sender):
        try:
            self.checkPhpVersion()
            startScript = self.path + "start" + self.phpVersion

            self.auth.executeWithPrivileges(startScript)
            self.enableUwsgi()
            self.changeStatusStartButtonALL()

            self.startNginx.setHidden_(YES)
            self.stopNginx.setHidden_(NO)
            self.startMySQL.setHidden_(YES)
            self.stopMySQL.setHidden_(NO)
            self.startPHP.setHidden_(YES)
            self.stopPHP.setHidden_(NO)

            self.appDelegate.changeStatusStartMenuALL()

            self.appDelegate.startNginx.setHidden_(YES)
            self.appDelegate.stopNginx.setHidden_(NO)
            self.appDelegate.startMySQL.setHidden_(YES)
            self.appDelegate.stopMySQL.setHidden_(NO)
            self.appDelegate.startPHP.setHidden_(YES)
            self.appDelegate.stopPHP.setHidden_(NO)

        except:
            pass

    @objc.IBAction
    def stopServers_(self, sender):
        try:
            self.checkPhpVersion()
            stopScript = self.path + "stop" + self.phpVersion
            self.disableUwsgi()
            self.auth.executeWithPrivileges(stopScript)

            self.changeStatusStopButtonALL()
            self.startNginx.setHidden_(NO)
            self.stopNginx.setHidden_(YES)
            self.startMySQL.setHidden_(NO)
            self.stopMySQL.setHidden_(YES)
            self.startPHP.setHidden_(NO)
            self.stopPHP.setHidden_(YES)

            self.appDelegate.changeStatusStopMenuALL()
            self.appDelegate.stopNginx.setHidden_(YES)
            self.appDelegate.startNginx.setHidden_(NO)
            self.appDelegate.stopMySQL.setHidden_(YES)
            self.appDelegate.startMySQL.setHidden_(NO)
            self.appDelegate.stopPHP.setHidden_(YES)
            self.appDelegate.startPHP.setHidden_(NO)

        except:
            pass

    @objc.IBAction
    def openPage_(self, sender):
        urlMNPP = NSURL.URLWithString_("http://mnpp.local")
        workspace = NSWorkspace.sharedWorkspace().openURL_(urlMNPP)

    @objc.IBAction
    def startNginx_(self, sender):
        try:
            startNginx = self.path + "startNginx"
            self.auth.executeWithPrivileges(startNginx)
            self.enableUwsgi()

            self.changeStatusStartButtonALL()
            self.startNginx.setHidden_(YES)
            self.stopNginx.setHidden_(NO)
            """
			Menu status bar options
			"""
            self.appDelegate.changeStatusStartMenuALL()
            #self.appDelegate.startNginx_(self)
            self.appDelegate.startNginx.setHidden_(YES)
            self.appDelegate.stopNginx.setHidden_(NO)

        except:
            pass

    @objc.IBAction
    def stopNginx_(self, sender):
        try:
            stopNginx = self.path + "stopNginx"
            self.auth.executeWithPrivileges(stopNginx)
            self.disableUwsgi()

            self.changeStatusStopButtonALL()
            self.startNginx.setHidden_(NO)
            self.stopNginx.setHidden_(YES)
            """
			Menu status bar options
			"""
            self.appDelegate.changeStatusStopMenuALL()
            self.appDelegate.stopNginx.setHidden_(YES)
            self.appDelegate.startNginx.setHidden_(NO)

        except:
            pass

    @objc.IBAction
    def startMySQL_(self, sender):
        try:
            startMySQL = self.path + "startMySQL"
            self.auth.executeWithPrivileges(startMySQL)
            self.changeStatusStartButtonALL()
            self.startMySQL.setHidden_(YES)
            self.stopMySQL.setHidden_(NO)
            """
			Menu options
			"""
            self.appDelegate.changeStatusStartMenuALL()
            self.appDelegate.startMySQL.setHidden_(YES)
            self.appDelegate.stopMySQL.setHidden_(NO)

        except:
            pass

    @objc.IBAction
    def stopMySQL_(self, sender):
        try:
            stopMySQL = self.path + "stopMySQL"
            self.auth.executeWithPrivileges(stopMySQL)
            self.changeStatusStopButtonALL()
            self.startMySQL.setHidden_(NO)
            self.stopMySQL.setHidden_(YES)
            """
			Menu options
			"""
            self.appDelegate.changeStatusStopMenuALL()
            self.appDelegate.stopMySQL.setHidden_(YES)
            self.appDelegate.startMySQL.setHidden_(NO)
        except:
            pass

    @objc.IBAction
    def startPHP_(self, sender):
        try:
            self.checkPhpVersion()
            startPHP = self.path + "startPHP" + self.phpVersion

            self.auth.executeWithPrivileges(startPHP)
            self.changeStatusStartButtonALL()
            self.startPHP.setHidden_(YES)
            self.stopPHP.setHidden_(NO)
            """
			Menu options
			"""
            self.appDelegate.changeStatusStartMenuALL()
            self.appDelegate.startPHP.setHidden_(YES)
            self.appDelegate.stopPHP.setHidden_(NO)

        except:
            pass

    @objc.IBAction
    def stopPHP_(self, sender):
        try:
            stopPHP = self.path + "stopPHP" + self.phpVersion
            self.auth.executeWithPrivileges(stopPHP)
            self.changeStatusStopButtonALL()
            self.startPHP.setHidden_(NO)
            self.stopPHP.setHidden_(YES)
            """
			Menu options
			"""
            self.appDelegate.changeStatusStopMenuALL()
            self.appDelegate.stopPHP.setHidden_(YES)
            self.appDelegate.startPHP.setHidden_(NO)
        except:
            pass

    @objc.IBAction
    def preferences_(self, sender):
        PreferencesController.show()

    @objc.IBAction
    def showPreferencesWindow_(self, sender):
        PreferencesController.show()
        #self.preferencesController = PreferencesController.alloc().init()
        #self.preferencesController.showWindow_(self)

    @objc.IBAction
    def exit_(self, sender):
        settings = NSUserDefaults.standardUserDefaults()
        stopMNPP = settings.boolForKey_("stop")

        if stopMNPP:
            self.stopServers_(self)

        NSApp().terminate_(self)

    def checkSettings(self):
        settings = NSUserDefaults.standardUserDefaults()
        php53 = settings.boolForKey_("php53")
        php52 = settings.boolForKey_("php52")

        if not php53 and not php52:
            settings.setObject_forKey_("1", 'php53')
            settings.setObject_forKey_("0", 'php52')

        startMNPP = settings.boolForKey_("start")
        if startMNPP:
            self.startServers_(self)

        openMNPP = settings.boolForKey_("open")
        if openMNPP:
            self.startServers_(self)

    def checkPhpVersion(self):
        settings = NSUserDefaults.standardUserDefaults()
        php53 = settings.boolForKey_("php53")
        php52 = settings.boolForKey_("php52")

        if php53:
            self.phpVersion = "53"
        else:
            self.phpVersion = "52"

    def changeStatusStartButtonALL(self):
        self.startButton.setHidden_(YES)
        self.stopButton.setHidden_(NO)

    def changeStatusStopButtonALL(self):
        self.startButton.setHidden_(NO)
        self.stopButton.setHidden_(YES)

    def enableUwsgi(self):
        settings = NSUserDefaults.standardUserDefaults()
        uwsgi = settings.boolForKey_("uwsgi")

        if uwsgi:
            enableUwsgi = self.path + "enableUwsgi"
            self.auth.executeWithPrivileges(enableUwsgi)

    def disableUwsgi(self):
        settings = NSUserDefaults.standardUserDefaults()
        uwsgi = settings.boolForKey_("uwsgi")

        disableUwsgi = self.path + "disableUwsgi"
        self.auth.executeWithPrivileges(disableUwsgi)
Ejemplo n.º 11
0
class MNPPController (NSWindowController):
    statusMenu = objc.IBOutlet()
    preferences = objc.IBOutlet()
    window = objc.IBOutlet()
	
    def init(self):
		self = super(MNPPController, self).initWithWindowNibName_("MainMenu")
		self.phpVersion = ""
		if self:
			self.path = "/Applications/MNPP/init/"
			self.auth = Authorization(destroyflags=(kAuthorizationFlagDestroyRights,))

		self.appDelegate = NSApp.delegate()
		return self
		
    @objc.IBAction
    def startServers_(self, sender):
		try:
			self.checkPhpVersion()
			startScript = self.path + "start" + self.phpVersion

			self.auth.executeWithPrivileges(startScript)
			self.enableUwsgi()
		except:
			pass
		
    @objc.IBAction
    def stopServers_(self, sender):
		try:
			self.checkPhpVersion()
			stopScript = self.path + "stop" + self.phpVersion

			self.disableUwsgi()
			self.auth.executeWithPrivileges(stopScript)
		except:
			pass

    @objc.IBAction
    def restartServers_(self, sender):
        try:
            self.checkPhpVersion()
            restartScript = self.path + "restart" + self.phpVersion
        
            self.disableUwsgi()
            self.auth.executeWithPrivileges(restartScript)
        except:
            pass

    @objc.IBAction
    def openPage_(self, sender):
		urlMNPP = NSURL.URLWithString_("http://mnpp.local")
		workspace = NSWorkspace.sharedWorkspace().openURL_(urlMNPP)
	
    @objc.IBAction
    def startNginx_(self, sender):
		try:
			startNginx = self.path + "startNginx"
			self.auth.executeWithPrivileges(startNginx)
			self.enableUwsgi()
		except:
			pass
	
    @objc.IBAction
    def stopNginx_(self, sender):
		try:		
			stopNginx = self.path + "stopNginx"
			self.auth.executeWithPrivileges(stopNginx)
			self.disableUwsgi()
		except:
			pass

    @objc.IBAction
    def startMySQL_(self, sender):
		try:
			startMySQL = self.path + "startMySQL"
			self.auth.executeWithPrivileges(startMySQL)
		except:
			pass
	
    @objc.IBAction
    def stopMySQL_(self, sender):
		try:
			stopMySQL = self.path + "stopMySQL"
			self.auth.executeWithPrivileges(stopMySQL)
		except:
			pass

			
    @objc.IBAction
    def startPHP_(self, sender):
		try:
			self.checkPhpVersion()
			startPHP = self.path + "startPHP" + self.phpVersion

			self.auth.executeWithPrivileges(startPHP)
			self.changeStatusStartButtonALL()
		except:
			pass
	
    @objc.IBAction
    def stopPHP_(self, sender):
		try:
			stopPHP = self.path + "stopPHP" + self.phpVersion
			self.auth.executeWithPrivileges(stopPHP)
		except:
			pass

    @objc.IBAction
    def preferences_(self, sender):
		PreferencesController.show()
	
    @objc.IBAction
    def showPreferencesWindow_(self, sender):
		PreferencesController.show()

    @objc.IBAction
    def exit_(self, sender):
		settings = NSUserDefaults.standardUserDefaults()
		stopMNPP = settings.boolForKey_("stop")
		
		if stopMNPP:
			self.stopServers_(self)

		NSApp().terminate_(self)

    def checkSettings(self):
		settings = NSUserDefaults.standardUserDefaults()
		php54 = settings.boolForKey_("php54")
		php53 = settings.boolForKey_("php53")
		php52 = settings.boolForKey_("php52")
        
		if not php54 and not php53 and not php52:
			settings.setObject_forKey_("1", 'php54')
			settings.setObject_forKey_("0", 'php53')
			settings.setObject_forKey_("0", 'php52')
                
		startMNPP = settings.boolForKey_("start")
		if startMNPP:
			self.startServers_(self)
		
		openMNPP = settings.boolForKey_("open")
		if openMNPP:
			self.startServers_(self)
            

    def checkPhpVersion(self):
		settings = NSUserDefaults.standardUserDefaults()
		php54 = settings.boolForKey_("php54")
		php53 = settings.boolForKey_("php53")
		php52 = settings.boolForKey_("php52")

		if php54:
			self.phpVersion = "54"
		elif php53:
			self.phpVersion = "53"
		else:
			self.phpVersion = "52"

		
    def enableUwsgi(self):
		settings = NSUserDefaults.standardUserDefaults()
		uwsgi = settings.boolForKey_("uwsgi")
		
		if uwsgi:
			enableUwsgi = self.path + "enableUwsgi"
			self.auth.executeWithPrivileges(enableUwsgi)

    def disableUwsgi(self):
		settings = NSUserDefaults.standardUserDefaults()
		uwsgi = settings.boolForKey_("uwsgi")
		
		disableUwsgi = self.path + "disableUwsgi"
		self.auth.executeWithPrivileges(disableUwsgi)