Monthly Archives: May 2014
Authentication in mongodb
Mysql databases allow username and password. Similarly if you require to keep authentication for your mongodb database as well, please do the following. Suppose, I have a database named abc, and I need to create a user named abc with password abc123.
First, create an admin user.
root@abc:~# mongo
MongoDB shell version: 2.4.10
connecting to: test
> use admin
> db.addUser(“admin”, “admin”)
> use abc (Switch to the database abc)
> db.addUser(“abc”, “abc123″)
Quit the mongoshell and stop mongo
root@abc:~# /etc/init.d/mongodb stop
root@abc:~# vi /etc/mongodb.conf and make the following change
auth = true
root@abc:~#/etc/init.d/mongodb start
Now we need to test if authentication works. Which means, if not authenticated, you should not be able to saw the details of the database.
root@abc:~# mongo
MongoDB shell version: 2.4.10
connecting to: test
> use abc
> show collections
“$err” : “not authorized for query on abc.system.namespaces”,
“code” : 16550
Now it shows the error that you are not authorized to view the collections. Now, authenticate with the details you created earlier and try.
> db.auth(“abc”, “abc123″)
>show collections
testcollection
system.indexes
This is how you create a user for mongodb database.
Accessing Gmail with Roundcube
Requirement : I want to access my gmail under my own domain with the help of webmail.
Say my domain name is abc.com , I want to access it as http://abc.com/mail
Suppose I am on a cpanel server. Download and install Roundcube as follows.
root@me [/home/abc/public_html]# wget http://downloads.sourceforge.net/project/roundcubemail/roundcubemail/1.0.0/roundcubemail-1.0.0.tar.gz
root@me [/home/abc/public_html]# tar -xzvf roundcubemail-1.0.0.tar.gz
root@me [/home/abc/public_html]# mv roundcubemail-1.0.0 mail
root@me [/home/abc/public_html]# chown -R abc:abc mail
root@me [/home/abc/public_html]# cd mail
Now login to your cpanel and create a database for roundcube installation, create a database user and assign privileges. This can all be done from cpanel.
Once done, go to the installer link as http://abc.com/mail/installer, follow the on screen instructions, make sure to give the database details correct and do not overwrite or create any conflict with the existing roundcube installation that comes with cpanel.
Once the installation is done, there are two files which requires attention.
root@me [/home/abc/public_html/mail]# cd /home/abc/public_html/mail/config
Make sure the config.inc.php and defaults.inc.php are populated with the correct database details.
root@me [/home/abc/public_html/mail/config]# vi defaults.inc.php and edit the following fields
// IMAP Settings
$rcmail_config[‘default_host’] = ‘ssl://imap.gmail.com';
$rcmail_config[‘defaul_port’] = 993;
$rcmail_config[‘imap_auth_type’] = null;
$rcmail_config[‘username_domain’] = ‘yourdomainname'; // Give the domain name that use googleapps. If you are using gmail account, give gmail.com
$rcmail_config[‘mail_domain’] = ‘yourdomainname'; // Give the domain name that use googleapps. If you are using gmail account, give gmail.com
// SMTP Settings
$rcmail_config[‘smtp_server’] = ‘ssl://smtp.gmail.com';
$rcmail_config[‘smtp_port’] = 465;
$rcmail_config[‘smtp_user’] = ‘%u';
$rcmail_config[‘smtp_pass’] = ‘%p';
//MBOX Settings
$rcmail_config[‘drafts_mbox’] = ‘[Gmail]/Drafts';
$rcmail_config[‘junk_mbox’] = ‘[Gmail]/Spam';
$rcmail_config[‘sent_mbox’] = ”;
$rcmail_config[‘trash_mbox’] = ”;
Save and quit the file. Remove the installer folder.
root@me [/home/abc/public_html/mail/config]# rm -rf /home/abc/public_html/mail/installer
Now access your gmail through your roundcube installation.
http://abc.com/mail
Username : test if my gmail account is test@gmail.com
Password : test123 if my gmail pass is test123
Migrating emails from mailenable to exim
If you want to copy emails from a windows mailenable server to linux server with exim, you can do it as follows.
I am copying the email account test@abc.com to new server. Its password is test123c on both servers.
root@abc [~]# cd /usr/local/src/
root@abc [/usr/local/src]# wget http://home.arcor.de/armin.diehl/imapcopy/imapcopy.tar.gz
root@abc [/usr/local/src]# tar -xvf imapcopy.tar.gz
root@abc [/usr/local/src]# cd imapcopy
root@abc [/usr/local/src/imapcopy]# ls
./ ../ imapcopy* ImapCopy.cfg
root@abc [/usr/local/src/imapcopy]# cp -pv ImapCopy.cfg ImapCopy.cfg.original
`ImapCopy.cfg’ -> `ImapCopy.cfg.original’
root@abc [/usr/local/src/imapcopy]# vi ImapCopy.cfg
You need to edit the following values to make the migration smoother.
##############
# Sourceserver
##############
SourceServer 1.2.3.4 (Source Server IP Address)
SourcePort 143
###################
# Destinationserver
###################
DestServer localhost
DestPort 143
#############################
# List of users and passwords
#############################
# SourceUser SourcePassword DestinationUser DestinationPassword
Copy “test@abc.com” “test123c” “test@abc.com” “test123c”
[/stextbox]
Make sure you are able to connect to port 143 of source server from destination server
[stextbox id=”info”]
root@abc [/usr/local/src/imapcopy]# telnet 1.2.3.4 143
Trying 1.2.3.4…
Connected to abc.greproot.com (1.2.3.4).
Escape character is ‘^]’.
* OK IMAP4rev1 server ready at 05/07/14 05:46:17
^]
telnet> q
Connection closed.
[/stextbox]
Now test the configuration
[stextbox id=”info”]
root@abc [/usr/local/src/imapcopy]# ./imapcopy -t
IMAPCopy 1.04 – 2009/07/18 [compiled with FreePascal]
written 2001-2009 by Armin Diehl <ad@ardiehl.de>
Running on Linux
Login on sourceserver as test@abc.com OK
Login on destinationserver as test@abc.com OK
Getting folderlist on sourceserver OK, found 1 folder
1 User processed, 0 Messages copied, 0 Error(s)
0 Folder(s) created, 0 Folder create errors, 0 Folder not copied
[/stextbox]
The configuration looks fine without any errors. Now we can start copying the email account contents.
[stextbox id=”info”]
root@abc [/usr/local/src/imapcopy]#./imapcopy
IMAPCopy 1.04 – 2009/07/18 [compiled with FreePascal]
written 2001-2009 by Armin Diehl <ad@ardiehl.de>
Running on Linux
Login on sourceserver as test@abc.com OK
Login on destinationserver as test@abc.com OK
Getting folderlist on sourceserver OK, found 1 folder
Getting List of messages in “INBOX” OK, 7 Messages found
Processing Folder INBOX
7 Messages copied, 0 Errors
1 User processed, 7 Messages copied, 0 Error(s)
0 Folder(s) created, 0 Folder create errors, 0 Folder not copied
[/stextbox]
Now the mails have been copied. Try accessing webmail of the account test@abc.com and see if mails are displayed fine.