27 October 2016

Auto-forward Webmails

After much toiling to get webmails to be pushed to mobile, I was still dissatisfied with it.

It only fetched mails if I was connected to the intranet.

So I figured since a lot of us have access to a work station that runs 24*7 and is connected to both the internet and the intranet, why not use it as a relay for webmails.


So here is a guide to do the same -

1. Make an account on mail-gun. Register for it using the email you want to forward your webmails to and verify your account to enable a sandbox domain.

We will be using mail-gun's https api to forward our mails ( Since our institute blocks all ports apart from 80 or 443, so no gmail pop3/imap to the rescue)

2. Once you have created an account and verified it go to the following link -
https://mailgun.com/app/domains

You will see a sandbox domain. Click on it and keep a copy of the domain and the api-key.

Your domain will look something like this -

sandboxd6eebfa15f55422ab904868718950d50.mailgun.org

Your api-key will look like the following - 
key-##################77ae

Be careful not to copy the spaces after the key or the domain.

3.  Now run the following commands - 

sudo apt-get install python-requests


Right click on it and save it at an appropriate location.

5. Run the above script and fill in the appropriate values. ( Make sure the email-id you are forwarding to is the same as the one you registered for mailgun)

To run the script, cd to the appropriate directory and run "python mail.py"



6. The script will create the necessary files and send a few email depending on your input.

7. To auto-push the mails, add a cronjob for the above script.

If you configured the above script correctly, it should have displayed a line of code to configure the cronjob for your particular system.

8. Copy that line.

9. Run  the following command in terminal - 

crontab -e

Crontab should open with your default editor.
If you haven't picked one already, pick nano.

Paste the line copied in step 8 at the end of the crontab file that opened.

Press Ctrl+X and then Y to confirm the addition of the new cronjob.

Voila, enjoy.


If you know of a better method to forward webmails, please let me know in the comments :)


26 July 2016

Squid for Ubuntu, because proxies are too much of a hassle

EDIT : Added Authentication methods for dynamic ips


It has been more than a year since I have been using squid to mitigate all the proxy problems that come due to the proxy authentication.

This is the most effective and hassle free way to set proxy in Linux.

Steps:

Note : Replace 'squid' with 'squid3' if you are not using Ubuntu 16.04

1. Install squid

sudo apt-get install squid

2. Edit the squid configuration file.

sudo vim /etc/squid/squid.conf

(for Ubuntu 15.10 and older)

sudo vim /etc/squid3/squid.conf

3. Delete all the contents of that file and replace them with the configuration given below:


Replace 10.0.2.21 with your own ip address/ other ip addresses that you want to access this proxy from.

Change 202.141.80.22 with your Proxy server address.

Change username:password to your proxy username and password.

4. Save the file ( Esc and ":wq" for vim noobs)

5. Restart the squid server.

sudo service squid restart

(for Ubuntu 15.10 and older)

sudo service squid3 restart

6. Edit your Proxy Settings from the network manager.




















7. Open your bash profile.

sudo vim ~/.bashrc

Append the following to the end of the file.

export http_proxy=http://127.0.0.1:3128
export https_proxy=http://127.0.0.1:3128


The above two things should effectively resolve all proxy problems ( Environment Variables inclusive. )

8. Source the bashrc

source ~/.bashrc

And with that you are done!

You have your own personal proxy server!

Say goodbye to proxy problems.


PS - For those of you on the more geeky side of things, what we have done with the above is create our own proxy server that caches another proxy server with authentication.

The proxy server we have made is effectively a non authentication proxy server for the ips in the allowed_ips acl.

If used a bit cleverly it might also help you get around some other big-'time' restrictions ;) .

Use wisely!