def CheckCredentials(username, password): sess = CreateSession(username, password) if macho.mode == 'client': cherrypy.session['machoSession'] = sess return auth = base.GetServiceSession('cherry').ConnectToAnyService( 'authentication') sptype = const.userConnectTypeServerPages try: sessstuff, _ = auth.Login(sess.sid, username, password, None, sptype, cherrypy.request.remote.ip) except UserError: return u'Incorrect username or password' except Exception: return u'Incorrect username or password' session = CreateSession(username, password) sessstuff['role'] |= sess.role for otherSession in base.FindSessions('userid', [sessstuff['userid']]): otherSession.LogSessionHistory( 'Usurped by user %s via HTTP using local authentication' % username) base.CloseSession(otherSession) cherrypy.session['machoSession'] = sess sess.SetAttributes(sessstuff)
def GetUserSession(self, userid): foundSessions = base.FindSessions('userid', [userid]) if not foundSessions: return for foundSession in foundSessions: if foundSession.charid is None: return foundSession
def ProcessInventoryChange(self, items, change, isRemote, inventory2): """Translate inventory changes into session changes""" if macho.mode != 'server': return if isRemote: return if const.ixLocationID not in change and const.ixFlag not in change: return locationID = locationGroupID = None if const.ixLocationID in change: locationID = change[const.ixLocationID][1] if IsSolarSystem(locationID): locationGroupID = const.groupSolarSystem elif IsStation(locationID): locationGroupID = const.groupStation chars = {} for item in items: if item.categoryID == const.categoryShip and None not in (locationID, locationGroupID): inv2 = self.i2.GetInventory(locationID, locationGroupID) for i in inv2.SelectItems(item.itemID): if i.groupID == const.groupCharacter: chars[i.itemID] = self.GetSessionValuesFromItemID(item.itemID, inventory2, item) elif item.groupID == const.groupCharacter: if const.ixLocationID in change and item.customInfo == logConst.eventMovementUndock: continue chars[item.itemID] = self.GetSessionValuesFromItemID(item.itemID, inventory2, item) if len(chars) == 0: return for charID, updateDict in chars.iteritems(): for sess in base.FindSessions('charid', [charID]): sess.LogSessionHistory('Transmogrifying OnInventoryChange to SetAttributes') sess.SetAttributes(updateDict) sess.LogSessionHistory('Transmogrified OnInventoryChange to SetAttributes')
def GetCharLocationEx(charID): sessions = base.FindSessions('charid', [charID]) if len(sessions) and IsLocationNode(sessions[0]): s = sessions[0] if s.solarsystemid: return (s.solarsystemid, const.groupSolarSystem, s.shipid) if s.stationid and s.shipid: return (s.stationid, const.groupStation, s.shipid) if s.stationid: return (s.stationid, const.groupStation, s.stationid) if s.worldspaceid: return (s.worldspaceid, const.groupWorldSpace, s.worldspaceid) else: while sm.services['DB2'].state != SERVICE_RUNNING: blue.pyos.synchro.SleepWallclock(100) rs = sm.services['DB2'].GetSchema('character').Characters_LocationInfo( charID) locationInfo = rs[0] if locationInfo.locationID is None: raise RuntimeError('No such locationID', locationInfo.locationID, 'for charID', charID) if locationInfo.locationGroupID in (const.groupStation, const.groupSolarSystem, const.groupWorldSpace): return (locationInfo.locationID, locationInfo.locationGroupID, locationInfo.characterLocationID) return (locationInfo.locationID, None, locationInfo.characterLocationID)
def ProcessInventoryChange(self, items, change, isRemote, inventory2): if macho.mode != 'server': return if isRemote: return if const.ixLocationID not in change and const.ixFlag not in change: return chars = {} for item in items: if item.categoryID == const.categoryShip: for sess in base.FindSessions('shipid', [item.itemID]): if sess.charid == item.ownerID: chars[sess.charid] = self.GetSessionValuesFromItemID(item.itemID, inventory2, item) elif item.groupID == const.groupCharacter: chars[item.itemID] = self.GetSessionValuesFromItemID(item.itemID, inventory2, item) if len(chars) == 0: return for charID, updateDict in chars.iteritems(): for sess in base.FindSessions('charid', [charID]): sess.LogSessionHistory('Transmogrifying OnInventoryChange to SetAttributes') sess.SetAttributes(updateDict) sess.LogSessionHistory('Transmogrified OnInventoryChange to SetAttributes')
def GetSession(parent, request, response, sessionsBySID, sessionsByFlatkaka): parent.LogInfo('GetSession') if request.cookie.has_key('flatkaka'): flatkaka = request.cookie['flatkaka'] if sessionsByFlatkaka.has_key(flatkaka): sess = sessionsByFlatkaka[flatkaka] if macho.mode == 'client': return sess uspa = request.Authorization() if uspa != None: u = sess.esps.contents['username'] p = sess.esps.contents['password'] if uspa[0] != u or uspa[1] != p: parent.LogWarn("User %s is trying to hijack %s's session, with sessID=%d" % (uspa[0], u, sess.sid)) else: parent.LogInfo('cookie information verified') return sess sess = None success = False if macho.mode == 'client': sess = base.CreateSession(None, const.session.SESSION_TYPE_ESP, None) sess.esps = ESPSession(parent, sess.sid) success = True else: usernameAndPassword = request.Authorization() reason = 'Access denied' statusCode = '401 Unauthorized' if usernameAndPassword != None: parent.LogInfo('GetSession uap<>n') username = usernameAndPassword[0] password = usernameAndPassword[1] for s in sessionsBySID.itervalues(): if hasattr(s, 'esps') and s.esps.contents['username'] == username: if s.userid and s.esps.contents['password'] == password: return s break if macho.mode == 'server' and ('authentication' not in sm.services or sm.services['authentication'].state != service.SERVICE_RUNNING): blue.pyos.synchro.SleepWallclock(3000) raise UserError('AutClusterStarting') try: if sm.services['http'].session.ConnectToProxyServerService('machoNet').CheckACL(request.ep.address, espCheck=True): blue.pyos.synchro.SleepWallclock(3000) raise UserError('AutClusterStarting') except UnMachoDestination: blue.pyos.synchro.SleepWallclock(3000) raise UserError('AutClusterStarting') sessionID = base.GetNewSid() sess = base.CreateSession(sessionID, const.session.SESSION_TYPE_ESP) sess.esps = ESPSession(parent, sess.sid) auth = base.GetServiceSession('httpService').ConnectToAnyService('authentication') try: try: sessstuff, _ = auth.Login(sessionID, username, password, None, const.userConnectTypeServerPages, request.ep.address) sessstuff['role'] |= sess.role except UserError as e: if e.msg != 'CharacterInDifferentRegion': raise sys.exc_clear() for each in base.FindSessions('userid', [sessstuff['userid']]): each.LogSessionHistory('Usurped by user %s via HTTP using local authentication' % username) base.CloseSession(each) sess.LogSessionHistory('Authenticating user %s via HTTP using local authentication' % username) sess.SetAttributes(sessstuff) sess.LogSessionHistory('Authenticated user %s via HTTP using local authentication' % username) success = True except UnMachoDestination: reason = 'The proxy server was unable to connect to any Sol Server Node to handle your authentication request.' statusCode = '500 No Sol Server available' sys.exc_clear() except UserError as e: if e.msg != 'LoginAuthFailed': raise sys.exc_clear() if not success: sess.LogSessionHistory('Session closed due to local authentication failure') base.CloseSession(sess) parent.LogInfo('GetSession done auth %s' % success) if success: sessID = sess.sid while sessionsBySID.has_key(sessID): parent.LogWarn('Session %d already exits, adding 1 to it' % sessID) sessID += 1 sessionsBySID[sessID] = sess sessionsByFlatkaka[sess.esps.GetFlatkaka()] = sess parent.OnSessionBegin(sessID) session = sess session.cacheList = [] session.requestCount = 0 session.esps.contents['timeoutTimer'] = None if macho.mode != 'client': session.esps.contents['username'] = username session.esps.contents['password'] = password return session else: response.Clear() response.status = statusCode response.Write(reason) response.authenticate = 1 response.Flush() return
def GetCharacterSession(self, charid): s = base.FindSessions('charid', [charid]) if not s: return None return s[0]
def GetSession(self, charID): s = base.FindSessions('charid', [charID]) if not s: return None return s[0]