Ejemplo n.º 1
0
    def do_hosts(self, args):
        """Says hello. If you provide a name, it will greet you with it."""

        parser = self.hosts_args()
        try:
            params = parser.parse_args(args.split(' '))
        except:
            return

        filters = True
        if params.S:
            for search in params.S:
                filters = and_(
                    filters, or_(
                        Host.comment.ilike('%{}%'.format(search)),
                        Host.ipv4.ilike('%{}%'.format(search)),
                        Host.hostname.ilike('%{}%'.format(search)),
                    )
                )

        fmt = "{}{:<15}  {}{:<39}  {}{}"
        hosts = self.controller.db.filter(Host, filters)

        print(fmt.format(Fore.GREEN, 'host', Fore.YELLOW,
              'hostname', Style.RESET_ALL, 'comment'))
        for host in hosts:
            print(fmt.format(Fore.GREEN, host.ipv4, Fore.YELLOW,
                  host.hostname, Style.RESET_ALL, host.comment))
Ejemplo n.º 2
0
  def removeTeam(self, leagueID, teamID):
    # Returns a json string
    user = User()
    if user:
      RUser = user[0]
      if RUser.Permissions[0].teams:
        RTeam = db.Session.query(db.Teams).filter(db.Teams.id == teamID).first()
        if RTeam:
          RMatch = db.Session.query(db.Matches).filter(db.or_(db.Matches.team1 == teamID, db.Matches.team2 == teamID)).first()
          if RMatch:
            success = False
            message = "<strong>Oh snap!</strong> I can't remove a team with matches."
          else:
            db.Session.delete(RTeam)
            db.Session.commit()
            success = True
            message = "Removed selected team."
        else:
          success = False
          message = "<strong>Oh snap!</strong> Couldn't remove this team."
      else:
        success = False
        message = "You don't have sufficent priviledges to access this page."
    else:
      success = False
      message = "You don't have sufficent priviledges to access this page."

    array = {"success": success, "message": message}
    return json.dumps(array)
Ejemplo n.º 3
0
    def removeTeam(self, leagueID, teamID):
        # Return a rendered template
        #return render('/manage.mako')
        # or, return a string
        user = User()
        if user:
            RUser = user[0]
            if RUser.level <= 3:
                RTeam = db.Session.query(
                    db.Teams).filter(db.Teams.id == teamID).first()
                if RTeam:
                    RMatch = db.Session.query(db.Matches).filter(
                        db.or_(db.Matches.team1 == teamID,
                               db.Matches.team2 == teamID)).first()
                    if RMatch:
                        success = False
                        message = "<strong>Oh snap!</strong> I can't remove a team with matches."
                    else:
                        db.Session.delete(RTeam)
                        db.Session.commit()
                        success = True
                        message = "Removed selected team."
                else:
                    success = False
                    message = "<strong>Oh snap!</strong> Couldn't remove this team."
            else:
                success = False
                message = "You don't have sufficent priviledges to access this page."
        else:
            success = False
            message = "You don't have sufficent priviledges to access this page."

        array = {"success": success, "message": message}
        return json.dumps(array)
Ejemplo n.º 4
0
def daily_matches_finished(club_id):
    club = Club.query.filter(Club.club_id == club_id).first()
    matches = ClubMatches.query\
        .filter(ClubMatches.status == 'finished')\
        .filter(ClubMatches.time_class == 'daily') \
        .filter(or_(ClubMatches.team1_id == club_id, ClubMatches.team2_id == club_id)) \
        .all()
    return render_template("daily_matches_finished.html", matches=matches, club=club)
Ejemplo n.º 5
0
def search(search_query: str, db: database.Session = Depends(database.get_db)):
    result = db.query(database.Listing).filter(
        database.or_(database.Listing.context.contains(search_query),
                     database.Listing.title.contains(search_query))).all()
    if not result:
        raise HTTPException(status.HTTP_404_NOT_FOUND,
                            detail=f'No listing contained: \'{search_query}\'')
    else:
        return result
Ejemplo n.º 6
0
def live_matches(club_id):
    club = Club.query.filter(Club.club_id == club_id).first()
    matches = ClubMatches.query \
        .filter(or_(ClubMatches.team1_id == club_id, ClubMatches.team2_id == club_id)) \
        .filter(ClubMatches.time_class == 'live') \
        .order_by(ClubMatches.end_time.desc()) \
        .all()

    return render_template("live_matches.html", matches=matches, club=club)
Ejemplo n.º 7
0
def index():
    return cursor.query(Link).filter(and_(Link.combined_prediction == True,or_(Link.hidden == None,Link.hidden == False))).order_by(Link.evaluation_date.desc()).limit(5).from_self().order_by(Link.evaluation_date.asc()).all() \
         + cursor.query(Link).filter(and_(Link.evaluation_date == None,Link.combined_prediction == True,or_(Link.hidden == None,Link.hidden == False))).order_by(Link.date.desc()).limit(45).all()
Ejemplo n.º 8
0
def disliked():
    return cursor.query(Link).filter(and_(Link.evaluation == False,or_(Link.hidden == None,Link.hidden == False))).order_by(Link.date.asc()).limit(50).all()
Ejemplo n.º 9
0
    def do_services(self, args):
        """list stored services"""
        parser = self.services_args()
        args = [] if args == '' else args.split(' ')

        try:
            params = parser.parse_args(args)
        except:
            return

        filters = True

        # ilike filter in version banner
        if params.S:
            for search in params.S:
                filters = and_(filters, or_(
                    *[Service.version.ilike('%{}%'.format(search))
                      for search in params.S]
                ))

        # filter open ports
        if params.u:
            filters = and_(filters, Service.state == 'open')

        # filter specific
        if params.p:
            pfilter = or_(*[(Service.port == port) for port in params.p])
            filters = and_(filters, pfilter)

        # filter hostname
        if params.H:
            try:
                for host in params.H:
                    hosts = self.controller.db.filter(
                        Host,
                        Host.ipv4.like('%{}%'.format(host))
                    )
                    hosts_id = [h.id for h in hosts]
                    filters = and_(filters, Service.host_id.in_(hosts_id))
            except NoResultFound:
                print('no such host')
                return

        colormap = {
            'closed': Fore.RED,
            'open': Fore.GREEN,
            'filtered': Fore.YELLOW
        }
        line = "{:<15} {:<10} {:<20} {:<15} {}"
        services = self.controller.db.filter(Service, filters)

        print(line.format('host', 'port', 'service', 'state', 'version'))
        for service in services:
            color = colormap[service.state]
            if not service.version:
                service.version = ''

            print(line.format(
                service.host.ipv4, str(service.port)+'/'+service.proto,
                service.service, color + service.state + Style.RESET_ALL,
                service.version)
            )
        print(line.format('host', 'port', 'service', 'state', 'version'))