request->isAjax) { return $this->success('ok', $service->getConfig()); } return $this->render($this->action->id, ['isInstallSalary' => (int)$service->isInstallSalary()]); } /** * 提交配置 * * @return mixed */ public function actionSubmit() { if (Yii::$app->request->isPost) { $params = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['certificate', 'server'], 'required'], // [['ssl_path'], 'safe'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $service = new ExpireNoticeService(); return $service->setConfig($params) ? $this->success('保存成功') : $this->error('保存失败'); } } /** * 证书到期提醒 * * @return mixed */ public function actionCertificateNotice() { $service = new ExpireNoticeService(); return $this->success('ok', $service->certificateNotice()); } /** * 服务器到期提醒 * * @return mixed */ public function actionServerNotice() { $service = new ExpireNoticeService(); return $this->success('ok', $service->serverNotice()); } //备份管理 public function actionBackups() { $request = Yii::$app->request; try { if ($request->isAjax && $request->isGet) { $get = $request->get(); $res = Yii::$app->services->validate->validate($get, [ [['page', 'limit'], 'integer'], [['datetime'], 'safe'], ]); if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage()); $list = (new BackupsService())->getBackupsList($get); return $this->success('获取成功', $list); } } catch (\Exception $e) { $this->error($e->getMessage()); } return $this->render($this->action->id); } //下载 public function actionDown() { try{ $download_id = Yii::$app->request->get('download_id'); // ob_start(); $download = Backups::find()->where(['id' => $download_id])->one(); if (empty($download)) { $url = \Yii::$app->urlManager->createAbsoluteUrl('expire-notice/backups/index'); return $this->redirect($url, 301); } // $filename= $download->name; // $path_info = pathinfo($download->url); // // $file = fopen($filename, 'r'); // // $filestat = fstat($file); // $size=filesize($download->url); // header( "Content-type: application/octet-stream "); // header( "Accept-Ranges: bytes "); // header( "Content-Disposition: attachment; filename= {$filename}.".$path_info['extension']); // header( "Accept-Length: " .$size); $file_path = $download->url; $file_name = $download->name; // 打开文件 $file_handle = fopen($file_path, 'rb'); // 设置响应头信息 header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename={$file_name}"); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($file_path)); // 输出文件内容 while (!feof($file_handle)) { echo fread($file_handle, 1024); } // 关闭文件 fclose($file_handle); exit; }catch (\Exception $e){ $url = \Yii::$app->urlManager->createAbsoluteUrl('expire-notice/backups'); return $this->redirect($url, 301); } } //操作删除 public function actionDelete() { $request = Yii::$app->request; if ($request->isAjax && $request->isPost) { try { $post = $request->post(); $res = Yii::$app->services->validate->validate($post, [ [['id'], 'safe'], ]); if (!$res) throw new Exception(Yii::$app->services->validate->getErrorMessage()); $res = (new BackupsService())->deleteBackups($post); return $this->success('操作成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } } //开始备份 public function actionStartBackups() { $request = Yii::$app->request; if ($request->isAjax && $request->isPost) { try { $res = (new BackupsService())->startBackups(); return $this->success('数据备份中,消耗时间较长,请稍后再刷新页面查看'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } } }