Smartrules
Smartrules - Firewall - Alterar
Alterar uma smartrule de firewall.
Smartrules disponível a partir do plano GROWTH
PUT /v1/rules/firewall/{dominio}/{id}
$ curl -i https://api.gocache.com.br/v1/rules/firewall/seudominio.com.br/aabbccddeeffgghh \
-X PUT \
-H 'GoCache-Token:seu_token' \
-d 'match[host]=www.gocache.com.br' \
-d 'match[scheme]=https' \
-d 'match[request_uri]=/static/js/*' \
-d 'match[request_method]=GET' \
-d 'match[request_method]=POST' \
-d 'match[remote_address]=255.255.255.0/24' \
-d 'match[cookie]=mycookie1,mycookie2,mycookie3' \
-d 'match[cookie_content]=mycookie1=123*' \
-d 'match[header]=Accept:*' \
-d 'match[http_referer]=www.google.com.br' \
-d 'match[http_user_agent]=*Mozilla*' \
-d 'match[origin_country]=US|UK' \
-d 'match[origin_continent]=SA' \
-d 'match[origin_continent]=EU' \
-d 'match[http_version]=HTTP/1.0' \
-d 'match[http_version]=HTTP/1.1' \
-d 'match[device_type]=mobile' \
-d 'match[device_type]=bot' \
-d 'match[bots]=known' \
-d 'action[action]=block'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/firewall/seudominio.com.br/aabbccddeeffgghh");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$urls = array(
"match[host]=www.gocache.com.br",
"match[scheme]=https",
"match[request_uri]=/static/js/*",
"match[request_method]=GET",
"match[request_method]=POST",
"match[remote_address]=255.255.255.0/24",
"match[cookie]=mycookie1,mycookie2,mycookie3",
"match[cookie_content]=mycookie1=123*",
"match[header]=Accept:*",
"match[http_referer]=www.google.com.br",
"match[http_user_agent]=*Mozilla*",
"match[origin_country]=US|UK",
"match[origin_continent]=SA",
"match[origin_continent]=EU",
"match[http_version]=HTTP/1.0",
"match[http_version]=HTTP/1.1",
"match[device_type]=mobile",
"match[device_type]=bot",
"match[bots]=known",
"action[action]=block"
);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode("&", $urls));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
Parâmetros
Campo | Opcional | Tipo | Descrição |
---|---|---|---|
metadata | Object | ||
status | Boolean | Indica se a regra está ativa ou inativa Valor padrão: true Valores permitidos:true,false |
|
notes | String | Descrição da regra | |
match | Object | Critério da regra | |
host | String | Domínio/subdomínio de acesso do site. Ex: www.gocache.com.br. | |
scheme | String | Protocolo de acesso. Valores permitidos:http,https,http* |
|
request_uri | String | URI. Ex: /admin/*. | |
http_version | String | Versão do HTTP utilizada Valores permitidos: "HTTP/1.0", "HTTP/1.1", "HTTP/2.0" |
|
device_type | String | Tipo do dispositivo que está realizando a requisição Valores permitidos: "desktop", "mobile", "bot", "na" |
|
http_user_agent | String | User agent. Suporta wildcard (*). Ex: *Mozilla*. | |
cookie | String | Se possui um cookie, de uma lista de um ou mais cookies, presente. Pode ser mais de um, separado por vírgula. Suporta wildcard (*). Ex: wp_login,wp_test. | |
cookie_content | String | Se um cookie possui um valor específico. O nome e o valor são separados igual (=). Suporta wildcard (*) no valor do cookie. Ex: wp_test=yes. | |
request_method | String | Método da requisição Valores permitidos:GET,POST,PUT,DELETE |
|
http_referer | String | Referer da requisição | |
remote_address | String | IP ou range de IP da origem da requisição. Para ranges apenas as máscaras /32, /24 e /16 estão disponíveis | |
header | String | Se a requisiço possui um cabeçalho específico. O nome e o valor são separados por dois-pontos(:). Suporta wildcard (*) no valor do cabeçalho. Ex Accept:*. | |
origin_country | String | País de origem Valores permitidos: "BR", "US", "CN", "RU", "..." |
|
origin_continent | String | Continente de origem Valores permitidos: "SA", "NA", "OC", "EU", "AF", "AS" |
|
bots | String | Bots conhecidos Valores permitidos: "known", "others" |
|
action | Object | Ação | |
action | String | Tipo de liberação do firewall Valores permitidos: "block", "accept", "challenge" |
HTTP/1.1 200 OK
{
"response": {
"msg": "Success"
}
}
<?php
if( $statusCode == 200 ) {
echo("Sucesso!\n");
$obj = json_decode($response);
echo($obj->response->msg);
}
?>
Smartrules - Firewall - Criar
Criar smartrule de firewall
Disponível no plano
POST /v1/rules/firewall/{dominio}
$ curl -i https://api.gocache.com.br/v1/rules/firewall/seudominio.com.br \
-X POST \
-H 'GoCache-Token:seu_token' \
-d 'match[host]=www.gocache.com.br' \
-d 'match[scheme]=https' \
-d 'match[request_uri]=/static/js/*' \
-d 'match[request_method]=GET' \
-d 'match[request_method]=POST' \
-d 'match[remote_address]=255.255.255.0/24' \
-d 'match[cookie]=mycookie1,mycookie2,mycookie3' \
-d 'match[cookie_content]=mycookie1=123*' \
-d 'match[header]=Accept:*' \
-d 'match[http_referer]=www.google.com.br' \
-d 'match[http_user_agent]=*Mozilla*' \
-d 'match[origin_country]=US|UK' \
-d 'match[origin_continent]=SA' \
-d 'match[origin_continent]=EU' \
-d 'match[http_version]=HTTP/1.0' \
-d 'match[http_version]=HTTP/1.1' \
-d 'match[device_type]=mobile' \
-d 'match[device_type]=bot' \
-d 'match[bots]=known' \
-d 'action[action]=block'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/firewall/seudominio.com.br");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$urls = array(
"match[host]=www.gocache.com.br",
"match[scheme]=https",
"match[request_uri]=/static/js/*",
"match[request_method]=GET",
"match[request_method]=POST",
"match[remote_address]=255.255.255.0/24",
"match[cookie]=mycookie1,mycookie2,mycookie3",
"match[cookie_content]=mycookie1=123*",
"match[header]=Accept:*",
"match[http_referer]=www.google.com.br",
"match[http_user_agent]=*Mozilla*",
"match[origin_country]=US|UK",
"match[origin_continent]=SA",
"match[origin_continent]=EU",
"match[http_version]=HTTP/1.0",
"match[http_version]=HTTP/1.1",
"match[device_type]=mobile",
"match[device_type]=bot",
"match[bots]=known",
"action[action]=block"
);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode("&", $urls));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
Parâmetros
Campo | Opcional | Tipo | Descrição |
---|---|---|---|
metadata | Object | ||
status | Boolean | Indica se a regra está ativa ou inativa Valor padrão: true Valores permitidos: true, false |
|
notes | String | Descrição da regra | |
match | Object | Critério da regra | |
host | String | Domínio/subdomínio de acesso do site. Ex: www.gocache.com.br. | |
scheme | String | Protocolo de acesso. Valores permitidos: http, https, http* |
|
request_uri | String | URI. Ex: /admin/*. | |
http_version | String | Versão do HTTP utilizada Valores permitidos: "HTTP/1.0", "HTTP/1.1", "HTTP/2.0" |
|
device_type | String | Tipo do dispositivo que está realizando a requisição Valores permitidos: "desktop", "mobile", "bot", "na" |
|
http_user_agent | String | User agent. Suporta wildcard (*). Ex: *Mozilla*. | |
cookie | String | Se possui um cookie, de uma lista de um ou mais cookies, presente. Pode ser mais de um, separado por vírgula. Suporta wildcard (*). Ex: wp_login,wp_test. | |
cookie_content | String | Se um cookie possui um valor específico. O nome e o valor são separados igual (=). Suporta wildcard (*) no valor do cookie. Ex: wp_test=yes. | |
request_method | String | Método da requisição Valores permitidos: GET, POST, PUT, DELETE |
|
http_referer | String | Referer da requisição | |
remote_address | String | IP ou range de IP da origem da requisição. Para ranges apenas as máscaras /32, /24 e /16 estão disponíveis | |
header | String | Se a requisiço possui um cabeçalho específico. O nome e o valor são separados por dois-pontos (:). Suporta wildcard (*) no valor do cabeçalho. Ex Accept:*. | |
origin_country | String | País de origem Valores permitidos: "BR", "US", "CN", "RU", "..." |
|
origin_continent | String | Continente de origem Valores permitidos: "SA", "NA", "OC", "EU", "AF", "AS" |
|
bots | String | Bots conhecidos Valores permitidos: "known", "others" |
|
action | Object | Ação | |
action | String | Tipo de liberação do firewall Valores permitidos: "block", "accept", "challenge" |
HTTP/1.1 200 OK
{
"response": {
"id": "aXBfYWRkcmVzcy1kZWZhdWx0fGlwX2FkZHJlc3N8MS4xLjEuMQ=="
}
<?php
if( $statusCode == 200 ) {
echo("Sucesso!\n");
$obj = json_decode($response);
echo("ID da regra criada: " . $obj->response->id);
}
?>
Smartrules - Firewall - Listar
Listar as smartrules de firewall de um domínio.
Disponível no plano
GET /v1/rules/firewall/{dominio}
$ curl -i https://api.gocache.com.br/v1/rules/firewall/seudominio.com.br \
-X GET \
-H 'GoCache-Token:seu_token'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/firewall/seudominio.com.br");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
HTTP/1.1 200 OK
{
"response": {
"rule": [
{
"match": {
"host": "www.gocache.com.br",
"request_method": [
"GET",
"POST"
]
},
"action": {
"action": "block"
},
"id": "aabbccddeeff",
"metadata": {
"status": "true"
}
},
{
"match": {
"origin_country": "BR"
},
"action": {
"action": "accept"
},
"id": "gghhiijjkkll",
"metadata": {
"status": "false"
}
}
]
}
}
<?php
if ($statusCode == 200) {
echo ("Sucesso!\n");
$obj = json_decode($response);
foreach ($obj->response->rule as $rule) {
echo ("\n<br /><br />\n");
echo ("Smartrule:" . "<br />\n");
echo ("ID: " . $rule->id . "<br />\n");
foreach ($rule->match as $match_type => $match_value) {
echo ("Match " . $match_type . ": " . $match_value . "<br />\n");
}
foreach ($rule->action as $action_type => $action_value) {
echo ("Action: " . $action_type . ": " . $action_value . "<br />\n");
}
if ($rule->metadata->status == "true") {
echo ("Smartrule enabled<br />\n");
} else {
echo ("Smartrule disabled<br />\n");
}
}
}
?>
Smartrules - Firewall - Remover
Remover uma smartrule de firewall.
Disponível no plano
DELETE /v1/rules/firewall/{dominio}/{id}
$ curl -i https://api.gocache.com.br/v1/rules/firewall/seudominio.com.br/aabbccddeeffgghh \
-X DELETE \
-H 'GoCache-Token:seu_token'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/firewall/seudominio.com.br/aabbccddeeffgghh");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
HTTP/1.1 200 OK
{
"response": {
"msg": "Success"
}
<?php
if( $statusCode == 200 ) {
echo("Sucesso!\n");
$obj = json_decode($response);
echo($obj->response->msg);
}
?>
Smartrules - Geral - Alterar
Alterar uma smartrule geral.
PUT /v1/rules/settings/{dominio}/{id}
$ curl -i https://api.gocache.com.br/v1/rules/settings/seudominio.com.br/aabbccddeeffgghh \
-X PUT \
-H 'GoCache-Token:seu_token' \
-d 'match[host]=www.gocache.com.br' \
-d 'match[scheme]=http*' \
-d 'match[request_uri]=/static/js/*' \
-d 'match[request_method]=GET' \
-d 'match[request_method]=POST' \
-d 'match[remote_address]=255.255.255.0/24' \
-d 'match[cookie]=mycookie1,mycookie2,mycookie3' \
-d 'match[cookie_content]=mycookie1=123*' \
-d 'match[http_referer]=www.google.com.br' \
-d 'match[header]=Accept:*' \
-d 'match[http_user_agent]=*Mozilla*' \
-d 'match[origin_country]=US|UK' \
-d 'match[origin_continent]=SA' \
-d 'match[origin_continent]=EU' \
-d 'match[http_version]=HTTP/1.0' \
-d 'match[http_version]=HTTP/1.1' \
-d 'match[device_type]=mobile' \
-d 'match[device_type]=bot' \
-d 'match[bots]=known' \
-d 'action[set_host]=blog.gocache.com.br' \
-d 'action[backend]=255.255.255.254' \
-d 'action[set_uri]=/js/$1' \
-d 'action[custom_cache_key]=logado,$cookie_user' \
-d 'action[expires_ttl]=14400' \
-d 'action[caching_behavior]=ignore_query_string' \
-d 'action[cache_mode]=default' \
-d 'action[cache_ttl]=86400' \
-d 'action[cors]=http://www.gocache.com.br' \
-d 'action[ssl_mode]=partial' \
-d 'action[connection]=keep-alive' \
-d 'action[hide]=X-Powered-By' \
-d 'action[encoding]=$accept_encoding' \
-d 'action[set]=X-Powered-By-GoCache: true' \
-d 'action[set_req_header][0]=GoCache-Header: true' \
-d 'action[signed_url_key]=1234' \
-d 'action[signed_url_type]=off' \
-d 'action[cache_301]=false' \
-d 'action[cache_302]=false' \
-d 'action[cache_404]=false' \
-d 'action[gzip_status]=false' \
-d 'action[ignore_cache_control]=false' \
-d 'action[ignore_expires]=false' \
-d 'action[ignore_vary]=false' \
-d 'action[waf_status]=true' \
-d 'action[waf_mode]=challenge' \
-d 'action[waf_level]=high' \
-d 'action[waf_rule_action]=CHALLENGE:gocache-v1/90015;SIMULATE:gocache-v1/21003;BLOCK:gocache-v1/41*;'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/settings/seudominio.com.br/aabbccddeeffgghh");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$urls = array(
"match[host]=www.gocache.com.br",
"match[scheme]=http*",
"match[request_uri]=/static/js/*",
"match[request_method]=GET",
"match[request_method]=POST",
"match[remote_address]=255.255.255.0/24",
"match[cookie]=mycookie1,mycookie2,mycookie3",
"match[cookie_content]=mycookie1=123*",
"match[http_referer]=www.google.com.br",
"match[header]=Accept:*",
"match[http_user_agent]=*Mozilla*",
"match[origin_country]=US|UK",
"match[origin_continent]=SA",
"match[origin_continent]=EU",
"match[http_version]=HTTP/1.0",
"match[http_version]=HTTP/1.1",
"match[device_type]=mobile",
"match[device_type]=bot",
"match[bots]=known",
"action[set_host]=blog.gocache.com.br",
"action[backend]=255.255.255.254",
"action[set_uri]=/js/$1",
"action[custom_cache_key]=logado,\$cookie_user",
"action[expires_ttl]=14400",
"action[caching_behavior]=ignore_query_string",
"action[cache_mode]=default",
"action[cache_ttl]=86400",
"action[cors]=http://www.gocache.com.br",
"action[ssl_mode]=partial",
"action[connection]=keep-alive",
"action[hide]=X-Powered-By",
"action[encoding]=\$accept_encoding",
"action[set]=X-Powered-By-GoCache: true",
"action[set_req_header][0]=GoCache-Header: true",
"action[signed_url_key]=1234",
"action[signed_url_type]=off",
"action[cache_301]=false",
"action[cache_302]=false",
"action[cache_404]=false",
"action[gzip_status]=false",
"action[ignore_cache_control]=false",
"action[ignore_expires]=false",
"action[ignore_vary]=false",
"action[waf_status]=true",
"action[waf_mode]=challenge",
"action[waf_level]=high",
"action[waf_rule_action]=gocache-v1/90015,CHALLENGE;gocache-v1/21003,DENY;gocache-v1/41*,SIMULATE;"
);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode("&", $urls));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
Parâmetros
Campo | Opcional | Tipo | Descrição |
---|---|---|---|
metadata | Object | ||
status | Boolean | Indica se a regra está ativa ou inativa Valor padrão: true Valores permitidos: true, false |
|
notes | String | Descrição da regra | |
match | Object | Critério da regra | |
host | String | Domínio/subdomínio de acesso do site. Ex: www.gocache.com.br. | |
scheme | String | Protocolo de acesso. Valores permitidos: http, https, http* |
|
request_uri | String | URI. Ex: /admin/*. | |
http_version | String | Versão do HTTP utilizada Valores permitidos: "HTTP/1.0", "HTTP/1.1", "HTTP/2.0" |
|
device_type | String | Tipo do dispositivo que está realizando a requisição Valores permitidos: "desktop", "mobile", "bot", "na" |
|
http_user_agent | String | User agent. Suporta wildcard (*). Ex: *Mozilla*. | |
cookie | String | Se possui um cookie, de uma lista de um ou mais cookies, presente. Pode ser mais de um, separado por vírgula. Suporta wildcard (*). Ex: wp_login,wp_test. | |
cookie_content | String | Se um cookie possui um valor específico. O nome e o valor são separados igual (=). Suporta wildcard (*) no valor do cookie. Ex: wp_test=yes. | |
request_method | String | Método da requisição Valores permitidos: GET, POST, PUT, DELETE |
|
http_referer | String | Referer da requisição | |
remote_address | String | IP ou range de IP da origem da requisição. Para ranges apenas as máscaras /32, /24 e /16 estão disponíveis | |
header | String | Se a requisiço possui um cabeçalho específico. O nome e o valor são separados por dois-pontos (:). Suporta wildcard (*) no valor do cabeçalho. Ex Accept:*. | |
origin_country | String | País de origem Valores permitidos: "BR", "US", "CN", "RU", "..." |
|
origin_continent | String | Continente de origem Valores permitidos: "SA", "NA", "OC", "EU", "AF", "AS" |
|
bots | String | Bots conhecidos Valores permitidos: "known", "others" |
|
action | Object | Ação | |
set_host | String | Sobrescreve o cabeçalho Host da requisição. Ex: mybucket.s3.amazonaws.com. | |
backend | String | Define o IP ou hostname de destino. Ex: s3.amazonaws.com. | |
set_uri | String | Sobrescreve URI. É possível utilizar o valor do wildcard (*) do parâmetro match.request_uri através da variável $1. Ex: /imagens/$1 | |
custom_cache_key | String | Customiza chave de cache. Permite o uso das variáveis: $cookie_NOME, $http_NOME para utilizar o valor de um cookie/header específico, e $geoip2_data_country_code, $geoip2_data_continent_code para utilizar país/continente. Ex: logado,$cookie_user. Também há a possibilidade de usar parâmetros de url com $1, $2, $3... quando o critério for URL e houver wildcard |
|
expires_ttl | Number | Tempo de cache do navegador, em segundos. O valor -1 desabilita o cache de navegador. Valores permitidos: -1, 3600, 7200, 14400, 43200, 86400, 172800, 345600, 604800, 1296000, 2592000, 15552000, 31536000 |
|
caching_behavior | String | Comportamento do cache Valores permitidos:default,ignore_query_string |
|
cache_mode | String | Tipo de cache (desligado, somente conteúdo estático ou full cache, respectivamente) Valores permitidos:off,default,full |
|
cache_ttl | Number | Tempo de expiração de cache, em segundos. Valores permitidos: 300, 600, 900, 1800, 3600, 7200, 14400, 86400, 172800, 604800, 1296000 |
|
cors | String | Define Cross-Origin. Ex: http://www.gocache.com.br | |
ssl_mode | String | Modo SSL. O valor partial é equivalente ao modo Edge Valores permitidos:partial,full |
|
connection | String | Define o cabeçalho Connection da requisição Valores permitidos: close, keep-alive |
|
hide | String | Remove cabeçalho de resposta. O valor deve ser o nome do cabeçalho | |
encoding | String | Define o cabeçalho Accept-Encoding. Ex: $accept_encoding. | |
set | String | Define um cabeçalho de resposta: Ex: Strict-Transport-Security: max-age=86400. | |
set_req_header | Array | Define um cabeçalho de requisição: Ex: X-GoCache-Custom-Header:true. É possível especificar no máximo 3 cabeçalhos de requisição. |
|
signed_url_key | String | Define a chave da URL assinada | |
signed_url_type | String | Define o tipo de URL assinada Valores permitidos: s3qs, off |
|
cache_301 | Boolean | Ativar/desativar o cache de requisições com status 301 Valores permitidos: true, false |
|
cache_302 | Boolean | Ativar/desativar o cache de requisições com status 302 Valores permitidos: true, false |
|
cache_404 | Boolean | Ativar/desativar o cache de requisições com status 404 Valores permitidos: true, false |
|
gzip_status | Boolean | Ativar/desativar a compressão Gzip Valores permitidos: true, false |
|
ignore_cache_control | Boolean | Ativar/desativar a opção de ignorar o cabeçalho Cache-Control Valores permitidos: true, false |
|
ignore_expires | Boolean | Ativar/desativar a opção de ignorar o cabeçalho Expires Valores permitidos: true, false |
|
ignore_vary | Boolean | Ativar/desativar a opção de ignorar o cabeçalho Vary Valores permitidos: true, false |
|
waf_status | Boolean | Ativar/desativar o WAF Valores permitidos: true, false |
|
waf_mode | String | Modo de operação do WAF Valores permitidos: block, simulate, challenge |
|
waf_level | String | Nível de proteção do WAF Valores permitidos: low, medium, high |
|
ratelimit_status | String | Liga/Desliga o contador de Rate Limit. Valores permitidos: on, off |
|
image_optimize | Boolean | Otimização de imagens ativada ou desativada Valores permitidos: true, false |
|
image_optimize_webp | Boolean | Conversão de imagens para WEBP Valores permitidos: true, false |
|
image_optimize_progressive | Boolean | Conversão de imagens JPEG para o formato progressivo Valores permitidos: true, false |
|
image_optimize_metadata | Boolean | Remoção de metadados Valores permitidos: true, false |
|
image_optimize_level | Number | Nível de otimização de imagem. Utilize 0 para manter o nível original, 90 para nível baixo, 75 para nível médio e 65 para nível alto. Faixa de tamanho: 0-100 |
|
waf_rule_action | String | Customiza o comportamento de uma ou mais regras de WAF, redefinindo a ação individual de cada uma delas ao dar match com uma requisição. Para configurar, você deve enviar pelo menos um par, formado pela ação desejada, seguida de dois pontos e os seletores de regras separados por vírgulas. As ações possíveis são DISABLE, DEFAULT, BLOCK, CHALLENGE, SIMULATE. Um seletor identifica uma regra, seu grupo de regras, ou todo o ruleset. O seletor de uma regra começa com o nome do ruleset, seguido de uma barra, e o id da regra (ex.: gocache-v1/41010). Para selecionar um grupo de regras, no lugar do id da regra, deve se inserir os digitos que identificam o grupo, seguidos de asterisco (ex.: gocache-v1/41*). Já para selecionar todo o ruleset, insira asterisco no lugar do id de regra (ex.: gocache-v1/*). Exemplos: Apenas uma regra: CHALLENGE:gocache-v1/90015 Para um grupo de regras: BLOCK:gocache-v1/90* Para um ruleset: SIMULATE:gocache-v1/* Mais de uma regra: CHALLENGE:gocache-v1/90015,gocache-v1/41*; Mais de um grupo: CHALLENGE:gocache-v1/90015;SIMULATE:gocache-v1/41*;BLOCK:gocache-v1/10*;DISABLE:gocache-v1/*; O exemplo acima altera a regra 90015 para desafiar, altera todas as regras do grupo 41 para simular, altera o grupo 10 para bloquear e todas as outras regras ficam desabilitadas |
HTTP/1.1 200 OK
{
"response": {
"msg": "Success"
}
}
<?php
if( $statusCode == 200 ) {
echo("Sucesso!\n");
$obj = json_decode($response);
echo($obj->response->msg);
}
?>
Smartrules - Geral - Criar
Criar smartrule geral
Disponível no plano
POST /v1/rules/settings/{dominio}
$ curl -i https://api.gocache.com.br/v1/rules/settings/seudominio.com.br \
-X POST \
-H 'GoCache-Token:seu_token' \
-d 'match[host]=www.gocache.com.br' \
-d 'match[scheme]=http*' \
-d 'match[request_uri]=/static/js/*' \
-d 'match[request_method]=GET' \
-d 'match[request_method]=POST' \
-d 'match[remote_address]=255.255.255.0/24' \
-d 'match[cookie]=mycookie1,mycookie2,mycookie3' \
-d 'match[cookie_content]=mycookie1=123*' \
-d 'match[http_referer]=www.google.com.br' \
-d 'match[header]=Accept:*' \
-d 'match[http_user_agent]=*Mozilla*' \
-d 'match[origin_country]=US|UK' \
-d 'match[origin_continent]=SA' \
-d 'match[origin_continent]=EU' \
-d 'match[http_version]=HTTP/1.0' \
-d 'match[http_version]=HTTP/1.1' \
-d 'match[device_type]=mobile' \
-d 'match[device_type]=bot' \
-d 'match[bots]=known' \
-d 'action[set_host]=blog.gocache.com.br' \
-d 'action[backend]=255.255.255.254' \
-d 'action[set_uri]=/js/$1' \
-d 'action[custom_cache_key]=logado,$cookie_user' \
-d 'action[expires_ttl]=14400' \
-d 'action[caching_behavior]=ignore_query_string' \
-d 'action[cache_mode]=default' \
-d 'action[cache_ttl]=86400' \
-d 'action[cors]=http://www.gocache.com.br' \
-d 'action[ssl_mode]=partial' \
-d 'action[connection]=keep-alive' \
-d 'action[hide]=X-Powered-By' \
-d 'action[encoding]=$accept_encoding' \
-d 'action[set]=X-Powered-By-GoCache: true' \
-d 'action[set_req_header][0]=GoCache-Header: true' \
-d 'action[signed_url_key]=1234' \
-d 'action[signed_url_type]=off' \
-d 'action[cache_301]=false' \
-d 'action[cache_302]=false' \
-d 'action[cache_404]=false' \
-d 'action[gzip_status]=false' \
-d 'action[ignore_cache_control]=false' \
-d 'action[ignore_expires]=false' \
-d 'action[ignore_vary]=false' \
-d 'action[waf_status]=true' \
-d 'action[waf_mode]=challenge' \
-d 'action[waf_level]=high' \
-d 'action[waf_rule_action]=CHALLENGE:gocache-v1/90015;SIMULATE:gocache-v1/21003;BLOCK:gocache-v1/41*;'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/settings/seudominio.com.br");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$urls = array(
"match[host]=www.gocache.com.br",
"match[scheme]=http*",
"match[request_uri]=/static/js/*",
"match[request_method]=GET",
"match[request_method]=POST",
"match[remote_address]=255.255.255.0/24",
"match[cookie]=mycookie1,mycookie2,mycookie3",
"match[cookie_content]=mycookie1=123*",
"match[http_referer]=www.google.com.br",
"match[header]=Accept:*",
"match[http_user_agent]=*Mozilla*",
"match[origin_country]=US|UK",
"match[origin_continent]=SA",
"match[origin_continent]=EU",
"match[http_version]=HTTP/1.0",
"match[http_version]=HTTP/1.1",
"match[device_type]=mobile",
"match[device_type]=bot",
"match[bots]=known",
"action[set_host]=blog.gocache.com.br",
"action[backend]=255.255.255.254",
"action[set_uri]=/js/$1",
"action[custom_cache_key]=logado,\$cookie_user",
"action[expires_ttl]=14400",
"action[caching_behavior]=ignore_query_string",
"action[cache_mode]=default",
"action[cache_ttl]=86400",
"action[cors]=http://www.gocache.com.br",
"action[ssl_mode]=partial",
"action[connection]=keep-alive",
"action[hide]=X-Powered-By",
"action[encoding]=\$accept_encoding",
"action[set]=X-Powered-By-GoCache: true",
"action[set_req_header][0]=GoCache-Header: true",
"action[signed_url_key]=1234",
"action[signed_url_type]=off",
"action[cache_301]=false",
"action[cache_302]=false",
"action[cache_404]=false",
"action[gzip_status]=false",
"action[ignore_cache_control]=false",
"action[ignore_expires]=false",
"action[ignore_vary]=false",
"action[waf_status]=true",
"action[waf_mode]=challenge",
"action[waf_level]=high",
"action[waf_rule_action]=gocache-v1/90015,CHALLENGE;gocache-v1/21003,DENY;gocache-v1/41*,SIMULATE;"
);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode("&", $urls));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
Parâmetros
Campo | Opcional | Tipo | Descrição |
---|---|---|---|
metadata | Object | ||
status | Boolean | Indica se a regra está ativa ou inativa Valor padrão: true Valores permitidos: true, false |
|
notes | String | Descrição da regra | |
match | Object | Critério da regra | |
host | String | Domínio/subdomínio de acesso do site. Ex: www.gocache.com.br. | |
scheme | String | Protocolo de acesso. Valores permitidos: http, https, http* |
|
request_uri | String | URI. Ex: /admin/*. | |
http_version | String | Versão do HTTP utilizada Valores permitidos: "HTTP/1.0", "HTTP/1.1", "HTTP/2.0" |
|
device_type | String | Tipo do dispositivo que está realizando a requisição Valores permitidos: "desktop", "mobile", "bot", "na" |
|
http_user_agent | String | User agent. Suporta wildcard (*). Ex: *Mozilla*. | |
cookie | String | Se possui um cookie, de uma lista de um ou mais cookies, presente. Pode ser mais de um, separado por vírgula. Suporta wildcard (*). Ex: wp_login,wp_test. | |
cookie_content | String | Se um cookie possui um valor específico. O nome e o valor são separados igual (=). Suporta wildcard (*) no valor do cookie. Ex: wp_test=yes. | |
request_method | String | Método da requisição Valores permitidos: GET, POST, PUT, DELETE |
|
http_referer | String | Referer da requisição | |
remote_address | String | IP ou range de IP da origem da requisição. Para ranges apenas as máscaras /32, /24 e /16 estão disponíveis | |
header | String | Se a requisiço possui um cabeçalho específico. O nome e o valor são separados por dois-pontos (:). Suporta wildcard (*) no valor do cabeçalho. Ex Accept:*. | |
origin_country | String | País de origem Valores permitidos: "BR", "US", "CN", "RU", "..." |
|
origin_continent | String | Continente de origem Valores permitidos: "SA", "NA", "OC", "EU", "AF", "AS" |
|
bots | String | Bots conhecidos Valores permitidos: "known", "others" |
|
action | Object | Ação | |
set_host | String | Sobrescreve o cabeçalho Host da requisição. Ex: mybucket.s3.amazonaws.com. | |
backend | String | Define o IP ou hostname de destino. Ex: s3.amazonaws.com. | |
set_uri | String | Sobrescreve URI. É possível utilizar o valor do wildcard (*) do parâmetro match.request_uri através da variável $1. Ex: /imagens/$1 | |
custom_cache_key | String | Customiza chave de cache. Permite o uso das variáveis: $cookie_NOME, $http_NOME para utilizar o valor de um cookie/header específico, e $geoip2_data_country_code, $geoip2_data_continent_code para utilizar país/continente. Ex: logado,$cookie_user. Também há a possibilidade de usar parâmetros de url com $1, $2, $3... quando o critério for URL e houver wildcard | |
expires_ttl | Number | Tempo de cache do navegador, em segundos. O valor -1 desabilita o cache de navegador. Valores permitidos: -1, 3600, 7200, 14400, 43200, 86400, 172800, 345600, 604800, 1296000, 2592000, 15552000, 31536000 |
|
caching_behavior | String | Comportamento do cache Valores permitidos: default, ignore_query_string |
|
cache_mode | String | Tipo de cache (desligado, somente conteúdo estático ou full cache, respectivamente) Valores permitidos: off, default, full |
|
cache_ttl | Number | Tempo de expiração de cache, em segundos. Valores permitidos: 300, 600, 900, 1800, 3600, 7200, 14400, 86400, 172800, 604800, 1296000 |
|
cors | String | Define Cross-Origin. Ex: http://www.gocache.com.br | |
ssl_mode | String | Modo SSL. O valor partial é equivalente ao modo Edge Valores permitidos: partial, full |
|
connection | String | Define o cabeçalho Connection da requisição Valores permitidos: close, keep-alive |
|
hide | String | Remove cabeçalho de resposta. O valor deve ser o nome do cabeçalho | |
encoding | String | Define o cabeçalho Accept-Encoding. Ex: $accept_encoding. | |
set | String | Define um cabeçalho de resposta: Ex: Strict-Transport-Security: max-age=86400. | |
set_req_header | Array | Define um cabeçalho de requisição: Ex: X-GoCache-Custom-Header:true. É possível especificar no máximo 3 cabeçalhos de requisição. |
|
signed_url_key | String | Define a chave da URL assinada | |
signed_url_type | String | Define o tipo de URL assinada Valores permitidos: s3qs, off |
|
cache_301 | Boolean | Ativar/desativar o cache de requisições com status 301 Valores permitidos: true, false |
|
cache_302 | Boolean | Ativar/desativar o cache de requisições com status 302 Valores permitidos: true, false |
|
cache_404 | Boolean | Ativar/desativar o cache de requisições com status 404 Valores permitidos: true, false |
|
gzip_status | Boolean | Ativar/desativar a compressão Gzip Valores permitidos: true, false |
|
ignore_cache_control | Boolean | Ativar/desativar a opção de ignorar o cabeçalho Cache-Control Valores permitidos: true, false |
|
ignore_expires | Boolean | Ativar/desativar a opção de ignorar o cabeçalho Expires Valores permitidos: true, false |
|
ignore_vary | Boolean | Ativar/desativar a opção de ignorar o cabeçalho Vary Valores permitidos: true, false |
|
waf_status | Boolean | Ativar/desativar o WAF Valores permitidos: true, false |
|
waf_mode | String | Modo de operação do WAF Valores permitidos: block, simulate, challenge |
|
waf_level | String | Nível de proteção do WAF Valores permitidos: low, medium, high |
|
ratelimit_status | String | Liga/Desliga o contador de Rate Limit. Valores permitidos: on, off |
|
image_optimize | Boolean | Otimização de imagens ativada ou desativada Valores permitidos: true, false |
|
image_optimize_webp | Boolean | Conversão de imagens para WEBP Valores permitidos: true, false |
|
image_optimize_progressive | Boolean | Conversão de imagens JPEG para o formato progressivo Valores permitidos: true, false |
|
image_optimize_metadata | Boolean | Remoção de metadados Valores permitidos: true, false |
|
image_optimize_level | Number | Nível de otimização de imagem. Utilize 0 para manter o nível original, 90 para nível baixo, 75 para nível médio e 65 para nível alto. Faixa de tamanho: 0-100 |
|
waf_rule_action | String | Customiza o comportamento de uma ou mais regras de WAF, redefinindo a ação individual de cada uma delas ao dar match com uma requisição. Para configurar, você deve enviar pelo menos um par, formado pela ação desejada, seguida de dois pontos e os seletores de regras separados por vírgulas. As ações possíveis são DISABLE, DEFAULT, BLOCK, CHALLENGE, SIMULATE. Um seletor identifica uma regra, seu grupo de regras, ou todo o ruleset. O seletor de uma regra começa com o nome do ruleset, seguido de uma barra, e o id da regra (ex.: gocache-v1/41010). Para selecionar um grupo de regras, no lugar do id da regra, deve se inserir os digitos que identificam o grupo, seguidos de asterisco (ex.: gocache-v1/41*). Já para selecionar todo o ruleset, insira asterisco no lugar do id de regra (ex.: gocache-v1/*). Exemplos: Apenas uma regra: CHALLENGE:gocache-v1/90015 Para um grupo de regras: BLOCK:gocache-v1/90* Para um ruleset: SIMULATE:gocache-v1/* Mais de uma regra: CHALLENGE:gocache-v1/90015,gocache-v1/41*; Mais de um grupo: CHALLENGE:gocache-v1/90015;SIMULATE:gocache-v1/41*;BLOCK:gocache-v1/10*;DISABLE:gocache-v1/*; O exemplo acima altera a regra 90015 para desafiar, altera todas as regras do grupo 41 para simular, altera o grupo 10 para bloquear e todas as outras regras ficam desabilitadas |
HTTP/1.1 200 OK
{
"response": {
"id": "aXBfYWRkcmVzcy1kZWZhdWx0fGlwX2FkZHJlc3N8MS4xLjEuMQ=="
}
}
<?php
if( $statusCode == 200 ) {
echo("Sucesso!\n");
$obj = json_decode($response);
echo("ID da regra criada: " . $obj->response->id);
}
?>
Smartrules - Geral - Listar
Listar as smartrules gerais de um domínio.
GET /v1/rules/settings/{dominio}
$ curl -i https://api.gocache.com.br/v1/rules/settings/seudominio.com.br \
-X GET \
-H 'GoCache-Token:seu_token'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/settings/seudominio.com.br");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
HTTP/1.1 200 OK
{
"response": {
"rule": [
{
"match": {
"host": "www.gocache.com.br",
"request_method": [
"GET",
"POST"
]
},
"action": {
"waf_level": "high",
"waf_mode": "block"
},
"id": "aabbccddeeff",
"metadata": {
"status": "true"
}
},
{
"match": {
"origin_country": "BR"
},
"action": {
"cache_404": "false"
},
"id": "gghhiijjkkll",
"metadata": {
"status": "false"
}
}
]
}
}
<?php
if ($statusCode == 200) {
echo ("Sucesso!\n");
$obj = json_decode($response);
foreach ($obj->response->rule as $rule) {
echo ("\n<br /><br />\n");
echo ("Smartrule:" . "<br />\n");
echo ("ID: " . $rule->id . "<br />\n");
foreach ($rule->match as $match_type => $match_value) {
echo ("Match " . $match_type . ": " . $match_value . "<br />\n");
}
foreach ($rule->action as $action_type => $action_value) {
echo ("Action: " . $action_type . ": " . $action_value . "<br />\n");
}
if ($rule->metadata->status == "true") {
echo ("Smartrule enabled<br />\n");
} else {
echo ("Smartrule disabled<br />\n");
}
}
}
?>
Smartrules - Geral - Remover
Remover uma smartrule geral.
DELETE /v1/rules/settings/{dominio}/{id}
$ curl -i https://api.gocache.com.br/v1/rules/settings/seudominio.com.br/aabbccddeeffgghh \
-X DELETE \
-H 'GoCache-Token:seu_token'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/settings/seudominio.com.br/aabbccddeeffgghh");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
HTTP/1.1 200 OK
{
"response": {
"msg": "Success"
}
}
<?php
if( $statusCode == 200 ) {
echo("Sucesso!\n");
$obj = json_decode($response);
echo($obj->response->msg);
}
?>
Smartrules - Redirecionamento - Alterar
Alterar uma smartrule de redirecionamento.
PUT /v1/rules/rewrite/{dominio}/{id}
$ curl -i https://api.gocache.com.br/v1/rules/rewrite/seudominio.com.br/aabbccddeeffgghh \
-X PUT \
-H 'GoCache-Token:seu_token' \
-d 'match[request]=http://www.gocache.com.br/blog/*' \
-d 'match[request_method]=GET' \
-d 'match[request_method]=POST' \
-d 'match[remote_address]=255.255.255.0/24' \
-d 'match[cookie]=mycookie1,mycookie2,mycookie3' \
-d 'match[cookie_content]=mycookie1=123*' \
-d 'match[header]=Accept:*' \
-d 'match[http_referer]=www.google.com.br' \
-d 'match[http_user_agent]=*Mozilla*' \
-d 'match[origin_country]=US|UK' \
-d 'match[origin_continent]=SA' \
-d 'match[origin_continent]=EU' \
-d 'match[http_version]=HTTP/1.0' \
-d 'match[http_version]=HTTP/1.1' \
-d 'match[device_type]=mobile' \
-d 'match[device_type]=bot' \
-d 'match[bots]=known' \
-d 'action[redirect_type]=301' \
-d 'action[redirect_to]=https://blog.gocache.com.br/$1'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/rewrite/seudominio.com.br/aabbccddeeffgghh");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$urls = array(
"match[request]=http://www.gocache.com.br/blog/*",
"match[request_method]=GET",
"match[request_method]=POST",
"match[remote_address]=255.255.255.0/24",
"match[cookie]=mycookie1,mycookie2,mycookie3",
"match[cookie_content]=mycookie1=123*",
"match[header]=Accept:*",
"match[http_referer]=www.google.com.br",
"match[http_user_agent]=*Mozilla*",
"match[origin_country]=US|UK",
"match[origin_continent]=SA",
"match[origin_continent]=EU",
"match[http_version]=HTTP/1.0",
"match[http_version]=HTTP/1.1",
"match[device_type]=mobile",
"match[device_type]=bot",
"match[bots]=known",
"action[redirect_type]=301",
"action[redirect_to]=https://blog.gocache.com.br/\$1",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode("&", $urls));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
Parâmetros
Campo | Opcional | Tipo | Descrição |
---|---|---|---|
metadata | Object | ||
status | Boolean | Indica se a regra está ativa ou inativa Valor padrão: true Valores permitidos: true, false |
|
notes | String | Descrição da regra | |
match | Object | Critério da regra | |
request | String | A URL completa da requisição, composta do protocolo HTTP, de um host e da URI. Ex: http://www.gocache.com.br/blog/*. | |
http_version | String | Versão do HTTP utilizada Valores permitidos: "HTTP/1.0", "HTTP/1.1", "HTTP/2.0" |
|
device_type | String | Tipo do dispositivo que está realizando a requisição Valores permitidos: "desktop", "mobile", "bot", "na" |
|
http_user_agent | String | User agent. Suporta wildcard (*). Ex: *Mozilla*. | |
cookie | String | Se possui um cookie, de uma lista de um ou mais cookies, presente. Pode ser mais de um, separado por vírgula. Suporta wildcard (*). Ex: wp_login,wp_test. | |
cookie_content | String | Se um cookie possui um valor específico. O nome e o valor são separados igual (=). Suporta wildcard (*) no valor do cookie. Ex: wp_test=yes. | |
request_method | String | Método da requisição Valores permitidos: GET, POST, PUT, DELETE |
|
http_referer | String | Referer da requisição | |
remote_address | String | IP ou range de IP da origem da requisição. Para ranges apenas as máscaras /32, /24 e /16 estão disponíveis | |
header | String | Se a requisiço possui um cabeçalho específico. O nome e o valor são separados por dois-pontos (:). Suporta wildcard (*) no valor do cabeçalho. Ex Accept:*. | |
origin_country | String | País de origem Valores permitidos: "BR", "US", "CN", "RU", "..." |
|
origin_continent | String | Continente de origem Valores permitidos: "SA", "NA", "OC", "EU", "AF", "AS" |
|
bots | String | Bots conhecidos Valores permitidos: "known", "others" |
|
action | Object | Ação | |
redirect_type | Number | Tipo de redirecionamento Valores permitidos: 301, 302 |
|
redirect_to | String | URL de redirecionamento. É possível utilizar o valor do wildcard (*) do parâmetro match.request através das variáveis $1, $2, .... Ex: https://blog.gocache.com.br/$1. |
HTTP/1.1 200 OK
{
"response": {
"msg": "Success"
}
}
<?php
if( $statusCode == 200 ) {
echo("Sucesso!\n");
$obj = json_decode($response);
echo($obj->response->msg);
}
?>
Smartrules - Redirecionamento - Criar
Criar smartrule de redirecionamento
POST /v1/rules/rewrite/{dominio}
$ curl -i https://api.gocache.com.br/v1/rules/rewrite/seudominio.com.br \
-X POST \
-H 'GoCache-Token:seu_token' \
-d 'match[request]=http://www.gocache.com.br/blog/*' \
-d 'match[request_method]=GET' \
-d 'match[request_method]=POST' \
-d 'match[remote_address]=255.255.255.0/24' \
-d 'match[cookie]=mycookie1,mycookie2,mycookie3' \
-d 'match[cookie_content]=mycookie1=123*' \
-d 'match[header]=Accept:*' \
-d 'match[http_referer]=www.google.com.br' \
-d 'match[http_user_agent]=*Mozilla*' \
-d 'match[origin_country]=US|UK' \
-d 'match[origin_continent]=SA' \
-d 'match[origin_continent]=EU' \
-d 'match[http_version]=HTTP/1.0' \
-d 'match[http_version]=HTTP/1.1' \
-d 'match[device_type]=mobile' \
-d 'match[device_type]=bot' \
-d 'match[bots]=known' \
-d 'action[redirect_type]=301' \
-d 'action[redirect_to]=https://blog.gocache.com.br/$1'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/rewrite/seudominio.com.br");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$urls = array(
"match[request]=http://www.gocache.com.br/blog/*",
"match[request_method]=GET",
"match[request_method]=POST",
"match[remote_address]=255.255.255.0/24",
"match[cookie]=mycookie1,mycookie2,mycookie3",
"match[cookie_content]=mycookie1=123*",
"match[header]=Accept:*",
"match[http_referer]=www.google.com.br",
"match[http_user_agent]=*Mozilla*",
"match[origin_country]=US|UK",
"match[origin_continent]=SA",
"match[origin_continent]=EU",
"match[http_version]=HTTP/1.0",
"match[http_version]=HTTP/1.1",
"match[device_type]=mobile",
"match[device_type]=bot",
"match[bots]=known",
"action[redirect_type]=301",
"action[redirect_to]=https://blog.gocache.com.br/\$1",
);
curl_setopt($ch, CURLOPT_POSTFIELDS, implode("&", $urls));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
Parâmetros
Campo | Opcional | Tipo | Descrição |
---|---|---|---|
metadata | Object | ||
status | Boolean | Indica se a regra está ativa ou inativa Valor padrão: true Valores permitidos:true,false |
|
notes | String | Descrição da regra | |
match | Object | Critério da regra | |
request | String | A URL completa da requisição, composta do protocolo HTTP, de um host e da URI. Ex: http://www.gocache.com.br/blog/*. | |
http_version | String | Versão do HTTP utilizada Valores permitidos: "HTTP/1.0", "HTTP/1.1", "HTTP/2.0" |
|
device_type | String | Tipo do dispositivo que está realizando a requisição Valores permitidos: "desktop", "mobile", "bot", "na" |
|
http_user_agent | String | User agent. Suporta wildcard (*). Ex: *Mozilla*. | |
cookie | String | Se possui um cookie, de uma lista de um ou mais cookies, presente. Pode ser mais de um, separado por vírgula. Suporta wildcard (*). Ex: wp_login,wp_test. | |
cookie_content | String | Se um cookie possui um valor específico. O nome e o valor são separados igual (=). Suporta wildcard (*) no valor do cookie. Ex: wp_test=yes. | |
request_method | String | Método da requisição Valores permitidos: GET , POST , PUT, DELETE |
|
http_referer | String | Referer da requisição | |
remote_address | String | IP ou range de IP da origem da requisição. Para ranges apenas as máscaras /32, /24 e /16 estão disponíveis | |
header | String | Se a requisiço possui um cabeçalho específico. O nome e o valor são separados por dois-pontos (:). Suporta wildcard (*) no valor do cabeçalho. Ex Accept:*. | |
origin_country | String | País de origem Valores permitidos:"BR","US","CN","RU","..." |
|
origin_continent | String | Continente de origem Valores permitidos:"SA","NA","OC","EU","AF","AS" |
|
bots | String | Bots conhecidos Valores permitidos:"known","others" |
|
action | Object | Ação | |
redirect_type | Number | Tipo de redirecionamento Valores permitidos:301,302 |
|
redirect_to | String | URL de redirecionamento. É possível utilizar o valor do wildcard (*) do parâmetro match.request através das variáveis $1, $2, .... Ex: https://blog.gocache.com.br/$1. |
HTTP/1.1 200 OK
{
"response": {
"id": "aXBfYWRkcmVzcy1kZWZhdWx0fGlwX2FkZHJlc3N8MS4xLjEuMQ=="
}
}
<?php
if( $statusCode == 200 ) {
echo("Sucesso!\n");
$obj = json_decode($response);
echo("ID da regra criada: " . $obj->response->id);
}
?>
Smartrules - Redirecionamento - Listar
Listar as smartrules de redirecionamento de um domínio.
GET /v1/rules/rewrite/{dominio}
$ curl -i https://api.gocache.com.br/v1/rules/rewrite/seudominio.com.br \
-X GET \
-H 'GoCache-Token:seu_token'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/rewrite/seudominio.com.br");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
HTTP/1.1 200 OK
{
"response": {
"rule": [
{
"match": {
"request": "http://www.gocache.com.br/",
"request_method": [
"GET",
"POST"
]
},
"action": {
"redirect_type": "301",
"redirect_to": "http://blog.gocache.com.br/"
},
"id": "aabbccddeeff",
"metadata": {
"status": "true"
}
},
{
"match": {
"origin_country": "BR|AR"
},
"action": {
"redirect_type": "302",
"redirect_to": "http://ww2.gocache.com.br"
},
"id": "gghhiijjkkll",
"metadata": {
"status": "false",
"updated_on": "1122334455"
}
}
]
}
}
<?php
if ($statusCode == 200) {
echo ("Sucesso!\n");
$obj = json_decode($response);
foreach ($obj->response->rule as $rule) {
echo ("\n<br /><br />\n");
echo ("Smartrule:" . "<br />\n");
echo ("ID: " . $rule->id . "<br />\n");
foreach ($rule->match as $match_type => $match_value) {
echo ("Match " . $match_type . ": " . $match_value . "<br />\n");
}
foreach ($rule->action as $action_type => $action_value) {
echo ("Action: " . $action_type . ": " . $action_value . "<br />\n");
}
if ($rule->metadata->status == "true") {
echo ("Smartrule enabled<br />\n");
} else {
echo ("Smartrule disabled<br />\n");
}
}
}
?>
Smartrules - Redirecionamento - Remover
Remover uma smartrule de redirecionamento.
DELETE /v1/rules/rewrite/{dominio}/{id}
$ curl -i https://api.gocache.com.br/v1/rules/rewrite/seudominio.com.br/aabbccddeeffgghh \
-X DELETE \
-H 'GoCache-Token:seu_token'
<?php
$ch = curl_init("https://api.gocache.com.br/v1/rules/rewrite/seudominio.com.br/aabbccddeeffgghh");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("GoCache-Token: seu_token"));
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
?>
HTTP/1.1 200 OK
{
"response": {
"msg": "Success"
}
}
<?php
if( $statusCode == 200 ) {
echo("Sucesso!\n");
$obj = json_decode($response);
echo($obj->response->msg);
}
?>