Guest User

Untitled

a guest
Feb 2nd, 2024
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.86 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. Auteur : warkx
  5. Version originale Developpé le : 23/11/2013
  6. Version : 3.2.6 (modifié par zmog)
  7. Développé le : 07/07/2019
  8. Description : Support du compte gratuit, access, premium et CDN
  9.  
  10. Packaging by => tar zcf "OneFichierCom_X.host" INFO OneFichierCom.php
  11. Update :
  12. - 2024-02-02 : Ajout d'un test pour verifier que le compte est premium.
  13. */
  14.  
  15. class SynoFileHosting
  16. {
  17. private $Url;
  18. private $HostInfo;
  19. private $Username;
  20. private $Password;
  21. private $FILEID;
  22. private $ORIGINAL_URL;
  23. private $ACCOUNT_TYPE;
  24. private $ADZONE_NAME = 'adz';
  25. private $ADZONE_VALUE = '';
  26.  
  27. private $ENABLE_DEBUG = TRUE;
  28. private $ENABLE_DEBUG_HTML = FALSE;
  29. private $ENABLE_DEBUGCURL_VERBOSE = FALSE;
  30. private $LOG_DIR = '/tmp/';
  31. private $LOG_DIR_HTML = '1fichier_log/';
  32. private $LOG_FILE = '1fichier.log';
  33. private $LOG_FILE_WINNT = 'C:\intel\1fichier.log';
  34.  
  35. private $COOKIE_PATH = '/tmp/1fichier.cookie';
  36. private $COOKIE_PATH_WINNT = 'C:\intel\1fichier.cookie';
  37.  
  38. private $CHECKLINK_URL_REQ = 'https://1fichier.com/check_links.pl';
  39.  
  40. private $FILEID_REGEX = '`https?:\/\/1fichier\.com\/\?([a-zA-Z0-9]+)\/?`i';
  41. private $FILEID_OLD_REGEX = '`https?:\/\/([a-z0-9A-Z]+)\.1fichier\.com\/?`i';
  42. private $FILE_OFFLINE_REGEX = '`BAD LINK|NOT FOUND`i';
  43. private $DOWNLOAD_WAIT_REGEX = '`You must wait (\d+) minutes`i';
  44. private $PREMIUM_REAL_URL_REGEX = '`https?:\/\/[a-z0-9]+-[a-z0-9]+\.1fichier\.com\/[a-z0-9]+`i';
  45. private $FREE_REAL_URL_REGEX = '`href=\"(https?:\/\/[a-z0-9]+-[a-z0-9]+\.1fichier\.com\/[a-z0-9]+)\"?`i';
  46. private $DEBUG_REGEX = '/(https?:\/\/1fichier\.com\/.+)\/debug/i';
  47. // private $ADZONE_REGEX = '`name="adzone" value="(.+?)"`i';
  48. private $ADZONE_REGEX = '/name="adz" value="([0-9A-z.]*)"/'; /*new REGEX by Babasss*/
  49.  
  50. private $PREMIUM_TYPE_REGEX = '`(^[0-9]{2}+)`i';
  51.  
  52. private $WAITING_TIME_DEFAULT = 300;
  53. private $QUERYAGAIN = 1;
  54.  
  55. private $MIN_CDN_GB = 5;
  56. private $CDN_FR_REGEX='`Votre compte a ([0-9.]+) Go`i';
  57. private $CDN_EN_REGEX='`Your account have ([0-9.]+) GB`i';
  58. private $CDN_CHECKBOX_REGEX='<input type="checkbox" checked="checked" name="own_credit">';
  59.  
  60. public function __construct($Url, $Username, $Password, $HostInfo)
  61. {
  62. $this->DebugMessage("\n");
  63. $this->DebugMessage("DEBUG construct function");
  64.  
  65. $this->Url = $Url;
  66. $this->Username = $Username;
  67. $this->Password = $Password;
  68. $this->HostInfo = $HostInfo;
  69.  
  70. //verifie si le debug est activé avec un "/debug"
  71. preg_match($this->DEBUG_REGEX, $Url, $debugmatch);
  72. if(!empty($debugmatch[1]))
  73. {
  74. $this->Url = $debugmatch[1];
  75. $this->ENABLE_DEBUG = TRUE;
  76. }else
  77. {
  78. $this->Url = $Url;
  79. }
  80. }
  81.  
  82. //fonction a executer pour recuperer les informations d'un fichier en fonction d'un lien
  83. public function GetDownloadInfo()
  84. {
  85. $this->DebugMessage("DEBUG GetDownloadInfo function");
  86.  
  87. $ret = false;
  88.  
  89. //verifie le type de compte
  90. $this->ACCOUNT_TYPE = $this->Verify(false);
  91.  
  92. //Recupere l'id, s'il nest pas bon, renvoie NON PRIS EN CHARGE
  93. $GetFILEIDRet = $this->GetFILEID($this->Url);
  94. if ($GetFILEIDRet == false)
  95. {
  96. $ret[DOWNLOAD_ERROR] = ERR_NOT_SUPPORT_TYPE;
  97. }else
  98. {
  99. //Créé l'url en fonction du type de compte
  100. $this->MakeUrl();
  101.  
  102. /*verifie si le lien est valide, si c'est le cas
  103. le nom du fichier est récupéré, sinon c'est false
  104. */
  105.  
  106. $LinkInfo = $this->CheckLink($this->ORIGINAL_URL);
  107.  
  108. $this->DebugMessage("DEBUG Original URL LinkInfo", $this->ORIGINAL_URL);
  109. $this->DebugMessage("DEBUG GetDownloadInfo LinkInfo", $this->coalesce_string($LinkInfo));
  110.  
  111. //Renvoie que le fichier n'existe pas si le lien est obsolète
  112. if($LinkInfo == false)
  113. {
  114. $ret[DOWNLOAD_ERROR] = ERR_FILE_NO_EXIST;
  115. }else
  116. {
  117. //en fonction du type de compte, lance la fonction correspondante
  118. if($this->ACCOUNT_TYPE == USER_IS_PREMIUM)
  119. {
  120. $ret = $this->DownloadPremium();
  121. }else
  122. {
  123. $ret = $this->DownloadWaiting();
  124. }
  125.  
  126. //$ret[ACCOUNT_TYPE] = $this->ACCOUNT_TYPE;
  127.  
  128. /*Si les fonctions précedentes ont retourné un tableau avec des informations,
  129. on y ajoute le nom du fichier aisi que les INFO_NAME (permet de mettre play/pause).
  130. si aucun info n'a été retourné on renvoie fichier inexistant
  131. */
  132. if($ret != false)
  133. {
  134. #### Quand on un fichier en mode private, on arrive pas à récupérer son nom, ici on corrige si en Premium, on obtient un nom de fichier
  135. if ( isset($ret[INFO_NAME])) { $ret[DOWNLOAD_FILENAME] = $ret[INFO_NAME]; } else { $ret[DOWNLOAD_FILENAME] = $LinkInfo; }
  136. $ret[INFO_NAME] = trim($this->HostInfo[INFO_NAME]);
  137. }else
  138. {
  139. $ret[DOWNLOAD_ERROR] = ERR_FILE_NO_EXIST;
  140. }
  141. }
  142. }
  143.  
  144. // if (empty($ret[DOWNLOAD_FILENAME])) { $ret_dl = 'File not exists'; } else { $ret_dl = $ret[DOWNLOAD_FILENAME]; }
  145.  
  146. $this->DebugMessage("DEBUG GetDownloadInfo DownloadName", $this->coalesce_string($ret[DOWNLOAD_FILENAME], 'File not exists'));
  147.  
  148. return $ret;
  149. }
  150.  
  151. //verifie le type de compte entré
  152. public function Verify($ClearCookie)
  153. {
  154. $this->DebugMessage("DEBUG Verify function");
  155.  
  156. $ret = LOGIN_FAIL;
  157.  
  158. if(!empty($this->Username) && !empty($this->Password))
  159. {
  160. $ret = $this->TypeAccount($this->Username, $this->Password);
  161. }
  162. else
  163. {
  164. $this->DebugMessage("DEBUG No username and password => LOGIN_FAIL");
  165. }
  166.  
  167. return $ret;
  168. }
  169.  
  170. private function DownloadPremium()
  171. {
  172. $this->DebugMessage("DEBUG DownloadPremium function");
  173.  
  174. $page = false;
  175. $DownloadInfo = false;
  176.  
  177. $page = $this->DownloadPageWithAuth();
  178. $this->DebugMessage("DEBUG DownloadPremium HTML", $this->coalesce_string($page));
  179.  
  180. //Si aucune page n'est retourné, renvoie false
  181. if($page != false)
  182. {
  183. $DownloadInfo = array();
  184.  
  185. /*Divise le résultat de la page pour recuperer la vrai URL.
  186. s'il n'est pas trouvé, renvoie ERREUR
  187. */
  188. $result = explode(';', $page);
  189. $realUrl = $result[0];
  190.  
  191. preg_match($this->PREMIUM_REAL_URL_REGEX,$realUrl,$urlmatch);
  192.  
  193. $DownloadInfo[INFO_NAME] = $result[1];
  194.  
  195. if(!empty($urlmatch[0]))
  196. {
  197. $DownloadInfo[DOWNLOAD_URL] = $realUrl;
  198. $this->DebugMessage("DEBUG DownloadPremium URL_PREMIUM", $this->coalesce_string($realUrl));
  199. $DownloadInfo[DOWNLOAD_ISPARALLELDOWNLOAD] = TRUE;
  200. }else
  201. {
  202. $page = $this->UrlFilePremiumWithDownloadMenu();
  203.  
  204. preg_match($this->PREMIUM_REAL_URL_REGEX,$page,$urlmatch);
  205. if(!empty($urlmatch[0]))
  206. {
  207. $DownloadInfo[DOWNLOAD_URL] = $urlmatch[0];
  208. $this->DebugMessage("DEBUG DownloadPremium URL_PREMIUM", $this->coalesce_string($urlmatch[0]));
  209. $DownloadInfo[DOWNLOAD_ISPARALLELDOWNLOAD] = TRUE;
  210. }else
  211. {
  212. $DownloadInfo[DOWNLOAD_ERROR] = ERR_UPATE_FAIL;
  213. }
  214. }
  215. }
  216. return $DownloadInfo;
  217. }
  218.  
  219. private function DownloadWaiting()
  220. {
  221. $this->DebugMessage("DEBUG DownloadWaiting function");
  222.  
  223. $DownloadInfo = false;
  224. $page = false;
  225.  
  226. if($this->ACCOUNT_TYPE != LOGIN_FAIL)
  227. {
  228. $page = $this->DownloadPageWithAuth();
  229. }else
  230. {
  231. $page = $this->DownloadPage($this->Url);
  232. }
  233. $this->DebugMessage("DEBUG DownloadWaiting HTML", $page);
  234.  
  235. $this->GenerateRequest($page);
  236. $this->DebugMessage("DEBUG DownloadWaiting ADZONE_VALUE", $this->ADZONE_VALUE);
  237.  
  238. //Si aucune page n'est retourné, renvoie false
  239. if($page != false)
  240. {
  241. //si un temps d'attente est detecté sur la page, renvoie le temps à attendre
  242. $result = $this->VerifyWaitDownload($page);
  243. if($result != false)
  244. {
  245. $DownloadInfo[DOWNLOAD_COUNT] = $result['COUNT'];
  246. $this->DebugMessage("DEBUG DownloadWaiting WAITING_FREE", $this->coalesce_string($result['COUNT']));
  247. $DownloadInfo[DOWNLOAD_ISQUERYAGAIN] = $this->QUERYAGAIN;
  248. }else
  249. {
  250. /*Genere le clic sur le bouton Download et tente de récuperer la vrai URL.
  251. si la vrai URL n'est pas retourné, on attends un temps par défaut car la page
  252. précédente n'indiquait pas qu'il fallait attendre
  253. */
  254. $page = false;
  255. $URLFinded = false;
  256.  
  257. if($this->ACCOUNT_TYPE != LOGIN_FAIL)
  258. {
  259. $page = $this->UrlFileWithFreeAccount();
  260. }else
  261. {
  262. $page = $this->UrlFileFree($this->Url);
  263. }
  264. $this->DebugMessage("DEBUG DownloadWaiting HTML PAGE_GENERATE_FREE_", $page);
  265.  
  266. if($page != false)
  267. {
  268. preg_match($this->FREE_REAL_URL_REGEX, $page, $realUrl);
  269. if(!empty($realUrl[1]))
  270. {
  271. $DownloadInfo[DOWNLOAD_URL] = $realUrl[1];
  272. $this->DebugMessage("DEBUG URL_FREE", $realUrl[1]);
  273. //$DownloadInfo[DOWNLOAD_ISPARALLELDOWNLOAD] = false;
  274. $URLFinded = TRUE;
  275. }
  276. }
  277.  
  278. if($URLFinded == false)
  279. {
  280. $DownloadInfo[DOWNLOAD_COUNT] = $this->WAITING_TIME_DEFAULT;
  281. $this->DebugMessage("DEBUG DownloadWaiting WAITING_DEFAULT_TIME", $this->coalesce_string($this->WAITING_TIME_DEFAULT));
  282. $DownloadInfo[DOWNLOAD_ISQUERYAGAIN] = $this->QUERYAGAIN;
  283. }
  284. }
  285. }
  286. return $DownloadInfo;
  287. }
  288.  
  289. //verifie sur la page s'il faut attendre et renvoie ce temps + 10 secondes de marge d'erreur
  290. private function VerifyWaitDownload($page)
  291. {
  292. $this->DebugMessage("DEBUG VerifyWaitDownload function");
  293. $this->DebugMessage("DEBUG VerifyWaitDownload HTML", $page);
  294.  
  295. $ret = false;
  296. preg_match($this->DOWNLOAD_WAIT_REGEX, $page, $waitingmatch);
  297.  
  298. if(!empty($waitingmatch[1]))
  299. {
  300. $waitingtime = ($waitingmatch[1] *60) + 10;
  301. $ret['COUNT'] = $waitingtime;
  302. }
  303.  
  304. $this->DebugMessage("DEBUG VerifyWaitDownload WaitCount", $this->coalesce_string($ret['COUNT']) );
  305.  
  306. return $ret;
  307. }
  308.  
  309. //telecharge une page en y indiquant une URL
  310. private function DownloadPage($strUrl, $inputoption = null)
  311. {
  312. $this->DebugMessage("DEBUG DownloadPage function");
  313. $this->DebugMessage("DEBUG DownloadPage URL", $strUrl);
  314.  
  315. $option = array('CURL_OPTION_FOLLOWLOCATION' => TRUE);
  316.  
  317. $ret = false;
  318.  
  319. if (!($inputoption == null))
  320. {
  321. $option = array_merge ($option, $inputoption);
  322. }
  323.  
  324. $curl = $this->GenerateCurl($strUrl,$option);
  325. $ret = curl_exec($curl);
  326. $ret_curl = $this->debug_curl($curl);
  327. curl_close($curl);
  328.  
  329. $this->DebugMessage("DEBUG DownloadPage Status", $ret_curl);
  330.  
  331. return $ret;
  332. }
  333.  
  334. //Telecharge la page en se connectant
  335. private function DownloadPageWithAuth()
  336. {
  337. $this->DebugMessage("DEBUG DownloadPageWithAuth function");
  338.  
  339. $ret = false;
  340.  
  341. $url = $this->Url.'&auth=1';
  342.  
  343. $this->DebugMessage("DEBUG DownloadPageWithAuth URL", $url);
  344.  
  345. //Permet de recuperer la vrai url directement pour les comptes premium
  346. if($this->ACCOUNT_TYPE == USER_IS_PREMIUM)
  347. {
  348. $url = $url.'&e=1';
  349. }
  350.  
  351. $option = array('CURL_OPTION_FOLLOWLOCATION' =>false);
  352. $curl = $this->GenerateCurl($url,$option);
  353. curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  354. curl_setopt($curl, CURLOPT_USERPWD, $this->Username.':'.$this->Password);
  355. $ret = curl_exec($curl);
  356. $ret_curl = $this->debug_curl($curl);
  357. curl_close($curl);
  358.  
  359. $this->DebugMessage("DEBUG DownloadPageWithAuth Status", $ret_curl);
  360.  
  361. return $ret;
  362. }
  363.  
  364. //retourne la page après s'etre connecté en premium et avoir cliqué sur le menu de telechargement
  365. private function UrlFilePremiumWithDownloadMenu()
  366. {
  367. $this->DebugMessage("DEBUG UrlFilePremiumWithDownloadMenu function");
  368.  
  369. $ret = false;
  370.  
  371. $url = $this->Url.'&auth=1&e=1';
  372.  
  373. $this->DebugMessage("DEBUG UrlFilePremiumWithDownloadMenu URL", $url);
  374.  
  375. $data = array('submit'=>'download');
  376.  
  377. $option = array('CURL_OPTION_POSTDATA' => $data,
  378. 'CURL_OPTION_HEADER' => TRUE,
  379. 'CURL_OPTION_FOLLOWLOCATION' =>false);
  380.  
  381. $curl = $this->GenerateCurl($url,$option);
  382. curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  383. curl_setopt($curl, CURLOPT_USERPWD, $this->Username.':'.$this->Password);
  384. $ret = curl_exec($curl);
  385. $ret_curl = $this->debug_curl($curl);
  386. curl_close($curl);
  387.  
  388. $this->DebugMessage("DEBUG UrlFilePremiumWithDownloadMenu Status", $ret_curl);
  389.  
  390. return $ret;
  391. }
  392.  
  393. private function GenerateRequest($page)
  394. {
  395. $this->DebugMessage("DEBUG GenerateRequest function");
  396. $this->DebugMessage("DEBUG GenerateRequest HTML", $this->coalesce_string($page));
  397.  
  398. preg_match($this->ADZONE_REGEX, $page, $adzonematch);
  399. if(isset($adzonematch[1]))
  400. {
  401. $this->ADZONE_VALUE = $adzonematch[1];
  402. }
  403. }
  404.  
  405. //Retourne la page après avoir cliqué sur le bouton et s'etre authentifié en gratuit
  406. private function UrlFileWithFreeAccount()
  407. {
  408. $this->DebugMessage("DEBUG UrlFileWithFreeAccount function");
  409.  
  410. $ret = false;
  411. $url = $this->Url.'&auth=1';
  412. $this->DebugMessage("DEBUG UrlFileWithFreeAccount URL", $url);
  413.  
  414. $data = array('submit'=>'Access to download', $this->ADZONE_NAME=>$this->ADZONE_VALUE);
  415.  
  416. $option = array('CURL_OPTION_POSTDATA' => $data,
  417. 'CURL_OPTION_FOLLOWLOCATION' =>false);
  418.  
  419. $curl = $this->GenerateCurl($url,$option);
  420. curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  421. curl_setopt($curl, CURLOPT_USERPWD, $this->Username.':'.$this->Password);
  422. $ret = curl_exec($curl);
  423. $ret_curl = $this->debug_curl($curl);
  424. curl_close($curl);
  425.  
  426. $this->DebugMessage("DEBUG UrlFileWithFreeAccount Status", $ret_curl);
  427.  
  428. return $ret;
  429. }
  430.  
  431. //envoie une requete POST pour generer le clic sur Download et renvoie la vrai url du fichier. ou false si la page ne renvoie rien
  432. private function UrlFileFree($strUrl)
  433. {
  434. $this->DebugMessage("DEBUG UrlFileFree function");
  435. $this->DebugMessage("DEBUG UrlFileFree URL", $strUrl);
  436.  
  437. $ret = false;
  438.  
  439. // $data = array('submit'=>'Access to download', 'adzone'=>$this->ADZONE_VALUE);
  440. $data = array('submit'=>'Download', $this->ADZONE_NAME=>$this->ADZONE_VALUE);
  441. // print_r($data);
  442.  
  443. $option = array('CURL_OPTION_POSTDATA' => $data,
  444. 'CURL_OPTION_HEADER' => false);
  445.  
  446. $curl = $this->GenerateCurl($strUrl,$option);
  447. $ret = curl_exec($curl);
  448. $ret_curl = $this->debug_curl($curl);
  449. curl_close($curl);
  450.  
  451. $this->DebugMessage("DEBUG UrlFileFree VraiURL", $ret_curl);
  452.  
  453. return $ret;
  454. }
  455.  
  456. //verifie si le lien est valide et retourne le nom du fichier si c'est le cas. Renvoie false si ça n'est pas le cas
  457. private function CheckLink($strUrl)
  458. {
  459. $this->DebugMessage("DEBUG CheckLink function");
  460.  
  461. $ret = false;
  462. $data = array('links[]'=>$strUrl);
  463.  
  464. $this->DebugMessage("DEBUG CheckLink URL", $strUrl);
  465.  
  466. $option = array('CURL_OPTION_POSTDATA' => $data);
  467. $curl = $this->GenerateCurl($this->CHECKLINK_URL_REQ,$option);
  468. $page = curl_exec($curl);
  469. $ret_curl = $this->debug_curl($curl);
  470.  
  471. curl_close($curl);
  472.  
  473. $this->DebugMessage("DEBUG Checklink HTML", $page);
  474.  
  475. preg_match($this->FILE_OFFLINE_REGEX, $page, $errormatch);
  476. if(!isset($errormatch[0]))
  477. {
  478. $result = explode(';', $page);
  479. if ( trim($result[3]) == 'PRIVATE' ) { $ret = 'Private file'; } else { $ret = $result[1]; }
  480. }
  481.  
  482. $this->DebugMessage("DEBUG CheckLink FileName", $this->coalesce_string($ret));
  483.  
  484. return $ret;
  485. }
  486.  
  487. private function TypeAccount($Username, $Password)
  488. {
  489. $this->DebugMessage("DEBUG TypeAccount function");
  490.  
  491. $ret = LOGIN_FAIL;
  492.  
  493. $postData=array('mail'=>$Username,'pass'=>$Password,'lt'=>'on','purge'=>'on','valider'=>'Envoyer');
  494.  
  495. //Generation d'un cookie à la première connexion$cookiepath
  496. if (strpos(PHP_OS, "WINNT") === false)
  497. {
  498. $cookiepath = $this->COOKIE_PATH;
  499. }
  500. else
  501. {
  502. $cookiepath = $this->COOKIE_PATH_WINNT;
  503. }
  504.  
  505. $option = array('CURL_OPTION_COOKIE' => TRUE, 'CURL_OPTION_SAVECOOKIEFILE' => $cookiepath, 'CURL_OPTION_POSTDATA'=>$postData);
  506. $queryUrl = 'https://1fichier.com/login.pl';
  507. $page = $this->DownloadPage($queryUrl,$option);
  508.  
  509. $this->DebugMessage("DEBUG TypeAccount LoginURL", $queryUrl);
  510. $this->DebugMessage("DEBUG TypeAccount IndexHTML", $page);
  511.  
  512. $pos = strpos($page, $Username);
  513.  
  514. $this->DebugMessage("DEBUG TypeAccount Pos Username", $this->coalesce_string($pos, 'No Username'));
  515.  
  516. if($pos > 0)
  517. {
  518.  
  519. $option = array('CURL_OPTION_COOKIE' => TRUE, 'CURL_OPTION_LOADCOOKIEFILE' => $cookiepath);
  520. $queryUrl = 'https://1fichier.com/console/index.pl';
  521. $page = $this->DownloadPage($queryUrl, $option);
  522.  
  523. $this->DebugMessage("DEBUG TypeAccount IndexURL", $queryUrl);
  524. $this->DebugMessage("DEBUG TypeAccount IndexHTML", $page);
  525.  
  526. // if((strpos($page, "Premium") > 0) || (strpos($page, "Access") > 0))
  527. if( (strpos($page, "Premium offer Account") > 0) || (strpos($page, "Compte offre Premium") > 0) || (strpos($page, "Access offer Account") > 0) || (strpos($page, "Compte offre Access") > 0) || (strpos($page,"<div class=\"alc\">Compte Premium</div>")>0) )
  528. {
  529.  
  530. $ret = USER_IS_PREMIUM;
  531. }
  532. else
  533. {
  534.  
  535. if((strpos($page, "Free") > 0) || (strpos($page, "Gratuit") > 0))
  536. {
  537. if ($this->HaveCDN()===true) $ret = USER_IS_PREMIUM;
  538. else $ret = USER_IS_FREE;
  539. }
  540. }
  541.  
  542. switch($ret)
  543. {
  544. case USER_IS_FREE:
  545. $this->DebugMessage("DEBUG TypeAccount Type : FREE");
  546. break;
  547. case USER_IS_PREMIUM:
  548. $this->DebugMessage("DEBUG TypeAccount Type : PREMIUM");
  549. break;
  550. case LOGIN_FAIL:
  551. $this->DebugMessage("DEBUG TypeAccount Type : Login Fail");
  552. break;
  553. }
  554. }
  555.  
  556. return $ret;
  557. }
  558.  
  559. //extrait l'identifiant du fichier de l'url entré
  560. private function GetFILEID($strUrl)
  561. {
  562. $this->DebugMessage("DEBUG GetFILEID function");
  563.  
  564. $ret = false;
  565.  
  566. $this->DebugMessage("DEBUG GetFILEID SourceURL", $strUrl);
  567.  
  568. /*si l'url est sous le nouveau format elle renvoie son ID
  569. si elle est sous l'ancien format, renvoie également son ID
  570. sinon renvoie faux
  571. */
  572. preg_match($this->FILEID_REGEX, $strUrl, $FILEIDMatch);
  573.  
  574. if(!empty($FILEIDMatch[1]))
  575. {
  576. $this->FILEID = $FILEIDMatch[1];
  577. $ret = TRUE;
  578. }else
  579. {
  580. preg_match($this->FILEID_OLD_REGEX, $strUrl, $FILEIDMatch);
  581. if(!empty($FILEIDMatch[1]))
  582. {
  583. $this->FILEID = $FILEIDMatch[1];
  584. $ret = TRUE;
  585. }
  586. }
  587.  
  588. $this->DebugMessage("DEBUG GetFILEID FileID", $this->coalesce_string($ret));
  589.  
  590. return $ret;
  591. }
  592.  
  593. /*créé une URL propre qui permettra de l'utiliser correctement
  594. */
  595. private function MakeUrl()
  596. {
  597. $this->DebugMessage("DEBUG MakeUrl function");
  598.  
  599. //créé une url d'origine propre
  600. $this->ORIGINAL_URL = 'https://1fichier.com/?'.$this->FILEID;
  601. $this->Url = $this->ORIGINAL_URL.'&lg=en';
  602.  
  603. $this->DebugMessage("DEBUG MakeUrl ORIGINAL_URL", $this->ORIGINAL_URL);
  604. $this->DebugMessage("DEBUG MakeUrl URL", $this->Url);
  605. }
  606.  
  607. //ecrit un message dans un fichier afin de debug le programme
  608. private function DebugMessage($texte, $data = '')
  609. {
  610. If($this->ENABLE_DEBUG == TRUE)
  611. {
  612.  
  613. $pos = strpos($texte, "HTML");
  614.  
  615. $now = DateTime::createFromFormat('U.u', microtime(true));
  616.  
  617. if (strpos(PHP_OS, "WINNT") === false)
  618. {
  619. $logfile = $this->LOG_DIR . $this->LOG_FILE;
  620. }
  621. else
  622. {
  623. $logfile = $this->LOG_FILE_WINNT;
  624. }
  625.  
  626. if ( !empty($data) ) $texte = $texte ." : ";
  627.  
  628. if ( $this->ENABLE_DEBUG_HTML == true )
  629. {
  630. if ( strlen($data) > 100 )
  631. {
  632. $myfile_html = fopen($this->LOG_DIR . $this->LOG_DIR_HTML . date_format($now,'Y-m-d-H-i-s-u') .'.html', "a");
  633. fwrite($myfile_html, $data);
  634. fclose($myfile_html);
  635. $data = 'Contenu HTML';
  636. }
  637. }
  638. elseif ($pos === false ) { $data = $data; }
  639. elseif ( !empty($data) ) { $data = 'Contenu HTML'; }
  640. else { $data = 'Aucun contenu'; }
  641.  
  642. $myfile = fopen($logfile, "a");
  643. fwrite($myfile, $now->format('Y-m-d H:i:s.u') ." | ". $texte . $data);
  644. fwrite($myfile,"\n");
  645. fclose($myfile);
  646. }
  647. }
  648.  
  649. //Fonction pour detecter si le compte possede des CDN
  650. private function HaveCDN()
  651. {
  652. $this->DebugMessage("DEBUG HaveCDN function");
  653.  
  654. $creditCDN=0;
  655.  
  656. if (strpos(PHP_OS, "WINNT") === false)
  657. {
  658. $cookiepath = $this->COOKIE_PATH;
  659. }
  660. else
  661. {
  662. $cookiepath = $this->COOKIE_PATH_WINNT;
  663. }
  664.  
  665. $option = array('CURL_OPTION_COOKIE' => TRUE, 'CURL_OPTION_LOADCOOKIEFILE' => $cookiepath);
  666. $queryUrl = 'https://1fichier.com/console/params.pl';
  667. $page = $this->DownloadPage($queryUrl,$option);
  668.  
  669. $this->DebugMessage("DEBUG HaveCDN LoginURL", $queryUrl);
  670. $this->DebugMessage("DEBUG HaveCDN IndexHTML", $page);
  671.  
  672. //Obtient la quantité de CDN
  673. preg_match($this->CDN_FR_REGEX, $page, $stringArrayFRCreditCDN);
  674. preg_match($this->CDN_EN_REGEX, $page, $stringArrayENCreditCDN);
  675. if(!empty($stringArrayFRCreditCDN[1]))
  676. {
  677. $creditCDN=floatval($stringArrayFRCreditCDN[1]);
  678. }
  679. else if(!empty($stringArrayENCreditCDN[1]))
  680. {
  681. $creditCDN=floatval($stringArrayENCreditCDN[1]);
  682. }
  683.  
  684. $this->DebugMessage("DEBUG HaveCDN CDN credit", $this->coalesce_string($creditCDN));
  685.  
  686. //Verifie si la case des CDN est coché
  687. $checkedCdnBox=preg_match($this->CDN_CHECKBOX_REGEX,$page);
  688. if($checkedCdnBox) $this->DebugMessage("DEBUG CDN Checkbox is checked");
  689. else $this->DebugMessage("DEBUG CDN Checkbox is NOT checked");
  690.  
  691. if(($creditCDN>=$MIN_CDN_GB)&&$checkedCdnBox) return TRUE;
  692. else return FALSE;
  693.  
  694. }
  695.  
  696. private function GenerateCurl($Url, $Option=NULL)
  697. {
  698. $ret = FALSE;
  699. $curl = curl_init();
  700. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  701. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, DOWNLOAD_TIMEOUT);
  702. curl_setopt($curl, CURLOPT_TIMEOUT, DOWNLOAD_TIMEOUT);
  703. // curl_setopt($curl, CURLOPT_USERAGENT, DOWNLOAD_STATION_USER_AGENT);
  704. if (NULL != $Option) {
  705. if (!empty($Option['CURL_OPTION_POSTDATA'])) {
  706. $PostData = http_build_query($Option['CURL_OPTION_POSTDATA']);
  707. curl_setopt($curl, CURLOPT_POST, TRUE);
  708. curl_setopt($curl, CURLOPT_POSTFIELDS, $PostData);
  709. }
  710. if (!empty($Option['CURL_OPTION_COOKIE'])) {
  711. curl_setopt($curl, CURLOPT_COOKIE, $Option['CURL_OPTION_COOKIE']);
  712. }
  713. if (!empty($Option['CURL_OPTION_HTTPHEADER'])) {
  714. curl_setopt($curl, CURLOPT_HTTPHEADER, $Option['CURL_OPTION_HTTPHEADER']);
  715. }
  716. if (!empty($Option['CURL_OPTION_SAVECOOKIEFILE'])) {
  717. curl_setopt($curl, CURLOPT_COOKIEJAR, $Option['CURL_OPTION_SAVECOOKIEFILE']);
  718. }
  719. if (!empty($Option['CURL_OPTION_LOADCOOKIEFILE'])) {
  720. curl_setopt($curl, CURLOPT_COOKIEFILE, $Option['CURL_OPTION_LOADCOOKIEFILE']);
  721. }
  722. if (!empty($Option['CURL_OPTION_FOLLOWLOCATION']) && TRUE == $Option['CURL_OPTION_FOLLOWLOCATION']) {
  723. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
  724. }
  725. if (!empty($Option['CURL_OPTION_HEADER'])&& TRUE == $Option['CURL_OPTION_HEADER']) {
  726. curl_setopt($curl, CURLOPT_HEADER, TRUE);
  727. }
  728. if ( $this->ENABLE_DEBUGCURL_VERBOSE == TRUE ) { curl_setopt($curl, CURLOPT_VERBOSE, TRUE); }
  729. }
  730. curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
  731. curl_setopt($curl, CURLOPT_URL, $Url);
  732. // curl_setopt($curl, CURLINFO_HEADER_OUT, TRUE);
  733. $ret = $curl;
  734. return $ret;
  735. }
  736.  
  737. private function debug_curl ( $curl )
  738. {
  739. $info = curl_getinfo($curl);
  740.  
  741. if ( !curl_errno($curl) )
  742. {
  743. $ret_string = 'OK | ';
  744. }
  745. else
  746. {
  747. $ret_string = 'KO | ' . curl_error($curl) .' | ';
  748. }
  749.  
  750. $ret_string .= 'HTTP code : '. $info['http_code'] . ' | URL : '. $info['url'] . ' | Temps : '. $info['total_time'];
  751.  
  752. return $ret_string;
  753. }
  754.  
  755. private function coalesce_string ($string, $default_string = 'N/A')
  756. {
  757. if ( empty( $string ) )
  758. { $ret_dl = $default_string; }
  759. else
  760. { $ret_dl = $string; }
  761. return $ret_dl;
  762. }
  763. }
  764. ?>
  765.  
  766.  
Add Comment
Please, Sign In to add comment