Advertisement
Guest User

ONET_CZAT

a guest
Dec 8th, 2015
1,429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 25.05 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. ############### CONFIG ###############
  4. kolor = 1                 # obsluga kolorow, 0 aby wylaczyc;
  5. bold = 1                   # obsluga pogrubienia czcionki;
  6. kodowanie = 2              # Kodowanie 0 - ISO, 1 - WIN, 2 - UTF;
  7. emoty = 1                  # Emoty 0 - %Ihihi%, 1 - <hihi>, 2 - //hihi;                                            
  8. TUNEL_PASS = ""            # haslo do zabezpieczenia tunelu;
  9. local_ip = ""              # vHost MOCNY_FULL;
  10. port = 6667              # port, bez ""
  11. realname = "uuu"   # nazwa
  12.  
  13. ######################################
  14.  
  15.  
  16. from socket import *
  17. from thread import start_new_thread
  18. from re import findall, sub, search
  19. import time
  20. from time import ctime
  21. import select
  22.  
  23. import sys
  24. wersja = sys.version[0] + sys.version[2]
  25. if (wersja <= "25"):
  26.  import _ssl
  27. else:
  28.  import ssl
  29.  
  30. print "ONET"
  31.  
  32. print "realname:" + realname + ""
  33.  
  34. if (realname == ""):
  35.  realname = ""
  36. if kolor == 1:
  37.     print "Wlaczona obsluga kolorow"
  38. else:
  39.     print "Wylaczona obsluga kolorow"
  40. if bold == 1: print "Wlaczona obsluga pogrubienia czcionki"
  41. if kodowanie == 1: print "Wlaczona obsluga kodowania CP1250"
  42. def dawaj_date():
  43.  sys.stdout.write("[%s] = " % ctime())
  44. if len(sys.argv) == 2:
  45.  BindPort = int(sys.argv[1])
  46. else:
  47.  BindPort = port
  48. def czas(cz):
  49.  a = ""
  50.  try:
  51.   a=[x for x in ctime(int(cz)).split(' ') if x.find(':') != -1][0]
  52.  except:
  53.   a=cz
  54.  return a
  55.  
  56.  
  57. def auth(s):
  58.     stringbuffer = ""
  59.     i_list = range(16)
  60.     ai = []
  61.     pomoc = []
  62.     f1 = [
  63.           29, 43,  7,  5, 52, 58, 30, 59, 26, 35,
  64.           35, 49, 45,  4, 22,  4,  0,  7,  4, 30,
  65.           51, 39, 16,  6, 32, 13, 40, 44, 14, 58,
  66.           27, 41, 52, 33,  9, 30, 30, 52, 16, 45,
  67.           43, 18, 27, 52, 40, 52, 10,  8, 10, 14,
  68.           10, 38, 27, 54, 48, 58, 17, 34,  6, 29,
  69.           53, 39, 31, 35, 60, 44, 26, 34, 33, 31,
  70.           10, 36, 51, 44, 39, 53,  5, 56
  71.       ]
  72.     f2 = [
  73.            7, 32, 25, 39, 22, 26, 32, 27, 17, 50,
  74.           22, 19, 36, 22, 40, 11, 41, 10, 10,  2,
  75.           10,  8, 44, 40, 51,  7,  8, 39, 34, 52,
  76.           52,  4, 56, 61, 59, 26, 22, 15, 17,  9,
  77.           47, 38, 45, 10,  0, 12,  9, 20, 51, 59,
  78.           32, 58, 19, 28, 11, 40,  8, 28,  6,  0,
  79.           13, 47, 34, 60,  4, 56, 21, 60, 59, 16,
  80.           38, 52, 61, 44,  8, 35,  4, 11
  81.       ]
  82.     f3 = [
  83.           60, 30, 12, 34, 33,  7, 15, 29, 16, 20,
  84.           46, 25,  8, 31,  4, 48,  6, 44, 57, 16,
  85.           12, 58, 48, 59, 21, 32,  2, 18, 51,  8,
  86.           50, 29, 58,  6, 24, 34, 11, 23, 57, 43,
  87.           59, 50, 10, 56, 27, 32, 12, 59, 16,  4,
  88.           40, 39, 26, 10, 49, 56, 51, 60, 21, 37,
  89.           12, 56, 39, 15, 53, 11, 33, 43, 52, 37,
  90.           30, 25, 19, 55,  7, 34, 48, 36
  91.       ]
  92.     p1 = [
  93.           11, 9, 12, 0, 1, 4, 10, 13, 3,
  94.           6, 7, 8, 15, 5, 2, 14
  95.       ]
  96.     p2 = [
  97.           1, 13, 5, 8, 7, 10, 0, 15, 12, 3,
  98.           14, 11, 2, 9, 6, 4
  99.       ]
  100.  
  101.  
  102.     if len(s) < 16:
  103.         return "(key to short)"
  104.  
  105.     for c in s:
  106.         if c > '9':
  107.             if c > 'Z':
  108.                 ai.append((ord(c) - 97) + 36)
  109.             else:
  110.                 ai.append((ord(c) - 65) + 10)
  111.         else:
  112.             ai.append(ord(c) - 48)
  113.  
  114.     for i in i_list:
  115.         ai[i] = f1[ai[i] + i]
  116.  
  117.     for i in i_list:
  118.         pomoc.insert(i, (ai[i] + ai[p1[i]]) % 62)
  119.     ai = pomoc
  120.  
  121.     for i in i_list:
  122.         ai[i] = f2[ai[i] + i]
  123.  
  124.     pomoc = []
  125.     for i in i_list:
  126.         pomoc.insert(i, (ai[i] + ai[p2[i]]) % 62)
  127.     ai = pomoc
  128.  
  129.     for i in i_list:
  130.         ai[i] = f3[ai[i] + i]
  131.  
  132.     for j in ai:
  133.         if j >= 10:
  134.             if j >= 36:
  135.                 stringbuffer += chr((97 + j) - 36)
  136.             else:
  137.                 stringbuffer += chr((65 + j) - 10)
  138.         else:
  139.             stringbuffer += chr(48 + j)
  140.  
  141.     return stringbuffer
  142. def zassaj(host, z, mssl):
  143.     a = ""
  144.     s = socket()
  145.     if mssl == 1:
  146.         s.connect((host, 443))
  147.         if (wersja <= "25"):
  148.          sssl = ssl(s)
  149.         else:
  150.          sssl = ssl.wrap_socket(s)
  151.         sssl.write(z)
  152.         sssl.read()
  153.         del sssl
  154.         s.close()
  155.         return ""
  156.     s.connect((host, 80))
  157.     s.send(z)
  158.     while True:
  159.         b = s.recv(1024)
  160.         if b == "":
  161.             break
  162.         a += b
  163.     s.close()
  164.     return a
  165. def zassaj_http(host, z, get_uo = 0, mssl=0):
  166.     a = zassaj(host, z, mssl)
  167.     if get_uo == 1:
  168.         x = a.find("<uoKey>")
  169.         if x == -1:
  170.             return ""
  171.         x2 = a.find("</uoKey>")
  172.         return a[x + 7:x2]
  173.     c = findall("Cookie:(.+?;)", a)
  174.     if len(c) > 0:
  175.         return ''.join(c)
  176.     else:
  177.         return ""
  178.  
  179.  
  180. def autoryzuj(nickname, password):
  181.     Cookie = "Cookie:"
  182.     Cookie += zassaj_http("kropka.onet.pl",
  183.                           "GET /_s/kropka/1?DV=czat/applet/FULL HTTP/1.1\r\n"\
  184.                           "Host: kropka.onet.pl\r\n"\
  185.                           "Connection: keep-alive\r\n\r\n")
  186.     Cookie += zassaj_http("czat.onet.pl",
  187.                           "GET /myimg.gif HTTP/1.1\r\n"\
  188.                           "Host: czat.onet.pl\r\n" + Cookie + "\r\n\r\n")
  189.     POST = "api_function=getUoKey&params=a:3:{"\
  190.            "s:4:\"nick\";s:%d:\"%s\";"\
  191.            "s:8:\"tempNick\";i:%d;"\
  192.            "s:7:\"version\";s:22:\"1.1(20110425-2020 - R)\";}"
  193.     if nickname[0] == '~':
  194.         POST = POST % (len(nickname) - 1, nickname[1:], 1)
  195.     else:
  196.         POST = POST % (len(nickname), nickname, 0)
  197.         POST_s = "r=&url=&login=%s&haslo=%s&app_id=20&ssl=1&ok=1" % (nickname, password)
  198.         POST_OVERRIDE = "api_function=userOverride&params=a:3:{s:4:\"nick\";s:%d:\"%s\";}" % (len(nickname), nickname)
  199.         zassaj_http("secure.onet.pl",
  200.                     "POST /mlogin.html HTTP/1.1\r\n"\
  201.                     "Content-Type: application/x-www-form-urlencoded\r\n"\
  202.                     "Content-Length: %d\r\n"\
  203.                     "Cache-Control: no-cache\r\n"\
  204.                     "Pragma: no-cache\r\n"\
  205.                     "User-Agent: Mozilla/4.0 (Windows NT 5.0)\r\n"\
  206.                     "Host: secure.onet.pl\r\n"\
  207.                     "Connection: keep-alive\r\n"\
  208.                     "%s\r\n\r\n"\
  209.                     "%s" % (len(POST_s), Cookie, POST_s), 0, 1)
  210.        
  211.         zassaj_http("czat.onet.pl",
  212.                     "POST /include/ajaxapi.xml.php3 HTTP/1.1\r\n"\
  213.                     "Content-Type: application/x-www-form-urlencoded\r\n"\
  214.                     "Content-Length: %d\r\n"\
  215.                     "Cache-Control: no-cache\r\n"\
  216.                     "Pragma: no-cache\r\n"\
  217.                     "User-Agent: Mozilla/4.0 (Windows NT 5.0)\r\n"\
  218.                     "Host: czat.onet.pl\r\n"\
  219.                     "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*;"\
  220.                     "q=.2\r\n"\
  221.                     "Connection: close\r\n"\
  222.                     "%s\r\n\r\n"\
  223.                     "%s" % (len(POST_OVERRIDE), Cookie, POST_OVERRIDE), 1)
  224.  
  225.     uoKey = \
  226.     zassaj_http("czat.onet.pl",
  227.                 "POST /include/ajaxapi.xml.php3 HTTP/1.1\r\n"\
  228.                 "Content-Type: application/x-www-form-urlencoded\r\n"\
  229.                 "Content-Length: %d\r\n"\
  230.                 "Cache-Control: no-cache\r\n"\
  231.                 "Pragma: no-cache\r\n"\
  232.                 "User-Agent: Mozilla/4.0 (Windows NT 5.0)\r\n"\
  233.                 "Host: czat.onet.pl\r\n"\
  234.                 "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*;"\
  235.                 "q=.2\r\n"\
  236.                 "Connection: close\r\n"\
  237.                 "%s\r\n\r\n"\
  238.                 "%s" % (len(POST), Cookie, POST), 1)
  239.     return uoKey
  240.  
  241.  
  242. def jedziesz(sock, ID):
  243.  bufor = ""
  244.  koniec = 0
  245.  nickname = ""
  246.  password = "asd123"
  247.  lkodowanie = kodowanie
  248.  lkolor = kolor
  249.  lbold = bold
  250.  lemoty = emoty
  251.  while 1:
  252.   b1 = ""
  253.   b1=sock.recv(1024)
  254.   if b1 == "": return
  255.   bufor += b1
  256.   if not bufor.find("NICK") == -1:
  257.    nickname = findall("NICK (.*?)(\r|\n)", bufor)[0][0]
  258.    if nickname[0] == '~':
  259.     break
  260.   if not bufor.find("PASS") == -1:
  261.    password = findall("PASS (.*?)(\r|\n)", bufor)[0][0]
  262.   if (password != "") and (nickname != ""):
  263.    break
  264.  sock.send((":fake.host 666 nik : 10[Tunel] uzycie:\r\n"
  265.             ":fake.host 666 nik : 10[Tunel] /set nick 10Twoj_nick\r\n"
  266.             ":fake.host 666 nik : 10[Tunel] /server 127.0.0.1 7777 10haslo_do_nicka\r\n"
  267.             ":fake.host 666 nik : 10[Tunel] \r\n"
  268.             ":fake.host 666 nik : 10[Tunel] dla nicka tymczasowego: /set nick 10~Twoj_nick\r\n"))
  269.  sock.send((":fake.host 666 nik : 10[Tunel] \r\n"
  270.             ":fake.host 666 nik : 10[Tunel] ustawienia polaczenia:\r\n"
  271.             ":fake.host 666 nik : 10[Tunel] obsluga kolorow:5              %d\r\n"
  272.             ":fake.host 666 nik : 10[Tunel] obsluga pogrubienia czcionki:5 %d\r\n"
  273.             ":fake.host 666 nik : 10[Tunel] \r\n")%(lkolor,lbold))
  274.  sock.send((":fake.host 666 nik : 10[Tunel] komendy:\r\n"
  275.             ":fake.host 666 nik : 10[Tunel] /sets 10<--- pokazuje ustawienia\r\n"
  276.             ":fake.host 666 nik : 10[Tunel] /uo 10<--- zwraca UoKey\r\n"
  277.             ":fake.host 666 nik : 10[Tunel] /sets kolor 0 10<---5 010: wylacza kolor,5 110: wlaczyc\r\n"
  278.             ":fake.host 666 nik : 10[Tunel] /sets kodowanie 0 10<---5 010: ISO 8859-2 (irssi),5 110: CP-1250 (mIRC 6.*),5 210: UTF-8 (mIRC 7.*)\r\n"
  279.             ":fake.host 666 nik : 10[Tunel] /sets bold 0 10<---5 010: wylacza pogrubienie czcionki,5 110: wlacza\r\n"))
  280.  sock.send((":fake.host 666 nik : 10[Tunel] /sets emoty 0 10<---5 010: %Ihihi%,5 110: <hihi>,5 210: //hihi\r\n"))
  281.  
  282.  if not TUNEL_PASS == "":
  283.   password = password.split(':')
  284.   if not len(password) == 2:
  285.    sys.stdout.write("[%3d]nick: %s :: pass: %s\n" % (ID, nickname, ':'.join(password)))
  286.    sock.send("uzywaj: /server host port haslo_do_tunel:haslo_do_nick\r\n")
  287.    sock.close()
  288.    return
  289.   if not password[0] == TUNEL_PASS:
  290.    sys.stdout.write("[%3d]nick: %s :: pass: %s\n" % (ID, nickname, ':'.join(password)))
  291.    sock.send("zle haslo do tunela\r\n")
  292.    sock.close()
  293.    return
  294.   password = password[1]
  295.  sys.stdout.write("nick: %s\n" % nickname)
  296.  try:
  297.  
  298.   UOkey  = autoryzuj(nickname, password)
  299.  
  300.   sock.send((":fake.host 666 nik : 10[Tunel] \r\n"
  301.              ":fake.host 2012 " + nickname + " : 10[Tunel] Twoja maska: " + UOkey + "\r\n"))
  302.   sock.send((":Tunel!fake@fake.fake PRIVMSG fake :VERSION\r\n"))
  303.  except:
  304.   dawaj_date()
  305.   my_err = "[%3d] ERROR: sprawdz swoje polaczenie sieciowe z internetem, poprawnosc wprowadzonego hasla i nicka lub dostepnosc serwerow onet.pl (zmiany autoryzacji)\r\n" % ID
  306.   sys.stdout.write(my_err)
  307.   sock.send(my_err)
  308.   sock.close()
  309.   return
  310.  gniazda = []
  311.  gniazda.append(sock)
  312.  onet = socket(AF_INET, SOCK_STREAM)
  313.  gniazda.append(onet)
  314.  onet.bind((local_ip, 0))
  315.  onet.connect(("czat-app.onet.pl", 5015))
  316.  sock.send(onet.recv(1024))
  317.  onet.send("AUTHKEY\r\n")
  318.  onet.send("NICK %s\r\n" % nickname)
  319.  onet.send("USER * %s czat-app.onet.pl :%s\r\n" % (UOkey, realname))
  320.  authkey = auth(findall(":.*?801.*?:(.*?)\r", onet.recv(1024))[0])
  321.  onet.send("AUTHKEY %s\r\n" % authkey)
  322.  while 1:
  323.   (dr, dw, de) = select.select(gniazda, [], [])
  324.   for gotowe in dr:
  325.    if gotowe == sock:
  326.     try:
  327.      bufor = gotowe.recv(1024)
  328.      if bufor == "":
  329.       koniec = 1
  330.       break
  331.      if bufor.find("NOTICE") != -1 and bufor.find("VERSION") != -1:
  332.       if bufor.find("mIRC v6") != -1:
  333.        lkodowanie = 1
  334.       elif bufor.find("mIRC v7") != -1:
  335.        lkodowanie = 2
  336.       else:
  337.        lkodowanie = 0
  338.       sock.send((":fake.host 666 nik : 10[Tunel] ustawiono typ kodowania:5                %d\r\n")%(lkodowanie))
  339.      if lkodowanie == 1:
  340.       bufor = bufor.replace('\xa5', '\xa1')
  341.       bufor = bufor.replace('\xb9', '\xb1')
  342.       bufor = bufor.replace('\x8c', '\xa6')
  343.       bufor = bufor.replace('\x9c', '\xb6')
  344.       bufor = bufor.replace('\x8f', '\xac')
  345.       bufor = bufor.replace('\x9f', '\xbc')
  346.      elif lkodowanie == 2:
  347.       bufor = bufor.replace("\xc4\x84", "\xa1")
  348.       bufor = bufor.replace("\xc4\x86", "\xc6")
  349.       bufor = bufor.replace("\xc4\x98", "\xca")
  350.       bufor = bufor.replace("\xc5\x81", "\xa3")
  351.       bufor = bufor.replace("\xc5\x83", "\xd1")
  352.       bufor = bufor.replace("\xc3\x93", "\xd3")
  353.       bufor = bufor.replace("\xc5\x9a", "\xa6")
  354.       bufor = bufor.replace("\xc5\xb9", "\xac")
  355.       bufor = bufor.replace("\xc5\xbb", "\xaf")
  356.       bufor = bufor.replace("\xc4\x85", "\xb1")
  357.       bufor = bufor.replace("\xc4\x87", "\xe6")
  358.       bufor = bufor.replace("\xc4\x99", "\xea")
  359.       bufor = bufor.replace("\xc5\x82", "\xb3")
  360.       bufor = bufor.replace("\xc5\x84", "\xf1")
  361.       bufor = bufor.replace("\xc3\xb3", "\xf3")
  362.       bufor = bufor.replace("\xc5\x9b", "\xb6")
  363.       bufor = bufor.replace("\xc5\xba", "\xbc")
  364.       bufor = bufor.replace("\xc5\xbc", "\xbf")
  365.      bufor = bufor.replace('\x03' + "14", "%C959595%")
  366.      bufor = bufor.replace('\x03' + "5", "%C990033%")
  367.      bufor = bufor.replace('\x03' + "7", "%Cc86c00%")
  368.      bufor = bufor.replace('\x03' + "5", "%C623c00%")
  369.      bufor = bufor.replace('\x03' + "13", "%Cce00ff%")
  370.      bufor = bufor.replace('\x03' + "4", "%Ce40f0f%")
  371.      bufor = bufor.replace('\x03' + "12", "%C3030ce%")
  372.      bufor = bufor.replace('\x03' + "3", "%C008100%")
  373.      bufor = bufor.replace('\x03' + "10", "%C1a866e%")
  374.      bufor = bufor.replace('\x03' + "11", "%C006699%")
  375.      bufor = bufor.replace('\x03' + "6", "%C8800ab%")
  376.      bufor = bufor.replace('\x03' + "2", "%C0f2ab1%")
  377.      bufor = bufor.replace('\x03' + "7", "%Cff6500%")
  378.      bufor = bufor.replace('\x03' + "4", "%Cff0000%")
  379.      if lemoty == 1:
  380.       b = findall("(<(.+?)>)", bufor)
  381.       for c in b:
  382.        bufor = bufor.replace(c[0], "%I" + c[1] + "%")
  383.      elif lemoty == 2:
  384.       b = findall("(//(\w+))", bufor)
  385.       for c in b:
  386.        bufor = bufor.replace(c[0], "%I" + c[1] + "%")
  387.      tmpb = bufor.split(' ')
  388.      if tmpb[0] == "PRIVMSG":
  389.       if tmpb[1][0:2] == '#^':
  390.        tmpb[1] = tmpb[1].replace('#^','^')
  391.        bufor = ' '.join(tmpb)
  392.      elif (tmpb[0] == "JOIN") and (tmpb[1][0:2] == '#^'):
  393.       tmpb[1] = tmpb[1].replace('#^','^')
  394.       bufor = ' '.join(tmpb)
  395.      elif (tmpb[0] == "PART") and (tmpb[1][0:2] == '#^'):
  396.       tmpb[1] = tmpb[1].replace('#^','^')
  397.       bufor = ' '.join(tmpb)
  398.      elif (tmpb[0] == "INVITE") and (tmpb[2][0:2] == '#^'):
  399.       tmpb[2]=tmpb[2].replace('#^','^')
  400.       bufor = ' '.join(tmpb)
  401.      elif tmpb[0][:2] == "UO":
  402.       sock.send(":fake.host 2012 " + nickname + " : 10[Tunel] Twoj UOkey: " + UOkey + "\r\n")
  403.      elif tmpb[0][:4] == "SETS":
  404.         try:
  405.          if tmpb[1] == "kolor":
  406.              try:
  407.                  lkolor = int(tmpb[2][0])
  408.              except:
  409.                  sock.send("onettunel.py - dozwolone wartosci: 2, 1 i 0\r\n")
  410.          elif tmpb[1] == "kodowanie":
  411.              try:
  412.                  lkodowanie = int(tmpb[2][0])
  413.              except:
  414.                  sock.send("onettunel.py - dozwolone wartosci: 1 i 0\r\n")
  415.          elif tmpb[1] == "bold":
  416.              try:
  417.                  lbold = int(tmpb[2][0])
  418.              except:
  419.                  sock.send("onettunel.py - dozwolone wartosci: 1 i 0\r\n")
  420.          elif tmpb[1] == "emoty":
  421.              try:
  422.                  lemoty = int(tmpb[2][0])
  423.              except:
  424.                  sock.send("onettunel.py - dozwolone wartosci: 2, 1 i 0\r\n")
  425.         except: pass
  426.         sock.send((":fake.host 666 nik : 10[Tunel] ustawienia polaczenia:\r\n"
  427.                    ":fake.host 666 nik : 10[Tunel]  kolor:5     %d\r\n"
  428.                    ":fake.host 666 nik : 10[Tunel]  kodowanie:5 %d\r\n"
  429.                    ":fake.host 666 nik : 10[Tunel]  bold:5      %d\r\n"
  430.                    ":fake.host 666 nik : 10[Tunel]  emoty:5     %d\r\n")%(lkolor,lkodowanie,lbold,lemoty))
  431.      elif tmpb[0] == "LIST":
  432.       bufor = "SLIST\r\n"
  433.      elif (tmpb[0] == "PROTOCTL"):
  434.       bufor = bufor.replace("NAMESX","ONETNAMESX")
  435.      elif tmpb[0] == "CAM":
  436.       if tmpb[3][:2] == "on":
  437.        cammsg = ":WebcamServ!service@service.onet MODE " + tmpb[2] + " +Cam " + tmpb[1] + "\r\n"
  438.       if tmpb[3][:3] == "off":
  439.        cammsg = ":WebcamServ!service@service.onet MODE " + tmpb[2] + " -Cam " + tmpb[1] + "\r\n"
  440.       if lkodowanie == 1:
  441.        cammsg = cammsg.replace('\xa1', '\xa5')
  442.        cammsg = cammsg.replace('\xb1', '\xb9')
  443.        cammsg = cammsg.replace('\xa6', '\x8c')
  444.        cammsg = cammsg.replace('\xb6', '\x9c')
  445.        cammsg = cammsg.replace('\xac', '\x8f')
  446.        cammsg = cammsg.replace('\xbc', '\x9f')
  447.       if lkodowanie == 2:
  448.        cammsg = cammsg.replace("\xa1", "\xc4\x84")
  449.        cammsg = cammsg.replace("\xc6", "\xc4\x86")
  450.        cammsg = cammsg.replace("\xca", "\xc4\x98")
  451.        cammsg = cammsg.replace("\xa3", "\xc5\x81")
  452.        cammsg = cammsg.replace("\xd1", "\xc5\x83")
  453.        cammsg = cammsg.replace("\xd3", "\xc3\x93")
  454.        cammsg = cammsg.replace("\xa6", "\xc5\x9a")
  455.        cammsg = cammsg.replace("\xac", "\xc5\xb9")
  456.        cammsg = cammsg.replace("\xaf", "\xc5\xbb")
  457.        cammsg = cammsg.replace("\xb1", "\xc4\x85")
  458.        cammsg = cammsg.replace("\xe6", "\xc4\x87")
  459.        cammsg = cammsg.replace("\xea", "\xc4\x99")
  460.        cammsg = cammsg.replace("\xb3", "\xc5\x82")
  461.        cammsg = cammsg.replace("\xf1", "\xc5\x84")
  462.        cammsg = cammsg.replace("\xf3", "\xc3\xb3")
  463.        cammsg = cammsg.replace("\xb6", "\xc5\x9b")
  464.        cammsg = cammsg.replace("\xbc", "\xc5\xba")
  465.        cammsg = cammsg.replace("\xbf", "\xc5\xbc")
  466.       sock.send(cammsg)
  467.      onet.send(bufor)
  468.     except:
  469.      dawaj_date()
  470.      print "[%3d] nick: %s = blad odczytu/zapisu z/do gniazda" % (ID, nickname)
  471.      koniec = 1
  472.      break
  473.    if gotowe == onet:
  474.     bufor=""
  475.     try:
  476.      while 1:
  477.          bu2 = gotowe.recv(1024)
  478.          if bu2 == "":
  479.              koniec = 1
  480.              break
  481.          if bu2[len(bu2) - 1] == '\n':
  482.              bufor += bu2
  483.              break
  484.          bufor += bu2
  485.      tab = findall("(.*?\n)", bufor)
  486.      for linia in tab:
  487.       if lkodowanie == 1:
  488.        linia = linia.replace('\xa1', '\xa5')
  489.        linia = linia.replace('\xb1', '\xb9')
  490.        linia = linia.replace('\xa6', '\x8c')
  491.        linia = linia.replace('\xb6', '\x9c')
  492.        linia = linia.replace('\xac', '\x8f')
  493.        linia = linia.replace('\xbc', '\x9f')
  494.       if lkodowanie == 2:
  495.        linia = linia.replace("\xa1", "\xc4\x84")
  496.        linia = linia.replace("\xc6", "\xc4\x86")
  497.        linia = linia.replace("\xca", "\xc4\x98")
  498.        linia = linia.replace("\xa3", "\xc5\x81")
  499.        linia = linia.replace("\xd1", "\xc5\x83")
  500.        linia = linia.replace("\xd3", "\xc3\x93")
  501.        linia = linia.replace("\xa6", "\xc5\x9a")
  502.        linia = linia.replace("\xac", "\xc5\xb9")
  503.        linia = linia.replace("\xaf", "\xc5\xbb")
  504.        linia = linia.replace("\xb1", "\xc4\x85")
  505.        linia = linia.replace("\xe6", "\xc4\x87")
  506.        linia = linia.replace("\xea", "\xc4\x99")
  507.        linia = linia.replace("\xb3", "\xc5\x82")
  508.        linia = linia.replace("\xf1", "\xc5\x84")
  509.        linia = linia.replace("\xf3", "\xc3\xb3")
  510.        linia = linia.replace("\xb6", "\xc5\x9b")
  511.        linia = linia.replace("\xbc", "\xc5\xba")
  512.        linia = linia.replace("\xbf", "\xc5\xbc")
  513.       if lkolor == 1:
  514.        linia = linia.replace("%C959595%", '\x03' + "14")
  515.        linia = linia.replace("%C990033%", '\x03' + "05")
  516.        linia = linia.replace("%Cc86c00%", '\x03' + "07")
  517.        linia = linia.replace("%C623c00%", '\x03' + "05")
  518.        linia = linia.replace("%Cce00ff%", '\x03' + "13")
  519.        linia = linia.replace("%Ce40f0f%", '\x03' + "04")
  520.        linia = linia.replace("%C3030ce%", '\x03' + "12")
  521.        linia = linia.replace("%C008100%", '\x03' + "03")
  522.        linia = linia.replace("%C1a866e%", '\x03' + "10")
  523.        linia = linia.replace("%C006699%", '\x03' + "11")
  524.        linia = linia.replace("%C8800ab%", '\x03' + "06")
  525.        linia = linia.replace("%C0f2ab1%", '\x03' + "02")
  526.        linia = linia.replace("%Cff6500%", '\x03' + "07")
  527.        linia = linia.replace("%Cff0000%", '\x03' + "04")
  528.       if lbold == 1:
  529.        linia = sub("%Fb.*?%", '\x02', linia)
  530.       linia = sub("%C[a-fA-F0-9]{6}%", '', linia)
  531.       linia = linia.replace("%C%", '')
  532.       linia = sub("%F.?.?:[a-z]+%", '', linia)
  533.       linia = sub("%F[bi]{0,2}%", '', linia)
  534.       if lemoty == 1:
  535.        tmpb=linia.split(' ')
  536.        if tmpb[1] != "353":
  537.         b = findall("(%I(.+?)%)", linia)
  538.         for c in b:
  539.          linia = linia.replace(c[0], "<" + c[1] + ">")
  540.       elif lemoty == 2:
  541.        tmpb=linia.split(' ')
  542.        if tmpb[1] != "353":
  543.         b = findall("(%I(.+?)%)", linia)
  544.         for c in b:
  545.          linia = linia.replace(c[0], "//" + c[1])
  546.       try:
  547.        tmpb=linia.split(' ')
  548.        if tmpb[1]=="PRIVMSG":
  549.            if tmpb[2][0]=='^':
  550.                tmpb[2]=tmpb[2].replace('^','#^')
  551.                linia=' '.join(tmpb)
  552.  
  553.        elif tmpb[1] == "MODERMSG":
  554.             linia = "%s PRIVMSG %s :MODERMSG %s: %s" % (tmpb[0], tmpb[4], tmpb[2], ' '.join(tmpb[5:])[1:])
  555.        elif tmpb[1] == "MODERNOTICE":
  556.             linia = "%s PRIVMSG %s :MODERNOTICE: %s" % (tmpb[0], tmpb[2], ' '.join(tmpb[3:])[1:])
  557.  
  558.  
  559.  
  560.        elif tmpb[1] == "JOIN":
  561.         if tmpb[2][0] == '^':
  562.             linia=linia.replace('^','#^')
  563.         elif tmpb[3][:2] == ':W':
  564.              tmpb[3] = sub(",[0-3]\r\n", '', tmpb[3])
  565.              if tmpb[3][:3] == ":Wr":
  566.                 linia = tmpb[3].replace(":Wrx", tmpb[0] + " " + tmpb[1] + " " + tmpb[2] + "\r\n:WebcamServ!service@service.onet MODE " + tmpb[2] + " +Cam " + tmpb[0][1:].split('!')[0] + "\r\n")
  567.              elif tmpb[3][:4] == ":Wbr":
  568.                 linia = tmpb[3].replace(":Wbrx", tmpb[0] + " " + tmpb[1] + " " + tmpb[2] + "\r\n:WebcamServ!service@service.onet MODE " + tmpb[2] + " +Cam " + tmpb[0][1:].split('!')[0] + "\r\n")
  569.        elif tmpb[1] == "MODE":
  570.         if tmpb[3][:2] == "+W":
  571.          linia = tmpb[0] + " 2010 :CAM " + tmpb[2] + " on\r\n"
  572.         elif tmpb[3][:2] == "-W":
  573.          linia = tmpb[0] + " 2010 :CAM " + tmpb[2] + " off\r\n"
  574.        elif tmpb[1] == "353":
  575.           if tmpb[4][0]=='^':
  576.               tmpb[4]=tmpb[4].replace('^','#^')
  577.               linia=' '.join(tmpb)
  578.           if linia.find('|') != -1:
  579.                   tmpstr=""
  580.                   a1=linia.split(':')
  581.                   a1[2]=a1[2].replace("\r\n","")
  582.                   ta1=a1[2].split(' ')
  583.                   for aa1 in ta1:
  584.                        if aa1 == '': continue
  585.                        xx=aa1.split('|')
  586.                        if (xx[1][:3]=="Wbr") or (xx[1][:2]=="Wr"):
  587.                            tmpstr += '=' + xx[0] + " "
  588.                        else:
  589.                            tmpstr += xx[0] + " "
  590.                   a1[2] = tmpstr
  591.                   linia=':'.join(a1)+"\r\n"
  592.        elif tmpb[1]=="366":
  593.            if tmpb[3][0]=='^':
  594.                tmpb[3]=tmpb[3].replace('^','#^')
  595.                linia=' '.join(tmpb)
  596.        elif tmpb[1]=="341":
  597.            if tmpb[4][0]=='^':
  598.                tmpb[4]=tmpb[4].replace('^','#^')
  599.                linia=' '.join(tmpb)
  600.        elif tmpb[1]=="NOTICE":
  601.            if tmpb[2][0]=='^':
  602.                tmpb[2]=tmpb[2].replace('^','#^')
  603.                linia=' '.join(tmpb)
  604.        elif tmpb[1]=="PART":
  605.            if tmpb[2][0]=='^':
  606.                tmpb[2]=tmpb[2].replace('^','#^')
  607.                linia=' '.join(tmpb)
  608.        elif tmpb[1]=="INVITE":
  609.            if tmpb[3][1]=='^':
  610.                tmpb[3]=tmpb[3].replace('^','#^')
  611.                linia=' '.join(tmpb)
  612.        elif tmpb[1] == "817":
  613.         linia = ":_-_!name@host.org PRIVMSG %s :%s <%s> %s" % (tmpb[3], czas(tmpb[4]), tmpb[5], ' '.join(tmpb[7:]))
  614.        elif tmpb[1] == "819":
  615.         onethost = tmpb[0]
  616.         tab3 = findall("(#.+?):.:(\d+)", linia)
  617.         for room in tab3:
  618.          sock.send("%s 322 %s %s %s :\r\n" % (onethost, nickname, room[0], room[1]))
  619.         linia = ""
  620.        elif tmpb[1] == "820":
  621.         linia = "%s 323 %s :End of LIST\r\n" % (tmpb[0], nickname)
  622.        elif tmpb[1] == "421":
  623.         linia = linia.replace(" MODE :This command has been disabled.", '')
  624.         linia = linia.replace(" SETS :Unknown command", '')
  625.         linia = linia.replace(" CAM :Unknown command", '')
  626.         linia = linia.replace(" UO :Unknown command", '')
  627.        elif tmpb[1] == "005":
  628.         linia = linia.replace(" PREFIX=(qaohXYv)`&@%!=+ ", ' PREFIX=(CqaohXv)=`&@%!+ ')
  629.       except:
  630.        pass
  631.       if linia != "":
  632.        sock.send(linia)
  633.     except:
  634.      dawaj_date()
  635.      print "[%3d] nick: %s = blad odczytu/zapisu z/do gniazda" % (ID, nickname)
  636.      koniec = 1
  637.      break
  638.   if koniec == 1:
  639.    sock.close()
  640.    onet.close()
  641.    break
  642. s = socket(AF_INET, SOCK_STREAM)
  643. try:
  644.  s.bind(('', BindPort))
  645. except:
  646.  dawaj_date()
  647.  print "ERROR: nie mozna zabindowac portu %s, wybierz inny" % BindPort
  648.  s.close()
  649.  sys.exit()
  650. dawaj_date()
  651. if local_ip != '':
  652.  print "server: " + local_ip + ":%d" % BindPort
  653. else:
  654.  print "server: %s:%d" % (gethostbyname(gethostname()), BindPort)
  655. s.listen(5)
  656. cID = 1
  657. while 1:
  658.  c, cinfo = s.accept()
  659.  dawaj_date()
  660.  sys.stdout.write("[%3d] %s:%s = " % ((cID, ) + cinfo))
  661.  start_new_thread(jedziesz, (c, cID, ))
  662.  cID = cID + 1
  663. s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement