def POST(self): """ input: org_name: push_serv: ws_serv: wf_serv: eg_serv: output: rt: """ rt = ecode.FAILED try: i = ws_io.ws_input( ['org_name', 'push_serv', 'ws_serv', 'wf_serv', 'eg_serv']) if not i: raise ecode.WS_INPUT addr_db.add_org(i['org_name'], i['push_serv'], i['ws_serv'], i['wf_serv'], i['eg_serv']) rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('add org.') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid), error_info)
def POST(self): """ input: app_id: name: logo_base64: version: url: remark: output: rt: error code """ rt = ecode.FAILED try: i = ws_io.ws_input( ['app_id', 'name', 'logo_base64', 'version', 'url', 'remark']) if not i: raise ecode.WS_INPUT app_db.update(i['app_id'], i['name'], 'web', i['logo_base64'], i['version'], i['url'], i['remark']) rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('update web app') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid), error_info)
def GET(self): """ input: org_name: output: rt: orgaddr: """ rt = ecode.FAILED orgaddr = {} try: i = ws_io.ws_input(['org_name']) if not i: raise ecode.WS_INPUT orgaddr = addr_db.get(i['org_name']) rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('org list.') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid, orgaddr=orgaddr), error_info)
def POST(self): """ input: uid: user id pw: password dev_id: output: rt: error code """ rt = ecode.FAILED try: i = ws_io.ws_input(['uid', 'pw', 'dev_id']) if not i: raise ecode.WS_INPUT if not backup_user_db.check_pw(i['uid'], sha.new(i['pw']).hexdigest()): if not backup_user_db.is_has_user(i['uid']): raise ecode.USER_UN_REGISTER else: raise ecode.USER_AUTH #登陆标识为dev_id,dev_id为空则未登陆 if not backup_user_db.set_dev(i['uid'], i['dev_id']): raise ecode.DB_OP rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('backup user login') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid), error_info)
def POST(self): """ input: uid: user id / phone number dev_id: imei pw: passwd output: rt: error code """ rt = ecode.FAILED try: i = ws_io.ws_input(['uid', 'pw', 'dev_id']) if not i: raise ecode.WS_INPUT if not send_sms.check_pnumber(i['uid']): raise ecode.ERROR_PNUMBER if not backup_user_db.create(i['uid'], sha.new(i['pw']).hexdigest(), ''): raise ecode.USER_EXIST rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('backup user reg.') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid), error_info)
def GET(self): """ input: cid: value: output: rt: error code """ rt = ecode.FAILED try: i = ws_io.ws_input(['cid', 'value']) if not i: raise ecode.WS_INPUT if captcha_mng.check_captcha(i['cid'], i['value']): rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('check a captcha.') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid), error_info)
def POST(self): """ input: apk_path: remark: apptype: output: rt: error code app_id: """ rt = ecode.FAILED app_id = '' try: i = ws_io.ws_input(['apk_path', 'remark', 'apptype']) if not i: raise ecode.WS_INPUT ap = i['apk_path'].strip(" ") if (ap == ""): raise ecode.NOT_EXIST_APP app_type = ap.split(".")[-1] if app_type == "apk": ai = apk_info.get_apk_info(ap) appfile = "%s.apk" % (ai['app_id']) elif app_type == "sop": ai = apk_info.get_sop_info(ap) appfile = "%s.sop" % (ai['app_id']) else: raise ecode.FAILED logging.error('apkinfo%s', ai) # copy apk file to web download dir. dest_file = os.path.join(config.get('app_download_dir'), 'apps', appfile) #直接复制到远程文件夹中 #shutil.copy2(ap, dest_file) #远程传输到数据服务器 +++20150317 back_host = config.get('redis_host') #都存在数据库服务器,同Mongo地址 rt_c = commands.getstatusoutput('scp %s %s:%s' % (ap, back_host, dest_file)) logging.error('add: scp %s %s:%s!%s', ap, back_host, dest_file, rt_c) commands.getstatusoutput('rm -f %s' % (ap)) #删除临时文件 if rt_c[0] != 0: raise ecode.DB_OP app_db.add_app(ai['app_id'], ai['app_name'], i['apptype'], ai['version'], ai['versionCode'], '/apps/%s' % (appfile), i['remark']) app_id = ai['app_id'] rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED commands.getstatusoutput('rm -f %s' % (ap)) #删除临时文件 logging.error('add app') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid, app_id=app_id), error_info)
def GET(self): """ 此接口的作用是客户端根据收到的应用信息获取应用的下载地址,以下载应用 input: sid:身份验证 output: rt: error code apps:[{app_id,versionCode,url}] """ rt = ecode.FAILED apps = [] try: i = ws_io.ws_input(['sid']) if not i: raise ecode.WS_INPUT user = session_db.user.get_user(i['sid'], web.ctx.ip) if not user: raise ecode.NOT_LOGIN apps_sent = user_db.get_app_buffer(user) if apps_sent: for app_sent in apps_sent: app_id = app_sent.split(',')[0] versionCode = app_sent.split(',')[1] logging.error('app_id is : %s, version code is : %s', app_id, versionCode) #app = app_db.getapp(app_id,versionCode) #apps.append(app) user_db.del_app_buffer(user) #for system update +++11.13 temps = baseStation.get('updatesystem') for temp in temps: #就一个 if app_id == temp[0]: app = { 'app_id': app_id, 'versionCode': versionCode, 'url': '/update/secphone.apk' } else: app = app_db.getapp(app_id, versionCode) apps.append(app) rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('GetAppAddr') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid, apps=apps), error_info)
def GET(self): """ 客户端调用,获取所有的应用id,然后根据应用id获取应用信息 input: sort: utime|name is_asc: yes|no start: count: key: 查询关键字 output: rt: error code applist: [{},{}] """ rt = ecode.FAILED applist = [] try: i = ws_io.ws_input([]) sortkey = 'utime' if i.has_key('sort') and i['sort'] == 'name': sortkey = 'app_name' asc = 1 if i.has_key('is_asc') and i['is_asc'] == 'no': asc = -1 start = 0 if i.has_key('start'): start = int(i['start']) count = 100 if i.has_key('count'): count = int(i['count']) key = '' if i.has_key('key'): key = i['key'] applist = app_db.get_apps_list(key, sortkey, asc, start, count) logging.error('app list.=%s', applist) rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('客户端app list.') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid, applist=applist), error_info)
def GET(self): """ input: uid: phonenumber filename: backupdata name 压缩包 backuptime: 备份时间 (int) output: rt: error code PATH: [filepath,filemd5] """ rt = ecode.FAILED PATH = [] try: i = ws_io.ws_input(['uid', 'filename', 'backuptime']) if not i: raise ecode.WS_INPUT if not backup_user_db.get_dev(i['uid']): raise ecode.NOT_LOGIN #生成校验值 md5 phonenumber = i['uid'] backup_home = '/home/wcloud/opt/org/backup' back_host = config.get('redis_host') #远程主机 file_backup = os.path.join(backup_home, phonenumber, i['backuptime'], i['filename']) rt_md5 = commands.getstatusoutput('ssh ' + back_host + ' "md5sum -b %s"' % (file_backup)) if rt_md5[0] != 0: raise ecode.FAILED file_md5 = rt_md5[1][0:32] #生成下载路径 download_path = os.path.join(phonenumber, i['backuptime'], i['filename']) PATH = [download_path, file_md5] rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('Get backup data') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid, PATH=PATH), error_info)
def GET(self): """ 此接口的作用是获取新系统版本号用于显示 input: sid:身份验证 output: rt: error code version:version """ rt = ecode.FAILED version = 1.0 try: i = ws_io.ws_input(['sid']) if not i: raise ecode.WS_INPUT user = session_db.user.get_user(i['sid'], web.ctx.ip) if not user: raise ecode.NOT_LOGIN if not config.get('is_org'): raise ecode.NOT_ALLOW_OP if not admin_db.is_has_admin( user) and not org.get_config()['admin'] == user: raise ecode.NOT_PERMISSION #for system update +++11.4 temps = baseStation.get('updatesystem') for temp in temps: #就一个 if temp[0] == "secphone": version = temp[1] rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('get system version') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid, version=version), error_info)
def GET(self): """ input: app_id: output: rt: error code appinfo: {} updatetime:{'year':'','month':'','day':''} """ rt = ecode.FAILED appinfo = {} updatetime = {} try: i = ws_io.ws_input(['app_id']) if not i: raise ecode.WS_INPUT appinfo = app_db.get(i['app_id']) #返回更新时间 utime = int(appinfo['utime']) utimeArry = time.localtime(utime) updatetime['year'] = utimeArry.tm_year updatetime['month'] = utimeArry.tm_mon updatetime['day'] = utimeArry.tm_mday rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('app info.') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output( dict(rt=rt.eid, appinfo=appinfo, updatetime=updatetime), error_info)
def POST(self): """ input: uid: user id output: rt: error code """ rt = ecode.FAILED try: i = ws_io.ws_input(['uid']) if not i: raise ecode.WS_INPUT #登陆标识为dev_id,dev_id为空则未登陆 if not backup_user_db.set_dev(i['uid'], ''): raise ecode.DB_OP rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('backup user logout') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid), error_info)
def POST(self): """ input: app_id: output: rt: error code """ rt = ecode.FAILED try: i = ws_io.ws_input(['app_id']) if not i: raise ecode.WS_INPUT app_db.del_app(i['app_id']) rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('del app') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid), error_info)
def POST(self): """ input: uid: user id backuptime: (int) backup_type: (int) 备份类型:0 累加,1 覆盖 data_path: default path data_verify:"file:md5" output: rt: error code """ rt = ecode.FAILED try: i = ws_io.ws_input([ 'uid', 'backuptime', 'backup_type', 'data_path', 'data_verify' ]) data = i['data_path'] if not i: raise ecode.WS_INPUT if not backup_user_db.get_dev(i['uid']): raise ecode.NOT_LOGIN #生成存储路径 phonenumber = i['uid'] backup_type = i['backup_type'] backuptime = i['backuptime'] backup_home = '/home/wcloud/opt/org/backup/' file_path = os.path.join(backup_home, phonenumber, backuptime) #存放备份的文件夹 back_host = config.get('redis_host') #远程主机 #远程创建路径 rt_mkdir = os.popen('ssh ' + back_host + ' "mkdir -p %s"' % (file_path)).close() # if rt_mkdir: #将文件放到生成的目录下 data_verify = i['data_verify'] dataverify = data_verify.split(':') filename = dataverify[0] #校验文件 # rt_md5=commands.getstatusoutput('md5sum -b %s'%(data)) # print rt_md5 # file_md5=rt_md5[1][0:32] # logging.warn("the md5 of backup data is : %s",file_md5) # if file_md5!=dataverify[1]: # commands.getstatusoutput('ssh '+back_host+' "rm %s"'%(file_path)) #校验失败,删除文件 # raise ecode.FAILED # +++20151204 查看备份类型,决定是否进行覆盖操作 # 将原来已有的短信和通讯录插入新的文件中 if (filename.split(".")[1].lower() == "vcf"): old_array = backup_user_db.get_contacts(phonenumber) logging.error("已有通讯录" + str(len(old_array)) + "条") analysis_contact(phonenumber, old_array, data, int(backup_type)) else: old_array = backup_user_db.get_smss(phonenumber) logging.error("已有短信" + str(len(old_array)) + "条") analysis_sms(phonenumber, old_array, data, int(backup_type)) #远程传输 logging.error("存在新文件路径:" + str(os.path.exists(data))) file_backup = os.path.join(file_path, filename) rt_scp = commands.getstatusoutput('scp %s %s:%s' % (data, back_host, file_backup)) logging.error('scp %s %s:%s ! %s', data, back_host, file_backup, rt_scp) if rt_scp[0] != 0: raise ecode.DB_OP rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('data backup') error_info = str(traceback.format_exc()).replace("\n", " ") commands.getstatusoutput('rm -f %s' % (data)) #删除临时文件 return ws_io.ws_output(dict(rt=rt.eid), error_info)
def POST(self): """ 此接口的作用是向用户推送应用信息, 输入数据是推送的应用id和需要推送的用户列表 input: sid:身份验证 app_ids:['app_id,versionCode',''] users:[uid1,uid2,uid3] output: rt: error code """ rt = ecode.FAILED try: i = ws_io.ws_input(['sid', 'users', 'app_ids']) logging.error(i) if not i: raise ecode.WS_INPUT user = session_db.user.get_user(i['sid'], web.ctx.ip) if not user: raise ecode.NOT_LOGIN if not config.get('is_org'): raise ecode.NOT_ALLOW_OP if not admin_db.is_has_admin( user) and not org.get_config()['admin'] == user: raise ecode.NOT_PERMISSION logging.error("用户信息:%s", i['users']) logging.error("应用信息:%s", i['app_ids']) # +++20150801 分级加载导致获取用户方式修改,从后太获取数据 # users=json.loads(i['users']) users = user_db.get_selected_uids(user) app_ids = json.loads(i['app_ids']) #for system update +++11.4 temps = baseStation.get('updatesystem') for temp in temps: #就一个 if app_ids[0][0:8] == temp[0]: newtemp = temp[0] + ',' + temp[1] app_ids = [newtemp] logging.error("应用长度:%d", len(app_ids)) #在每次向用户推送应用之前在用户数据表中写入缓存应用信息,要不然就只能向在线的用户推送应用了 for uid in users: #将app数组传入app_buffer中暂时存储 user_db.add_app_buffer(uid, app_ids) if len(user_db.devs(uid)) == 0: continue else: dev_id = user_db.devs(uid)[0] dev_sid = session_db.user.get_sid(uid, dev_id) if dev_sid != None: logging.error("dev_sid:%s", dev_sid) info = 'apps' logging.error("notify info:%s", info) config.notify_by_push_server(dev_sid, info) rt = ecode.OK error_info = "" except Exception as e: rt = (type(e) == type(ecode.OK)) and e or ecode.FAILED logging.error('send app') error_info = str(traceback.format_exc()).replace("\n", " ") return ws_io.ws_output(dict(rt=rt.eid), error_info)