From d0e2e9eafddf5590ccf7508a3a21f7e9feab2d79 Mon Sep 17 00:00:00 2001 From: wangjuntao Date: Tue, 21 Feb 2023 00:49:18 +0800 Subject: [PATCH] 2023-02-21 00:49:13 : ui update --- app/cwmp_preset.go | 6 +- assets/buildinfo.txt | 10 +- assets/static/myskin/webix_dark_ext.css | 5 +- assets/static/myskin/webix_dark_ext.min.css | 2 +- assets/static/myskin/webix_light_ext.css | 6 +- assets/static/myskin/webix_light_ext.min.css | 2 +- assets/templates/cwmp_config_session.html | 265 +++++++++++-------- assets/templates/cwmp_factoryreset.html | 22 +- assets/templates/cwmp_firmwareconfig.html | 22 +- assets/templates/cwmp_preset.html | 22 +- assets/templates/cwmp_preset_task.html | 47 +++- common/web/web.go | 27 ++ controllers/cwmpconfig/cwmpconfig.go | 16 +- controllers/cwmpconfig/cwmpconfig_session.go | 11 +- controllers/cwmppreset/cwmp.go | 40 ++- controllers/factoryreset/factoryreset.go | 12 +- controllers/firmwareconfig/firmwareconfig.go | 12 +- controllers/supervise/cwmp_factorycfg.go | 4 +- controllers/supervise/cwmp_updatefirmware.go | 4 +- controllers/supervise/cwmpconfig.go | 4 +- models/cwmp.go | 8 +- webserver/jwt_skips.json | 15 -- webserver/server.go | 66 ++--- webserver/session_skip.json | 21 -- 24 files changed, 384 insertions(+), 265 deletions(-) delete mode 100644 webserver/jwt_skips.json delete mode 100644 webserver/session_skip.json diff --git a/app/cwmp_preset.go b/app/cwmp_preset.go index 40c2cdbf..ba661d5c 100644 --- a/app/cwmp_preset.go +++ b/app/cwmp_preset.go @@ -193,7 +193,7 @@ func (c *CwmpCpe) creatFactoryResetConfigDownloadTask(presetId int64, freset *mo return err } - if !c.MatchDevice(fconfig.OUI, fconfig.ProductClass, fconfig.SoftwareVersion) { + if !c.MatchDevice(fconfig.Oui, fconfig.ProductClass, fconfig.SoftwareVersion) { return fmt.Errorf("device not match CwmpFactoryResetConfig") } @@ -250,7 +250,7 @@ func (c *CwmpCpe) creatFirmwareConfigDownloadTask(presetId int64, fconfig *model return err } - if !c.MatchDevice(firmwareCfg.OUI, firmwareCfg.ProductClass, firmwareCfg.SoftwareVersion) { + if !c.MatchDevice(firmwareCfg.Oui, firmwareCfg.ProductClass, firmwareCfg.SoftwareVersion) { return fmt.Errorf("device not match CwmpFirmwareConfig") } @@ -305,7 +305,7 @@ func (c *CwmpCpe) creatDownloadTask(presetId int64, download models.CwmpPresetDo return err } - if !c.MatchDevice(script.OUI, script.ProductClass, script.SoftwareVersion) { + if !c.MatchDevice(script.Oui, script.ProductClass, script.SoftwareVersion) { return fmt.Errorf("device not match CwmpConfig") } diff --git a/assets/buildinfo.txt b/assets/buildinfo.txt index cdebe348..04595141 100644 --- a/assets/buildinfo.txt +++ b/assets/buildinfo.txt @@ -1,8 +1,8 @@ -BuildVersion=latest v8.0.1 2023-02-20 22:53:17 +BuildVersion=latest v8.0.1 2023-02-21 00:49:13 ReleaseVersion=v8.0.1 -BuildTime=2023-02-20 22:53:17 +BuildTime=2023-02-21 00:49:13 BuildName=toughradius -CommitID=5cb0701c20a1ceeced3577f1683cf0834a7f6099 -CommitDate=Mon, 20 Feb 2023 14:07:24 +0800 +CommitID=fbe5b570896d41f4fe72fa0ae60a9cc5774aa1bd +CommitDate=Mon, 20 Feb 2023 22:53:50 +0800 CommitUser=jamiesun.net@gmail.com -CommitSubject=2023-02-20 14:07:13 : set lang +CommitSubject=2023-02-20 22:53:17 : radsec secret cwmpconfig query diff --git a/assets/static/myskin/webix_dark_ext.css b/assets/static/myskin/webix_dark_ext.css index 7f6a42c3..470b45c1 100644 --- a/assets/static/myskin/webix_dark_ext.css +++ b/assets/static/myskin/webix_dark_ext.css @@ -224,5 +224,8 @@ } .webix_sidebar .webix_tree_branch_1 .webix_tree_item { - padding-left: 30px!important; + padding-left: 13px!important; +} +.webix_sidebar .webix_tree_branch_2 .webix_tree_item { + padding-left: 26px!important; } \ No newline at end of file diff --git a/assets/static/myskin/webix_dark_ext.min.css b/assets/static/myskin/webix_dark_ext.min.css index 68283278..90bd1bd3 100644 --- a/assets/static/myskin/webix_dark_ext.min.css +++ b/assets/static/myskin/webix_dark_ext.min.css @@ -1 +1 @@ -.webix_view{border-color:#3f3f3f!important;font-weight:400;font-size:13px}.webix_sidebar .webix_view{font-weight:600!important;font-size:14px!important}.webix_list .webix_view,.webix_property_label,.webix_property_value{font-weight:500!important;font-size:12px!important}.webix_property_value{color:#707070}.webix_list .webix_view{font-size:13px!important}.webix_sidebar .webix_sidebar_icon{width:20px;vertical-align:middle;color:#8f8f8f;font-size:16px}.webix_sidebar .webix_tree_branch_1>.webix_tree_item,.webix_sidebar .webix_tree_item{color:#dedede;cursor:pointer;border-bottom:1px solid #ebebeb0a!important}.webix_sidebar{border-color:rgba(231,231,231,.07)!important;background:linear-gradient(45deg,#2f2f2f,#252525)!important}.webix_sidebar .webix_tree_item:hover,.webix_sidebar.webix_sidebar_expanded .webix_tree_item.webix_sidebar_selected:hover{background-color:#373737!important}.webix_sidebar .webix_tree_item.webix_selected,.webix_sidebar .webix_tree_item.webix_sidebar_selected{color:#b2b2b2!important;background-color:#2d2d2d!important;font-weight:500}.webix_sidebar .webix_tree_item.webix_selected span{background-color:#9b9b9b00!important;color:#bbb;font-weight:600}.webix_sidebar .webix_tree_item.webix_selected .webix_sidebar_dir_icon,.webix_sidebar .webix_tree_item.webix_selected .webix_sidebar_icon,.webix_sidebar .webix_tree_item.webix_sidebar_selected .webix_sidebar_dir_icon,.webix_sidebar .webix_tree_item.webix_sidebar_selected .webix_sidebar_icon{color:#fff}.webix_dtable .webix_hs_left,.webix_dtable .webix_hs_right,.webix_dtable .webix_ss_left,.webix_dtable .webix_ss_right{box-shadow:none}.webix_sidebar .webix_tree_item{height:40px;line-height:39px}.webix_sidebar .webix_tree_branch_1>.webix_tree_item{height:40px;line-height:39px;padding-left:10px;padding-right:10px}.webix_sidebar .webix_tree_branch_1{border-color:#2b2b2b}.webix_dtable .webix_hs_left .webix_hcell.webix_last{border-right:1px solid #424242}.webix_dtable .webix_ss_header .webix_hcolumn div.webix_last_row,.webix_dtable .webix_ss_header .webix_span.webix_last_row{border-bottom:1px solid #676767}.webix_ss_header .webix_hcolumn .webix_hcell,.webix_ss_header .webix_span{border-right:1px solid transparent}.webix_window,.webix_window:focus{box-shadow:none}.webix_transparent .webix_button .webix_icon,.webix_transparent .webix_button .webix_icon_btn{color:#c6c6c6}.webix_switch_box.webix_switch_on{background-color:#078af5;color:#fff}.webix_switch_box{display:block;position:relative;top:50%;margin-top:-12px;height:24px;background-color:#9fdcff;border:1px solid #0078da;border-radius:9px;transition:background-color .4s ease;color:#666;text-align:center;float:left}.webix_switch_handle{height:22px;width:22px;border-radius:9px!important;box-shadow:0 1px 5px rgb(0 0 0/11%);border:1px solid #eeeeeea1;position:absolute;top:0;background-color:#009dff;transition:left .3s ease}.webix_button{padding:0}.webix_inp_bottom_label{font-size:10px;color:#979797}.webix_el_label .webix_el_box,.webix_inp_label,.webix_inp_top_label,legend.webix_forminput_label{font-family:Roboto,sans-serif;font-size:12px;font-weight:500;color:#a9a9a9;letter-spacing:.2px}.webix_header .webix_dark,.webix_header.webix_dark .webix_custom_checkbox,.webix_header.webix_dark .webix_custom_radio,.webix_header.webix_dark .webix_label_right{color:#fff;font-weight:600}.webix_header.webix_dark{background:#2d2d2d;border-color:#545454}.webix_el_radio .webix_radio_1 .webix_custom_radio:before{content:" "}.webix_sidebar .webix_tree_branch_1 .webix_tree_item{padding-left:30px!important} \ No newline at end of file +.webix_view{border-color:#3f3f3f!important;font-weight:400;font-size:13px}.webix_sidebar .webix_view{font-weight:600!important;font-size:14px!important}.webix_list .webix_view,.webix_property_label,.webix_property_value{font-weight:500!important;font-size:12px!important}.webix_property_value{color:#707070}.webix_list .webix_view{font-size:13px!important}.webix_sidebar .webix_sidebar_icon{width:20px;vertical-align:middle;color:#8f8f8f;font-size:16px}.webix_sidebar .webix_tree_branch_1>.webix_tree_item,.webix_sidebar .webix_tree_item{color:#dedede;cursor:pointer;border-bottom:1px solid #ebebeb0a!important}.webix_sidebar{border-color:rgba(231,231,231,.07)!important;background:linear-gradient(45deg,#2f2f2f,#252525)!important}.webix_sidebar .webix_tree_item:hover,.webix_sidebar.webix_sidebar_expanded .webix_tree_item.webix_sidebar_selected:hover{background-color:#373737!important}.webix_sidebar .webix_tree_item.webix_selected,.webix_sidebar .webix_tree_item.webix_sidebar_selected{color:#b2b2b2!important;background-color:#2d2d2d!important;font-weight:500}.webix_sidebar .webix_tree_item.webix_selected span{background-color:#9b9b9b00!important;color:#bbb;font-weight:600}.webix_sidebar .webix_tree_item.webix_selected .webix_sidebar_dir_icon,.webix_sidebar .webix_tree_item.webix_selected .webix_sidebar_icon,.webix_sidebar .webix_tree_item.webix_sidebar_selected .webix_sidebar_dir_icon,.webix_sidebar .webix_tree_item.webix_sidebar_selected .webix_sidebar_icon{color:#fff}.webix_dtable .webix_hs_left,.webix_dtable .webix_hs_right,.webix_dtable .webix_ss_left,.webix_dtable .webix_ss_right{box-shadow:none}.webix_sidebar .webix_tree_item{height:40px;line-height:39px}.webix_sidebar .webix_tree_branch_1>.webix_tree_item{height:40px;line-height:39px;padding-left:10px;padding-right:10px}.webix_sidebar .webix_tree_branch_1{border-color:#2b2b2b}.webix_dtable .webix_hs_left .webix_hcell.webix_last{border-right:1px solid #424242}.webix_dtable .webix_ss_header .webix_hcolumn div.webix_last_row,.webix_dtable .webix_ss_header .webix_span.webix_last_row{border-bottom:1px solid #676767}.webix_ss_header .webix_hcolumn .webix_hcell,.webix_ss_header .webix_span{border-right:1px solid transparent}.webix_window,.webix_window:focus{box-shadow:none}.webix_transparent .webix_button .webix_icon,.webix_transparent .webix_button .webix_icon_btn{color:#c6c6c6}.webix_switch_box.webix_switch_on{background-color:#078af5;color:#fff}.webix_switch_box{display:block;position:relative;top:50%;margin-top:-12px;height:24px;background-color:#9fdcff;border:1px solid #0078da;border-radius:9px;transition:background-color .4s ease;color:#666;text-align:center;float:left}.webix_switch_handle{height:22px;width:22px;border-radius:9px!important;box-shadow:0 1px 5px rgb(0 0 0/11%);border:1px solid #eeeeeea1;position:absolute;top:0;background-color:#009dff;transition:left .3s ease}.webix_button{padding:0}.webix_inp_bottom_label{font-size:10px;color:#979797}.webix_el_label .webix_el_box,.webix_inp_label,.webix_inp_top_label,legend.webix_forminput_label{font-family:Roboto,sans-serif;font-size:12px;font-weight:500;color:#a9a9a9;letter-spacing:.2px}.webix_header .webix_dark,.webix_header.webix_dark .webix_custom_checkbox,.webix_header.webix_dark .webix_custom_radio,.webix_header.webix_dark .webix_label_right{color:#fff;font-weight:600}.webix_header.webix_dark{background:#2d2d2d;border-color:#545454}.webix_el_radio .webix_radio_1 .webix_custom_radio:before{content:" "}.webix_sidebar .webix_tree_branch_1 .webix_tree_item{padding-left:13px!important}.webix_sidebar .webix_tree_branch_2 .webix_tree_item{padding-left:26px!important} \ No newline at end of file diff --git a/assets/static/myskin/webix_light_ext.css b/assets/static/myskin/webix_light_ext.css index ff10dc7a..66235471 100644 --- a/assets/static/myskin/webix_light_ext.css +++ b/assets/static/myskin/webix_light_ext.css @@ -189,5 +189,9 @@ } .webix_sidebar .webix_tree_branch_1 .webix_tree_item { - padding-left: 20px!important; + padding-left: 13px!important; +} + +.webix_sidebar .webix_tree_branch_1 .webix_tree_item { + padding-left: 26px!important; } diff --git a/assets/static/myskin/webix_light_ext.min.css b/assets/static/myskin/webix_light_ext.min.css index 127d8bba..6b13f063 100644 --- a/assets/static/myskin/webix_light_ext.min.css +++ b/assets/static/myskin/webix_light_ext.min.css @@ -1 +1 @@ -.webix_all_tabs .webix_item_tab.webix_selected:hover,.webix_item_tab.webix_selected{background-color:rgba(174,174,174,.37)}.webix_item_tab.webix_selected{border-bottom-width:0}.webix_all_tabs .webix_item_tab{border-top:#e8e8e8 solid 1px;border-right:#e8e8e8 solid 1px;border-bottom-width:0;border-left-width:0;border-top-right-radius:10px;text-decoration:none!important}.webix_inp_bottom_label{font-size:10px;color:#696969}.webix_view{border-color:#e7e7e7!important;font-weight:400;font-size:13px}.webix_sidebar .webix_view{font-weight:600!important;font-size:14px!important}.webix_list .webix_view,.webix_property_label,.webix_property_value{font-weight:500!important;font-size:12px!important}.webix_property_value{color:#707070}.webix_list .webix_view{font-size:13px!important}.webix_dtable .webix_ss_header .webix_hcolumn{font-weight:600!important;font-size:13px!important;color:#5b5b5b!important}.webix_dtable .webix_ss_body .webix_cell{font-weight:400!important;font-size:13px!important;color:#3f3f3f!important}.webix_sidebar .webix_sidebar_icon{width:20px;vertical-align:middle;color:#8f8f8f;font-size:16px}.webix_sidebar .webix_tree_branch_1>.webix_tree_item,.webix_sidebar .webix_tree_item{color:#dedede;cursor:pointer;border-bottom:1px solid #ebebeb0a!important}.webix_sidebar{border-color:rgba(231,231,231,.07)!important;background:linear-gradient(45deg,#2f2f2f,#252525)!important}.webix_sidebar .webix_tree_item:hover,.webix_sidebar.webix_sidebar_expanded .webix_tree_item.webix_sidebar_selected:hover{background-color:#373737!important}.webix_sidebar .webix_tree_item.webix_selected,.webix_sidebar .webix_tree_item.webix_sidebar_selected{color:#b2b2b2!important;background-color:#2d2d2d!important;font-weight:500}.webix_sidebar .webix_tree_item.webix_selected span{background-color:#9b9b9b00!important;color:#bbb;font-weight:600}.webix_sidebar .webix_tree_item.webix_selected .webix_sidebar_dir_icon,.webix_sidebar .webix_tree_item.webix_selected .webix_sidebar_icon,.webix_sidebar .webix_tree_item.webix_sidebar_selected .webix_sidebar_dir_icon,.webix_sidebar .webix_tree_item.webix_sidebar_selected .webix_sidebar_icon{color:#fff}.webix_dtable .webix_hs_left,.webix_dtable .webix_hs_right,.webix_dtable .webix_ss_left,.webix_dtable .webix_ss_right{box-shadow:none}.webix_sidebar .webix_tree_branch_1>.webix_tree_item,.webix_sidebar .webix_tree_item{height:40px;line-height:39px}.webix_switch_box.webix_switch_on{background-color:#078af5;color:#fff}.webix_switch_box{display:block;position:relative;top:50%;margin-top:-12px;height:24px;background-color:#9fdcff;border:1px solid #0078da;border-radius:9px;transition:background-color .4s ease;color:#666;text-align:center;float:left}.webix_switch_handle{height:22px;width:22px;border-radius:9px!important;box-shadow:0 1px 5px rgb(0 0 0/11%);border:1px solid #eeeeeea1;position:absolute;top:0;background-color:#009dff;transition:left .3s ease}.webix_button{padding:0}.webix_transparent .webix_button{color:#37a9ef;box-shadow:none}.webix_transparent .webix_button:focus,.webix_transparent .webix_button:hover{background-color:#e7f4fd0f}.webix_header .webix_dark,.webix_header.webix_dark .webix_custom_checkbox,.webix_header.webix_dark .webix_custom_radio,.webix_header.webix_dark .webix_label_right{color:#464646;font-weight:600}.webix_header.webix_dark{color:#363636;font-weight:600;background:#f5f5f5;border-color:#545454}.webix_sidebar .webix_tree_branch_1 .webix_tree_item{padding-left:20px!important} \ No newline at end of file +.webix_all_tabs .webix_item_tab.webix_selected:hover,.webix_item_tab.webix_selected{background-color:rgba(174,174,174,.37)}.webix_item_tab.webix_selected{border-bottom-width:0}.webix_all_tabs .webix_item_tab{border-top:#e8e8e8 solid 1px;border-right:#e8e8e8 solid 1px;border-bottom-width:0;border-left-width:0;border-top-right-radius:10px;text-decoration:none!important}.webix_inp_bottom_label{font-size:10px;color:#696969}.webix_view{border-color:#e7e7e7!important;font-weight:400;font-size:13px}.webix_sidebar .webix_view{font-weight:600!important;font-size:14px!important}.webix_list .webix_view,.webix_property_label,.webix_property_value{font-weight:500!important;font-size:12px!important}.webix_property_value{color:#707070}.webix_list .webix_view{font-size:13px!important}.webix_dtable .webix_ss_header .webix_hcolumn{font-weight:600!important;font-size:13px!important;color:#5b5b5b!important}.webix_dtable .webix_ss_body .webix_cell{font-weight:400!important;font-size:13px!important;color:#3f3f3f!important}.webix_sidebar .webix_sidebar_icon{width:20px;vertical-align:middle;color:#8f8f8f;font-size:16px}.webix_sidebar .webix_tree_branch_1>.webix_tree_item,.webix_sidebar .webix_tree_item{color:#dedede;cursor:pointer;border-bottom:1px solid #ebebeb0a!important}.webix_sidebar{border-color:rgba(231,231,231,.07)!important;background:linear-gradient(45deg,#2f2f2f,#252525)!important}.webix_sidebar .webix_tree_item:hover,.webix_sidebar.webix_sidebar_expanded .webix_tree_item.webix_sidebar_selected:hover{background-color:#373737!important}.webix_sidebar .webix_tree_item.webix_selected,.webix_sidebar .webix_tree_item.webix_sidebar_selected{color:#b2b2b2!important;background-color:#2d2d2d!important;font-weight:500}.webix_sidebar .webix_tree_item.webix_selected span{background-color:#9b9b9b00!important;color:#bbb;font-weight:600}.webix_sidebar .webix_tree_item.webix_selected .webix_sidebar_dir_icon,.webix_sidebar .webix_tree_item.webix_selected .webix_sidebar_icon,.webix_sidebar .webix_tree_item.webix_sidebar_selected .webix_sidebar_dir_icon,.webix_sidebar .webix_tree_item.webix_sidebar_selected .webix_sidebar_icon{color:#fff}.webix_dtable .webix_hs_left,.webix_dtable .webix_hs_right,.webix_dtable .webix_ss_left,.webix_dtable .webix_ss_right{box-shadow:none}.webix_sidebar .webix_tree_branch_1>.webix_tree_item,.webix_sidebar .webix_tree_item{height:40px;line-height:39px}.webix_switch_box.webix_switch_on{background-color:#078af5;color:#fff}.webix_switch_box{display:block;position:relative;top:50%;margin-top:-12px;height:24px;background-color:#9fdcff;border:1px solid #0078da;border-radius:9px;transition:background-color .4s ease;color:#666;text-align:center;float:left}.webix_switch_handle{height:22px;width:22px;border-radius:9px!important;box-shadow:0 1px 5px rgb(0 0 0/11%);border:1px solid #eeeeeea1;position:absolute;top:0;background-color:#009dff;transition:left .3s ease}.webix_button{padding:0}.webix_transparent .webix_button{color:#37a9ef;box-shadow:none}.webix_transparent .webix_button:focus,.webix_transparent .webix_button:hover{background-color:#e7f4fd0f}.webix_header .webix_dark,.webix_header.webix_dark .webix_custom_checkbox,.webix_header.webix_dark .webix_custom_radio,.webix_header.webix_dark .webix_label_right{color:#464646;font-weight:600}.webix_header.webix_dark{color:#363636;font-weight:600;background:#f5f5f5;border-color:#545454}.webix_sidebar .webix_tree_branch_1 .webix_tree_item{padding-left:26px!important} \ No newline at end of file diff --git a/assets/templates/cwmp_config_session.html b/assets/templates/cwmp_config_session.html index 7b86c554..8e7af257 100644 --- a/assets/templates/cwmp_config_session.html +++ b/assets/templates/cwmp_config_session.html @@ -6,127 +6,172 @@ - + }) + \ No newline at end of file diff --git a/assets/templates/cwmp_factoryreset.html b/assets/templates/cwmp_factoryreset.html index d286ce72..a1a3d1a3 100644 --- a/assets/templates/cwmp_factoryreset.html +++ b/assets/templates/cwmp_factoryreset.html @@ -40,9 +40,10 @@ webix.ready(function () { + let queryid = webix.uid(); let tableid = webix.uid(); let uploadid = webix.uid(); - let reloadData = wxui.reloadDataFunc(tableid, "/admin/cwmp/factoryreset/query", null) + let reloadData = wxui.reloadDataFunc(tableid, "/admin/cwmp/factoryreset/query", queryid) webix.ui({ css: "main-panel", padding: 7, @@ -111,6 +112,25 @@ }), ], }), + wxui.getTableQueryCustomForm(queryid, [ + { + cols: [ + {view: "search", id: "keyword", name: "keyword", placeholder: "keywords", width: 320}, + { + view: "button", + label: gtr("Query"), + css: "webix_transparent", + type: "icon", + icon: "mdi mdi-search-web", + borderless: true, + width: 100, + click: function () { + reloadData() + } + }, {} + ] + } + ]), wxui.getDatatable({ tableid: tableid, url: '/admin/cwmp/factoryreset/query', diff --git a/assets/templates/cwmp_firmwareconfig.html b/assets/templates/cwmp_firmwareconfig.html index 88539652..359789e9 100644 --- a/assets/templates/cwmp_firmwareconfig.html +++ b/assets/templates/cwmp_firmwareconfig.html @@ -40,9 +40,10 @@ webix.ready(function () { + let queryid = webix.uid(); let tableid = webix.uid(); let uploadid = webix.uid(); - let reloadData = wxui.reloadDataFunc(tableid, "/admin/cwmp/firmwareconfig/query") + let reloadData = wxui.reloadDataFunc(tableid, "/admin/cwmp/firmwareconfig/query", queryid) webix.ui({ css: "main-panel", padding: 7, @@ -111,6 +112,25 @@ }), ], }), + wxui.getTableQueryCustomForm(queryid, [ + { + cols: [ + {view: "search", id: "keyword", name: "keyword", placeholder: "keywords", width: 320}, + { + view: "button", + label: gtr("Query"), + css: "webix_transparent", + type: "icon", + icon: "mdi mdi-search-web", + borderless: true, + width: 100, + click: function () { + reloadData() + } + }, {} + ] + } + ]), wxui.getDatatable({ tableid: tableid, url: '/admin/cwmp/firmwareconfig/query', diff --git a/assets/templates/cwmp_preset.html b/assets/templates/cwmp_preset.html index 5da6c10d..06029617 100644 --- a/assets/templates/cwmp_preset.html +++ b/assets/templates/cwmp_preset.html @@ -90,8 +90,9 @@ webix.ready(function () { + let queryid = webix.uid(); let tableid = webix.uid(); - let reloadData = wxui.reloadDataFunc(tableid, "/admin/cwmp/preset/query", null) + let reloadData = wxui.reloadDataFunc(tableid, "/admin/cwmp/preset/query", queryid) webix.ui({ css: "main-panel", padding: 7, @@ -166,6 +167,25 @@ }), ], }), + wxui.getTableQueryCustomForm(queryid, [ + { + cols: [ + {view: "search", id: "keyword", name: "keyword", placeholder: "keywords", width: 320}, + { + view: "button", + label: gtr("Query"), + css: "webix_transparent", + type: "icon", + icon: "mdi mdi-search-web", + borderless: true, + width: 100, + click: function () { + reloadData() + } + }, {} + ] + } + ]), wxui.getDatatable({ tableid: tableid, url: '/admin/cwmp/preset/query', diff --git a/assets/templates/cwmp_preset_task.html b/assets/templates/cwmp_preset_task.html index e964728f..de7bcbcf 100644 --- a/assets/templates/cwmp_preset_task.html +++ b/assets/templates/cwmp_preset_task.html @@ -29,8 +29,9 @@ } webix.ready(function () { + let queryid = webix.uid(); let tableid = webix.uid(); - let reloadData = wxui.reloadDataFunc(tableid, "/admin/cwmp/presettask/query", null) + let reloadData = wxui.reloadDataFunc(tableid, "/admin/cwmp/presettask/query", queryid) webix.ui({ css: "main-panel", padding: 7, @@ -49,6 +50,50 @@ }), ] }), + wxui.getTableQueryCustomForm(queryid, [ + { + cols: [ + { + view: "datepicker", + timepicker: true, + name: "starttime", + label: gtr("Time From"), + labelWidth: 80, + width: 240, + stringResult: true, + format: "%Y-%m-%d %H:%i", + css: "nborder-input", + value: webix.Date.add(new Date(), -8, "hour"), + editable: true + }, + { + view: "datepicker", + timepicker: true, + name: "endtime", + label: gtr("to"), + labelWidth: 20, + stringResult: true, + format: "%Y-%m-%d %H:%i", + css: "nborder-input", + value: new Date(), + editable: true + }, + {view: "search", id: "keyword", name: "keyword", placeholder: "keywords", width: 320}, + { + view: "button", + label: "Query", + css: "webix_transparent", + type: "icon", + icon: "mdi mdi-search-web", + borderless: true, + width: 100, + click: function () { + reloadData() + } + }, {} + ] + } + ]), wxui.getDatatable({ tableid: tableid, url: "/admin/cwmp/presettask/query", diff --git a/common/web/web.go b/common/web/web.go index 3f435a7c..1a56b2ed 100644 --- a/common/web/web.go +++ b/common/web/web.go @@ -33,6 +33,7 @@ import ( "github.com/labstack/echo/v4" "github.com/spf13/cast" "github.com/talkincode/toughradius/common" + "gorm.io/gorm" ) type DateRange struct { @@ -404,3 +405,29 @@ func CreateToken(secret, uid, level string, exp time.Duration) (string, error) { claims["exp"] = time.Now().Add(exp).Unix() return token.SignedString([]byte(secret)) } + +func QueryPageResult[T any](c echo.Context, tx *gorm.DB, prequery *PreQuery) (*PageResult, error) { + var count, start int + NewParamReader(c). + ReadInt(&start, "start", 0). + ReadInt(&count, "count", 40) + var data []T + var total int64 + models := new(T) + common.Must(prequery.Query(tx.Model(models)).Count(&total).Error) + query := prequery.Query(tx.Debug().Model(models)).Offset(start).Limit(count) + if err := query.Find(&data).Error; err != nil { + return nil, err + } + return &PageResult{TotalCount: total, Pos: int64(start), Data: data}, nil +} + +func QueryDataResult[T any](c echo.Context, tx *gorm.DB, prequery *PreQuery) ([]T, error) { + var count int + NewParamReader(c).ReadInt(&count, "count", 10000) + var data []T + if err := prequery.Query(tx.Model(new(T))).Limit(count).Find(&data).Error; err != nil { + return nil, err + } + return data, nil +} diff --git a/controllers/cwmpconfig/cwmpconfig.go b/controllers/cwmpconfig/cwmpconfig.go index 219536bf..95f021e5 100644 --- a/controllers/cwmpconfig/cwmpconfig.go +++ b/controllers/cwmpconfig/cwmpconfig.go @@ -46,24 +46,16 @@ func initTemplateRouter() { }) webserver.GET("/admin/cwmp/config/query", func(c echo.Context) error { - var count, start int - web.NewParamReader(c). - ReadInt(&start, "start", 0). - ReadInt(&count, "count", 40) - var data []models.CwmpConfig prequery := web.NewPreQuery(c). DefaultOrderBy("updated_at desc"). KeyFields("oid", "name", "software_version", - "product_class", "o_ui", "task_tags") - - var total int64 - common.Must(prequery.Query(app.GDB().Model(&models.CwmpConfig{})).Count(&total).Error) + "product_class", "oui", "task_tags") - query := prequery.Query(app.GDB().Model(&models.CwmpConfig{})).Offset(start).Limit(count) - if query.Find(&data).Error != nil { + result, err := web.QueryPageResult[models.CwmpConfig](c, app.GDB(), prequery) + if err != nil { return c.JSON(http.StatusOK, common.EmptyList) } - return c.JSON(http.StatusOK, &web.PageResult{TotalCount: total, Pos: int64(start), Data: data}) + return c.JSON(http.StatusOK, result) }) webserver.POST("/admin/cwmp/config/add", func(c echo.Context) error { diff --git a/controllers/cwmpconfig/cwmpconfig_session.go b/controllers/cwmpconfig/cwmpconfig_session.go index 667837fe..13515697 100644 --- a/controllers/cwmpconfig/cwmpconfig_session.go +++ b/controllers/cwmpconfig/cwmpconfig_session.go @@ -48,16 +48,17 @@ func InitRouter() { }) webserver.GET("/admin/cwmp/config/session/query", func(c echo.Context) error { - var data []models.CwmpConfigSession prequery := web.NewPreQuery(c). DefaultOrderBy("created_at desc"). DateRange2("starttime", "endtime", "created_at", time.Now().Add(-time.Hour*24), time.Now()). QueryField("cpe_id", "cpe_id"). - KeyFields("name", "software_version", "product_class", "oui", "task_tags", "content") + KeyFields("name", "software_version", "product_class", "oui", "task_tags") - err := prequery.Query(app.GDB()).Find(&data).Error - common.Must(err) - return c.JSON(http.StatusOK, data) + result, err := web.QueryPageResult[models.CwmpConfigSession](c, app.GDB(), prequery) + if err != nil { + return c.JSON(http.StatusOK, common.EmptyList) + } + return c.JSON(http.StatusOK, result) }) webserver.POST("/admin/cwmp/config/session/execute", func(c echo.Context) error { diff --git a/controllers/cwmppreset/cwmp.go b/controllers/cwmppreset/cwmp.go index f09961f3..43afe5ac 100644 --- a/controllers/cwmppreset/cwmp.go +++ b/controllers/cwmppreset/cwmp.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "strings" + "time" "github.com/labstack/echo/v4" "github.com/spf13/cast" @@ -64,10 +65,15 @@ func InitRouter() { }) webserver.GET("/admin/cwmp/preset/query", func(c echo.Context) error { - var data []models.CwmpPreset - err := app.GDB().Find(&data).Error - common.Must(err) - return c.JSON(http.StatusOK, data) + prequery := web.NewPreQuery(c). + DefaultOrderBy("updated_at desc"). + KeyFields("name", "event", "task_tags", "content") + + result, err := web.QueryPageResult[models.CwmpPreset](c, app.GDB(), prequery) + if err != nil { + return c.JSON(http.StatusOK, common.EmptyList) + } + return c.JSON(http.StatusOK, result) }) webserver.GET("/admin/cwmp/preset/execute", func(c echo.Context) error { @@ -98,29 +104,17 @@ func InitRouter() { }) webserver.GET("/admin/cwmp/presettask/query", func(c echo.Context) error { - var count, start int - var sn string - web.NewParamReader(c). - ReadInt(&start, "start", 0). - ReadInt(&count, "count", 40). - ReadString(&sn, "sn") - var data []models.CwmpPresetTask prequery := web.NewPreQuery(c). - DefaultOrderBy("updated_at desc"). - KeyFields("name") - - if sn != "" { - prequery = prequery.SetParam("sn", sn) - } - - var total int64 - common.Must(prequery.Query(app.GDB().Model(&models.CwmpPresetTask{})).Count(&total).Error) + DefaultOrderBy("created_at desc"). + DateRange2("starttime", "endtime", "created_at", time.Now().Add(-time.Hour*24), time.Now()). + QueryField("sn", "sn"). + KeyFields("sn", "name", "batch", "event") - query := prequery.Query(app.GDB().Model(&models.CwmpPresetTask{})).Offset(start).Limit(count) - if query.Find(&data).Error != nil { + result, err := web.QueryPageResult[models.CwmpPresetTask](c, app.GDB(), prequery) + if err != nil { return c.JSON(http.StatusOK, common.EmptyList) } - return c.JSON(http.StatusOK, &web.PageResult{TotalCount: total, Pos: int64(start), Data: data}) + return c.JSON(http.StatusOK, result) }) webserver.POST("/admin/cwmp/preset/add", func(c echo.Context) error { diff --git a/controllers/factoryreset/factoryreset.go b/controllers/factoryreset/factoryreset.go index 89cbbb3e..9a39bdc1 100644 --- a/controllers/factoryreset/factoryreset.go +++ b/controllers/factoryreset/factoryreset.go @@ -34,10 +34,14 @@ func InitRouter() { }) webserver.GET("/admin/cwmp/factoryreset/query", func(c echo.Context) error { - var data []models.CwmpFactoryReset - err := app.GDB().Find(&data).Error - common.Must(err) - return c.JSON(http.StatusOK, data) + prequery := web.NewPreQuery(c). + DefaultOrderBy("updated_at desc"). + KeyFields("oid", "name", "software_version", "product_class", "oui") + result, err := web.QueryPageResult[models.CwmpFactoryReset](c, app.GDB(), prequery) + if err != nil { + return c.JSON(http.StatusOK, common.EmptyList) + } + return c.JSON(http.StatusOK, result) }) webserver.POST("/admin/cwmp/factoryreset/add", func(c echo.Context) error { diff --git a/controllers/firmwareconfig/firmwareconfig.go b/controllers/firmwareconfig/firmwareconfig.go index 58a85eed..13c882b9 100644 --- a/controllers/firmwareconfig/firmwareconfig.go +++ b/controllers/firmwareconfig/firmwareconfig.go @@ -34,10 +34,14 @@ func InitRouter() { }) webserver.GET("/admin/cwmp/firmwareconfig/query", func(c echo.Context) error { - var data []models.CwmpFirmwareConfig - err := app.GDB().Find(&data).Error - common.Must(err) - return c.JSON(http.StatusOK, data) + prequery := web.NewPreQuery(c). + DefaultOrderBy("updated_at desc"). + KeyFields("oid", "name", "software_version", "product_class", "oui") + result, err := web.QueryPageResult[models.CwmpFirmwareConfig](c, app.GDB(), prequery) + if err != nil { + return c.JSON(http.StatusOK, common.EmptyList) + } + return c.JSON(http.StatusOK, result) }) webserver.POST("/admin/cwmp/firmwareconfig/add", func(c echo.Context) error { diff --git a/controllers/supervise/cwmp_factorycfg.go b/controllers/supervise/cwmp_factorycfg.go index c5134754..d9701fdf 100644 --- a/controllers/supervise/cwmp_factorycfg.go +++ b/controllers/supervise/cwmp_factorycfg.go @@ -34,7 +34,7 @@ func execCwmpMikrotikFactoryConfiguration(c echo.Context, id string, deviceId in } cpe := app.GApp().CwmpTable().GetCwmpCpe(dev.Sn) - if !cpe.MatchDevice(factscript.OUI, factscript.ProductClass, factscript.SoftwareVersion) { + if !cpe.MatchDevice(factscript.Oui, factscript.ProductClass, factscript.SoftwareVersion) { return c.JSON(http.StatusOK, web.RestError(fmt.Sprintf("Device %s Does not match CwmpFactoryReset", dev.Sn))) } @@ -52,7 +52,7 @@ func execCwmpMikrotikFactoryConfiguration(c echo.Context, id string, deviceId in Level: "major", SoftwareVersion: factscript.SoftwareVersion, ProductClass: factscript.ProductClass, - OUI: factscript.OUI, + Oui: factscript.Oui, Content: factscript.Content, ExecStatus: "initialize", LastError: "", diff --git a/controllers/supervise/cwmp_updatefirmware.go b/controllers/supervise/cwmp_updatefirmware.go index 2ebb6517..1abc77ea 100644 --- a/controllers/supervise/cwmp_updatefirmware.go +++ b/controllers/supervise/cwmp_updatefirmware.go @@ -41,7 +41,7 @@ func execCwmpUpdateFirmware(c echo.Context, devids []string, firmwareId, session } cpe := app.GApp().CwmpTable().GetCwmpCpe(dev.Sn) - if !cpe.MatchDevice(firmwareCfg.OUI, firmwareCfg.ProductClass, firmwareCfg.SoftwareVersion) { + if !cpe.MatchDevice(firmwareCfg.Oui, firmwareCfg.ProductClass, firmwareCfg.SoftwareVersion) { events.PubSuperviseLog(dev.ID, session, "error", fmt.Sprintf("cpe %s not match CwmpFirmwareConfig", dev.Sn)) continue @@ -59,7 +59,7 @@ func execCwmpUpdateFirmware(c echo.Context, devids []string, firmwareId, session Level: "manage", SoftwareVersion: firmwareCfg.SoftwareVersion, ProductClass: firmwareCfg.ProductClass, - OUI: firmwareCfg.OUI, + Oui: firmwareCfg.Oui, Content: firmwareCfg.Content, ExecStatus: "initialize", LastError: "", diff --git a/controllers/supervise/cwmpconfig.go b/controllers/supervise/cwmpconfig.go index 03b02aab..2b3fa978 100644 --- a/controllers/supervise/cwmpconfig.go +++ b/controllers/supervise/cwmpconfig.go @@ -39,7 +39,7 @@ func execCwmpConfig(c echo.Context, id string, deviceId int64, session string) e cpe := app.GetCwmpCpe(dev.Sn) - if !app.MatchDevice(dev, script.OUI, script.ProductClass, script.SoftwareVersion) { + if !app.MatchDevice(dev, script.Oui, script.ProductClass, script.SoftwareVersion) { return c.JSON(http.StatusOK, web.RestError(fmt.Sprintf("device version %s mismatch %s", dev.SoftwareVersion, script.SoftwareVersion))) } @@ -62,7 +62,7 @@ func execCwmpConfig(c echo.Context, id string, deviceId int64, session string) e Level: script.Level, SoftwareVersion: script.SoftwareVersion, ProductClass: script.ProductClass, - OUI: script.OUI, + Oui: script.Oui, TaskTags: script.TaskTags, Content: script.Content, ExecStatus: "initialize", diff --git a/models/cwmp.go b/models/cwmp.go index 0e4e2cc6..3653b5ac 100644 --- a/models/cwmp.go +++ b/models/cwmp.go @@ -13,7 +13,7 @@ type CwmpConfig struct { Level string `json:"level" form:"level"` // script level normal|major SoftwareVersion string `json:"software_version" form:"software_version"` ProductClass string `json:"product_class" form:"product_class"` - OUI string `json:"oui" form:"oui"` + Oui string `json:"oui" form:"oui"` TaskTags string `gorm:"index" json:"task_tags" form:"task_tags"` // task label Content string `json:"content" form:"content"` // script content TargetFilename string `json:"target_filename" form:"target_filename"` @@ -31,7 +31,7 @@ type CwmpConfigSession struct { Level string `json:"level" form:"level"` // script level normal|major SoftwareVersion string `json:"software_version" form:"software_version"` ProductClass string `json:"product_class" form:"product_class"` - OUI string `json:"oui" form:"oui"` + Oui string `json:"oui" form:"oui"` TaskTags string `gorm:"index" json:"task_tags" form:"task_tags"` // task label Content string `json:"content" form:"content"` // script content ExecStatus string `gorm:"index" json:"exec_status" form:"exec_status"` // execution state success | failure @@ -56,7 +56,7 @@ type CwmpFactoryReset struct { Name string `json:"name" form:"name"` SoftwareVersion string `json:"software_version" form:"software_version"` ProductClass string `json:"product_class" form:"product_class"` - OUI string `json:"oui" form:"oui"` + Oui string `json:"oui" form:"oui"` Content string `json:"content" form:"content"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` @@ -69,7 +69,7 @@ type CwmpFirmwareConfig struct { Name string `json:"name" form:"name"` SoftwareVersion string `json:"software_version" form:"software_version"` ProductClass string `json:"product_class" form:"product_class"` - OUI string `json:"oui" form:"oui"` + Oui string `json:"oui" form:"oui"` Content string `json:"content" form:"content"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` diff --git a/webserver/jwt_skips.json b/webserver/jwt_skips.json deleted file mode 100644 index 9ee115b3..00000000 --- a/webserver/jwt_skips.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "paths": [ - "/ready", - "/login", - "/admin/login" - ], - "prefixs": [ - "/ready", - "/static", - "/metrics" - ], - "suffixs": [ - ".css" - ] -} \ No newline at end of file diff --git a/webserver/server.go b/webserver/server.go index 5223754d..e48f70b0 100644 --- a/webserver/server.go +++ b/webserver/server.go @@ -2,7 +2,6 @@ package webserver import ( _ "embed" - "encoding/json" "fmt" "io/fs" "net/http" @@ -41,17 +40,23 @@ const UserSessionName = "toughradius_user_session_name" const UserSessionLevel = "toughradius_user_session_level" const ConstCookieName = "toughradius_cookie" -type Skips struct { - Paths []string `json:"paths"` - Prefixs []string `json:"prefixs"` - Suffixs []string `json:"suffixs"` -} - -//go:embed jwt_skips.json -var jwtSkipsData []byte - -//go:embed session_skip.json -var SessionSkipsData []byte +var ( + SessionSkipPrefix = []string{ + "/ready", + "/realip", + "/api", + "/login", + "/admin/login", + "/static", + } + JwtSkipPrefix = []string{ + "/ready", + "/realip", + "/login", + "/admin/login", + "/static", + } +) var server *AdminServer @@ -120,7 +125,7 @@ func NewAdminServer() *AdminServer { s.jwtConfig = echojwt.Config{ SigningKey: []byte(appconfig.Web.Secret), SigningMethod: middleware.AlgorithmHS256, - Skipper: skipFUnc(jwtSkipsData), + Skipper: jwtSkipFunc(), ErrorHandler: func(c echo.Context, err error) error { return c.JSON(http.StatusBadRequest, web.RestError("Resource access is limited "+err.Error())) }, @@ -217,31 +222,17 @@ func ServerRecover(debug bool) echo.MiddlewareFunc { } // skipFUnc Web 请求过滤中间件 -func skipFUnc(skipdata []byte) func(c echo.Context) bool { +func jwtSkipFunc() func(c echo.Context) bool { return func(c echo.Context) bool { if os.Getenv("TEAMSACS_DEVMODE") == "true" { return true } - var skip Skips - err := json.Unmarshal(skipdata, &skip) - if err != nil { - common.Must(err) - } - - if common.InSlice(c.Request().RequestURI, skip.Paths) { - return true - } - for _, prefix := range skip.Prefixs { + for _, prefix := range JwtSkipPrefix { if strings.HasPrefix(c.Path(), prefix) { return true } } - for _, suffix := range skip.Suffixs { - if strings.HasSuffix(c.Path(), suffix) { - return true - } - } return false } } @@ -254,26 +245,11 @@ func sessionCheck() echo.MiddlewareFunc { return next(c) } - var skip Skips - err := json.Unmarshal(SessionSkipsData, &skip) - if err != nil { - common.Must(err) - } - - if common.InSlice(c.Request().RequestURI, skip.Paths) { - return next(c) - } - - for _, prefix := range skip.Prefixs { + for _, prefix := range SessionSkipPrefix { if strings.HasPrefix(c.Path(), prefix) { return next(c) } } - for _, suffix := range skip.Suffixs { - if strings.HasSuffix(c.Path(), suffix) { - return next(c) - } - } sess, _ := session.Get(UserSession, c) username := sess.Values[UserSessionName] if username == nil || username == "" { diff --git a/webserver/session_skip.json b/webserver/session_skip.json deleted file mode 100644 index 4a97f7a0..00000000 --- a/webserver/session_skip.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "paths": [ - "/ready", - "/realip", - "/login", - "/logout", - "/admin/login" - ], - "prefixs": [ - "/ready", - "/realip", - "/nbi", - "/login", - "/logout", - "/admin/login", - "/static" - ], - "suffixs": [ - ".css" - ] -} \ No newline at end of file