Saturday, September 29, 2012

How to install Redmine

This is the cleanest way I found. If you know any of the steps could be skips, please share :-)

# Ubunut 12.04

# Run the following commands one by one

# install LAMP
tasksel install lamp-server

sudo apt-get install ruby1.9.3 libmysqlclient-dev libapache2-mod-passenger

sudo gem install bundler

# go to the directory where you put the redmine source code
# i.e. replace /path/to/ with your directory path
cd /path/to/redmine

sudo bundle install --without development test postgresql sqlite rmagick

# go into mysql 
# e.g. mysql -u root -p

-- create database
create database redmine character set utf8;

-- create db user
create user 'redmine'@'localhost' identified by 'password.you.want.to.use';

-- assign privileges
grant all privileges on redmine.* to 'redmine'@'localhost';

# create configuration file
cp /path/to/redmine/config/database.yml.example /path/to/redmine/config/database.yml

# put your database details in this file
vi /path/to/redmine/config/database.yml


rake generate_secret_token

sudo RAILS_ENV=production rake db:migrate
sudo RAILS_ENV=production rake redmine:load_default_data

mkdir /path/to/redmine/public/plugin_assets
sudo chown -R www-data:www-data files log tmp public/plugin_assets
sudo chmod -R 755 files log tmp public/plugin_assets

# if email does not work

sudo install postfix
cp /path/to/redmine/config/configuration.yml.example /path/to/redmine/config/configuration.yml
# set email to :sendmail in /path/to/redmine/config/configuration.yml


Reference:
http://www.redmine.org/projects/redmine/wiki/RedmineInstall

Friday, September 28, 2012

CIDR notation

This might help you understand CIDR notation.

IPv4 version:

IP / Bit Mask - 0.0.0.0/32

IP / Bit Mask represents a pool of IP addresses.

Bit mask is a number from  0 to 32

example: 192.168.1.1 / 32

Think IP as a string of thirty two 1s or 0s, eight bits in each section.

1111 1111.1111 1111.1111 1111.1111 1111 (255.255.255.255)

so 10.0.0.1 / 32 could be seen as
0000 1010.0000 0000.0000 0000.0000 0001 / 32
(I put a space between every 4 bit just to make it easier to read)

bit mask means the number of bits must match to this 32 bits representation of the IP.

so /32 here means all IP addresses in this pool must match all 32 bits of this IP 
i.e. 10.0.0.1/32 represents one ip address: 10.0.0.1

10.0.0.1/31 means only first 31 bits must match/be same. The last bit is free to be anything. 
00001010.00000000.00000000.0000000 1
00001010.00000000.00000000.0000000 0

so the IP pool represented by 10.0.0.1/31 contains two IPs. 10.0.0.0 and 10.0.0.1

another example: 

10.0.0.1/24 requires the first 24 bits match 10.0.0.1 so leave last 8 bits free which creates a pool of 256 IP address (28 IP) i.e. 10.0.0.0 ~ 10.0.0.255

example from Wikipedia:





References:

http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
http://en.wikipedia.org/wiki/IPv4_subnetting_reference

Saturday, September 15, 2012

Redirect all outbound emails to one address

Short Version:

sudo apt-get install postfix

sudo vi /etc/postfix/main.cf

    # add into /etc/postfix/main.cf
    always_bcc = youremail@yourdomain.com
    transport_maps = hash:/etc/postfix/transport

sudo vi /etc/postfix/transport

    # add into /etc/postfix/transport
    your-email@your-domain.com :
    * discard:

sudo postmap /etc/postfix/transport
sudo /etc/init.d/postfix restart


Long Version:
 
Took me hours to find this "clean" method... Just to save you some time from searching...

You might need this because...

On my local development server, I don't want to send emails to users in my dev database  which in my case is a copy of the production db. I need catch all out going emails and redirect them to my email address so I can test if the code sends correct emails without spamming real users.

According to the second reference link at the bottom, the way I used here does what you want without filling your outbound queue or requiring CPU time to process all the bounces. 

What to do:

# Install Postifx:

sudo apt-get install postfix

# Edit postfix configuration file

sudo vi /etc/postfix/main.cf

# add following settings

# bcc all outbound (and inbound?) email to developer
# why bcc? you can still see "To" in emails, useful for testing

always_bcc = youremail@yourdomain.com

# redirect emails based on /etc/postfix/transport
transport_maps = hash:/etc/postfix/transport

# optional, just in case some mail server reject emails from development server, change myhostname to a FQDN
myhostname = your-domain.com

# create mapping

sudo vi /etc/postfix/transport

# add following lines

# no restriction for your email your-email@your-domain.com
# as you still need BCC going out to your email 
# format below: email [space] [colon] [new line]

your-email@your-domain.com :

# all other emails going to nowhere/black hole
# [asterisk] [space] discard[colon]

* discard:

# apply map

sudo postmap /etc/postfix/transport

# restart postfix

sudo /etc/init.d/postfix restart

# reference
# http://www.informedemail.com/blog/2011/01/using-postfix-transport-maps-for-email-address-specific-aliasing.html
# http://rene.bz/redirect-all-outgoing-email-single-account-postfix/