Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telnetlib
- import socket
- from datetime import datetime
- from datetime import timedelta
- from socket import error as socket_error
- import os
- import time as tm
- import _thread
- import subprocess
- from random import randint
- from scapy.all import *
- # Login creds
- HOST = "localhost"
- user = "serveradmin"
- password = "HIDING"
- apikey="HIDING"
- # misc
- banmsg = "automated"
- user_to_ban = "Juicetin" #Default User
- temp_current_banner = "https://i.imgur.com/37Ju1fC.png"
- yt_thread_active = 0
- wheel_used = {'':datetime.now()}
- tn = telnetlib.Telnet(HOST, 10011)
- tnclient = telnetlib.Telnet("localhost", 25639)
- ## main method ##
- def main():
- # Initial telnet config for server and client
- tn = telnetlib.Telnet(HOST, 10011)
- tnclient = telnetlib.Telnet("localhost", 25639)
- # Login to serverquery
- login_string = "login %s %s\n" % (user, password)
- tn.write(bytes(login_string, encoding="ascii"))
- tn.read_until(b"msg=ok",2)
- # Server handler initialization
- tn.write(b"use 1\n")
- tn.read_until(b"msg=ok",2)
- # Clientquery apikey authorization
- clientauth = "auth apikey=%s\n" % (apikey)
- tnclient.write(bytes(clientauth, encoding="ascii"))
- tnclient.read_until(b"msg=ok",2)
- # client notify for pokes
- tnclient.write(b"clientnotifyregister schandlerid=0 event=notifyclientpoke\n")
- tnclient.read_until(b"msg=ok",2)
- # Find bot clid
- tn.write(b"clientfind pattern=juicero\n")
- tn.read_until(b"=",2)
- juicero = tn.read_until(b" ",2)
- juicero = juicero.decode("utf-8").strip(" ")
- # Move bot to juice box (cid=6)
- movecmd="clientmove cid=6 clid=%s\n" % (juicero)
- tnclient.write(bytes(movecmd,encoding="ascii"))
- connect()
- # Runs a help command every minute to ensure telnet connection stays alive
- #_thread.start_new_thread(keep_alive, (60, ) )
- # Create empty youtube link queue
- yt_link_queue = []
- global yt_thread_active
- yt_thread_active = 0
- global wheel_used
- del wheel_used['']
- while 1:
- #sniff(prn=arp_display, filter="arp",store=0,count=0)
- # Remove empty strings from queue
- if '' in yt_link_queue:
- for i in range(len(yt_link_queue) - 1, -1, -1):
- if yt_link_queue[i] == '':
- del yt_link_queue[i]
- try:
- if tnclient.read_until(b"notifyclientpoke",2) == b"notifyclientpoke" or (yt_link_queue and yt_thread_active == 0):
- print("Got poked!\n")
- tnclient.read_until(b"invokername=",2)
- msg_from = tnclient.read_until(b" ",2)
- print(msg_from)
- tnclient.read_until(b"msg=",2)
- message = tnclient.read_until(b"\n",2)
- print(message)
- print(yt_thread_active)
- print(yt_link_queue)
- # Strip the message of the newline and the \s given in the original format
- message = message.decode("utf-8").strip("\\s").strip("\n")
- msg_from = msg_from.decode("utf-8").strip("\\s").strip("\n")
- msg_from = msg_from[:-1]
- print(message)
- print(msg_from)
- msg_from_cmd = "clientfind pattern=%s\n" % (msg_from)
- tn.write(bytes(msg_from_cmd, encoding="ascii"))
- tn.read_until(b"=",2)
- msg_from_clid = tn.read_until(b" ", 2).decode("utf-8").strip(" ")
- tn.read_until(b"msg=ok",2)
- """"""" # # # # Poke Message Management # # # # """""""
- if message[:6] == "!wheel":
- print("GOT WHEELED")
- time = datetime.now()
- print(time)
- """(time - wheel_used[msg_from]).total_seconds() >= 3600 or"""
- if True:
- user_to_ban = message[8:]
- print("Commencing wheel")
- wheel(user_to_ban)
- else:
- print("NOT COMMENCING WHEEL")
- pokecmd = "clientpoke clid=%d msg=%s" % (msg_from_clid, str(time-wheel_used[msg_from]))
- print(pokecmd)
- tnclient.write(bytes(pokecmd, encoding="ascii"))
- tnclient.read_until("msg=ok",2)
- wheel_used[msg_from] = time
- elif message[:3] == "!yt" or (yt_link_queue and yt_thread_active == 0):
- yt_link = message[5:]
- yt_link_queue.append(yt_link)
- print(yt_link_queue)
- if yt_thread_active == 0 and yt_link_queue:
- yt_thread_active = 1
- _thread.start_new_thread(ytaudio, (yt_link_queue[0], msg_from, ) )
- print("Finished audio and playing next in queue")
- yt_link_queue.pop(0)
- except KeyboardInterrupt:
- print("Quitting...")
- exit()
- except socket_error as serr:
- #os.system("/home/jscd/ts_startscript.sh")
- exit()
- except EOFError:
- print("EOF Error")
- os.system("python3 /home/jscd/ban_user.py")
- exit()
- except Exception as e:
- try:
- print(e)
- #print("Disconneced...\nReconnecting...\n")
- connect()
- #print("Reconnected!\n")
- except Exception as e2:
- print(e2)
- print("Dead...")
- exit()
- def keep_alive(time):
- i = 0
- while 1:
- print("Is alive")
- tm.sleep(time)
- tn.write(b"help\n")
- tn.read_until(b"msg=ok",2)
- tnclient.write(b"help\n")
- tnclient.read_until(b"msg=ok",2)
- i = i + 1
- def arp_display(pkt):
- if pkt[ARP].op == 1:
- if pkt[ARP].hwsrc == 'b4:7c:9c:44:9f:e9': #Your button MAC - parcel
- print("POOF")
- ## play audio from youtube link ##
- def ytaudio(yt_link, msg_from):
- global yt_thread_active
- print("Playing %s..." % (yt_link))
- # Find bot clid
- tn.write(b"clientfind pattern=juicero\n")
- tn.read_until(b"clid=",2)
- juicero = tn.read_until(b" ",2)
- juicero = juicero.decode("utf-8").strip(" ")
- #msg_from = msg_from.decode("utf-8").strip(" ")
- # Get current channel to return to
- tnclient.write(b"clientlist\n")
- original_channel_id = -100
- other_channel_id = -100
- while original_channel_id == -100 or other_channel_id == -100:
- tnclient.read_until(b"cid=",2)
- channel_id = tnclient.read_until(b" ",2).decode("utf-8").strip(" ")
- tnclient.read_until(b"client_nickname=",2)
- nick = tnclient.read_until(b" ",2).decode("utf-8").strip(" ")
- if nick == "juicero":
- original_channel_id = channel_id
- elif nick == msg_from:
- other_channel_id = channel_id
- tnclient.read_until(b"msg=ok",2)
- # Download youtube audio
- os.system("youtube-dl --extract-audio -o audio.wav --audio-format wav %s" % (yt_link))
- # Move client to 'Slay the Gay Away' Channel
- movecmd = "clientmove cid=%s clid=%s\n" % (other_channel_id,juicero)
- print(movecmd)
- tnclient.write(bytes(movecmd,encoding="ascii"))
- # Play audio
- os.system("vlc-wrapper -I dbus --play-and-exit audio.wav")
- print("Finished playing audio")
- # Remove audio file
- os.system("rm audio.wav")
- # Move client back
- movecmd = "clientmove cid=%s clid=%s\n" % (original_channel_id, juicero)
- tnclient.write(bytes(movecmd,encoding="ascii"))
- yt_thread_active = 0
- ## connect to telnet for server/client query ##!yt
- def connect():
- #tnclient.read_until(b"=1", 2)
- login_string = "login %s %s\n" % (user, password)
- tn.write(bytes(login_string, encoding="ascii"))
- tn.read_until(b"msg=ok",2)
- tn.write(b"use 1\n")
- tn.read_until(b"msg=ok",2)
- clientauth = "auth apikey=%s\n" % (apikey)
- tnclient.write(bytes(clientauth, encoding="ascii"))
- tnclient.read_until(b"msg=ok",2)
- tnclient.write(b"clientnotifyregister schandlerid=0 event=notifyclientpoke\n")
- tnclient.read_until(b"msg=ok",2)
- ## get random time for use with wheel ##
- def get_time():
- # Possible options:
- # 1 hour - 3% http://i.imgur.com/5v8w5Tl.gif
- # 15 minutes - 3% http://i.imgur.com/QLJxDah.gif
- # 10 minutes - 5% http://i.imgur.com/HtZP64g.gif
- # 5 minutes - 10% http://i.imgur.com/eki5Y1i.gif
- # 2 minutes - 30% http://i.imgur.com/EqkXFnX.gif
- # 45 seconds - 30% http://i.imgur.com/TQG01JR.gif
- # 30 seconds - 10% http://i.imgur.com/4gfjLGA.gif
- # 15 seconds - 5% http://i.imgur.com/JxZWgtN.gif
- # 5 seconds - 3% http://i.imgur.com/ll4i5fb.gif
- # 1 second - 1% http://i.imgur.com/Uu875et.gif
- #
- # Here is the fucking bell curve: http://imgur.com/ZZouAlR
- n = randint(1,100)
- if n <= 3: # hour
- time = 3600
- elif n <= 6: # 15 mins
- time = 900
- elif n <= 11: # etc...
- time = 600
- elif n <= 21:
- time = 300
- elif n <= 51:
- time = 120
- elif n <= 81:
- time = 45
- elif n <= 91:
- time = 30
- elif n <= 96:
- time = 15
- elif n <= 99:
- time = 5
- elif n <= 100:
- time = 1
- return time
- ## get link for wheel method ##
- def get_link(time):
- if time == 3600: # hour
- link = "http://i.imgur.com/5v8w5Tl.gif"
- elif time == 900: # 15 mins
- link = "http://i.imgur.com/QLJxDah.gif"
- elif time == 600: # etc...
- link = "http://i.imgur.com/HtZP64g.gif"
- elif time == 300:
- link = "http://i.imgur.com/eki5Y1i.gif"
- elif time == 120:
- link = "http://i.imgur.com/EqkXFnX.gif"
- elif time == 45:
- link = "http://i.imgur.com/TQG01JR.gif"
- elif time == 30:
- link = "http://i.imgur.com/4gfjLGA.gif"
- elif time == 15:
- link = "http://i.imgur.com/JxZWgtN.gif"
- elif time == 5:
- link = "http://i.imgur.com/ll4i5fb.gif"
- elif time == 1:
- link = "http://i.imgur.com/Uu875et.gif"
- return link
- ## wheel of ban method ##
- def wheel(user_to_ban):
- print("Wheeling")
- # Get ban time and link to banner gif
- time = get_time()
- link = get_link(time)
- # Change banner to wheel gif (link)
- change_pic = "serveredit virtualserver_hostbanner_gfx_url=%s\n" % (link)
- tn.write(bytes(change_pic, encoding="ascii"))
- tn.read_until(b"msg=ok",2)
- # Find the clid of user to ban
- client_find = "clientfind pattern=%s\n" % (user_to_ban)
- print(client_find)
- tn.write(bytes(client_find, encoding="ascii"))
- print(tn.read_until(b"clid=",2))
- client = tn.read_until(b" ",2)
- client = client.decode("utf-8").strip(" ")
- print(client)
- print(tn.read_until(b"msg=ok",2))
- # Find clid of juicero... again
- tn.write(b"clientfind pattern=juicero\n")
- tn.read_until(b"=",2)
- juicero = tn.read_until(b" ",2)
- juicero = juicero.decode("utf-8").strip(" ")
- print("%s: %s juicero: %s\n" % (user_to_ban, client, juicero))
- # Find the channels of juicero and user to ban
- tnclient.write(b"clientlist\n")
- original_channel_id = -100
- banned_channel_id = -100
- while original_channel_id == -100 or banned_channel_id == -100:
- tnclient.read_until(b"cid=",2)
- channel_id = tnclient.read_until(b" ",2).decode("utf-8").strip(" ")
- tnclient.read_until(b"client_nickname=",2)
- nick = tnclient.read_until(b" ",2).decode("utf-8").strip(" ")
- if nick == "juicero":
- original_channel_id = channel_id
- print("%s %s\n" % (nick,channel_id))
- elif nick == user_to_ban:
- print("%s %s\n" % (nick, channel_id))
- banned_channel_id = channel_id
- print("banned:%s original:%s\n" % (banned_channel_id, original_channel_id))
- tnclient.read_until(b"msg=ok",2)
- movecmd = "clientmove cid=%s clid=%s\n" % (banned_channel_id, juicero)
- print(movecmd)
- tnclient.write(bytes(movecmd,encoding="ascii"))
- # Play audio
- os.system("vlc-wrapper -I dbus --play-and-exit /home/jscd/wheel_fx/winner.wav")
- # Ban user
- ban_cmd = "banclient clid=%s time=%s banreason=%s\n" % (client, time, banmsg)
- print(ban_cmd)
- tn.read_until(b"msg=ok",2)
- tn.write(bytes(ban_cmd, encoding="ascii"))
- # Change banner back
- tm.sleep(2)
- change_pic = "serveredit virtualserver_hostbanner_gfx_url=%s\n" % (temp_current_banner)
- tn.write(bytes(change_pic, encoding="ascii"))
- tn.read_until(b"msg=ok",2)
- # Move juicero back to original channel
- movecmd = "clientmove cid=%s clid=%s\n" % (original_channel_id, juicero)
- tnclient.write(bytes(movecmd,encoding="ascii"))
- if __name__=='__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement