Ejemplo n.º 1
0
    def index():
        form = InputForm()
        if request.method == 'GET':
            return render_template('index.html', form=form)

        if request.method == 'POST':
            # note: the form won't submit with empty data, so we don't have to handle that
            data = form.field.data
            print 'Form data:', data

            try:
                sv = utils.classifySearchString(data)
                return redirect(url_for('search', data=sv.value))

            except ValueError:
                flash('Invalid search data')
                return render_template('index.html', form=form)
Ejemplo n.º 2
0
    def index():
        form = InputForm()
        if request.method == 'GET':
            return render_template('index.html', form=form)

        if request.method == 'POST':
            # note: the form won't submit with empty data, so we don't have to handle that
            data = form.field.data
            print 'Form data:', data

            try:
                sv = utils.classifySearchString(data)
                return redirect(url_for('search', data=sv.value))

            except ValueError as e:
                flash('Invalid search data: ' + str(e))
                return render_template('index.html', form=form)
Ejemplo n.º 3
0
    def test_classification(self):

        a = utils.classifySearchString('10.0.0.1')
        self.assertEquals(type(a), utils.Prefix)

        a = utils.classifySearchString('1.3.4.0/24')
        self.assertEquals(type(a), utils.Prefix)

        a = utils.classifySearchString('AS2603')
        self.assertEquals(type(a), utils.ASNumber)

        a = utils.classifySearchString('AS-NTT')
        self.assertEquals(type(a), utils.ASMacro)

        a = utils.classifySearchString('AS-57344')
        self.assertEquals(type(a), utils.ASMacro)

        a = utils.classifySearchString('AS9498:AS-BHARTI-IN')
        self.assertEquals(type(a), utils.ASMacro)
Ejemplo n.º 4
0
    def search(data):

        query_data = request.args.get('data')
        if query_data:
            # this means that we got search request
            print 'query data', query_data
            return redirect(url_for('search', data=query_data))

        if not data:
            flash('No search data provided')
            return render_template('search.html')

        try:
            sv = utils.classifySearchString(data)

            # prevent people from killing the machine by searching through all prefixes in one query
            if type(sv) is Prefix and '/' in sv.value and int(sv.value.split('/',2)[-1]) < 15:
                flash('Only prefixes longer than /15 are searchable (kills the database)')
                return render_template('search.html')

            tables = []

            # page: title (object type : data)

            # json url for each table, not per report...
            # stuff that is needed per table:
            # id (tables.key)
            # name
            # source url
            # column ordering (first, and last, we cannot do complete until we get results)
            # note (optional)

            if type(sv) is Prefix:
                title = 'Prefix: ' + sv.value
                tables.append({
                    'id'           : 'prefixes',
                    'title'        : 'Matching prefixes',
                    'url'          : '/json/prefix/' + sv.value,
                    'start_fields' : ["prefix", "bgp" ]
                })

            if type(sv) is ASNumber:
                title = 'AS Number: ' + data
                tables.append({
                    'id'           : 'prefixes',
                    'title'        : 'Prefixes',
                    'url'          : '/json/as_prefixes/' + str(sv.value),
                    'start_fields' : ["prefix", "bgp" ],
                    'note'         : 'Offending prefixes are only found if initial prefix sets is smaller than 1000'
                })

            if type(sv) is ASMacro:
                title = 'AS Macro: ' + data
                tables.append({
                    'id'           : 'expanded',
                    'title'        : 'Macro Expansion',
                    'url'          : '/json/macro_expand/' + sv.value,
                    'start_fields' : ["as_macro", "depth", "path", "source", "members"],
                    'note'         : 'AS Macro expansion is limited to 10K rows'
                })

            if type(sv) in (ASNumber, ASMacro):
                key = 'AS' + str(sv.value) if type(sv) is ASNumber else str(sv.value)
                tables.append({
                    'id'           : 'macros',
                    'title'        : 'Included in the following macros:',
                    'url'          : '/json/macro_contain/' + key,
                    'start_fields' : ["as_macro" ]
                })

            return render_template('search.html', title=title, tables=tables)


        except ValueError:
            flash('Invalid search data')
            return render_template('search.html')
Ejemplo n.º 5
0
    def search(data):

        query_data = request.args.get('data')
        if query_data:
            # this means that we got search request
            print 'query data', query_data
            return redirect(url_for('search', data=query_data))

        if not data:
            flash('No search data provided')
            return render_template('search.html')

        try:
            sv = utils.classifySearchString(data)

            # prevent people from killing the machine by searching through all prefixes in one query
            if type(sv) is Prefix and '/' in sv.value and int(
                    sv.value.split('/', 2)[-1]) < 15:
                flash(
                    'Only prefixes longer than /15 are searchable (kills the database)'
                )
                return render_template('search.html')

            tables = []

            # page: title (object type : data)

            # json url for each table, not per report...
            # stuff that is needed per table:
            # id (tables.key)
            # name
            # source url
            # column ordering (first, and last, we cannot do complete until we get results)
            # note (optional)

            if type(sv) is Prefix:
                title = 'Prefix: ' + sv.value
                tables.append({
                    'id': 'prefixes',
                    'title': 'Matching prefixes',
                    'url': '/json/prefix/' + sv.value,
                    'start_fields': ["prefix", "bgp"]
                })

            if type(sv) is ASNumber:
                title = 'AS Number: ' + data
                tables.append({
                    'id':
                    'prefixes',
                    'title':
                    'Prefixes',
                    'url':
                    '/json/as_prefixes/' + str(sv.value),
                    'start_fields': ["prefix", "bgp"],
                    'note':
                    'Offending prefixes are only found if initial prefix sets is smaller than 1000'
                })

            if type(sv) is ASMacro:
                title = 'AS Macro: ' + data
                tables.append({
                    'id':
                    'expanded',
                    'title':
                    'Macro Expansion',
                    'url':
                    '/json/macro_expand/' + sv.value,
                    'start_fields':
                    ["as_macro", "depth", "path", "source", "members"],
                    'note':
                    'AS Macro expansion is limited to 10K rows'
                })

            if type(sv) in (ASNumber, ASMacro):
                key = 'AS' + str(sv.value) if type(sv) is ASNumber else str(
                    sv.value)
                tables.append({
                    'id': 'macros',
                    'title': 'Included in the following macros:',
                    'url': '/json/macro_contain/' + key,
                    'start_fields': ["as_macro"]
                })

            return render_template('search.html', title=title, tables=tables)

        except ValueError as e:
            flash('Invalid search data: ' + str(e))
            return render_template('search.html')