From aab8d7a8f2494f860423f59e44807a8ba4c99a45 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Fri, 4 Sep 2020 17:33:16 +0800 Subject: [PATCH] =?UTF-8?q?demo=E5=88=86=E6=94=AF=E8=BF=87=E6=BB=A4?= =?UTF-8?q?=E6=95=8F=E6=84=9F=E6=95=B0=E6=8D=AE=E4=BB=A5=E5=8F=8A=E9=99=90?= =?UTF-8?q?=E5=88=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Admin/Controllers/Controller.php | 11 +++ .../Admin/Controllers/PublicController.php | 4 + .../Admin/Controllers/SettingController.php | 26 +++--- app/Http/Admin/Services/Chapter.php | 1 - app/Http/Admin/Services/Course.php | 1 - app/Http/Admin/Services/Setting.php | 73 +++++++++++----- app/Http/Admin/Views/chapter/lessons.volt | 6 +- .../Admin/Views/chapter/lessons_live.volt | 16 ++-- app/Http/Admin/Views/chapter/lessons_vod.volt | 6 +- app/Http/Admin/Views/setting/live_notify.volt | 13 +-- app/Http/Admin/Views/setting/live_pull.volt | 25 +++--- app/Http/Admin/Views/setting/live_push.volt | 15 ++-- app/Http/Admin/Views/setting/smser.volt | 2 + app/Services/Live.php | 33 ++++---- app/Services/LiveNotify.php | 10 +-- .../20200827112717_insert_setting_data.php | 84 +++++++++++++------ 16 files changed, 202 insertions(+), 124 deletions(-) diff --git a/app/Http/Admin/Controllers/Controller.php b/app/Http/Admin/Controllers/Controller.php index 2704f7b3..2c3bb1f1 100644 --- a/app/Http/Admin/Controllers/Controller.php +++ b/app/Http/Admin/Controllers/Controller.php @@ -21,6 +21,17 @@ class Controller extends \Phalcon\Mvc\Controller public function beforeExecuteRoute(Dispatcher $dispatcher) { + /** + * demo分支拒绝数据提交 + */ + if ($this->isNotSafeRequest()) { + $dispatcher->forward([ + 'controller' => 'public', + 'action' => 'forbidden', + ]); + return false; + } + if ($this->isNotSafeRequest()) { $this->checkHttpReferer(); $this->checkCsrfToken(); diff --git a/app/Http/Admin/Controllers/PublicController.php b/app/Http/Admin/Controllers/PublicController.php index 04b8d8f1..5e0a1ab4 100644 --- a/app/Http/Admin/Controllers/PublicController.php +++ b/app/Http/Admin/Controllers/PublicController.php @@ -17,6 +17,8 @@ class PublicController extends \Phalcon\Mvc\Controller */ public function authAction() { + $this->response->setStatusCode(401); + if ($this->request->isAjax()) { return $this->jsonError(['msg' => '会话已过期,请重新登录']); } @@ -29,6 +31,8 @@ class PublicController extends \Phalcon\Mvc\Controller */ public function forbiddenAction() { + $this->response->setStatusCode(403); + if ($this->request->isAjax()) { return $this->jsonError(['msg' => '无相关操作权限']); } diff --git a/app/Http/Admin/Controllers/SettingController.php b/app/Http/Admin/Controllers/SettingController.php index 670c6700..c06cf6d6 100644 --- a/app/Http/Admin/Controllers/SettingController.php +++ b/app/Http/Admin/Controllers/SettingController.php @@ -31,7 +31,7 @@ class SettingController extends Controller $site = $settingService->getSectionSettings($section); - $site->base_url = $site->base_url ?: kg_site_base_url(); + $site['base_url'] = $site['base_url'] ?: kg_site_base_url(); $this->view->setVar('site', $site); } @@ -117,12 +117,12 @@ class SettingController extends Controller */ public function liveAction() { - $section = 'live'; - $settingService = new SettingService(); if ($this->request->isPost()) { + $section = $this->request->getPost('section'); + $data = $this->request->getPost(); $settingService->updateLiveSettings($section, $data); @@ -131,9 +131,13 @@ class SettingController extends Controller } else { - $live = $settingService->getLiveSettings(); + $push = $settingService->getLiveSettings('live.push'); + $pull = $settingService->getLiveSettings('live.pull'); + $notify = $settingService->getLiveSettings('live.notify'); - $this->view->setVar('live', $live); + $this->view->setVar('push', $push); + $this->view->setVar('pull', $pull); + $this->view->setVar('notify', $notify); } } @@ -156,13 +160,8 @@ class SettingController extends Controller } else { - $alipay = $settingService->getSectionSettings('pay.alipay'); - - $alipay->notify_url = $alipay->notify_url ?: kg_full_url(['for' => 'desktop.alipay_notify']); - - $wxpay = $settingService->getSectionSettings('pay.wxpay'); - - $wxpay->notify_url = $wxpay->notify_url ?: kg_full_url(['for' => 'desktop.wxpay_notify']); + $alipay = $settingService->getAlipaySettings(); + $wxpay = $settingService->getWxpaySettings(); $this->view->setVar('alipay', $alipay); $this->view->setVar('wxpay', $wxpay); @@ -190,10 +189,7 @@ class SettingController extends Controller $smser = $settingService->getSectionSettings($section); - $template = json_decode($smser->template); - $this->view->setVar('smser', $smser); - $this->view->setVar('template', $template); } } diff --git a/app/Http/Admin/Services/Chapter.php b/app/Http/Admin/Services/Chapter.php index 32cfcbad..6071a2f4 100644 --- a/app/Http/Admin/Services/Chapter.php +++ b/app/Http/Admin/Services/Chapter.php @@ -118,7 +118,6 @@ class Chapter extends Service $logger = $this->getLogger(); $logger->error('Create Chapter Error ' . kg_json_encode([ - 'line' => $e->getLine(), 'code' => $e->getCode(), 'message' => $e->getMessage(), ])); diff --git a/app/Http/Admin/Services/Course.php b/app/Http/Admin/Services/Course.php index 31a3fb3b..503e96b2 100644 --- a/app/Http/Admin/Services/Course.php +++ b/app/Http/Admin/Services/Course.php @@ -113,7 +113,6 @@ class Course extends Service $logger = $this->getLogger(); $logger->error('Create Course Error ' . kg_json_encode([ - 'line' => $e->getLine(), 'code' => $e->getCode(), 'message' => $e->getMessage(), ])); diff --git a/app/Http/Admin/Services/Setting.php b/app/Http/Admin/Services/Setting.php index a3502f58..68b7709c 100644 --- a/app/Http/Admin/Services/Setting.php +++ b/app/Http/Admin/Services/Setting.php @@ -9,17 +9,64 @@ use App\Repos\Vip as VipRepo; class Setting extends Service { + public function getAlipaySettings() + { + $alipay = $this->getSectionSettings('pay.alipay'); + + $alipay['notify_url'] = $alipay['notify_url'] ?: kg_full_url(['for' => 'desktop.alipay_notify']); + + return $alipay; + } + + public function getWxpaySettings() + { + $wxpay = $this->getSectionSettings('pay.wxpay'); + + $wxpay['notify_url'] = $wxpay['notify_url'] ?: kg_full_url(['for' => 'desktop.wxpay_notify']); + + return $wxpay; + } + + public function getVipSettings() + { + $vipRepo = new VipRepo(); + + return $vipRepo->findAll(['deleted' => 0]); + } + + public function getLiveSettings($section) + { + $result = $this->getSectionSettings($section); + + if ($section == 'live.notify') { + $result['stream_begin_url'] = $result['stream_begin_url'] ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'streamBegin']); + $result['stream_end_url'] = $result['stream_end_url'] ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'streamEnd']); + $result['record_url'] = $result['record_url'] ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'record']); + $result['snapshot_url'] = $result['snapshot_url'] ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'snapshot']); + $result['porn_url'] = $result['porn_url'] ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'porn']); + } + + return $result; + } + public function getSectionSettings($section) { $settingsRepo = new SettingRepo(); $items = $settingsRepo->findBySection($section); - $result = new \stdClass(); + $result = []; + /** + * demo分支过滤敏感数据 + */ if ($items->count() > 0) { foreach ($items as $item) { - $result->{$item->item_key} = $item->item_value; + $pattern = '/(auth|key|secret|pwd|password)/'; + if (preg_match($pattern, $item->item_key)) { + $item->item_value = '***'; + } + $result[$item->item_key] = $item->item_value; } } @@ -81,7 +128,9 @@ class Setting extends Service public function updateSmserSettings($section, $settings) { $template = $settings['template']; + $keys = array_keys($template['id']); + $myTemplate = []; foreach ($keys as $key) { @@ -96,13 +145,6 @@ class Setting extends Service $this->updateSectionSettings($section, $settings); } - public function getVipSettings() - { - $vipRepo = new VipRepo(); - - return $vipRepo->findAll(['deleted' => 0]); - } - public function updateVipSettings($items) { $vipRepo = new VipRepo(); @@ -114,17 +156,4 @@ class Setting extends Service } } - public function getLiveSettings() - { - $live = $this->getSectionSettings('live'); - - $live->notify_stream_begin_url = $live->notify_stream_begin_url ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'streamBegin']); - $live->notify_stream_end_url = $live->notify_stream_end_url ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'streamEnd']); - $live->notify_record_url = $live->notify_record_url ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'record']); - $live->notify_snapshot_url = $live->notify_snapshot_url ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'snapshot']); - $live->notify_porn_url = $live->notify_porn_url ?: kg_full_url(['for' => 'desktop.live_notify'], ['action' => 'porn']); - - return $live; - } - } diff --git a/app/Http/Admin/Views/chapter/lessons.volt b/app/Http/Admin/Views/chapter/lessons.volt index 26246c29..8ec5ab29 100644 --- a/app/Http/Admin/Views/chapter/lessons.volt +++ b/app/Http/Admin/Views/chapter/lessons.volt @@ -21,11 +21,11 @@ - {% if course.model == '1' %} + {% if course.model == 1 %} {{ partial('chapter/lessons_vod') }} - {% elseif course.model == '2' %} + {% elseif course.model == 2 %} {{ partial('chapter/lessons_live') }} - {% elseif course.model == '3' %} + {% elseif course.model == 3 %} {{ partial('chapter/lessons_read') }} {% endif %} diff --git a/app/Http/Admin/Views/chapter/lessons_live.volt b/app/Http/Admin/Views/chapter/lessons_live.volt index 3c280789..649374af 100644 --- a/app/Http/Admin/Views/chapter/lessons_live.volt +++ b/app/Http/Admin/Views/chapter/lessons_live.volt @@ -7,9 +7,13 @@ {% endif %} {%- endmacro %} -{%- macro live_status_info(attrs) %} - {% if attrs['stream']['status'] != 'active' %} - 直播中 +{%- macro live_status_info(status) %} + {% if status == 'active' %} + 活跃 + {% elseif status == 'inactive' %} + 沉默 + {% elseif status == 'forbid' %} + 禁播 {% endif %} {%- endmacro %} @@ -21,13 +25,15 @@ + 编号 名称 - 时间 + 直播时间 + 推流状态 排序 免费 发布 @@ -46,9 +52,9 @@ {{ item.title }} - {{ live_status_info(item.attrs) }} {{ live_time_info(item.attrs) }} + {{ live_status_info(item.attrs['stream']['status']) }} diff --git a/app/Http/Admin/Views/chapter/lessons_vod.volt b/app/Http/Admin/Views/chapter/lessons_vod.volt index 157e6a83..93777824 100644 --- a/app/Http/Admin/Views/chapter/lessons_vod.volt +++ b/app/Http/Admin/Views/chapter/lessons_vod.volt @@ -27,8 +27,8 @@ 编号 名称 - 视频状态 - 视频时长 + 状态 + 时长 排序 免费 发布 @@ -37,7 +37,7 @@ {% for item in lessons %} - {% set show_url = url({'for':'desktop.chapter.show','id':item.id}) %} + {% set preview_url = url({'for':'desktop.chapter.show','id':item.id}) %} {% set edit_url = url({'for':'admin.chapter.edit','id':item.id}) %} {% set update_url = url({'for':'admin.chapter.update','id':item.id}) %} {% set delete_url = url({'for':'admin.chapter.delete','id':item.id}) %} diff --git a/app/Http/Admin/Views/setting/live_notify.volt b/app/Http/Admin/Views/setting/live_notify.volt index dd74b74a..ae93063d 100644 --- a/app/Http/Admin/Views/setting/live_notify.volt +++ b/app/Http/Admin/Views/setting/live_notify.volt @@ -2,37 +2,37 @@
- +
- +
- +
- +
- +
- +
@@ -40,6 +40,7 @@
+
\ No newline at end of file diff --git a/app/Http/Admin/Views/setting/live_pull.volt b/app/Http/Admin/Views/setting/live_pull.volt index f3664fca..85299f4f 100644 --- a/app/Http/Admin/Views/setting/live_pull.volt +++ b/app/Http/Admin/Views/setting/live_pull.volt @@ -1,5 +1,5 @@ -{% set pull_auth_display = live.pull_auth_enabled == 0 ? 'style="display:none;"' : '' %} -{% set ppt_display = live.pull_trans_enabled == 0 ? 'style="display:none;"' : '' %} +{% set auth_display = pull.auth_enabled == 0 ? 'style="display:none;"' : '' %} +{% set ppt_display = pull.trans_enabled == 0 ? 'style="display:none;"' : '' %}
@@ -8,14 +8,14 @@
- - + +
- +
@@ -24,21 +24,21 @@
- - + +
-
+
- +
- +
@@ -48,8 +48,8 @@
- - + +
@@ -96,6 +96,7 @@
+
diff --git a/app/Http/Admin/Views/setting/live_push.volt b/app/Http/Admin/Views/setting/live_push.volt index 4d069390..1727f086 100644 --- a/app/Http/Admin/Views/setting/live_push.volt +++ b/app/Http/Admin/Views/setting/live_push.volt @@ -1,4 +1,4 @@ -{% set push_auth_display = live.push_auth_enabled == 0 ? 'style="display:none;"' : '' %} +{% set auth_display = push.auth_enabled == 0 ? 'style="display:none;"' : '' %}
@@ -7,7 +7,7 @@
- +
@@ -16,21 +16,21 @@
- - + +
-
+
- +
- +
@@ -39,6 +39,7 @@
+
diff --git a/app/Http/Admin/Views/setting/smser.volt b/app/Http/Admin/Views/setting/smser.volt index 1c34fc03..ce9f9e41 100644 --- a/app/Http/Admin/Views/setting/smser.volt +++ b/app/Http/Admin/Views/setting/smser.volt @@ -2,6 +2,8 @@ {% block content %} + {% set template = smser.template|json_decode %} +
基础配置 diff --git a/app/Services/Live.php b/app/Services/Live.php index e4494e95..d9cfc1c4 100644 --- a/app/Services/Live.php +++ b/app/Services/Live.php @@ -34,7 +34,9 @@ class Live extends Service public function __construct() { - $this->settings = $this->getSectionSettings('live'); + $this->settings['push'] = $this->getSectionSettings('live.push'); + $this->settings['pull'] = $this->getSectionSettings('live.pull'); + $this->settings['notify'] = $this->getSectionSettings('live.notify'); $this->logger = $this->getLogger('live'); @@ -55,7 +57,7 @@ class Live extends Service $request = new DescribeLiveStreamStateRequest(); $params = json_encode([ - 'DomainName' => $this->settings['push_domain'], + 'DomainName' => $this->settings['push']['domain'], 'AppName' => $appName ?: 'live', 'StreamName' => $streamName, ]); @@ -73,7 +75,6 @@ class Live extends Service } catch (TencentCloudSDKException $e) { $this->logger->error('Describe Live Stream State Exception ' . kg_json_encode([ - 'line' => $e->getLine(), 'code' => $e->getErrorCode(), 'message' => $e->getMessage(), 'requestId' => $e->getRequestId(), @@ -100,7 +101,7 @@ class Live extends Service $request = new ForbidLiveStreamRequest(); $params = json_encode([ - 'DomainName' => $this->settings['push_domain'], + 'DomainName' => $this->settings['push']['domain'], 'AppName' => $appName ?: 'live', 'StreamName' => $streamName, 'Reason' => $reason, @@ -119,7 +120,6 @@ class Live extends Service } catch (TencentCloudSDKException $e) { $this->logger->error('Forbid Live Stream Exception ' . kg_json_encode([ - 'line' => $e->getLine(), 'code' => $e->getErrorCode(), 'message' => $e->getMessage(), 'requestId' => $e->getRequestId(), @@ -145,7 +145,7 @@ class Live extends Service $request = new ResumeLiveStreamRequest(); $params = json_encode([ - 'DomainName' => $this->settings['push_domain'], + 'DomainName' => $this->settings['push']['domain'], 'AppName' => $appName ?: 'live', 'StreamName' => $streamName, ]); @@ -163,7 +163,6 @@ class Live extends Service } catch (TencentCloudSDKException $e) { $this->logger->error('Resume Live Stream Exception ' . kg_json_encode([ - 'line' => $e->getLine(), 'code' => $e->getErrorCode(), 'message' => $e->getMessage(), 'requestId' => $e->getRequestId(), @@ -186,10 +185,10 @@ class Live extends Service { $appName = $appName ?: 'live'; - $authEnabled = $this->settings['push_auth_enabled']; - $authKey = $this->settings['push_auth_key']; - $expireTime = $this->settings['push_auth_delta'] + time(); - $domain = $this->settings['push_domain']; + $authEnabled = $this->settings['push']['auth_enabled']; + $authKey = $this->settings['push']['auth_key']; + $expireTime = $this->settings['push']['auth_delta'] + time(); + $domain = $this->settings['push']['domain']; $authParams = $this->getAuthParams($streamName, $authKey, $expireTime); @@ -210,12 +209,12 @@ class Live extends Service { $appName = $appName ?: 'live'; - $protocol = $this->settings['pull_protocol']; - $domain = $this->settings['pull_domain']; - $authEnabled = $this->settings['pull_auth_enabled']; - $transEnabled = $this->settings['pull_trans_enabled']; - $authKey = $this->settings['pull_auth_key']; - $expireTime = $this->settings['pull_auth_delta'] + time(); + $protocol = $this->settings['pull']['protocol']; + $domain = $this->settings['pull']['domain']; + $authEnabled = $this->settings['pull']['auth_enabled']; + $transEnabled = $this->settings['pull']['trans_enabled']; + $authKey = $this->settings['pull']['auth_key']; + $expireTime = $this->settings['pull']['auth_delta'] + time(); $formats = ['rtmp', 'flv', 'm3u8']; diff --git a/app/Services/LiveNotify.php b/app/Services/LiveNotify.php index 52262a00..9ed304f5 100644 --- a/app/Services/LiveNotify.php +++ b/app/Services/LiveNotify.php @@ -136,11 +136,11 @@ class LiveNotify extends Service $redis = $cache->getRedis(); - $keyName = $this->getNotifyKeyName(); + $key = $this->getNotifyKey(); - $redis->sAdd($keyName, $chapter->id); + $redis->sAdd($key, $chapter->id); - $redis->expire($keyName, 86400); + $redis->expire($key, 86400); } protected function getChapter($streamId) @@ -176,9 +176,9 @@ class LiveNotify extends Service return false; } - $live = $this->getSectionSettings('live'); + $live = $this->getSectionSettings('live.notify'); - $mySign = md5($live['notify_auth_key'] . $time); + $mySign = md5($live['auth_key'] . $time); return $sign == $mySign; } diff --git a/db/migrations/20200827112717_insert_setting_data.php b/db/migrations/20200827112717_insert_setting_data.php index 79f8c1f1..955feb10 100644 --- a/db/migrations/20200827112717_insert_setting_data.php +++ b/db/migrations/20200827112717_insert_setting_data.php @@ -76,53 +76,83 @@ final class InsertSettingData extends AbstractMigration 'item_value' => '0', ], [ - 'section' => 'live', - 'item_key' => 'push_domain', - 'item_value' => 'push.abc.com', + 'section' => 'live.push', + 'item_key' => 'domain', + 'item_value' => '', ], [ - 'section' => 'live', - 'item_key' => 'pull_trans_enabled', - 'item_value' => '1', - ], - [ - 'section' => 'live', - 'item_key' => 'pull_auth_enabled', - 'item_value' => '1', - ], - [ - 'section' => 'live', + 'section' => 'live.push', 'item_key' => 'push_auth_enabled', 'item_value' => '1', ], [ - 'section' => 'live', - 'item_key' => 'pull_protocol', - 'item_value' => 'http', + 'section' => 'live.push', + 'item_key' => 'push_auth_key', + 'item_value' => '', ], [ - 'section' => 'live', + 'section' => 'live.push', 'item_key' => 'push_auth_delta', 'item_value' => '18000', ], [ - 'section' => 'live', - 'item_key' => 'pull_auth_delta', - 'item_value' => '18000', + 'section' => 'live.pull', + 'item_key' => 'pull_protocol', + 'item_value' => 'http', ], [ - 'section' => 'live', + 'section' => 'live.pull', + 'item_key' => 'pull_domain', + 'item_value' => '', + ], + [ + 'section' => 'live.pull', + 'item_key' => 'pull_trans_enabled', + 'item_value' => '0', + ], + [ + 'section' => 'live.pull', + 'item_key' => 'pull_auth_enabled', + 'item_value' => '1', + ], + [ + 'section' => 'live.pull', 'item_key' => 'pull_auth_key', 'item_value' => '', ], [ - 'section' => 'live', - 'item_key' => 'pull_domain', - 'item_value' => 'play.abc.com', + 'section' => 'live.pull', + 'item_key' => 'pull_auth_delta', + 'item_value' => '18000', ], [ - 'section' => 'live', - 'item_key' => 'push_auth_key', + 'section' => 'live.notify', + 'item_key' => 'pull_auth_key', + 'item_value' => '', + ], + [ + 'section' => 'live.notify', + 'item_key' => 'stream_begin_url', + 'item_value' => '', + ], + [ + 'section' => 'live.notify', + 'item_key' => 'stream_end_url', + 'item_value' => '', + ], + [ + 'section' => 'live.notify', + 'item_key' => 'record_url', + 'item_value' => '', + ], + [ + 'section' => 'live.notify', + 'item_key' => 'snapshot_url', + 'item_value' => '', + ], + [ + 'section' => 'live.notify', + 'item_key' => 'porn_url', 'item_value' => '', ], [