Ejemplo n.º 1
0
    def __init__(self):
        db.configure(bind=create_engine(
            'sqlite:///%(here)s/cyberrange.sqlite'))

        self.rr = results.ResultReader()

        self.log = IxiaLogger(__name__)

        self.log.debug('ResultsConsumer: initialized')

        self._test_result_id = None
        self._test_config_obj = None

        self._results = list()
Ejemplo n.º 2
0
import socket
import fcntl
import struct
import array
import string
import random
import subprocess
import datetime
import transaction
from ixiacr.models import (IxiaVersion, UIMessage)
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from zope.sqlalchemy import ZopeTransactionExtension
from ixiacr.lib import IxiaLogger

log = IxiaLogger(__name__)

pad = lambda s: s + (16 - len(s) % 16) * chr(16 - len(s) % 16)
unpad = lambda s: s[0:-ord(s[-1])]


def enum(*sequential, **named):
    enums = dict(zip(sequential, range(len(sequential))), **named)
    reverse = dict((value, key) for key, value in enums.iteritems())
    enums['reverse_mapping'] = reverse
    return type('Enum', (), enums)


def get_ip(iface='eth0'):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sockfd = sock.fileno()
Ejemplo n.º 3
0
from pyramid.i18n import TranslationStringFactory, get_locale_name
from sqlalchemy.exc import DBAPIError
from pyramid.security import authenticated_userid
from pyramid_handlers import action
from pyramid.response import Response

from ixiacr.handlers import base
from ixiacr.models import *
from ixiacr.tasks import (reset_db_task,
                              reboot_task,
                              shutdown_task)
from ixiacr.lib import IxiaLogger
from ixiacr.lib.utils import admin_helper
from ixiacr.lib.bps.bpsRest import BPS

ixiacrlogger = IxiaLogger(__name__)

_ = TranslationStringFactory('messages')


def view_includes(config):
    # Admin handlers
    config.add_handler('verify_password', '/ixia/verify_password.json',
                       'ixiacr.handlers.admin:IxiaAdminHandler',
                       action='verify_password')
    config.add_handler('add_user', '/ixia/add_user.json',
                       'ixiacr.handlers.admin:IxiaAdminHandler',
                       action='add_user')
    config.add_handler('verify_user', '/ixia/verify_user.json',
                       'ixiacr.handlers.admin:IxiaAdminHandler',
                       action='verify_user')
Ejemplo n.º 4
0
import transaction
from pyramid.httpexceptions import HTTPFound
from pyramid.security import remember, forget, NO_PERMISSION_REQUIRED
from pyramid.url import route_url
from pyramid_handlers import action
from sqlalchemy import asc

import ixiacr.handlers.base as base
from ixiacr.models import *
from ixiacr.lib import IxiaLogger
from ixiacr.lib.session_key_value import SessionKeyValueStore
from ixiacr.lib.utils import get_global_vars

# auth
ixiacrlogger = IxiaLogger(__name__)

_ = TranslationStringFactory('messages')


def view_includes(config):
    # Auth handlers
    config.add_handler('login', '/login', 'ixiacr.handlers.auth:AuthHandler', action='login',
                       permission=NO_PERMISSION_REQUIRED)
    config.add_handler('logout', '/logout', 'ixiacr.handlers.auth:AuthHandler', action='logout')


class AuthHandler(base.Handler):
    @action(renderer='login.jinja2')
    def login(self):
        # basic auth/login for the  application
Ejemplo n.º 5
0
class ResultsConsumer(object):

    RESULT_SYNC_TRIGGERS = [
        ResultPacket.ResultType.TestStop,
        ResultPacket.ResultType.ResultSetStop
    ]

    def __init__(self):
        db.configure(bind=create_engine(
            'sqlite:///%(here)s/cyberrange.sqlite'))

        self.rr = results.ResultReader()

        self.log = IxiaLogger(__name__)

        self.log.debug('ResultsConsumer: initialized')

        self._test_result_id = None
        self._test_config_obj = None

        self._results = list()

    @property
    def current_config(self):
        return None

    def _sync_results(self):
        '''
        Process all of the accumulated results in one swell foop.
        '''
        config = self.current_config

        start = time.time()

        with transaction.manager:
            sp = transaction.savepoint()
            for count, result in enumerate(self._results):
                if not config.test.process_result_transactionless(
                        config, result.__dict__, config.result_id, db):
                    self.log.error('ResultsConsumer: Processing failed for {0}. '
                                   'Rolling back to last savepoint.'.format(result))
                    sp.rollback()
                    break

        stop = time.time()

        fargs = {
            'count': count,
            'time': stop - start,
            'avg': (stop - start) / float(count) if count > 0 else 0
        }
        self.log.debug('ResultsConsumer: Processed {count} results in {time:.3f} seconds '
                       '({avg:.3f} seconds/result)'.format(**fargs))

        self._results = list()

    def process_result(self, ch, method, properties, body):
        '''
        The result data consumer callback that processes results into the data
        object being passed in from the task consumer.
        '''
        try:
            result = cPickle.loads(body)
            assert result, 'Unable to unpickle result object'

            self._results.append(result)

            if result.resulttype in self.RESULT_SYNC_TRIGGERS:
                self._sync_results()

            return True

        except Exception as e:
            self.log.exception('ResultsConsumer: {0}'.format(e))
            return False

    def run(self):
        self.rr.read(self.process_result)
Ejemplo n.º 6
0
import httplib
import os
import transaction


from pyramid_handlers import action
from pyramid.security import authenticated_userid

from ixiacr.handlers import base
from ixiacr.lib import IxiaLogger, UiLogger
from ixiacr.lib.utils import (admin_helper,
                            generate_file_object)
from ixiacr.models.core import (db, User)
from pyramid.security import NO_PERMISSION_REQUIRED

ixiacrlogger = IxiaLogger(__name__)
uilogger = UiLogger('UiLogger')

LOCAL_CHASSIS_IP = '169.254.0.3'
LOCALHOST = '127.0.0.1'


def view_includes(config):
    # Main (Tests etc.) handler
    config.add_handler('get_images',
                       '/ixia/get_images',
                       'ixiacr.handlers.utils:IxiaUtilHandler',
                       action='get_images',
                       permission=NO_PERMISSION_REQUIRED)
    config.add_handler('log_js',
                       '/ixia/log_js.json',
Ejemplo n.º 7
0
from datetime import datetime
from pyramid.i18n import TranslationStringFactory
import transaction
from pyramid_handlers import action
from celery.result import AsyncResult
from celery.contrib.abortable import AbortableAsyncResult

from ixiacr.handlers import base
from ixiacr.lib import IxiaLogger
from ixiacr.lib.bps.bpsTest import aTestBpt

from ixiacr.lib.session_key_value import SessionKeyValueStore
from ixiacr.lib import component_registry
from ixiacr.models import *

ixiacrlogger = IxiaLogger(__name__)

_ = TranslationStringFactory('messages')


def view_includes(config):
    config.add_handler('config_test', '/ixia/config_test',
                       'ixiacr.handlers.tests:IxiaTestHandler',
                       action='config_test')
    config.add_handler('run_test', '/ixia/run_test',
                       'ixiacr.handlers.tests:IxiaTestHandler',
                       action='run_test')
    config.add_handler('get_istestready', '/ixia/get_istestready',
                       'ixiacr.handlers.tests:IxiaTestHandler',
                       action='get_istestready')
    config.add_handler('cancel_test', '/ixia/cancel_test',