Esempio n. 1
0
def _main():
    # _d = {
    #     "key": "NGY3YjM2MGM1ZDExNTRlOGRiNDcxNjhjNjA2Y2ExMDE1YmNiOTVkNA==",
    #     "secret": "NGY3YjM2MGM1ZDExNTRlOGRiNDcxNjhjNjA2Y2ExMDE1YmNiOTVkNA==",
    #     "ssl": "off",
    #     "server_name":  "ppmessage.com",
    #     "server_port": "80"
    # }
    from ppmessage.core.constant import API_LEVEL
    from ppmessage.core.constant import CONFIG_STATUS
    from ppmessage.core.utils.config import _get_config

    if _get_config(
    ) == None or _get_config().get("config_status") != CONFIG_STATUS.RESTART:
        print("PPMessage not configed.")
        return

    _api = _get_config().get("api")
    _d = {
        "key": _api.get(API_LEVEL.PPCOM.lower()).get("key"),
        "secret": _api.get(API_LEVEL.PPCOM.lower()).get("secret"),
        "ssl": "off",
        "server_name": _get_config().get("server").get("name"),
        "server_port": _get_config().get("server").get("port")
    }
    config(_d)

    return
Esempio n. 2
0
    def _welcome_email(self, _request):
        _subject = "Welcome to use PPMessage"
        _template = os.path.join(
            _cur_dir(), "../resource/email/welcome-template-en-us.html")

        if _get_config().get("server").get("language").get(
                "locale") == "zh_CN":
            _subject = "欢迎使用 PPMessage"
            _template = os.path.join(
                _cur_dir(), "../resource/email/welcome-template-zh-cn.html")

        with open(_template, "r") as _f:
            _template = _f.read()

        _template = _template.replace("{{user_email}}",
                                      _request.get("user_email"))
        _template = _template.replace("{{user_fullname}}",
                                      _request.get("user_fullname"))
        _template = _template.replace("{{server_name}}",
                                      _get_config().get("server").get("name"))
        _template = _template.replace(
            "{{server_port}}", str(_get_config().get("server").get("port")))
        _email_request = {
            "to": [_request.get("user_email")],
            "subject": _subject,
            "text": _template,
            "html": _template
        }
        self.application.redis.rpush(REDIS_EMAIL_KEY,
                                     json.dumps(_email_request))
        return
Esempio n. 3
0
 def get(self):
     if _get_config() == None or _get_config().get(
             "config_status") != CONFIG_STATUS.RESTART:
         self.redirect("/ppconfig/")
     else:
         self.redirect("/ppconsole/")
     return
Esempio n. 4
0
def _main():
    import sys
    reload(sys)
    sys.setdefaultencoding('utf8')

    tornado.options.parse_command_line()

    _app = MainApplication()

    _app.copy_default_icon()

    _app.load_db_to_cache()

    tornado.httpserver.HTTPServer(_app).listen(
        tornado.options.options.main_port)
    _app.run_periodic()

    #mqtt_message_main()

    _str = "Access http://%s:%d/ to %s PPMessage."
    if _get_config(
    ) == None or _get_config().get("config_status") != CONFIG_STATUS.RESTART:
        logging.info(
            _str %
            (get_ip_address(), tornado.options.options.main_port, "config"))
    else:
        logging.info(
            _str %
            (get_ip_address(), tornado.options.options.main_port, "use"))
    tornado.ioloop.IOLoop.instance().start()
    return
Esempio n. 5
0
def _main():
    # _d = {
    #     "key": "NGY3YjM2MGM1ZDExNTRlOGRiNDcxNjhjNjA2Y2ExMDE1YmNiOTVkNA==",
    #     "secret": "NGY3YjM2MGM1ZDExNTRlOGRiNDcxNjhjNjA2Y2ExMDE1YmNiOTVkNA==",
    #     "ssl": "off",
    #     "server_name":  "ppmessage.com",
    #     "server_port": "80"
    # }
    from ppmessage.core.constant import API_LEVEL
    from ppmessage.core.constant import CONFIG_STATUS
    from ppmessage.core.utils.config import _get_config

    if _get_config() == None or _get_config().get("config_status") != CONFIG_STATUS.RESTART:
        print("PPMessage not configed.")
        return
    
    _api = _get_config().get("api")
    _d = {
        "key": _api.get(API_LEVEL.PPCOM.lower()).get("key"),
        "secret": _api.get(API_LEVEL.PPCOM.lower()).get("secret"),
        "ssl": "off",
        "server_name": _get_config().get("server").get("name"),
        "server_port": _get_config().get("server").get("port")
    }
    config(_d)

    return
Esempio n. 6
0
def _main():
    import sys
    reload(sys)
    sys.setdefaultencoding('utf8')

    tornado.options.parse_command_line()

    _app = MainApplication()

    _app.copy_default_icon()

    _app.load_db_to_cache()
    
    tornado.httpserver.HTTPServer(_app).listen(tornado.options.options.main_port)
    _app.run_periodic()

    #mqtt_message_main()
    
    _str = "Access http://%s:%d/ to %s PPMessage."
    if _get_config() == None or _get_config().get("config_status") != CONFIG_STATUS.RESTART:
        logging.info(_str % (get_ip_address(), tornado.options.options.main_port, "config"))
    else:
        logging.info(_str % (get_ip_address(), tornado.options.options.main_port, "use"))
    tornado.ioloop.IOLoop.instance().start()
    return
Esempio n. 7
0
def _main():
    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')

    tornado.options.define("email", default=None, help="", type=str)
    tornado.options.define("password", default=None, help="", type=str)
    
    tornado.options.parse_command_line()

    _user_email = tornado.options.options.email
    _user_password = tornado.options.options.password

    if not _user_email or not _user_password:
        logging.error("run config with --email=your_email_address --password=initial_password_you_want_set")
        return
    
    if _get_config() != None and _get_config().get("config_status") == CONFIG_STATUS.FIRST:
        logging.error("PPMessage Lite Server alreay configed, run lite.py to start server. Or remove ppmessage/bootstrap/config.json and run config.py again")
        return

    ServerHandler().post()
    DatabaseHandler().post()
    FirstHandler().post({
        "user_email": _user_email,
        "user_password": _user_password,
        "user_fullname": _user_email
    })
    
    return
    def _create_user_name(self, user_uuid=None, data_uuid=None, ip=None):
        logging.info("create anonymous user_uuid: %s, ip: %s" % (user_uuid, ip))
        if user_uuid == None or ip == None or data_uuid == None:
            return
        
        url = "http://123.57.154.168:8099/IP2GEO/"
        http_headers = {"Content-Type" : "application/json"}
        
        http_body = {
            "ip": ip,
            "language": _get_config().get("server").get("language").get("locale"),
            "team_uuid": _get_config().get("team").get("app_uuid"),
            "team_name": _get_config().get("team").get("name")
        }
        
        http_request = HTTPRequest(
            url, method='POST',
            headers=http_headers,
            validate_cert=False,
            body=json.dumps(http_body)
        )

        http_client = AsyncHTTPClient()
        response = yield http_client.fetch(http_request)

        logging.info("geoservice return: %s" % response.body)
        _body = json.loads(response.body)
        
        if _body == None or _body.get("error_code") != 0:
            logging.error("cant get user name by ip: %s" % ip)
            return
        
        _country = _body.get("country")
        _state = _body.get("state")
        _city = _body.get("city")
        _location_user = []
            
        if _country != None and len(_country) != 0:
            _location_user.append(_country)

        if _state != None and len(_state) != 0:
            _location_user.append(_state)

        if _city != None and len(_city) != 0:
            _location_user.append(_city)

        if len(_location_user) == 0:
            return
        
        _user_name = ".".join(_location_user)
        _row = DeviceUser(uuid=user_uuid, user_name=_user_name, user_fullname=_user_name)
        _row.update_redis_keys(self.application.redis)
        _row.async_update(self.application.redis)

        _row = AppUserData(uuid=data_uuid, user_fullname=_user_name)
        _row.update_redis_keys(self.application.redis)
        _row.async_update(self.application.redis)

        return
Esempio n. 9
0
 def post(self, id=None):
     _status = {"status": CONFIG_STATUS.NONE}
     if _get_config() != None:
         _status["status"] = _get_config().get("config_status")
     logging.info(_status)
     self.write(_status)
     self.flush()
     return
Esempio n. 10
0
 def load_db_to_cache(self):
     if _get_config() == None or _get_config().get("config_status") != CONFIG_STATUS.RESTART:
         self.redis.flushdb()
         return
     else:
         from ppmessage.core.utils.db2cache import load
         load(self.redis)
     return
Esempio n. 11
0
 def post(self, id=None):
     _status = {"status": CONFIG_STATUS.NONE}
     if _get_config() != None:
         _status["status"] = _get_config().get("config_status")
     logging.info(_status)
     self.write(_status)
     self.flush()
     return
Esempio n. 12
0
 def load_db_to_cache(self):
     if _get_config() == None or _get_config().get("config_status") != CONFIG_STATUS.RESTART:
         self.redis.flushdb()
         return
     else:
         from ppmessage.core.utils.db2cache import load
         load(self.redis)
     return
Esempio n. 13
0
    def _create_user_name(self, user_uuid=None, ip=None):
        logging.info("create anonymous user_uuid: %s, ip: %s" %
                     (user_uuid, ip))
        if user_uuid == None or ip == None:
            return

        url = "http://123.57.154.168:8099/IP2GEO/"
        http_headers = {"Content-Type": "application/json"}

        http_body = {
            "ip": ip,
            "language":
            _get_config().get("server").get("language").get("locale"),
            "team_uuid": _get_config().get("team").get("app_uuid"),
            "team_name": _get_config().get("team").get("name")
        }

        http_request = HTTPRequest(url,
                                   method='POST',
                                   headers=http_headers,
                                   validate_cert=False,
                                   body=json.dumps(http_body))

        http_client = AsyncHTTPClient()
        response = yield http_client.fetch(http_request)

        logging.info(response.body)
        _body = json.loads(response.body)

        if _body == None or _body.get("error_code") != 0:
            logging.error("cant get user name by ip: %s" % ip)
            return

        _country = _body.get("country")
        _state = _body.get("state")
        _city = _body.get("city")
        _location_user = []

        if _country != None and len(_country) != 0:
            _location_user.append(_country)

        if _state != None and len(_state) != 0:
            _location_user.append(_state)

        if _city != None and len(_city) != 0:
            _location_user.append(_city)

        if len(_location_user) == 0:
            return

        _user_name = ".".join(_location_user)
        _row = DeviceUser(uuid=user_uuid,
                          user_name=_user_name,
                          user_fullname=_user_name)
        _row.update_redis_keys(self.application.redis)
        _row.async_update(self.applicataion.redis)
        return
Esempio n. 14
0
 def copy_default_icon(self):
     if _get_config() == None or _get_config().get("config_status") != CONFIG_STATUS.RESTART:
         return
     _src = os.path.join(os.path.dirname(__file__), "../core/default_icon.png")
     _dst = os.path.join(_get_config().get("server").get("identicon_store"), "default_icon.png")
     if os.path.exists(_dst):
         return
     from shutil import copyfile
     copyfile(_src, _dst)
     return
Esempio n. 15
0
 def copy_default_icon(self):
     if _get_config() == None or _get_config().get("config_status") != CONFIG_STATUS.RESTART:
         return
     _src = os.path.join(os.path.dirname(__file__), "../core/default_icon.png")
     _dst = os.path.join(_get_config().get("server").get("identicon_store"), "default_icon.png")
     if os.path.exists(_dst):
         return
     from shutil import copyfile
     copyfile(_src, _dst)
     return
Esempio n. 16
0
 def _dist_ppcom(self, _request):
     from ppmessage.ppconfig.config.ppcom.config import config
     _d = {
         "ssl": _get_config().get("server").get("ssl"),
         "server_name": _get_config().get("server").get("name"),
         "server_port": _get_config().get("server").get("port"),
         "key": self._api.get(API_LEVEL.PPCOM.lower()).get("key"),
         "secret": self._api.get(API_LEVEL.PPCOM.lower()).get("secret"),
     }
     config(_d)
     return True
Esempio n. 17
0
 def _get_conversation_by_min_uuid(self, min_uuid, page_size): 
     _api = "PP_PAGE_USER_CONVERSATION"
     _data = {
         "app_uuid": _get_config().get("team").get("app_uuid"),
         "user_uuid": _get_config().get("user").get("user_uuid"),
         "min_uuid": min_uuid,
         "page_size": page_size
     }
     self._prepare(_api)
     self._exec(_data)
     return self._get_return("list")        
Esempio n. 18
0
 def _dist_ppcom(self, _request):
     from ppmessage.ppcom.config.config import config
     _d = {
         "ssl": _get_config().get("server").get("ssl"),
         "server_name": _get_config().get("server").get("name"),
         "server_port": _get_config().get("server").get("port"),
         "key": self._api.get(API_LEVEL.PPCOM.lower()).get("key"),
         "secret": self._api.get(API_LEVEL.PPCOM.lower()).get("secret"),
     }
     config(_d)
     return True
    def test_create_p2s_conversation(self):
        print "\n test create p2s conversation \n"
        _api = "PP_CREATE_ANONYMOUS"
        _data = {
            "ppcom_trace_uuid": str(uuid.uuid1()),
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        _user_uuid = self._get_return("user_uuid")

        _api = "PPCOM_CREATE_CONVERSATION"
        _data = {
            "user_uuid": _user_uuid,
            "conversation_type": CONVERSATION_TYPE.P2S,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        _conversation_uuid = self._get_return("uuid")

        for item in self._return_data:
            print item, "\t", self._return_data[item]
        print "\n"

        # from the view of portal_user(the creator)
        _api = "PP_GET_CONVERSATION_INFO"
        _data = {
            "user_uuid": _user_uuid,
            "conversation_uuid": _conversation_uuid,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)

        print "This is how it looks like when a portal user get this p2s conversation \n"
        for item in self._return_data:
            print item, "\t", self._return_data[item]

        # from the view of a service user
        _api = "PP_GET_CONVERSATION_INFO"
        _data = {
            "user_uuid": _get_config().get("user").get("user_uuid"),
            "conversation_uuid": _conversation_uuid,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)

        print "This is how it looks like when a service user get this p2s conversation \n"
        for item in self._return_data:
            print item, "\t", self._return_data[item]

        return
    def test_create_predefined_script(self):
        print "\n test create predefined script \n"
        _api = "PP_ADD_PREDEFINED_SCRIPT_GROUP"
        _data = {
            "group_name": str(uuid.uuid1),
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        _group_uuid = self._get_return("uuid")

        _api = "PPCOM_CREATE_CONVERSATION"
        _data = {
            "user_uuid": _user_uuid,
            "conversation_type": CONVERSATION_TYPE.P2S,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        _conversation_uuid = self._get_return("uuid")

        for item in self._return_data:
            print item, "\t", self._return_data[item]
        print "\n"

        # from the view of portal_user(the creator)
        _api = "PP_GET_CONVERSATION_INFO"
        _data = {
            "user_uuid": _user_uuid,
            "conversation_uuid": _conversation_uuid,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        
        print "This is how it looks like when a portal user get this p2s conversation \n"
        for item in self._return_data:
            print item, "\t", self._return_data[item]

        # from the view of a service user
        _api = "PP_GET_CONVERSATION_INFO"
        _data = {
            "user_uuid": _get_config().get("user").get("user_uuid"),
            "conversation_uuid": _conversation_uuid,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        
        print "This is how it looks like when a service user get this p2s conversation \n"
        for item in self._return_data:
            print item, "\t", self._return_data[item]
        
        return
    def test_create_p2s_conversation(self):
        print "\n test create p2s conversation \n"
        _api = "PP_CREATE_ANONYMOUS"
        _data = {
            "ppcom_trace_uuid": str(uuid.uuid1()),
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        _user_uuid = self._get_return("user_uuid")

        _api = "PPCOM_CREATE_CONVERSATION"
        _data = {
            "user_uuid": _user_uuid,
            "conversation_type": CONVERSATION_TYPE.P2S,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        _conversation_uuid = self._get_return("uuid")

        for item in self._return_data:
            print item, "\t", self._return_data[item]
        print "\n"

        # from the view of portal_user(the creator)
        _api = "PP_GET_CONVERSATION_INFO"
        _data = {
            "user_uuid": _user_uuid,
            "conversation_uuid": _conversation_uuid,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        
        print "This is how it looks like when a portal user get this p2s conversation \n"
        for item in self._return_data:
            print item, "\t", self._return_data[item]

        # from the view of a service user
        _api = "PP_GET_CONVERSATION_INFO"
        _data = {
            "user_uuid": _get_config().get("user").get("user_uuid"),
            "conversation_uuid": _conversation_uuid,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        
        print "This is how it looks like when a service user get this p2s conversation \n"
        for item in self._return_data:
            print item, "\t", self._return_data[item]
        
        return
    def test_create_predefined_script(self):
        print "\n test create predefined script \n"
        _api = "PP_ADD_PREDEFINED_SCRIPT_GROUP"
        _data = {
            "group_name": str(uuid.uuid1),
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        _group_uuid = self._get_return("uuid")

        _api = "PPCOM_CREATE_CONVERSATION"
        _data = {
            "user_uuid": _user_uuid,
            "conversation_type": CONVERSATION_TYPE.P2S,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)
        _conversation_uuid = self._get_return("uuid")

        for item in self._return_data:
            print item, "\t", self._return_data[item]
        print "\n"

        # from the view of portal_user(the creator)
        _api = "PP_GET_CONVERSATION_INFO"
        _data = {
            "user_uuid": _user_uuid,
            "conversation_uuid": _conversation_uuid,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)

        print "This is how it looks like when a portal user get this p2s conversation \n"
        for item in self._return_data:
            print item, "\t", self._return_data[item]

        # from the view of a service user
        _api = "PP_GET_CONVERSATION_INFO"
        _data = {
            "user_uuid": _get_config().get("user").get("user_uuid"),
            "conversation_uuid": _conversation_uuid,
            "app_uuid": _get_config().get("team").get("app_uuid")
        }
        self._prepare(_api)
        self._exec(_data)

        print "This is how it looks like when a service user get this p2s conversation \n"
        for item in self._return_data:
            print item, "\t", self._return_data[item]

        return
Esempio n. 23
0
    def post(self, id=None):
        _status = {"status": CONFIG_STATUS.NONE, "ip": get_ip_address()}
        if _get_config() != None:
            _status["status"] = _get_config().get("config_status")

        if _status["status"] == CONFIG_STATUS.RESTART:
            logging.error("should not request config for PPMessage already configed.")
            return
        
        self.write(_status)
        self.flush()
        return
Esempio n. 24
0
 def get(self, id=None):
     if _get_config() != None and _get_config().get("config_status") == CONFIG_STATUS.RESTART:
         self.redirect("/ppkefu/")
         return
     
     _dir = os.path.dirname(os.path.abspath(__file__))
     _html_path = _dir + "/../resource/html/ppconfig-index.html" 
     _html_file = open(_html_path, "rb")
     _html = _html_file.read()
     _html_file.close()
     self.write(_html)
     self.flush()
Esempio n. 25
0
    def post(self, id=None):
        _status = {"status": CONFIG_STATUS.NONE}
        if _get_config() != None:
            _status["status"] = _get_config().get("config_status")

        if _status["status"] == CONFIG_STATUS.RESTART:
            self.redirect("/")
            return
        
        self.write(_status)
        self.flush()
        return
Esempio n. 26
0
 def _get_access_token(self):
     TOKEN_URI = "http://localhost:8080/ppauth/token"
     body = self._create_body_string({
         "grant_type": "client_credentials",
         "client_id": _get_config().get("api").get("ppcom").get("key"),
         "client_secret": _get_config().get("api").get("ppcom").get("secret"),
     })
     request = tornado.httpclient.HTTPRequest(TOKEN_URI, method="POST", body=body)
     client = tornado.httpclient.HTTPClient()
     response = client.fetch(request)
     res_body = json.loads(response.body)
     return res_body.get("access_token")
Esempio n. 27
0
 def get(self, id=None):
     if _get_config() != None and _get_config().get("config_status") == CONFIG_STATUS.RESTART:
         self.redirect("/ppconsole/")
         return
     
     _dir = os.path.dirname(os.path.abspath(__file__))
     _html_path = _dir + "/../resource/html/ppconfig-index.html" 
     _html_file = open(_html_path, "rb")
     _html = _html_file.read()
     _html_file.close()
     self.write(_html)
     self.flush()
Esempio n. 28
0
    def post(self, id=None):
        _status = {"status": CONFIG_STATUS.NONE, "ip": get_ip_address()}
        if _get_config() != None:
            _status["status"] = _get_config().get("config_status")

        if _status["status"] == CONFIG_STATUS.RESTART:
            logging.error("should not request config for PPMessage already configed.")
            return
        
        self.write(_status)
        self.flush()
        return
Esempio n. 29
0
 def _dump_mqtt_config(self, _request):
     _config = _get_config()
     _config["android"] = {
         "type": "MQTT"
     }
     _dump_config(_config)
     return _return(self, 0)
Esempio n. 30
0
    def _create_user(self, _request):
        from ppmessage.db.models import DeviceUser

        _user_email = _request.get("user_email")
        _user_fullname = _request.get("user_fullname")
        _user_password = _request.get("user_password")
        _user_language = _get_config().get("server").get("language").get(
            "locale")
        _user_icon = random_identicon(_user_email)

        IOLoop.current().spawn_callback(download_random_identicon, _user_icon)

        _row = DeviceUser(uuid=self._user_uuid,
                          app_uuid=self._app_uuid,
                          user_email=_user_email,
                          user_icon=_user_icon,
                          user_status=USER_STATUS.OWNER_2,
                          user_fullname=_user_fullname,
                          user_password=_user_password,
                          user_language=_user_language)

        _row.create_redis_keys(self.application.redis)
        _insert_into(_row)
        self._user_fullname = _user_fullname
        return True
Esempio n. 31
0
 def _unknown_user_name(self):
     _language = "en"
     _locale_string = USER_NAME["en"]
     if _get_config().get("server").get("language").get(
             "locale").lower() == "zh_cn":
         _locale_string = USER_NAME["cn"]
     return _locale_string.get("unknown") + "." + _locale_string.get("user")
Esempio n. 32
0
    def _du(self):

        _request = json.loads(self.request.body)

        _user_uuid = _request.get("user_uuid")
        if not _user_uuid:
            self.setErrorCode(API_ERR.NO_PARA)
            return

        _o = redis_hash_to_dict(self.application.redis, DeviceUser, _user_uuid)
        if not _o:
            self.setErrorCode(API_ERR.NO_OBJECT)
            return

        # not return the password default
        return_password = False
        if "return_password" in _request:
            return_password = _request["return_password"]
        if not return_password:
            del _o["user_password"]
        
        _fn = _o.get("user_fullname")
        if _fn != None and not isinstance(_fn, unicode):
            _fn = _fn.decode("utf-8")

        _rdata = self.getReturnData()
        _rdata.update(_o)
        _rdata["pinyinname0"] = "".join(lazy_pinyin(_fn))
        _rdata["pinyinname1"] = "".join(list(itertools.chain.from_iterable(pinyin(_fn, style=pypinyin.INITIALS))))

        _app_uuid = _get_config().get("team").get("app_uuid")
        _o = redis_hash_to_dict(self.application.redis, AppInfo, _app_uuid)
        _rdata.update({"team": _o});
        return
Esempio n. 33
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
Esempio n. 34
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
Esempio n. 35
0
    def _create_user(self, _request):
        from ppmessage.db.models import DeviceUser
        
        _user_email = _request.get("user_email")
        _user_fullname = _request.get("user_fullname")
        _user_password = _request.get("user_password")
        _user_language = _get_config().get("server").get("language").get("locale")
        _user_icon = random_identicon(_user_email)

        IOLoop.current().spawn_callback(download_random_identicon, _user_icon)
        
        _user_uuid = str(uuid.uuid1())
        _row = DeviceUser(uuid=_user_uuid,
                          user_email=_user_email,
                          user_icon=_user_icon,
                          user_status=USER_STATUS.OWNER_2,
                          user_fullname=_user_fullname,
                          user_password=_user_password,
                          user_language=_user_language)
        
        _row.create_redis_keys(self.application.redis)
        _insert_into(_row)
        self._user_uuid = _user_uuid
        self._user_fullname = _user_fullname
        return True
Esempio n. 36
0
 def _dump_config(self, _request):
     _config = _get_config()
     _config["ios"] = {
         "configed": True
     }
     _dump_config(_config)
     return
Esempio n. 37
0
 def post(self, id=None):
     _status = {"status": CONFIG_STATUS.NONE}
     if _get_config() == None:
         pass  
     elif _get_config().get("db") and _get_config().get("team") and _get_config().get("apns") and _get_config.get("gcm"):
         _status["status"] = CONFIG_STATUS.ANDROID
     elif _get_config().get("db") and _get_config().get("team") and _get_config().get("apns"):
         _status["status"] = CONFIG_STATUS.IOS
     elif _get_config().get("db") and _get_config().get("team"):
         _status["status"] = CONFIG_STATUS.FIRST
     elif _get_config().get("db"):
         _status["status"] = CONFIG_STATUS.DATABASE
     else:
         _status["status"] = CONFIG_STATUS.NONE
     self.write(_status)
     self.flush()
     return
Esempio n. 38
0
 def _dump_config(self):
     _config = _get_config()
     _config["config_status"] = CONFIG_STATUS.IOS
     _config["ios"] = {
         "configed": True
     }
     _dump_config(_config)
     return
Esempio n. 39
0
 def get(self, id=None):
     _status = {"status": "NONE"}
     if _get_config() == None:
         pass  
     elif _get_config().get("db") and _get_config().get("team") and _get_config().get("apns") and _get_config.get("gcm"):
         _status["status"] = "ANDROID"
     elif _get_config().get("db") and _get_config().get("team") and _get_config().get("apns"):
         _status["status"] = "IOS"
     elif _get_config().get("db") and _get_config().get("team"):
         _status["status"] = "FIRST"
     elif _get_config().get("db"):
         _status["status"] = "DATABASE"
     else:
         _status["status"] = "NONE"
     self.set_header("Content-Type", "application/json")
     self.write(json.dumps(_status))
     return
Esempio n. 40
0
 def _dump_mqtt_config(self, _request):
     _config = _get_config()
     _config["config_status"] = CONFIG_STATUS.ANDROID
     _config["android"] = {
         "type": "MQTT"
     }
     _dump_config(_config)
     return _return(self, 0)
Esempio n. 41
0
 def load_db_to_cache(self):
     if _get_config() == None:
         self.redis.flushdb()
         return
     else:
         from ppmessage.core.utils.db2cache import load
         load(self.redis)
     return
Esempio n. 42
0
 def _dump_mqtt_config(self, _request):
     _config = _get_config()
     _config["config_status"] = CONFIG_STATUS.ANDROID
     _config["android"] = {
         "type": "MQTT"
     }
     _dump_config(_config)
     return _return(self, 0)
Esempio n. 43
0
 def _dump_config(self):
     _config = _get_config()
     _config["config_status"] = CONFIG_STATUS.IOS
     _config["ios"] = {
         "configed": True
     }
     _dump_config(_config)
     return
Esempio n. 44
0
 def _dist_ppkefu(self, _request):
     from ppmessage.ppconfig.config.ppkefu.config import config
     _d = {
         "key": self._api.get(API_LEVEL.PPKEFU.lower()).get("key"),
         "server_url": _get_config().get("server").get("url")
     }
     config(_d)
     return True
Esempio n. 45
0
 def _dist_ppkefu(self, _request):
     from ppmessage.ppkefu.config.config import config
     _d = {
         "key": self._api.get(API_LEVEL.PPKEFU.lower()).get("key"),
         "server_url": _get_config().get("server").get("url")
     }
     config(_d)
     return True
Esempio n. 46
0
 def _dump_config(self, _request):
     _config = _get_config()
     _config["api"] = self._api
     _config["team"] = {
         "app_uuid": self._app_uuid
     }
     _config["configed"] = True
     _dump_config(_config)
     return True
Esempio n. 47
0
    def task(self, _data):
        _data = json.loads(_data)
        _config = _data.get("config")
        _body = _data.get("body")

        # FIXME: so far not support for every team has APN cert
        if _get_config() == None:
            logging.error("PPMessage not configed")
            return

        _app_uuid = _get_config().get("team").get("app_uuid")

        if _config == None or _body == None:
            logging.error("Illegal ios push: %s." % str(_data))
            return

        self._push(_app_uuid, _body, _config)
        return
Esempio n. 48
0
 def _dump_gcm_config(self, _request):
     _config = _get_config()
     _config["android"] = {
         "type": "GCM",
         "gcm": {
             api_key: _request.get("api_key")
         }
     }
     _dump_config(_config)
     return _return(self, 0)
Esempio n. 49
0
 def _dump_jpush_config(self, _request):
     _config = _get_config()
     _config["android"] = {
         "type": "JPUSH",
         "jpush": {
             api_key: _request.get("master_secret")
         }
     }
     _dump_config(_config)
     return _return(self, 0)
Esempio n. 50
0
 def _dump_config(self, _request):
     _config = _get_config()
     _config["config_status"] = CONFIG_STATUS.FIRST
     _config["api"] = self._api
     _config["team"] = {
         "app_uuid": self._app_uuid
     }
     _config["configed"] = True
     _dump_config(_config)
     return True
Esempio n. 51
0
 def task(self, _data):
     _data = json.loads(_data)
     _config = _data.get("config")
     _body = _data.get("body")
     #_app_uuid = _data.get("app_uuid")
     
     # FIXME: so far not support for every team has APN cert
     if _get_config() == None:
         logging.error("PPMessage not configed")
         return
     
     _app_uuid = _get_config().get("team").get("app_uuid")
             
     if _config == None or _body == None:
         logging.error("Illegal ios push: %s." % str(_data))
         return
 
     self._push(_app_uuid, _body, _config)
     return
Esempio n. 52
0
 def _dump_config(self, _request):
     _config = _get_config()
     _config["config_status"] = CONFIG_STATUS.FIRST
     _config["api"] = self._api
     _config["team"] = {
         "app_uuid": self._app_uuid
     }
     _config["configed"] = True
     _dump_config(_config)
     return True
Esempio n. 53
0
 def _dump_gcm_config(self, _request):
     _config = _get_config()
     _config["config_status"] = CONFIG_STATUS.ANDROID
     _config["android"] = {
         "type": "GCM",
         "gcm": {
             api_key: _request.get("api_key")
         }
     }
     _dump_config(_config)
     return _return(self, 0)
Esempio n. 54
0
 def _dump_jpush_config(self, _request):
     _config = _get_config()
     _config["config_status"] = CONFIG_STATUS.ANDROID
     _config["android"] = {
         "type": "JPUSH",
         "jpush": {
             api_key: _request.get("master_secret")
         }
     }
     _dump_config(_config)
     return _return(self, 0)
Esempio n. 55
0
    def post(self, id=None):        
        _request = json.loads(self.request.body)

        _config = _get_config()
        if _config == None or _config.get("config_status") != CONFIG_STATUS.FIRST:
            logging.error("can not restart for config_status: %s." % _config.get("config_status"))
            return _return(self, -1)

        self._dump_restart_config()
        _return(self, 0)
        self._restart()
Esempio n. 56
0
    def _return(self):
        _redis = self.application.redis
        _user = redis_hash_to_dict(_redis, DeviceUser, self.user.get("uuid"))
        _r = self.getReturnData()
        _r.update(_user)

        _app_uuid = _get_config().get("team").get("app_uuid")
        _key = AppInfo.__tablename__ + ".uuid." + _app_uuid
        _r["app"] = _redis.hgetall(_key)

        logging.info("PPKEFULOGIN RETURN: %s" % _r)
        return
    def _create(self, _ppcom_trace_uuid):
        _redis = self.application.redis
        _key = DeviceUser.__tablename__ + ".ppcom_trace_uuid." + _ppcom_trace_uuid
        _uuid = _redis.get(_key)

        if _uuid != None:
            _user = redis_hash_to_dict(_redis, DeviceUser, _uuid)
            if _user != None:
                _rdata = self.getReturnData()
                _rdata["user_uuid"] = _uuid
                _rdata["user_email"] = _user["user_email"]
                _rdata["user_fullname"] = _user["user_fullname"]
                _rdata["user_icon"] = _user["user_icon"]
                _rdata["user_status"] = _user.get("user_status")
                return

        _app_uuid = _get_config().get("team").get("app_uuid")
        _du_uuid = str(uuid.uuid1())
        _user_email = _du_uuid + "@" + _app_uuid
        _user_name = self._unknown_user_name()
        _user_icon = random_identicon(_du_uuid)
        
        _values = {
            "uuid": _du_uuid,
            "ppcom_trace_uuid": _ppcom_trace_uuid,
            "user_status": USER_STATUS.ANONYMOUS,
            "is_anonymous_user": True,
            "is_service_user": False,
            "is_owner_user": False,
            "is_removed_user": False,
            "user_name": _user_name,
            "user_email": _user_email,
            "user_fullname": _user_name,
            "user_icon": _user_icon
        }
        
        _row = DeviceUser(**_values)
        _row.async_add(self.application.redis)
        _row.create_redis_keys(self.application.redis)
        
        _rdata = self.getReturnData()
        _rdata["user_uuid"] = _du_uuid
        _rdata["user_fullname"] = _user_name
        _rdata["user_email"] = _user_email
        _rdata["user_name"] = _user_name
        _rdata["user_icon"] = _user_icon

        _ip = self.request.headers.get("X-Real-Ip") or self.request.headers.get("remote_ip") or self.request.remote_ip
        IOLoop.current().spawn_callback(self._create_user_name, user_uuid=_du_uuid, ip=_ip)
        return
Esempio n. 58
0
    def _welcome_email(self, _request):
        _subject = "Welcome to use PPMessage"
        _template = os.path.join(_cur_dir(), "../resource/email/welcome-template-en-us.html")
        
        if _get_config().get("server").get("language").get("locale") == "zh_CN":
            _subject = "欢迎使用 PPMessage"
            _template = os.path.join(_cur_dir(), "../resource/email/welcome-template-zh-cn.html")

        with open(_template, "r") as _f:
            _template = _f.read()
            
        _template = _template.replace("{{user_email}}", _request.get("user_email"))
        _template = _template.replace("{{user_fullname}}", _request.get("user_fullname"))
        _template = _template.replace("{{server_name}}", _get_config().get("server").get("name"))
        _template = _template.replace("{{server_port}}", str(_get_config().get("server").get("port")))
        _email_request = {
            "to": [_request.get("user_email")],
            "subject": _subject,
            "text": _template,
            "html": _template
        }
        self.application.redis.rpush(REDIS_EMAIL_KEY, json.dumps(_email_request))
        return