Setup And Host My Own VPN

What I used: Windows 7 Professional, TP-Link TL-R600VPN Router

This is pretty cool. VPNs have been around for aaaages, and there are tons of amazing uses for a VPN. Today I’m going to show you one scenario and what I did to take advantage of VPN technology to provide a solution. You will need a PPTP VPN-capable router for this setup.

The Scenario

My brother wants to access resources on my LAN, such as my media server, but he lives 30 miles away. We both have great broadband and he runs a Windows 7 PC (since neither of us can stand Windows 10). Enter the humble VPN. With this tech he can connect remotely to my network and be treated like just another machine on the Local Area Network – sweet!

The remote PC in this scenario is running Windows 7 Professional with Service Pack 1. Later on I will show you how to configure a VPN connection for that Operating System, but this can be modified for your own OS and version as applicable.

The Router

To be completely honest, my own network is double-NAT’ed. That essentially means I have 2 routers; in my setup one router faces the internet and forwards all traffic to a second router, and that second router acts as the LAN gateway. It also serves DNS records for the LAN and is the DHCP server for the range 192.168.0.2192.168.0.200 (this range is important, I will explain why later on). I’ve omitted the first (WAN-facing) router in this guide since it is basically invisible and has no bearing on the setup as described here. FWIW that is a standard, unmodified Sky Router with WiFi disabled.

OK, onwards!

You will (obviously) need to have a VPN-capable router for this to work, since remote clients will be connecting to the router using that protocol. I’m using the brilliant little TP-Link TL-R600VPN. I know, I know, TP-Link is funded by the Chinese government and I’m supporting a suppressive regime by using one, etc. etc. They are great products, and inexpensive as well. Personally I’ve had a great experience with TP-Link products on the whole. This particular model supports several VPN modes. I will be using PPTP since it is easy to setup and maintain. Check out the wikipedia page for more information on PPTP.

Admittedly PPTP is rather old now, and this type of connection is not very secure, therefore I DO NOT recommend this for any scenario requiring a high level of security..

There, I said it; you have been warned.

Router Setup

1. Connect to your router’s admin interface using a web browser; it’s usually at 192.168.0.1. Login if necessary.

2. Navigate to the PPTP VPN Server page using the left-side navigation menu.

3. Enable both the PPTP Server and MPPE Encryption options.

4. Enter the IP range that the VPN server will use. This range must be within the address range of the LAN and also must not overlap the DHCP pool. For example, if the DHCP range runs from 192.168.0.2192.168.0.200 then your VPN server range must be outside that, as is the case in my example above. Adjust your settings as necessary.

Also your range should allow for several addresses, even if you intend to connect only 1 client. I’ve allowed for 20 IP addresses in my range (201 – 221). Next we need to add some accounts for users to connect with.

5. Save your settings.

6. Navigate to Account Settings, still under the PPTP VPN Server section.

From here we will add some accounts for users to connect with.

7. Click on the Add New… button and fill out the form.

The Account field is essentially the username.

8. Be sure to set the Status to Enabled and save the account info.

That’s the router setup completed. See, that wasn’t too difficult at all. Next we will move on – to the connection from the remote PC.

Remote PC Connection

Our VPN “server” is setup and waiting for connections. The next thing is to configure our client PC to connect to the server remotely.

In this setup I am using the basic Windows 7 theme. Your screen may differ slightly if you are setup to use the default “Aero” theme that ships with Windows 7 Pro. Despite the different appearance, the settings are identical.

1. Click on the Network icon on the Windows 7 taskbar (normally on the bottom right of your screen).

2. A small popup appears. Click on Open Network and Sharing Center.

3. Click on Set up a new connection or network.

4. Choose the option Connect to a workplace and click Next.

5. Choose the first option; Use my Internet Connection (VPN).

6. Next you will enter the VPN location address. Also we don’t want to connect now, so select that option. When you’re done, click Next.

In this example we will use the public IP of the remote network. If you want to get really fancy, you could setup a domain name to use here. Most Internet Service Providers will use dynamic IP addresses (as opposed to static IP addresses), in which case you will need to use a Dynamic DNS (DDNS) service if you want to have a domain name instead of an IP address. That is beyond the scope of this article though. For now we will use the WAN IP address of the remote network, which I’m pretending is 8.8.8.8. Name the connection anything you like.

Help, I don’t know the public IP address! From the target network (where the VPN server is listening), click this link.

7. Almost done. Next enter the account details you created earlier on the VPN server and click Create.

8. That’s the setup complete. Click Close since we want to tweak the properties before we connect to the VPN.

Connect to the VPN

Now that we have setup the connection, we just need to make some minor tweaks and we will be ready to connect.

1. On the Network and Sharing Center window, click on Change adapter settings.

2. Right-click on the VPN connection and select Properties.

3. Click on the Security tab and select PPTP from the Type of VPN drop-down list.

Depending on the VPN Router you are using, you may also have to check the option Unencrypted password (PAP).

4. Click OK to save the settings. Then right-click the connection again and click Connect.

5. We entered the account details earlier, so you should be ready to go. Click Connect.

After a short interval the VPN should connect. You will also see the connection listed on your connections popup when you click the network icon in the taskbar.

If you want to be connected to the VPN only then just disable the other connections in the Network Connections window.

 

Yay, you just setup your own VPN! The remote user can now connect to LAN resources as if they were sitting next to you.

read more

View The Git Commit Tree In Terminal

Ubuntu 14.04.2 LTS, Git 1.9.1

Sometimes it’s super-useful to view the Git commit tree right in the terminal on the remote host. This can be achieved in several ways. I’m going to show you how we can get a simple coloured summary output of the state of the repo right in the terminal. Lastly we’ll add an alias to make future requests super-easy.

The Tree

We can use Git’s log feature to dig up old commits and spit them out. We can even do this in a decorative order if we add some parameters. First, let’s see the standard output;

1
$ git log

This will give us some expanded output, similar to the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
commit 7eaddaec9306993jdu02110071ed0477146717cd
Author: Jason <webmaster@commitit.now>
Date:   Thu Apr 16 20:29:42 2015 +0100

    Allowing to simmer now, garlic is in.

commit 532c7f4akdi3sfe7d3fcc045b99de10a6c02d65c
Author: Jason <webmaster@commitit.now>
Date:   Thu Apr 16 20:27:02 2015 +0100

    Smells amazing, time for a splash of white wine.

commit 2a89c4f3cca638f9debf4830b57fe3fca980cc03
Author: Jason <webmaster@commitit.now>
Date:   Thu Apr 16 20:25:47 2015 +0100

    Add some onions, and the seasoning, yummy.

commit a1a4e91b2f2e3k239sf456ecdd178d28340cb99a
Author: Jason <webmaster@commitit.now>
Date:   Thu Apr 16 20:24:25 2015 +0100

    Created the repo, let's get cooking!

As you can see, standard log gives us a detailed view of each commit in the history. While this is useful for some tasks, I’m more interested in getting a quick summary of the repo in a tree-like view, particularly the date, commit and commit message.

Let’s make this pretty by passing in some extra arguments.

1
$ git log --oneline --decorate --all --graph

Now we get a much nicer, decorative summary of what’s going on in the repo:

1
2
3
4
* 7eaddae (HEAD, master) Allowing to simmer now, garlic is in.
* 532c7f4 Smells amazing, time for a splash of white wine.
* 2a89c4f Add some onions, and the seasoning, yummy.
* a1a4e91 Created the repo, let's get cooking!

Bingo, that’s what we wanted. We can also see at a glance which branch the HEAD is pointing at. Now to add an alias and simplify future summaries!

Adding A Git Alias

We could add this to the repo’s .git/config file, but since we want this alias available at the user level, we’ll edit the file at ~/.gitconfig instead. You can create this if it doesn’t exist; Git will automatically include this file and any aliases it contains; sweet!

1
2
3
$ vi ~/.gitconfig
[alias]
        tree = log --oneline --decorate --all --graph

Save that and exit. You now have access to the tree alias in Git. You can execute this as simple as:

1
$ git tree

Conclusion

There are other ways to achieve this, and some admins prefer to get very detailed with the Git log. Hopefully this will be a good starting point for you!

read more

Login Redirects Back To Itself Magento 1.5

Magento 1.5.1.0 CE

In a multi-store environment, the user may experience issues trying to login to their account on Magento CE pre-1.7. Any of the following symptoms may be present:

  • Login page just redirects, no error or success message, user is not logged in.
  • Admin sessions are unaffected, and admin users can login normally.
  • Login may succeed if there is an admin session underway.
  • Login may succeed randomly, or if a specific path to the login page is followed.

If yours is instead a Magento version greater than 1.7 CE and you are getting one or more of these issues, check that the hidden form_key fields are present in your theme files. Onwards!

Update The Core Files

As most Magento developers know, you never, ever update the core files, but I’m going to make an exception for this issue! The only time one should ever modify the core files to Magento is if we don’t care what happens to our change upon an update of the Magento Core (version upgrades, for example).

Since this issue is specific to Magento 1.5.1.0, we can safely modify the core file(s) in this case. Around line 78 of the Session Varien Class, inside the start method, we have the following block of code;

File: app/code/core/Mage/Core/Model/Session/Abstract/Varien.php

1
2
3
4
5
6
7
$cookieParams = array(
    'lifetime' => $cookie->getLifetime(),
    'path'     => $cookie->getPath(),
    'domain'   => $cookie->getConfigDomain(),
    'secure'   => $cookie->isSecure(),
    'httponly' => $cookie->getHttponly()
);

We need to keep the array elements since they are referenced elsewhere, so instead we set them to empty. Change the code block as follows;

File: app/code/core/Mage/Core/Model/Session/Abstract/Varien.php

1
2
3
4
5
6
7
8
9
10
$cookieParams = array(
    'lifetime' => $cookie->getLifetime(),
    'path'     => $cookie->getPath(),
    'domain'   => '',
    'secure'   => '',
    'httponly' => ''
    //'domain'   => $cookie->getConfigDomain(),
    //'secure'   => $cookie->isSecure(),
    //'httponly' => $cookie->getHttponly()
);

Conclusion

Once you have saved the changes, you will need to flush the cache, or (better yet) the var folder in your Magento root directory. Also, if you are using an opcode caching system (Memcached, APC, etc), that should also be flushed.

read more