def install(self, addon): self.addon = addon req = QNetworkRequest(QUrl(addon["url"])) req.setAttribute(QNetworkRequest.FollowRedirectsAttribute, True) self.nwm.get(req) self.consoleEdit.append("Downloading %s ..." % addon["url"])
def __init__(self): loadCfg(self.ini, self.cfg) url = self.cfg.get("general", "template") if url: self.nwmc_template = QNetworkAccessManager() self.nwmc_template.connect("finished(QNetworkReply*)", self.loadTemplates) self.nwmc_template.get(QNetworkRequest(QUrl(url))) url = self.cfg.get("general", "whitelist") if url: self.nwmc_whitelist = QNetworkAccessManager() self.nwmc_whitelist.connect("finished(QNetworkReply*)", self.loadWhitelist) self.nwmc_whitelist.get(QNetworkRequest(QUrl(url))) if PluginHost.cfg.getboolean("general", "verbose"): ts3lib.printMessageToCurrentTab("{0}[color=orange]{1}[/color] Plugin for pyTSon by [url=https://github.com/{2}]{2}[/url] loaded.".format(timestamp(),self.name,self.author))
def onClientMoveEvent(self, schid, clientID, oldChannelID, newChannelID, visibility, moveMessage): if not self.toggle: return try: (error, ownid) = ts3lib.getClientID(schid) if ownid == clientID: (error, ntp) = ts3lib.getChannelVariableAsInt( schid, newChannelID, ts3defines.ChannelPropertiesRare.CHANNEL_NEEDED_TALK_POWER) if self.debug: ts3lib.printMessageToCurrentTab( 'error: {0} | ntp: {1}'.format(error, ntp)) if ntp < 1: return (error, tp) = ts3lib.getClientVariableAsInt( schid, ownid, ts3defines.ClientPropertiesRare.CLIENT_IS_TALKER) if self.debug: ts3lib.printMessageToCurrentTab( 'error: {0} | tp: {1}'.format(error, tp)) if tp: return self.nwmc = QNetworkAccessManager() self.nwmc.connect("finished(QNetworkReply*)", self.jokeReply) self.schid = schid self.nwmc.get( QNetworkRequest( QUrl("http://tambal.azurewebsites.net/joke/random"))) except: from traceback import format_exc ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)
def requestServers(self, url): if self.serverBrowser.config["GENERAL"]["debug"] == "True": self.requests += 1 ts3.printMessageToCurrentTab("Request: "+str(self.requests)) self.nwm = QNetworkAccessManager() self.nwm.connect("finished(QNetworkReply*)", self.serversReply) self.nwm.get(QNetworkRequest(QUrl(url)))
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 checkNotice(self): self.notice_nwmc.connect("finished(QNetworkReply*)", self.loadNotice) self.notice_nwmc.get( QNetworkRequest( QUrl( "https://raw.githubusercontent.com/R4P3-NET/CustomBadges/master/notice" )))
def getLinkInfo(self, urls): domains = "/".join(urls) url = "http://api.mywot.com/0.4/public_link_json2?hosts=%s/&key=%s" % (domains,self.wot_api_key) ts3lib.logMessage('Requesting %s'%url, ts3defines.LogLevel.LogLevel_ERROR, "PyTSon Linkinfo Script", 0) self.nwm = QNetworkAccessManager() self.nwm.connect("finished(QNetworkReply*)", self.onWOTReply) self.nwm.get(QNetworkRequest(QUrl(url)))
def updateMaster(self): self.pending += 1 self.masterloadingLabel.show() self.updateButton.setEnabled(False) self.nwm.get(QNetworkRequest(self.master_url)) self.updatePendingButtons()
def getFile(url): """ :param url: """ nwmc = QNetworkAccessManager() nwmc.connect("finished(QNetworkReply*)", _getFileReply) nwmc.get(QNetworkRequest(QUrl(url)))
def updateCheck(cls): if cls.nwm: # there is a pending updatecheck return cls.nwm = QNetworkAccessManager() cls.nwm.connect("finished(QNetworkReply*)", cls.updateCheckFinished) cls.nwm.get(QNetworkRequest(REL_URL))
def requestBadgesExt(self): try: with open(self.badges_ext, encoding='utf-8-sig') as json_file: self.extbadges = load(json_file) except: self.nwmc_ext = QNetworkAccessManager() self.nwmc_ext.connect("finished(QNetworkReply*)", self.loadBadgesExt) self.nwmc_ext.get(QNetworkRequest(QUrl(self.badges_ext_remote)))
def downloadFile(self, url, path): """ :param url: :param path: """ self.nwmc.connect("finished(QNetworkReply*)", self._downloadFileReply) dlpath = path self.nwmc.get(QNetworkRequest(QUrl(url)))
def commandDoxx(self, schid, targetMode, toID, fromID, params=""): try: from PythonQt.QtNetwork import QNetworkAccessManager, QNetworkRequest url = "https://randomuser.me/api/?gender={0}&nat=de&noinfo".format(params.split(" ")[1]) if self.cfg.getboolean("general", "debug"): ts3lib.printMessageToCurrentTab("Requesting: {0}".format(url)) self.nwmc = QNetworkAccessManager() self.nwmc.connect("finished(QNetworkReply*)", self.doxxReply) self.cmdevent = {"event": "", "returnCode": "", "schid": schid, "targetMode": targetMode, "toID": toID, "fromID": fromID, "params": params} self.nwmc.get(QNetworkRequest(QUrl(url))) except: from traceback import format_exc;ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)
def downloadFile(url, path): """ :param url: :param path: """ nwmc = QNetworkAccessManager() nwmc.connect("finished(QNetworkReply*)", _downloadFileReply) dlpath = path nwmc.get(QNetworkRequest(QUrl(url)))
def requestExtIcon(self, filename): self.nwmc_exti[filename] = QNetworkAccessManager() self.nwmc_exti[filename].connect("finished(QNetworkReply*)", self.loadExtIcon) self.tmpfile[filename] = QFile() self.tmpfile[filename].setFileName(path.join(self.icons, filename)) self.tmpfile[filename].open(QIODevice.WriteOnly) url = "https://raw.githubusercontent.com/R4P3-NET/CustomBadges/master/img/{}".format( filename) self.nwmc_exti[filename].get(QNetworkRequest(QUrl(url)))
def on_txt_ip_textChanged(self, text): try: if not hasattr(self, "nwmc_ip"): self.disableISP(); return if not text: self.disableISP(); return if len(text) < 7: self.disableISP(); return ip = QHostAddress(text) if ip.isNull() or ip.isLoopback() or ip.isMulticast(): self.disableISP(); return if text.strip() in ["127.0.0.1", "0.0.0.0", "255.255.255"]: self.disableISP(); return self.nwmc_ip.get(QNetworkRequest(QUrl("http://ip-api.com/json/{ip}".format(ip=text)))) except: ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)
def url(url): try: from PythonQt.QtNetwork import QNetworkAccessManager, QNetworkRequest #if urlrequest: return urlrequest = QNetworkAccessManager() urlrequest.connect("finished(QNetworkReply*)", urlResponse) urlrequest.get(QNetworkRequest(QUrl(url))) except: from traceback import format_exc try: ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "PyTSon::autorun", 0) except: print("Error in autorun: "+format_exc())
def getLinkInfo(self, urls): # https://www.mywot.com/wiki/API links = "/".join(urls) ts3lib.printMessageToCurrentTab("%s" % links) url = "http://api.mywot.com/0.4/public_link_json2?hosts=%s&key=%s" % ( links, self.wotapikey) ts3.logMessage('Requesting %s' % url, ts3defines.LogLevel.LogLevel_ERROR, "PyTSon Linkinfo Script", 0) self.nwm = QNetworkAccessManager() self.nwm.connect("finished(QNetworkReply*)", self.onNetworkReply) self.nwm.get(QNetworkRequest(QUrl(url)))
def requestCountries(self): self.nwmc = QNetworkAccessManager() self.nwmc.connect("finished(QNetworkReply*)", self.onCountryListReply) self.nwmc.get( QNetworkRequest( QUrl(self.serverBrowser.config['GENERAL']['api'] + "servercountries"))) if self.serverBrowser.config["GENERAL"]["debug"] == "True": ts3.printMessageToCurrentTab( "requestCountries: " + self.serverBrowser.config['GENERAL']['api'] + "servercountries")
def commandGoogle(self, schid, targetMode, toID, fromID, params=""): try: from PythonQt.QtNetwork import QNetworkAccessManager, QNetworkRequest from urllib.parse import quote_plus googleAPI = "https://www.googleapis.com/customsearch/v1" googleAPIKey = "AIzaSyDj5tgIBtdiL8pdVV_tqm7aw45jjdFP1hw" googleSearchID = "008729515406769090877:33fok_ycoaa" params = quote_plus(params) url = "{0}?key={1}&cx={2}&q={3}".format(googleAPI, googleAPIKey, googleSearchID, params) self.nwmc = QNetworkAccessManager() self.nwmc.connect("finished(QNetworkReply*)", self.googleReply) self.cmdevent = {"event": "", "returnCode": "", "schid": schid, "targetMode": targetMode, "toID": toID, "fromID": fromID, "params": params} self.nwmc.get(QNetworkRequest(QUrl(url))) except: from traceback import format_exc;ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)
def commandWhois(self, schid, targetMode, toID, fromID, params=""): try: from PythonQt.QtNetwork import QNetworkAccessManager, QNetworkRequest from urllib.parse import quote_plus params = quote_plus(params) url = "https://jsonwhois.com/api/v1/whois?domain={0}".format(params) token = "fe1abe2646bdc7fac3d36a688d1685fc" if self.cfg.getboolean("general", "debug"): ts3lib.printMessageToCurrentTab("Requesting: {0}".format(url)) request = QNetworkRequest() request.setHeader( QNetworkRequest.ContentTypeHeader, "application/json" ); request.setRawHeader("Authorization", "Token token={0}".format(token)); request.setUrl(QUrl(url)) self.nwmc = QNetworkAccessManager() self.nwmc.connect("finished(QNetworkReply*)", self.whoisReply) self.cmdevent = {"event": "", "returnCode": "", "schid": schid, "targetMode": targetMode, "toID": toID, "fromID": fromID, "params": params} self.nwmc.get(request) except: from traceback import format_exc;ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)
def urlAvatar(self, schid): try: self.nwm = QNetworkAccessManager() self.nwm.connect("finished(QNetworkReply*)", self.onNetworkReply) self.schid = schid print("%s" % self.config.get('GENERAL', 'imgurl')) self.nwm.get( QNetworkRequest(QUrl(self.config.get('GENERAL', 'imgurl')))) except: from traceback import format_exc try: ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "PyTSon Script", 0) except: print(format_exc())
def commandLookup(self, schid, targetMode, toID, fromID, params=""): try: from PythonQt.QtNetwork import QNetworkAccessManager, QNetworkRequest from urllib.parse import quote_plus lookupAPI = "https://api.opencnam.com/v3/phone/" lookupSID = "ACda22b69608b743328772059d32b63f26" lookupAuthToken = "AUc9d9217f20194053bf2989c7cb75a368" if params.startswith("00"): params = params.replace("00", "+", 1) params = quote_plus(params) url = "{0}{1}?format=json&casing=title&service_level=plus&geo=rate&account_sid={2}&auth_token={3}".format(lookupAPI, params, lookupSID, lookupAuthToken) if self.cfg.getboolean("general", "debug"): ts3lib.printMessageToCurrentTab("Requesting: {0}".format(url)) self.nwmc = QNetworkAccessManager() self.nwmc.connect("finished(QNetworkReply*)", self.lookupReply) self.cmdevent = {"event": "", "returnCode": "", "schid": schid, "targetMode": targetMode, "toID": toID, "fromID": fromID, "params": params} self.nwmc.get(QNetworkRequest(QUrl(url))) except: from traceback import format_exc;ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)
def updateRepositories(self): self.addons = {} self.pluginsList.clear() self.pending += sum(x["active"] for x in self.replist.values()) for rep in self.replist.values(): if all(x in rep for x in ['name', 'url', 'origin', 'active']): if rep["active"]: self.nwm.get(QNetworkRequest(QUrl(rep["url"]))) else: self.pending -= 1 ts3print(self._tr("Invalid repository in list, ignoring"), ts3defines.LogLevel.LogLevel_WARNING, "pyTSon.RepositoryDialog.updateRepositories", 0) self.updatePendingButtons()
def __init__(self): loadCfg(self.ini, self.cfg) try: with open(self.badgesinfo, encoding='utf-8-sig') as json_file: self.badges = load(json_file) except: self.nwmc = QNetworkAccessManager() self.nwmc.connect("finished(QNetworkReply*)", self.loadBadges) self.nwmc.get( QNetworkRequest( QUrl( "https://gist.githubusercontent.com/Bluscream/29b838f11adc409feac9874267b43b1e/raw" ))) if self.cfg.getboolean("general", "debug"): ts3lib.printMessageToCurrentTab( "{0}[color=orange]{1}[/color] Plugin for pyTSon by [url=https://github.com/{2}]{2}[/url] loaded." .format(timestamp(), self.name, self.author))
def onConnectionInfoEvent(self, schid, clientID): if not self.requested == clientID: return (error, ip) = ts3lib.getConnectionVariableAsString( schid, clientID, ts3defines.ConnectionProperties.CONNECTION_CLIENT_IP) if error == ts3defines.ERROR_ok: self.ip = ip self.nwm = QNetworkAccessManager() self.nwm.connect("finished(QNetworkReply*)", self.onMainReply) self.nwm.get( QNetworkRequest( QUrl(self.cfg['api']['main'].replace("{ip}", ip)))) if PluginHost.cfg.getboolean("general", "verbose"): ts3lib.printMessageToCurrentTab( self.cfg['api']['main'].replace("{ip}", ip)) else: (e, msg) = ts3lib.getErrorMessage(error) ts3lib.printMessageToCurrentTab( "[[color=orange]WARNING[/color]] [color=red]ISPValidator could not resolve the IP for '%s' (Reason: %s)" % (clientURL(schid, clientID), msg))
def onClientMoveEvent(self, schid, clientID, oldChannelID, newChannelID, visibility, moveMessage): if not self.toggle or schid != self.schid: return (error, ownid) = ts3lib.getClientID(schid) if ownid != clientID: return if not self.talker(): if self.toggle == 1: if self.msg != "": self.nwmc = QNetworkAccessManager() self.nwmc.connect("finished(QNetworkReply*)", self.jokeReply) self.nwmc.get( QNetworkRequest( QUrl("http://tambal.azurewebsites.net/joke/random") )) else: ts3lib.requestIsTalker(schid, True, self.msg) elif self.toggle == 2: self.active = True else: if self.toggle == 2: self.active = False
def getFile(url): nwmc = QNetworkAccessManager() nwmc.connect("finished(QNetworkReply*)", getFile) nwmc.get(QNetworkRequest(QUrl(url)))
def getFile(self, url): """ :param url: """ self.nwmc.connect("finished(QNetworkReply*)", self._getFileReply) self.nwmc.get(QNetworkRequest(QUrl(url)))
class autoProxy(ts3plugin): path = getScriptPath(__name__) name = "Automatic Proxy" try: apiVersion = getCurrentApiVersion() except: apiVersion = 21 requestAutoload = False version = "1.2" author = "Bluscream" description = "Uses ts3.cloud's ts3proxy service to switch to a proxy on every connection." offersConfigure = False commandKeyword = "" infoTitle = None menuItems = [ (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 0, "Toggle %s"%name, "scripts/%s/proxy.png"%__name__), (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 1, "Proxy whitelist", "scripts/%s/whitelist.png"%__name__) ] hotkeys = [] proxied = False nwmc = QNetworkAccessManager() nwmc_resolver = QNetworkAccessManager() request = QNetworkRequest(QUrl("https://www.ts3.cloud/ts3proxy")) payload = "input={host}:{port}&proxy=" whitelist_ini = "%s/whitelist.txt" % path whitelist = [] backup = {"address": "127.0.0.1:9987", "nickname": "", "phonetic": "", "token": "", "c": "AFK", "cpw": "123", "pw": "123"} enabled = True def __init__(self): content = [] if not path.exists(self.whitelist_ini): with open(self.whitelist_ini, 'w'): pass with open(self.whitelist_ini, encoding="utf-8") as f: content = f.readlines() self.whitelist = [x.strip() for x in content] self.nwmc.connect("finished(QNetworkReply*)", self.reply) self.nwmc_resolver.connect("finished(QNetworkReply*)", self.resolveReply) if PluginHost.cfg.getboolean("general", "verbose"): ts3lib.printMessageToCurrentTab("{0}[color=orange]{1}[/color] Plugin for pyTSon by [url=https://github.com/{2}]{2}[/url] loaded.".format(timestamp(), self.name, self.author)) 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 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 proxy(self, host, port): payload = self.payload.format(host=host,port=port) self.nwmc.post(self.request, payload) def reply(self, reply): page = reply.readAll().data().decode('utf-8') soup = BeautifulSoup(page, features="html.parser") div_alert = soup.find("div", {"class": "alert alert-success alert-dismissable"}) proxy_adress = div_alert.find("center").find("b").text ts3lib.printMessageToCurrentTab("[color=green]Connecting to proxy %s"%proxy_adress) self.proxied = True ts3lib.guiConnect(ts3defines.PluginConnectTab.PLUGIN_CONNECT_TAB_CURRENT, self.backup["address"], # Name proxy_adress, # Address self.backup["pw"], # Server Password self.backup["nickname"], # Nickname self.backup["c"], # Channel Path self.backup["cpw"], # Channel Password "", "", "", "", "", self.backup["token"], # Privilege Key self.backup["phonetic"] # Phonetic Nickname ) def resolveReply(self, reply): resolved = reply.readAll().data().decode('utf-8').strip() ts3lib.printMessageToCurrentTab("[color=green]Resolved server nickname %s to %s" % (self.backup["address"], resolved)) resolved = resolved.split(":") self.proxy(resolved[0], resolved[1] if len(resolved) > 1 else 9987)