def init(self): self = super(MNPPController, self).initWithWindowNibName_("MainMenu") if self: self.path = "/Applications/MNPP/init/" self.auth = Authorization() return self
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."))
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."))
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
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)
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)
class Fitbit(object): authorization = None database = None def __init__(self, database): self.authorization = Authorization() self.database = database def getHeartIntradayRate(self, date, callback=None): data = self.getHeartRateIntradaytDb(date) if data == None: print("Data not found in database, reaching Fitbit.com") data = self.getHeartRateIntradayOnline(date) if callback != None: callback(data) else: return data def getHeartRateIntradaytDb(self, date): return self.database.getIntradayData(date) def getHeartRateIntradayOnline(self, date): uri = AppConfig().get("uri_heart") uri = uri.replace("[date]", date) uri = uri.replace("[end-date]", date) authorizationHeader = self.authorization.getAuthorizationHeader( self.authorization.getToken(self.database)) response = requests.get(uri, headers={"Authorization": authorizationHeader}) data = self.formatJson(response.json()) if data == None: return None self.database.saveIntraday(data[0]) self.database.saveZones(data[1]) return data[0] def formatJson(self, json): date = None intradayData = list() zonesData = list() for activity in json["activities-heart"]: date = activity["dateTime"] for zone in activity["value"]["heartRateZones"]: if "caloriesOut" not in zone: return None zonesData.append((date, zone["name"], zone["max"], zone["min"], zone["caloriesOut"], zone["minutes"])) for intraday in json["activities-heart-intraday"]["dataset"]: intradayData.append((date, intraday["time"], intraday["value"])) return (intradayData, zonesData)
def updateUser(): dao = PersonDAO() if not Authorization().authorized(request.headers): return unauthorized content = request.get_json() user = dao.updatePerson(content["id"], content["education"], content["experience"]) return jsonify(user.serialize())
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
def createReferral(): dao = ReferralDAO() if not Authorization().authorized(request.headers): return unauthorized content = request.get_json() result = dao.createReferral( ReferralDTO(-1, content['sender'], "", content['recipient'], "", -1, content['status'])) return jsonify(result.serialize())
def handle(self): srvIface = Authorization(self.server.users, self._set_authenticated_user) self.transport.start_server(server=srvIface) # Get the session channel chan = self.transport.accept(self.auth_timeout) if chan is None: raise ProtocolError( "session channel not opened (authentication failure?)") self.transport.join()
def updateReferral(): dao = ReferralDAO() if not Authorization().authorized(request.headers): return unauthorized content = request.get_json() result = dao.updateReferral( ReferralDTO(content['id'], content['senderId'], "", content['recipientId'], "", content['company'], content['status'])) return jsonify(result.serialize())
def handle(self): print('Handling incoming request by thread: %s' % (threading.current_thread().name)) srvIface = Authorization(self.server.users, self._set_authenticated_user) self.transport.start_server(server=srvIface) # Get the session channel chan = self.transport.accept(self.auth_timeout) if chan is None: raise ProtocolError( "session channel not opened (authentication failure?)") self.transport.join()
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
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
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)
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"
def filter(): dao = PersonDAO() if not Authorization().authorized(request.headers): return unauthorized filtered = dao.filter(request.get_json()) return jsonify([x.serialize() for x in filtered])
def create(self): return Authorization.create(self)
def getReferrals(userId): dao = ReferralDAO() if not Authorization().authorized(request.headers): return unauthorized referrals = dao.getReferrals(userId) return jsonify([x.serialize() for x in referrals])
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)
def __init__(self, database): self.authorization = Authorization() self.database = database
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)
также можно перегрузить verification_params для проверки параметров на корректность потом вставить получившееся обьект класса в соотвествующий словарь api_methods_get["TestReq"] = TestReq() """ api_methods_get, api_methods_post = {}, {} api_methods_get["GetResult"] = GetResult() api_methods_get["GetAddresse"] = GetAddresse() api_methods_get["GetRoute"] = GetRoute() api_methods_get["GetSegment"] = GetSegment() api_methods_get["SetSegment"] = SetSegment() api_methods_get["getAllWayPoints"] = GetAllWayPoints() api_methods_get["addNewPoint"] = AddNewPoint() api_methods_get["Authorization"] = Authorization() api_methods_get["addNewLink"] = AddNewLink() api_methods_get["getAllWaySegments"] = GetAllWaySegments() api_methods_get["Registration"] = Registration() class HttpServer(BaseHTTPRequestHandler): def _set_headers(self): self.send_response(200) self.send_header('Content-type', 'text/plain') self.send_header('Access-Control-Allow-Origin', '*') self.end_headers() def do_GET(self): self._set_headers() url = self.requestline[9:-9]
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)
def getUser(identifier=None): dao = PersonDAO() if not Authorization().authorized(request.headers): return unauthorized user = dao.getPerson(identifier) return jsonify(user.serialize())