Skip to content

Instantly share code, notes, and snippets.

@marcofbb
marcofbb / cloudflare-masive.php
Created June 5, 2022 02:05
Cloudflare delete all DNS records and set news (MASSIVE PHP)
<?php
/*
RUN:
composer install cloudflare/sdk
*/
require_once('vendor/autoload.php');
$domains = array('domain1.com','domain2.com');
$key = new \Cloudflare\API\Auth\APIKey('useremail@email.com', 'ApiKey');
@marcofbb
marcofbb / functions.php
Created January 19, 2021 17:40
WordPress extend results append POST in Tag list
function extend_search_tag($query){
global $wpdb;
if(is_tag()){
// GET LIMIT RANGE OF ORIGINAL SQL QUERY
preg_match('@(LIMIT [0-9]+, [0-9]+)@', $query, $limitData);
$limit = $limitData[1];
$query = str_replace($limit, '', $query);
$query = str_replace('SQL_CALC_FOUND_ROWS', '', $query);
# Se utilizo https://www.percona.com/doc/percona-toolkit/LATEST/pt-table-sync.html para sincronizar la tablas
# En el hosting destino ejecutar las lineas
# Sincronizar tabla wp_posts
pt-table-sync --execute h=host_source,D=database_source,u=username_source,p="pass_source",t=wp_posts h=127.0.0.1,D=database_end,u=user_end,p=password_end --function MD5
# Replicar lo mismo para wp_posts, wp_postmeta, wp_termmeta, wp_terms, wp_term_relationships, wp_term_taxonomy
@marcofbb
marcofbb / command-varnish.sh
Last active February 14, 2024 22:19
TOP and Logs command varnish 4
# Muestro las URL que se envian al backend
varnishtop -i BereqURL
# Muestro los host de peticiones al back
varnishtop -b -I BeReqHeader:Host
# Muestro todas URL peticionadas
varnishtop -i requrl
# Mostrar peticiones metodo
@marcofbb
marcofbb / signed_url_google_storage.php
Last active May 6, 2020 21:43
Signed manually url google storage PHP
<?php
/*
DOCS:
https://cloud.google.com/storage/docs/access-control/signed-urls
https://cloud.google.com/storage/docs/access-control/signing-urls-manually
Translate to PHP of code Python: https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/storage/signed_urls/generate_signed_urls.py
*/
function generate_signed_url_google($service_account_file, $bucket_name, $object_name, $subresource = null, $expiration=604800, $http_method='GET', $query_parameters = array(), $headers = array()){
date_default_timezone_set('UTC');
@marcofbb
marcofbb / limit_rate.vcl
Created April 3, 2020 04:57
varnish limit rate request for seconds with cloudflare
## ## Not complete default.vcl code
# Install https://github.com/varnish/varnish-modules
import vsthrottle;
# If I want to implement limitation to any request (do not declare req.http.X-Actual-IP again in other subsequent subroutines)
sub vcl_recv {
# GET REAL IP USER from proxy CLOUDFLARE
set req.http.X-Actual-IP = regsub(req.http.X-Forwarded-For, "[, ].*$", "");
if(vsthrottle.is_denied(req.http.X-Actual-IP, 50, 5s, 60s)) {
@marcofbb
marcofbb / default.vcl
Created April 3, 2020 01:53
Varnish cache different for each country with Cloudflare header
## ## Not complete default.vcl code
sub vcl_recv {
set req.http.IPCountry = "no-specified";
# usage ISO 3166-1 alpha-2 ( https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 )
## If I want to group BR and US in same group cache
if (req.http.CF-IPCountry == "BR" || req.http.CF-IPCountry == "US") {
set req.http.IPCountry = "group-br-and-us";
} else {
set req.http.IPCountry = req.http.CF-IPCountry;
}
@marcofbb
marcofbb / default.vcl
Last active December 28, 2021 12:24
Varnish cache different for Mobile / PC/ Tablet
## ## Not complete default.vcl code
# Routine to try and identify device
sub identify_device {
# Default to thinking it's desktop
set req.http.X-UA-Device = "desktop";
if (req.http.User-Agent ~ "iPad" ) {
# It says its a iPad - so let's give them the tablet-site
set req.http.X-UA-Device = "tablet";
@marcofbb
marcofbb / cloudflare_remove_gets.vcl
Created April 3, 2020 01:41
Varnish remove GET parameters Cloudflare under attack challange
# in vcl_recv
if (req.url ~ "(\?|&)(__cf_chl_jschl_tk__)=") {
set req.url = regsuball(req.url, "&(__cf_chl_jschl_tk__)=([A-z0-9_\-\.%25]+)", "");
set req.url = regsuball(req.url, "\?(__cf_chl_jschl_tk__)=([A-z0-9_\-\.%25]+)", "?");
set req.url = regsub(req.url, "\?&", "?");
set req.url = regsub(req.url, "\?$", "");
}