Tuesday, September 15, 2015

Allowing secondary monitor for VirtualBox (5.0.4) VM in three easy steps

1. Power off VM. Go to Settings->Display, change number of monitors to 2. Add video memory if there is a warning.
2. Run the VM. Open View->Virtual screen 2 menu and select "Enabled". The second VM window appears.
3. As per your VM OS go to Settings / Control Panel and modify Display so the OS can use both monitors, just like with the normal Windows or Linux computer. For Ubuntu it is Settings->Display, for Windows you can right-click on desktop background and select "Screen Resolution..." menu.

Installing Ubuntu 14.04 in VirtualBox for NGiNX modules development

For teh first time, after many years with RHEL / FEdora / CentOS family I decded to give a try to Ubuntu. Why? First, because it is the Linux of choice at AWS, after Amazon Linux of course.
Second, in order to learn something different. Third, in order to make some comparison by myself.

First surprise with Ubuntu 14.04.03 which I installed with Oracle VirtualBox (I gave this development VM 4 CPUs, 12 GB RAM, 40GB HD) is that there is no root access. I defined a user during the install and this user got 'sudo' permissions. So either I have to write 'sudo' every time or allow root access. The latest is not recommended, and this explains why the root access is by default disabled at Ubuntu. In general, I agree with the idea that there is no need to run any user process as a root, and for any system I develop I actually define a specific user which such a system uses. So let's see if I can manage it without enabling root account.

After installing a basic server configuration I wanted to add a Desktop so I could add development IDE there. The only thing I needed to run was:
sudo apt-get install ubuntu-desktop
(as per this link) followed by reboot did the job. Next, I added VBox Guest Additions and got a full-screen resizable Desktop. After that I started to look how I can open a terminal window :). This was a real challenge since "Search" for 'xterm' using top-left Ubuntu icon only gave me the reference documentation for that. It did not run the terminal process though.
CTR-ALT-T worked, but I could not find any other app as well, even not a web browser.

Since I do dnot save the snapshot for teh basic server install I decided to give up and re-installed Ubuntu 14.04 server. Once the basic server install was completed I ran
sudo apt-get --install-recommends install ubuntu-desktop
It took about 15 minutes on my i7 Windows 8.1 machine to install all the required packages, and than I got a black screen with no text. As per System Monitor the VirtualBox process was keep writing things on disk and kept using CPU. First time it happened I killed the process after 10 minutes or so and started over. Next time it happened again, so I decided to give it a chance and left it open.
At the end I found out that I just had to press ENTER and the text is now shown again!
sudo reboot now.
I started VirtualBox Guest Additions CDROM, than Rebooted the machine (had to repeat it twice until it worked) and got teh working Desktop environment.

All-in-all, about 4h to get there with trial and errors.

Next, I installet NetBeans 8.1beta for C++/Java/Scala development. It requested to install JDK (8u60). I also had to install GNU C++ compiler:
sudo apt-get install g++
and CMake
sudo apt-get install cmake
I also had to install PCRE, zlib and a few more librbaries on Ubuntu in order to properly build quite a minimal configuration of NGiNX from the sources:
sudo apt-get install libpcre3 libpcre3-dev zlib1g-dev build-essential libssl-dev

Now I configured NGiNX from the source to be installed in a development path:
cd ; ./configure --prefix=/home/david/dev/nginx
It created Makefile in that folder. I started NetBeans with "New C/C++ project from existing source", pointed to that  and got the Netbeans project for NGiNX.

I had to modify Netbeans project (Right-click on project -> Properties)
adding
${MAKE} -f Makefile install 
instead of 
${MAKE} -f Makefile
to Build section,
and adding 
./configure --prefix=/home/david/dev/nginx
to Pre-build section (check "Pre-build" checkbox!)
After all, I got an IDE-compiled running NGiNX.



Thursday, June 04, 2015

Installing s3cmd from the sources

1. Go to s3cmd GitHub home page: https://github.com/s3tools/s3cmd

2.  Install python, wget and unzip if not installed
yum install unzip python-pip wget

3. Download the archive with the sources:
wget https://github.com/s3tools/s3cmd/archive/master.zip

4. unzip, change directory and run install:

unzip master.zip

cd s3cmd-master

python setup.py install

 5. Run s3cmd and save configuration in the config file:
s3cmd --configure

(provide your access and secret keys on the prompt)

Sunday, May 10, 2015

Create a new Git repository for new / existing project in Netbeans while putting it on Bitbucket

First, there are free accounts at Bitbucket.org, up to 10 users, no obligations, private repositories.

Create a Bitbucket account. Login. Go to "Repositories" menu at the top screen bar and select "Create repository". Add the repository name and other info and create the repository. When done, copy & paste the URL which now appears in the browser, e.g. "https://bitbucket.org/david_mail/my_new_repository".

Open your Netbeans project (I am currently using NB 8.0.2), right click on the project name, select "Versioning"->"Initialize Git Repository". Next, right-click again on the project name and select "Git"->"Commit".

Your project is no in th elocal repository. Let's connect it to teh remote repository so they'll auto-merge. At top NB menu open "Team"->"Remote"->"Push".
If it is the first time you add this Git repository put the Bitbucket' repository URL in "Specify Git Repository Location / origin"->"Repository URL" and provide your user credentials for Bitbucket. Hit "Next" and "Finish" buttons and you are done.

Saturday, April 18, 2015

Installing VirtualBox Guest Additions 4.3.26 on CentOS 7 minimal install

#login as root or "su" there

mkdir /media/cdrom
mount /dev/cdrom /media/cdrom

# will be mounted as read-only, no worries

cd /media/cdrom
./VBoxLinuxAdditions.run

# it will skip all X installs since there is no X in minimal edition

Monday, July 21, 2014

Configuring QT to show flash on CentOs 6

1. Install Flash plugin

wget http://get.adobe.com/flashplayer/download/?installer=Flash_Player_11.2_for_other_Linux_%28.rpm%29_64-bit&standalone=1

sudo rpm -ivh flash-plugin-11.2.202.394-release.x86_64.rpm

2. Make sure your QT source code have this line:

QWebSettings::globalSettings()->setAttribute( QWebSettings::PluginsEnabled, true);


Your QWebView should now properly show embedded flash players.

Wednesday, June 18, 2014

Mass-mailing with SMTP (ssmtp) from Linux/CentOS via GMail or outlook365.com

I needed to send 500 emails to the customers followed by another few thousands customers notifying them about the changes in their account. Unfortunately, our other departments are not skilled enough to use MailChimp, iContact or any other mass-mailer, so... no choice.

I wanted to go over our SMTP server to reduce any risk of emails going to spam. I also needed full control of "From:" field, so while sending from account "aaa" I could force emails to appear like they were sent from account "bbb" in our company. After about two hours of playing with
mail -s "some subject" address@domain.com -- -f "bbb@ccc.com"
I came into conclusion I can not do it with "mail" utility. Below I describe further steps I took to start sending emails.

1. Install ssmtp


yum install ssmtp


2. Edit the configuration file


sudo vi /etc/ssmtp/ssmtp.conf

so it looks this way:

2.a for sending via GMail -


#
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.
#
# See the ssmtp.conf(5) man page for a more verbose explanation of the
# available options.
#

# The person who gets all mail for userids < 500
# Make this empty to disable rewriting.
root=

# The place where the mail goes. The actual machine name is required
# no MX records are consulted. Commonly mailhosts are named mail.domain.com
# The example will fit if you are in domain.com and your mailhub is so named.

# Where will the mail seem to come from?
RewriteDomain=my-company.com
mailhub=smtp.gmail.com:465
AuthUser=my-username-at-gmail
AuthPass=my-password-at-gmail
TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt
FromLineOverride=YES
UseTLS=YES



2.b for sending via outlook365.com


#
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.
#
# See the ssmtp.conf(5) man page for a more verbose explanation of the
# available options.
#

# The person who gets all mail for userids < 500
# Make this empty to disable rewriting.
root=

# The place where the mail goes. The actual machine name is required
# no MX records are consulted. Commonly mailhosts are named mail.domain.com
# The example will fit if you are in domain.com and your mailhub is so named.

# Where will the mail seem to come from?
RewriteDomain=biscience.com
mailhub=smtp.office365.com:587
AuthUser=my-user@my-company.com
AuthPass=my-pwd
TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt
FromLineOverride=YES
UseTLS=YES
UseSTARTTLS=YES

3.  Create a text file with your email, e.g. vi /tmp/email.txt


To: __EMAIL__
From: "Support "
Reply-To: "Support "
Subject: Link to reset your password

Hi __USER__,

Following our previous e-mail, your login credentials have been reset. Please click the below link and follow the instructions to reset your password.


Reset your password now: __LINK__

Best Regards,
__ACCOUNT_MANAGER__


4. Test you can send your email to some address:


ssmtp -v your-user@your-company.com < /tmp/email.txt



For GMail, you have to approve the IP you are sending from via GMail web interface. Do it after your first sending attempt (obviously it will fail since you did not approve your IP yet). GMail policy is to block all suspicious sending requests, so you have to explicitly approve your IP. 

For Outlook365 you have to create a SMTP-Relay connector like it is described here
http://technet.microsoft.com/en-us/library/dn554323.aspx
and allow your IP address sending to any domains.


5. Create a script to send all emails out

Once you are sure you are getting test emails via eitehr GMail or Outlook365, write a script which takes CSV with users data (the variable fields in the above email template), replaces them with the users data and then sends email by email.

Here is a sample script which replaces template' values and then sends an email out:

#!/bin/bash
TMP_FILE=/tmp/e.tmp

while IFS=, read email user link mgr;
do
        cat $2 | sed "s/__EMAIL__/$email/g" > $TMP_FILE
        sed -i "s/__USER__/$user/g" $TMP_FILE
        sed -i "s/__LINK__/$link/g" $TMP_FILE
        sed -i "s/__ACCOUNT_MANAGER__/$mgr/g" $TMP_FILE
#cat /tmp/e.tmp
        echo "Sending message..."
        ssmtp -v $email < $TMP_FILE
        echo "Message has been sent, now sleeping for 5 seconds..."
        sleep 5s
done < $1

6. Run the script

/tmp/send_emails.sh /tmp/users.csv /tmp/email.txt > /tmp/emails.log 2>&1; echo "Emails sending has been completed!"

It is supposed that users.csv is in the following format:

email, user name, link, account manager
email, user name, link, account manager
email, user name, link, account manager
...
Your emails are on their way out, good luck!