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.

194 lines
6.5 KiB

2 years ago
2 months ago
2 years 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['ltd'] = strtotime('+10 year');
  54. }
  55. foreach($data['list'] as &$plugin){
  56. if(isset($plugin['endtime'])) $plugin['endtime'] = 0;
  57. }
  58. $json_file = get_data_dir($os).'config/plugin_list.json';
  59. if(!file_put_contents($json_file, json_encode($data))){
  60. throw new Exception('保存插件列表失败,文件无写入权限');
  61. }
  62. }
  63. //多账号数量
  64. private static function get_aln($count = '9999'){
  65. $key = 'FB8upo8XMgP5by54';
  66. $iv = 'lOrrq3lNEURZNdK7';
  67. return openssl_encrypt($count, 'aes-128-cbc', $key, 0, $iv);
  68. }
  69. //获取插件列表
  70. public static function get_plugin_list($os = 'Linux'){
  71. $json_file = get_data_dir($os).'config/plugin_list.json';
  72. if(file_exists($json_file)){
  73. $data = file_get_contents($json_file);
  74. $json_arr = json_decode($data, true);
  75. if($json_arr){
  76. return $json_arr;
  77. }
  78. }
  79. return false;
  80. }
  81. //获取一个插件信息
  82. public static function get_plugin_info($name, $os = 'Linux'){
  83. $json_arr = self::get_plugin_list($os);
  84. if(!$json_arr) return null;
  85. foreach($json_arr['list'] as $plugin){
  86. if($plugin['name'] == $name){
  87. return $plugin;
  88. }
  89. }
  90. return null;
  91. }
  92. //下载插件(自动判断是否第三方)
  93. public static function download_plugin($plugin_name, $version, $os = 'Linux'){
  94. $plugin_info = Plugins::get_plugin_info($plugin_name, $os);
  95. if(!$plugin_info) throw new Exception('未找到该插件信息');
  96. $btapi = self::get_btapi($os);
  97. $btapi->download_plugin($plugin_name, $version, $plugin_info);
  98. }
  99. //下载插件主程序文件
  100. public static function download_plugin_main($plugin_name, $version, $os = 'Linux'){
  101. $btapi = self::get_btapi($os);
  102. $btapi->download_plugin_main($plugin_name, $version);
  103. }
  104. //本地解密插件主程序文件
  105. public static function decode_plugin_main_local($main_filepath, $os = 'Linux'){
  106. $btapi = new BtPlugins($os);
  107. return $btapi->decode_plugin_main_local($main_filepath);
  108. }
  109. //本地解密模块文件
  110. public static function decode_module_file($filepath){
  111. $src = file_get_contents($filepath);
  112. if($src===false)throw new Exception('文件打开失败');
  113. if(!$src || strpos($src, 'import ')!==false)return 0;
  114. $key = 'Z2B87NEAS2BkxTrh';
  115. $iv = 'WwadH66EGWpeeTT6';
  116. $data_arr = explode("\n", $src);
  117. $de_text = '';
  118. foreach($data_arr as $data){
  119. $data = trim($data);
  120. if(!empty($data)){
  121. $tmp = openssl_decrypt($data, 'aes-128-cbc', $key, 0, $iv);
  122. if($tmp !== false) $de_text .= $tmp;
  123. }
  124. }
  125. if(!empty($de_text) && strpos($de_text, 'import ')!==false){
  126. file_put_contents($filepath, $de_text);
  127. return 1;
  128. }
  129. return 2;
  130. }
  131. //刷新一键部署列表
  132. public static function refresh_deplist($os = 'Linux'){
  133. $btapi = self::get_btapi($os);
  134. $result = $btapi->get_deplist();
  135. $json_file = get_data_dir($os).'config/deployment_list.json';
  136. if(!file_put_contents($json_file, json_encode($result))){
  137. throw new Exception('保存一键部署列表失败,文件无写入权限');
  138. }
  139. }
  140. //获取一键部署列表
  141. public static function get_deplist($os = 'Linux'){
  142. $json_file = get_data_dir($os).'config/deployment_list.json';
  143. if(file_exists($json_file)){
  144. $data = file_get_contents($json_file);
  145. $json_arr = json_decode($data, true);
  146. if($json_arr){
  147. return $json_arr;
  148. }
  149. }
  150. return false;
  151. }
  152. //获取蜘蛛IP列表
  153. public static function btwaf_getspiders(){
  154. $result = cache('btwaf_getspiders');
  155. if($result){
  156. return $result;
  157. }
  158. $btapi = self::get_btapi('Linux');
  159. $result = $btapi->btwaf_getspiders();
  160. cache('btwaf_getspiders', $result, 3600 * 24 * 3);
  161. return $result;
  162. }
  163. //分类获取蜘蛛IP列表
  164. public static function get_spider($type){
  165. $result = cache('get_spider_'.$type);
  166. if($result){
  167. return $result;
  168. }
  169. $url = 'https://www.bt.cn/api/panel/get_spider?spider='.$type;
  170. $data = get_curl($url);
  171. $result = json_decode($data, true);
  172. if(!$result) return [];
  173. cache('get_spider_'.$type, $result, 3600 * 24);
  174. return $result;
  175. }
  176. }