예제 #1
0
 def post(self, *args, **kwargs):
     '''
     Reset the Game
     '''
     errors = []
     success = None
     try:
         users = User.all()
         for user in users:
             user.money = 0
         teams = Team.all()
         for team in teams:
             if options.banking:
                 team.money = options.starting_team_money
             else:
                 team.money = 0
             team.flags = []
             team.hints = []
             team.boxes = []
             team.items = []
             team.purchased_source_code = []
             level_0 = GameLevel.by_number(0)
             if not level_0:
                 level_0 = GameLevel.all()[0]
             team.game_levels = [level_0]
             self.dbsession.add(team)
         self.dbsession.commit()
         self.dbsession.flush()
         for team in teams:
             for paste in team.pastes:
                 self.dbsession.delete(paste)
             for shared_file in team.files:
                 shared_file.delete_data()
                 self.dbsession.delete(shared_file)
         self.dbsession.commit()
         self.dbsession.flush()
         Penalty.clear()
         Notification.clear()
         snapshot = Snapshot.all()
         for snap in snapshot:
             self.dbsession.delete(snap)
         self.dbsession.commit()
         snapshot_team = SnapshotTeam.all()
         for snap in snapshot_team:
             self.dbsession.delete(snap)
         self.dbsession.commit()
         game_history = GameHistory.instance()
         game_history.take_snapshot()  # Take starting snapshot
         flags = Flag.all()
         for flag in flags:
             flag.value = flag._original_value if flag._original_value else flag.value
             self.dbsession.add(flag)
         self.dbsession.commit()
         self.dbsession.flush()
         success = "Successfully Reset Game"
         self.render('admin/reset.html', success=success, errors=errors)
     except BaseException as e:
         errors.append("Failed to Reset Game")
         logging.error(str(e))
         self.render('admin/reset.html', success=None, errors=errors)
예제 #2
0
 def bot_scored(self, team, message=None):
     """ Callback for when a bot scores """
     if message is None:
         message = "%s botnet has scored" % team.name
     Notification.create_team(team, "Botnet Scored", message, SUCCESS)
     self.io_loop.add_callback(self.push_team, team.id)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #3
0
 def team_file_shared(self, user, file_upload):
     ''' Callback when a team file share is created '''
     message = "%s has shared the file '%s'" % (
         user.handle, file_upload.file_name,
     )
     Notification.create_team(user.team, "File Share", message, INFO)
     self.io_loop.add_callback(self.push_team, user.team.id)
예제 #4
0
 def user_joined_team(self, user):
     ''' Callback when a user joins a team'''
     message = "%s has joined the %s team" % (
         user.handle, user.team.name,
     )
     Notification.create_team(user.team, "New Team Member", message, INFO)
     self.io_loop.add_callback(self.push_team, user.team.id)
예제 #5
0
 def level_unlocked(self, user, level):
     ''' Callback for when a team unlocks a new level '''
     message = "%s unlocked level #%d." % (user.team.name, level.number)
     Notification.create_broadcast(user.team, "Level Unlocked", message,
                                   SUCCESS)
     self.io_loop.add_callback(self.push_broadcast)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #6
0
 def team_paste_shared(self, user, paste_bin):
     ''' Callback when a pastebin is created '''
     message = "%s posted '%s' to the team paste bin" % (
         user.handle, paste_bin.name
     )
     Notification.create_team(user.team, "Text Share", message, INFO)
     self.io_loop.add_callback(self.push_team, user.team.id)
예제 #7
0
 def bot_added(self, user, count):
     ''' Callback for when a bot is added '''
     message = "%s added a new bot; total number of bots is now %d" % (
         user.team.name, count)
     Notification.create_broadcast(user.team, "Bot added", message, INFO)
     self.io_loop.add_callback(self.push_broadcast)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #8
0
 def player_swated(self, user, target):
     message = "%s called the SWAT team on %s." % (user.handle,
                                                   target.handle)
     Notification.create_broadcast(user.team, "Player Arrested!", message,
                                   INFO)
     self.io_loop.add_callback(self.push_broadcast)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #9
0
 def push_user_notification(self, event_uuid, team_id, user_id):
     ''' Push to one user '''
     if team_id in self.notify_connections and user_id in self.notify_connections[team_id]:
         json = Notification.by_event_uuid(event_uuid).to_dict()
         for wsocket in self.notify_connections[team_id][user_id]:
             wsocket.write_message(json)
             Notification.delivered(wsocket.user_id, event_uuid)
예제 #10
0
 def flag_decayed(self, team, flag):
     """ Callback for when a bot is added """
     message = (
         "The value of Flag %s has decreased due to other team captures - score adjusted."
         % (flag.name, ))
     Notification.create_team(team, "Flag Value Decreased", message, INFO)
     self.io_loop.add_callback(self.push_team, team.id)
예제 #11
0
 def flag_captured(self, player, flag):
     """ Callback for when a flag is captured """
     if isinstance(player, User):
         team = player.team
     else:
         team = player
     if isinstance(player, User) and options.teams:
         message = '%s (%s) has completed "%s" in %s' % (
             player.handle,
             team.name,
             flag.name,
             flag.box.name,
         )
     else:
         message = '%s has completed "%s" in %s' % (
             team.name,
             flag.name,
             flag.box.name,
         )
     if len(GameLevel.all()) > 1:
         message = message + " (%s)" % (
             GameLevel.by_id(flag.box.game_level_id).name,
         )
     Notification.create_broadcast(team, "Flag Capture", message, SUCCESS)
     self.io_loop.add_callback(self.push_broadcast)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #12
0
 def flag_captured(self, user, flag):
     ''' Callback for when a flag is captured '''
     message = "%s has captured the '%s' flag" % (
         user.team.name, flag.name
     )
     Notification.create_broadcast("Flag Capture", message)
     self.io_loop.add_callback(self.push_broadcast)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #13
0
 def item_purchased(self, user, item):
     ''' Callback when a team purchases an item '''
     message = "%s purchased %s from the black market" % (
         user.handle, item.name,
     )
     Notification.create_team(user.team, "Upgrade Purchased", message, SUCCESS)
     self.io_loop.add_callback(self.push_team, user.team.id)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #14
0
 def push_user_notification(self, event_uuid, team_id, user_id):
     ''' Push to one user '''
     if team_id in self.notify_connections and user_id in self.notify_connections[
             team_id]:
         json = Notification.by_event_uuid(event_uuid).to_dict()
         for wsocket in self.notify_connections[team_id][user_id]:
             wsocket.write_message(json)
             Notification.delivered(wsocket.user_id, event_uuid)
예제 #15
0
 def level_unlocked(self, user, level):
     ''' Callback for when a team unlocks a new level '''
     message = "%s unlocked level #%d." % (
         user.team.name, level.number
     )
     Notification.create_broadcast("Level Unlocked", message)
     self.io_loop.add_callback(self.push_broadcast)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #16
0
 def user_joined_team(self, user):
     """ Callback when a user joins a team"""
     if options.teams:
         message = "%s has joined the %s team" % (user.handle, user.team.name)
         Notification.create_team(user.team, "New Team Member", message, INFO)
     else:
         message = "%s has joined the game" % (user.handle,)
         Notification.create_team(user.team, "New Player", message, INFO)
     self.io_loop.add_callback(self.push_team, user.team.id)
예제 #17
0
 def push_broadcast_notification(self, event_uuid):
     ''' Push to everyone '''
     json = Notification.by_event_uuid(event_uuid).to_dict()
     for team_id in self.notify_connections:
         for user_id in self.notify_connections[team_id]:
             for wsocket in self.notify_connections[team_id][user_id]:
                 wsocket.write_message(json)
                 # Only mark delivered for non-public users
                 if wsocket.user_id != '$public_user':
                     Notification.delivered(user_id, event_uuid)
예제 #18
0
 def push_broadcast_notification(self, event_uuid):
     ''' Push to everyone '''
     json = Notification.by_event_uuid(event_uuid).to_dict()
     for team_id in self.notify_connections:
         for user_id in self.notify_connections[team_id]:
             for wsocket in self.notify_connections[team_id][user_id]:
                 wsocket.write_message(json)
                 # Only mark delivered for non-public users
                 if wsocket.user_id != '$public_user':
                     Notification.delivered(user_id, event_uuid)
예제 #19
0
 def admin_score_update(self, team, message, value):
     """ Callback for when admin point change is made """
     if value < 0:
         icon = WARNING
     else:
         icon = SUCCESS
     Notification.create_team(team, "Admin Update",
                              "%s (%s)" % (message, str(value)), icon)
     self.io_loop.add_callback(self.push_team, team.id)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #20
0
 def flag_penalty(self, user, flag):
     ''' Callback for when a flag is captured '''
     if len(GameLevel.all()) > 1:
         message = "%s was penalized on the '%s' flag in %s (Lvl %s)" % (
             user.team.name, flag.name, flag.box.name,
             GameLevel.by_id(flag.box.game_level_id).number)
     else:
         message = "%s was penalized on the '%s' flag in %s" % (
             user.team.name, flag.name, flag.box.name)
     Notification.create_team(user.team, "Flag Penalty", message, WARNING)
     self.io_loop.add_callback(self.push_team, user.team.id)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #21
0
 def hint_taken(self, user, hint):
     ''' Callback for when a hint is taken '''
     if len(GameLevel.all()) > 1:
         message = "%s has taken a hint for %s (Lvl %s)" % (
             user.team.name, hint.box.name,
             GameLevel.by_id(hint.box.game_level_id).number)
     else:
         message = "%s has taken a hint for %s" % (user.team.name,
                                                   hint.box.name)
     Notification.create_team(user.team, "Hint Taken", message, INFO)
     self.io_loop.add_callback(self.push_team, user.team.id)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #22
0
 def hint_taken(self, user, hint):
     """ Callback for when a hint is taken """
     if options.teams:
         message = "%s has taken a hint for %s" % (user.handle, hint.box.name)
     else:
         message = "%s has taken a hint for %s" % (user.team.name, hint.box.name)
     if len(GameLevel.all()) > 1:
         message = message + " (%s)" % (
             GameLevel.by_id(hint.box.game_level_id).name,
         )
     Notification.create_team(user.team, "Hint Taken", message, INFO)
     self.io_loop.add_callback(self.push_team, user.team.id)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #23
0
 def __anonymous__(cls, title, message, category, event_uuid, icon=None):
     ''' Creates anonysmous notification where user_id = NULL '''
     notification = Notification(
         user_id=None,
         event_uuid=event_uuid,
         title=unicode(title),
         message=unicode(message),
         category=category,
     )
     if icon is not None:
         notification.icon = icon
     dbsession.add(notification)
     dbsession.commit()
예제 #24
0
 def __create__(cls, user, title, message, category, event_uuid, icon=None):
     ''' Create a notification and save it to the database '''
     notification = Notification(
         user_id=user.id,
         event_uuid=event_uuid,
         title=unicode(title),
         message=unicode(message),
         category=category,
     )
     if icon is not None:
         notification.icon = icon
     dbsession.add(notification)
     dbsession.commit()
예제 #25
0
 def flag_captured(self, user, flag):
     ''' Callback for when a flag is captured '''
     if len(GameLevel.all()) > 1:
         message = "%s has captured the '%s' flag in %s (Lvl %s)" % (
             user.team.name, flag.name, flag.box.name,
             GameLevel.by_id(flag.box.game_level_id).number)
     else:
         message = "%s has captured the '%s' flag in %s" % (
             user.team.name, flag.name, flag.box.name)
     Notification.create_broadcast(user.team, "Flag Capture", message,
                                   SUCCESS)
     self.io_loop.add_callback(self.push_broadcast)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #26
0
 def __create__(cls, user, title, message, category, event_uuid, icon=None):
     ''' Create a notification and save it to the database '''
     notification = Notification(
         user_id=user.id,
         event_uuid=event_uuid,
         title=unicode(title),
         message=unicode(message),
         category=category,
     )
     if icon is not None:
         notification.icon = icon
     dbsession.add(notification)
     dbsession.commit()
예제 #27
0
 def __anonymous__(cls, title, message, category, event_uuid, icon=None):
     ''' Creates anonysmous notification where user_id = NULL '''
     notification = Notification(
         user_id=None,
         event_uuid=event_uuid,
         title=unicode(title),
         message=unicode(message),
         category=category,
     )
     if icon is not None:
         notification.icon = icon
     dbsession.add(notification)
     dbsession.commit()
예제 #28
0
 def cracked_password(self, cracker, victim, password, value):
     '''
     This is created when a user successfully cracks another
     players password.
     '''
     user_msg = "Your password '%s' was cracked by %s" % (
         password, cracker.handle,
     )
     Notification.create_user(victim, "Security Breach", user_msg, ERROR)
     message = "%s hacked %s's bank account and stole $%d" % (
         cracker.handle, victim.team.name, value,
     )
     Notification.create_broadcast("Password Cracked", message, SUCCESS)
     self.io_loop.add_callback(self.push_broadcast)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #29
0
 def player_swated(self, user, target):
     message = "%s called the SWAT team on %s." % (
         user.handle, target.handle
     )
     evt_id = Notification.create_broadcast("Player Arrested!", message)
     self.io_loop.add_callback(self.push_broadcast)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #30
0
def notifyUser(user_id, message):
    """
    How to use this method:
        from socket_events import notifyUser
        notifyUser(1, "sample notification message")
    """
    new_notification = Notification(user_id, message)
    new_notification.save()
    ser_notification = NotificationSchema().dump(new_notification)
    socketid = online_users.get(user_id)
    if socketid:
        emit('new notification',
             ser_notification,
             room=socketid,
             namespace='/')
    return ser_notification
예제 #31
0
 def bot_added(self, user, count):
     """ Callback for when a bot is added """
     if options.teams:
         message = "%s (%s) added a new bot; total number of bots is now %d" % (
             user.handle,
             user.team.name,
             count,
         )
     else:
         message = "%s added a new bot; total number of bots is now %d" % (
             user.team.name,
             count,
         )
     Notification.create_broadcast(user.team, "Bot added", message, INFO)
     self.io_loop.add_callback(self.push_broadcast)
     self.io_loop.add_callback(self.push_scoreboard)
예제 #32
0
 def updateNotification(self):
     notifications = Notification.getActiveByEmployeeId(10)
     print notifications
     for notification in notifications:
         if notification != None:
             notification.message = "Sucka"
             notification.update()
예제 #33
0
def change_ticket_status():
    userInfo = session.get('userProfile')

    # Fetch all required information from the front end
    ticket_id = request.form.get('ticketid')
    project_id = request.form.get('projectid')
    status = request.form.get('status')
    t_date = DATE

    # Fetch the ticket from the backend by the ticket_id
    ticket = Ticket.query.get(ticket_id)

    # if status changed that record it to ticket_history, notification table and add a comment
    if ticket.t_status != status:
        new_id = db.session.query(func.max(Ticket_history.id))
        if new_id[0][0] == None:
            new_id[0][0] = 0

        ticket_history = Ticket_history(new_id[0][0] + 1, ticket_id,
                                        ticket.users_id, status, t_date,
                                        ticket.t_priority)
        try:
            ticket_history.insert()
        except:
            print(sys.exc_info())
            abort(500)

        project_user = Map_users_proj.query.with_entities(
            Map_users_proj.users_id).filter(
                Map_users_proj.p_id == project_id).all()
        for p in project_user:
            notify = Notification(ticket_id, p, type='update')
            try:
                notify.insert()
            except:
                print(sys.exc_info())
                abort(500)

        comment = "Status changed to " + status
        new_id = db.session.query(func.max(Comment.c_id))
        if new_id[0][0] == None:
            new_id[0][0] = 0

        comment = Comment(new_id[0][0] + 1, ticket_id, userInfo['id'], t_date,
                          comment)
        try:
            comment.insert()
        except:
            print(sys.exc_info())
            abort(500)

    # if updated status = closed than update the close_date in the ticket table
    if ticket.t_status != status and status == "closed":
        ticket.t_close_date = t_date

    # finally update the status in the ticket table
    ticket.t_status = status
    ticket.update()

    return redirect('/ticket-details/' + str(ticket_id))
예제 #34
0
 def team_paste_shared(self, user, paste_bin):
     ''' Callback when a pastebin is created '''
     message = "%s posted '%s' to the team paste bin" % (
         user.handle, paste_bin.name
     )
     evt_id = Notification.create_team(user.team, "Text Share", message, INFO)
     self.io_loop.add_callback(self.push_team, user.team.id)
예제 #35
0
 def open(self):
     ''' When we receive a new websocket connect '''
     if self.session is not None and 'team_id' in self.session:
         logging.debug("[Web Socket] Opened new websocket with user id: %s" % (
             self.session['user_id'],
         ))
         notifications = Notification.new_messages(self.session['user_id'])
         logging.debug("[Web Socket] %d new notification(s) for user id %d" % (
             len(notifications), self.session['user_id']),
         )
         for notify in notifications:
             self.write_message(notify.to_dict())
             Notification.delivered(notify.user_id, notify.event_uuid)
     else:
         logging.debug("[Web Socket] Opened public notification socket.")
     self.start_time = datetime.now()
     self.manager.add_connection(self)
예제 #36
0
 def put(self):
     user_id = get_jwt_identity().get('id')
     all_notifications = Notification.mark_all_as_read(user_id)
     data = {
         "message": "Notifications received",
         "notifications": notifications_schema.dump(all_notifications)
     }
     return custom_json_response(data, 200)
예제 #37
0
 def get(self):
     # return all the notifications for the current logged in user
     # return json
     notifications = Notification.getActiveByEmployeeId(current_user.employee_id)
     json_not = list()
     for notif in notifications:
         json_not.append(notif.toDict())
     return json.dumps(json_not)
예제 #38
0
 def push_user(self, team_id, user_id):
     ''' Push all unread notifications to open user websockets '''
     connections = self.get_user_connections(team_id, user_id)
     notifications = Notification.unread_by_user_id(user_id)
     logging.debug("User #%s has %d unread notification(s)" % (
         user_id, len(notifications)
     ))
     for notification in notifications:
         for connection in connections:
             self.safe_write_message(connection,
                                     notification.to_dict()
                                     )
         notification.viewed = True
         dbsession.add(notification)
     dbsession.commit()