Advertisement
Guest User

Untitled

a guest
Sep 12th, 2023
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.08 KB | None | 0 0
  1. <?php
  2. /*
  3. *
  4. * @ This File Decoded by : ionZender Tool @
  5. * || Best Decoder For PHP Files ||
  6.  
  7. * @ Version : 4.2.0
  8. * @ Author : @ionZender
  9. * @ Release on : 08.30.2023
  10. * @ Official site : https://t.me/ionZender
  11. *
  12. */
  13.  
  14. if(count(get_included_files()) == 1) exit("No direct script access allowed");
  15.  
  16. define("LB_API_DEBUG", false);
  17. define("LB_SHOW_UPDATE_PROGRESS", true);
  18.  
  19. define("LB_TEXT_CONNECTION_FAILED", 'Server is unavailable at the moment, please try again.');
  20. define("LB_TEXT_INVALID_RESPONSE", 'Server returned an invalid response, please contact support.');
  21. define("LB_TEXT_VERIFIED_RESPONSE", 'Verified! Thanks for purchasing.');
  22. define("LB_TEXT_PREPARING_MAIN_DOWNLOAD", 'Preparing to download main update...');
  23. define("LB_TEXT_MAIN_UPDATE_SIZE", 'Main Update size:');
  24. define("LB_TEXT_DONT_REFRESH", '(Please do not refresh the page).');
  25. define("LB_TEXT_DOWNLOADING_MAIN", 'Downloading main update...');
  26. define("LB_TEXT_UPDATE_PERIOD_EXPIRED", 'Your update period has ended or your license is invalid, please contact support.');
  27. define("LB_TEXT_UPDATE_PATH_ERROR", 'Folder does not have write permission or the update file path could not be resolved, please contact support.');
  28. define("LB_TEXT_MAIN_UPDATE_DONE", 'Main update files downloaded and extracted.');
  29. define("LB_TEXT_UPDATE_EXTRACTION_ERROR", 'Update zip extraction failed.');
  30. define("LB_TEXT_PREPARING_SQL_DOWNLOAD", 'Preparing to download SQL update...');
  31. define("LB_TEXT_SQL_UPDATE_SIZE", 'SQL Update size:');
  32. define("LB_TEXT_DOWNLOADING_SQL", 'Downloading SQL update...');
  33. define("LB_TEXT_SQL_UPDATE_DONE", 'SQL update files downloaded.');
  34. define("LB_TEXT_UPDATE_WITH_SQL_IMPORT_FAILED", 'Application was successfully updated but automatic SQL importing failed, please import the downloaded SQL file in your database manually.');
  35. define("LB_TEXT_UPDATE_WITH_SQL_IMPORT_DONE", 'Application was successfully updated and SQL file was automatically imported.');
  36. define("LB_TEXT_UPDATE_WITH_SQL_DONE", 'Application was successfully updated, please import the downloaded SQL file in your database manually.');
  37. define("LB_TEXT_UPDATE_WITHOUT_SQL_DONE", 'Application was successfully updated, there were no SQL updates.');
  38.  
  39. if(!LB_API_DEBUG){
  40. @ini_set('display_errors', 0);
  41. }
  42.  
  43. if((@ini_get('max_execution_time')!=='0')&&(@ini_get('max_execution_time'))<600){
  44. @ini_set('max_execution_time', 600);
  45. }
  46. @ini_set('memory_limit', '256M');
  47.  
  48. class LicenseBoxExternalAPI{
  49.  
  50. private $product_id;
  51. private $api_url;
  52. private $api_key;
  53. private $api_language;
  54. private $current_version;
  55. private $verify_type;
  56. private $verification_period;
  57. private $current_path;
  58. private $root_path;
  59. private $license_file;
  60.  
  61. public function __construct(){
  62. $this->product_id = 'C0D294F4';
  63. $this->api_url = 'https://tp98-server.xyz/';
  64. $this->api_key = '93D9D090D01D2488558B';
  65. $this->api_language = 'english';
  66. $this->current_version = 'v1.0.0';
  67. $this->verify_type = 'non_envato';
  68. $this->verification_period = 1;
  69. $this->current_path = realpath(__DIR__);
  70. $this->root_path = realpath($this->current_path.'/..');
  71. $this->license_file = $this->current_path.'/.lic';
  72. }
  73.  
  74. public function check_local_license_exist(){
  75. return is_file($this->license_file);
  76. }
  77.  
  78. public function get_current_version(){
  79. return $this->current_version;
  80. }
  81.  
  82. private function call_api($method, $url, $data = null){
  83. $curl = curl_init();
  84. switch ($method){
  85. case "POST":
  86. curl_setopt($curl, CURLOPT_POST, 1);
  87. if($data)
  88. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  89. break;
  90. case "PUT":
  91. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
  92. if($data)
  93. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  94. break;
  95. default:
  96. if($data)
  97. $url = sprintf("%s?%s", $url, http_build_query($data));
  98. }
  99. $this_server_name = getenv('SERVER_NAME')?:
  100. $_SERVER['SERVER_NAME']?:
  101. getenv('HTTP_HOST')?:
  102. $_SERVER['HTTP_HOST'];
  103. $this_http_or_https = ((
  104. (isset($_SERVER['HTTPS'])&&($_SERVER['HTTPS']=="on"))or
  105. (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])and
  106. $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
  107. )?'https://':'http://');
  108. $this_url = $this_http_or_https.$this_server_name.$_SERVER['REQUEST_URI'];
  109. $this_ip = getenv('SERVER_ADDR')?:
  110. $_SERVER['SERVER_ADDR']?:
  111. $this->get_ip_from_third_party()?:
  112. gethostbyname(gethostname());
  113. curl_setopt($curl, CURLOPT_HTTPHEADER,
  114. array('Content-Type: application/json',
  115. 'LB-API-KEY: '.$this->api_key,
  116. 'LB-URL: '.$this_url,
  117. 'LB-IP: '.$this_ip,
  118. 'LB-LANG: '.$this->api_language)
  119. );
  120. curl_setopt($curl, CURLOPT_URL, $url);
  121. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  122. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
  123. curl_setopt($curl, CURLOPT_TIMEOUT, 30);
  124. $result = curl_exec($curl);
  125. if(!$result&&!LB_API_DEBUG){
  126. $rs = array(
  127. 'status' => FALSE,
  128. 'message' => LB_TEXT_CONNECTION_FAILED
  129. );
  130. return json_encode($rs);
  131. }
  132. $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  133. if($http_status != 200){
  134. if(LB_API_DEBUG){
  135. $temp_decode = json_decode($result, true);
  136. $rs = array(
  137. 'status' => FALSE,
  138. 'message' => ((!empty($temp_decode['error']))?
  139. $temp_decode['error']:
  140. $temp_decode['message'])
  141. );
  142. return json_encode($rs);
  143. }else{
  144. $rs = array(
  145. 'status' => FALSE,
  146. 'message' => LB_TEXT_INVALID_RESPONSE
  147. );
  148. return json_encode($rs);
  149. }
  150. }
  151. curl_close($curl);
  152. return $result;
  153. }
  154.  
  155. public function check_connection(){
  156. $get_data = $this->call_api(
  157. 'POST',
  158. $this->api_url.'api/check_connection_ext'
  159. );
  160. $response = json_decode($get_data, true);
  161. return $response;
  162. }
  163.  
  164. public function get_latest_version(){
  165. $data_array = array(
  166. "product_id" => $this->product_id
  167. );
  168. $get_data = $this->call_api(
  169. 'POST',
  170. $this->api_url.'api/latest_version',
  171. json_encode($data_array)
  172. );
  173. $response = json_decode($get_data, true);
  174. return $response;
  175. }
  176.  
  177. public function activate_license($license, $client, $create_lic = true){
  178. $data_array = array(
  179. "product_id" => $this->product_id,
  180. "license_code" => $license,
  181. "client_name" => $client,
  182. "verify_type" => $this->verify_type
  183. );
  184. $get_data = $this->call_api(
  185. 'POST',
  186. $this->api_url.'api/activate_license',
  187. json_encode($data_array)
  188. );
  189. $response = json_decode($get_data, true);
  190. if(!empty($create_lic)){
  191. if($response['status']){
  192. $licfile = trim($response['lic_response']);
  193. file_put_contents($this->license_file, $licfile, LOCK_EX);
  194. }else{
  195. @chmod($this->license_file, 0777);
  196. if(is_writeable($this->license_file)){
  197. unlink($this->license_file);
  198. }
  199. }
  200. }
  201. return $response;
  202. }
  203.  
  204. public function verify_license($time_based_check = false, $license = false, $client = false){
  205. if(!empty($license)&&!empty($client)){
  206. $data_array = array(
  207. "product_id" => $this->product_id,
  208. "license_file" => null,
  209. "license_code" => $license,
  210. "client_name" => $client
  211. );
  212. }else{
  213. if(is_file($this->license_file)){
  214. $data_array = array(
  215. "product_id" => $this->product_id,
  216. "license_file" => file_get_contents($this->license_file),
  217. "license_code" => null,
  218. "client_name" => null
  219. );
  220. }else{
  221. $data_array = array();
  222. }
  223. }
  224. $res = array('status' => TRUE, 'message' => LB_TEXT_VERIFIED_RESPONSE);
  225. if($time_based_check && $this->verification_period > 0){
  226. ob_start();
  227. if(session_status() == PHP_SESSION_NONE){
  228. session_start();
  229. }
  230. $type = (int) $this->verification_period;
  231. $today = date('d-m-Y');
  232. if(empty($_SESSION["3cef80e4aca995e"])){
  233. $_SESSION["3cef80e4aca995e"] = '00-00-0000';
  234. }
  235. if($type == 1){
  236. $type_text = '1 day';
  237. }elseif($type == 3){
  238. $type_text = '3 days';
  239. }elseif($type == 7){
  240. $type_text = '1 week';
  241. }elseif($type == 30){
  242. $type_text = '1 month';
  243. }elseif($type == 90){
  244. $type_text = '3 months';
  245. }elseif($type == 365) {
  246. $type_text = '1 year';
  247. }else{
  248. $type_text = $type.' days';
  249. }
  250. if(strtotime($today) >= strtotime($_SESSION["3cef80e4aca995e"])){
  251. $get_data = $this->call_api(
  252. 'POST',
  253. $this->api_url.'api/verify_license',
  254. json_encode($data_array)
  255. );
  256. $res = json_decode($get_data, true);
  257. if($res['status']==true){
  258. $tomo = date('d-m-Y', strtotime($today. ' + '.$type_text));
  259. $_SESSION["3cef80e4aca995e"] = $tomo;
  260. }
  261. }
  262. ob_end_clean();
  263. }else{
  264. $get_data = $this->call_api(
  265. 'POST',
  266. $this->api_url.'api/verify_license',
  267. json_encode($data_array)
  268. );
  269. $res = json_decode($get_data, true);
  270. }
  271. return $res;
  272. }
  273.  
  274. public function deactivate_license($license = false, $client = false){
  275. if(!empty($license)&&!empty($client)){
  276. $data_array = array(
  277. "product_id" => $this->product_id,
  278. "license_file" => null,
  279. "license_code" => $license,
  280. "client_name" => $client
  281. );
  282. }else{
  283. if(is_file($this->license_file)){
  284. $data_array = array(
  285. "product_id" => $this->product_id,
  286. "license_file" => file_get_contents($this->license_file),
  287. "license_code" => null,
  288. "client_name" => null
  289. );
  290. }else{
  291. $data_array = array();
  292. }
  293. }
  294. $get_data = $this->call_api(
  295. 'POST',
  296. $this->api_url.'api/deactivate_license',
  297. json_encode($data_array)
  298. );
  299. $response = json_decode($get_data, true);
  300. if($response['status']){
  301. @chmod($this->license_file, 0777);
  302. if(is_writeable($this->license_file)){
  303. unlink($this->license_file);
  304. }
  305. }
  306. return $response;
  307. }
  308.  
  309. public function check_update(){
  310. $data_array = array(
  311. "product_id" => $this->product_id,
  312. "current_version" => $this->current_version
  313. );
  314. $get_data = $this->call_api(
  315. 'POST',
  316. $this->api_url.'api/check_update',
  317. json_encode($data_array)
  318. );
  319. $response = json_decode($get_data, true);
  320. return $response;
  321. }
  322.  
  323. public function download_update($update_id, $type, $version, $license = false, $client = false, $db_for_import = false){
  324. if(!empty($license)&&!empty($client)){
  325. $data_array = array(
  326. "license_file" => null,
  327. "license_code" => $license,
  328. "client_name" => $client
  329. );
  330. }else{
  331. if(is_file($this->license_file)){
  332. $data_array = array(
  333. "license_file" => file_get_contents($this->license_file),
  334. "license_code" => null,
  335. "client_name" => null
  336. );
  337. }else{
  338. $data_array = array();
  339. }
  340. }
  341. ob_end_flush();
  342. ob_implicit_flush(true);
  343. $version = str_replace(".", "_", $version);
  344. ob_start();
  345. $source_size = $this->api_url."api/get_update_size/main/".$update_id;
  346. echo LB_TEXT_PREPARING_MAIN_DOWNLOAD."<br>";
  347. if(LB_SHOW_UPDATE_PROGRESS){echo '<script>document.getElementById(\'prog\').value = 1;</script>';}
  348. ob_flush();
  349. echo LB_TEXT_MAIN_UPDATE_SIZE." ".$this->get_remote_filesize($source_size)." ".LB_TEXT_DONT_REFRESH."<br>";
  350. if(LB_SHOW_UPDATE_PROGRESS){echo '<script>document.getElementById(\'prog\').value = 5;</script>';}
  351. ob_flush();
  352. $temp_progress = '';
  353. $ch = curl_init();
  354. $source = $this->api_url."api/download_update/main/".$update_id;
  355. curl_setopt($ch, CURLOPT_URL, $source);
  356. curl_setopt($ch, CURLOPT_POST, 1);
  357. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_array);
  358. $this_server_name = getenv('SERVER_NAME')?:
  359. $_SERVER['SERVER_NAME']?:
  360. getenv('HTTP_HOST')?:
  361. $_SERVER['HTTP_HOST'];
  362. $this_http_or_https = ((
  363. (isset($_SERVER['HTTPS'])&&($_SERVER['HTTPS']=="on"))or
  364. (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])and
  365. $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
  366. )?'https://':'http://');
  367. $this_url = $this_http_or_https.$this_server_name.$_SERVER['REQUEST_URI'];
  368. $this_ip = getenv('SERVER_ADDR')?:
  369. $_SERVER['SERVER_ADDR']?:
  370. $this->get_ip_from_third_party()?:
  371. gethostbyname(gethostname());
  372. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  373. 'LB-API-KEY: '.$this->api_key,
  374. 'LB-URL: '.$this_url,
  375. 'LB-IP: '.$this_ip,
  376. 'LB-LANG: '.$this->api_language)
  377. );
  378. if(LB_SHOW_UPDATE_PROGRESS){curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, array($this, 'progress'));}
  379. if(LB_SHOW_UPDATE_PROGRESS){curl_setopt($ch, CURLOPT_NOPROGRESS, false);}
  380. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  381. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  382. echo LB_TEXT_DOWNLOADING_MAIN."<br>";
  383. if(LB_SHOW_UPDATE_PROGRESS){echo '<script>document.getElementById(\'prog\').value = 10;</script>';}
  384. ob_flush();
  385. $data = curl_exec($ch);
  386. $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  387. if($http_status != 200){
  388. if($http_status == 401){
  389. curl_close($ch);
  390. exit("<br>".LB_TEXT_UPDATE_PERIOD_EXPIRED);
  391. }else{
  392. curl_close($ch);
  393. exit("<br>".LB_TEXT_INVALID_RESPONSE);
  394. }
  395. }
  396. curl_close($ch);
  397. $destination = $this->root_path."/update_main_".$version.".zip";
  398. $file = fopen($destination, "w+");
  399. if(!$file){
  400. exit("<br>".LB_TEXT_UPDATE_PATH_ERROR);
  401. }
  402. fputs($file, $data);
  403. fclose($file);
  404. if(LB_SHOW_UPDATE_PROGRESS){echo '<script>document.getElementById(\'prog\').value = 65;</script>';}
  405. ob_flush();
  406. $zip = new ZipArchive;
  407. $res = $zip->open($destination);
  408. if($res === TRUE){
  409. $zip->extractTo($this->root_path."/");
  410. $zip->close();
  411. unlink($destination);
  412. echo LB_TEXT_MAIN_UPDATE_DONE."<br><br>";
  413. if(LB_SHOW_UPDATE_PROGRESS){echo '<script>document.getElementById(\'prog\').value = 75;</script>';}
  414. ob_flush();
  415. }else{
  416. echo LB_TEXT_UPDATE_EXTRACTION_ERROR."<br><br>";
  417. ob_flush();
  418. }
  419. if($type == true){
  420. $source_size = $this->api_url."api/get_update_size/sql/".$update_id;
  421. echo LB_TEXT_PREPARING_SQL_DOWNLOAD."<br>";
  422. ob_flush();
  423. echo LB_TEXT_SQL_UPDATE_SIZE." ".$this->get_remote_filesize($source_size)." ".LB_TEXT_DONT_REFRESH."<br>";
  424. if(LB_SHOW_UPDATE_PROGRESS){echo '<script>document.getElementById(\'prog\').value = 85;</script>';}
  425. ob_flush();
  426. $temp_progress = '';
  427. $ch = curl_init();
  428. $source = $this->api_url."api/download_update/sql/".$update_id;
  429. curl_setopt($ch, CURLOPT_URL, $source);
  430. curl_setopt($ch, CURLOPT_POST, 1);
  431. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_array);
  432. $this_server_name = getenv('SERVER_NAME')?:
  433. $_SERVER['SERVER_NAME']?:
  434. getenv('HTTP_HOST')?:
  435. $_SERVER['HTTP_HOST'];
  436. $this_http_or_https = ((
  437. (isset($_SERVER['HTTPS'])&&($_SERVER['HTTPS']=="on"))or
  438. (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])and
  439. $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
  440. )?'https://':'http://');
  441. $this_url = $this_http_or_https.$this_server_name.$_SERVER['REQUEST_URI'];
  442. $this_ip = getenv('SERVER_ADDR')?:
  443. $_SERVER['SERVER_ADDR']?:
  444. $this->get_ip_from_third_party()?:
  445. gethostbyname(gethostname());
  446. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  447. 'LB-API-KEY: '.$this->api_key,
  448. 'LB-URL: '.$this_url,
  449. 'LB-IP: '.$this_ip,
  450. 'LB-LANG: '.$this->api_language)
  451. );
  452. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  453. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
  454. echo LB_TEXT_DOWNLOADING_SQL."<br>";
  455. if(LB_SHOW_UPDATE_PROGRESS){echo '<script>document.getElementById(\'prog\').value = 90;</script>';}
  456. ob_flush();
  457. $data = curl_exec($ch);
  458. $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  459. if($http_status!=200){
  460. curl_close($ch);
  461. exit(LB_TEXT_INVALID_RESPONSE);
  462. }
  463. curl_close($ch);
  464. $destination = $this->root_path."/update_sql_".$version.".sql";
  465. $file = fopen($destination, "w+");
  466. if(!$file){
  467. exit(LB_TEXT_UPDATE_PATH_ERROR);
  468. }
  469. fputs($file, $data);
  470. fclose($file);
  471. echo LB_TEXT_SQL_UPDATE_DONE."<br><br>";
  472. if(LB_SHOW_UPDATE_PROGRESS){echo '<script>document.getElementById(\'prog\').value = 95;</script>';}
  473. ob_flush();
  474. if(is_array($db_for_import)){
  475. if(!empty($db_for_import["db_host"])&&!empty($db_for_import["db_user"])&&!empty($db_for_import["db_name"])){
  476. $db_host = strip_tags(trim($db_for_import["db_host"]));
  477. $db_user = strip_tags(trim($db_for_import["db_user"]));
  478. $db_pass = strip_tags(trim($db_for_import["db_pass"]));
  479. $db_name = strip_tags(trim($db_for_import["db_name"]));
  480. $con = @mysqli_connect($db_host, $db_user, $db_pass, $db_name);
  481. if(mysqli_connect_errno()){
  482. echo LB_TEXT_UPDATE_WITH_SQL_IMPORT_FAILED;
  483. }else{
  484. $templine = '';
  485. $lines = file($destination);
  486. foreach($lines as $line){
  487. if(substr($line, 0, 2) == '--' || $line == '')
  488. continue;
  489. $templine .= $line;
  490. $query = false;
  491. if(substr(trim($line), -1, 1) == ';'){
  492. $query = mysqli_query($con, $templine);
  493. $templine = '';
  494. }
  495. }
  496. @chmod($destination,0777);
  497. if(is_writeable($destination)){
  498. unlink($destination);
  499. }
  500. echo LB_TEXT_UPDATE_WITH_SQL_IMPORT_DONE;
  501. }
  502. }else{
  503. echo LB_TEXT_UPDATE_WITH_SQL_IMPORT_FAILED;
  504. }
  505. }else{
  506. echo LB_TEXT_UPDATE_WITH_SQL_DONE;
  507. }
  508. if(LB_SHOW_UPDATE_PROGRESS){echo '<script>document.getElementById(\'prog\').value = 100;</script>';}
  509. ob_flush();
  510. }else{
  511. if(LB_SHOW_UPDATE_PROGRESS){echo '<script>document.getElementById(\'prog\').value = 100;</script>';}
  512. echo LB_TEXT_UPDATE_WITHOUT_SQL_DONE;
  513. ob_flush();
  514. }
  515. ob_end_flush();
  516. }
  517.  
  518. private function progress($resource, $download_size, $downloaded, $upload_size, $uploaded){
  519. static $prev = 0;
  520. if($download_size == 0){
  521. $progress = 0;
  522. }else{
  523. $progress = round( $downloaded * 100 / $download_size );
  524. }
  525. if(($progress!=$prev) && ($progress == 25)){
  526. $prev = $progress;
  527. echo '<script>document.getElementById(\'prog\').value = 22.5;</script>';
  528. ob_flush();
  529. }
  530. if(($progress!=$prev) && ($progress == 50)){
  531. $prev=$progress;
  532. echo '<script>document.getElementById(\'prog\').value = 35;</script>';
  533. ob_flush();
  534. }
  535. if(($progress!=$prev) && ($progress == 75)){
  536. $prev=$progress;
  537. echo '<script>document.getElementById(\'prog\').value = 47.5;</script>';
  538. ob_flush();
  539. }
  540. if(($progress!=$prev) && ($progress == 100)){
  541. $prev=$progress;
  542. echo '<script>document.getElementById(\'prog\').value = 60;</script>';
  543. ob_flush();
  544. }
  545. }
  546.  
  547. private function get_ip_from_third_party(){
  548. $curl = curl_init ();
  549. curl_setopt($curl, CURLOPT_URL, "http://ipecho.net/plain");
  550. curl_setopt($curl, CURLOPT_HEADER, 0);
  551. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  552. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
  553. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  554. $response = curl_exec($curl);
  555. curl_close($curl);
  556. return $response;
  557. }
  558.  
  559. private function get_remote_filesize($url){
  560. $curl = curl_init();
  561. curl_setopt($curl, CURLOPT_HEADER, TRUE);
  562. curl_setopt($curl, CURLOPT_URL, $url);
  563. curl_setopt($curl, CURLOPT_NOBODY, TRUE);
  564. $this_server_name = getenv('SERVER_NAME')?:
  565. $_SERVER['SERVER_NAME']?:
  566. getenv('HTTP_HOST')?:
  567. $_SERVER['HTTP_HOST'];
  568. $this_http_or_https = ((
  569. (isset($_SERVER['HTTPS'])&&($_SERVER['HTTPS']=="on"))or
  570. (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])and
  571. $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')
  572. )?'https://':'http://');
  573. $this_url = $this_http_or_https.$this_server_name.$_SERVER['REQUEST_URI'];
  574. $this_ip = getenv('SERVER_ADDR')?:
  575. $_SERVER['SERVER_ADDR']?:
  576. $this->get_ip_from_third_party()?:
  577. gethostbyname(gethostname());
  578. curl_setopt($curl, CURLOPT_HTTPHEADER, array(
  579. 'LB-API-KEY: '.$this->api_key,
  580. 'LB-URL: '.$this_url,
  581. 'LB-IP: '.$this_ip,
  582. 'LB-LANG: '.$this->api_language)
  583. );
  584. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  585. curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
  586. $result = curl_exec($curl);
  587. $filesize = curl_getinfo($curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
  588. if ($filesize){
  589. switch ($filesize){
  590. case $filesize < 1024:
  591. $size = $filesize .' B'; break;
  592. case $filesize < 1048576:
  593. $size = round($filesize / 1024, 2) .' KB'; break;
  594. case $filesize < 1073741824:
  595. $size = round($filesize / 1048576, 2) . ' MB'; break;
  596. case $filesize < 1099511627776:
  597. $size = round($filesize / 1073741824, 2) . ' GB'; break;
  598. }
  599. return $size;
  600. }
  601. }
  602. }
  603. ";
  604.  
  605. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement