You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
6.5 KiB

2 years ago
2 months ago
2 years ago
2 months ago
1 month ago
2 months ago
2 years ago
2 months ago
2 years ago
2 months ago
2 years ago
1 year ago
2 years ago
  1. <?php
  2. namespace app\lib;
  3. use Exception;
  4. use ZipArchive;
  5. class Plugins
  6. {
  7. private static function get_btapi($os){
  8. if(self::is_third($os)){
  9. return new ThirdPlugins($os);
  10. }else{
  11. return new BtPlugins($os);
  12. }
  13. }
  14. private static function is_third($os){
  15. if($os == 'en'){
  16. $type = config_get('enbt_type');
  17. }elseif($os == 'Windows'){
  18. $type = config_get('wbt_type');
  19. }else{
  20. $type = config_get('bt_type');
  21. }
  22. return $type == 1;
  23. }
  24. //刷新插件列表
  25. public static function refresh_plugin_list($os = 'Linux'){
  26. $btapi = self::get_btapi($os);
  27. $result = $btapi->get_plugin_list();
  28. self::save_plugin_list($result, $os);
  29. }
  30. //保存插件列表
  31. private static function save_plugin_list($data, $os){
  32. $data['ip'] = '127.0.0.1';
  33. if($os == 'en'){
  34. $data['serverId'] = '';
  35. $data['aln'] = self::get_aln();
  36. $data['pro'] = 0;
  37. $data['pro_authorization_sn'] = '0';
  38. if(!empty($data['authorization_map'])){
  39. foreach($data['authorization_map'] as $code => &$plugin){
  40. if($code != '0' && isset($plugin['end_time'])) $plugin['end_time'] = 0;
  41. }
  42. }
  43. if(isset($data['expansions']['mail'])){
  44. $data['expansions']['mail']['total'] = 2000000;
  45. $data['expansions']['mail']['available'] = 2000000;
  46. }
  47. }else{
  48. $data['serverid'] = '';
  49. $data['aln'] = self::get_aln();
  50. $data['beta'] = 0;
  51. $data['uid'] = 1;
  52. $data['skey'] = '';
  53. $data['pro'] = -1;
  54. $data['ltd'] = strtotime('+10 year');
  55. }
  56. foreach($data['list'] as &$plugin){
  57. if(isset($plugin['endtime'])) $plugin['endtime'] = 0;
  58. }
  59. $json_file = get_data_dir($os).'config/plugin_list.json';
  60. if(!file_put_contents($json_file, json_encode($data))){
  61. throw new Exception('保存插件列表失败,文件无写入权限');
  62. }
  63. }
  64. //多账号数量
  65. private static function get_aln($count = '9999'){
  66. $key = 'FB8upo8XMgP5by54';
  67. $iv = 'lOrrq3lNEURZNdK7';
  68. return openssl_encrypt($count, 'aes-128-cbc', $key, 0, $iv);
  69. }
  70. //获取插件列表
  71. public static function get_plugin_list($os = 'Linux'){
  72. $json_file = get_data_dir($os).'config/plugin_list.json';
  73. if(file_exists($json_file)){
  74. $data = file_get_contents($json_file);
  75. $json_arr = json_decode($data, true);
  76. if($json_arr){
  77. return $json_arr;
  78. }
  79. }
  80. return false;
  81. }
  82. //获取一个插件信息
  83. public static function get_plugin_info($name, $os = 'Linux'){
  84. $json_arr = self::get_plugin_list($os);
  85. if(!$json_arr) return null;
  86. foreach($json_arr['list'] as $plugin){
  87. if($plugin['name'] == $name){
  88. return $plugin;
  89. }
  90. }
  91. return null;
  92. }
  93. //下载插件(自动判断是否第三方)
  94. public static function download_plugin($plugin_name, $version, $os = 'Linux'){
  95. $plugin_info = Plugins::get_plugin_info($plugin_name, $os);
  96. if(!$plugin_info) throw new Exception('未找到该插件信息');
  97. $btapi = self::get_btapi($os);
  98. $btapi->download_plugin($plugin_name, $version, $plugin_info);
  99. }
  100. //下载插件主程序文件
  101. public static function download_plugin_main($plugin_name, $version, $os = 'Linux'){
  102. $btapi = self::get_btapi($os);
  103. $btapi->download_plugin_main($plugin_name, $version);
  104. }
  105. //本地解密插件主程序文件
  106. public static function decode_plugin_main_local($main_filepath, $os = 'Linux'){
  107. $btapi = new BtPlugins($os);
  108. return $btapi->decode_plugin_main_local($main_filepath);
  109. }
  110. //本地解密模块文件
  111. public static function decode_module_file($filepath){
  112. $src = file_get_contents($filepath);
  113. if($src===false)throw new Exception('文件打开失败');
  114. if(!$src || strpos($src, 'import ')!==false)return 0;
  115. $key = 'Z2B87NEAS2BkxTrh';
  116. $iv = 'WwadH66EGWpeeTT6';
  117. $data_arr = explode("\n", $src);
  118. $de_text = '';
  119. foreach($data_arr as $data){
  120. $data = trim($data);
  121. if(!empty($data)){
  122. $tmp = openssl_decrypt($data, 'aes-128-cbc', $key, 0, $iv);
  123. if($tmp !== false) $de_text .= $tmp;
  124. }
  125. }
  126. if(!empty($de_text) && strpos($de_text, 'import ')!==false){
  127. file_put_contents($filepath, $de_text);
  128. return 1;
  129. }
  130. return 2;
  131. }
  132. //刷新一键部署列表
  133. public static function refresh_deplist($os = 'Linux'){
  134. $btapi = self::get_btapi($os);
  135. $result = $btapi->get_deplist();
  136. $json_file = get_data_dir($os).'config/deployment_list.json';
  137. if(!file_put_contents($json_file, json_encode($result))){
  138. throw new Exception('保存一键部署列表失败,文件无写入权限');
  139. }
  140. }
  141. //获取一键部署列表
  142. public static function get_deplist($os = 'Linux'){
  143. $json_file = get_data_dir($os).'config/deployment_list.json';
  144. if(file_exists($json_file)){
  145. $data = file_get_contents($json_file);
  146. $json_arr = json_decode($data, true);
  147. if($json_arr){
  148. return $json_arr;
  149. }
  150. }
  151. return false;
  152. }
  153. //获取蜘蛛IP列表
  154. public static function btwaf_getspiders(){
  155. $result = cache('btwaf_getspiders');
  156. if($result){
  157. return $result;
  158. }
  159. $btapi = self::get_btapi('Linux');
  160. $result = $btapi->btwaf_getspiders();
  161. cache('btwaf_getspiders', $result, 3600 * 24 * 3);
  162. return $result;
  163. }
  164. //分类获取蜘蛛IP列表
  165. public static function get_spider($type){
  166. $result = cache('get_spider_'.$type);
  167. if($result){
  168. return $result;
  169. }
  170. $url = 'https://www.bt.cn/api/panel/get_spider?spider='.$type;
  171. $data = get_curl($url);
  172. $result = json_decode($data, true);
  173. if(!$result) return [];
  174. cache('get_spider_'.$type, $result, 3600 * 24);
  175. return $result;
  176. }
  177. }