Просмотр файла sys/fnc/license.php

Размер файла: 4.09Kb
  1. <?
  2.  
  3. function lic_dcms_loc() // получение локальной лицензии
  4. {
  5. $return=false;
  6. $od_lic=opendir(H.'sys/license/');
  7. while ($rd_lic=readdir($od_lic))
  8. {
  9. if (eregi(str_replace('.', '\.', $rd_lic).'$',$_SERVER['HTTP_HOST']))
  10. {
  11. if ($license=@unserialize(@file_get_contents(H.'sys/license/'.$rd_lic)))
  12. {
  13. if (isset($license['url']) && eregi(str_replace('.', '\.', $license['url']).'$',$_SERVER['HTTP_HOST']))
  14. {
  15. if ($license['last_time']<time()-604800 || $license['last_time']<$license['last_update']-604800)
  16. {
  17. @unlink(H.'sys/license/'.$rd_lic);
  18. }
  19. else
  20. {
  21. $return=$license;
  22. }
  23. break;
  24. }
  25. else
  26. {
  27. @unlink(H.'sys/license/'.$rd_lic);
  28. }
  29. }
  30. }
  31. }
  32. return $return;
  33. closedir($od_lic);
  34. }
  35.  
  36. function copyright2($copyright){
  37. return eregi_replace("</div>(\n|\r)*</body>", "<div style='font-size:small;'>&copy; <a title='Бесплатный WAP-движок для вашего сайта' href=\"http://dcms.su\">DCMS</a><br />\n</div>\n</div>\n</body>", $copyright);
  38. }
  39.  
  40.  
  41.  
  42. function lic_dcms($send=null)
  43. {
  44. global $set,$license;
  45. if ($sock=@fsockopen($set['http_license'], 80, $err_no, $err_str, 7))
  46. {
  47. $data_out['host']=$_SERVER['HTTP_HOST']; // адрес сайта
  48. $data_out['ver']=$set['dcms_version']; // версия движка
  49. $data_out['data']=$send; // отправляемые данные
  50.  
  51.  
  52.  
  53. // ключег
  54. if ($license)
  55. {
  56. $data_out['key']=$license['key'];
  57. $data_out['last_time']=$license['last_time'];
  58. }
  59. else
  60. {
  61. $data_out['tmp_key']=md5(passgen());
  62. @file_put_contents(H.'sys/tmp/tmp_key.dat', $data_out['tmp_key']);
  63. @chmod(H.'sys/tmp/tmp_key.dat', 0777);
  64. }
  65.  
  66. $post_value='data='.serialize($data_out);
  67. $s_head="POST /dcms/license.dcms HTTP/1.0\r\n";
  68. $s_head.="Host: $set[http_license]\r\n";
  69. $s_head.="User-Agent: DCMS/$set[dcms_version]\r\n";
  70. //$s_head.="Keep-Alive: 300\r\n";
  71. $s_head.="Connection: close\r\n";
  72. $s_head .= "Content-Type: application/x-www-form-urlencoded\r\n";
  73. $s_head .= "Content-Length: ".strlen($post_value)."\r\n\r\n";
  74. $s_head .= $post_value;
  75.  
  76. fwrite($sock, $s_head); // отправка данных
  77.  
  78. $buffer=null;while (!feof($sock)){$buffer .= fgets($sock);} // прием данных
  79. fclose($sock);
  80.  
  81.  
  82. list($header,$content)=explode("\r\n\r\n", $buffer); // разборка данных
  83.  
  84. $data_in=@unserialize($content);
  85.  
  86. // информация о лицензии
  87. if (isset($data_in['lic_info']))
  88. {
  89. $data_in['lic_info']['last_update']=time();
  90. @unlink(H.'sys/license/'.$data_in['lic_info']['url']);
  91. @file_put_contents(H.'sys/license/'.$data_in['lic_info']['url'], serialize($data_in['lic_info']));
  92. @chmod(H.'sys/license/'.$data_in['lic_info']['url'], 0777);
  93. $license=$data_in['lic_info'];
  94. }
  95. else $license=false;
  96.  
  97.  
  98. // список новых версий
  99. if (isset($data_in['new_ver']))
  100. {
  101. mysql_query('TRUNCATE TABLE `license_list_ver`');
  102. mysql_query('TRUNCATE TABLE `license_list_changelog`');
  103. $new_ver=$data_in['new_ver'];
  104. for ($i=0;$i<count($new_ver);$i++)
  105. {
  106. mysql_query("INSERT INTO `license_list_ver` (`id`, `ver_1`, `ver_2`, `ver_3`, `delete`, `sql`)
  107. VALUES ('".$new_ver[$i]['id']."', '".$new_ver[$i]['ver_1']."', '".$new_ver[$i]['ver_2']."', '".$new_ver[$i]['ver_3']."','".my_esc($new_ver[$i]['delete'])."','".my_esc($new_ver[$i]['sql'])."')");
  108. for ($z=0;(isset($new_ver[$i]['changelog']) && $z<count($new_ver[$i]['changelog']) );$z++)
  109. {
  110. mysql_query("INSERT INTO `license_list_changelog` (`text`, `ver_1`, `ver_2`, `ver_3`) VALUES ('".my_esc($new_ver[$i]['changelog'][$z])."', '".$new_ver[$i]['ver_1']."','".$new_ver[$i]['ver_2']."','".$new_ver[$i]['ver_3']."')");
  111. }
  112. }
  113. }
  114.  
  115. // запрашиваемые занные
  116. if (isset($data_in['data']))return $data_in['data'];else return false;
  117. }
  118. elseif($license!==false)
  119. {
  120. $license['last_update']=time();
  121. @unlink(H.'sys/license/'.$data_in['lic_info']['url']);
  122. @file_put_contents(H.'sys/license/'.$data_in['lic_info']['url'], serialize($license));
  123. }
  124. else return false;
  125. }
  126.  
  127.  
  128. $license=lic_dcms_loc(); // получение локальной лицензии
  129.  
  130. if (!isset($nolicupdate)){
  131. if (isset($license['last_update']) && $license['last_update']<time()-60*60*6)
  132. lic_dcms(); // обновление сведений раз в 6 часов
  133. }
  134. if (isset($compress) && $license==false)ob_start ("copyright2");
  135. ?>