def tong_all_inianddata(): mymsg = [] cf = ConfigParser.ConfigParser() cf.read('path.ini') str_val = cf.get("sec_a", "boxpath") if find_file_servers() == None: return starr = {} for server in find_file_servers(): ip = server['FileServer_IpAddress'] print "ip", ip if ip == '127.0.0.1': continue if ip == getLocalIp("eth0"): continue try: actionCommand(str_val, ip) tongbu_file(ip) set_other_ip_thunder(ip) syn_all_file(ip) mymsg.append(str(ip) + "同步成功|") except: mymsg.append(str(ip) + "同步失败|") continue return mymsg
def check_change_version_code(): #第一步去主服务器上获取,并携带本地的code allinfo={} #获取主服务器地址 tminfo=read_all_info() mainservser=tminfo['mainserver'] ip=mainservser['DataBaseServerIp'] if ip=="127.0.0.1": return 2 #获取本机的ip地址 if ip==getLocalIp("eth0"): return 3 #获取本地的code changecode=read_thunder_changecode() allinfo['changecode']=changecode recodata=postHttp(ip,allinfo,"3") dictdata=json.loads(recodata) if dictdata['code']==0: ttype=(dictdata["result"]) if ttype['type']==0: thunderinfo=ttype[thunder] #设置本地的文件 set_all_thunder_data(thunderinfo) #并且设置本地的文件的code set_thunder_changecode(ttype["versioncode"]) return 0 else: return 1 return 1
def is_a_nect(ip): iparr = ip.split('.') locaarr = (getLocalIp("eth0")).split('.') if iparr[0] == locaarr[0] and iparr[1] == locaarr[1] and iparr[ 2] == locaarr[2]: return 0 else: return 1
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_main_server(filename, jsondata, strcode): item = jsondata cf = IniConfig() cf.readfp(codecs.open(filename, "r", strcode)) cf.set("MainServer", "DataBaseServerName", item['DataBaseServerName']) cf.set("MainServer", "DataBaseServerIp", item['DataBaseServerIp']) cf.set("MainServer", "UserName", item['UserName']) cf.set("MainServer", "Password", item['Password']) localIP = getLocalIp("eth0") cf.set("MainServer", "FileServerIP", localIP) cf.write(codecs.open(filename, "w", strcode))
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 writer_other_setting(): #写入本机ip thunderdata=read_all_setting() mainserver=thunderdata['mainserver'] mdata={} mdata['DataBaseServerIp']=mainserver['DataBaseServerIp'] mdata['UserName']=mainserver['UserName'] mdata['Password']=mainserver['Password'] localIP =getLocalIp("eth0") mdata['FileServerIP']=localIP set_main_server_first(mdata,"utf8") #写主服务器的ip地址 #写conf mainserver=thunderdata['erpserver'] set_erp_conf(mainserver['DataBaseServerIp'])
def tongbu_file(ip): str_licenseinfo = '/opt/thunder/bin/mainktvserver/' try: cf = ConfigParser.ConfigParser() cf.read('path.ini') str_val = cf.get("sec_a", "boxpath") if ip == '127.0.0.1': return 0 if ip == getLocalIp("eth0"): return 0 #同步license action_other_command_docker(str_licenseinfo, ip) if action_other_command_docker(str_val, ip) == 1: return 1 return 0 except: return 1
def set_stb_syscn(): cf = ConfigParser.ConfigParser() cf.read('path.ini') str_val = cf.get("sec_a", "boxpath") if find_file_servers() == None: return starr = {} for server in find_file_servers(): ip = server['FileServer_IpAddress'] print "ip", ip if ip == '127.0.0.1': continue if ip == getLocalIp("eth0"): continue try: actionCommand(str_val, ip) except: continue
def get_doginfo_by_local(): read_path = '/opt/thunder/bin/mainktvserver/' filename = os.path.join(read_path, 'licenseinfo') cf = IniConfig() f = open(filename, "r") data = f.read() cf.readfp(codecs.open(filename, 'r', 'gbk')) doginfo = cf.items("DOGINFO") print('^' * 17) print("%s" % doginfo) mdata = {} for colum in doginfo: mdata[colum[0]] = colum[1] mdata['dogip'] = getLocalIp("eth0") #set_dog_info(getLocalIp("eth0"),mdata['describe']) return mdata
def dog_all_inianddata(): mymsg = [] str_licenseinfo = '/opt/thunder/bin/mainktvserver/' if find_file_servers() == None: return starr = {} for server in find_file_servers(): ip = server['FileServer_IpAddress'] print "ip", ip if ip == '127.0.0.1': continue if ip == getLocalIp("eth0"): continue try: action_other_command_docker(str_licenseinfo, ip) mymsg.append(str(ip) + "同步成功|") except Exception, e: print 'exception', e mymsg.append(str(ip) + "同步失败|") continue
def syn_all_file(ip): msg=[] print "ip",ip if ip=='127.0.0.1': return msg if ip==getLocalIp("eth0"): return msg 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_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 get_thunder_ini_db(): #获取主服务器地址 tminfo=read_all_info() mainservser=tminfo['mainserver'] ip=mainservser['DataBaseServerIp'] if ip=="127.0.0.1": return 2 #获取本机的ip地址 if ip==getLocalIp("eth0"): return 3 content=sp_findthunder_ini() if content=='': return 1 else: result=writer_thunder_ini(content) #去更改文件 writer_other_setting() if result==0: return 0 else: return 3
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): mtype = self.get_argument('type') _strcode = "utf8" cf = ConfigParser.ConfigParser() cf.read('path.ini') str_val = cf.get("sec_a", "systemparh") _res = {} _res['code'] = 0 _res['msg'] = "修改成功!" if mtype == "1": #保存系统设置 mdata = self.get_argument('mdata') mchangetype = self.get_argument('changetype') if (mchangetype == "sure"): mjsondata = json.loads(mdata) misc = mjsondata['misc'] # mainserver = mjsondata['mainserver'] erpserver = mjsondata['erpserver'] # erp=mjsondata['erp'] # ktv=mjsondata['ktv'] cloudset = mjsondata['cloudset'] cloudmusic = mjsondata['cloudlogin'] try: set_erpserver(str_val, erpserver, _strcode) set_misc(str_val, misc, _strcode) # set_ktv(str_val,ktv,_strcode) up_cloud_setting(cloudset) up_cloudmusic_setting(cloudmusic) allip = find_all_servers_ip() print allip jsondata = {} for ip in allip: if ip == getLocalIp("eth0"): pass else: state = postHttp(ip, mjsondata, "0") if state != 0: print ip + "修改失败" mresult = 1 tminfo = read_all_info() mainserver = tminfo['mainserver'] if getLocalIp("eth0") == mainserver['DataBaseServerIp']: mresult = read_thunder_ini_to_db() _res['result'] = mresult _res['msg'] = "设置成功!" if 'loginpassword' in cloudmusic.keys( ) and cloudmusic['loginpassword']: CloudLoginTask.get_auth_info() _bres, _msg = CloudLoginTask.cloud_login_msg() if _bres: _res['msg'] += "云端帐号登录测试成功!" else: _res['msg'] += "云端帐号登录测试失败!云端消息:%s" % _msg except Exception as ex: print traceback.format_exc() _res['code'] = 1 _res['result'] = 1 _res['msg'] = "设置失败" #//分发数据 #获取各个服务器ip self.send_json(_res) elif mtype == "3": updatatype = self.get_argument('updatatype') mdata = self.get_argument('mdata') mjsondata = json.loads(mdata) if updatatype == "addFristLevel": mid = add_server_groups(mjsondata) infojson = {} infojson['result'] = "0" infojson['groupid'] = mid infojson['groupservers'] = find_file_servers() infojson['servergroups'] = find_server_groups() self.send_json(infojson) elif updatatype == "updataFristLevel": result = updata_server_groups(mjsondata['ServerGroup_ID'], mjsondata) infojson = {} infojson['result'] = result self.send_json(infojson) elif updatatype == 'deleteFristLevel': result = delete_server_groups_id(mjsondata['ServerGroup_ID']) infojson = {} infojson['result'] = result self.send_json(infojson) elif updatatype == 'addSecondLevel': mn = sp_addfileserver(name=mjsondata['name'], ipaddress=mjsondata['ipaddress'], os=mjsondata['os'], isvalid=mjsondata['isvalid'], group_id=mjsondata['group_id'], group_name=mjsondata['group_name'], ismain=mjsondata['ismain']) # mtjson={} # mtjson['server_ip']=mjsondata['ipaddress'] # mtjson['server_type']="0" # sp_add_systhunder(mtjson) infojson = {} infojson['msg'] = '操作成功' try: sp_roomktvservermapping() except: infojson['msg'] = "设置服务器优先级出错!" if tongbu_file(mjsondata['ipaddress']) == 1: infojson['msg'] = ("添加成功,但" + mjsondata['ipaddress'] + "网络异常,请查看是否配置或者是否连接") mresult = set_other_ip_thunder(mjsondata['ipaddress']) # if mresult==1: # infojson["msg"]="在同一个服务器下" # elif mresult==0: # infojson["msg"]="同步成功" # else: # infojson["msg"]="同步失败" # infojson['msg']=is_allright_ip(mjsondata['ipaddress']) infojson['mtype'] = str(mn) self.send_json(infojson) elif updatatype == "removeSecondLevel": ipaddress = mjsondata['ipaddress'] print ipaddress if sp_check_by_address(ipaddress): deleteAllData() infojson = {} amn = sp_deletefileserver(rid='', ipaddress=ipaddress) # sp_delete_synthunder(ipaddress) try: sp_roomktvservermapping() except: infojson['msg'] = "设置服务器优先级出错!" infojson['msg'] = "修改成功!" print "result:" + str(amn) infojson['mtype'] = str(amn) infojson['result'] = "删除成功" self.send_json(infojson) elif updatatype == "updataSecondLevel": amn = sp_modifyfileserver(mjsondata) sp_roomktvservermapping() infojson = {} print "result:" + str(amn) infojson['mtype'] = str(amn) self.send_json(infojson) elif updatatype == "setmianlevel": amn = set_mian_group(mjsondata['ServerGroup_ID']) infojson = {} infojson['mtype'] = str(amn) infojson['result'] = "0" infojson['groupservers'] = find_file_servers() infojson['servergroups'] = find_server_groups() self.send_json(infojson) elif updatatype == "checkisonly": #检查是否为最后一台 count = sp_check_only_fileserver(mjsondata['ServerGroup_ID']) infojson = {} if count == 1: if sp_check_is_have_media(mjsondata['ServerGroup_ID']): infojson['count'] = count else: infojson['count'] = "2" else: infojson['count'] = count infojson['result'] = "0" self.send_json(infojson) elif mtype == "4": updatatype = self.get_argument('updatatype') mdata = self.get_argument('mdata') mjsondata = json.loads(mdata) if updatatype == "find": infojson = {} infojson['theme'] = get_all_theme_info() infojson['localtheme'] = get_theme_package() self.send_json(infojson) elif updatatype == "addtheme": mdata = self.get_argument('mdata') _res = {} if sp_find_theme_by_name(mjsondata['theme_name']) == 0: _res['code'] = "1" _res['msg'] = "有重复皮肤!" else: _res['code'] = sp_add_theme_con(mjsondata) _res['msg'] = "添加成功!" self.send_json(_res) elif updatatype == "updatatheme": mdata = self.get_argument('mdata') _res = {} _res['code'] = sp_modify_theme_con(mjsondata) _res['msg'] = "修改成功!" self.send_json(_res) elif updatatype == "deletetheme": _res = {} _res['code'] = sp_delete_theme_con(mjsondata) _res['msg'] = "删除成功!" self.send_json(_res) pass elif mtype == "5": #获取服务器信息 updatatype = self.get_argument('updatatype') mdata = self.get_argument('mdata') mjsondata = json.loads(mdata) #需要去调用获取服务的信息 if updatatype == "ls": mjson = {} mjson['server'] = lsService() result = get_server_info(mjsondata['ip']) mjson['sbtinfo'] = {} if result != 1: mjson['sbtinfo'] = result _res = {} _res['msg'] = "获取成功" _res['code'] = 0 _res['data'] = mjson self.send_json(_res) elif updatatype == "restart": servierarr = [ 'dbass', 'dhcp', 'recog', 'record', 'broadcast', 'video', 'stbmodule' ] serverjson = {} serverjson['dbass'] = 'KTV数据服务' serverjson['dhcp'] = 'DHCP服务' serverjson['recog'] = '手写服务' serverjson['record'] = '录音服务' serverjson['broadcast'] = '广播服务' serverjson['video'] = '视频服务' serverjson['stbmodule'] = '模板同步服务' serverjson['mainktv'] = '加密狗服务' serverjson['twm'] = '数据管理服务' serverjson['search'] = '搜索服务' serverjson['transfer_vod'] = '微信点歌服务' serverjson['wx_ngrok'] = '微信点歌连接' _res = {} _res['msg'] = '' try: for sign in mjsondata['name']: if restartService(sign) == 0: if _res['msg'] == '': _res['msg'] = serverjson[sign] + "操作成功!" else: _res['msg'] = _res['msg'] + "," + serverjson[ sign] + "操作成功!" else: if _res['msg'] == '': _res['msg'] = serverjson[sign] + "操作失败!" else: _res['msg'] = _res['msg'] + "," + serverjson[ sign] + "操作失败!" except: _res['msg'] = "启动失败!" _res['code'] = 0 self.send_json(_res) elif updatatype == "stopserver": servierarr = [ 'TD_DBAss', 'TD_DHCP', 'TD_RecogServer', 'TD_RecordServer', 'TD_Broadcast', 'TD_VideoServer' ] _res = {} _res['msg'] = '' for sign in mjsondata['name']: if sign == "twm": continue if stopService(sign) == 0: if _res['msg'] == '': _res['msg'] = sign + "停止服务成功!" else: _res['msg'] = _res['msg'] + "," + sign + "停止服务成功!" else: if _res['msg'] == '': _res['msg'] = sign + "停止失败!" else: _res['msg'] = _res['msg'] + "," + sign + "停止失败!" _res['code'] = 0 self.send_json(_res) elif mtype == "6": _res = {} _res['msg'] = "获取成功" _res['code'] = check_change_version_code() self.send_json(_res) pass elif mtype == "7": #同步服务器 _res = {} _res['code'] = "0" mmsg = tong_all_inianddata() if len(mmsg) == 0: _res['msg'] = '只有一台服务器' else: _res['msg'] = mmsg self.send_json(_res) pass else: print mtype #get systemset info cf = ConfigParser.ConfigParser() cf.read('path.ini') str_val = cf.get("sec_a", "systemparh") infojson = {} add_defult_groups() infojson['systemsetting'] = read_all_setting(str_val, _strcode) infojson['groupservers'] = find_file_servers() infojson['servergroups'] = find_server_groups() mtemp = {} cloudmusic = {} try: for disco in find_data_setting(): if disco['SettingInfo_Name'] == "中转服务器IP": mtemp["centerinip"] = disco['SettingInfo_Value'] elif disco['SettingInfo_Name'] == "中转服务器外网IP": mtemp["centeroutip"] = disco['SettingInfo_Value'] elif disco['SettingInfo_Name'] == "本地VPN域名": mtemp["localname"] = disco['SettingInfo_Value'] elif disco['SettingInfo_Name'] == "SSID": mtemp["ssid"] = disco['SettingInfo_Value'] elif disco['SettingInfo_Name'] == "SSID_Pwd": mtemp["ssidpw"] = disco['SettingInfo_Value'] #for cloud music login info: elif disco['SettingInfo_Name'] == "CloudMusic_uname": cloudmusic["loginname"] = disco['SettingInfo_Value'] elif disco['SettingInfo_Name'] == "CloudMusic_passwd": cloudmusic["loginpassword"] = disco[ 'SettingInfo_Value'] elif disco['SettingInfo_Name'] == "CloudMusic_realdown": cloudmusic["realdown"] = disco['SettingInfo_Value'] except: pass infojson['cloudset'] = mtemp infojson['karaokversion'] = find_last_karaok_version() infojson['cloudlogin'] = cloudmusic print mtemp # sp_lookupktvservers(id='',ipaddress='') # sp_lookupfileservers(id='', ipaddress='', group_id='', group_name='') # get_thunder_ini_db() self.send_json(infojson)
def post(self): ret = {} mdata={} mdata['DataBaseServerIp']=self.get_argument('DataBaseServerIp', '127.0.0.1') # mdata['UserName']=self.get_argument('UserName', 'root') # mdata['Password']=self.get_argument('Password', 'Thunder#123') mdata['UserName']='******' mdata['Password']='******' localIP =getLocalIp("eth0") mdata['FileServerIP']=localIP mflag=0 if isvild_sql(mdata)==0: if set_main_server_first(mdata,"utf8")==0: set_is_setting() if localIP==mdata['DataBaseServerIp']: read_thunder_ini_to_db() #分发给各个子服务器 #获取各个服务器ip try: allip=find_all_servers_ip() jsondata={} for ip in allip: if ip==getLocalIp("eth0"): pass else: state=postHttp(ip,mdata,"4") if state!=0: print ip+"修改失败" except: pass mflag=1 ret['code'] = 0 ret['result'] = "设置成功,将要重启!" else: ret['code'] = 1 ret['result']="配置添加失败" #重启服务器 # allip=find_all_servers_ip() # print allip # # jsondata={} # for ip in allip: # if ip=="10.0.0.3": # pass # else: # state=postHttp(ip,mdata,"1") # if state!=0: # print ip+"修改失败" else: ret['code'] = 1 ret['result'] = "设置数据库不正确,请重新设置" self.send_json(ret) if mflag==1: try: restartService('twm') except: pass
def post(self): mtype = self.get_argument('type') logger.debug("有反应") print mtype _res = {} _res['code'] = 0 if mtype == "1": # _res['msg'] = "修改成功!" mdata = self.get_argument('mdata') changetype = self.get_argument('changetype') mjsondata = json.loads(mdata) if (changetype == "delete"): for item in mjsondata['filename']: delete_file_ini(item) _res['msg'] = "删除成功!" elif (changetype == "setting"): pass self.send_json(_res) elif mtype == "3": _res = {} _res['code'] = 0 _res['msg'] = 'ip都正确' cf = ConfigParser.ConfigParser() cf.read('path.ini') str_val = cf.get("sec_a", "boxpath") for server in find_file_servers(): ip = server['FileServer_IpAddress'] print "ip", ip if ip == '127.0.0.1': _res['msg'] = ip + "ip地址有误" continue if ip == getLocalIp("eth0"): continue try: actionCommand(str_val, ip) _res['result'] = ip + "同步成功" except: _res['code'] = 1 _res['result'] = ip + "同步失败" self.send_json(_res) else: cf = ConfigParser.ConfigParser() cf.read('path.ini') sections = cf.sections() options = cf.options("sec_a") str_val = cf.get("sec_a", "boxpath") files = [] print "str_val" for filename in glob.glob(str_val + "*.ini"): conjson = {} update_init_ini(filename) name = filename.replace(str_val, "") mname = name.replace(".ini", "") conjson['filename'] = mname conjson['isuse'] = find_ip_ishave(filename) conjson['Stbtype'] = find_stb_ishave(filename) conjson['Name'] = find_stb_name(filename) files.append(conjson) infojson = {} infojson['box'] = files infojson['server'] = find_file_servers() infojson['fangtai'] = get_all_rooms_info() self.send_json(infojson)
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