Пример #1
0
 def get_team_list(self):
     teams = get('ScoringTeam').objects.filter(game=self)
     return {
         'id':
         self.id,
         'name':
         self.name,
         'teams': [{
             'id': team.id,
             'name': team.name,
             'token': str(team.token.uid)
         } for team in teams]
     }
Пример #2
0
 def get_json(self):
     return {
         'name':
         self.name,
         'mode':
         self.get_mode_display(),
         'status':
         self.get_status_display(),
         'end': (self.end.isoformat() if self.end is not None else None),
         'start':
         (self.start.isoformat() if self.start is not None else None),
         'teams': [
             team.get_json()
             for team in get('PlayerTeam').objects.filter(game=self)
         ]
     }
Пример #3
0
 def get_scoreboard(self, old=False):
     if old:
         return {
             'name':
             escape(self.name),
             'message':
             'This is Scorebot',
             'mode':
             self.mode,
             'teams': [
                 team.get_scoreboard(old)
                 for team in get('PlayerTeam').objects.filter(game=self)
             ],
             'events': [],
             'credit':
             ''
         }
     return None
Пример #4
0
 def get_team_token(self, uuid, beacon=False):
     try:
         uuid_string = UUID(str(uuid))
     except ValueError as err:
         return None, None
     else:
         try:
             token = get('Token').objects.get(uid=uuid_string)
         except (ObjectDoesNotExist, MultipleObjectsReturned):
             return None, None
         else:
             try:
                 if beacon:
                     return self.get(registered__in=[token]), token
                 return self.get(token=token), token
             except (ObjectDoesNotExist, MultipleObjectsReturned):
                 return None, None
         finally:
             del uuid_string
     return None, None
Пример #5
0
 def get_montiors(self, ip, token):
     try:
         monitor = get('Monitor').objects.get(token=token)
     except ObjectDoesNotExist:
         Authentication.error(
             '[%s] Attempted to access the jobs interface without being assigned a Monitor Token!'
             % ip)
         return None, None, HttpResponseForbidden(
             content=JOB_MESSAGE_NOT_MONTIOR)
     except MultipleObjectsReturned:
         Authentication.error(
             '[%s] Attempted to access the jobs interface with an improper Monitor Token!'
             % ip)
         return None, None, HttpResponseForbidden(
             content=JOB_MESSAGE_NO_MONTIOR)
     assigned = self.filter(monitor=monitor, game__status=GAME_RUNNING)
     if len(assigned) == 0:
         Authentication.error(
             '[%s] Monitor "%s" is not assigned to any running Games!' %
             (ip, monitor.name))
         return None, None, HttpResponseForbidden(
             content=JOB_MESSAGE_NO_GAMES)
     return assigned, monitor, None
Пример #6
0
 def get_beacon(self, team, token, address):
     try:
         target = IPv4Address(address)
     except ValueError:
         General.error(
             'Team "%s" reported a Beacon for an invalid IP address "%s"!' %
             (team.get_path(), address))
         return HttpResponseBadRequest(content=HOST_MESSAGE_INVALID_IP)
     General.info(
         'Received a Beacon request by Team "%s" for address "%s"!' %
         (team.get_path(), address))
     host = None
     ghost = False
     try:
         host = self.exclude(range__team=team).get(ip=address)
     except MultipleObjectsReturned:
         General.error(
             'Team "%s" reported a Beacon for an invalid IP address "%s" that matches multiple Hosts!'
             % (team.get_path(), address))
         return HttpResponseBadRequest(content=HOST_MESSAGE_INVALID_IP)
     except ObjectDoesNotExist:
         ghost = True
         try:
             host = get('BeaconHost').objects.exclude(range__team=team).get(
                 ip=address)
         except (ObjectDoesNotExist, MultipleObjectsReturned):
             pass
         if host is None:
             General.info(
                 'Beacon request by Team "%s" for address "%s" does not match a known host, will attempt to match!'
                 % (team.get_path(), address))
             victim = None
             for match in team.get_game().teams.exclude(id=team.id):
                 match_playing = match.get_playingteam()
                 if match_playing is None or match_playing.assets is None:
                     continue
                 try:
                     network = IPv4Network(match_playing.assets.subnet)
                 except ValueError:
                     General.warning(
                         'Team "%s" does not have a valid subnet entered for it\'s range "%s"!'
                         % (match.get_path(), match_playing.assets.subnet))
                     continue
                 else:
                     if target in network:
                         victim = match_playing
                         break
                 finally:
                     del match_playing
             if victim is None:
                 General.error(
                     'Beacon request by Team "%s" for address "%s" does not match a known host or Team subnet range!'
                     % (team.get_path(), address))
                 return HttpResponseNotFound(content=HOST_MESSAGE_NO_HOST)
             General.debug(
                 'Creating BeaconHost due to Beacon request by Team "%s" for address "%s" that matches Team "%s" '
                 'range!' % (team.get_path(), address, victim.get_path()))
             host = new('BeaconHost', False)
             host.ip = address
             host.range = victim.assets
             host.save()
             del victim
     del target
     General.debug('Received Beacon request by Team "%s" for Host "%s"!' %
                   (team.get_path(), host.get_path()))
     if not host.get_game().__bool__():
         General.error(
             'Received Beacon request by Team "%s" for Host "%s" for a non-running Game!'
             % (team.get_path(), host.get_path()))
         return HttpResponseBadRequest(content=MESSAGE_GAME_NO_RUNNING)
     if host.get_game().id != team.get_game().id:
         General.error(
             'Received Beacon request by Team "%s" for Host "%s" not in the same Game!'
             % (team.get_path(), host.get_path()))
         return HttpResponseBadRequest(content=HOST_MESSAGE_NO_HOST)
     try:
         beacon = host.beacons.get(end__isnull=True, owner=team)
     except MultipleObjectsReturned:
         General.warning(
             'Received Beacon request by Team "%s" for Host "%s" attempting to add multiple Beacons!'
             % (team.get_path(), host.get_path()))
         return HttpResponseForbidden(content=HOST_MESSAGE_BEACON_EXISTS)
     except ObjectDoesNotExist:
         Events.info(
             'Created a new Beacon on Host "%s" owned by Team "%s" from "%s"!'
             %
             (host.get_path(), host.get_team().get_path(), team.get_path()))
         General.info(
             'Created a new Beacon on Host "%s" owned by Team "%s" from "%s"!'
             %
             (host.get_path(), host.get_team().get_path(), team.get_path()))
         team.get_game().event(
             '%s has compromised a Host on %s\'s network!' %
             (team.get_name(), host.get_team().get_name()))
         beacon = new('Beacon', False)
         beacon.owner = team
         if ghost:
             beacon.ghost = host
         else:
             beacon.host = host
     beacon.update = now()
     beacon.token = token
     beacon.save()
     return HttpResponse(status=201)
Пример #7
0
 def get_list(self):
     ports = list()
     for game in get('Game').objects.filter(status=GAME_RUNNING):
         for port in game.ports.all():
             ports.append(str(port.port))
     return ports