Esempio n. 1
0
    def get(self):
        EmailVerifyHandler.configure()

        email = unquote(self.get_argument("email", None))
        user_id = unquote(self.get_argument("user_id", None))
        verification_code = unquote(
            self.get_argument("verification_code", None))
        if user_id == None or email == None:
            EmailVerifyHandler.log_error("Bad request to email handler")
            return

        EmailVerifyHandler.log_info(
            "Request to verify email %s with user_id %s", email, user_id)

        if not EmailWhitelistHandler.is_whitelisted(email):
            self.render(
                os.path.join(EmailWhitelistHandler.TEMPLATE_PATH,
                             "email_whitelist.tpl"),
                cfg=JBoxCfg.nv,
                user_id=user_id,
                message=
                "ERROR: entered email is not whitelisted, please try again:")
            return

        if verification_code == None:
            record = EmailVerifyDB(user_id)
            record.set_email(email)

            base_uri = self.request.protocol + "://" + self.request.host + self.request.uri.split(
                '?')[0]
            mail_body = base_uri + '?' + urllib.urlencode(
                {
                    "user_id": user_id,
                    "email": email,
                    "verification_code": record.get_code()
                })
            EmailVerifyHandler.EMAIL_PLUGIN.send_email(
                email, EmailVerifyHandler.EMAIL_SENDER,
                'JuliaBox account activation', mail_body)

            self.render(
                os.path.join(EmailWhitelistHandler.TEMPLATE_PATH,
                             "message.tpl"),
                cfg=JBoxCfg.nv,
                message="Email sent. Please click the link in the mail.")
        else:
            record = EmailVerifyDB(user_id)
            if record.verify(verification_code):
                s = dict(error="",
                         success="Verification OK, please log in again",
                         info="",
                         pending_activation=False,
                         user_id="")
                self.rendertpl("index.tpl", cfg=JBoxCfg.nv, state=s)
            else:
                self.render(os.path.join(EmailWhitelistHandler.TEMPLATE_PATH,
                                         "message.tpl"),
                            cfg=JBoxCfg.nv,
                            message="Verification failed.")
Esempio n. 2
0
    def get(self):
        user_id = unquote(self.get_argument("user_id"))

        if len(user_id) > 0:
            self.post_auth_launch_container(user_id)
        else:
            self.rendertpl("index.tpl", cfg=JBoxCfg.nv, state=self.state(
                error="Please provide an email Id to login with.", success=''))
Esempio n. 3
0
    def get(self):
        user_id = unquote(self.get_argument("user_id"))

        if len(user_id) > 0:
            self.post_auth_launch_container(user_id)
        else:
            self.rendertpl(
                "index.tpl",
                cfg=JBoxCfg.nv,
                state=self.state(
                    error="Please provide an email Id to login with.",
                    success=''))
Esempio n. 4
0
    def get(self):
        EmailVerifyHandler.configure()

        email = unquote(self.get_argument("email", None))
        user_id = unquote(self.get_argument("user_id", None))
        verification_code = unquote(self.get_argument("verification_code", None))
        if user_id == None or email == None:
            EmailVerifyHandler.log_error("Bad request to email handler")
            return

        EmailVerifyHandler.log_info("Request to verify email %s with user_id %s", email, user_id)

        if not EmailWhitelistHandler.is_whitelisted(email):
            self.render(os.path.join(EmailWhitelistHandler.TEMPLATE_PATH, "email_whitelist.tpl"), cfg=JBoxCfg.nv, user_id=user_id, message="ERROR: entered email is not whitelisted, please try again:")
            return

        if verification_code == None:
            record = EmailVerifyDB(user_id)
            record.set_email(email)

            base_uri = self.request.protocol + "://" + self.request.host + self.request.uri.split('?')[0]
            mail_body = base_uri + '?' + urllib.urlencode({
                "user_id": user_id,
                "email": email,
                "verification_code": record.get_code()
            })
            EmailVerifyHandler.EMAIL_PLUGIN.send_email(email, EmailVerifyHandler.EMAIL_SENDER, 'JuliaBox account activation', mail_body)

            self.render(os.path.join(EmailWhitelistHandler.TEMPLATE_PATH, "message.tpl"), cfg=JBoxCfg.nv, message="Email sent. Please click the link in the mail.")
        else:
            record = EmailVerifyDB(user_id)
            if record.verify(verification_code):
                s = dict(error="", success="Verification OK, please log in again", info="", pending_activation=False, user_id="")
                self.rendertpl("index.tpl", cfg=JBoxCfg.nv, state=s)
            else:
                self.render(os.path.join(EmailWhitelistHandler.TEMPLATE_PATH, "message.tpl"), cfg=JBoxCfg.nv, message="Verification failed.")
Esempio n. 5
0
    def _get_container(self, validate=True):
        if (self._session_id is None) or (validate and (not self._valid_session)):
            lenpfx = len(JBoxCookies.COOKIE_PFX_PORT)
            rcvd_cookies = dict()
            for cname in [JBoxCookies.COOKIE_SESS, JBoxCookies.COOKIE_INSTANCEID]:
                rcvd_cookies[cname] = unquote(self.get_cookie(cname))

            for cookie in self.cookies:
                if cookie.startswith(JBoxCookies.COOKIE_PFX_PORT):
                    rcvd_cookies[cookie] = unquote(self.get_cookie(cookie))

            # self.log_debug("received cookies %r", rcvd_cookies)
            try:
                sess_cookie = rcvd_cookies[JBoxCookies.COOKIE_SESS]
                sess_cookie = json.loads(base64.b64decode(sess_cookie))
                # self.log_debug("received sess cookie %r", sess_cookie)
                self._session_id = sess_cookie['c']
                self._instance_id = sess_cookie['i']
                # self.log_debug("received sess_id %r, inst_id %r", self._session_id, self._instance_id)
                self._ports = dict()
                for port_cookie, port_val in rcvd_cookies.iteritems():
                    if port_cookie.startswith(JBoxCookies.COOKIE_PFX_PORT):
                        portname = port_cookie[lenpfx:]
                        port_val = base64.b64decode(port_val)
                        # self.log_debug("read port %s=%s", port_cookie, port_val)
                        port_val = json.loads(port_val)
                        if len(portname) > 0:
                            self._ports[portname] = port_val['p']
            except:
                self._valid_session = False
                self.log_error("exception while reading sess/port cookie")
                traceback.print_exc()
                return False

            if validate:
                # validate the session
                try:
                    sign = signstr(sess_cookie['c'] + sess_cookie['i'] + sess_cookie['t'], JBoxCfg.get('sesskey'))
                    if sign != sess_cookie['x']:
                        self._valid_session = False
                        self.log_info("signature mismatch for %s", sess_cookie['c'])
                        return False

                    d = isodate.parse_datetime(sess_cookie['t'])
                    age = (datetime.datetime.now(pytz.utc) - d).total_seconds()
                    if age > JBoxCookies.AUTH_VALID_SECS:
                        self.log_info("cookie for %s older than allowed days: %r", sess_cookie['c'], sess_cookie['t'])
                        return False
                    self._valid_session = True
                except:
                    self.log_error("exception while validating sess/port cookie")
                    traceback.print_exc()
                    return False

                # validate the ports
                # failure to validate a port still returns True, but removes ports from the port list
                sig1 = self._get_sig(JBoxCookies.COOKIE_AUTH)
                sig2 = sess_cookie['x']

                for port_cookie, port_val in rcvd_cookies.iteritems():
                    if port_cookie.startswith(JBoxCookies.COOKIE_PFX_PORT):
                        portname = port_cookie[lenpfx:]
                        try:
                            port_val = base64.b64decode(port_val)
                            # self.log_debug("session %s, port %s=%s", self._session_id, portname, port_val)
                            port_val = json.loads(port_val)
                            sign = signstr(sig1 + sig2 + portname + str(port_val['p']), JBoxCfg.get('sesskey'))
                            if sign != port_val['x']:
                                self.log_info('session %s port %s has signature mismatch', self._session_id, portname)
                                del self._ports[portname]
                        except:
                            self.log_error('exception parsing session %r port %r', self._session_id, portname)
                            traceback.print_exc()
                            del self._ports[portname]
        return True
Esempio n. 6
0
    def _get_container(self, validate=True):
        if (self._session_id is None) or (validate and
                                          (not self._valid_session)):
            lenpfx = len(JBoxCookies.COOKIE_PFX_PORT)
            rcvd_cookies = dict()
            for cname in [
                    JBoxCookies.COOKIE_SESS, JBoxCookies.COOKIE_INSTANCEID
            ]:
                rcvd_cookies[cname] = unquote(self.get_cookie(cname))

            for cookie in self.cookies:
                if cookie.startswith(JBoxCookies.COOKIE_PFX_PORT):
                    rcvd_cookies[cookie] = unquote(self.get_cookie(cookie))

            # self.log_debug("received cookies %r", rcvd_cookies)
            try:
                sess_cookie = rcvd_cookies[JBoxCookies.COOKIE_SESS]
                sess_cookie = json.loads(base64.b64decode(sess_cookie))
                # self.log_debug("received sess cookie %r", sess_cookie)
                self._session_id = sess_cookie['c']
                self._instance_id = sess_cookie['i']
                # self.log_debug("received sess_id %r, inst_id %r", self._session_id, self._instance_id)
                self._ports = dict()
                for port_cookie, port_val in rcvd_cookies.iteritems():
                    if port_cookie.startswith(JBoxCookies.COOKIE_PFX_PORT):
                        portname = port_cookie[lenpfx:]
                        port_val = base64.b64decode(port_val)
                        # self.log_debug("read port %s=%s", port_cookie, port_val)
                        port_val = json.loads(port_val)
                        if len(portname) > 0:
                            self._ports[portname] = port_val['p']
            except:
                self._valid_session = False
                self.log_error("exception while reading sess/port cookie")
                traceback.print_exc()
                return False

            if validate:
                # validate the session
                try:
                    sign = signstr(
                        sess_cookie['c'] + sess_cookie['i'] + sess_cookie['t'],
                        JBoxCfg.get('sesskey'))
                    if sign != sess_cookie['x']:
                        self._valid_session = False
                        self.log_info("signature mismatch for %s",
                                      sess_cookie['c'])
                        return False

                    d = isodate.parse_datetime(sess_cookie['t'])
                    age = (datetime.datetime.now(pytz.utc) - d).total_seconds()
                    if age > JBoxCookies.AUTH_VALID_SECS:
                        self.log_info(
                            "cookie for %s older than allowed days: %r",
                            sess_cookie['c'], sess_cookie['t'])
                        return False
                    self._valid_session = True
                except:
                    self.log_error(
                        "exception while validating sess/port cookie")
                    traceback.print_exc()
                    return False

                # validate the ports
                # failure to validate a port still returns True, but removes ports from the port list
                sig1 = self._get_sig(JBoxCookies.COOKIE_AUTH)
                sig2 = sess_cookie['x']

                for port_cookie, port_val in rcvd_cookies.iteritems():
                    if port_cookie.startswith(JBoxCookies.COOKIE_PFX_PORT):
                        portname = port_cookie[lenpfx:]
                        try:
                            port_val = base64.b64decode(port_val)
                            # self.log_debug("session %s, port %s=%s", self._session_id, portname, port_val)
                            port_val = json.loads(port_val)
                            sign = signstr(
                                sig1 + sig2 + portname + str(port_val['p']),
                                JBoxCfg.get('sesskey'))
                            if sign != port_val['x']:
                                self.log_info(
                                    'session %s port %s has signature mismatch',
                                    self._session_id, portname)
                                del self._ports[portname]
                        except:
                            self.log_error(
                                'exception parsing session %r port %r',
                                self._session_id, portname)
                            traceback.print_exc()
                            del self._ports[portname]
        return True
Esempio n. 7
0
 def get(self):
     #EmailWhitelistHandler.log_info("State arg: %s", self.get_argument("state"))
     email = unquote(self.get_argument("email"))
     EmailWhitelistHandler.log_info("Obtained email %s", email)
Esempio n. 8
0
 def get(self):
     #EmailWhitelistHandler.log_info("State arg: %s", self.get_argument("state"))
     email = unquote(self.get_argument("email"))
     EmailWhitelistHandler.log_info("Obtained email %s", email)