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.

631 lines
24 KiB

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