def set_config_syscn(file): for server in get_server_ips(): ip=server if ip=='127.0.0.1': continue if ip==getLocalIp("eth0"): continue try: action_config_command(file,ip) except: pass
def set_config_delete(file): for server in get_server_ips(): ip=server if ip=='127.0.0.1': continue if ip==getLocalIp("eth0"): continue try: mydata={} mydata['filename']=file postHttp(ip,mydata,"6") except: pass
def get_doginfo_byip(): mdog = get_dog_serverip() if mdog['result'] != 0: iniip = read_dog_ip() if iniip != '': return get_doginfo_by_ini(iniip) else: mdata = {} mdata['dogip'] = '1010' mdata['result'] = mdog['result'] return mdata ip = mdog['value'] if ip in get_server_ips(): try: print("dogserver ip is : %s" % ip) #判断是不是本机 if ip == getLocalIp("eth0"): return get_doginfo_by_local() else: mjson = {} mjson['doginfo'] = "get" #读取文件 doginfo = postHttp(ip, mjson, "5") jsondata = json.loads(doginfo) return jsondata['doginfo'] except: mdata = {} mdata['name'] = get_dogname() mdata['dogip'] = get_dog_serverip()['value'] mdata['maxuser'] = get_dog_maxuser() mdata['remaintime'] = "" return mdata else: mdata = {} mdata['name'] = get_dogname() mdata['dogip'] = get_dog_serverip()['value'] mdata['maxuser'] = get_dog_maxuser() mdata['remaintime'] = "" return mdata
def syn_other_file(): msg=[] for server in get_server_ips(): ip=server if ip=='127.0.0.1': continue if ip==getLocalIp("eth0"): continue try: #同步到其他服务器 result=action_other_command_docker('/opt/thunder/www/',ip) action_other_command_docker('/data/OpenRoomToPlay/',ip) action_other_command_docker('/data/AD/',ip) if result==1: msg.append(ip+"同步失败,请检查服务器是否配置或者网络是否畅通") else: msg.append(ip+"同步成功") except: msg.append(ip+"同步失败") return msg
def get_doginfo_by_ini(ip): if ip in get_server_ips(): try: print ip #判断是不是本机 if ip == getLocalIp("eth0"): return get_doginfo_by_local() else: mjson = {} mjson['doginfo'] = "get" #读取文件 doginfo = postHttp(ip, mjson, "5") jsondata = json.loads(doginfo) return jsondata['doginfo'] except: mdata = {} mdata['dogip'] = '1010' mdata['result'] = "请稍后再试" return mdata else: mdata = {} mdata['dogip'] = '1010' mdata['result'] = "请稍后再试" return mdata
def post(self, op): #mtype=self.get_argument('type') ret = {} #查询 #if mtype=="1": if op == 'get': ret['serverip'] = [] try: servers = get_server_ips() ret['serverip'] = servers doginfo = get_doginfo_byip() if doginfo['dogip'] == '1010': ret['code'] = 2 ret['result'] = doginfo['result'] self.send_json(ret) return ret['doginfo'] = doginfo ret['code'] = 0 except: logger.error(traceback.format_exc()) ret['code'] = 1 ret['result'] = None self.send_json(ret) return #elif mtype=="2": elif op == 'upfile': #上传认证文件 result = {} try: upload_path = '/opt/thunder/bin/mainktvserver/' fileN = "license.bin" filepath = os.path.join(upload_path, fileN) if os.path.exists(upload_path): pass else: os.mkdir(upload_path) file_metas = self.request.files['file'] meta = file_metas[0] with open(filepath, 'wb') as up: up.write(meta['body']) up.close() result['code'] = 0 result['msg'] = '操作成功' except: result['code'] = 1 result['msg'] = '操作失败' try: dog_all_inianddata() restartService('mainktv') except: pass set_dog_info_ip(getLocalIp("eth0")) self.send_json(result) return #elif mtype=="3": elif op == 'setpwd': #设置加密狗密码 mdata = self.get_argument('mdata') jsondata = json.loads(mdata) ret = {} upload_path = '/opt/thunder/bin/mainktvserver/' if jsondata['sercrt'] == '': ret['code'] = 1 else: try: # upload_path='config/' fileN = "licensepasswd" filepath = os.path.join(upload_path, fileN) f = open(filepath, 'w') f.write(jsondata['sercrt']) f.close() dog_all_inianddata() restartService('mainktv') ret['code'] = 0 ret['msg'] = '操作成功' except: ret['code'] = 1 ret['msg'] = '权限异常' self.send_json(ret) return #elif mtype=="4": elif op == 'delpwd': #删除密码 ret = {} upload_path = '/opt/thunder/bin/mainktvserver/' try: print 1111 # upload_path='conf/' fileN = "licensepasswd" filename = os.path.join(upload_path, fileN) print filename if os.path.exists(filename): os.remove(filename) dog_all_inianddata() restartService('mainktv') ret['code'] = 0 ret['msg'] = '操作成功' except: ret['code'] = 1 ret['msg'] = '权限异常' self.send_json(ret) return