Exemple #1
0
    def prepare(self):
        """Pre-process HTTP request
        """
        if self.request.headers.has_key('X-An-App-Name'):
            """ App name """
            self.appname = self.request.headers['X-An-App-Name']

        if not self.appname:
            self.appname = filter_alphabetanum(self.get_argument('appname'))

        if self.request.headers.has_key('X-An-App-Key'):
            """ App key """
            self.appkey = self.request.headers['X-An-App-Key']

        self.token = self.get_argument('token', None)
        self.device = self.get_argument('device', DEVICE_TYPE_IOS).lower()
        if self.device == DEVICE_TYPE_IOS:
            if self.token:
                # If token provided, it must be 64 chars
                if len(self.token) != 64:
                    self.send_response(BAD_REQUEST,
                                       dict(error='Invalid token'))
                try:
                    # Validate token
                    binascii.unhexlify(self.token)
                except Exception, ex:
                    self.send_response(BAD_REQUEST,
                                       dict(error='Invalid token: %s' % ex))
    def post(self):
        # Create a new app
        app = {}
        self.appname = filter_alphabetanum(self.get_argument('appshortname').strip().lower())
        app['shortname'] = self.appname
        app['environment'] = 'sandbox'
        app['enableapns'] = 0
        app['connections'] = 1
        app['blockediplist'] = ''
        app['gcmprojectnumber'] = ''
        app['gcmapikey'] = ''
        if self.get_argument('appfullname', None):
            app['fullname'] = self.get_argument('appfullname')
        else:
            app['fullname'] = self.appname

        if self.get_argument('appdescription', None):
            app['description'] = self.get_argument('appdescription')
        else:
            app['description'] = ""

        current_app = self.masterdb.applications.find_one({'shortname': self.appname})
        if not current_app:
            self.masterdb.applications.insert(app)
        self.redirect(r"/applications/%s/settings" % self.appname)
    def prepare(self):
        """Pre-process HTTP request
        """
        if self.request.headers.has_key('X-An-App-Name'):
            """ App name """
            self.appname = self.request.headers['X-An-App-Name'];

        if not self.appname:
            self.appname = filter_alphabetanum(self.get_argument('appname'))

        if self.request.headers.has_key('X-An-App-Key'):
            """ App key """
            self.appkey = self.request.headers['X-An-App-Key']

        self.token = self.get_argument('token', None)
        self.device = self.get_argument('device', DEVICE_TYPE_IOS).lower()
        if self.device == DEVICE_TYPE_IOS:
            if self.token:
                # If token provided, it must be 64 chars
                if len(self.token) != 64:
                    self.send_response(BAD_REQUEST, dict(error='Invalid token'))
                try:
                    # Validate token
                    binascii.unhexlify(self.token)
                except Exception, ex:
                    self.send_response(BAD_REQUEST, dict(error='Invalid token: %s' % ex))
Exemple #4
0
    def post(self):
        # Create a new app
        app = {}
        self.appname = filter_alphabetanum(
            self.get_argument('appshortname').strip().lower())
        app['shortname'] = self.appname
        app['environment'] = 'sandbox'
        app['enableapns'] = 0
        app['connections'] = 1
        app['blockediplist'] = ''
        app['gcmprojectnumber'] = ''
        app['gcmapikey'] = ''
        if self.get_argument('appfullname', None):
            app['fullname'] = self.get_argument('appfullname')
        else:
            app['fullname'] = self.appname

        if self.get_argument('appdescription', None):
            app['description'] = self.get_argument('appdescription')
        else:
            app['description'] = ""

        current_app = self.masterdb.applications.find_one(
            {'shortname': self.appname})
        if not current_app:
            self.masterdb.applications.insert(app)
        self.redirect(r"/applications/%s/settings" % self.appname)
Exemple #5
0
    def prepare(self):
        """Pre-process HTTP request
        """
        self.appname = None
        if "X-An-App-Name" in self.request.headers:
            self.appname = self.request.headers["X-An-App-Name"]
        else:
            self.send_response(BAD_REQUEST, dict(error="app name is required"))

        if not self.appname:
            self.appname = filter_alphabetanum(self.get_argument("appname"))

        self.dao.set_current_app(self.appname)

        self.appkey = None
        if "X-An-App-Key" in self.request.headers:
            self.appkey = self.request.headers["X-An-App-Key"]
        else:
            self.send_response(BAD_REQUEST, dict(error="app key is required"))

        self.token = self.get_argument("token", None)
        self.device = self.get_argument("device", DEVICE_TYPE_IOS).lower()
        if self.device == DEVICE_TYPE_IOS and self.token:
            if len(self.token) != 64:
                # hack until we resolve some bugs at the moodle side
                if len(self.token) > 64:
                    self.device = DEVICE_TYPE_ANDROID
                else:
                    self.send_response(BAD_REQUEST,
                                       dict(error="Invalid token"))
                    return
            else:
                try:
                    binascii.unhexlify(self.token)
                except Exception as ex:
                    self.send_response(BAD_REQUEST,
                                       dict(error="Invalid token"))
        else:
            # if it's not ios then we force android type device here
            self.device = DEVICE_TYPE_ANDROID

        self.app = self.dao.find_app_by_name(self.appname)

        if not self.app:
            self.send_response(BAD_REQUEST,
                               dict(error="Invalid application name"))

        if not self.check_blockediplist(self.request.remote_ip, self.app):
            self.send_response(LOCKED, dict(error="Blocked IP"))
        else:
            key = self.db.keys.find_one({"key": self.appkey})
            if not key:
                self.permission = 0
                if self.accesskeyrequired:
                    self.send_response(BAD_REQUEST,
                                       dict(error="Invalid access key"))
            else:
                if "permission" not in key:
                    key["permission"] = 0
                self.permission = int(key["permission"])
    def prepare(self):
        """Pre-process HTTP request
        """
        self.appname = None
        if self.request.headers.has_key('X-An-App-Name'):
            """ App name """
            self.appname = self.request.headers['X-An-App-Name']

        if not self.appname:
            self.appname = filter_alphabetanum(self.get_argument('appname'))

        self.appkey = None
        if self.request.headers.has_key('X-An-App-Key'):
            """ App key """
            self.appkey = self.request.headers['X-An-App-Key']

        self.token = self.get_argument('token', None)
        self.device = self.get_argument('device', DEVICE_TYPE_IOS).lower()
        if self.device == DEVICE_TYPE_IOS:
            if self.token:
                # If token provided, it must be 64 chars
                if len(self.token) != 64:
                    self.send_response(BAD_REQUEST,
                                       dict(error='Invalid token'))
                try:
                    # Validate token
                    binascii.unhexlify(self.token)
                except Exception as ex:
                    self.send_response(BAD_REQUEST,
                                       dict(error='Invalid token: %s' % ex))
        else:
            self.device = DEVICE_TYPE_ANDROID

        self.app = self.masterdb.applications.find_one(
            {'shortname': self.appname})

        if not self.app:
            self.send_response(BAD_REQUEST,
                               dict(error='Invalid application name'))

        if not self.check_blockediplist(self.request.remote_ip, self.app):
            self.send_response(LOCKED, dict(error='Blocked IP'))
        else:
            key = self.db.keys.find_one({'key': self.appkey})
            if not key:
                self.permission = 0
                if self.accesskeyrequired:
                    self.send_response(BAD_REQUEST,
                                       dict(error='Invalid access key'))
            else:
                if 'permission' not in key:
                    key['permission'] = 0
                self.permission = int(key['permission'])
Exemple #7
0
    def post(self):
        # Create a new app
        app = {}
        self.appname = filter_alphabetanum(
            self.get_argument("appshortname").strip().lower())
        app["shortname"] = self.appname
        if self.currentuser["orgid"] == 0:
            app["orgid"] = int(self.get_argument("orgid", 0))
        else:
            app["orgid"] = self.currentuser["orgid"]
        app["blockediplist"] = ""
        app["clickatellusername"] = ""
        app["clickatellpassport"] = ""
        app["clickatellappid"] = ""
        app[KEY_APNS_AUTHKEY] = ""
        app[KEY_APNS_BUNDLEID] = ""
        app[KEY_APNS_KEYID] = ""
        app[KEY_APNS_TEAMID] = ""
        app[KEY_FCM_JSON_KEY] = ""
        app[KEY_FCM_PROJECT_ID] = ""
        if self.get_argument("appfullname", None):
            app["fullname"] = self.get_argument("appfullname")
        else:
            app["fullname"] = self.appname

        if self.get_argument("appdescription", None):
            app["description"] = self.get_argument("appdescription")
        else:
            app["description"] = ""

        current_app = self.masterdb.applications.find_one(
            {"shortname": self.appname})
        if not current_app:
            self.masterdb.applications.insert(app)
            indexes = [("created", DESCENDING)]
            self.db["tokens"].create_index(indexes)
            self.db["logs"].create_index(indexes)
        self.redirect(r"/applications/%s/settings" % self.appname)