网页加速、下载分发、动态加速、全站加速、点播分发、直播分发、上传加速、移动加速、上网加速、S-P2P、PCDN、应用性能管理、WEB应用防火墙、BotGuard爬虫管理、WSS、DMS、DDoS云清洗、IPv6一体化解决方案、电商安全加速解决方案、金融安全加速解决方案、政企安全加速解决方案、应用安全解决方案、区块链安全加速解决方案、IPv6安全加速解决方案
修改时间戳防盗链
单用户调用频率:300/5min
Open API在线调试功能提供可视化界面在线调试API、支持生成代码示例、快速检索查看API文档等能力。前往调试
参数名称 | 类型 | 必填 | 描述 |
---|---|---|---|
domain | String | 是 | 需要查询配置的域名或域名id |
参数名称 | 类型 | 必填 | 描述 |
---|---|---|---|
timestamp-visit-control-rule | Object | 是 | 时间戳防盗链设置
注意:
1、时间戳防盗链分为两部分,一部分是防盗链校验,一部分是时间有效性校验。二者都有效,则防盗链通过,否则不通过。
2、防盗链校验:加密算法为md5sum,按照参与MD5计算的参数及组合顺序进行防盗链加密串的计算,对匹配目录下所有文件的url进行防盗链校验,未匹配到的url,则拒绝访问。
3、时间有效性检验:按照年月日时分秒换算的当前时间,与请求url中所带的名文时间相减,判断是否超过设置的上下限(即前后60s内),时间差小于设置上下限的,系统才会给予正常的响应,否则拒绝请求,返回403
4、日志记录没有带加密串的url
6、需要清空时间戳防盗链规则时,可以只传入节点 |
path-pattern | String | 否 | url匹配模式,支持正则,如果是全部匹配,入参可以配置为:.* 对匹配到的URL进行时间戳防盗链验证;未匹配到的URL,则拒绝。 |
except-path-pattern | String | 否 | 例外的url匹配模式,某些URL除外:如abc.jpg,不做防盗链 |
protocol-of-path-pattern | String | 否 | 可选值为: http、https、http;https、noprefix、空。为空默认为"http;https";为noprefix表示不指定url的协议前缀,仅按path-pattern的正则匹配。本配置项只与path-pattern(url匹配模式)结合匹配。 例子: 1、指定protocol-of-path-pattern=https,path-pattern=.*,则匹配所有https的请求,不匹配http的请求。 2、指定protocol-of-path-pattern=http;https,path-pattern=.*,则匹配所有http和https的请求。 3、指定protocol-of-path-pattern=noprefix,path-pattern=^http://[^/]+/.*,则匹配所有http的请求,不匹配https的请求。 |
directory | String | 否 | 目录,多个以英文分号隔开。对于匹配到的目录进行时间戳防盗链验证;未匹配到的则拒绝。和path-pattern互斥。 |
allowed-ips | String | 否 | 例外的IP,支持输入IP或IP段,IP段之间用分号(;)隔开,如1.1.1.0/24;2.2.2.2,某些IP例外,不做防盗链 |
ignore-uri-slash | String | 否 | 防盗链中的$uri是否去掉/,可选值为true、false,默认为false,即包含/。 例如: http://www.test.com/1.flv,则$uri默认为/1.flv,若ignore-uri-slash为true,则$uri为1.flv |
ignore-key-and-time-position | String | 否 | key与time是否允许互换,可选值为true和false,true则允许,false则不允许。默认情况下,密钥参数和时间参数的顺序,必须严格参照鉴权模式要求的顺序,即,默认key和time不能互换位置。如选择true,key和time位置可以互换并鉴权成功。 |
encrypt-method | String | 否 | 加密算法 当前支持入参:md5sum |
cipher-combination | String | 否 | 防盗链生成方式,参与MD5计算的参数及组合顺序,仅支持传入以下参数:
$uri:介于domain和问号之间的字符串
例如http://cdn.example.com/v0/test.dat?k=v,则URI为/v0/test.dat
$ourkey:秘钥,实际秘钥在入参 |
secret-key | String | 否 | 防盗链加密串的秘钥,只允许传入一个秘钥
示例: |
cipher-param | String | 否 | 防盗链串的参数名称
示例: |
time-param | String | 否 | 时间串的参数名称
示例: |
lower-limit-expiry-time | Integer | 否 | 防盗链串的过期时间下限
示例:
|
upper-limit-expiry-time | Integer | 否 | 防盗链串的过期时间上限
示例:
|
multiple-secret-keys | String | 否 | 防盗链加密串,支持多个加密串,多个加密串以分号(;)隔开
示例: |
time-format | String | 否 | 防盗链加密串时间格式,可多选,以分号(;)分隔
年|月|日|时|分|秒|UNIX时间戳|16进制时间戳:1Y;2m;3d;4H;5M;6S;7s;8x
示例: |
request-url-style | String | 否 | 防盗链请求url格式,支持两种防盗链方式,即加密串和时间戳放到“?”后面或者是加密串和时间戳放到“host”后面,url格式支持的参数如下:
$domain:域名
$uri:不包含域名的url部分
$key:防盗链加密串的MD5值
$time:防盗链时间串
$args:问号后的QUERY_STRING参数
示例:支持以下请求url格式,可替换为https://,url请求协议根据实际使用,如不知道如何正确配置,请找客户技术支持协助;携带加密串和时间串两个值的参数名“keyname”和“tname”,可替换为实际使用的参数名
|
dst-style | Integer | 否 | 防盗链回源方式,可选值:1(使用未加密url回源)、2(使用客户请求带加密串url回源)
示例: |
log-format | String | 否 | 日志记录原始url,可选值:true(日志记录原始url)、false(不开启日志记录原始url) |
url-key | String | 否 | 用于配置获取url中的key的名称
示例: |
参数名称 | 类型 | 描述 |
---|---|---|
http status code | Integer | httpstatus=202; 表示成功调用新增域名接口,可使用header中的x-cnc-request-id查看当前新增域名的部署情况 |
x-cnc-request-id | String | 唯一标示的id,用于查询每次请求的任务 (适用全部接口) |
code | String | 错误代码,当HTTPStatus不为202时出现,表示当前请求调用的错误类型 |
message | String | 响应信息,成功时为success |
错误代码(code) | 描述(message) | HTTP状态码 | 语义 |
---|---|---|---|
InternalError | We encountered an internal error. Please try again. | 500 | 内部错误 |
InvalidParameter | No domain was specified. | 400 | uri中没有指定域名或者域名ID |
NoSuchDomain | The specified domain does not exist. | 404 | 指定的域名不存在 |
ConfigError | The config {} does not access. | 400 | 域名没有规划指定配置,无法修改 |
DomainNotRestored | The domain you are trying to cancel has not been restored. | 409 | 请求的域名已经取消结束,无法修改 |
Forbidden | The domain is being deleted | 403 | 请求的域名已经挂起,无法修改 |
WrongDataId | Wrong data-d. | 400 | 错误的DataId |
InternalError | We encountered an internal error. Please try again. | 500 | 内部错误 |
NoSuchDomain | The specified domain does not exist. | 404 | 请求的域名不存在 |
CustomerNoOwnDomain | customer not own domain name[*] | 400 | 请求账号无法操作请求的域名 |
InvalidParameter | No domain was specified. | 400 | uri中没有指定域名或者域名ID |
InvalidParameter | The specified allowed-ips was invalid. | 400 | 参数allowed-ips的格式不正确 |
InvalidParameter | The specified cipher-combination was invalid. | 400 | 参数cipher-combination的格式不正确 |
InvalidParameter | The specified lower-limit-expiry-time must be digits. | 400 | 参数lower-limit-expiry-time的格式不正确 |
InvalidParameter | The specified upper-limit-expiry-time must be digits. | 400 | 参数upper-limit-expiry-time的格式不正确 |
InvalidParameter | The specified time-format was invalid. | 400 | 参数time-format的格式不正确 |
InvalidParameter | The time-format's value separated by semicolon can appear only once. | 400 | 参数time-format中的数据不能出现重复的 |
InvalidParameter | The specified request-url-style was invalid. | 400 | 参数request-url-style的格式不正确 |
InvalidParameter | The specified dst-style is either 1 or 2. | 400 | 参数dst-style的格式不正确 |
InvalidParameter | The specified encrypt-method was invalid. | 400 | 参数encrypt-method的格式不正确 |
InvalidParameter | The specified log-format was invalid. | 400 | 参数log-format的格式不正确 |
InvalidParameter | The specified m3u8 was invalid. | 400 | 参数lm3u8的格式不正确 |
InvalidParameter | The path-pattern is required when path-pattern-protocol has value. | 400 | 参数timestamp-control-rule/path-pattern-protocol存在时,参数timestamp-control-rule/path-pattern也必须存在 |
InvalidParameter | The specified (timestamp-control-rule/path-pattern-protocol) was invalid. | 400 | 参数timestamp-control-rule/path-pattern-protocol的格式不正确 |
InvalidParameter | The except-path-pattern is required when except-path-pattern-protocol has value. | 400 | 参数timestamp-control-rule/except-path-pattern-protocol存在时参数timestamp-control-rule/except-path-pattern也必须存在 |
InvalidParameter | The specified (timestamp-control-rule/except-path-pattern-protocol) was invalid. | 400 | 参数timestamp-control-rule/except-path-pattern-protocol的格式不正确 |
InvalidParameter | The specified (timestamp-control-rule/cipher-combination) was invalid. | 400 | 参数timestamp-control-rule/cipher-combination的格式不正确 |
InvalidParameter | The specified (timestamp-control-rule/lower-limit-expiry-time) must be digits. | 400 | 参数timestamp-control-rule/lower-limit-expiry-time的格式不正确 |
InvalidParameter | The specified (timestamp-control-rule/upper-limit-expiry-time) must be digits. | 400 | 参数timestamp-control-rule/upper-limit-expiry-time的格式不正确 |
InvalidParameter | The specified (timestamp-control-rule/request-url-style) was invalid. | 400 | 参数timestamp-control-rule/request-url-style的格式不正确 |
InvalidParameter | The (timestamp-control-rule/uri-select) was invalid. | 400 | 参数timestamp-control-rule/uri-select的格式不正确 |
InvalidParameter | Conflicting request parameters,The parameters "cipher-combination|secret-key|cipher-param|time-param|lower-limit-expiry-time|upper-limit-expiry-time" must only exist in "timestamp-visit-control-rule" or "timestamp-control-rules". | 400 | 参数cipher-combination|secret-key|cipher-param|time-param|lower-limit-expiry-time|upper-limit-expiry-time 同时仅能在父标签timestamp-visit-control-rule或者timestamp-control-rules下的一处配置 |
InvalidParameter | Conflicting request parameters, The parameters "request-url-style" must only exist in "timestamp-visit-control-rule" or "timestamp-control-rules". | 400 | 参数request-url-style同时仅能在父标签timestamp-visit-control-rule或者timestamp-control-rules下的一处配置 |
MalformedXML | 400 | 参数request-url-style的格式不正确,?后的$key或者$time对应的参数需要符合预期 | |
ConfigError | [The format of request URL] just one value can be configured. | 400 | 配置[请求url格式]仅能在一处配置 |
ConfigError | [Access Control generation method] just one value can be configured. | 400 | 配置[防盗链生成方式]仅能在一处配置 |
InvalidParameter | The path-pattern and directory cannot have values at the same time. | 400 | path-pattern 和 directory 不能同时有值 |
#!/bin/bash username="example_username" apiKey="example_apiKey" date=`env LANG="en_US.UTF-8" date -u "+%a, %d %b %Y %H:%M:%S GMT"` password=`echo -en "$date" | openssl dgst -sha1 -hmac $apiKey -binary | openssl enc -base64` curl -i --url "https://open.chinanetcenter.com/api/config/timecontrol/www.aaa.com" \ -X "PUT" \ -u "$username:$password" \ -H "Date: $date" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d '{ "timestamp-visit-control-rule":{ "path-pattern":"/*", "except-path-pattern":"/*", "allowed-ips":"1.1.1.1", "cipher-combination":"$uri$ourkey$time$args{param1}", "secret-key":"ad", "cipher-param":"keyname", "time-param":"tname", "lower-limit-expiry-time":"60", "upper-limit-expiry-time":"60", "multiple-secret-keys":"60", "time-format":"1Y;2m;3d;4H;5M;6S;7s;8x", "request-url-style":"http://$domain/$uri?$args&keyname=$key&tname=$time", "dst-style":"1", "encrypt-method":"md5sum" } }'
HTTP/1.1 202 Accepted Server: openresty/1.11.2.2 Date: Wed, 15 May 2019 07:31:43 GMT Content-Type: application/json;charset=utf-8 Content-Length: 60 Connection: keep-alive App-Name: service_confApi x-cnc-request-id: 5c429816-5fda-4d6d { "message":"success", "code":"" }