Skip to content

Instantly share code, notes, and snippets.

Avatar

Cristhian Martínez Ochoa QROkes

View GitHub Profile
@QROkes
QROkes / qa-plugin.php
Last active Jan 11, 2020
Akismet SPAM Check for Question2Answer
View qa-plugin.php
<?php
/*
File: qa-plugin/webinoly-custom/qa-plugin.php
Description: Anti SPAM Registration Plugin for Question2Answer
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@QROkes
QROkes / bash
Created Apr 7, 2019
Check if domain name is subdomain
View bash
# Check if domain is subdomain
if [[ -n $domain ]]; then
count=1
while true; do
tld=$(echo "${domain}" | rev | cut -d'.' -f -$count -s | rev)
if ! grep -Fxq "$tld" /opt/webinoly/lib/public_suffix_list.dat; then
break
fi
count=$[$count+1]
done
@QROkes
QROkes / bash
Created Apr 7, 2019
Check for valid domain name
View bash
# Only numerals 0-9, basic Latin letters, both lowercase and uppercase, hyphen.
[[ $domain =~ ^[\.0-9A-Za-z\-]+$ ]] || domfail="true"
# Check Lenght
[[ ${#domain} -gt 67 ]] && domfail="true"
# Can not start or end with a hyphen
[[ $(echo "${domain}" | cut -c-1) == "-" || $(echo "${domain}" | rev | cut -c-1) == "-" ]] && domfail="true"
# Can not contain two points together and can not start or end with a point
@QROkes
QROkes / bash
Created Apr 7, 2019
Check for valid IP address
View bash
# Check for valid IPv4 and IPv6 values, including CIDR.
if [[ -n $ip && $ip =~ ^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\/([0-9]|[1-2][0-9]|3[0-2]))?$ || $ip =~ ^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))(\/([0-9]|[1-9][0-9]|1[0-2][0-8]))?$ ]]; then
echo "Valid IP!"
else
echo "[ERROR]
@QROkes
QROkes / qa-plugin.php
Last active Feb 23, 2021
Anti SPAM Registration Plugin for Question2Answer - StopForumSpam API
View qa-plugin.php
<?php
/*
File: qa-plugin/webinoly-custom/qa-plugin.php
Description: Anti SPAM Registration Plugin for Question2Answer
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
@QROkes
QROkes / qa-plugin.php
Created Jul 25, 2018
Add the META robots noindex for better SEO and avoid duplicate content in Question2Answer forum.
View qa-plugin.php
<?php
/*
Plugin Name: SEO Custom Meta-Robots
Plugin URI: https://qrokes.com/
Plugin Description: SEO Custom Meta Robots
Plugin Version: 1.0
Plugin Date:
Plugin Author: QROkes
Plugin Author URI: https://qrokes.com/
Plugin License: GPLv3
@QROkes
QROkes / functions.php
Created May 10, 2017
How to use Amazon SES in WordPress.
View functions.php
// Amazon SES (AWS) instead php mail.
add_action( 'phpmailer_init', 'qr_aws_ses_smtp' );
function qr_aws_ses_smtp( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'email-smtp.us-east-1.amazonaws.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 25;
$phpmailer->Username = 'AWS SES Credentials - username';
$phpmailer->Password = 'AWS SES Credentials - password';
$phpmailer->SMTPSecure = 'tls';
@QROkes
QROkes / nginx.conf
Last active Sep 3, 2017
Nginx (Reverse Proxy) Configuration file for Traccar GPS
View nginx.conf
server {
listen 80;
listen [::]:80;
server_name domain.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@QROkes
QROkes / traccar.xml
Last active Sep 29, 2018
Traccar GPS Configuration file
View traccar.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE properties SYSTEM 'http://java.sun.com/dtd/properties.dtd'>
<properties>
<entry key="config.default">./conf/default.xml</entry>
<!-- DataBase MariaDB -->
<entry key='database.driver'>com.mysql.jdbc.Driver</entry>
<entry key='database.url'>jdbc:mysql://[HOST]:3306/[DATABASE]?useSSL=false&amp;allowMultiQueries=true&amp;autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding=UTF-8&amp;sessionVariables=sql_mode=''</entry>
<entry key='database.user'>[USER]</entry>
@QROkes
QROkes / functions.php
Created Mar 25, 2016
Sends an email notification when a comment receives a reply - WordPress
View functions.php
<?php
/* Based on: https://wordpress.org/plugins/comment-reply-email-notification/ */
add_action('wp_insert_comment', 'qr_comment_notification', 99, 2);
add_action('wp_set_comment_status','qr_comment_status_update', 99, 2);
add_filter('wp_mail_content_type', function($contentType) { return 'text/html'; });
/**
* Sends an email notification when a comment receives a reply
* @param int $commentId The comment ID