编辑网页防篡改策略信息
功能介绍
编辑网页防篡改策略信息
调用方法
请参见如何调用API。
URI
PUT /v5/{project_id}/webtamper/{host_id}/policy
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
参数解释: 项目ID,用于明确项目归属,配置后可通过该ID查询项目下资产。获取方式请参见获取项目ID。 约束限制: 不涉及 取值范围: 字符长度1-256位 默认取值: 不涉及 |
host_id |
是 |
String |
参数解释: 服务器ID,要求服务器已开启网页防篡改防护 约束限制: 需要使用 ListWtpProtectHost 接口查询网页防篡改主机防护状态列表信息,在 ListWtpProtectHost 接口的响应体中,protect_status 等于 opened,open_failed,protection_pause或partial_protection 的 host_id 是符合修改条件的服务器ID 取值范围: 字符长度1-256位 默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
enterprise_project_id |
否 |
String |
参数解释: 企业项目ID,用于过滤不同企业项目下的资产。获取方式请参见获取企业项目ID。 如需查询所有企业项目下的资产请传参“all_granted_eps”。 约束限制: 开通企业项目功能后才需要配置企业项目ID参数。 取值范围: 字符长度1-256位 默认取值: 0,表示默认企业项目(default)。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
参数解释: 用户Token,包含了用户的身份、权限等信息,在调用API接口时,可通过Token进行身份认证。获取方式请参见获取用户Token。 约束限制: 不涉及 取值范围: 字符长度1-32768位 默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
protect_dir_info |
是 |
防护目录信息 |
|
enable_timing_off |
否 |
Boolean |
参数解释: 定时开关设置状态 约束限制: 不涉及 取值范围:
默认取值: False |
timing_off_config_info |
否 |
定时开关配置详情 |
|
enable_rasp_protect |
否 |
Boolean |
参数解释: 动态网页防篡改开启状态,仅Linux服务器支持。 约束限制: 仅Linux服务器支持开启动态网页防篡改,Windows服务器不可填写该字段。 取值范围:
默认取值: False |
rasp_path |
否 |
String |
参数解释: 动态网页防篡改的Tomcat bin目录,仅Linux服务器支持。 约束限制: 仅Linux服务器支持配置动态网页防篡改的Tomcat bin目录,Windows服务器不可填写该字段。 取值范围: 字符长度1-256位,必须以/开头,不能以/结尾,只能包含英文大小写字母,数字,下划线,中划线和点。 默认取值: 不涉及 |
enable_privileged_process |
否 |
Boolean |
参数解释: 特权进程开启状态 约束限制: 不涉及 取值范围:
默认取值: False |
privileged_process_info |
否 |
特权进程配置详情 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
protect_dir_list |
是 |
Array of WebTamperProtectHostDirRequestInfo objects |
参数解释: 防护目录列表 约束限制: 不涉及 取值范围: 最少1条,最多50条 默认取值: 不涉及 |
exclude_file_type |
否 |
String |
参数解释: 排除文件类型 约束限制: 不涉及 取值范围: 文件类型只能输入字母、数字,最多支持10个文件类型,每个文件类型长度不超过10个字符,多个文件类型以分号隔开。 默认取值: 不涉及 |
protect_mode |
否 |
String |
参数解释: 防护模式,仅Linux服务器支持设置防护模式为告警模式,Windows服务器仅支持拦截模式。 约束限制: 不涉及 取值范围:
默认取值: recovery |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
protect_dir |
是 |
String |
参数解释: 防护目录 约束限制: 不涉及 取值范围: 字符长度1-256位。Linux服务器,必须以/开头,不能以/结尾,只能包含英文大小写字母,数字,下划线,中划线和点。Windows服务器,目录名不能包含;/*?"<>|,不能以空格开头,不能以\结尾。 默认取值: 不涉及 |
exclude_child_dir |
否 |
String |
参数解释: 排除子目录 约束限制: 不涉及 取值范围: 子目录名必须是防护目录的有效相对路径,目录名最大长度不能超过256个字符,最多可添加10个子目录,多个子目录用;隔开。Linux服务器的子目录名不能以/开头或结尾,Windows服务器的子目录名不能以\开头或结尾。 默认取值: 不涉及 |
exclude_file_path |
否 |
String |
参数解释: 排除文件路径 约束限制: 仅Linux服务器支持填写排除文件路径,Windows服务器不可填写该字段。 取值范围: 排除文件路径必须是防护目录的有效相对路径,不能以/开头或结尾,文件路径最大长度不能超过256个字符;最多可添加50个文件路径,多个文件路径用;隔开。 默认取值: 不涉及 |
local_backup_dir |
否 |
String |
参数解释: 本地备份路径,Linux服务器必须填写该字段。 约束限制: 仅Linux服务器需要填写本地备份路径,Windows服务器不可填写该字段。 取值范围: 本地备份路径不能包含;字符,不能以空格开头,不能以/结尾,本地备份路径长度不得超过256个字符。 默认取值: 不涉及 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
week_off_list |
否 |
Array of integers |
参数解释: 自动关闭防护周期列表 约束限制: 不涉及 取值范围: 最少1条,最多7条 默认取值: 不涉及 |
timing_range_list |
否 |
Array of TimingRangeConfigRequestInfo objects |
参数解释: 自动关闭防护时间段 约束限制: 不涉及 取值范围: 最少1条,最多5条 默认取值: 不涉及 |
响应参数
状态码:200
请求已成功
无
请求示例
编辑网页防篡改策略信息。
PUT https://{endpoint}/v5/{project_id}/webtamper/{host_id}/policy { "protect_dir_info" : { "protect_dir_list" : [ { "local_backup_dir" : "/root/test2", "protect_dir" : "/root/test1" }, { "exclude_child_dir" : "pro", "exclude_file_path" : "path", "local_backup_dir" : "/root/test4", "protect_dir" : "/root/test3" } ], "exclude_file_type" : "log;pid;text", "protect_mode" : "recovery" }, "enable_timing_off" : true, "enable_privileged_process" : true, "enable_rasp_protect" : true, "timing_off_config_info" : { "week_off_list" : [ 5, 7 ], "timing_range_list" : [ { "time_range" : "02:00-04:00", "description" : "close" }, { "time_range" : "12:05-14:00" } ] }, "privileged_process_info" : { "privileged_process_path_list" : [ "/usr/bin/echo" ], "privileged_child_status" : true }, "rasp_path" : "/usr/bin/tomcat/bin" }
响应示例
无
SDK代码示例
SDK代码示例如下。
编辑网页防篡改策略信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.hss.v5.region.HssRegion; import com.huaweicloud.sdk.hss.v5.*; import com.huaweicloud.sdk.hss.v5.model.*; import java.util.List; import java.util.ArrayList; public class UpdateWebTamperHostPolicySolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); HssClient client = HssClient.newBuilder() .withCredential(auth) .withRegion(HssRegion.valueOf("<YOUR REGION>")) .build(); UpdateWebTamperHostPolicyRequest request = new UpdateWebTamperHostPolicyRequest(); request.withHostId("{host_id}"); UpdateWebTamperHostPolicyRequestInfo body = new UpdateWebTamperHostPolicyRequestInfo(); List<String> listPrivilegedProcessInfoPrivilegedProcessPathList = new ArrayList<>(); listPrivilegedProcessInfoPrivilegedProcessPathList.add("/usr/bin/echo"); WebTamperPrivilegedProcessRequestInfo privilegedProcessInfobody = new WebTamperPrivilegedProcessRequestInfo(); privilegedProcessInfobody.withPrivilegedProcessPathList(listPrivilegedProcessInfoPrivilegedProcessPathList) .withPrivilegedChildStatus(true); List<TimingRangeConfigRequestInfo> listTimingOffConfigInfoTimingRangeList = new ArrayList<>(); listTimingOffConfigInfoTimingRangeList.add( new TimingRangeConfigRequestInfo() .withTimeRange("02:00-04:00") .withDescription("close") ); listTimingOffConfigInfoTimingRangeList.add( new TimingRangeConfigRequestInfo() .withTimeRange("12:05-14:00") ); List<Integer> listTimingOffConfigInfoWeekOffList = new ArrayList<>(); listTimingOffConfigInfoWeekOffList.add(5); listTimingOffConfigInfoWeekOffList.add(7); WebTamperTimingOffConfigInfoRequestInfo timingOffConfigInfobody = new WebTamperTimingOffConfigInfoRequestInfo(); timingOffConfigInfobody.withWeekOffList(listTimingOffConfigInfoWeekOffList) .withTimingRangeList(listTimingOffConfigInfoTimingRangeList); List<WebTamperProtectHostDirRequestInfo> listProtectDirInfoProtectDirList = new ArrayList<>(); listProtectDirInfoProtectDirList.add( new WebTamperProtectHostDirRequestInfo() .withProtectDir("/root/test1") .withLocalBackupDir("/root/test2") ); listProtectDirInfoProtectDirList.add( new WebTamperProtectHostDirRequestInfo() .withProtectDir("/root/test3") .withExcludeChildDir("pro") .withExcludeFilePath("path") .withLocalBackupDir("/root/test4") ); WebTamperProtectDirRequestInfo protectDirInfobody = new WebTamperProtectDirRequestInfo(); protectDirInfobody.withProtectDirList(listProtectDirInfoProtectDirList) .withExcludeFileType("log;pid;text") .withProtectMode("recovery"); body.withPrivilegedProcessInfo(privilegedProcessInfobody); body.withEnablePrivilegedProcess(true); body.withRaspPath("/usr/bin/tomcat/bin"); body.withEnableRaspProtect(true); body.withTimingOffConfigInfo(timingOffConfigInfobody); body.withEnableTimingOff(true); body.withProtectDirInfo(protectDirInfobody); request.withBody(body); try { UpdateWebTamperHostPolicyResponse response = client.updateWebTamperHostPolicy(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
编辑网页防篡改策略信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkhss.v5.region.hss_region import HssRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkhss.v5 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = HssClient.new_builder() \ .with_credentials(credentials) \ .with_region(HssRegion.value_of("<YOUR REGION>")) \ .build() try: request = UpdateWebTamperHostPolicyRequest() request.host_id = "{host_id}" listPrivilegedProcessPathListPrivilegedProcessInfo = [ "/usr/bin/echo" ] privilegedProcessInfobody = WebTamperPrivilegedProcessRequestInfo( privileged_process_path_list=listPrivilegedProcessPathListPrivilegedProcessInfo, privileged_child_status=True ) listTimingRangeListTimingOffConfigInfo = [ TimingRangeConfigRequestInfo( time_range="02:00-04:00", description="close" ), TimingRangeConfigRequestInfo( time_range="12:05-14:00" ) ] listWeekOffListTimingOffConfigInfo = [ 5, 7 ] timingOffConfigInfobody = WebTamperTimingOffConfigInfoRequestInfo( week_off_list=listWeekOffListTimingOffConfigInfo, timing_range_list=listTimingRangeListTimingOffConfigInfo ) listProtectDirListProtectDirInfo = [ WebTamperProtectHostDirRequestInfo( protect_dir="/root/test1", local_backup_dir="/root/test2" ), WebTamperProtectHostDirRequestInfo( protect_dir="/root/test3", exclude_child_dir="pro", exclude_file_path="path", local_backup_dir="/root/test4" ) ] protectDirInfobody = WebTamperProtectDirRequestInfo( protect_dir_list=listProtectDirListProtectDirInfo, exclude_file_type="log;pid;text", protect_mode="recovery" ) request.body = UpdateWebTamperHostPolicyRequestInfo( privileged_process_info=privilegedProcessInfobody, enable_privileged_process=True, rasp_path="/usr/bin/tomcat/bin", enable_rasp_protect=True, timing_off_config_info=timingOffConfigInfobody, enable_timing_off=True, protect_dir_info=protectDirInfobody ) response = client.update_web_tamper_host_policy(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
编辑网页防篡改策略信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" hss "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/hss/v5/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := hss.NewHssClient( hss.HssClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.UpdateWebTamperHostPolicyRequest{} request.HostId = "{host_id}" var listPrivilegedProcessPathListPrivilegedProcessInfo = []string{ "/usr/bin/echo", } privilegedChildStatusPrivilegedProcessInfo:= true privilegedProcessInfobody := &model.WebTamperPrivilegedProcessRequestInfo{ PrivilegedProcessPathList: &listPrivilegedProcessPathListPrivilegedProcessInfo, PrivilegedChildStatus: &privilegedChildStatusPrivilegedProcessInfo, } timeRangeTimingRangeList:= "02:00-04:00" descriptionTimingRangeList:= "close" timeRangeTimingRangeList1:= "12:05-14:00" var listTimingRangeListTimingOffConfigInfo = []model.TimingRangeConfigRequestInfo{ { TimeRange: &timeRangeTimingRangeList, Description: &descriptionTimingRangeList, }, { TimeRange: &timeRangeTimingRangeList1, }, } var listWeekOffListTimingOffConfigInfo = []int32{ int32(5), int32(7), } timingOffConfigInfobody := &model.WebTamperTimingOffConfigInfoRequestInfo{ WeekOffList: &listWeekOffListTimingOffConfigInfo, TimingRangeList: &listTimingRangeListTimingOffConfigInfo, } localBackupDirProtectDirList:= "/root/test2" excludeChildDirProtectDirList:= "pro" excludeFilePathProtectDirList:= "path" localBackupDirProtectDirList1:= "/root/test4" var listProtectDirListProtectDirInfo = []model.WebTamperProtectHostDirRequestInfo{ { ProtectDir: "/root/test1", LocalBackupDir: &localBackupDirProtectDirList, }, { ProtectDir: "/root/test3", ExcludeChildDir: &excludeChildDirProtectDirList, ExcludeFilePath: &excludeFilePathProtectDirList, LocalBackupDir: &localBackupDirProtectDirList1, }, } excludeFileTypeProtectDirInfo:= "log;pid;text" protectModeProtectDirInfo:= "recovery" protectDirInfobody := &model.WebTamperProtectDirRequestInfo{ ProtectDirList: listProtectDirListProtectDirInfo, ExcludeFileType: &excludeFileTypeProtectDirInfo, ProtectMode: &protectModeProtectDirInfo, } enablePrivilegedProcessUpdateWebTamperHostPolicyRequestInfo:= true raspPathUpdateWebTamperHostPolicyRequestInfo:= "/usr/bin/tomcat/bin" enableRaspProtectUpdateWebTamperHostPolicyRequestInfo:= true enableTimingOffUpdateWebTamperHostPolicyRequestInfo:= true request.Body = &model.UpdateWebTamperHostPolicyRequestInfo{ PrivilegedProcessInfo: privilegedProcessInfobody, EnablePrivilegedProcess: &enablePrivilegedProcessUpdateWebTamperHostPolicyRequestInfo, RaspPath: &raspPathUpdateWebTamperHostPolicyRequestInfo, EnableRaspProtect: &enableRaspProtectUpdateWebTamperHostPolicyRequestInfo, TimingOffConfigInfo: timingOffConfigInfobody, EnableTimingOff: &enableTimingOffUpdateWebTamperHostPolicyRequestInfo, ProtectDirInfo: protectDirInfobody, } response, err := client.UpdateWebTamperHostPolicy(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
请求已成功 |
错误码
请参见错误码。