Enable Wake On Lan (WoL) on Ubuntu 16.04

If you have bought crappy motherboard from gigabyte like me that doesn’t even have support for WoL in the BIOS, and no-brand ethernet for which even the manufacturer can’t tell you if it support WoL(such unique feature!), then you will have to buy additional NIC, and add few line to the file:

/etc/network/interfaces

and add the following

auto enp3s0
iface enp3s0 inet dhcp
	up ethtool -s enp3s0 wol g

where enp3s0 is your interface name.

Or you can just buy yourself something decent.

pptpd on Raspbian

I wanted VPN running on my RaspberryPi 2, so I could WoL my PC and also see my network.
Initially I was going for OpenVPN, but it is a pain to use on all devices and also can be fiddly to set up.

pptp is known to be very insecure, and you shouldn’t really use it.

Setting pptpd on raspbian is pretty easy
Before we begin we need to run to usual update/upgrade

sudo apt-get update
sudo apt-get upgrade

Then install pptpd

sudo apt-get install pptpd

We will need to tell pptpd on which ip is installed and also what IP addresses to give to our clients:

sudo nano /etc/pptpd.conf

Find the line

#localip 192.168.0.1 

uncomment it(remove the #) and change the IP address to the IP of the Pi.

If you want the clients to be given specific IP addresses, you will need to uncomment:

#remoteip 192.168.1.234-238,192.168.1.245

Add DNS servers (I used google ones),
open

sudo nano /etc/ppp/pptpd-options

and at the end of the file add this:

ms-dns 8.8.8.8
noipx
mtu 1490
mru 1490

Enable port forwarding, open

sudo nano /etc/sysctl.conf

and ucomment

#net.ipv4.ip_forward=1 

Iptables will have to allow connections and routing, and also to make iptables riles permanent(after restart) we will add them to the crontab:

sudo crontab -e

add this:

@reboot sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

The final thing is to populate the table with the users and their passwords, yoi can do this by opening

sudo nano /etc/ppp/chap-secrets

and add you user/s like that

user[TAB]*[TAB]password[TAB]*

The file should look something like that:

# Secrets for authentication using CHAP
# client        server  secret                  IP addresses
user   *       password       *

Of course change user and password with your own, and if you want add more users.

Restart the pptp server and you should be good to go:

sudo systemctl restart pptpd.service

If you are having problems to connect you might need to forward tcp port 1723 to the same port on your RPi IP.

HTML5 Blank page

Bare bones html5 markup page for copy/pasting purposes 🙂

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">

  <title>Page title</title>
  <meta name="description" content="HTML5 Blank">
  <meta name="author" content="idenkov">

  <link rel="stylesheet" href="css/styles.css">
  <script src="js/scripts.js"></script>

  <!--[if lt IE 9]>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
  <![endif]-->
</head>

<body>

</body>

</html>

How to make border smaller than div

CSS sometimes can be like trying to fit puzzle made of solid color.
And by sometimes I mean almost every time.

Recently I had to make border under element which is smaller in width than the element.
That sounds fairly simple, but it took more than hour of my time so I think it have it’s place here.

First when you google, you would think that you can use the property

border-bottom-width

But guess what, that would not determine the border width, but its height/thickness. Because that makes sense somehow.

 

So here is the snippet, with pseudo after element and the parent –


.div {
color: #3483DF;
position: relative;
}

.div:after {
content: '';
position: absolute;
width: 50%;
left: 25%;
bottom: -20px;
border-bottom: 1px solid #3483DF;
}

Hide WordPress plugin from the plugin list.

If you want to hide a plugin name from the WordPress backend for whatever reason, you can use this piece of code in the functions file on your active theme:

	function hide_plugin_reallusion() {
	  global $wp_list_table;
	  $hidearr = array('plugin-folder/plugin.php');
	  $myplugins = $wp_list_table->items;
	  foreach ($myplugins as $key => $val) {
		if (in_array($key,$hidearr)) {
		  unset($wp_list_table->items[$key]);
		}
	  }
	}
	 
	add_action('hide_plugin_backend', 'hide_plugin_reallusion');

Or make this into plugin? Why not – plugins for everyone, let’s get covered in plugins.

Postfix allow only localhost outgoing emails.

A lot of servers don’t need to receive mail, as people nowadays use services like Gmail.

It is simple as changing the inet_interfaces directive in main.cnf from all to 127.0.0.1

vim /etc/postfix/main.cf
inet_interfaces = 127.0.0.1

You can verify it by testing with nmap, it should say it is a closed port

nmap -p 25 domain.com

Starting Nmap 6.40 ( http://nmap.org ) at 2016-01-28 22:55 EET
Nmap scan report for embodyactive.net.au (128.199.108.77)
Host is up (0.37s latency).
PORT   STATE  SERVICE
25/tcp closed smtp

Nmap done: 1 IP address (1 host up) scanned in 0.79 seconds

Nginx simple load balancing.

Nginx is amazing and load balancing with it is so easy, since it is a proxy too we can have everything working perfectly on the same domain.
First you will need few application servers that are listening to some ports, and the might be different like 81, 82, 83 etc. But that is not necessarily.

Then you need something like this on the load balancer, and voila –

server {

  listen 80;
  server_name balancer;

  location / {
     proxy_pass  http://balancer;
     include /etc/nginx/proxy_params;
  }

}
    
upstream balancer {
   ip_hash;
   server ha1.com;
   server ha2.com:82;
   server ha3.com:83;
}

ip_hash is important for sessions and logins, if you don’t want to have users logged out from your site, as the default behavior is round-robin which mean the users will cycle on the next node after every request.

There is other configuration options, but this is just quick syntax reference, you can check the documentation here – http://nginx.org/en/docs/http/load_balancing.html

Convert AWS .ppk key to .pem openSSH

I had to deal recently with AWS instance, and I was provided only with .ppk key, which is not not exaclty compatible with openSSH.
You can use PuTTY under Linux, but this thing looks really awful, if you think I am being pretentious just take a look at this garbage:

So what you need to do is to use

puttygen

which comes with PuTTY.

You will have to install with your package manager PuTTY, it should be available in yout repos, as it is fairly popular package.

I am using Ubuntu so for me that would be:

sudo apt-get install putty

Navigate to the folder where your .ppk key is and generate .pem key:

puttygen aws.ppk -O private-openssh -o aws.pem

Move it to your .ssh filder where all the other keys are and change key permissions:

sudo chown 400 .ssh/aws.pem 

And then connect specifying that you want to use your with the -i option:

ssh -i .ssh/aws.pem ubuntu@ec2-21-000-12-37.compute-1.amazonaws.com

Just be careful about the key path, and typos and it should be fine.

Contact Forms not working on GoDaddy

If you are pulling your hair why the hell any php form on your site hosted on GoDaddy is not working, you are on the right place.

The reason is because GoDaddy added some kind of “security” feature that will not allow you to send e-mails from accounts that doesn’t exist in the system (CPanel).

So for example if your form is sending emails from behalf of wordpress@site.com it is not going to work.

What you need to do is to go the CPanel and create a freakin mail account from which you want to send the mails.
I mean WTF GoDaddy? Can’t you at least mention this on your freaking site?