diff --git a/internal/web/actions/default/servers/serverutils/server_helper.go b/internal/web/actions/default/servers/serverutils/server_helper.go index 427e164b..9aa7c646 100644 --- a/internal/web/actions/default/servers/serverutils/server_helper.go +++ b/internal/web/actions/default/servers/serverutils/server_helper.go @@ -378,6 +378,12 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri "isActive": secondMenuItem == "traffic", "isOn": serverConfig.TrafficLimit != nil && serverConfig.TrafficLimit.IsOn, }) + menuItems = append(menuItems, maps.Map{ + "name": "边缘脚本", + "url": "/servers/server/settings/requestScripts?serverId=" + serverIdString, + "isActive": secondMenuItem == "requestScripts", + "isOn": serverConfig.Web != nil && serverConfig.Web.RequestScripts != nil && !serverConfig.Web.RequestScripts.IsEmpty(), + }) } menuItems = append(menuItems, maps.Map{ diff --git a/web/public/js/components.js b/web/public/js/components.js index d806706e..c7e21aba 100755 --- a/web/public/js/components.js +++ b/web/public/js/components.js @@ -2203,6 +2203,42 @@ Vue.component("http-firewall-actions-view", { ` }) +Vue.component("http-request-scripts-config-box", { + props: ["vRequestScriptsConfig"], + data: function () { + let config = this.vRequestScriptsConfig + if (config == null) { + config = {} + } + return { + config: config + } + }, + methods: { + changeInitScript: function (scriptConfig) { + this.config.onInitScript = scriptConfig + this.$forceUpdate() + }, + changeRequestScript: function (scriptConfig) { + this.config.onRequestScript = scriptConfig + this.$forceUpdate() + } + }, + template: `
+ +
+

请求初始化

+
+ +
+

准备发送请求

+
+ +
+
+
` +}) + // 显示WAF规则的标签 Vue.component("http-firewall-rule-label", { props: ["v-rule"], @@ -5984,7 +6020,7 @@ Vue.component("http-header-policy-box", { -
+
由于已经在当前服务分组中进行了对应的配置,在这里的配置将不会生效。 @@ -7220,6 +7256,60 @@ Vue.component("http-gzip-box", {
` }) +Vue.component("script-config-box", { + props: ["id", "v-script-config", "comment"], + data: function () { + let config = this.vScriptConfig + if (config == null) { + config = { + isPrior: false, + isOn: false, + code: "" + } + } + + if (config.code.length == 0) { + config.code = "\n\n\n\n" + } + + return { + config: config + } + }, + watch: { + "config.isOn": function () { + this.change() + } + }, + methods: { + change: function () { + this.$emit("change", this.config) + }, + changeCode: function (code) { + this.config.code = code + this.change() + } + }, + template: `
+ + + + + + + + + + + + + +
是否启用
脚本代码{{config.code}} +

{{comment}}

+
+
` +}) + Vue.component("ssl-certs-view", { props: ["v-certs"], data: function () { @@ -11725,6 +11815,19 @@ Vue.component("source-code-box", { this.createEditor(box, value, readOnly) }, + data: function () { + let index = sourceCodeBoxIndex++ + + let valueBoxId = 'source-code-box-value-' + sourceCodeBoxIndex + if (this.id != null) { + valueBoxId = this.id + } + + return { + index: index, + valueBoxId: valueBoxId + } + }, methods: { createEditor: function (box, value, readOnly) { let boxEditor = CodeMirror.fromTextArea(box, { @@ -11739,7 +11842,11 @@ Vue.component("source-code-box", { lineWrapping: true, highlightFormatting: false, indentUnit: 4, - indentWithTabs: true + indentWithTabs: true, + }) + let that = this + boxEditor.on("change", function () { + that.change(boxEditor.getValue()) }) boxEditor.setValue(value) @@ -11762,19 +11869,9 @@ Vue.component("source-code-box", { CodeMirror.modeURL = "/codemirror/mode/%N/%N.js" CodeMirror.autoLoadMode(boxEditor, info.mode) } - } - }, - data: function () { - let index = sourceCodeBoxIndex++ - - let valueBoxId = 'source-code-box-value-' + sourceCodeBoxIndex - if (this.id != null) { - valueBoxId = this.id - } - - return { - index: index, - valueBoxId: valueBoxId + }, + change: function (code) { + this.$emit("change", code) } }, template: `
diff --git a/web/public/js/components/common/source-code-box.js b/web/public/js/components/common/source-code-box.js index b83af969..19ccbb56 100644 --- a/web/public/js/components/common/source-code-box.js +++ b/web/public/js/components/common/source-code-box.js @@ -18,6 +18,19 @@ Vue.component("source-code-box", { this.createEditor(box, value, readOnly) }, + data: function () { + let index = sourceCodeBoxIndex++ + + let valueBoxId = 'source-code-box-value-' + sourceCodeBoxIndex + if (this.id != null) { + valueBoxId = this.id + } + + return { + index: index, + valueBoxId: valueBoxId + } + }, methods: { createEditor: function (box, value, readOnly) { let boxEditor = CodeMirror.fromTextArea(box, { @@ -32,7 +45,11 @@ Vue.component("source-code-box", { lineWrapping: true, highlightFormatting: false, indentUnit: 4, - indentWithTabs: true + indentWithTabs: true, + }) + let that = this + boxEditor.on("change", function () { + that.change(boxEditor.getValue()) }) boxEditor.setValue(value) @@ -55,19 +72,9 @@ Vue.component("source-code-box", { CodeMirror.modeURL = "/codemirror/mode/%N/%N.js" CodeMirror.autoLoadMode(boxEditor, info.mode) } - } - }, - data: function () { - let index = sourceCodeBoxIndex++ - - let valueBoxId = 'source-code-box-value-' + sourceCodeBoxIndex - if (this.id != null) { - valueBoxId = this.id - } - - return { - index: index, - valueBoxId: valueBoxId + }, + change: function (code) { + this.$emit("change", code) } }, template: `
diff --git a/web/public/js/components/server/http-request-scripts-config-box.js b/web/public/js/components/server/http-request-scripts-config-box.js new file mode 100644 index 00000000..10994de0 --- /dev/null +++ b/web/public/js/components/server/http-request-scripts-config-box.js @@ -0,0 +1,35 @@ +Vue.component("http-request-scripts-config-box", { + props: ["vRequestScriptsConfig"], + data: function () { + let config = this.vRequestScriptsConfig + if (config == null) { + config = {} + } + return { + config: config + } + }, + methods: { + changeInitScript: function (scriptConfig) { + this.config.onInitScript = scriptConfig + this.$forceUpdate() + }, + changeRequestScript: function (scriptConfig) { + this.config.onRequestScript = scriptConfig + this.$forceUpdate() + } + }, + template: `
+ +
+

请求初始化

+
+ +
+

准备发送请求

+
+ +
+
+
` +}) \ No newline at end of file diff --git a/web/public/js/components/server/script-config-box.js b/web/public/js/components/server/script-config-box.js new file mode 100644 index 00000000..2de7e19d --- /dev/null +++ b/web/public/js/components/server/script-config-box.js @@ -0,0 +1,53 @@ +Vue.component("script-config-box", { + props: ["id", "v-script-config", "comment"], + data: function () { + let config = this.vScriptConfig + if (config == null) { + config = { + isPrior: false, + isOn: false, + code: "" + } + } + + if (config.code.length == 0) { + config.code = "\n\n\n\n" + } + + return { + config: config + } + }, + watch: { + "config.isOn": function () { + this.change() + } + }, + methods: { + change: function () { + this.$emit("change", this.config) + }, + changeCode: function (code) { + this.config.code = code + this.change() + } + }, + template: `
+ + + + + + + + + + + + + +
是否启用
脚本代码{{config.code}} +

{{comment}}

+
+
` +}) \ No newline at end of file