Skip to content

Commit 35f3de7

Browse files
committed
fix named_acl/named_mark config update bug
1 parent 0abc5c7 commit 35f3de7

File tree

10 files changed

+244
-57
lines changed

10 files changed

+244
-57
lines changed

console/src/views/acccess/AccessView.vue

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { onMounted, ref } from 'vue';
33
import TableView from './TableView.vue'
44
import DefaultAction from './ActionView.vue';
5-
import { whm_get } from '@/components/Whm.vue';
5+
import { whm_get, whm_post } from '@/components/Whm.vue';
66
import ModuleView, { type ModuleBase } from './ModuleView.vue';
77
import ModuleSelectView from './ModuleSelectView.vue';
88
@@ -43,7 +43,7 @@ function flush_table() {
4343
});
4444
}
4545
function flush_named_module() {
46-
var param: Record<string, any> = { access: props.access, detail: 1 };
46+
var param: Record<string, any> = { access: props.access, detail: 1 ,type:2};
4747
if (props.vh) {
4848
param["vh"] = props.vh;
4949
}
@@ -91,6 +91,13 @@ function del_named_module(type: number, m: NamedModule) {
9191
if (!confirm("确定要删除命名模块" + m.name + "吗?")) {
9292
return;
9393
}
94+
let param: Record<string, any> = { access: props.access, name: m.name, type: type }
95+
if (props.vh) {
96+
param["vh"] = props.vh;
97+
}
98+
whm_post('del_named_module',param).then((json)=>{
99+
flush_named_module();
100+
})
94101
}
95102
function edit_named_module(type: number, m: NamedModule) {
96103
let param: Record<string, any> = { access: props.access, name: m.name, type: type }
@@ -110,6 +117,28 @@ function select_module(m:ModuleBase) {
110117
}
111118
curEditNamedModule.value.m = m;
112119
}
120+
function submit_edit_named_module() {
121+
if (curEditNamedModule.value==null) {
122+
return;
123+
}
124+
const form: any = document.getElementById("form");
125+
const formData = new FormData(form);
126+
if (props.vh) {
127+
formData.append("vh", props.vh);
128+
}
129+
formData.append("access", props.access);
130+
if (!curEditNamedModule.value.edit) {
131+
formData.append("add", "1");
132+
} else {
133+
if (curEditNamedModule.value.name!=null) {
134+
formData.append("name",curEditNamedModule.value.name);
135+
}
136+
}
137+
whm_post('edit_named_module', formData).then((json) => {
138+
curEditNamedModule.value = null;
139+
flush_named_module();
140+
});
141+
}
113142
</script>
114143
<template>
115144
<div>
@@ -160,7 +189,7 @@ function select_module(m:ModuleBase) {
160189
<td>名称</td>
161190
<td>
162191
<template v-if="!curEditNamedModule.edit">
163-
<input name="module" :value="curEditNamedModule.name"/>
192+
<input name="name" :value="curEditNamedModule.name"/>
164193
</template>
165194
<template v-else>
166195
{{ curEditNamedModule.name }}
@@ -191,7 +220,7 @@ function select_module(m:ModuleBase) {
191220
</tr>
192221
<tr>
193222
<td colspan="2">
194-
<button @click="">确定</button>
223+
<button @click="submit_edit_named_module()">确定</button>
195224
<button @click="cancel_edit_named_module()">取消</button>
196225
</td>
197226
</tr>

console/src/views/acccess/ChainView.vue

Lines changed: 67 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
import { onMounted, ref } from 'vue';
33
import ModuleView, { type ModuleBase } from './ModuleView.vue';
44
import ModuleSelectView from './ModuleSelectView.vue'
5+
import NamedModuleSelectView ,{type NamedModuleSelect} from './NamedModuleSelectView.vue';
56
6-
export interface Module extends ModuleBase{
7+
export interface Module extends ModuleBase {
78
is_or: number,
89
revers: number,
910
ref?: string
@@ -20,7 +21,7 @@ export interface ChainValue {
2021
mark?: Module[],
2122
}
2223
export interface Chain {
23-
add?:boolean,
24+
add?: boolean,
2425
action: string,
2526
jump?: string,
2627
k: ChainKey,
@@ -43,7 +44,7 @@ function submit_chain() {
4344
formData.append("index", props.chain.k.index.toString());
4445
formData.append("id", props.chain.k.id.toString());
4546
if (props.chain.add) {
46-
formData.append("add","1");
47+
formData.append("add", "1");
4748
}
4849
fetch('/core.whm?whm_call=edit_chain&format=json', {
4950
method: 'POST',
@@ -74,27 +75,25 @@ function updateModule(type: number, index: number, module: string) {
7475
chain_value.value.mark[index].module = module
7576
}
7677
}
77-
function UpModule(type:number,index:number) {
78-
if (index==0) {
79-
return;
80-
}
81-
if (chain_value.value == null) {
78+
function UpModule(type: number, index: number) {
79+
if (index == 0 || chain_value.value == null) {
8280
return;
8381
}
82+
8483
if (type == 0) {
8584
if (chain_value.value?.acl == null) {
8685
return;
8786
}
88-
var m = chain_value.value.acl[index];
89-
chain_value.value.acl[index] = chain_value.value.acl[index-1];
90-
chain_value.value.acl[index-1] = m;
87+
var m = chain_value.value.acl[index];
88+
chain_value.value.acl[index] = chain_value.value.acl[index - 1];
89+
chain_value.value.acl[index - 1] = m;
9190
} else {
9291
if (chain_value.value?.mark == null) {
9392
return
9493
}
95-
var m = chain_value.value.mark[index];
96-
chain_value.value.mark[index] = chain_value.value.mark[index-1];
97-
chain_value.value.mark[index-1] = m;
94+
var m = chain_value.value.mark[index];
95+
chain_value.value.mark[index] = chain_value.value.mark[index - 1];
96+
chain_value.value.mark[index - 1] = m;
9897
}
9998
}
10099
function delModule(type: number, index: number) {
@@ -144,42 +143,65 @@ function addModule(type: number, index: number) {
144143
chain_value.value.mark.splice(index, 0, emptyModule)
145144
}
146145
}
147-
*/
146+
*/
147+
function addNamedModule(type: number, mb: NamedModuleSelect) {
148+
if (chain_value.value == null) {
149+
return;
150+
}
151+
let m: Module = {
152+
is_or: 0,
153+
revers: 0,
154+
html: "",
155+
ref: mb.name,
156+
module: mb.module
157+
};
158+
if (type == 0) {
159+
if (chain_value.value?.acl == null) {
160+
chain_value.value.acl = <Module[]>[];
161+
}
162+
chain_value.value.acl.push(m);
163+
} else {
164+
if (chain_value.value?.mark == null) {
165+
chain_value.value.mark = <Module[]>[];
166+
}
167+
chain_value.value.mark.push(m);
168+
}
169+
}
148170
function addModule(type: number, mb: ModuleBase) {
149171
if (chain_value.value == null) {
150172
return;
151173
}
152-
let m:Module = {
153-
is_or:0,
154-
revers:0,
155-
html:mb.html,
156-
module:mb.module
174+
let m: Module = {
175+
is_or: 0,
176+
revers: 0,
177+
html: mb.html,
178+
module: mb.module
157179
};
158180
if (type == 0) {
159181
if (chain_value.value?.acl == null) {
160182
chain_value.value.acl = <Module[]>[];
161-
}
162-
chain_value.value.acl.push(m);
183+
}
184+
chain_value.value.acl.push(m);
163185
} else {
164186
if (chain_value.value?.mark == null) {
165187
chain_value.value.mark = <Module[]>[];
166-
}
167-
chain_value.value.mark.push(m);
188+
}
189+
chain_value.value.mark.push(m);
168190
}
169191
}
170192
onMounted(() => {
171193
if (!props.chain.add) {
172194
fetch('/core.whm?whm_call=get_chain&access=' + props.access +
173195
'&table=' + props.table +
174196
'&file=' + props.chain.k.file +
175-
'&index=' + props.chain.k.index +
176-
(props.vh?'&vh='+props.vh:"") +
197+
'&index=' + props.chain.k.index +
198+
(props.vh ? '&vh=' + props.vh : "") +
177199
'&id=' + props.chain.k.id +
178200
'&format=json').then((res) => res.json()).then((json) => {
179201
chain_value.value = json.result;
180202
});
181203
} else {
182-
chain_value.value = {hit:0}
204+
chain_value.value = { hit: 0 }
183205
}
184206
}
185207
);
@@ -195,39 +217,38 @@ onMounted(() => {
195217
</tr>
196218
<template v-for="(modules, type) in [chain_value.acl, chain_value.mark]">
197219
<tr v-for="(m, index) in modules">
198-
<td>
220+
<td>
199221
[<a href=# @click="delModule(type, index)">删</a>]
200222
[<a href=# @click="UpModule(type, index)">UP</a>]
201223
<span v-if="m.module">
202224
{{ m.module }}
203225
</span>
204226
</td>
205227
<td>
206-
<div v-if="m.module != ''">
207-
<input type="hidden" name="begin_sub_form"
208-
:value="(type == 0 ? 'acl_' : 'mark_') + m.module" />
209-
<template v-if="m.ref">
210-
<input type="hidden" name="ref" :value="m.ref" />ref:{{ m.ref }}
211-
</template>
212-
<template v-else>
213-
<ModuleView :module="m" />
214-
</template>
215-
<input type="hidden" name="end_sub_form" value='1' />
216-
</div>
217-
<div v-else>
218-
<ModuleSelectView :access="props.access" :type="type"/>
219-
</div>
228+
229+
<input type="hidden" name="begin_sub_form" :value="(type == 0 ? 'acl_' : 'mark_') + m.module" />
230+
<template v-if="m.ref">
231+
<input type="hidden" name="ref" :value="m.ref" />命名模块:{{ m.ref }}
232+
</template>
233+
<template v-else>
234+
<ModuleView :module="m" />
235+
</template>
236+
<input type="hidden" name="end_sub_form" value='1' />
237+
220238
</td>
221239
</tr>
222-
223240
<tr>
224-
<td colspan="2">{{ type==0?"可用的匹配模块":"可用的标记模块" }}<ModuleSelectView @select_module="addModule(type,$event)" :access="props.access" :type="type"/></td>
241+
<td colspan="2">
242+
<ModuleSelectView @select_module="addModule(type, $event)" :access="props.access" :type="type" />
243+
<NamedModuleSelectView @select_module="addNamedModule(type, $event)" :access="props.access"
244+
:type="type" />
245+
</td>
225246
</tr>
226247
</template>
227248
<tr>
228249
<td colspan="2">
229-
<button @click="submit_chain()">确定</button>
230-
<button @click="cancel_chain()">取消</button>
250+
<button @click="submit_chain()">确定</button>
251+
<button @click="cancel_chain()">取消</button>
231252
</td>
232253
</tr>
233254
</table>

console/src/views/acccess/ModuleSelectView.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ onMounted(flush_module);
3737
</script>
3838
<template>
3939
<template v-if="modules!=null">
40+
{{ type==0?"可用的匹配模块":"可用的标记模块" }}
4041
<select @change="select_module($event)">
4142
<option value="">--请选择--</option>
4243
<template v-for="module in modules">

console/src/views/acccess/ModuleView.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { computed, onMounted, ref, watchEffect } from 'vue';
33
export interface ModuleBase {
44
module: string,
55
html: string,
6+
refs?: number,
67
}
78
89
const props = defineProps<{

include/KAccess.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ class KAccess final : public kconfig::KConfigListen
118118
void listTable(KVirtualHostEvent* ctx);
119119
int dump_chain(KVirtualHostEvent* ctx,const KString table_name);
120120
int dump_named_module(KVirtualHostEvent* ctx, bool detail);
121+
/*
122+
* type=0 acl
123+
* type=1 mark
124+
*/
125+
int dump_available_named_module(KVirtualHostEvent* ctx, int type,bool only_public);
121126
int get_named_module(KVirtualHostEvent* ctx, const KString &name, bool is_mark);
122127
int get_module(KVirtualHostEvent* ctx, const KString& name, bool is_mark);
123128
public:
@@ -129,6 +134,7 @@ class KAccess final : public kconfig::KConfigListen
129134
static bool addAclModel(u_short type, KAcl* acl, bool replace = false);
130135
static bool addMarkModel(u_short type, KMark* acl, bool replace = false);
131136
static void build_action_attribute(KXmlAttribute& attribute, const KUrlValue& uv);
137+
bool named_module_can_remove(const KString& name, int type);
132138
private:
133139
~KAccess();
134140
void inter_destroy();

include/KUrlValue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class KUrlValue
3232
KXmlAttribute attribute;
3333
khttpd::KSafeXmlNode to_xml(const char *tag,size_t len,const char *vary=nullptr,size_t vary_len=0) {
3434
auto xml = kconfig::new_xml(tag, len,vary,vary_len);
35-
xml->attributes().swap(attribute);
35+
xml->attributes().merge(attribute);
3636
return xml;
3737
}
3838
const KString &operator[](const KString&name) const

module/whm/WhmCore.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ int WhmCore::call_check_vh_db(const char* call_name, const char* event_type, Whm
303303
}
304304
return WHM_OK;
305305
}
306+
int WhmCore::call_list_available_named_module(const char* call_name, const char* event_type, WhmContext* ctx) {
307+
auto access = whm_get_access(ctx);
308+
if (!access) {
309+
return WHM_CALL_FAILED;
310+
}
311+
return access->dump_available_named_module(ctx, ctx->getUrlValue()->attribute.get_int("type"), false);
312+
}
306313
int WhmCore::call_list_named_module(const char* call_name, const char* event_type, WhmContext* ctx) {
307314
auto access = whm_get_access(ctx);
308315
if (!access) {
@@ -403,4 +410,50 @@ int WhmCore::call_kill_process(const char* call_name, const char* event_type, Wh
403410
int WhmCore::call_list_connect_per_ip(const char* call_name, const char* event_type, WhmContext* ctx) {
404411
kangle::dump_connect_per_ip(ctx->data());
405412
return WHM_OK;
413+
}
414+
int WhmCore::call_del_named_module(const char* call_name, const char* event_type, WhmContext* ctx) {
415+
auto access = whm_get_access(ctx);
416+
if (!access) {
417+
return WHM_CALL_NOT_FOUND;
418+
}
419+
auto uv = ctx->getUrlValue();
420+
auto type = uv->attribute.get_int("type");
421+
auto name = uv->attribute["name"];
422+
if (!access->named_module_can_remove(name, type)) {
423+
ctx->setStatus("named module is used");
424+
return WHM_CALL_FAILED;
425+
}
426+
KStringBuf path;
427+
path << uv->get("access") << (type == 0 ? "/named_acl@"_CS : "/named_mark@"_CS) << name;
428+
return config_result(kconfig::remove(path.str().str(), 0), ctx);
429+
}
430+
int WhmCore::call_edit_named_module(const char* call_name, const char* event_type, WhmContext* ctx) {
431+
KStringBuf path;
432+
auto access = whm_get_access(ctx);
433+
if (!access) {
434+
return WHM_CALL_FAILED;
435+
}
436+
auto uv = ctx->getUrlValue();
437+
auto type = uv->attribute.get_int("type");
438+
auto name = uv->attribute["name"];
439+
path << uv->get("access") << (type == 0 ? "/named_acl@"_CS : "/named_mark@"_CS) << name;
440+
auto add = uv->attribute.get_int("add");
441+
auto it = uv->subs.begin();
442+
if (it == uv->subs.end()) {
443+
return WHM_CALL_FAILED;
444+
}
445+
khttpd::KSafeXmlNode xml;
446+
if (strncmp((*it).first.c_str(), _KS("acl")) == 0) {
447+
xml = (*it).second->to_xml(_KS("named_acl"),name.c_str(),name.size());
448+
xml->attributes().emplace("module"_CS, (*it).first.substr(4));
449+
} else if (strncmp((*it).first.c_str(), _KS("mark")) == 0) {
450+
xml = (*it).second->to_xml(_KS("named_mark"), name.c_str(), name.size());
451+
xml->attributes().emplace("module"_CS, (*it).first.substr(5));
452+
} else {
453+
return WHM_CALL_FAILED;
454+
}
455+
if (add) {
456+
return config_result(kconfig::update(path.str().str(), 0, xml.get(), kconfig::EvNew), ctx);
457+
}
458+
return config_result(kconfig::update(path.str().str(), 0, xml.get(), kconfig::EvUpdate), ctx);
406459
}

0 commit comments

Comments
 (0)