def backup(self, serverConnectionHandlerID): ownID = ts3lib.getClientID(serverConnectionHandlerID)[1] ip = ts3lib.getConnectionVariableAsString( serverConnectionHandlerID, ownID, ts3defines.ConnectionProperties.CONNECTION_SERVER_IP)[1] self.cfg['data']['ip'] = ip port = ts3lib.getConnectionVariableAsUInt64( serverConnectionHandlerID, ownID, ts3defines.ConnectionProperties.CONNECTION_SERVER_PORT)[1] self.cfg['data']['port'] = str(port) serverPassword = ts3lib.getServerConnectInfo(serverConnectionHandlerID, 256)[3] self.currentServerPW = serverPassword nickname = ts3lib.getClientSelfVariableAsString( serverConnectionHandlerID, ts3defines.ClientProperties.CLIENT_NICKNAME)[1] self.cfg.set('data', 'nickname', nickname) tabID = ts3defines.PluginConnectTab.PLUGIN_CONNECT_TAB_CURRENT self.cfg['data']['tabID'] = str(tabID) channelID = ts3lib.getChannelOfClient(serverConnectionHandlerID, ownID)[1] channelPassword = ts3lib.getChannelConnectInfo( serverConnectionHandlerID, channelID, 256)[2] self.currentChannelPW = channelPassword return
def onConnectStatusChangeEvent(self, schid, newStatus, errorNumber): if not self.enabled: return if newStatus != ts3defines.ConnectStatus.STATUS_CONNECTING: return if self.proxied: self.proxied = False; return err, host, port, pw = ts3lib.getServerConnectInfo(schid) if host.lower() in self.whitelist: ts3lib.printMessageToCurrentTab("[color=green]%s is whitelisted, not using proxy!" % host); return ip = QHostAddress(host) if not ip.isNull(): if ip.isLoopback(): ts3lib.printMessageToCurrentTab("[color=green]%s is Loopback, not using proxy!" % host); return elif ip.isMulticast(): ts3lib.printMessageToCurrentTab("[color=green]%s is Multicast, not using proxy!" % host); return is_nickname = False if not "." in host: ts3lib.printMessageToCurrentTab("[color=orange]%s is a server nickname, resolving..." % host) self.backup["address"] = host is_nickname = True if not is_nickname: self.backup["address"] = "{}:{}".format(host,port) ts3lib.printMessageToCurrentTab("[color=red]Not proxied on %s, disconnecting!"%self.backup["address"]) ts3lib.stopConnection(schid, "switching to proxy") if pw: self.backup["pw"] = pw err, nickname = ts3lib.getClientSelfVariable(schid, ts3defines.ClientProperties.CLIENT_NICKNAME) if not err and nickname: self.backup["nickname"] = nickname err, nickname_phonetic = ts3lib.getClientSelfVariable(schid, ts3defines.ClientPropertiesRare.CLIENT_NICKNAME_PHONETIC) if not err and nickname_phonetic: self.backup["phonetic"] = nickname_phonetic err, c = ts3lib.getClientSelfVariable(schid, ts3defines.ClientProperties.CLIENT_DEFAULT_CHANNEL) if not err and c: self.backup["c"] = c err, cpw = ts3lib.getClientSelfVariable(schid, ts3defines.ClientProperties.CLIENT_DEFAULT_CHANNEL_PASSWORD) if not err and cpw: self.backup["cpw"] = cpw err, default_token = ts3lib.getClientSelfVariable(schid, ts3defines.ClientPropertiesRare.CLIENT_DEFAULT_TOKEN) if not err and default_token: self.backup["token"] = default_token if is_nickname: self.nwmc_resolver.get(QNetworkRequest(QUrl("https://named.myteamspeak.com/lookup?name=%s"%host))) return self.proxy(host, port)
def onMenuItemEvent(self, schid, atype, menuItemID, selectedItemID): if atype != ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL: return if menuItemID == 0: self.enabled = not self.enabled if self.enabled: ts3lib.printMessageToCurrentTab( "{} > [color=green]Enabled!".format(self.name)) else: ts3lib.printMessageToCurrentTab( "{} > [color=red]Disabled!".format(self.name)) elif menuItemID == 1: err, host, port, pw = ts3lib.getServerConnectInfo(schid) host = inputBox(self.name, "Server address:", host) if not host: msgBox("Nothing to add!", title=self.name) return if host in self.whitelist: self.whitelist.remove(host) ts3lib.printMessageToCurrentTab( "{} > Removed {} from whitelist!".format(self.name, host)) else: self.whitelist.append(host.lower()) ts3lib.printMessageToCurrentTab( "{} > Added {} to whitelist!".format(self.name, host)) with open(self.whitelist_ini, "a") as myfile: myfile.write('\n{0}'.format(host))
def on_copyAction_triggered(self): cur = self.listmodel.fileByIndex(self.currentItem()) if not cur: return err, host, port, _ = ts3lib.getServerConnectInfo(self.schid) if err == ERROR_ok: url = ("[URL=ts3file://{address}?port={port}&channel={cid}&" "path={path}&filename={fname}&isDir={isdir}&" "size={size}&fileDateTime={date}]{fname}[/URL]").format( address=host, port=port, cid=self.cid, path=QUrl.toPercentEncoding(cur.path), fname=cur.name, isdir=1 if cur.isDirectory else 0, size=cur.size, date=int(cur.datetime.timestamp())) QApplication.clipboard().setText(url) else: self.showError(self._tr("Error getting server connection info"), err)
def getServerInfo(self, schid): i = [] (err, host, port, password) = ts3.getServerConnectInfo(schid) i.append('Host: {0}'.format(host)) if port: i.append('Port: {0}'.format(port)) if password != "": i.append('Password: {0}'.format(password)) i.extend(self.getInfo(schid, None, [VirtualServerProperties, VirtualServerPropertiesRare])) return i if len(i) > 0 else None
def onHotkeyOrCommandEvent(self, keyword, schid=0): if not schid: schid = ts3lib.getCurrentServerConnectionHandlerID() # (err, status) = ts3lib.getConnectionStatus(schid) # if status != ts3defines.ConnectStatus.STATUS_CONNECTION_ESTABLISHED: return arguments = [] if keyword == "yatqa_start": pass elif keyword == "yatqa_connect_current": (err, ownID) = ts3lib.getClientID(schid) (err, ip) = ts3lib.getConnectionVariable( schid, ownID, ts3defines.ConnectionProperties.CONNECTION_SERVER_IP) (err, port) = ts3lib.getServerVariable( schid, ts3defines.VirtualServerPropertiesRare.VIRTUALSERVER_PORT) title = ("{} > {}".format(self.name, ip)) qport = inputInt(title, "Query Port:", 10011, 1, 65535) name = inputBox(title, "Query Login Name:", "serveradmin") pw = inputBox( title, "Query Login Password:"******"") args = ["-c", ip, qport] if name and pw: args.extend([name, pw, port]) else: args.append(port) self.yatqa.setArguments( args) # IP Query_Port [User Pass] [Voice_Port] elif keyword == "yatqa_stats_current": (err, ownID) = ts3lib.getClientID(schid) (err, ip) = ts3lib.getConnectionVariable( schid, ownID, ts3defines.ConnectionProperties.CONNECTION_SERVER_IP) (err, port) = ts3lib.getServerVariable( schid, ts3defines.VirtualServerPropertiesRare.VIRTUALSERVER_PORT) self.yatqa.setArguments(["-s", ip, port]) # IP elif keyword == "yatqa_blacklist_current": (err, ownID) = ts3lib.getClientID(schid) (err, ip) = ts3lib.getConnectionVariable( schid, ownID, ts3defines.ConnectionProperties.CONNECTION_SERVER_IP) self.yatqa.setArguments(["-b", ip]) # IP elif keyword == "yatqa_lookup_dns": (err, host, port, pw) = ts3lib.getServerConnectInfo(schid) self.yatqa.setArguments(["-d", host]) elif keyword == "yatqa_browse_icons": (err, suid) = ts3lib.getServerVariable( schid, ts3defines.VirtualServerProperties. VIRTUALSERVER_UNIQUE_IDENTIFIER) self.yatqa.setArguments(["-i", suid]) elif keyword == "yatqa_permission_editor": self.yatqa.setArguments(["-p"]) elif keyword == "yatqa_connect_default": self.yatqa.setArguments(["-a"]) else: return False if PluginHost.cfg.getboolean("general", "verbose"): print(self.bin, self.yatqa.arguments()) self.yatqa.start() return True
def onConnectStatusChangeEvent(self, schid, status, errorNumber): if status == ConnectStatus.STATUS_CONNECTION_ESTABLISHED: srv = self.ts3host.getServer(schid) self.tabs[schid] = { "channelBanGroup": None, "channelModGroup": None, # "clients": {} } srv.requestServerGroupList() srv.requestChannelGroupList() self.tabs[schid][ "name"] = srv.name # ts3lib.getServerVariable(schid, VirtualServerProperties.VIRTUALSERVER_NAME) err, self.tabs[schid]["host"], self.tabs[schid]["port"], self.tabs[ schid]["pw"] = ts3lib.getServerConnectInfo(schid) self.tabs[schid]["address"] = '{}:{}'.format( self.tabs[schid]["host"], self.tabs[schid]["port"]) if hasattr( self.tabs[schid], 'port') else self.tabs[schid]["host"] self.tabs[schid]["clid"] = srv.me.clientID self.tabs[schid][ "nick"] = srv.me.name # ts3lib.getClientSelfVariable(schid, ClientProperties.CLIENT_NICKNAME) # ts3lib.getClientVariable(schid, self.tabs[schid]["clid"], ClientProperties.CLIENT_NICKNAME) err, self.tabs[schid][ "nick_phonetic"] = ts3lib.getClientSelfVariable( schid, ClientPropertiesRare.CLIENT_NICKNAME_PHONETIC) self.tabs[schid][ "uid"] = srv.me.uid # ts3lib.getClientSelfVariable(schid, ClientProperties.CLIENT_UNIQUE_IDENTIFIER) err, self.tabs[schid]["token"] = ts3lib.getClientSelfVariable( schid, ClientPropertiesRare.CLIENT_DEFAULT_TOKEN) self.tabs[schid][ "cid"] = srv.me.channel.channelID # ts3lib.getChannelOfClient(schid, self.tabs[schid]["clid"]) err, self.tabs[schid]["cpath"], self.tabs[schid][ "cpw"] = ts3lib.getChannelConnectInfo(schid, self.tabs[schid]["cid"]) err, self.tabs[schid][ "input_muted"] = ts3lib.getClientSelfVariable( schid, ClientProperties.CLIENT_INPUT_MUTED) # srv.me.isInputMuted err, self.tabs[schid][ "input_deactivated"] = ts3lib.getClientSelfVariable( schid, ClientProperties.CLIENT_INPUT_DEACTIVATED) err, self.tabs[schid][ "input_enabled"] = ts3lib.getClientSelfVariable( schid, ClientProperties.CLIENT_INPUT_HARDWARE) err, self.tabs[schid][ "output_muted"] = ts3lib.getClientSelfVariableAsInt( schid, ClientProperties.CLIENT_OUTPUT_MUTED ) # srv.me.isOutputMuted err, self.tabs[schid][ "output_enabled"] = ts3lib.getClientSelfVariable( schid, ClientProperties.CLIENT_OUTPUT_HARDWARE) # elif status == ConnectStatus.STATUS_DISCONNECTED: if schid in self.tabs: self.tabs[schid]["status"] = status
def saveTab(self, schid): if not hasattr(self.tabs, '%s' % schid): self.tabs[schid] = {} (err, self.tabs[schid]["name"]) = ts3lib.getServerVariable( schid, ts3defines.VirtualServerProperties.VIRTUALSERVER_NAME) (err, self.tabs[schid]["host"], self.tabs[schid]["port"], self.tabs[schid]["pw"]) = ts3lib.getServerConnectInfo(schid) (err, self.tabs[schid]["clid"]) = ts3lib.getClientID(schid) (err, self.tabs[schid]["nick"]) = ts3lib.getClientDisplayName( schid, self.tabs[schid]["clid"]) (err, cid) = ts3lib.getChannelOfClient(schid, self.tabs[schid]["clid"]) (err, self.tabs[schid]["cpath"], self.tabs[schid]["cpw"]) = ts3lib.getChannelConnectInfo(schid, cid) self.log(LogLevel.LogLevel_DEBUG, "Saved Tab: {}".format(self.tabs[schid]), schid)
def reconnect(self, schid=0, cid=0): if not schid: schid = ts3lib.getCurrentServerConnectionHandlerID() err, host, port, pw = ts3lib.getServerConnectInfo(schid) address = host if not "." in host else "{}:{}".format(host, port) # ts3lib.stopConnection(schid, "") err, nickname = ts3lib.getClientSelfVariable( schid, ts3defines.ClientProperties.CLIENT_NICKNAME) err, nickname_phonetic = ts3lib.getClientSelfVariable( schid, ts3defines.ClientPropertiesRare.CLIENT_NICKNAME_PHONETIC) err, uid = ts3lib.getClientSelfVariable( schid, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER) cpw = "" if not cid: err, cid = ts3lib.getClientSelfVariable( schid, ts3defines.ClientProperties.CLIENT_DEFAULT_CHANNEL) err, cpw = ts3lib.getClientSelfVariable( schid, ts3defines.ClientProperties.CLIENT_DEFAULT_CHANNEL_PASSWORD) else: (err, cid, cpw) = ts3lib.getChannelConnectInfo(schid, cid) err, default_token = ts3lib.getClientSelfVariable( schid, ts3defines.ClientPropertiesRare.CLIENT_DEFAULT_TOKEN) args = [ ts3defines.PluginConnectTab. PLUGIN_CONNECT_TAB_CURRENT, # connectTab: int, address, # serverLabel: Union[str, unicode], address, # serverAddress: Union[str, unicode], pw, # serverPassword: Union[str, unicode], nickname, # nickname: Union[str, unicode], cid, # channel: Union[str, unicode], cpw if cpw else "123", # channelPassword: Union[str, unicode] "", # captureProfile: Union[str, unicode], "", # playbackProfile: Union[str, unicode] "", # hotkeyProfile: Union[str, unicode], "Default Sound Pack (Female)", # soundPack uid, # userIdentity: Union[str, unicode], default_token, # oneTimeKey: Union[str, unicode], nickname_phonetic, # phoneticName: Union[str, unicode] ] print("ts3lib.guiConnect({})".format("\", \"".join( str(x) for x in args))) ts3lib.guiConnect(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9], args[10], args[11], args[12], args[13])
def setStatus(self, schid): try: err, ownid = ts3.getClientID(schid) err, schids = ts3.getServerConnectionHandlerList() regex = re.compile(r'.*(<{0}>.*</{0}>).*'.format(self.tag), re.IGNORECASE) for tab in schids: err, meta_data = ts3.getClientSelfVariable( tab, ts3defines.ClientProperties.CLIENT_META_DATA) meta_data = regex.sub("", meta_data) if tab == schid: ts3.setClientSelfVariableAsInt( tab, ts3defines.ClientPropertiesRare.CLIENT_AWAY, ts3defines.AwayStatus.AWAY_NONE) else: err, away_message = ts3.getClientSelfVariable( tab, ts3defines.ClientPropertiesRare.CLIENT_AWAY_MESSAGE) err, away = ts3.getClientSelfVariable( tab, ts3defines.ClientPropertiesRare.CLIENT_AWAY) if away != ts3defines.AwayStatus.AWAY_ZZZ: ts3.setClientSelfVariableAsInt( tab, ts3defines.ClientPropertiesRare.CLIENT_AWAY, ts3defines.AwayStatus.AWAY_ZZZ) host = "" port = 0 name = "" if self.cfg.getboolean('general', 'enabled'): err, host, port, pw = ts3.getServerConnectInfo(schid) # err, ip = ts3.getConnectionVariableAsString(schid, ownid, ts3defines.ConnectionProperties.CONNECTION_SERVER_IP) # err, port = ts3.getConnectionVariableAsString(schid, ownid, ts3defines.ConnectionProperties.CONNECTION_SERVER_PORT) # err, ip = ts3.getServerVariableAsString(schid, ts3defines.VirtualServerPropertiesRare.VIRTUALSERVER_IP) # err, port = ts3.getServerVariableAsString(schid, ts3defines.VirtualServerPropertiesRare.VIRTUALSERVER_PORT) if host: newmeta = xml.Element(self.tag) c = xml.SubElement(newmeta, "tab") c.set("id", str(schid)) err, name = ts3.getServerVariable( schid, ts3defines.VirtualServerProperties. VIRTUALSERVER_NAME) if name: c.text = escape(name.strip()) c.set("host", escape(host)) if port and port != 9987: c.set("port", "{}".format(port)) if pw and self.cfg.getboolean('general', 'pw'): c.set("pw", pw) meta_data = "{old}{new}".format( old=meta_data, new=xml.tostring(newmeta).decode("utf-8")) # meta_data = "{}<server>{}{}</server>".format(meta_data, ip, ":" + port if port else "") _away_message = self.cfg.get('general', 'status').replace( '{host}', host if host else "").replace( '{name}', name if name else "").replace( '{port}', str(port) if port else "") if away_message != _away_message: ts3.setClientSelfVariableAsString( tab, ts3defines.ClientPropertiesRare. CLIENT_AWAY_MESSAGE, _away_message) ts3.setClientSelfVariableAsString( tab, ts3defines.ClientProperties.CLIENT_META_DATA, meta_data) ts3.flushClientSelfUpdates(tab) except: from traceback import format_exc ts3.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0) pass
def setStatus(self, schid): err, ownid = ts3.getClientID(schid) err, schids = ts3.getServerConnectionHandlerList() regex = re.compile(r'.*(<{0}>.*</{0}>).*'.format(self.tag), re.IGNORECASE) host = "" port = 9987 pw = "" name = "" nick = "" err, host, port, pw = ts3.getServerConnectInfo(schid) err, name = ts3.getServerVariable( schid, ts3defines.VirtualServerProperties.VIRTUALSERVER_NAME) err, nick = ts3.getServerVariable( schid, 83 ) # ts3defines.VirtualServerPropertiesRare.VIRTUALSERVER_NICKNAME if err == ts3defines.ERROR_ok and nick.strip(): nick = nick.split(":") err, ip = ts3.getConnectionVariableAsString( schid, ownid, ts3defines.ConnectionProperties.CONNECTION_SERVER_IP) if err != ts3defines.ERROR_ok or not ip.strip(): err, ip = ts3.getServerVariableAsString( schid, ts3defines.VirtualServerPropertiesRare.VIRTUALSERVER_IP) err, port = ts3.getConnectionVariableAsString( schid, ownid, ts3defines.ConnectionProperties.CONNECTION_SERVER_PORT) if err != ts3defines.ERROR_ok or not port or port < 1: err, port = ts3.getServerVariableAsString( schid, ts3defines.VirtualServerPropertiesRare.VIRTUALSERVER_PORT) for tab in schids: err, meta_data = ts3.getClientSelfVariable( tab, ts3defines.ClientProperties.CLIENT_META_DATA) meta_data = regex.sub("", meta_data) if tab == schid: ts3.setClientSelfVariableAsInt( tab, ts3defines.ClientPropertiesRare.CLIENT_AWAY, ts3defines.AwayStatus.AWAY_NONE) else: err, away = ts3.getClientSelfVariable( tab, ts3defines.ClientPropertiesRare.CLIENT_AWAY) if away != ts3defines.AwayStatus.AWAY_ZZZ: ts3.setClientSelfVariableAsInt( tab, ts3defines.ClientPropertiesRare.CLIENT_AWAY, ts3defines.AwayStatus.AWAY_ZZZ) if self.cfg.getboolean('general', 'enabled'): if host: newmeta = xml.Element(self.tag) c = xml.SubElement(newmeta, "tab") c.set("i", str(schid)) if name: c.text = escape(name.strip()) c.set("h", escape(host)) if port and port != 9987: c.set("port", "{}".format(port)) if pw and self.cfg.getboolean('general', 'pw'): c.set("p", pw) # if ip and ip.strip(): c.set("ip", ip) # if nick: c.set("nick", ":".join(nick)) meta_data = "{old}{new}".format( old=meta_data, new=xml.tostring(newmeta).decode("utf-8")) # meta_data = "{}<server>{}{}</server>".format(meta_data, ip, ":" + port if port else "") try: name = name[:78] + (name[78:] and '..') except: pass _away_message = self.cfg.get('general', 'status') if "{" in _away_message: _away_message = _away_message\ .replace('{host}', host if host else "")\ .replace('{nick}', nick[0] if nick and len(nick) > 0 else "")\ .replace('{name}', name if name else "")\ .replace('{nickname}', nick[0] if nick else name)\ .replace('{ip}', ip if ip else "")\ .replace('{port}', str(port) if port else "") err, away_message = ts3.getClientSelfVariable( tab, ts3defines.ClientPropertiesRare.CLIENT_AWAY_MESSAGE) if away_message != _away_message: ts3.setClientSelfVariableAsString( tab, ts3defines.ClientPropertiesRare.CLIENT_AWAY_MESSAGE, _away_message) ts3.setClientSelfVariableAsString( tab, ts3defines.ClientProperties.CLIENT_META_DATA, meta_data) ts3.flushClientSelfUpdates(tab)