Beispiel #1
0
def switch_request(host, url, akey, interface=None):

    #print('------- START SW')
    #    from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT

    request_lock.acquire()

    request_switch.host = host
    request_switch.url = url

    request_host_parts = request_switch.host.split(':')

    if len(request_host_parts) == 2:
        request_switch.port = request_host_parts[1]
    else:
        request_switch.port = None

    request_switch.akey = akey

    from ilot.models import Interface

    if not interface:
        interface = Interface.objects.get(cname=host.split(':')[0])

    request_switch.interface = interface
    request_switch.organization = interface.application

    semester = datetime.timedelta(6 * 30)

    request_switch.end = AppManager.get_valid_time()
    request_switch.start = request_switch.end - semester

    host_name = host.split(':')[0]
    alias = None
Beispiel #2
0
    def open(self):

        #
        online_manager.wsockets.append(self)

        #
        if not 'sessionid' in self.request.cookies:
            self.close()
            return

        # path is the room where the user is arriving
        # we create a room per registred user ?
        session_id = self.request.cookies['sessionid'].value

        # get django session data
        try:
            session = Session.objects.get(session_key=session_id)
            session_data = session.get_decoded()
        except Session.DoesNotExist:
            session_data = {}
            session_data['akey'] = AppManager.get_new_uuid()
            #return

        #
        akey = session_data['akey']
        self.request.akey = akey
        self.request.path = akey

        from ilot.core.models import Item
        try:
            actor = Item.objects.get(id=akey)
        except ObjectDoesNotExist:
            actor = Item(id=akey,
                         locale=akey,
                          context=akey,
                          origin_id=akey,
                          target=akey,
                          related_id=akey,
                          akey=akey,
                          status='newVisitor')
            actor.save()

        # generate wkey ?
        wkey = online_manager.get_contact_uuid()
        online_manager.akey_by_wkey[wkey] = akey
        online_manager.register_online(self, wkey)
        #online_manager.join_network()

        # send it to the connecting user
        kwargs = {
            'context':session_data['akey'],
            'path':session_data['akey'],
            'input_data':{},
            'action':'index',
            'ext':'.html',
            'do':True,
            'todo':True,
            'text':'Welcome to the network. Please Authenticate or register',
        }
Beispiel #3
0
    def get_request_akey(cls, request):
        """
        Get actionpipe data container key
        Generates a new one if missing cookie
        """
        akey = None
        if cls.pipe_hash_key in request.session:
            akey = request.session[cls.pipe_hash_key]

        if not akey:
            akey = AppManager.get_new_uuid()
            request.session[cls.pipe_hash_key] = akey
        return akey
Beispiel #4
0
    def get_actions(cls):
        class_stack = inspect.getmro(cls)[::-1]

        actions = []
        actions_forms = {}
        action_templates = {}

        for base_class in class_stack:

            check_classes = inspect.getmro(base_class)

            if ActionView in check_classes:
                #
                if not 'actions' in cls.__dict__:
                    if 'class_actions' in base_class.__dict__:
                        for action in base_class.class_actions:
                            if action not in actions:
                                actions.append(action)
                #
                if not 'actions_forms' in cls.__dict__:
                    if 'class_actions_forms' in base_class.__dict__:
                        for action in base_class.class_actions_forms:
                            actions_forms[action] = base_class.class_actions_forms[action]
                #
                if not 'action_templates' in cls.__dict__:
                    if 'class_action_templates' in base_class.__dict__:
                        for action in base_class.class_action_templates:
                            action_templates[action] = base_class.class_action_templates[action]

        if not 'actions' in cls.__dict__:
            cls.actions = actions
        if not 'actions_forms' in cls.__dict__:
            cls.actions_forms = actions_forms
        if not 'action_templates' in cls.__dict__:
            cls.action_templates = action_templates

        #AppManager.register_actions(cls.actions)
        AppManager.register_class(cls, cls.actions)
        return cls.actions
Beispiel #5
0
    def run(self, prev):
        print('\n------- ', self.name,' \n')
        Scenario.objects.steps[self.id] = prev

        player = self.avatar.get_player()
        url = prev.get_url(self.action)

        refering_url = prev.get_refering_url()

        print('From:', refering_url)
        print('To:', self.method, url)
        print('\n')

        from ilot.core.manager import AppManager

        self.current_ref_time = AppManager.get_ref_time()

        if self.method == 'GET':
            player.get(refering_url, url, load_json(self.data), self.done)
        elif self.method == 'POST':
            player.post(refering_url, url, load_json(self.data), self.done)
        else:
            raise
Beispiel #6
0
#

from ilot.core.manager import AppManager

actions = AppManager.get_actions()

for action in actions:

    # evaluate the action tag function
    action_tag = """
    import {{className}}

    def action_name(item, param_a=None, param_b=None):

        action = {{action}}
        # execute the action within the context

        return rendered_content
    """
    # register it
Beispiel #7
0
handler401 = 'ilot.views.front.handler401'
handler404 = 'ilot.views.front.handler404'
handler403 = 'ilot.views.front.handler403'
handler500 = 'ilot.views.front.handler500'

# comming soon
import re
re_uuid = re.compile("[0-F]{8}-[0-F]{4}-[0-F]{4}-[0-F]{4}-[0-F]{12}", re.I)

# https://gist.github.com/luzfcb/186ee28b368450035e056228615db999
# okey this may be interesting to handle uppercase or lowercase
#
uuid_slug_regexp = '(?P<path>[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})'

AppManager.register_section(FrontView)

from django.conf.urls.static import static
from django.conf.urls import url

urlpatterns = [
    url(r'^$',
        SiteView.as_view(),
        name='front',
        kwargs={
            'path': '',
            'action': '',
            'ext': '.html'
        }),
    url(r'', include('ilot.api.urls')),
    url(uuid_slug_regexp + '+\/$',
Beispiel #8
0
            'PASSWORD': os.environ.get('POSTGRES_PASS', ''),
            'HOST': os.environ.get('POSTGRES_HOST', ''),
            'PORT': os.environ.get('POSTGRES_PORT', '')
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': SERVER_ROOT + '/.ilot.db',
        }
    }

if DEBUG:
    T_LOADERS = [
        ('django.template.loaders.locmem.Loader', AppManager.get_core()),
        'ilot.templates.Loader',
        'django.template.loaders.filesystem.Loader',
        'django.template.loaders.app_directories.Loader',
    ]
else:
    T_LOADERS = [
        ('django.template.loaders.locmem.Loader', AppManager.get_core()),
        ('django.template.loaders.cached.Loader', [
            'ilot.templates.Loader',
            'django.template.loaders.filesystem.Loader',
            'django.template.loaders.app_directories.Loader',
        ]),
    ]

TEMPLATES = [