Example #1
0
    def _save_db(self):
        from ppmessage.db.models import APNSSetting
        
        _dev_pem = None
        _pro_pem = None
        _com_pem = None
        
        if self._dev_cert_file != None and self._dev_cert_password != None:
            _dev_pem = der2pem(self._dev_cert_file, self._dev_cert_password)
        if self._pro_cert_file != None and self._pro_cert_password != None:
            _pro_pem = der2pem(self._pro_cert_file, self._pro_cert_password)
        if self._com_cert_file != None and self._com_cert_password != None:
            _com_pem = der2pem(self._com_cert_file, self._com_cert_password)

        _app_uuid = _get_config().get("team").get("app_uuid")
        _row = APNSSetting(
            uuid=str(uuid.uuid1()),
            name=_app_uuid,
            app_uuid=_app_uuid,
            production_pem=_pro_pem,
            development_pem=_dev_pem,
            combination_pem=_com_pem
        )
        _row.create_redis_keys(self.application.redis)
        _row.async_add(self.application.redis)
        return True
Example #2
0
    def _save_db(self):
        from ppmessage.db.models import APNSSetting
        
        _dev_pem = None
        _pro_pem = None
        _com_pem = None
        
        if self._dev_cert_file != None and self._dev_cert_password != None:
            _dev_pem = der2pem(self._dev_cert_file, self._dev_cert_password)
        if self._pro_cert_file != None and self._pro_cert_password != None:
            _pro_pem = der2pem(self._pro_cert_file, self._pro_cert_password)
        if self._com_cert_file != None and self._com_cert_password != None:
            _com_pem = der2pem(self._com_cert_file, self._com_cert_password)

        _app_uuid = _get_config().get("team").get("app_uuid")
        _row = APNSSetting(
            uuid=str(uuid.uuid1()),
            name=_app_uuid,
            app_uuid=_app_uuid,
            production_pem=_pro_pem,
            development_pem=_dev_pem,
            combination_pem=_com_pem
        )
        _row.create_redis_keys(self.application.redis)
        _row.async_add(self.application.redis)
        return True
Example #3
0
def _create(dbsession):
    _dev_pem = None
    _pro_pem = None
    _dev_p12 = None
    _pro_p12 = None

    _apns_config = BOOTSTRAP_CONFIG.get("apns")
    
    _dev_file = _apns_config.get("dev")
    _pro_file = _apns_config.get("pro")

    _certs_dir = os.path.dirname(os.path.abspath(__file__))
    _certs_dir = _certs_dir + os.path.sep + ".." + os.path.sep + "certs" + os.path.sep + "apnscerts"
    _dev_file = _certs_dir + os.path.sep + _dev_file
    _pro_file = _certs_dir + os.path.sep + _pro_file

    if not os.path.exists(_dev_file) or not os.path.exists(_pro_file):
        print("No dev or pro cert file found")
        sys.exit()
        
    with open(_dev_file, "rb") as _file:
        _dev_p12 = _file.read()
        _dev_pem = der2pem(_dev_p12)

    with open(_pro_file, "rb") as _file:
        _pro_p12 = _file.read()
        _pro_pem = der2pem(_pro_p12)

    _dev_p12 = base64.b64encode(_dev_p12)
    _dev_pem = base64.b64encode(_dev_pem)
    _pro_p12 = base64.b64encode(_pro_p12)
    _pro_pem = base64.b64encode(_pro_pem)

    _app_uuid = BOOTSTRAP_DATA.get("team").get("app_uuid")
    _name = BOOTSTRAP_DATA.get("apns").get("name")
    
    print(len(_dev_pem))
    print(len(_dev_p12))

    print(is_dev)
    _apns = APNSSetting(
        uuid=str(uuid.uuid1()),
        name=_name,
        app_uuid=_app_uuid,
        production_p12=_pro_p12,
        development_p12=_dev_p12,
        production_pem=_pro_pem,
        development_pem=_dev_pem,
        is_development=is_dev,
        is_production=not is_dev,
        createtime=datetime.datetime.now(),
        updatetime=datetime.datetime.now(),
    )

    dbsession.add(_apns)
    dbsession.commit()        
    return
Example #4
0
def _create(dbsession):
    _dev_pem = None
    _pro_pem = None
    _dev_p12 = None
    _pro_p12 = None

    _apns_config = BOOTSTRAP_CONFIG.get("apns")
    
    _dev_file = _apns_config.get("dev")
    _pro_file = _apns_config.get("pro")

    _certs_dir = os.path.dirname(os.path.abspath(__file__))
    _certs_dir = _certs_dir + os.path.sep + ".." + os.path.sep + "certs" + os.path.sep + "apnscerts"
    _dev_file = _certs_dir + os.path.sep + _dev_file
    _pro_file = _certs_dir + os.path.sep + _pro_file
    print(_pro_file)
    if not os.path.exists(_dev_file) or not os.path.exists(_pro_file):
        print("No dev or pro cert file found")
        sys.exit()
        
    with open(_dev_file, "rb") as _file:
        _dev_p12 = _file.read()
        _dev_pem = der2pem(_dev_p12)

    with open(_pro_file, "rb") as _file:
        _pro_p12 = _file.read()
        _pro_pem = der2pem(_pro_p12)

    _dev_p12 = base64.b64encode(_dev_p12)
    _dev_pem = base64.b64encode(_dev_pem)
    _pro_p12 = base64.b64encode(_pro_p12)
    _pro_pem = base64.b64encode(_pro_pem)

    _app_uuid = BOOTSTRAP_DATA.get("team").get("app_uuid")
    _name = BOOTSTRAP_DATA.get("apns").get("name")
    
    print(len(_dev_pem))
    print(len(_dev_p12))

    print(is_dev)
    _apns = APNSSetting(
        uuid=str(uuid.uuid1()),
        name=_name,
        app_uuid=_app_uuid,
        production_p12=_pro_p12,
        development_p12=_dev_p12,
        production_pem=_pro_pem,
        development_pem=_dev_pem,
        is_development=is_dev,
        is_production=not is_dev,
        createtime=datetime.datetime.now(),
        updatetime=datetime.datetime.now(),
    )

    dbsession.add(_apns)
    dbsession.commit()        
    return
Example #5
0
def _create_apns_settings(_session, _config):
    _dev_pem = None
    _pro_pem = None
    _dev_p12 = None
    _pro_p12 = None

    _app_uuid = _config.get("team").get("app_uuid")
    _apns_config = _config.get("apns")

    _name = _apns_config.get("name")
    _dev_file = _apns_config.get("dev")
    _pro_file = _apns_config.get("pro")

    _certs_dir = os.path.dirname(os.path.abspath(__file__))
    _certs_dir = _certs_dir + os.path.sep + ".." + os.path.sep + "certs" + os.path.sep + "apnscerts"
    _dev_file = _certs_dir + os.path.sep + _dev_file
    _pro_file = _certs_dir + os.path.sep + _pro_file

    if not os.path.exists(_dev_file) or not os.path.exists(_pro_file):
        print("No dev or pro cert file found")
        return _config
        
    with open(_dev_file, "rb") as _file:
        _dev_p12 = _file.read()
        _dev_pem = der2pem(_dev_p12)

    with open(_pro_file, "rb") as _file:
        _pro_p12 = _file.read()
        _pro_pem = der2pem(_pro_p12)

    _dev_p12 = base64.b64encode(_dev_p12)
    _dev_pem = base64.b64encode(_dev_pem)
    _pro_p12 = base64.b64encode(_pro_p12)
    _pro_pem = base64.b64encode(_pro_pem)

    _apns = APNSSetting(
        uuid=str(uuid.uuid1()),
        app_uuid=_app_uuid,
        name = _name,
        production_p12=_pro_p12,
        development_p12=_dev_p12,
        production_pem=_pro_pem,
        development_pem=_dev_pem,
        is_development=False,
        is_production=True
    )
    _session.add(_apns)
    _session.commit()
    return _config
Example #6
0
def _create_apns_settings(_session, _config):
    _dev_pem = None
    _pro_pem = None
    _dev_p12 = None
    _pro_p12 = None

    _apns = _config.get("apns")
    _dev_path = _apns.get("dev")
    _pro_path = _apns.get("pro")
    _name = _apns.get("name")
    _app_uuid = _config.get("team").get("app_uuid")

    if _apns == None or _dev_path == None or _pro_path == None or _name == None:
        return _config

    if len(_dev_path) == 0 or len(_pro_path) == 0 or len(_name) == 0:
        return _config

    try:
        with open(_dev_path, "rb") as _file:
            _dev_p12 = _file.read()
            _dev_pem = der2pem(_dev_p12)

        with open(_pro_path, "rb") as _file:
            _pro_p12 = _file.read()
            _pro_pem = der2pem(_pro_p12)
    except:
        print("no apns config. iospush will not start.")
        return _config

    _dev_p12 = base64.b64encode(_dev_p12)
    _dev_pem = base64.b64encode(_dev_pem)
    _pro_p12 = base64.b64encode(_pro_p12)
    _pro_pem = base64.b64encode(_pro_pem)
    
    _apns = APNSSetting(
        uuid=str(uuid.uuid1()),
        app_uuid=_app_uuid,
        name = _name,
        production_p12=_pro_p12,
        development_p12=_dev_p12,
        production_pem=_pro_pem,
        development_pem=_dev_pem,
        is_development=False,
        is_production=True
    )
    _session.add(_apns)
    _session.commit()
    return _config
Example #7
0
def _main():
    logging.basicConfig(level=logging.DEBUG)
    _file = "/Users/dingguijin/Desktop/ppkefu-123.p12"
    with open(_file, "r") as _f:
        _s = der2pem(_f.read(), "x")
        if _s == None:
            print("error")
        else:
            print("success")
        print(_s)
    return
def _main():
    logging.basicConfig(level=logging.DEBUG)
    _file = "/Users/dingguijin/Desktop/ppkefu-123.p12"
    with open(_file, "r") as _f:
        _s = der2pem(_f.read(), "x")
        if _s == None:
            print "error"
        else:
            print "success"
        print _s
    return
    def _create_apns(self, _app_uuid):
        from ppmessage.db.models import AppInfo
        _key = AppInfo.__tablename__ + ".uuid." + _app_uuid

        if self.redis.hget(_key, "enable_apns_push") == "False":
            return None

        _combination_pem = self.redis.hget(_key, "apns_combination_pem_data")
        if _combination_pem == None:
            return None

        _combination_pem_password = self.redis.hget(_key, "apns_combination_pem_password")
        _pem = der2pem(_combination_pem, _combination_pem_password)
        
        _file = os.path.abspath(os.path.join(os.path.dirname(__file__), "../certs/%s-combination.pem" % _app_uuid))
        with open(_file, "w") as _wf:
            _wf.write(_wf, _pem)

        _apns = {"combination_pem": _file}
        return _apns
Example #10
0
    def _create_apns(self, _app_uuid):
        from ppmessage.db.models import AppInfo
        _key = AppInfo.__tablename__ + ".uuid." + _app_uuid

        if self.redis.hget(_key, "enable_apns_push") == "False":
            return None

        _combination_pem = self.redis.hget(_key, "apns_combination_pem_data")
        if _combination_pem == None:
            return None

        _combination_pem_password = self.redis.hget(_key, "apns_combination_pem_password")
        _pem = der2pem(_combination_pem, _combination_pem_password)
        
        _file = os.path.abspath(os.path.join(os.path.dirname(__file__), "../certs/%s-combination.pem" % _app_uuid))
        with open(_file, "w") as _wf:
            _wf.write(_wf, _pem)

        _apns = {"combination_pem": _file}
        return _apns