コード例 #1
0
    def get(self):
        sessname = unquote(self.get_cookie("sessname"))
        jbox_cookie = self.get_session_cookie()

        if (None == sessname) or (len(sessname) == 0) or (None == jbox_cookie):
            self.send_error()
            return

        user_id = jbox_cookie['u']
        user = JBoxUserV2(user_id)
        is_admin = sessname in self.config("admin_sessnames", [])
        manage_containers = is_admin or user.has_role(JBoxUserV2.ROLE_MANAGE_CONTAINERS)
        show_report = is_admin or user.has_role(JBoxUserV2.ROLE_ACCESS_STATS)
        cont = JBoxContainer.get_by_name(sessname)

        if cont is None:
            self.send_error()
            return

        if self.handle_if_logout(cont):
            return
        if self.handle_if_stats(is_admin or show_report):
            return
        if self.handle_if_show_cfg(is_admin):
            return
        if self.handle_if_instance_info(is_admin):
            return
        if self.handle_switch_julia_img(user):
            return

        juliaboxver, _upgrade_available = self.get_upgrade_available(cont)

        jimg_type = 0
        if user.has_resource_profile(JBoxUserV2.RES_PROF_JULIA_PKG_PRECOMP):
            jimg_type = JBoxUserV2.RES_PROF_JULIA_PKG_PRECOMP

        d = dict(
            manage_containers=manage_containers,
            show_report=show_report,
            sessname=sessname,
            user_id=user_id,
            created=isodate.datetime_isoformat(cont.time_created()),
            started=isodate.datetime_isoformat(cont.time_started()),
            allowed_till=isodate.datetime_isoformat((cont.time_started() + timedelta(seconds=self.config('expire')))),
            mem=cont.get_memory_allocated(),
            cpu=cont.get_cpu_allocated(),
            disk=cont.get_disk_allocated(),
            expire=self.config('expire'),
            juliaboxver=juliaboxver,
            jimg_type=jimg_type
        )

        self.rendertpl("ipnbadmin.tpl", d=d, cfg=self.config())
コード例 #2
0
    def post(self):
        self.log_debug("Homework handler got POST request")
        sessname = unquote(self.get_cookie("sessname"))
        jbox_cookie = self.get_session_cookie()

        if (None == sessname) or (len(sessname) == 0) or (None == jbox_cookie):
            self.log_info(
                "Homework handler got invalid sessname[%r] or cookie[%r]",
                sessname, jbox_cookie)
            self.send_error()
            return

        user_id = jbox_cookie['u']
        user = JBoxUserV2(user_id)
        is_admin = sessname in self.config(
            "admin_sessnames", []) or user.has_role(JBoxUserV2.ROLE_SUPER)
        course_owner = is_admin or user.has_role(JBoxUserV2.ROLE_OFFER_COURSES)
        cont = JBoxContainer.get_by_name(sessname)
        self.log_info("user_id[%r], is_admin[%r], course_owner[%r]", user_id,
                      is_admin, course_owner)

        if cont is None:
            self.log_info("user_id[%r] container not found", user_id)
            self.send_error()
            return

        courses_offered = user.get_courses_offered()

        if self.handle_if_check(user_id):
            return
        if self.handle_create_course(user_id):
            return
        if self.handle_get_metadata(is_admin, courses_offered):
            return
        if course_owner and self.handle_if_report(user_id, is_admin,
                                                  courses_offered):
            return

        self.log_error("no handlers found")
        # only AJAX requests responded to
        self.send_error()
コード例 #3
0
    def post(self):
        self.log_debug("Homework handler got POST request")
        sessname = unquote(self.get_cookie("sessname"))
        jbox_cookie = self.get_session_cookie()

        if (None == sessname) or (len(sessname) == 0) or (None == jbox_cookie):
            self.log_info("Homework handler got invalid sessname[%r] or cookie[%r]", sessname, jbox_cookie)
            self.send_error()
            return

        user_id = jbox_cookie['u']
        user = JBoxUserV2(user_id)
        is_admin = sessname in self.config("admin_sessnames", []) or user.has_role(JBoxUserV2.ROLE_SUPER)
        course_owner = is_admin or user.has_role(JBoxUserV2.ROLE_OFFER_COURSES)
        cont = JBoxContainer.get_by_name(sessname)
        self.log_info("user_id[%r], is_admin[%r], course_owner[%r]", user_id, is_admin, course_owner)

        if cont is None:
            self.log_info("user_id[%r] container not found", user_id)
            self.send_error()
            return

        courses_offered = user.get_courses_offered()

        if self.handle_if_check(user_id):
            return
        if self.handle_create_course(user_id):
            return
        if self.handle_get_metadata(is_admin, courses_offered):
            return
        if course_owner and self.handle_if_report(user_id, is_admin, courses_offered):
            return

        self.log_error("no handlers found")
        # only AJAX requests responded to
        self.send_error()
コード例 #4
0
ファイル: auth.py プロジェクト: bauglir/JuliaBox
    def get(self):
        if self.config("gauth"):
            # self_redirect_uri should be similar to  'http://<host>/hostlaunchipnb/'
            self_redirect_uri = self.request.full_url()
            idx = self_redirect_uri.index("hostlaunchipnb/")
            self_redirect_uri = self_redirect_uri[0:(idx + len("hostlaunchipnb/"))]

            # state indicates the stage of auth during multistate auth
            state = self.get_argument('state', None)

            code = self.get_argument('code', False)
            if code is not False:
                user = yield self.get_authenticated_user(redirect_uri=self_redirect_uri, code=code)

                # get user info
                http = tornado.httpclient.AsyncHTTPClient()
                auth_string = "%s %s" % (user['token_type'], user['access_token'])
                response = yield http.fetch('https://www.googleapis.com/userinfo/v2/me',
                                            headers={"Authorization": auth_string})
                user_info = json.loads(response.body)

                user_id = user_info['email']

                jbuser = JBoxUserV2(user_id, create=True)
                if state == 'store_creds':
                    creds = self.make_credentials(user)
                    jbuser.set_gtok(base64.b64encode(creds.to_json()))
                    jbuser.save()
                    #self.log_info(str(user))
                    #self.log_info(creds.to_json())
                else:
                    if self.get_cookie("is_invite", "no") == "yes":
                        code, status = jbuser.get_activation_state()
                        if status != JBoxUserV2.ACTIVATION_GRANTED:
                            jbuser.set_activation_state(code, JBoxUserV2.ACTIVATION_REQUESTED)
                            jbuser.save()
                        self.redirect('/?_msg=' + str(status))
                        return
                    else:
                        self.set_session_cookie(user_id)
                        if jbuser.is_new:
                            jbuser.save()
                    self.redirect('/')
                    return
            else:
                if state == 'ask_gdrive':
                    jbox_cookie = AuthHandler.get_session_cookie(self)
                    scope = ['https://www.googleapis.com/auth/drive']
                    extra_params = {'approval_prompt': 'force', 'access_type': 'offline',
                                    'login_hint': jbox_cookie['u'], 'include_granted_scopes': 'true',
                                    'state': 'store_creds'}
                else:
                    scope = ['profile', 'email']
                    extra_params = {'approval_prompt': 'auto'}

                yield self.authorize_redirect(redirect_uri=self_redirect_uri,
                                              client_id=self.settings['google_oauth']['key'],
                                              scope=scope,
                                              response_type='code',
                                              extra_params=extra_params)
        else:
            sessname = unquote(self.get_argument("sessname"))
            self.set_session_cookie(sessname)
            self.redirect('/')
コード例 #5
0
ファイル: admin.py プロジェクト: arshak/JuliaBox
    def get(self):
        sessname = unquote(self.get_cookie("sessname"))
        jbox_cookie = self.get_session_cookie()

        if (None == sessname) or (len(sessname) == 0) or (None == jbox_cookie):
            self.send_error()
            return

        user_id = jbox_cookie['u']
        user = JBoxUserV2(user_id)
        is_admin = sessname in self.config("admin_sessnames", [])
        manage_containers = is_admin or user.has_role(
            JBoxUserV2.ROLE_MANAGE_CONTAINERS)
        show_report = is_admin or user.has_role(JBoxUserV2.ROLE_ACCESS_STATS)
        cont = JBoxContainer.get_by_name(sessname)

        if cont is None:
            self.send_error()
            return

        if self.handle_if_logout(cont):
            return
        if self.handle_if_stats(is_admin):
            return
        if self.handle_if_show_cfg(is_admin):
            return
        if self.handle_if_instance_info(is_admin):
            return

        juliaboxver, _upgrade_available = self.get_upgrade_available(cont)

        sections = []
        report = {}
        report_span = 'day'

        if manage_containers:
            sections = self.do_containers()

        if show_report:
            today = datetime.now()
            if self.get_argument('range', 'day') == 'week':
                dates = [today - timedelta(days=i) for i in range(6, -1, -1)]
                report_span = 'week'
            else:
                dates = [today]
            report = JBoxAccountingV2.get_stats(dates)

        d = dict(manage_containers=manage_containers,
                 show_report=show_report,
                 report_span=report_span,
                 sessname=sessname,
                 user_id=user_id,
                 created=isodate.datetime_isoformat(cont.time_created()),
                 started=isodate.datetime_isoformat(cont.time_started()),
                 allowed_till=isodate.datetime_isoformat(
                     (cont.time_started() +
                      timedelta(seconds=self.config('expire')))),
                 mem=cont.get_memory_allocated(),
                 cpu=cont.get_cpu_allocated(),
                 disk=cont.get_disk_allocated(),
                 expire=self.config('expire'),
                 sections=sections,
                 report=report,
                 juliaboxver=juliaboxver)

        self.rendertpl("ipnbadmin.tpl", d=d, cfg=self.config())
コード例 #6
0
ファイル: admin.py プロジェクト: arshak/JuliaBox
    def get(self):
        sessname = unquote(self.get_cookie("sessname"))
        jbox_cookie = self.get_session_cookie()

        if (None == sessname) or (len(sessname) == 0) or (None == jbox_cookie):
            self.send_error()
            return

        user_id = jbox_cookie['u']
        user = JBoxUserV2(user_id)
        is_admin = sessname in self.config("admin_sessnames", [])
        manage_containers = is_admin or user.has_role(JBoxUserV2.ROLE_MANAGE_CONTAINERS)
        show_report = is_admin or user.has_role(JBoxUserV2.ROLE_ACCESS_STATS)
        cont = JBoxContainer.get_by_name(sessname)

        if cont is None:
            self.send_error()
            return

        if self.handle_if_logout(cont):
            return
        if self.handle_if_stats(is_admin):
            return
        if self.handle_if_show_cfg(is_admin):
            return
        if self.handle_if_instance_info(is_admin):
            return

        juliaboxver, _upgrade_available = self.get_upgrade_available(cont)

        sections = []
        report = {}
        report_span = 'day'

        if manage_containers:
            sections = self.do_containers()

        if show_report:
            today = datetime.now()
            if self.get_argument('range', 'day') == 'week':
                dates = [today - timedelta(days=i) for i in range(6, -1, -1)]
                report_span = 'week'
            else:
                dates = [today]
            report = JBoxAccountingV2.get_stats(dates)

        d = dict(
            manage_containers=manage_containers,
            show_report=show_report,
            report_span=report_span,
            sessname=sessname,
            user_id=user_id,
            created=isodate.datetime_isoformat(cont.time_created()),
            started=isodate.datetime_isoformat(cont.time_started()),
            allowed_till=isodate.datetime_isoformat((cont.time_started() + timedelta(seconds=self.config('expire')))),
            mem=cont.get_memory_allocated(),
            cpu=cont.get_cpu_allocated(),
            disk=cont.get_disk_allocated(),
            expire=self.config('expire'),
            sections=sections,
            report=report,
            juliaboxver=juliaboxver
        )

        self.rendertpl("ipnbadmin.tpl", d=d, cfg=self.config())
コード例 #7
0
ファイル: auth.py プロジェクト: rudimk/JuliaBox
    def get(self):
        if self.config("gauth"):
            # self_redirect_uri should be similar to  'http://<host>/hostlaunchipnb/'
            self_redirect_uri = self.request.full_url()
            idx = self_redirect_uri.index("hostlaunchipnb/")
            self_redirect_uri = self_redirect_uri[0:(idx +
                                                     len("hostlaunchipnb/"))]

            # state indicates the stage of auth during multistate auth
            state = self.get_argument('state', None)

            code = self.get_argument('code', False)
            if code is not False:
                user = yield self.get_authenticated_user(
                    redirect_uri=self_redirect_uri, code=code)

                # get user info
                http = tornado.httpclient.AsyncHTTPClient()
                auth_string = "%s %s" % (user['token_type'],
                                         user['access_token'])
                response = yield http.fetch(
                    'https://www.googleapis.com/userinfo/v2/me',
                    headers={"Authorization": auth_string})
                user_info = json.loads(response.body)

                user_id = user_info['email']

                jbuser = JBoxUserV2(user_id, create=True)
                if state == 'store_creds':
                    creds = self.make_credentials(user)
                    jbuser.set_gtok(base64.b64encode(creds.to_json()))
                    jbuser.save()
                    #self.log_info(str(user))
                    #self.log_info(creds.to_json())
                else:
                    if self.get_cookie("is_invite", "no") == "yes":
                        code, status = jbuser.get_activation_state()
                        if status != JBoxUserV2.ACTIVATION_GRANTED:
                            jbuser.set_activation_state(
                                code, JBoxUserV2.ACTIVATION_REQUESTED)
                            jbuser.save()
                        self.redirect('/?_msg=' + str(status))
                        return
                    else:
                        self.set_session_cookie(user_id)
                        if jbuser.is_new:
                            jbuser.save()
                    self.redirect('/')
                    return
            else:
                if state == 'ask_gdrive':
                    jbox_cookie = AuthHandler.get_session_cookie(self)
                    scope = ['https://www.googleapis.com/auth/drive']
                    extra_params = {
                        'approval_prompt': 'force',
                        'access_type': 'offline',
                        'login_hint': jbox_cookie['u'],
                        'include_granted_scopes': 'true',
                        'state': 'store_creds'
                    }
                else:
                    scope = ['profile', 'email']
                    extra_params = {'approval_prompt': 'auto'}

                yield self.authorize_redirect(
                    redirect_uri=self_redirect_uri,
                    client_id=self.settings['google_oauth']['key'],
                    scope=scope,
                    response_type='code',
                    extra_params=extra_params)
        else:
            sessname = unquote(self.get_argument("sessname"))
            self.set_session_cookie(sessname)
            self.redirect('/')
コード例 #8
0
    def get(self):
        sessname = unquote(self.get_cookie("sessname"))
        jbox_cookie = AuthHandler.get_session_cookie(self)

        if (None == sessname) or (len(sessname) == 0) or (None == jbox_cookie):
            self.send_error()
            return

        user_id = jbox_cookie['u']
        cont = JBoxContainer.get_by_name(sessname)

        if cont is None:
            self.send_error()
            return

        juliaboxver, upgrade_available = self.get_upgrade_available(cont)
        if self.do_upgrade(cont, upgrade_available):
            response = {'code': 0, 'data': ''}
            self.write(response)
            return

        user = JBoxUserV2(user_id)

        is_admin = sessname in self.config("admin_sessnames", [])
        manage_containers = is_admin or user.has_role(
            JBoxUserV2.ROLE_MANAGE_CONTAINERS)
        show_report = is_admin or user.has_role(JBoxUserV2.ROLE_ACCESS_STATS)
        invites_perm = is_admin or user.has_role(
            JBoxUserV2.ROLE_MANAGE_INVITES)

        sections = []
        loads = []
        report = {}
        report_span = 'day'
        invites_info = []

        action = self.get_argument("action", None)
        #invite_code = self.request.get("invite_code", None)
        if action == "invites_report" and invites_perm:
            self.write(
                dict(code=0, data=[obj for obj in JBoxInvite.table().scan()]))
            return

        if manage_containers:
            sections, loads = self.do_containers()

        if show_report:
            today = datetime.now()
            if self.get_argument('range', 'day') == 'week':
                dates = [today - timedelta(days=i) for i in range(6, -1, -1)]
                report_span = 'week'
            else:
                dates = [today]
            report = JBoxAccountingV2.get_stats(dates)

        d = dict(manage_containers=manage_containers,
                 show_report=show_report,
                 invites_perm=invites_perm,
                 report_span=report_span,
                 sessname=sessname,
                 user_id=user_id,
                 created=isodate.datetime_isoformat(cont.time_created()),
                 started=isodate.datetime_isoformat(cont.time_started()),
                 allowed_till=isodate.datetime_isoformat(
                     (cont.time_started() +
                      timedelta(seconds=self.config('expire')))),
                 mem=cont.get_memory_allocated(),
                 cpu=cont.get_cpu_allocated(),
                 disk=cont.get_disk_allocated(),
                 expire=self.config('expire'),
                 sections=sections,
                 loads=loads,
                 report=report,
                 juliaboxver=juliaboxver,
                 upgrade_available=upgrade_available)

        self.rendertpl("ipnbadmin.tpl", d=d, cfg=self.config())
コード例 #9
0
ファイル: admin.py プロジェクト: bauglir/JuliaBox
    def get(self):
        sessname = unquote(self.get_cookie("sessname"))
        jbox_cookie = AuthHandler.get_session_cookie(self)

        if (None == sessname) or (len(sessname) == 0) or (None == jbox_cookie):
            self.send_error()
            return

        user_id = jbox_cookie['u']
        cont = JBoxContainer.get_by_name(sessname)

        if cont is None:
            self.send_error()
            return

        juliaboxver, upgrade_available = self.get_upgrade_available(cont)
        if self.do_upgrade(cont, upgrade_available):
            response = {'code': 0, 'data': ''}
            self.write(response)
            return

        user = JBoxUserV2(user_id)

        is_admin = sessname in self.config("admin_sessnames", [])
        manage_containers = is_admin or user.has_role(JBoxUserV2.ROLE_MANAGE_CONTAINERS)
        show_report = is_admin or user.has_role(JBoxUserV2.ROLE_ACCESS_STATS)
        invites_perm = is_admin or user.has_role(JBoxUserV2.ROLE_MANAGE_INVITES)

        sections = []
        loads = []
        report = {}
        report_span = 'day'
        invites_info = []

        action = self.get_argument("action", None)
        #invite_code = self.request.get("invite_code", None)
        if action == "invites_report" and invites_perm:
            self.write(dict(
                code=0,
                data=[obj for obj in JBoxInvite.table().scan()]))
            return

        if manage_containers:
            sections, loads = self.do_containers()

        if show_report:
            today = datetime.now()
            if self.get_argument('range', 'day') == 'week':
                dates = [today - timedelta(days=i) for i in range(6, -1, -1)]
                report_span = 'week'
            else:
                dates = [today]
            report = JBoxAccountingV2.get_stats(dates)

        d = dict(
            manage_containers=manage_containers,
            show_report=show_report,
            invites_perm=invites_perm,
            report_span=report_span,
            sessname=sessname,
            user_id=user_id,
            created=isodate.datetime_isoformat(cont.time_created()),
            started=isodate.datetime_isoformat(cont.time_started()),
            allowed_till=isodate.datetime_isoformat((cont.time_started() + timedelta(seconds=self.config('expire')))),
            mem=cont.get_memory_allocated(),
            cpu=cont.get_cpu_allocated(),
            disk=cont.get_disk_allocated(),
            expire=self.config('expire'),
            sections=sections,
            loads=loads,
            report=report,
            juliaboxver=juliaboxver,
            upgrade_available=upgrade_available
        )

        self.rendertpl("ipnbadmin.tpl", d=d, cfg=self.config())
コード例 #10
0
ファイル: admin.py プロジェクト: rudimk/JuliaBox
    def get(self):
        sessname = unquote(self.get_cookie("sessname"))
        jbox_cookie = AuthHandler.get_session_cookie(self)

        if (None == sessname) or (len(sessname) == 0) or (None == jbox_cookie):
            self.send_error()
            return

        user_id = jbox_cookie['u']
        cont = JBoxContainer.get_by_name(sessname)

        if cont is None:
            self.send_error()
            return

        juliaboxver, upgrade_available = self.get_upgrade_available(cont)
        if self.do_upgrade(cont, upgrade_available):
            response = {'code': 0, 'data': ''}
            self.write(response)
            return

        user = JBoxUserV2(user_id)
        show_report = (sessname in self.config("report_sessnames", []) or
                       user.get_role() == JBoxUserV2.ROLE_REPORT)

        admin_user = (sessname in self.config("admin_sessnames", []) or
                      user.get_role() == JBoxUserV2.ROLE_ADMIN)
        show_report = show_report or admin_user

        sections = []
        loads = []
        report = {}
        report_span = 'day'

        if admin_user:
            sections, loads = self.admin_stats()

        if show_report:
            today = datetime.now()
            if self.get_argument('range', 'day') == 'week':
                dates = [today - timedelta(days=i) for i in range(6, -1, -1)]
                report_span = 'week'
            else:
                dates = [today]
            report = JBoxAccountingV2.get_stats(dates)

        d = dict(
            admin_user=admin_user,
            show_report=show_report,
            report_span=report_span,
            sessname=sessname,
            user_id=user_id,
            created=isodate.datetime_isoformat(cont.time_created()),
            started=isodate.datetime_isoformat(cont.time_started()),
            allowed_till=isodate.datetime_isoformat((cont.time_started() + timedelta(seconds=self.config('expire')))),
            mem=cont.get_memory_allocated(),
            cpu=cont.get_cpu_allocated(),
            disk=cont.get_disk_allocated(),
            expire=self.config('expire'),
            sections=sections,
            loads=loads,
            report=report,
            juliaboxver=juliaboxver,
            upgrade_available=upgrade_available
        )

        self.rendertpl("ipnbadmin.tpl", d=d, cfg=self.config())
コード例 #11
0
ファイル: admin.py プロジェクト: rudimk/JuliaBox
    def get(self):
        sessname = unquote(self.get_cookie("sessname"))
        jbox_cookie = AuthHandler.get_session_cookie(self)

        if (None == sessname) or (len(sessname) == 0) or (None == jbox_cookie):
            self.send_error()
            return

        user_id = jbox_cookie['u']
        cont = JBoxContainer.get_by_name(sessname)

        if cont is None:
            self.send_error()
            return

        juliaboxver, upgrade_available = self.get_upgrade_available(cont)
        if self.do_upgrade(cont, upgrade_available):
            response = {'code': 0, 'data': ''}
            self.write(response)
            return

        user = JBoxUserV2(user_id)
        show_report = (sessname in self.config("report_sessnames", [])
                       or user.get_role() == JBoxUserV2.ROLE_REPORT)

        admin_user = (sessname in self.config("admin_sessnames", [])
                      or user.get_role() == JBoxUserV2.ROLE_ADMIN)
        show_report = show_report or admin_user

        sections = []
        loads = []
        report = {}
        report_span = 'day'

        if admin_user:
            sections, loads = self.admin_stats()

        if show_report:
            today = datetime.now()
            if self.get_argument('range', 'day') == 'week':
                dates = [today - timedelta(days=i) for i in range(6, -1, -1)]
                report_span = 'week'
            else:
                dates = [today]
            report = JBoxAccountingV2.get_stats(dates)

        d = dict(admin_user=admin_user,
                 show_report=show_report,
                 report_span=report_span,
                 sessname=sessname,
                 user_id=user_id,
                 created=isodate.datetime_isoformat(cont.time_created()),
                 started=isodate.datetime_isoformat(cont.time_started()),
                 allowed_till=isodate.datetime_isoformat(
                     (cont.time_started() +
                      timedelta(seconds=self.config('expire')))),
                 mem=cont.get_memory_allocated(),
                 cpu=cont.get_cpu_allocated(),
                 disk=cont.get_disk_allocated(),
                 expire=self.config('expire'),
                 sections=sections,
                 loads=loads,
                 report=report,
                 juliaboxver=juliaboxver,
                 upgrade_available=upgrade_available)

        self.rendertpl("ipnbadmin.tpl", d=d, cfg=self.config())