示例#1
0
    def connect(self):
        self.serverQueryService = ts3.TS3Server(self.host, self.port)
        isLoginSuccessful = self.serverQueryService.login(
            self.username, self.password)

        if not isLoginSuccessful:
            raise ()
            print('Login not successful')
            exit(1)
示例#2
0
    def initialize(self):
        addr = self.classconfig['addr'].rsplit(':')
        username = self.classconfig['username']
        password = self.classconfig['password']

        if not addr:
            raise Exception('No address specified!')

        try:
            self._connection = ts3.TS3Server(addr[0], int(addr[1]))
            self._connection.login(username, password)
            self._connection.use(1)
        except Exception as err:
            raise Exception(str(err))
示例#3
0
def ts3Status():
    try:
        conn = ts3.TS3Server(TS3_HOST, TS3_QUERY_PORT)
        conn.login(TS3_ADMIN, TS3_PW)
    except:
        print 'Connection Error'
        return False
    else:
        servers = conn.send_command("serverlist").data
        try:
            ids = []
            for server in servers:
                server['virtualserver_status'] == 'online'
        except:
            return False
        else:
            return True
示例#4
0
def ts3Clients():
    try:
        conn = ts3.TS3Server(TS3_HOST, TS3_QUERY_PORT)
        conn.login(TS3_ADMIN, TS3_PW)
    except:
        return False
    else:
        servers = conn.send_command('serverlist').data
        ids = []
        for server in servers:
            sid = server['virtualserver_id']
            ids.append(sid)
        count = 0
        for id in ids:
            conn.use(id)
            clients = conn.send_command('clientlist').data
            count -= 1
            for client in clients:
                count += 1
        return count
示例#5
0
def main():
    """main() will connect to slack and ts3 and then initialize the main loop"""
    # slack connection
    slack = SlackClient(apiToken)

    # ts3 connection
    conn = ts3.TS3Server(ts_ip, query_port)
    conn.login(ts_admin, ts_pw)
    servers = conn.send_command('serverlist').data

    #  get bot user id
    user_list = slack.api_call("users.list")
    for user in user_list.get("members"):
        if user.get("name") == "ts3bot":
            slack_user_id = user.get("id")
            break

    if slack.rtm_connect():
        print("Connected!")

    while True:
        for message in slack.rtm_read():
            if "text" in message and message["text"].startswith(
                    "<@{}".format(slack_user_id)):
                print("Message received: {}".format(
                    json.dumps(message, indent=2)))
                message_text = message["text"]

                # if message contains user(s) or client(s)
                if re.match(
                        r".*(client)(s\b|\b).*|.*(user)(s\b|\b).*|.*(!clientlist).*",
                        message_text, re.IGNORECASE):
                    clientlist(conn, slack, message, servers)

                # server uptime
                if re.match(r".*(!uptime).*", message_text, re.IGNORECASE):
                    uptime(conn, slack, message)

        time.sleep(1)
示例#6
0
def query():
    """
    Query the TeamSpeak3 server for status

    """
    try:
        svr = ts3.TS3Server(settings['TS3_IP'], settings['TS3_PORT'])
        svr.use(1)
    except ts3.ConnectionError:
        return

    response = svr.send_command('serverinfo')
    if response.response['msg'] != 'ok':
        return
    svr_info = response.data[0]

    response = svr.send_command('clientlist')
    if response.response['msg'] != 'ok':
        return
    client_list = response.data

    for client in client_list:
        if client['client_type'] != "0":
            client_list.remove(client)

    avg_ping = svr_info['virtualserver_total_ping']
    bandwidth_down = svr_info[
        'connection_bandwidth_received_last_second_total']
    bandwidth_up = svr_info['connection_bandwidth_sent_last_second_total']

    all_data = {
        'avg_ping': avg_ping,
        'bandwidth_down': bandwidth_down,
        'bandwidth_up': bandwidth_up,
        'connected_users': str(len(client_list)),
        'connected_users_list': client_list
    }

    return all_data
示例#7
0
def getTSStatus():
    import ts3
    global childrenCount
    svr = ts3.TS3Server("ts.ddnet.tw", 10011, 1)
    response = svr.send_command('use port=9987')

    response = svr.send_command('serverinfo')
    if response.response['msg'] != 'ok':
        exit
    svr_info = response.data[0]

    response = svr.send_command('channellist')
    if response.response['msg'] != 'ok':
        exit
    channel_list = response.data

    response = svr.send_command('clientlist')
    if response.response['msg'] != 'ok':
        exit
    client_list = response.data

    # Start building the channel / client tree.
    # We save tree nodes in a dictionary, keyed by their id so we can find
    # them later in order to support arbitrary channel hierarchies.
    channels = {}

    # Build the root, or channel 0
    channels[0] = {
        'title': svr_info['virtualserver_name'],
        'isFolder': True,
        'expand': True,
        'children': []
    }

    # Add the channels to our tree

    for channel in channel_list:
        node = {
            'title': channel['channel_name'],
            'isFolder': True,
            'expand': True,
            'children': []
        }
        parent = channels[int(channel['pid'])]
        parent['children'].append(node)
        channels[int(channel['cid'])] = node

        if node['title'] == 'DDraceNetwork':
            ddnetChan = node

    # Add the clients to the tree

    for client in client_list:
        if client['client_type'] == '0':
            node = {'title': client['client_nickname'], 'isFolder': False}
            channel = channels[int(client['cid'])]
            channel['children'].append(node)

    tree = [channels[0]]

    childrenCount = 0

    def renderChannel(chan, name):
        global childrenCount, second
        thisCount = 0
        result = '<div class="block3">\n<h3>%s</h3>\n<table>\n' % name
        childrenCount
        for child in chan['children']:
            if not child['isFolder']:
                result += '<tr>\n  <td>%s</td>\n</tr>\n' % child['title']
                childrenCount += 1
                thisCount += 1
        result += '</table>\n</div>\n'
        #if second:
        #  result += '<br/>'
        if thisCount > 0:
            second = not second
            return result
        else:
            return ''

    text = ''

    text += renderChannel(ddnetChan, 'DDraceNetwork Main')
    for chan in ddnetChan['children']:
        if chan['isFolder']:
            text += renderChannel(chan, 'DDraceNetwork %s' % chan['title'])

    #if childrenCount == 0:
    #  result = '<div class="block empty" style="display:none">\n'
    #else:
    result = '<div class="block">\n'
    result += '<h3 class="ip"><a href="ts3server://ts.ddnet.tw">ts.ddnet.tw</a></h3>'
    mbS = ''
    if childrenCount != 1:
        mbS = 's'
    result += '<h2>DDNet Teamspeak</h2>\n'
    result += text
    result += '<br/></div>'
    return result
示例#8
0
parser.add_argument('basic_url', action='store',
                help='The public url to the webpath.', default=None)

results = parser.parse_args()

web_path = results.webpath
basic_url = results.basic_url
username = results.serveradmin
password = results.password

while True:
	onlyfiles = [ f for f in listdir(web_path) if isfile(join(web_path,f)) ]
	img = random.choice(onlyfiles)

	# This is the what the description will be set too.
	description = "[IMG]%s[/IMG]" % (basic_url+img)

	# Server info change the port and address to what you need.
	server = ts3.TS3Server('127.0.0.1', 10011)
	server.login(username, password)

	# Which virtualserver to use
	server.use(1)

	# Set cid to the channel you want to modify.
	response = server.send_command('channeledit', keys={'cid': '4', 'channel_description': description})
	#print(response)

	# Time to sleep before changing the description again.
	time.sleep(60*60*5)
示例#9
0
 def __init__(self):
     self.server = ts3.TS3Server(HOST, PORT)
     self.server.login(USER, PASS)
     self.server.use(SERVER)