Admins eHow SysAdmin Tips & Tricks

April 26, 2017

Email to Telegram gateway

Filed under: PHP — Tags: , , , — admin @ 7:21 am

1.Create your own Telegram bot based on this tutorial :
https://www.domoticz.com/wiki/Telegram_Bot
or this one :
https://www.forsomedefinition.com/automation/creating-telegram-bot-notifications/
2.Create an email forwarder in cPanel and pipe it into a PHP script. make sure the script is executable (755 permission).
3.Here is the php script that will forward the email to your telegram bot :
Dont forget to adjust $url variable in telegram function based on first step.

#!/usr/local/bin/php -q
<?php
function mailRead($iKlimit = "")
{
	if ($iKlimit == "") {
		$iKlimit = 1024;
	}
	$sErrorSTDINFail = "Error - failed to read mail from STDIN!";
	$fp = fopen("php://stdin", "r");
	if (!$fp) {
		echo $sErrorSTDINFail;
		exit();
	}
	$sEmail = "";
	if ($iKlimit == - 1) {
		while (!feof($fp)) {
			$sEmail .= fread($fp, 1024);
		}
	}
	else {
		while (!feof($fp) && $i_limit < $iKlimit) {
			$sEmail .= fread($fp, 1024);
			$i_limit++;
		}
	}
	fclose($fp);
	return $sEmail;
}

function telegram($m)
{
	$url = 'https://api.telegram.org/botxxxxxxx:xxxxxxxxx/sendMessage?chat_id=xxxxx&text=';
	$url .= urlencode($m);
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$response = curl_exec($ch);
	curl_close($ch);
}

$mail = mailRead(4096);
$lines = explode("\n", $mail);

$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;

for ($i = 0; $i < count($lines); $i++) {
	if ($splittingheaders) {
		$headers .= $lines[$i] . "\n";
		if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
			$subject = $matches[1];
		}
		if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
			$from = $matches[1];
		}
		if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
			$to = $matches[1];
		}
	}
	else {
		$message .= $lines[$i] . "\n";
	}
	if (trim($lines[$i]) == "") {
		$splittingheaders = false;
	}
}

telegram("From: $from\nSubject: $subject\nMessage: $message");
?>

April 5, 2017

How to monitor bandwidth/traffic usage on a router

Filed under: Networking — Tags: , , , , , — admin @ 4:32 pm

Usually users dont care about their Internet traffic usage, especially on broadband lines as ISP’s provide unmetered bandwidth.
Unfortunately it is not the case for everyone, I have to pay for every single gigabyte of traffic that I use to my ISP. Can you believe that !?
Recently I noticed my ISP usage statistics are a tad high, so I decided to log my usage myself and compare it to my ISP stats.
I have a Mikrotik router which is somewhat advanced, so I expected an easy straight forward solution to measure my daily traffic, but to my surprise I was wrong.
Most solutions available are inaccurate -like query speed of interface every 5 minutes and calculate an estimate- or hard to implement and overkill.
So I came up with a novel idea. Here is the principle:
Most routers keep inbound & outbound bandwidth counters of their network interfaces. If we can query these numbers through SNMP on predefined intervals, we can calculate interface traffic precisely.
(more…)

AdminseHow BitcoinUnlimited and ElectrumX servers online !

Filed under: General — Tags: , , — admin @ 11:31 am

It’s been quite a while that I’ve been running a bitcoin unlimited node and an electrumx server as a contribution to bitcoin network.
I bought all of my bitcoins in 2010-2011 for $10 each and have already made a quite nice 120.000% profit on my investment so a contribution was due.
Both servers provide auto discovery and as a client, you usually don’t need to configure your server or peers manually but technically you can!
If you needed a reliable and fast bitcoin node peer or electrum server, feel free use the following :

Bitcoin Unlimited node:

electrumx.adminsehow.com:8333

Electrum TCP:

electrumx.adminsehow.com:50001

Electrum SSL:

electrumx.adminsehow.com:50002

Powered by WordPress