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.

755 lines
31 KiB

2 years ago
2 years ago
2 years ago
2 years ago
3 weeks ago
2 years ago
2 years ago
3 weeks ago
2 years ago
3 weeks ago
2 years ago
11 months ago
3 weeks ago
11 months ago
2 years ago
3 weeks ago
2 years ago
3 weeks ago
2 years ago
3 weeks ago
2 years ago
3 weeks ago
2 years ago
3 weeks ago
2 years ago
11 months ago
3 weeks ago
11 months ago
3 weeks ago
11 months ago
3 weeks ago
11 months ago
3 weeks ago
11 months ago
3 weeks ago
11 months ago
2 years ago
3 weeks ago
2 years ago
3 weeks ago
2 years ago
3 weeks ago
1 year ago
2 years ago
1 year ago
2 years ago
3 weeks ago
2 years ago
1 year ago
3 weeks ago
2 years ago
11 months ago
2 years ago
3 weeks ago
2 years ago
11 months ago
1 year ago
11 months ago
2 years ago
11 months ago
2 years ago
2 years ago
2 years ago
2 years ago
4 months ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
11 months ago
11 months ago
2 years ago
2 years ago
2 years ago
9 months ago
2 years ago
11 months ago
2 years ago
2 years ago
1 year ago
1 year ago
2 years ago
  1. <?php
  2. namespace app\controller;
  3. use think\facade\Db;
  4. use think\facade\Cache;
  5. use app\BaseController;
  6. use app\lib\Plugins;
  7. class Api extends BaseController
  8. {
  9. //获取插件列表
  10. public function get_plugin_list(){
  11. if(!$this->checklist()) return json('你的服务器被禁止使用此云端');
  12. $record = Db::name('record')->where('ip',$this->clientip)->find();
  13. if($record){
  14. Db::name('record')->where('id',$record['id'])->update(['usetime'=>date("Y-m-d H:i:s")]);
  15. }else{
  16. Db::name('record')->insert(['ip'=>$this->clientip, 'addtime'=>date("Y-m-d H:i:s"), 'usetime'=>date("Y-m-d H:i:s")]);
  17. }
  18. $json_arr = Plugins::get_plugin_list();
  19. if(!$json_arr) $json_arr = (object)[];
  20. return json($json_arr);
  21. }
  22. //获取插件列表(win)
  23. public function get_plugin_list_win(){
  24. if(!$this->checklist()) return json('你的服务器被禁止使用此云端');
  25. $os_version = input('post.os_version');
  26. $serverid = input('post.serverid');
  27. $uid = input('post.uid');
  28. $record = Db::name('record')->where('ip',$this->clientip)->find();
  29. if($record){
  30. Db::name('record')->where('id',$record['id'])->update(['usetime'=>date("Y-m-d H:i:s")]);
  31. }else{
  32. Db::name('record')->insert(['ip'=>$this->clientip, 'addtime'=>date("Y-m-d H:i:s"), 'usetime'=>date("Y-m-d H:i:s")]);
  33. }
  34. $json_arr = Plugins::get_plugin_list('Windows');
  35. if(!$json_arr) $json_arr = (object)[];
  36. if($os_version == 'windows_go'){
  37. return Plugins::encrypt_plugin_list($json_arr, $serverid, $uid);
  38. }
  39. return json($json_arr);
  40. }
  41. //获取插件列表(aapanel)
  42. public function get_plugin_list_en(){
  43. if(!$this->checklist()) return json('你的服务器被禁止使用此云端');
  44. $record = Db::name('record')->where('ip',$this->clientip)->find();
  45. if($record){
  46. Db::name('record')->where('id',$record['id'])->update(['usetime'=>date("Y-m-d H:i:s")]);
  47. }else{
  48. Db::name('record')->insert(['ip'=>$this->clientip, 'addtime'=>date("Y-m-d H:i:s"), 'usetime'=>date("Y-m-d H:i:s")]);
  49. }
  50. $json_arr = Plugins::get_plugin_list('en');
  51. if(!$json_arr) $json_arr = (object)[];
  52. return json($json_arr);
  53. }
  54. //下载插件包
  55. public function download_plugin(){
  56. $plugin_name = input('param.name');
  57. $version = input('param.version');
  58. $os = input('param.os');
  59. if(!$plugin_name || !$version){
  60. return json(['status'=>false, 'msg'=>'参数不能为空']);
  61. }
  62. if(!in_array($os,['Windows','Linux'])) $os = 'Linux';
  63. if(!preg_match('/^[a-zA-Z0-9_]+$/', $plugin_name) || !preg_match('/^[0-9.]+$/', $version)){
  64. return json(['status'=>false, 'msg'=>'参数不正确']);
  65. }
  66. if(!$this->checklist()) return json(['status'=>false, 'msg'=>'你的服务器被禁止使用此云端']);
  67. $filepath = get_data_dir($os).'plugins/package/'.$plugin_name.'-'.$version.'.zip';
  68. if(file_exists($filepath)){
  69. $filename = $plugin_name.'.zip';
  70. $this->output_file($filepath, $filename);
  71. }else{
  72. return json(['status'=>false, 'msg'=>'云端不存在该插件包']);
  73. }
  74. }
  75. //下载插件包aapanel
  76. public function download_plugin_en(){
  77. $plugin_name = input('param.name');
  78. $version = input('param.version');
  79. if(!$plugin_name || !$version){
  80. return json(['status'=>false, 'msg'=>'参数不能为空']);
  81. }
  82. if(!preg_match('/^[a-zA-Z0-9_]+$/', $plugin_name) || !preg_match('/^[0-9.]+$/', $version)){
  83. return json(['status'=>false, 'msg'=>'参数不正确']);
  84. }
  85. if(!$this->checklist()) return json(['status'=>false, 'msg'=>'你的服务器被禁止使用此云端']);
  86. $filepath = get_data_dir('en').'plugins/package/'.$plugin_name.'-'.$version.'.zip';
  87. if(file_exists($filepath)){
  88. $filename = $plugin_name.'.zip';
  89. $this->output_file($filepath, $filename);
  90. }else{
  91. return json(['status'=>false, 'msg'=>'云端不存在该插件包']);
  92. }
  93. }
  94. //下载插件主文件
  95. public function download_plugin_main(){
  96. $plugin_name = input('post.name');
  97. $version = input('post.version');
  98. $os = input('post.os');
  99. if(!$plugin_name || !$version){
  100. return json(['status'=>false, 'msg'=>'参数不能为空']);
  101. }
  102. if(!in_array($os,['Windows','Linux'])) $os = 'Linux';
  103. if(!preg_match('/^[a-zA-Z0-9_]+$/', $plugin_name) || !preg_match('/^[0-9.]+$/', $version)){
  104. return json(['status'=>false, 'msg'=>'参数不正确']);
  105. }
  106. if(!$this->checklist()) return json(['status'=>false, 'msg'=>'你的服务器被禁止使用此云端']);
  107. $filepath = get_data_dir($os).'plugins/package/'.$plugin_name.'-'.$version.'.zip';
  108. $mainfilepath = get_data_dir($os).'plugins/folder/'.$plugin_name.'-'.$version.'/'.$plugin_name.'/'.$plugin_name.'_main.py';
  109. if(file_exists($mainfilepath)){
  110. $filename = $plugin_name.'_main.py';
  111. $this->output_file($mainfilepath, $filename);
  112. }elseif(file_exists($filepath)){
  113. $zip = new \ZipArchive;
  114. if ($zip->open($filepath) === true){
  115. echo $zip->getFromName($plugin_name.'/'.$plugin_name.'_main.py');
  116. }else{
  117. return json(['status'=>false, 'msg'=>'插件包解压缩失败']);
  118. }
  119. }else{
  120. return json(['status'=>false, 'msg'=>'云端不存在该插件主文件']);
  121. }
  122. }
  123. //下载插件其他文件
  124. public function download_plugin_other(){
  125. $fname = input('get.fname');
  126. if(!$fname){
  127. $fname = input('get.filename');
  128. if(!$fname){
  129. return json(['status'=>false, 'msg'=>'参数不能为空']);
  130. }
  131. }
  132. if(strpos(dirname($fname),'.')!==false)return json(['status'=>false, 'msg'=>'参数不正确']);
  133. if(!$this->checklist()) return json(['status'=>false, 'msg'=>'你的服务器被禁止使用此云端']);
  134. $filepath = get_data_dir().'plugins/other/'.$fname;
  135. if(file_exists($filepath)){
  136. $filename = basename($fname);
  137. $this->output_file($filepath, $filename);
  138. }else{
  139. return json(['status'=>false, 'msg'=>'云端不存在该插件文件']);
  140. }
  141. }
  142. public function get_plugin_auth(){
  143. $productids = ["8","9","10","11","12","13","14","15","16","17","18","19","20","22","23","24","25","26","28","32","33","42","44","45","47","55","65","69","75","82","83","85","90","91","97","99","101","107","108","110","118","121","127","128","132","135","136","140","143","144","151","154","156","161","163","167","173","179","183","185","190","192","195","197","200","201","202","203","204","205","206","207","208","212","213","214","215","216","217","218","219","220","221","222","223","224","225","226","227","228","229","230","231","232","233","234","235","236","237","238","239","241","243","244","245","246","247","248","249","250","251","252","253","254","255","256","257","258","259","261","262","263","264","265","266","267","268","269","270","271","272","273","274","275","276","277","278","279","280","281","282","283","284","285","286","287","289","292","293","295","296","297","298","299","300","301","302","303","304","305","306","307","308","309","310","311","312","313","314","315","316","317","318","319","320","321","322","323","324","325","326","327","328","329","330","331","332","334","335","336","337","338","339","340","341","342","343","344","345","346","347","348","349","350","351","352","353","354","355","356","357","358","359","360","361","362","363","364","365","366","368","369","371","372","373","374","375","376","377","378","379","380","381","382","383","384","385","386","387","388","389","390","391","392","393","394","397","398","400","401","406","408","409","411","413","415","419","423","425","427","429","430","1111111","100000001","100000005","100000007","100000008","100000009","100000010","100000012","100000014","100000015","100000016","100000017","100000035","100000036","100000039","100000040","100000041","100000042","100000045","100000053","100000054","100000056","100000057","100000058","100000059","100000062","100000063","100000067","100000069","100000070","100000076","100000077","100000078","100000079","100000080","100000084","100000085","100000088","100000089","100000090","100000091","100000092","100000093","100000094","100000095","100000096","100000097","100000098"];
  144. $os_version = input('post.os_version');
  145. $address = input('post.address','');
  146. $uid = input('post.uid','');
  147. $username = input('post.username','');
  148. $serverid = input('post.serverid','');
  149. $mac = input('post.mac','');
  150. $data = ['ip'=>$address, 'uid'=>$uid, 'username'=>$username, 'serverid'=>$serverid, 'lasttime'=>time(), 'pro'=>-1, 'skey'=>'', 'ltd'=>strtotime('+10 year'), 'list'=>[]];
  151. foreach($productids as $pid){
  152. $data['list'][$pid] = strtotime('+10 year');
  153. }
  154. return Plugins::encrypt_plugin_list($data, $serverid, $uid);
  155. }
  156. public function get_plugin_auth_win(){
  157. $productids = ["49","50","51","52","53","54","56","57","58","59","60","61","67","68","72","76","80","84","88","89","92","93","119","120","133","134","137","138","139","142","145","146","150","168","169","170","172","176","184","396","404","414","420","422","424","426","428","100000001","100000018","100000019","100000024","100000026","100000027","100000028","100000031","100000039","100000043","100000047","100000048","100000049","100000051","100000052","100000060","100000061","100000064","100000067","100000075"];
  158. $os_version = input('post.os_version');
  159. $address = input('post.address','');
  160. $uid = input('post.uid','');
  161. $username = input('post.username','');
  162. $serverid = input('post.serverid','');
  163. $mac = input('post.mac','');
  164. $data = ['ip'=>$address, 'uid'=>$uid, 'username'=>$username, 'serverid'=>$serverid, 'lasttime'=>time(), 'pro'=>-1, 'skey'=>'', 'ltd'=>strtotime('+10 year'), 'list'=>[]];
  165. foreach($productids as $pid){
  166. $data['list'][$pid] = strtotime('+10 year');
  167. }
  168. return Plugins::encrypt_plugin_list($data, $serverid, $uid);
  169. }
  170. public function get_update_logs(){
  171. $type = input('get.type');
  172. if($type == 'Windows'){
  173. $version = config_get('new_version_win');
  174. $data = [
  175. [
  176. 'title' => 'Linux面板'.$version,
  177. 'body' => config_get('update_msg_win'),
  178. 'addtime' => config_get('update_date_win')
  179. ]
  180. ];
  181. }else{
  182. $version = config_get('new_version');
  183. $data = [
  184. [
  185. 'title' => 'Linux面板'.$version,
  186. 'body' => config_get('update_msg'),
  187. 'addtime' => config_get('update_date')
  188. ]
  189. ];
  190. }
  191. return jsonp($data);
  192. }
  193. public function get_version(){
  194. $version = config_get('new_version');
  195. return $version;
  196. }
  197. public function get_version_win(){
  198. $version = config_get('new_version_win');
  199. return $version;
  200. }
  201. public function get_version_en(){
  202. $version = config_get('new_version_en');
  203. return $version;
  204. }
  205. public function get_panel_version(){
  206. $version = config_get('new_version');
  207. $file = app()->getRootPath().'public/install/update/LinuxPanel-'.$version.'.zip';
  208. $hash = hash_file('sha256', $file);
  209. $data = [
  210. 'version' => $version,
  211. 'hash' => $hash,
  212. 'update_time' => filemtime($file),
  213. ];
  214. return json($data);
  215. }
  216. public function get_panel_version_v2(){
  217. $version = config_get('new_version');
  218. $down_url = request()->root(true).'/install/update/LinuxPanel-'.$version.'.zip';
  219. $data = [
  220. 'OfficialVersion' => [
  221. 'version' => $version,
  222. 'downUrl' => $down_url,
  223. 'updateMsg' => config_get('update_msg'),
  224. 'uptime' => config_get('update_date'),
  225. ],
  226. 'OfficialVersionLatest' => [],
  227. 'AccountVersion' => [],
  228. ];
  229. return json($data);
  230. }
  231. //安装统计
  232. public function setup_count(){
  233. return 'ok';
  234. }
  235. //检测更新
  236. public function check_update(){
  237. $version = config_get('new_version');
  238. $down_url = request()->root(true).'/install/update/LinuxPanel-'.$version.'.zip';
  239. $data = [
  240. 'force' => false,
  241. 'version' => $version,
  242. 'downUrl' => $down_url,
  243. 'updateMsg' => config_get('update_msg'),
  244. 'uptime' => config_get('update_date'),
  245. 'is_beta' => 0,
  246. 'adviser' => -1,
  247. 'btb' => '',
  248. 'beta' => [
  249. 'version' => $version,
  250. 'downUrl' => $down_url,
  251. 'updateMsg' => config_get('update_msg'),
  252. 'uptime' => config_get('update_date'),
  253. ]
  254. ];
  255. return json($data);
  256. }
  257. //检测更新(win)
  258. public function check_update_win(){
  259. $version = config_get('new_version_win');
  260. $down_url = request()->root(true).'/win/panel/panel_'.$version.'.zip';
  261. $data = [
  262. 'force' => false,
  263. 'version' => $version,
  264. 'downUrl' => $down_url,
  265. 'updateMsg' => config_get('update_msg_win'),
  266. 'uptime' => config_get('update_date_win'),
  267. 'is_beta' => 0,
  268. 'py_version' => '3.8.6',
  269. 'adviser' => -1,
  270. 'is_rec' => -1,
  271. 'btb' => '',
  272. 'beta' => [
  273. 'py_version' => '3.8.6',
  274. 'version' => $version,
  275. 'downUrl' => $down_url,
  276. 'updateMsg' => config_get('update_msg_win'),
  277. 'uptime' => config_get('update_date_win'),
  278. ]
  279. ];
  280. return json($data);
  281. }
  282. //检测更新(aapanel)
  283. public function check_update_en(){
  284. $version = config_get('new_version_en');
  285. $down_url = request()->root(true).'/install/update/LinuxPanel_EN-'.$version.'.zip';
  286. $data = [
  287. 'force' => false,
  288. 'version' => $version,
  289. 'downUrl' => $down_url,
  290. 'updateMsg' => config_get('update_msg_en'),
  291. 'uptime' => config_get('update_date_en'),
  292. 'is_beta' => 0,
  293. 'btb' => '',
  294. 'beta' => [
  295. 'version' => $version,
  296. 'downUrl' => $down_url,
  297. 'updateMsg' => config_get('update_msg_en'),
  298. 'uptime' => config_get('update_date_en'),
  299. ]
  300. ];
  301. return json($data);
  302. }
  303. //宝塔云监控获取最新版本
  304. public function btm_latest_version(){
  305. $data = [
  306. 'version' => config_get('new_version_btm'),
  307. 'description' => config_get('update_msg_btm'),
  308. 'create_time' => config_get('update_date_btm')
  309. ];
  310. return json($data);
  311. }
  312. //宝塔云监控更新日志
  313. public function btm_update_history(){
  314. $data = [
  315. [
  316. 'version' => config_get('new_version_btm'),
  317. 'description' => config_get('update_msg_btm'),
  318. 'create_time' => config_get('update_date_btm')
  319. ]
  320. ];
  321. return json($data);
  322. }
  323. //宝塔云WAF最新版本
  324. public function btwaf_latest_version(){
  325. $type = input('?post.type') ? input('post.type') : 0;
  326. if($type == 1){
  327. $data = [
  328. 'version' => '1.1',
  329. 'description' => '暂无更新日志',
  330. 'create_time' => 1705315163,
  331. ];
  332. }else{
  333. $data = [
  334. 'version' => '3.0',
  335. 'description' => '暂无更新日志',
  336. 'create_time' => 1705315163,
  337. ];
  338. }
  339. $data = bin2hex(json_encode($data));
  340. return json(['status'=>true,'err_no'=>0,'msg'=>'获取成功','data'=>$data]);
  341. }
  342. //宝塔云控版本信息
  343. public function cloudc_version_info(){
  344. return json(['status'=>true,'msg'=>'获取成功','data'=>[
  345. 'version' => '1.0.5',
  346. 'download' => '',
  347. 'uptime' => '2025/06/16',
  348. 'upmsg' => '暂无更新日志'
  349. ]]);
  350. }
  351. //宝塔云控版本信息
  352. public function cloudc_get_version(){
  353. return json(['status'=>true,'msg'=>'','oid'=>'','data'=>[
  354. 'officialVersion' => [
  355. 'version' => '1.0.5',
  356. 'download' => '',
  357. 'uptime' => '2025/06/16',
  358. 'updateMsg' => '暂无更新日志'
  359. ],
  360. ]]);
  361. }
  362. //宝塔云控授权信息
  363. public function cloudc_order_status(){
  364. $data = [
  365. 'status' => true,
  366. 'msg' => '获取成功',
  367. 'oid' => '',
  368. 'data' => [
  369. 'id' => 1,
  370. 'address' => real_ip(),
  371. 'buytime' => time(),
  372. 'endtime' => time() + 86400 * 3650,
  373. 'num' => 9999,
  374. 'max_num' => 9999,
  375. 'pid' => 100000023,
  376. 'renew_price' => 0,
  377. 'state' => 1,
  378. ]
  379. ];
  380. return json($data);
  381. }
  382. //获取内测版更新日志
  383. public function get_beta_logs(){
  384. return json(['beta_ps'=>'当前暂无内测版', 'list'=>[]]);
  385. }
  386. //检查用户绑定是否正确
  387. public function check_auth_key(){
  388. return '1';
  389. }
  390. //从云端验证域名是否可访问
  391. public function check_domain(){
  392. $domain = input('post.domain',null,'trim');
  393. $ssl = input('post.ssl/d');
  394. if(!$domain) return json(['status'=>false, 'msg'=>'域名不能为空']);
  395. if(!strpos($domain,'.')) return json(['status'=>false, 'msg'=>'域名格式不正确']);
  396. $domain = str_replace('*.','',$domain);
  397. $ip = gethostbyname($domain);
  398. if(!$ip || $ip == $domain){
  399. return json(['status'=>false, 'msg'=>'无法访问']);
  400. }else{
  401. return json(['status'=>true, 'msg'=>'访问正常']);
  402. }
  403. }
  404. //同步时间
  405. public function get_time(){
  406. return time();
  407. }
  408. //同步时间
  409. public function get_win_date(){
  410. return date("Y-m-d H:i:s");
  411. }
  412. //查询是否专业版(废弃)
  413. public function is_pro(){
  414. return json(['endtime'=>true, 'code'=>1]);
  415. }
  416. //获取产品推荐信息
  417. public function get_plugin_remarks(){
  418. return json(['list'=>[], 'pro_list'=>[], 'kfqq'=>'', 'kf'=>'', 'qun'=>'']);
  419. }
  420. //获取指定插件评分
  421. public function get_plugin_socre(){
  422. return json(['total'=>0, 'split'=>[0,0,0,0,0],'page'=>"<div><span class='Pcurrent'>1</span><span class='Pcount'>共计0条数据</span></div>",'data'=>[]]);
  423. }
  424. //提交插件评分
  425. public function plugin_score(){
  426. return json(['status'=>true, 'msg'=>'您的评分已成功提交,感谢您的支持!']);
  427. }
  428. //获取IP地址
  429. public function get_ip_address(){
  430. return $this->clientip;
  431. }
  432. //绑定账号
  433. public function get_auth_token(){
  434. if(!input('?post.data')) return json(['status'=>false, 'msg'=>'参数不能为空']);
  435. $reqData = hex2bin(input('post.data'));
  436. parse_str($reqData, $arr);
  437. $serverid = $arr['serverid'];
  438. $userinfo = ['uid'=>1, 'username'=>'Administrator', 'address'=>'127.0.0.1', 'serverid'=>$serverid, 'access_key'=>random(48), 'secret_key'=>random(48), 'ukey'=>md5(time()), 'state'=>1];
  439. $data = bin2hex(json_encode($userinfo));
  440. return json(['status'=>true, 'msg'=>'登录成功!', 'data'=>$data]);
  441. }
  442. //绑定账号新
  443. public function authorization_login(){
  444. if(!input('?post.data')) return json(['status'=>false, 'msg'=>'参数不能为空']);
  445. $reqData = hex2bin(input('post.data'));
  446. parse_str($reqData, $arr);
  447. $serverid = $arr['serverid'];
  448. $userinfo = ['uid'=>1, 'username'=>'Administrator', 'ip'=>'127.0.0.1', 'server_id'=>$serverid, 'access_key'=>random(48), 'secret_key'=>random(48)];
  449. $data = bin2hex(json_encode($userinfo));
  450. return json(['status'=>true, 'err_no'=>0, 'msg'=>'账号绑定成功', 'data'=>$data]);
  451. }
  452. //刷新授权信息
  453. public function authorization_info(){
  454. if(!input('?post.data')) return json(['status'=>false, 'msg'=>'参数不能为空']);
  455. $reqData = hex2bin(input('post.data'));
  456. parse_str($reqData, $arr);
  457. $id = isset($arr['id'])&&$arr['id']>0?$arr['id']:1;
  458. $userinfo = ['id'=>$id, 'product'=>$arr['product'], 'status'=>2, 'clients'=>9999, 'durations'=>0, 'end_time'=>strtotime('+10 year')];
  459. $data = bin2hex(json_encode($userinfo));
  460. return json(['status'=>true, 'err_no'=>0, 'data'=>$data]);
  461. }
  462. //刷新授权信息
  463. public function update_license(){
  464. if(!input('?post.data')) return json(['status'=>false, 'msg'=>'参数不能为空']);
  465. $reqData = hex2bin(input('post.data'));
  466. parse_str($reqData, $arr);
  467. if(!isset($arr['product']) || !isset($arr['serverid'])) return json(['status'=>false, 'msg'=>'缺少参数']);
  468. $license_data = ['product'=>$arr['product'], 'uid'=>random(32), 'phone'=>'138****8888', 'auth_id'=>random(32), 'server_id'=>substr($arr['serverid'], 0, 32), 'auth'=>['apis'=>[], 'menu'=>[], 'extra'=>['type'=>3,'location'=>-1,'smart_cc'=>-1,'site'=>0]], 'pages'=>[], 'end_time'=>strtotime('+10 year')];
  469. $json = json_encode($license_data);
  470. [$public_key, $private_key] = generateKeyPairs();
  471. $public_key = pemToBase64($public_key);
  472. $key1 = random(32);
  473. $key2 = substr($public_key, 0, 32);
  474. $encrypted1 = licenseEncrypt($json, $key1);
  475. $encrypted2 = licenseEncrypt($key1, $key2);
  476. $sign_data = $encrypted1.'.'.$encrypted2;
  477. openssl_sign($sign_data, $signature, $private_key, OPENSSL_ALGO_SHA256);
  478. $signature = base64_encode($signature);
  479. $license = base64_encode($sign_data.'.'.$signature);
  480. $data = bin2hex(json_encode(['public_key'=>$public_key, 'license'=>$license]));
  481. return json(['status'=>true, 'err_no'=>0, 'msg'=>'授权获取成功', 'data'=>$data]);
  482. }
  483. public function is_obtained_btw_trial(){
  484. $data = ['is_obtained'=>0];
  485. $data = bin2hex(json_encode($data));
  486. return json(['status'=>true, 'err_no'=>0, 'data'=>$data, 'msg'=>'检测成功']);
  487. }
  488. //一键部署列表
  489. public function get_deplist(){
  490. $os = input('post.os');
  491. $json_arr = Plugins::get_deplist($os);
  492. if(!$json_arr) return json([]);
  493. return json($json_arr);
  494. }
  495. //获取宝塔SSL列表
  496. public function get_ssl_list(){
  497. $data = bin2hex('[]');
  498. return json(['status'=>true, 'msg'=>'', 'data'=>$data]);
  499. }
  500. //获取堡塔云WAF恶意IP库
  501. public function get_malicious_ip_list()
  502. {
  503. $cacheKey = 'malicious_ip_list';
  504. // 尝试从缓存获取
  505. if (Cache::has($cacheKey)) {
  506. return json(json_decode(Cache::get($cacheKey), true));
  507. }
  508. $url = 'https://api.bt.cn/bt_waf/get_malicious_ip';
  509. $postData = json_encode([
  510. 'x_bt_token' => 'MzI3YjAzOGQ3Yjk3NjUxYjVlMDkyMGFm'
  511. ]);
  512. $ch = curl_init();
  513. curl_setopt($ch, CURLOPT_URL, $url);
  514. curl_setopt($ch, CURLOPT_POST, 1);
  515. curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
  516. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  517. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  518. 'Content-Type: application/json',
  519. 'Content-Length: ' . strlen($postData)
  520. ]);
  521. $response = curl_exec($ch);
  522. if (curl_errno($ch)) {
  523. return json(['status'=>true, 'msg'=>'', 'data'=>bin2hex('[]')]);
  524. }
  525. curl_close($ch);
  526. Cache::set($cacheKey, $response, 86400); //缓存一天
  527. return json(json_decode($response, true));
  528. }
  529. public function return_success(){
  530. return json(['status'=>true, 'msg'=>1, 'data'=>(object)[]]);
  531. }
  532. public function return_error(){
  533. return json(['status'=>false, 'msg'=>'不支持当前操作']);
  534. }
  535. public function return_error2(){
  536. return json(['success'=>false, 'res'=>'不支持当前操作']);
  537. }
  538. public function return_empty(){
  539. return '';
  540. }
  541. public function return_empty_array(){
  542. return json([]);
  543. }
  544. public function return_page_data(){
  545. return json(['page'=>"<div><span class='Pcurrent'>1</span><span class='Pnumber'>1/0</span><span class='Pline'>从1-1000条</span><span class='Pcount'>共计0条数据</span></div>", 'data'=>[]]);
  546. }
  547. public function nps_check(){
  548. return json(['err_no'=>0, 'success'=>true, 'res'=>true, 'nonce'=>time()]);
  549. }
  550. public function nps_questions(){
  551. return json(['err_no'=>0, 'success'=>true, 'res'=>[], 'nonce'=>time()]);
  552. }
  553. public function nps_submit(){
  554. return json(['err_no'=>0, 'success'=>true, 'res'=>'Success', 'nonce'=>time()]);
  555. }
  556. public function get_user_give_away(){
  557. return json(['no_exceed_limit'=>false, 'user_give'=>true]);
  558. }
  559. //获取所有蜘蛛IP列表
  560. public function btwaf_getspiders(){
  561. try{
  562. $result = Plugins::btwaf_getspiders();
  563. return json($result);
  564. }catch(\Exception $e){
  565. return json(['status'=>false, 'msg'=>$e->getMessage()]);
  566. }
  567. }
  568. //分类获取蜘蛛IP列表
  569. public function get_spider(){
  570. $type = input('get.spider/d');
  571. if(!$type) return json([]);
  572. $result = Plugins::get_spider($type);
  573. return json($result);
  574. }
  575. //获取堡塔恶意情报IP库
  576. public function btwaf_getmalicious(){
  577. try{
  578. $result = Plugins::btwaf_getmalicious();
  579. return json($result);
  580. }catch(\Exception $e){
  581. return json(['success'=>false, 'res'=>$e->getMessage()]);
  582. }
  583. }
  584. //检查是否国内IP
  585. public function check_cnip(){
  586. $clientip = bindec(decbin(ip2long($this->clientip)));
  587. $json_file = app()->getBasePath().'lib/cn.json';
  588. $arr = json_decode(file_get_contents($json_file), true);
  589. if(!$arr) return 'False';
  590. foreach($arr as $ip_arr){
  591. if($clientip >= $ip_arr[0] && $clientip <= $ip_arr[1]){
  592. return 'True';
  593. }
  594. }
  595. return 'False';
  596. }
  597. //邮件配额
  598. public function email_user_surplus(){
  599. $data = [
  600. 'free' => ['surplus' => '120000', 'total' => '120000', 'used' => '0'],
  601. 'period' => ['surplus' => '2000000', 'total' => '2000000', 'used' => '0'],
  602. ];
  603. return json(['success'=>true, 'msg'=>'获取成功', 'res'=>$data]);
  604. }
  605. //检查黑白名单
  606. private function checklist(){
  607. if(config_get('whitelist') == 1){
  608. if(Db::name('white')->where('ip', $this->clientip)->where('enable', 1)->find()){
  609. return true;
  610. }
  611. return false;
  612. }else{
  613. if(Db::name('black')->where('ip', $this->clientip)->where('enable', 1)->find()){
  614. return false;
  615. }
  616. return true;
  617. }
  618. }
  619. //下载大文件
  620. private function output_file($filepath, $filename){
  621. $filesize = filesize($filepath);
  622. $filemd5 = md5_file($filepath);
  623. ob_clean();
  624. header("Content-Type: application/octet-stream");
  625. header("Content-Disposition: attachment; filename={$filename}.zip");
  626. header("Content-Length: {$filesize}");
  627. header("File-size: {$filesize}");
  628. header("Content-md5: {$filemd5}");
  629. $read_buffer = 1024 * 100;
  630. $handle = fopen($filepath, 'rb');
  631. $sum_buffer = 0;
  632. while(!feof($handle) && $sum_buffer<$filesize) {
  633. echo fread($handle, min($read_buffer, ($filesize - $sum_buffer) + 1));
  634. $sum_buffer += $read_buffer;
  635. flush();
  636. }
  637. fclose($handle);
  638. exit;
  639. }
  640. public function logerror(){
  641. $content = date('Y-m-d H:i:s')."\r\n";
  642. $content.=$_SERVER['REQUEST_METHOD'].' '.$_SERVER['REQUEST_URI']."\r\n";
  643. if($_SERVER['REQUEST_METHOD'] == 'POST'){
  644. $content.=file_get_contents('php://input')."\r\n";
  645. }
  646. $handle = fopen(app()->getRootPath()."record.txt", 'a');
  647. fwrite($handle, $content."\r\n");
  648. fclose($handle);
  649. return json(['status'=>false, 'msg'=>'不支持当前操作']);
  650. }
  651. //生成自签名SSL证书
  652. public function bt_cert(){
  653. $data = input('post.data');
  654. $param = json_decode($data, true);
  655. if(!$param || !isset($param['action']) || !isset($param['domain'])) return json(['status'=>false, 'msg'=>'参数错误']);
  656. $dir = app()->getBasePath().'script/';
  657. $ssl_path = app()->getRootPath().'public/ssl/baota_root.pfx';
  658. $isca = file_exists($dir.'ca.crt') && file_exists($dir.'ca.key') && file_exists($ssl_path);
  659. if(!$isca) return json(['status'=>false, 'msg'=>'CA证书不存在']);
  660. if($param['action'] == 'get_domain_cert'){
  661. if(!$this->checklist()) return json(['status'=>false, 'msg'=>'你的服务器被禁止使用此云端']);
  662. $domain = $param['domain'];
  663. if(empty($domain)) return json(['status'=>false, 'msg'=>'域名不能为空']);
  664. $domain_list = explode(',', $domain);
  665. foreach($domain_list as $d){
  666. if(!checkDomain($d)) return json(['status'=>false, 'msg'=>'域名或IP格式不正确:'.$d]);
  667. }
  668. $common_name = $domain_list[0];
  669. $validity = 3650;
  670. $result = makeSelfSignSSL($common_name, $domain_list, $validity);
  671. if(!$result){
  672. return json(['status'=>false, 'msg'=>'生成证书失败']);
  673. }
  674. $ca_pfx = base64_encode(file_get_contents($ssl_path));
  675. return json(['status'=>true, 'msg'=>'生成证书成功', 'cert'=>$result['cert'], 'key'=>$result['key'], 'pfx'=>$ca_pfx, 'password'=>'']);
  676. }else{
  677. return json(['status'=>false, 'msg'=>'不支持当前操作']);
  678. }
  679. }
  680. }