Exemple #1
0
 def commandKickMe(self, schid, targetMode, toID, fromID, params=""):
     if self.cfg.getboolean('general', 'customprefix'):
         prefix = self.cfg.get('general', 'prefix')
     else:
         (error, id) = ts3lib.getClientID(schid);prefix = self.clientURL(schid, id)
     (error, nickname) = ts3lib.getClientVariableAsString(schid, fromID, ts3defines.ClientProperties.CLIENT_NICKNAME)
     if params != "": ts3lib.requestClientKickFromServer(schid, fromID, params)
     else: ts3lib.requestClientKickFromServer(schid, fromID, "Command %skickme used by %s" % (prefix, nickname))
Exemple #2
0
 def onClientDisplayNameChanged(self, serverConnectionHandlerID, clientID,
                                displayName, uniqueClientIdentifier):
     name = displayName
     (err_desc, desc) = ts3lib.getClientVariableAsString(
         serverConnectionHandlerID, clientID,
         ts3defines.ClientPropertiesRare.CLIENT_DESCRIPTION)
     if err_desc != ts3defines.ERROR_ok:
         log.error("{} - Error while obtaining client description".format(
             time.ctime(time.time())))
     else:
         log.info(
             "{} - Nickname change detected. New nickname: {}, desc: {}".
             format(time.ctime(time.time()), name, desc))
         # if nickname == desc
         if name == desc:
             log.info("{} - Client OK. Nickname: {}".format(
                 time.ctime(time.time()), name))
         # if desc not set
         elif desc == "":
             message = "Your description is empty. Ask server admin to set it"
             err_msg = ts3lib.requestSendPrivateTextMsg(
                 serverConnectionHandlerID, message, clientID)
             log.warning(
                 "{} - Client without description. Nickname: {}".format(
                     time.ctime(time.time()), name))
         # if name/desc mismatch
         elif name != desc:
             err_kick = ts3lib.requestClientKickFromServer(
                 serverConnectionHandlerID, clientID,
                 "Set your nickname as follows: %s" % desc)
             log.warning(
                 "{} - Nick/desc mismatch - kicking client. Nickname: {}, description: {}"
                 .format(time.ctime(time.time()), name, desc))
 def kick(self, kickReason, tserv=False):
     if tserv:
         err = ts3lib.requestClientKickFromServer(self.schid, self.clientID,
                                                  kickReason)
     else:
         err = ts3lib.requestClientKickFromChannel(self.schid,
                                                   self.clientID,
                                                   kickReason)
     if err != ts3defines.ERROR_ok:
         raise ts3Error("Error kicking client: (%s, %s)" %
                        (err, ts3lib.getErrorMessage(err)[1]))
Exemple #4
0
 def onConnectStatusChangeEvent(self, schid, status, errorNumber):
     if status != ts3defines.ConnectStatus.STATUS_CONNECTION_ESTABLISHED: return
     (err, mynick) = ts3lib.getClientSelfVariable(schid, ts3defines.ClientProperties.CLIENT_NICKNAME)
     if err != ts3defines.ERROR_ok: return
     sp = re.split(r"\d", mynick)
     if len(sp) > 1 and sp[0] != mynick and sp[1] == "":
         (err, clis) = ts3lib.getClientList(schid)
         if err != ts3defines.ERROR_ok: return
         for cli in clis:
             (err, nick) = ts3lib.getClientVariable(schid, cli, ts3defines.ClientProperties.CLIENT_NICKNAME)
             if err == ts3defines.ERROR_ok and nick == sp[0]:
                 err = ts3lib.requestClientKickFromServer(schid, cli, "Client not responding")
                 self.schid = schid; self.newnick = sp[0]
                 ts3lib.printMessageToCurrentTab('err: {0}'.format(err))
                 if err == ts3defines.ERROR_ok: self.rename()
                 else: QTimer.singleShot(30000, self.rename)
Exemple #5
0
 def onMenuItemEvent(self, schid, atype, menuItemID, selectedItemID):
     try:
         if atype == ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL:
             if menuItemID == 1: # Message all Clients
                 (error, clients) = ts3lib.getClientList(schid)
                 msgs = self.getText(multiline=True,title="Message all %s clients on this server"%len(clients),text="Enter Private Message")
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     for msg in msgs: ts3lib.requestSendPrivateTextMsg(schid, msg, c)
             elif menuItemID == 2: # OffineMessage all Clients
                 (error, clients) = ts3lib.getClientList(schid)
                 (error, ownID) = ts3lib.getClientID(schid)
                 uids = []
                 for c in clients:
                     if c == ownID: continue
                     (error, uid) = ts3lib.getClientVariableAsString(schid, c, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER)
                     uids.append(uid)
                 if not self.dlg: self.dlg = MessageDialog(schid, uids)
                 self.dlg.show();self.dlg.raise_();self.dlg.activateWindow()
             elif menuItemID == 3: # Message all Channels
                 (error, channels) = ts3lib.getChannelList(schid)
                 msgs = self.getText(multiline=True,title="Message all %s channels on this server"%len(channels),text="Enter Channel Message")
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in channels:
                     error = ts3lib.requestClientMove(schid, ownID, c, "123")
                     if not error == ts3defines.ERROR_ok: continue
                     for msg in msgs: ts3lib.requestSendChannelTextMsg(schid, msg, c)
             elif menuItemID == 4: # Poke all Clients
                 (error, clients) = ts3lib.getClientList(schid)
                 msgs = self.getText(title="Poke all %s clients on this server"%len(clients),text="Enter Poke Message",max=100)
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     for msg in msgs: ts3lib.requestClientPoke(schid, c, msg)
             elif menuItemID == 5: # ChannelKick all Clients
                 (error, clients) = ts3lib.getClientList(schid)
                 msg = self.getText(title="Kick all %s clients on this server from their channel"%len(clients),text="Enter Kick Reason",multimsg=False,max=80)
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     ts3lib.requestClientKickFromChannel(schid, c, msg)
             elif menuItemID == 6: # ChannelBan all Clients
                 (error, clients) = ts3lib.getClientList(schid)
                 msg = self.getText(title="ChannelBan all %s clients on this server"%len(clients),text="Enter Kick Reason",multimsg=False,max=80)
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     (error, chan) = ts3lib.getChannelOfClient(schid, selectedItemID)
                     (error, dbid) = ts3lib.getClientVariableAsUInt64(schid, c, ts3defines.ClientPropertiesRare.CLIENT_DATABASE_ID)
                     ts3lib.requestSetClientChannelGroup(schid, [self.sbgroup], [chan], [dbid])
                     ts3lib.requestClientKickFromChannel(schid, c, msg)
             elif menuItemID == 7: # Kick all Clients
                 (error, clients) = ts3lib.getClientList(schid)
                 msg = self.getText(title="Kick all %s clients from this server"%len(clients),text="Enter Kick Reason",multimsg=False,max=80)
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     ts3lib.requestClientKickFromServer(schid, c, msg)
             elif menuItemID == 8: # Ban all Clients
                 (error, clients) = ts3lib.getClientList(schid)
                 msg = self.getText(title="Ban all %s clients from this server"%len(clients),text="Enter Ban Reason",multimsg=False,max=80)
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     ts3lib.banclient(schid, c, -1, msg)
             elif menuItemID == 9: # Delete all Channels
                 (error, channels) = ts3lib.getChannelList(schid)
                 confirmation = self.confirm('Delete all Channels', 'Do you really want to delete all {0} channels on this server?'.format(len(channels)))
                 if not confirmation: return
                 for c in channels: ts3lib.requestChannelDelete(schid, c, True)
         elif atype == ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL:
             if menuItemID == 1: # Message all Clients
                 (error, clients) = ts3lib.getChannelClientList(schid, selectedItemID)
                 (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                 msgs = self.getText(multiline=True,title="Message to all %s clients in channel \"%s\""%(len(clients),name),text="Enter Private Message")
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     for msg in msgs: ts3lib.requestSendPrivateTextMsg(schid, msg, c)
             if menuItemID == 2: # OfflineMessage all Clients
                 (error, clients) = ts3lib.getChannelClientList(schid, selectedItemID)
                 (error, ownID) = ts3lib.getClientID(schid)
                 uids = []
                 for c in clients:
                     if c == ownID: continue
                     (error, uid) = ts3lib.getClientVariableAsString(schid, c, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER)
                     uids.append(uid)
                 if not self.dlg: self.dlg = MessageDialog(schid, uids)
                 self.dlg.show();self.dlg.raise_();self.dlg.activateWindow()
             elif menuItemID == 3: # Poke all Clients
                 (error, clients) = ts3lib.getChannelClientList(schid, selectedItemID)
                 (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                 msgs = self.getText(title="Poke all %s clients in channel \"%s\""%(len(clients),name),text="Enter Poke Message",max=100)
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     for msg in msgs: ts3lib.requestClientPoke(schid, c, msg)
             elif menuItemID == 4: # ChannelKick all Clients
                 (error, clients) = ts3lib.getChannelClientList(schid,selectedItemID)
                 (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                 msg = self.getText(title="Kick all %s clients from channel \"%s\""%(len(clients),name),text="Enter Kick Reason",multimsg=False,max=80)
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     ts3lib.requestClientKickFromChannel(schid, c, msg)
             elif menuItemID == 5: # ChannelBan all Clients
                 (error, clients) = ts3lib.getChannelClientList(schid,selectedItemID)
                 (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                 msg = self.getText(title="ChannelBan all %s clients from channel \"%s\""%(len(clients),name),text="Enter Kick Reason",multimsg=False,max=80)
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     (error, dbid) = ts3lib.getClientVariableAsUInt64(schid, c, ts3defines.ClientPropertiesRare.CLIENT_DATABASE_ID)
                     ts3lib.requestSetClientChannelGroup(schid, [self.sbgroup], [selectedItemID], [dbid])
                     ts3lib.requestClientKickFromChannel(schid, c, msg)
             elif menuItemID == 6: # Kick all Clients
                 (error, clients) = ts3lib.getChannelClientList(schid,selectedItemID)
                 (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                 msg = self.getText(title="Kick all %s clients in channel \"%s\" from this server"%(len(clients),name),text="Enter Kick Reason",multimsg=False,max=80)
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     ts3lib.requestClientKickFromServer(schid, c, msg)
             elif menuItemID == 7: # Ban all Clients
                 (error, clients) = ts3lib.getChannelClientList(schid,selectedItemID)
                 (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                 msg = self.getText(title="Ban all %s clients in channel \"%s\""%(len(clients),name),text="Enter Ban Reason",multimsg=False,max=80)
                 if bool(self.ok) != True:return
                 (error, ownID) = ts3lib.getClientID(schid)
                 for c in clients:
                     if c == ownID: continue
                     ts3lib.banclient(schid, c, -1, msg)
     except: from traceback import format_exc;ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)
Exemple #6
0
 def onFallbackReply(self, reply):
     if reply.error() == QNetworkReply.NoError:
         try:
             isp = reply.readAll().data().decode('utf-8')
             if isp.startswith('AS'): isp = isp.split(" ", 1)[1]
             if not isp or isp == "" or isp == "undefined":
                 ts3.printMessageToCurrentTab(
                     "[[color=orange]WARNING[/color]] [color=red]ISPValidator could not resolve the ISP for '%s' (Reason: %s)"
                     % (self.clientURL(self.schid,
                                       self.requested), format_exc()))
                 if self.cfg.getboolean("failover", "enabled"):
                     if self.cfg.getboolean('failover', 'kickonly'):
                         ts3.requestClientKickFromServer(
                             self.schid, self.requested,
                             self.cfg['failover']['reason'].replace(
                                 '{isp}', isp))
                     else:
                         ts3.banclient(
                             self.schid, self.requested,
                             int(self.cfg['failover']['bantime']),
                             self.cfg['failover']['reason'].replace(
                                 '{isp}', isp))
                     self.requested = 0
                     reply.deleteLater()
                     return
             if PluginHost.cfg.getboolean("general", "verbose"):
                 ts3.printMessageToCurrentTab(
                     "%s's ISP: %s" %
                     (self.clientURL(self.schid, self.requested), isp))
             _match = False
             for _isp in self.isps:
                 if isp == _isp: _match = True
             if self.cfg.getboolean('general', 'whitelist') and not _match:
                 if self.cfg.getboolean('main', 'kickonly'):
                     ts3.requestClientKickFromServer(
                         self.schid, self.requested,
                         "%s is not a valid Internet Service Provider!" %
                         isp)
                     self.requested = 0
                 else:
                     ts3.banclient(
                         self.schid, self.requested, 60,
                         "%s is not a valid Internet Service Provider!" %
                         isp)
                     self.requested = 0
             elif not self.cfg.getboolean('general',
                                          'whitelist') and _match:
                 if self.cfg.getboolean('main', 'kickonly'):
                     ts3.requestClientKickFromServer(
                         self.schid, self.requested,
                         "%s is not a valid Internet Service Provider!" %
                         isp)
                     self.requested = 0
                 else:
                     ts3.banclient(
                         self.schid, self.requested, 60,
                         "%s is not a valid Internet Service Provider!" %
                         isp)
                     self.requested = 0
         except:
             ts3.printMessageToCurrentTab(
                 "[[color=orange]WARNING[/color]] [color=red]ISPValidator could not resolve the ISP for '%s' (Reason: %s)"
                 %
                 (self.clientURL(self.schid, self.requested), format_exc()))
             if self.cfg.getboolean("failover", "enabled"):
                 if self.cfg.getboolean('failover', 'kickonly'):
                     ts3.requestClientKickFromServer(
                         self.schid, self.requested,
                         self.cfg['failover']['reason'].replace(
                             '{isp}', isp))
                 else:
                     ts3.banclient(
                         self.schid, self.requested,
                         int(self.cfg['failover']['bantime']),
                         self.cfg['failover']['reason'].replace(
                             '{isp}', isp))
     else:
         ts3.printMessageToCurrentTab(
             "[[color=orange]WARNING[/color]] [color=red]ISPValidator could not resolve the ISP for '%s' (Reason: %s)"
             % (self.clientURL(self.schid,
                               self.requested), reply.errorString()))
         if self.cfg.getboolean("failover", "enabled"):
             if self.cfg.getboolean('failover', 'kickonly'):
                 ts3.requestClientKickFromServer(
                     self.schid, self.requested,
                     self.cfg['failover']['reason'].replace('{isp}', isp))
             else:
                 ts3.banclient(
                     self.schid, self.requested,
                     int(self.cfg['failover']['bantime']),
                     self.cfg['failover']['reason'].replace('{isp}', isp))
     self.requested = 0
     reply.deleteLater()
Exemple #7
0
 def onMainReply(self, reply):
     if reply.error() == QNetworkReply.NoError:
         try:
             isp = reply.readAll().data().decode('utf-8')
             if isp.startswith('AS'): isp = isp.split(" ", 1)[1]
             if not isp or isp == "" or isp == "undefined":
                 ts3.printMessageToCurrentTab(
                     "[[color=orange]WARNING[/color]] [color=red]ISPValidator could not resolve the ISP for '%s' (Reason: %s) Falling back to %s"
                     % (self.clientURL(self.schid, self.requested),
                        format_exc(), self.cfg['api']['fallback'].replace(
                            "{ip}", self.ip)))
                 if self.cfg.getboolean("general", "debug"):
                     ts3.printMessageToCurrentTab(
                         self.cfg['api']['fallback'].replace(
                             "{ip}", self.ip))
                 self.nwb = QNetworkAccessManager()
                 self.nwb.connect("finished(QNetworkReply*)",
                                  self.onFallbackReply)
                 self.nwb.get(
                     QNetworkRequest(
                         QUrl(self.cfg['api']['fallback'].replace(
                             "{ip}", self.ip))))
                 return
             if self.cfg.getboolean("general", "debug"):
                 ts3.printMessageToCurrentTab(
                     "%s's ISP: %s" %
                     (self.clientURL(self.schid, self.requested), isp))
             _match = False
             for _isp in self.isps:
                 if isp == _isp: _match = True
             if self.cfg.getboolean('general', 'whitelist') and not _match:
                 if self.cfg.getboolean('main', 'kickonly'):
                     ts3.requestClientKickFromServer(
                         self.schid, self.requested,
                         "%s is not a valid Internet Service Provider!" %
                         isp)
                     self.requested = 0
                 else:
                     ts3.banclient(
                         self.schid, self.requested, 60,
                         "%s is not a valid Internet Service Provider!" %
                         isp)
                     self.requested = 0
             elif not self.cfg.getboolean('general',
                                          'whitelist') and _match:
                 if self.cfg.getboolean('main', 'kickonly'):
                     ts3.requestClientKickFromServer(
                         self.schid, self.requested,
                         "%s is not a valid Internet Service Provider!" %
                         isp)
                     self.requested = 0
                 else:
                     ts3.banclient(
                         self.schid, self.requested, 60,
                         "%s is not a valid Internet Service Provider!" %
                         isp)
                     self.requested = 0
         except:
             try:
                 ts3.printMessageToCurrentTab(
                     "[[color=orange]WARNING[/color]] [color=red]ISPValidator could not resolve the ISP for '%s' (Reason: %s) Falling back to %s"
                     % (self.clientURL(self.schid, self.requested),
                        format_exc(), self.cfg['api']['fallback'].replace(
                            "{ip}", self.ip)))
                 if self.cfg.getboolean("general", "debug"):
                     ts3.printMessageToCurrentTab(
                         self.cfg['api']['fallback'].replace(
                             "{ip}", self.ip))
                 self.nwb = QNetworkAccessManager()
                 self.nwb.connect("finished(QNetworkReply*)",
                                  self.onFallbackReply)
                 self.nwb.get(
                     QNetworkRequest(
                         QUrl(self.cfg['api']['fallback'].replace(
                             "{ip}", self.ip))))
             except:
                 ts3.printMessageToCurrentTab(format_exc())
     else:
         ts3.printMessageToCurrentTab(
             "[[color=orange]WARNING[/color]] [color=red]ISPValidator could not resolve the ISP for '%s' (Reason: %s) Falling back to %s"
             % (self.clientURL(self.schid, self.requested),
                reply.errorString(), self.cfg['api']['fallback'].replace(
                    "{ip}", self.ip)))
         if self.cfg.getboolean("general", "debug"):
             ts3.printMessageToCurrentTab(
                 self.cfg['api']['fallback'].replace("{ip}", self.ip))
         self.nwb = QNetworkAccessManager()
         self.nwb.connect("finished(QNetworkReply*)", self.onFallbackReply)
         self.nwb.get(
             QNetworkRequest(
                 QUrl(self.cfg['api']['fallback'].replace("{ip}",
                                                          self.ip))))
     reply.deleteLater()
Exemple #8
0
 def onClientMoveEvent(self, serverConnectionHandlerID, clientID,
                       oldChannelID, newChannelID, visibility, moveMessage):
     # when client joins server
     if oldChannelID == 0:
         (err_name, name) = ts3lib.getClientVariableAsString(
             serverConnectionHandlerID, clientID,
             ts3defines.ClientProperties.CLIENT_NICKNAME)
         (err_desc, desc) = ts3lib.getClientVariableAsString(
             serverConnectionHandlerID, clientID,
             ts3defines.ClientPropertiesRare.CLIENT_DESCRIPTION)
         if err_name != ts3defines.ERROR_ok:
             log.error("{} - Error while obtaining client nickname".format(
                 time.ctime(time.time())))
         elif err_desc != ts3defines.ERROR_ok:
             log.error(
                 "{} - Error while obtaining client description".format(
                     time.ctime(time.time())))
         else:
             log.info(
                 "{} - New client joining server. Nickname {}, desc: {}".
                 format(time.ctime(time.time()), name, desc))
             # if nickname == desc
             if name == desc:
                 log.info("{} - Client OK. Nickname: {}".format(
                     time.ctime(time.time()), name))
             # if desc not set
             elif desc == "":
                 err_poke = ts3lib.requestClientPoke(
                     serverConnectionHandlerID, clientID,
                     "Your description is empty. Ask server admin to set it"
                 )
                 log.warning(
                     "{} - Client without description. Nickname: {}".format(
                         time.ctime(time.time()), name))
             # if nickname/desc mismatch
             elif name != desc:
                 err_kick = ts3lib.requestClientKickFromServer(
                     serverConnectionHandlerID, clientID,
                     "Set your nickname as follows: %s" % desc)
                 log.warning(
                     "{} - Nick/desc mismatch - kicking client. Nickname: {}, description: {}"
                     .format(time.ctime(time.time()), name, desc))
     # on client changing channel
     elif newChannelID != 0:
         (err_name, name) = ts3lib.getClientVariableAsString(
             serverConnectionHandlerID, clientID,
             ts3defines.ClientProperties.CLIENT_NICKNAME)
         (err_desc, desc) = ts3lib.getClientVariableAsString(
             serverConnectionHandlerID, clientID,
             ts3defines.ClientPropertiesRare.CLIENT_DESCRIPTION)
         if err_name != ts3defines.ERROR_ok:
             log.error("{} - Error while obtaining client nickname".format(
                 time.ctime(time.time())))
         elif err_desc != ts3defines.ERROR_ok:
             log.error(
                 "{} - Error while obtaining client description".format(
                     time.ctime(time.time())))
         else:
             # if desc not set
             if desc == "":
                 message = "Your description is empty. Ask server admin to set it"
                 ts3lib.requestSendPrivateTextMsg(serverConnectionHandlerID,
                                                  message, clientID)
                 log.warning(
                     "{} - Client without description. Nickname: {}".format(
                         time.ctime(time.time()), name))
             # if nickname/desc mismatch
             elif name != desc:
                 err_kick = ts3lib.requestClientKickFromServer(
                     serverConnectionHandlerID, clientID,
                     "Set your nickname as follows: %s" % desc)
                 log.warning(
                     "{} - Nick/desc mismatch - kicking client. Nickname: {}, description: {}"
                     .format(time.ctime(time.time()), name, desc))