Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.81 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. customClines.append('C: fosterbox.no-ip.org 42000 gavazquez fe51d1')
  76.  
  77. #-------------------------
  78.  
  79. return customClines; #No borres esta linea!
  80.  
  81. #--------------------------------------------------------------------------------------------------
  82. #--------------------------------------------------------------------------------------------------
  83. #--------------------------------------------------------------------------------------------------
  84. #--------------------------------------------------------------------------------------------------
  85. #--------------------------------------------------------------------------------------------------
  86. #--------------------------- A partir de aqui ya empieza el codigo del script ---------------------
  87. #------------------------------ No lo cambies a menos que sepas lo que haces! ---------------------
  88. #--------------------------------------------------------------------------------------------------
  89. #--------------------------------------------------------------------------------------------------
  90. #--------------------------------------------------------------------------------------------------
  91. #--------------------------------------------------------------------------------------------------
  92. #--------------------------------------------------------------------------------------------------
  93. #--------------------------------------------------------------------------------------------------
  94.  
  95. #region Constants
  96.  
  97. arguments = ['mycccam','satna','cccam4you','testious','testiousRandom','testiousAll','freecline','all']
  98.  
  99. #endregion
  100.  
  101. #region Methods
  102.  
  103. #region Generic methods
  104.  
  105. def GetHtmlCode(headers, url):
  106. import urllib, urllib2, cookielib
  107.  
  108. cookieJar = cookielib.CookieJar()
  109. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar))
  110. if headers is not None and len(headers) > 0:
  111. opener.addheaders = headers
  112. try:
  113. htmlCode = opener.open(url).read()
  114. except:
  115. print "Could not open website! (No internet connection or bad URL: " + url + ")"
  116. return '';
  117.  
  118. return htmlCode;
  119.  
  120. def WriteCccamFile(clines, append, check):
  121. import os, os.path
  122.  
  123. existingClines = []
  124. clinesToWrite = []
  125.  
  126. if os.path.exists(cccamPath):
  127. with open(cccamPath) as f:
  128. existingClines = f.readlines()
  129.  
  130. if check: #Check and only write the Clines that are tested
  131. for cline in existingClines:
  132. if TestCline(cline) == True:
  133. clinesToWrite.append(cline)
  134. else:
  135. clinesToWrite = existingClines
  136.  
  137. for cline in clines:
  138. if cline is not None and cline != '' and TestCline(cline):
  139. clinesToWrite.append(cline)
  140.  
  141. file = open(cccamPath, 'w')
  142.  
  143. for cline in clinesToWrite:
  144. if check == False or (check == True and TestCline(cline)):
  145. file.write(cline + '\n')
  146. file.close()
  147.  
  148. print "Finished refreshing the file!"
  149.  
  150. def GetRandomClines():
  151. import random
  152. argument = arguments[random.randint(0,len(arguments)-1)]
  153. return GetClinesByArgument(argument)
  154.  
  155. def GetClinesByArgument(argument):
  156. clines = []
  157. clines += GetCustomClines()
  158.  
  159. if argument == arguments[0]:
  160. clines += GetMycccamClines()
  161. elif argument == arguments[1]:
  162. clines += GetSatnaClines()
  163. elif argument == arguments[2]:
  164. clines += GetCccam4youClines()
  165. elif argument == arguments[3]:
  166. clines += GetTestiousClines(False, False)
  167. elif argument == arguments[4]:
  168. clines += GetTestiousClines(True, False)
  169. elif argument == arguments[5]:
  170. clines += GetTestiousClines(True, True)
  171. elif argument == arguments[6]:
  172. clines += GetFreeclineClines() + GetFreeclineNlines()
  173. elif argument == arguments[7]:
  174. clines += GetMycccamClines() + GetSatnaClines() + GetCccam4youClines()
  175. else:
  176. clines += GetMycccamClines() + GetSatnaClines() + GetCccam4youClines()
  177.  
  178. return clines
  179.  
  180. def RestartCccam():
  181. import time, os
  182. os.system('killall ' + os.path.basename(cccamBin))
  183. time.sleep(2)
  184. os.system('rm -rf /tmp/*.info* /tmp/*.tmp*')
  185. os.system(cccamBin + ' &')
  186.  
  187. def TestCline(cline):
  188. import socket, re, sys
  189.  
  190. regExpr = re.compile('[CN]:\s?(\S+)?\s+(\d*)')
  191. match = regExpr.search(cline)
  192.  
  193. if match is None:
  194. return False;
  195.  
  196. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  197.  
  198. try:
  199. host = match.group(1)
  200. port = int(match.group(2))
  201. ip = socket.gethostbyname(host)
  202. s.connect((ip, port))
  203. return True
  204. except:
  205. s.close()
  206. return False
  207.  
  208. return False
  209.  
  210. #endregion
  211.  
  212. #region Mycccam
  213.  
  214. def GetMycccamClines():
  215. print "Now getting Myccam clines!"
  216. myccclineClines = []
  217. myccclineClines.append(GetMycccamCline(1))
  218. myccclineClines.append(GetMycccamCline(2))
  219. myccclineClines.append(GetMycccamCline(3))
  220. myccclineClines.append(GetMycccamCline(4))
  221. myccclineClines.append(GetMycccamCline(5))
  222. myccclineClines.append(GetMycccamCline(6))
  223.  
  224. return myccclineClines;
  225.  
  226. def GetMycccamCline(serverNo):
  227. import re
  228.  
  229. htmlCode = GetHtmlCode(None, "http://www.mycccam24.com/{0}sv2016.php".format(serverNo))
  230. regExpr = re.compile('Your Free CCcam line is.*C:(.*?)<\/')
  231. match = regExpr.search(htmlCode)
  232.  
  233. if match is None:
  234. return None;
  235.  
  236. cline = match.group(1)
  237.  
  238. return 'C:' + cline;
  239.  
  240. #endregion
  241.  
  242. #region Satna
  243.  
  244. def GetSatnaClines():
  245. print "Now getting Satna clines!"
  246. satnaClines = []
  247. satnaClines.append(GetSatnaCline(1))
  248. satnaClines.append(GetSatnaCline(2))
  249. satnaClines.append(GetSatnaCline(3))
  250. satnaClines.append(GetSatnaCline(4))
  251. satnaClines.append(GetSatnaCline(5))
  252. satnaClines.append(GetSatnaCline(6))
  253. return satnaClines;
  254.  
  255. def GetSatnaCline(serverNo):
  256. import re
  257.  
  258. htmlCode = GetHtmlCode(None, "http://satna4ever.no-ip.biz/satna/nwx{0}.php".format(serverNo))
  259. regExpr = re.compile('Your Free CCcam line is.*C:(.*?)<\/')
  260. match = regExpr.search(htmlCode)
  261.  
  262. if match is None:
  263. return None;
  264.  
  265. cline = match.group(1)
  266.  
  267. return 'C:' + cline;
  268.  
  269. #endregion
  270.  
  271. #region Cccam4you
  272.  
  273. def GetCccam4youClines():
  274. print "Now getting Cccam4you clines!"
  275. cccam4youClines = []
  276. cccam4youClines.append(GetCccam4youCline())
  277. return cccam4youClines;
  278.  
  279. def GetCccam4youCline():
  280. import re
  281.  
  282. htmlCode = GetHtmlCode(None, "http://cccam4you.com/FREE/get.php")
  283. regExpr = re.compile('C:(.*)\r')
  284. match = regExpr.search(htmlCode)
  285.  
  286. if match is None:
  287. return None;
  288.  
  289. cline = match.group(1)
  290.  
  291. return 'C:' + cline;
  292.  
  293. #endregion
  294.  
  295. #region Testious
  296.  
  297. def GetTestiousClines(getRandomLines, getAllLines):
  298. import re, time, datetime, random
  299. print "Now getting Testious clines!"
  300. clines = []
  301.  
  302. 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')]
  303. url = "http://www.testious.com/free-cccam-servers/" + datetime.date.today().strftime("%Y-%m-%d")
  304. htmlCode = GetHtmlCode(header, url)
  305.  
  306. regExpr = re.compile('([C]:.*?)#.*\n<br>')
  307. matches = regExpr.findall(htmlCode)
  308.  
  309. if len(matches) < 5:
  310. yesterday = datetime.date.today() - datetime.timedelta( days = 1 )
  311. url = "http://www.testious.com/free-cccam-servers/" + yesterday.strftime("%Y-%m-%d")
  312. htmlCode = GetHtmlCode(header, url)
  313. matches = regExpr.findall(htmlCode)
  314.  
  315. if (getAllLines): #get all lines
  316. return matches;
  317.  
  318. if len(matches) > 10:
  319. for i in range(0, 10):
  320. if (getRandomLines): #get 10 random lines
  321. clines.append(matches[random.randint(0,len(matches)-1)])
  322. else: #get first 10 lines
  323. clines.append(matches[i])
  324. else:
  325. return matches;
  326.  
  327. return clines;
  328.  
  329. #endregion
  330.  
  331. #region Freecline
  332.  
  333. def GetFreeclineClines():
  334. import re, time, datetime, random
  335. print "Now getting Freecline clines!"
  336. clines = []
  337.  
  338. 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')]
  339. url = "http://www.freecline.com/history/CCcam/" + datetime.date.today().strftime("%Y/%m/%d")
  340. htmlCode = GetHtmlCode(header, url)
  341.  
  342. regExpr = re.compile('Detailed information of the line.*([C]:.*?)<.*\n.*\n.*\n.*\n.*online')
  343. matches = regExpr.findall(htmlCode)
  344.  
  345. if len(matches) < 1:
  346. yesterday = datetime.date.today() - datetime.timedelta( days = 1 )
  347. url = "http://www.freecline.com/history/CCcam/" + yesterday.strftime("%Y/%m/%d")
  348. htmlCode = GetHtmlCode(header, url)
  349. matches = regExpr.findall(htmlCode)
  350.  
  351. if len(matches) > 10:
  352. for i in range(0, 10):
  353. if (getRandomLines): #get 10 random lines
  354. clines.append(matches[random.randint(0,len(matches)-1)])
  355. else: #get first 10 lines
  356. clines.append(matches[i])
  357. else:
  358. return matches;
  359.  
  360. return clines;
  361.  
  362. def GetFreeclineNlines():
  363. import re, time, datetime, random
  364. nlines = []
  365.  
  366. 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')]
  367. url = "http://www.freecline.com/history/Newcamd/" + datetime.date.today().strftime("%Y/%m/%d")
  368. htmlCode = GetHtmlCode(header, url)
  369.  
  370. regExpr = re.compile('Detailed information of the line.*([N]:.*?)<.*\n.*\n.*\n.*\n.*online')
  371. matches = regExpr.findall(htmlCode)
  372.  
  373. if len(matches) < 1:
  374. yesterday = datetime.date.today() - datetime.timedelta( days = 1 )
  375. url = "http://www.freecline.com/history/Newcamd/" + yesterday.strftime("%Y/%m/%d")
  376. htmlCode = GetHtmlCode(header, url)
  377. matches = regExpr.findall(htmlCode)
  378.  
  379. if len(matches) > 10:
  380. for i in range(0, 10):
  381. if (getRandomLines): #get 10 random lines
  382. nlines.append(matches[random.randint(0,len(matches)-1)])
  383. else: #get first 10 lines
  384. nlines.append(matches[i])
  385. else:
  386. return matches;
  387.  
  388. return nlines;
  389.  
  390. #endregion
  391.  
  392. #region Main
  393.  
  394. def main():
  395. import sys, os
  396. clines = []
  397. append = False
  398. check = False
  399.  
  400. if len(sys.argv) > 1:
  401. print "ReloadCam called with " + sys.argv[1] + " argument!"
  402. clines = GetClinesByArgument(sys.argv[1])
  403. else:
  404. print "Now retrieving all cclines!"
  405. clines = GetClinesByArgument('all')
  406.  
  407. if len(sys.argv) > 2:
  408. append = sys.argv[1] == "append" or sys.argv[2] == "append"
  409. check = sys.argv[1] == "check" or sys.argv[2] == "check"
  410. if len(sys.argv) > 3:
  411. check = sys.argv[1] == "check" or sys.argv[2] == "check" or sys.argv[3] == "check"
  412. append = sys.argv[1] == "append" or sys.argv[2] == "append" or sys.argv[3] == "append"
  413.  
  414. if len(clines) > 0:
  415. print "Now writing to the cccam.cfg!"
  416. WriteCccamFile(clines, append, check)
  417. print "Now restarting cam!"
  418. RestartCccam()
  419. print "Finished restarting cam!"
  420. else :
  421. print "NO CCCAMS LOADED!"
  422. return;
  423.  
  424. #endregion
  425.  
  426. if __name__ == "__main__":
  427. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement