Skip to content

Instantly share code, notes, and snippets.

@marcofbb
marcofbb / cloudflare-masive.php
Created Jun 5, 2022
Cloudflare delete all DNS records and set news (MASSIVE PHP)
View cloudflare-masive.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 Jan 19, 2021
WordPress extend results append POST in Tag list
View functions.php
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);
View Sincronizar posts Wordpress diferentes servidores
# 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 May 5, 2020
TOP and Logs command varnish 4
View command-varnish.sh
# Muestro las URL que se envian al backend
varnishtop -i BereqURL
# Muestro todas URL peticionadas
varnishtop -i requrl
# Mostrar peticiones metodo
varnishtop -i reqMethod
# Mostrar HTTP status
@marcofbb
marcofbb / signed_url_google_storage.php
Last active May 6, 2020
Signed manually url google storage PHP
View signed_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 Apr 3, 2020
varnish limit rate request for seconds with cloudflare
View limit_rate.vcl
## ## 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 Apr 3, 2020
Varnish cache different for each country with Cloudflare header
View default.vcl
## ## 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 Dec 28, 2021
Varnish cache different for Mobile / PC/ Tablet
View default.vcl
## ## 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 Apr 3, 2020
Varnish remove GET parameters Cloudflare under attack challange
View cloudflare_remove_gets.vcl
# 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, "\?$", "");
}