| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <?php
- namespace backend\modules\admin\controllers;
- use Yii;
- use backend\controllers\AdminController;
- use backend\modules\admin\services\BackupsService;
- use backend\modules\admin\services\ExpireNoticeService;
- use common\models\common\Backups;
- use Exception;
- /**
- * 过期提醒
- * @package backend\modules\admin\controllers
- */
- class ExpireNoticeController extends AdminController
- {
- /**
- * 配置页面
- *
- * @return mixed
- */
- public function actionIndex()
- {
- $service = new ExpireNoticeService();
- if (Yii::$app->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());
- }
- }
- }
- }
|