Simple SSH login email notify

Wanted to track remote SSH port forward login and the following is a great solution

$ cat /etc/profile.d/ssh-login-notify.sh
if [ -n "$SSH_CLIENT" ]; then
TEXT="$(date): ssh login to ${USER}@$(hostnamectl –static)"
TEXT="$TEXT from $(echo $SSH_CLIENT|awk '{print $1}')"
echo $TEXT|mail -s "ssh login" info@example.com
fi

view raw
ssh-login-notify.sh
hosted with ❤ by GitHub

Source https://askubuntu.com/a/702743/168459

Change locale for WooCommerce email

To change WooCommerce email language you need to change the locale after order submit.

Using $_GET might be dirty, but works 🙂

<?php
/**
* Plugin Name: Slovak WooCommerce emails
* Plugin URI: https://www.nevilleweb.sk/
* Description: Send only slovak WooCommerce emails
* Version: 1.0.0
* Author: Michal Zuber
* Author URI: https://nevilleweb.sk/
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
add_filter('plugin_locale', 'custom_locale', 10, 2);
function custom_locale($locale, $domain)
{
if ('woocommerce' == $domain && isset($_GET['wc-ajax']) && $_GET['wc-ajax'] == 'checkout') {
return 'sk_SK';
}
return $locale;
}

WooCommerce email with custom total row

To add a custom total row to woocommerce email total section just hook into woocommerce_get_order_item_totals

Customise order total rows

add_filter('woocommerce_get_order_item_totals', 'my_woocommerce_get_order_item_totals', 10, 2);
function my_woocommerce_get_order_item_totals($total_rows, $order)
{
    $new_total_rows['cart_subtotal'] = $total_rows['cart_subtotal'];

    $new_total_rows['shipping'] = array(
        'label' => 'Slovak Parcel Service:',
        'value' => wc_price(3),
    );

    $gateway = wc_get_payment_gateway_by_order($order);
    if ('cod' == $gateway->id) {
        $new_total_rows['cod'] = array(
            'label' => 'Cash on delivery:',
            'value' => wc_price(1),
        );
    }

    $new_total_rows['order_total'] = $total_rows['order_total'];

    return $new_total_rows;
}

Customizing Monolog HTML formatter for email

Monolog can send emails when there’s an error, but in the provided HTML formatter I missed the REQUEST_URI and REMOTE_ADDR that triggered the error.

Some info is in the exceptions section, but not always and needs horizontal scrolling in the email client 🙂

So I just replicated the HtmlFormatter and added some lines (dirty hacks).

Added service class

 <service id="app.monolog.formatter.html" class="App\Service\MonologEmailFormatter" public="false" />

Change formatter service ID

# app/config/config_prod.yml
swift:
    type: swift_mailer
    from_email: "php@example.com"
    to_email: ["info@example.com"]
    subject: 'Error'
    level: error
    formatter: custom.monolog.formatter.html
    content_type: text/html

UPDATE: You might be interested in https://stefanoalletti.wordpress.com/2017/03/09/symfony-and-monolog-how-use-processor-in-your-project/