Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.83 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. #Refrescador automatico de clines
  5. #Creado por Dagger
  6.  
  7. #Para usarlo:
  8. #1 - Crea un archivo llamado "ReloadCam.py" (La extension debe ser .py!) con algun editor de texto
  9. #2 - Pega todo este texto en ese fichero y guardalo
  10. #3 - Lee todo este texto hasta abajo y haz las correcciones que se indiquen en caso de que sea necesario
  11. #4 - Create otro fichero llamado "RefrescarCcam.sh" (La extension debe ser .sh!) con algun editor de texto
  12. #5 - Desde ese .sh sera desde donde llames al ReloadCam.py, para ello, puedes llamarlo con los estos parametros
  13.  
  14. #python 'ReloadCam.py' mycccam Refresca el CCcam.cfg con lineas de la web de mycccam
  15. #python 'ReloadCam.py' satna Refresca el CCcam.cfg con lineas de la web de satna
  16. #python 'ReloadCam.py' cccam4you Refresca el CCcam.cfg con lineas de la web de cccam4you
  17. #python 'ReloadCam.py' testious Refresca el CCcam.cfg con las 5 primeras lineas de la web de testious
  18. #python 'ReloadCam.py' testiousRandom Refresca el CCcam.cfg con lineas AL AZAR de la web de testious
  19. #python 'ReloadCam.py' testiousAll Refresca el CCcam.cfg con TODAS las lineas de la web de testious
  20. #python 'ReloadCam.py' freecline Refresca el CCcam.cfg con las lineas validas de la web de freecline
  21. #python 'ReloadCam.py' all Refresca el CCcam.cfg con lineas de todas las web (excepto testious y freecline)
  22. #python 'ReloadCam.py' Refresca el CCcam.cfg con lineas de todas las web (excepto testious y freecline)
  23.  
  24. #Tu archivo RefrescarCcam.sh deberia quedar con una sola linea
  25. #Ejemplo: ------> python 'ReloadCam.py' all
  26.  
  27. #6 - Sube esos 2 ficheros a /usr/script/ con permisos 755
  28. #7 - Desde el panel de scripts puedes llamarlo o configurarlo para que se ejecute cada X horas en el cron manager.
  29.  
  30. #-------------------------
  31. #CONSIDERACIONES ADICIONALES
  32. #-------------------------
  33.  
  34. #Si añades el parametro 'append' al final, las lineas nuevas solo se añadiran abajo
  35. #del archivo CCCam.cfg sin borrarlo antes.
  36.  
  37. #Ejemplo:
  38. #ReloadCam.py cccam4you append
  39.  
  40. #Con esta llamada tu CCCam.cfg quedaria con las lineas antiguas arriba y las nuevas abajo
  41.  
  42. #Si ademas le añades el parametro 'check' se abrira el archivo y borrara las lineas que no esten funcionando
  43. #para luego meter las nuevas lineas debajo
  44.  
  45. #Ejemplo:
  46. #ReloadCam.py cccam4you append check
  47.  
  48. #-------------------------
  49.  
  50. #Si quieres poner tus Clines propias, añadelas al metodo GetCustomClines() Tal y como se indica
  51.  
  52. #-------------------------
  53.  
  54. #En un futuro seria interesante añadir los 2 servidores de abajo, aunque para eso hay que abrir un zip y leerlas...
  55. #http://free-cccam.tk/MultiUser/cline.php?f=cline/CCcam.zip
  56. #http://free-cccam.tk/MultiUser2/cline.php?f=cline/CCcam.zip
  57.  
  58. #-------------------------
  59.  
  60. cccamPath = "/etc/CCcam.cfg" #Cambia esta ruta entre comillas en caso necesario pero no la borres!!
  61. cccamBin = "/usr/bin/CCcam_230" #Cambia esta ruta entre comillas en caso necesario pero no la borres!!
  62.  
  63. def GetCustomClines(): #No borres esta linea!
  64. customClines = [] #No borres esta linea!
  65.  
  66. #-------------------------
  67.  
  68. #Añade aqui una o mas custom clines si quieres (puede ser una cline privada o similar)
  69. #Ejemplos: (Recuerda borrar el '#')
  70.  
  71. #customClines.append('C: micline.no-ip.org 42000 user pass')
  72. #customClines.append('C: micline2.no-ip.org 42000 user2 pass2')
  73. #customClines.append('C: micline3.no-ip.org 42000 user3 pass3')
  74. #customClines.append('N: miNline1.no-ip.org 42000 user1 pass1')
  75.  
  76. #-------------------------
  77.  
  78. return customClines; #No borres esta linea!
  79.  
  80. #--------------------------------------------------------------------------------------------------
  81. #--------------------------------------------------------------------------------------------------
  82. #--------------------------------------------------------------------------------------------------
  83. #--------------------------------------------------------------------------------------------------
  84. #--------------------------------------------------------------------------------------------------
  85. #--------------------------- A partir de aqui ya empieza el codigo del script ---------------------
  86. #------------------------------ No lo cambies a menos que sepas lo que haces! ---------------------
  87. #--------------------------------------------------------------------------------------------------
  88. #--------------------------------------------------------------------------------------------------
  89. #--------------------------------------------------------------------------------------------------
  90. #--------------------------------------------------------------------------------------------------
  91. #--------------------------------------------------------------------------------------------------
  92. #--------------------------------------------------------------------------------------------------
  93.  
  94. #region Constants
  95.  
  96. arguments = ['mycccam','satna','cccam4you','testious','testiousRandom','testiousAll','freecline','all']
  97.  
  98. #endregion
  99.  
  100. #region Methods
  101.  
  102. #region Generic methods
  103.  
  104. def GetHtmlCode(headers, url):
  105. import urllib, urllib2, cookielib
  106.  
  107. cookieJar = cookielib.CookieJar()
  108. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar))
  109. if headers is not None and len(headers) > 0:
  110. opener.addheaders = headers
  111. try:
  112. htmlCode = opener.open(url).read()
  113. except:
  114. print "Could not open website! (No internet connection or bad URL: " + url + ")"
  115. return '';
  116.  
  117. return htmlCode;
  118.  
  119. def WriteCccamFile(clines, append, check):
  120. import os, os.path
  121.  
  122. existingClines = []
  123. clinesToWrite = []
  124.  
  125. if os.path.exists(cccamPath):
  126. with open(cccamPath) as f:
  127. existingClines = f.readlines()
  128.  
  129. if check: #Check and only write the Clines that are tested
  130. for cline in existingClines:
  131. if TestCline(cline) == True:
  132. clinesToWrite.append(cline)
  133. else:
  134. clinesToWrite = existingClines
  135.  
  136. for cline in clines:
  137. if cline is not None and cline != '' and TestCline(cline):
  138. clinesToWrite.append(cline)
  139.  
  140. file = open(cccamPath, 'w')
  141.  
  142. for cline in clinesToWrite:
  143. if check == False or (check == True and TestCline(cline)):
  144. file.write(cline + '\n')
  145. file.close()
  146.  
  147. print "Finished refreshing the file!"
  148.  
  149. def GetRandomClines():
  150. import random
  151. argument = arguments[random.randint(0,len(arguments)-1)]
  152. return GetClinesByArgument(argument)
  153.  
  154. def GetClinesByArgument(argument):
  155. clines = []
  156. clines += GetCustomClines()
  157.  
  158. if argument == arguments[0]:
  159. clines += GetMycccamClines()
  160. elif argument == arguments[1]:
  161. clines += GetSatnaClines()
  162. elif argument == arguments[2]:
  163. clines += GetCccam4youClines()
  164. elif argument == arguments[3]:
  165. clines += GetTestiousClines(False, False)
  166. elif argument == arguments[4]:
  167. clines += GetTestiousClines(True, False)
  168. elif argument == arguments[5]:
  169. clines += GetTestiousClines(True, True)
  170. elif argument == arguments[6]:
  171. clines += GetFreeclineClines() + GetFreeclineNlines()
  172. elif argument == arguments[7]:
  173. clines += GetMycccamClines() + GetSatnaClines() + GetCccam4youClines()
  174. else:
  175. clines += GetMycccamClines() + GetSatnaClines() + GetCccam4youClines()
  176.  
  177. return clines
  178.  
  179. def RestartCccam():
  180. import time, os
  181. os.system('killall ' + os.path.basename(cccamBin))
  182. time.sleep(2)
  183. os.system('rm -rf /tmp/*.info* /tmp/*.tmp*')
  184. os.system(cccamBin + ' &')
  185.  
  186. def TestCline(cline):
  187. import socket, re, sys
  188.  
  189. regExpr = re.compile('[CN]:\s?(\S+)?\s+(\d*)')
  190. match = regExpr.search(cline)
  191.  
  192. if match is None:
  193. return False;
  194.  
  195. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  196.  
  197. try:
  198. host = match.group(1)
  199. port = int(match.group(2))
  200. ip = socket.gethostbyname(host)
  201. s.connect((ip, port))
  202. return True
  203. except:
  204. s.close()
  205. return False
  206.  
  207. return False
  208.  
  209. #endregion
  210.  
  211. #region Mycccam
  212.  
  213. def GetMycccamClines():
  214. print "Now getting Myccam clines!"
  215. myccclineClines = []
  216. myccclineClines.append(GetMycccamCline(1))
  217. myccclineClines.append(GetMycccamCline(2))
  218. myccclineClines.append(GetMycccamCline(3))
  219. myccclineClines.append(GetMycccamCline(4))
  220. myccclineClines.append(GetMycccamCline(5))
  221. myccclineClines.append(GetMycccamCline(6))
  222.  
  223. return myccclineClines;
  224.  
  225. def GetMycccamCline(serverNo):
  226. import re
  227.  
  228. htmlCode = GetHtmlCode(None, "http://www.mycccam24.com/{0}sv2016.php".format(serverNo))
  229. regExpr = re.compile('Your Free CCcam line is.*C:(.*?)<\/')
  230. match = regExpr.search(htmlCode)
  231.  
  232. if match is None:
  233. return None;
  234.  
  235. cline = match.group(1)
  236.  
  237. return 'C:' + cline;
  238.  
  239. #endregion
  240.  
  241. #region Satna
  242.  
  243. def GetSatnaClines():
  244. print "Now getting Satna clines!"
  245. satnaClines = []
  246. satnaClines.append(GetSatnaCline(1))
  247. satnaClines.append(GetSatnaCline(2))
  248. satnaClines.append(GetSatnaCline(3))
  249. satnaClines.append(GetSatnaCline(4))
  250. satnaClines.append(GetSatnaCline(5))
  251. satnaClines.append(GetSatnaCline(6))
  252. return satnaClines;
  253.  
  254. def GetSatnaCline(serverNo):
  255. import re
  256.  
  257. htmlCode = GetHtmlCode(None, "http://satna4ever.no-ip.biz/satna/nwx{0}.php".format(serverNo))
  258. regExpr = re.compile('Your Free CCcam line is.*C:(.*?)<\/')
  259. match = regExpr.search(htmlCode)
  260.  
  261. if match is None:
  262. return None;
  263.  
  264. cline = match.group(1)
  265.  
  266. return 'C:' + cline;
  267.  
  268. #endregion
  269.  
  270. #region Cccam4you
  271.  
  272. def GetCccam4youClines():
  273. print "Now getting Cccam4you clines!"
  274. cccam4youClines = []
  275. cccam4youClines.append(GetCccam4youCline())
  276. return cccam4youClines;
  277.  
  278. def GetCccam4youCline():
  279. import re
  280.  
  281. htmlCode = GetHtmlCode(None, "http://cccam4you.com/FREE/get.php")
  282. regExpr = re.compile('C:(.*)\r')
  283. match = regExpr.search(htmlCode)
  284.  
  285. if match is None:
  286. return None;
  287.  
  288. cline = match.group(1)
  289.  
  290. return 'C:' + cline;
  291.  
  292. #endregion
  293.  
  294. #region Testious
  295.  
  296. def GetTestiousClines(getRandomLines, getAllLines):
  297. import re, time, datetime, random
  298. print "Now getting Testious clines!"
  299. clines = []
  300.  
  301. header = [('User-agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36')]
  302. url = "http://www.testious.com/free-cccam-servers/" + datetime.date.today().strftime("%Y-%m-%d")
  303. htmlCode = GetHtmlCode(header, url)
  304.  
  305. regExpr = re.compile('([C]:.*?)#.*\n<br>')
  306. matches = regExpr.findall(htmlCode)
  307.  
  308. if len(matches) < 5:
  309. yesterday = datetime.date.today() - datetime.timedelta( days = 1 )
  310. url = "http://www.testious.com/free-cccam-servers/" + yesterday.strftime("%Y-%m-%d")
  311. htmlCode = GetHtmlCode(header, url)
  312. matches = regExpr.findall(htmlCode)
  313.  
  314. if (getAllLines): #get all lines
  315. return matches;
  316.  
  317. if len(matches) > 10:
  318. for i in range(0, 10):
  319. if (getRandomLines): #get 10 random lines
  320. clines.append(matches[random.randint(0,len(matches)-1)])
  321. else: #get first 10 lines
  322. clines.append(matches[i])
  323. else:
  324. return matches;
  325.  
  326. return clines;
  327.  
  328. #endregion
  329.  
  330. #region Freecline
  331.  
  332. def GetFreeclineClines():
  333. import re, time, datetime, random
  334. print "Now getting Freecline clines!"
  335. clines = []
  336.  
  337. header = [('User-agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36')]
  338. url = "http://www.freecline.com/history/CCcam/" + datetime.date.today().strftime("%Y/%m/%d")
  339. htmlCode = GetHtmlCode(header, url)
  340.  
  341. regExpr = re.compile('Detailed information of the line.*([C]:.*?)<.*\n.*\n.*\n.*\n.*online')
  342. matches = regExpr.findall(htmlCode)
  343.  
  344. if len(matches) < 1:
  345. yesterday = datetime.date.today() - datetime.timedelta( days = 1 )
  346. url = "http://www.freecline.com/history/CCcam/" + yesterday.strftime("%Y/%m/%d")
  347. htmlCode = GetHtmlCode(header, url)
  348. matches = regExpr.findall(htmlCode)
  349.  
  350. if len(matches) > 10:
  351. for i in range(0, 10):
  352. if (getRandomLines): #get 10 random lines
  353. clines.append(matches[random.randint(0,len(matches)-1)])
  354. else: #get first 10 lines
  355. clines.append(matches[i])
  356. else:
  357. return matches;
  358.  
  359. return clines;
  360.  
  361. def GetFreeclineNlines():
  362. import re, time, datetime, random
  363. nlines = []
  364.  
  365. header = [('User-agent', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36')]
  366. url = "http://www.freecline.com/history/Newcamd/" + datetime.date.today().strftime("%Y/%m/%d")
  367. htmlCode = GetHtmlCode(header, url)
  368.  
  369. regExpr = re.compile('Detailed information of the line.*([N]:.*?)<.*\n.*\n.*\n.*\n.*online')
  370. matches = regExpr.findall(htmlCode)
  371.  
  372. if len(matches) < 1:
  373. yesterday = datetime.date.today() - datetime.timedelta( days = 1 )
  374. url = "http://www.freecline.com/history/Newcamd/" + yesterday.strftime("%Y/%m/%d")
  375. htmlCode = GetHtmlCode(header, url)
  376. matches = regExpr.findall(htmlCode)
  377.  
  378. if len(matches) > 10:
  379. for i in range(0, 10):
  380. if (getRandomLines): #get 10 random lines
  381. nlines.append(matches[random.randint(0,len(matches)-1)])
  382. else: #get first 10 lines
  383. nlines.append(matches[i])
  384. else:
  385. return matches;
  386.  
  387. return nlines;
  388.  
  389. #endregion
  390.  
  391. #region Main
  392.  
  393. def main():
  394. import sys, os
  395. clines = []
  396. append = False
  397. check = False
  398.  
  399. if len(sys.argv) > 1:
  400. print "ReloadCam called with " + sys.argv[1] + " argument!"
  401. clines = GetClinesByArgument(sys.argv[1])
  402. else:
  403. print "Now retrieving all cclines!"
  404. clines = GetClinesByArgument('all')
  405.  
  406. if len(sys.argv) > 2:
  407. append = sys.argv[1] == "append" or sys.argv[2] == "append"
  408. check = sys.argv[1] == "check" or sys.argv[2] == "check"
  409. if len(sys.argv) > 3:
  410. check = sys.argv[1] == "check" or sys.argv[2] == "check" or sys.argv[3] == "check"
  411. append = sys.argv[1] == "append" or sys.argv[2] == "append" or sys.argv[3] == "append"
  412.  
  413. if len(clines) > 0:
  414. print "Now writing to the cccam.cfg!"
  415. WriteCccamFile(clines, append, check)
  416. print "Now restarting cam!"
  417. RestartCccam()
  418. print "Finished restarting cam!"
  419. else :
  420. print "NO CCCAMS LOADED!"
  421. return;
  422.  
  423. #endregion
  424.  
  425. if __name__ == "__main__":
  426. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement