Beispiel #1
0
    def __init__(self):

        DB_NAME = BOOTSTRAP_CONFIG.get("mysql").get("db_name")
        DB_PASS = BOOTSTRAP_CONFIG.get("mysql").get("db_pass")
        DB_USER = BOOTSTRAP_CONFIG.get("mysql").get("db_user")
        DB_HOST = BOOTSTRAP_CONFIG.get("mysql").get("db_host")

        self.dbhost = DB_HOST
        self.dbname = DB_NAME
        self.dbuser = DB_USER
        self.dbpassword = DB_PASS
        self.dbengine = None
        self.dbsession_class = None
Beispiel #2
0
    def __init__(self):

        DB_NAME = BOOTSTRAP_CONFIG.get("mysql").get("db_name")
        DB_PASS = BOOTSTRAP_CONFIG.get("mysql").get("db_pass")
        DB_USER = BOOTSTRAP_CONFIG.get("mysql").get("db_user")
        DB_HOST = BOOTSTRAP_CONFIG.get("mysql").get("db_host")

        self.dbhost = DB_HOST
        self.dbname = DB_NAME
        self.dbuser = DB_USER
        self.dbpassword = DB_PASS
        self.dbengine = None
        self.dbsession_class = None
Beispiel #3
0
    def __init__(self):

        DB_NAME = BOOTSTRAP_CONFIG.get("mysql").get("db_name")
        DB_PASS = BOOTSTRAP_CONFIG.get("mysql").get("db_pass")
        DB_USER = BOOTSTRAP_CONFIG.get("mysql").get("db_user")
        DB_HOST = BOOTSTRAP_CONFIG.get("mysql").get("db_host")

        self.dbhost = DB_HOST
        self.dbname = DB_NAME
        self.dbuser = DB_USER
        self.dbpassword = DB_PASS

        super(SqlInstance, self).__init__()
        return
Beispiel #4
0
    def __init__(self):

        DB_NAME = BOOTSTRAP_CONFIG.get("mysql").get("db_name")
        DB_PASS = BOOTSTRAP_CONFIG.get("mysql").get("db_pass")
        DB_USER = BOOTSTRAP_CONFIG.get("mysql").get("db_user")
        DB_HOST = BOOTSTRAP_CONFIG.get("mysql").get("db_host")

        self.dbhost = DB_HOST
        self.dbname = DB_NAME
        self.dbuser = DB_USER
        self.dbpassword = DB_PASS

        super(SqlInstance, self).__init__()
        return
Beispiel #5
0
def _create_mysql_db():
    DB_HOST = BOOTSTRAP_CONFIG.get("mysql").get("db_host")
    DB_NAME = BOOTSTRAP_CONFIG.get("mysql").get("db_name")
    DB_PASS = BOOTSTRAP_CONFIG.get("mysql").get("db_pass")
    DB_USER = BOOTSTRAP_CONFIG.get("mysql").get("db_user")

    print "Drop MDM DB now, please wait..."
    
    _drop_cmd = "mysql -h%s -u%s -p%s mysql -e \"drop database if exists %s\"" % (DB_HOST, DB_USER, DB_PASS, DB_NAME)
    _create_cmd = "mysql -h%s -u%s -p%s mysql -e \"create database %s default charset utf8\"" % (DB_HOST, DB_USER, DB_PASS, DB_NAME)

    subprocess.check_output(_drop_cmd, shell=True)
    subprocess.check_output(_create_cmd, shell=True)
    return
Beispiel #6
0
 def __init__(self, app):
     _config = BOOTSTRAP_CONFIG.get("gcm")
     _api_key = _config.get("api_key")
     self.gcm = GCM(_api_key)
     self.redis = app.redis
     self.push_handler = GcmPushHandler(self)
     return
Beispiel #7
0
 def __init__(self, *args, **kwargs):
     _config = BOOTSTRAP_CONFIG.get("gcm")
     _api_key = _config.get("api_key")
     self.gcm = GCM(_api_key)
     self.push_handler = PushHandler(self)
     self.redis = redis.Redis(REDIS_HOST, REDIS_PORT, db=1)
     return
Beispiel #8
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
Beispiel #9
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
Beispiel #10
0
 def __init__(self):
     _sqlite = BOOTSTRAP_CONFIG.get("sqlite")
     _dbpath = None
     if _sqlite != None:
         _dbpath = _sqlite.get("db_path")
     if _dbpath == None:
         _dbpath = "/usr/local/var/db/sqlite/ppmessage.db"
     self.dbpath = _dbpath
     super(SqlInstance, self).__init__()
     return
Beispiel #11
0
 def __init__(self):
     _sqlite = BOOTSTRAP_CONFIG.get("sqlite")
     _dbpath = None
     if _sqlite != None:
         _dbpath = _sqlite.get("db_path")
     if _dbpath == None:
         _dbpath = "/usr/local/var/db/sqlite/ppmessage.db"
     self.dbpath = _dbpath
     super(SqlInstance, self).__init__()
     return
Beispiel #12
0
 def work(self, email_request):
     _email = BOOTSTRAP_CONFIG.get("email")
     _type = _email.get("service_type")
     _worker_class = self.service_mapping.get(_type)
     if _worker_class == None:
         logging.error("No worker for the mail service: %s" % _service_name)
         return
     _worker_object = _worker_class(self)
     _worker_object.config(_email)
     _worker_object.work(email_request)
     return
Beispiel #13
0
def _main():
    tornado.options.parse_command_line()

    _config = BOOTSTRAP_CONFIG.get("gcm")
    _api_key = _config.get("api_key")
    if _api_key == None or len(_api_key) == 0:
        logging.info("No gcm api_key config, gcmpush should not start.")
        sys.exit()
    
    _app = GcmPushApp()
    _app.get_delegate("").run_periodic()
    logging.info("Starting gcmpush service......")
    # set the periodic check outdated connection
    tornado.ioloop.IOLoop.instance().start()

    return
Beispiel #14
0
from ppmessage.bootstrap.config import BOOTSTRAP_CONFIG

import subprocess
import traceback
import uuid

def _updateMessagePushTasksCharset(_engine):
    '''
    let it support store emoji
    '''
    _update = "ALTER TABLE message_push_tasks CHANGE body body VARCHAR(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
    _engine.execute(_update)

if __name__ == "__main__":

    DB_NAME = BOOTSTRAP_CONFIG.get("mysql").get("db_name")
    DB_PASS = BOOTSTRAP_CONFIG.get("mysql").get("db_pass")
    DB_USER = BOOTSTRAP_CONFIG.get("mysql").get("db_user")
    
    print "Drop MDM DB now, please wait..."
    
    _drop_cmd = "mysql -u%s -p%s mysql -e \"drop database if exists %s\"" % (DB_USER, DB_PASS, DB_NAME)
    _create_cmd = "mysql -u%s -p%s mysql -e \"create database %s default charset utf8\"" % (DB_USER, DB_PASS, DB_NAME)

    subprocess.check_output(_drop_cmd, shell=True)
    subprocess.check_output(_create_cmd, shell=True)

    from ppmessage.db.models import AdminUser
    from ppmessage.db.models import DeviceUser
    from ppmessage.db.models import OrgGroup
    from ppmessage.db.models import OrgSubGroupData
Beispiel #15
0
import subprocess
import traceback
import uuid


def _updateMessagePushTasksCharset(_engine):
    '''
    let it support store emoji
    '''
    _update = "ALTER TABLE message_push_tasks CHANGE body body VARCHAR(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
    _engine.execute(_update)


if __name__ == "__main__":

    DB_NAME = BOOTSTRAP_CONFIG.get("mysql").get("db_name")
    DB_PASS = BOOTSTRAP_CONFIG.get("mysql").get("db_pass")
    DB_USER = BOOTSTRAP_CONFIG.get("mysql").get("db_user")

    print "Drop MDM DB now, please wait..."

    _drop_cmd = "mysql -u%s -p%s mysql -e \"drop database if exists %s\"" % (
        DB_USER, DB_PASS, DB_NAME)
    _create_cmd = "mysql -u%s -p%s mysql -e \"create database %s default charset utf8\"" % (
        DB_USER, DB_PASS, DB_NAME)

    subprocess.check_output(_drop_cmd, shell=True)
    subprocess.check_output(_create_cmd, shell=True)

    from ppmessage.db.models import AdminUser
    from ppmessage.db.models import DeviceUser
Beispiel #16
0
            logging.error("no gcm inited.")
            return
        # self.gcm.outdate(_delta)
        return

    def push(self):
        while True:
            _request = self.redis.lpop(REDIS_GCMPUSH_KEY)
            if _request == None or len(_request) == 0:
                return
            _request = json.loads(_request)
            self.push_handler.task(_request)
        return

if __name__ == "__main__":
    tornado.options.parse_command_line()

    _config = BOOTSTRAP_CONFIG.get("gcm")
    _api_key = _config.get("api_key")
    if _api_key == None or len(_api_key) == 0:
        logging.info("No gcm api_key config, gcmpush can not start.")
        sys.exit()
    
    _app = GcmPushApp()
    logging.info("Starting gcmpush service......")
    # set the periodic check outdated connection
    tornado.ioloop.PeriodicCallback(_app.outdate, 1000*30).start()
    tornado.ioloop.PeriodicCallback(_app.push, 1000).start()
    tornado.ioloop.IOLoop.instance().start()