Advertisement
Guest User

Untitled

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