Monday, 18 May 2015

Check SSL Certificate Expiration Date from the terminal/putty

Generally user want to check SSL certificate expiry date on the server and don't have an idea that.... is there any way to check this via putty, with the help of some commands. The answer is yes!


Explaining below few useful commands which would be very helpful in case you want to check SSL related on your server.


This is also useful when you have server in cluster. Lets take example of 4 weblogic application/web server and they are in cluster so that another can provide resilience in case one goes down.

Now if you have 4 different server obviously you should be having separate SSL certificate installed in each box. Below command can be used to check the SSL

Check when an SSL certificate expires from the Linux command line :
echo | openssl s_client -connect site:port 2>/dev/null | openssl x509 -noout -dates

Let's check when the SSL certificate of flipkart.com expires :

echo | openssl s_client -connect flipkart.com:443 2>/dev/null | openssl x509 -noout -dates
notBefore=Mar 30 15:45:41 2015 GMT
notAfter=Apr  5 04:55:40 2017 GMT

You can also extract additional information from SSL

MD5 fingerprint


Command:- 
echo | openssl s_client -connect flipkart.com:443 2>/dev/null | openssl x509 -noout -fingerprint
Result:-
SHA1 Fingerprint=9B:87:8F:F9:87:F1:74:40:68:19:3D:A9:CD:69:C1:57:33:B7:5F:03

Hash value

Command:- 
echo | openssl s_client -connect flipkart.com:443 2>/dev/null | openssl x509 -noout -hash

Result:-
139b0a9c

For what dates is the certificate valid?

Command:-
echo | openssl s_client -connect flipkart.com:443 2>/dev/null | openssl x509 -noout -dates

Result:-
notBefore=Mar 30 15:45:41 2015 GMT
notAfter=Apr  5 04:55:40 2017 GMT

Below is much more defined

Command:-
echo | openssl s_client -connect flipkart.com:443 2>/dev/null | openssl x509 -noout -issuer -subject -dates

Result:-
issuer= /C=US/O=Entrust, Inc./OU=See www.entrust.net/legal-terms/OU=(c) 2014 Entrust, Inc. - for authorized use only/CN=Entrust Certification Authority - L1M
subject= /C=IN/ST=Karnataka/L=Bangalore/1.3.6.1.4.1.311.60.2.1.3=IN/O=Flipkart Internet Private Limited/businessCategory=Private Organization/OU=Tech/serialNumber=066107/CN=www.flipkart.com
notBefore=Mar 30 15:45:41 2015 GMT
notAfter=Apr  5 04:55:40 2017 GMT

Sunday, 17 May 2015

Difference between Abstraction, Information hiding, Encapsulation

Difference between Abstraction, Information hiding, Encapsulation


(All citations are taken from the article mentioned above). Posting this here as I found useful and this may save your time of search in various websites.
Abstraction:
"One point of confusion regarding abstraction is its use as both process and an entity. Abstraction, as a process, denotes the extracting of the essential details about an item, or a group of items, while ignoring the inessential details. Abstraction, as an entity, denotes a model, a view, or some other focused representation for an actual item."
Information Hiding:
"Its interface or definition was chosen to reveal as little as possible about its inner workings." — [Parnas, 1972b]
"Abstraction can be […] used as a technique for identifying which information should be hidden."
"Confusion can occur when people fail to distinguish between the hiding of information, and a technique (e.g., abstraction) that is used to help identify which information is to be hidden."
Encapsulation:
"It […] refers to building a capsule, in the case a conceptual barrier, around some collection of things." — [Wirfs-Brock et al, 1990]
"As a process, encapsulation means the act of enclosing one or more items within a […] container. Encapsulation, as an entity, refers to a package or an enclosure that holds (contains, encloses) one or more items."
"If encapsulation was 'the same thing as information hiding,' then one might make the argument that 'everything that was encapsulated was also hidden.' This is not obviously not true."
Conclusion:
"Abstraction, information hiding, and encapsulation are very different, but highly-related, concepts. One could argue that abstraction is a technique that help us identify which specific information should be visible, and which information should be hidden. Encapsulation is then the technique for packaging the information in such a way as to hide what should be hidden, and make visible what is intended to be visible."



Go to the source! Grady Booch says (in Object Oriented Analysis and Design, page 49, second edition):
Abstraction and encapsulation are complementary concepts: abstraction focuses on the observable behavior of an object... encapsulation focuses upon the implementation that gives rise to this behavior... encapsulation is most often achieved through information hiding, which is the process of hiding all of the secrets of object that do not contribute to its essential characteristics.
In other words: abstraction = the object externally; encapsulation (achieved through information hiding) = the object internally



Saturday, 16 May 2015

how to install Drupal in ubuntu

Drupal is very popular and easy to use open-source CMS (content management system ) written in PHP and distributed under the GNU General Public License.


To install Drupal in ubuntu following steps to be followed. Its very easy and can be done easily.

Assumption:-
php, Apache, MySQL are installed and configured. This will be explained in another post if you are not aware of. Don’t worry it's easy.

You can use following commands to check if your system is up to date. Though these are not essential yet you can use if want

sudo apt-get update
sudo apt-get upgrade

Install Drush:
apt-get install drush php-console-table
Ubuntu 14.04 comes with Drush version 5.10.0. If you like to install and use the latest release of Drush, it can be installed via the custom PEAR channel using the following commands:

pear channel-discover pear.drush.org
pear install drush/drush


Following commands can be used to check if you have successfully installed the drus version.

drush version
Drush Version   :  6.2.0


Download the latest stable version of Drupal to the ‘/var/www/html/’ directory on your server:
cd /var/www/html/
drush dl drupal
mv /var/www/html/drupal-7.28 /var/www/html/drupal


Create a new MySQL database for Drupal on your server:
mysql -u root -p
mysql> CREATE DATABASE drupaldb;
mysql> GRANT ALL PRIVILEGES ON drupaldb.* TO 'drupaluser'@'localhost' IDENTIFIED BY 'your-password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> quit


Create a new virtual host directive in Apache. For example, create a new Apache configuration file ‘drupal.conf':
vi /etc/apache2/sites-available/drupal.conf
ln -s /etc/apache2/sites-available/drupal.conf /etc/apache2/sites-enabled/drupal.conf


then, add the following lines:

<VirtualHost *:80>
  ServerAdmin admin@your-domain.com
  DocumentRoot /var/www/html/drupal/
  ServerName your-domain.com
  ServerAlias www.your-domain.com
     <Directory /var/www/html/drupal/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
Order allow,deny
        allow from all
     </Directory>
  ErrorLog /var/log/apache2/your-domain.com-error_log
  CustomLog /var/log/apache2/your-domain.com-access_log common
</VirtualHost>
Restart the Apache web server for the changes to take effect:
service apache2 restart



Make the document root and the Drupal files and directories in it writable by the Apache service which is running as user ‘www-data’ and group ‘www-data’ by executing the following command:
chown www-data:www-data -R /var/www/html/drupal/


Thats it you can open your browser by simply typing

http://localhost/drupal




Below are the terminal logs that will be helpful. Attaching for reference
Please note if you see permission denied. Please make sure you are logged in as super user (use sudo command in from of all mentioned command as above) and for some paths/command it should be as root user




oyeweb@oyeweb-Latitude-3540:~$ apt-get install drush php-console-table
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
oyeweb@oyeweb-Latitude-3540:~$ sudo apt-get install drush php-console-table
[sudo] password for oyeweb:
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
 account-plugin-windows-live libupstart1
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
 php-pear
Suggested packages:
 git drupal7 php5-dev
Recommended packages:
 php-console-color
The following NEW packages will be installed:
 drush php-console-table php-pear
0 upgraded, 3 newly installed, 0 to remove and 3 not upgraded.
Need to get 634 kB of archives.
After this operation, 3,790 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu/ trusty-updates/main php-pear all 5.5.9+dfsg-1ubuntu4.9 [267 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu/ trusty/universe php-console-table all 1.1.6-1 [14.7 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu/ trusty/universe drush all 5.10.0-2 [353 kB]
Fetched 634 kB in 4s (143 kB/s)
Selecting previously unselected package php-pear.
(Reading database ... 255377 files and directories currently installed.)
Preparing to unpack .../php-pear_5.5.9+dfsg-1ubuntu4.9_all.deb ...
Unpacking php-pear (5.5.9+dfsg-1ubuntu4.9) ...
Selecting previously unselected package php-console-table.
Preparing to unpack .../php-console-table_1.1.6-1_all.deb ...
Unpacking php-console-table (1.1.6-1) ...
Selecting previously unselected package drush.
Preparing to unpack .../drush_5.10.0-2_all.deb ...
Unpacking drush (5.10.0-2) ...
Processing triggers for doc-base (0.10.5) ...
Processing 1 added doc-base file...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up php-pear (5.5.9+dfsg-1ubuntu4.9) ...
Setting up php-console-table (1.1.6-1) ...
Setting up drush (5.10.0-2) ...
oyeweb@oyeweb-Latitude-3540:~$ drush version
drush version 5.10.0
oyeweb@oyeweb-Latitude-3540:~$ pear channel-discover pear.drush.org
could not create lock file: fopen(/usr/share/php/.lock): failed to open stream: Permission denied
oyeweb@oyeweb-Latitude-3540:~$ sudo pear channel-discover pear.drush.org
Adding Channel "pear.drush.org" succeeded
Discovery of channel "pear.drush.org" succeeded
oyeweb@oyeweb-Latitude-3540:~$ sudo pear install drush/drush
downloading drush-6.2.0.0.tgz ...
Starting to download drush-6.2.0.0.tgz (505,989 bytes)
.....................................................................................................done: 505,989 bytes
install ok: channel://pear.drush.org/drush-6.2.0.0
oyeweb@oyeweb-Latitude-3540:~$
oyeweb@oyeweb-Latitude-3540:~$
oyeweb@oyeweb-Latitude-3540:~$ drush version
Drush Version   :  6.2.0

oyeweb@oyeweb-Latitude-3540:~$ cd /var/www/html/
oyeweb@oyeweb-Latitude-3540:/var/www/html$ ls -ltr
total 12
-rw-r--r-- 1 root root 11510 May 16 08:28 index.html
oyeweb@oyeweb-Latitude-3540:/var/www/html$ drush dl drupal
Directory /var/www/html exists, but is not writable. Please check directory permissions.                                              [error]
Project drupal (7.37) could not be downloaded to /var/www/html/drupal-7.37.                                                           [error]
oyeweb@oyeweb-Latitude-3540:/var/www/html$ sudo drush dl drupal
Project drupal (7.37) downloaded to /var/www/html/drupal-7.37.                                                                        [success]
Project drupal contains:                                                                                                              [success]
- 3 profiles: testing, minimal, standard
- 4 themes: stark, seven, bartik, garland
- 47 modules: drupal_system_listing_incompatible_test, drupal_system_listing_compatible_test, taxonomy, image, menu, update, trigger,
options, number, text, field_sql_storage, list, field, toolbar, color, poll, user, contextual, simpletest, block, node, overlay,
dashboard, blog, profile, translation, php, book, comment, filter, syslog, openid, shortcut, search, path, dblog, tracker, rdf,
field_ui, system, contact, help, locale, aggregator, forum, statistics, file

oyeweb@oyeweb-Latitude-3540:/var/www/html$ ls -ltr
total 16
-rw-r--r-- 1 root root 11510 May 16 08:28 index.html
drwxr-xr-x 9 root root  4096 May 16 16:35 drupal-7.37
oyeweb@oyeweb-Latitude-3540:/var/www/html$ mv /var/www/html/drupal-7.37 /var/www/html/drupal
mv: cannot move ‘/var/www/html/drupal-7.37’ to ‘/var/www/html/drupal’: Permission denied
oyeweb@oyeweb-Latitude-3540:/var/www/html$ sudo mv /var/www/html/drupal-7.37 /var/www/html/drupal
oyeweb@oyeweb-Latitude-3540:/var/www/html$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.5.43-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE drupaldb;
Query OK, 1 row affected (0.08 sec)

mysql> GRANT ALL PRIVILEGES ON drupaldb.* TO 'drupaluser'@'localhost' IDENTIFIED BY 'your-password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.27 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.04 sec)

mysql> quit
Bye
oyeweb@oyeweb-Latitude-3540:/var/www/html$ vi /etc/apache2/sites-available/drupal.conf
oyeweb@oyeweb-Latitude-3540:/var/www/html$ cd /etc/apache2/sites-available/
oyeweb@oyeweb-Latitude-3540:/etc/apache2/sites-available$ ls -ltr
total 20
-rw-r--r-- 1 root root 6437 Jan  7  2014 default-ssl.conf
-rw-r--r-- 1 root root 1332 Jan  7  2014 000-default.conf
-rw-r--r-- 1 root root 1332 May 16 08:57 default
-rw-r--r-- 1 root root 1346 May 16 08:57 drupal
oyeweb@oyeweb-Latitude-3540:/etc/apache2/sites-available$ su
Password:
root@oyeweb-Latitude-3540:/etc/apache2/sites-available# ln -s /etc/apache2/sites-available/drupal.conf /etc/apache2/sites-enabled/drupal.conf
root@oyeweb-Latitude-3540:/etc/apache2/sites-available# ls -ltr
total 20
-rw-r--r-- 1 root root 6437 Jan  7  2014 default-ssl.conf
-rw-r--r-- 1 root root 1332 Jan  7  2014 000-default.conf
-rw-r--r-- 1 root root 1332 May 16 08:57 default
-rw-r--r-- 1 root root 1346 May 16 08:57 drupal
root@oyeweb-Latitude-3540:/etc/apache2/sites-available# vi drupal.conf
root@oyeweb-Latitude-3540:/etc/apache2/sites-available# ls -ltr
total 20
-rw-r--r-- 1 root root 6437 Jan  7  2014 default-ssl.conf
-rw-r--r-- 1 root root 1332 Jan  7  2014 000-default.conf
-rw-r--r-- 1 root root 1332 May 16 08:57 default
-rw-r--r-- 1 root root 1346 May 16 08:57 drupal
root@oyeweb-Latitude-3540:/etc/apache2/sites-available# touch drupal.conf
root@oyeweb-Latitude-3540:/etc/apache2/sites-available# ls -ltr
total 20
-rw-r--r-- 1 root root 6437 Jan  7  2014 default-ssl.conf
-rw-r--r-- 1 root root 1332 Jan  7  2014 000-default.conf
-rw-r--r-- 1 root root 1332 May 16 08:57 default
-rw-r--r-- 1 root root 1346 May 16 08:57 drupal
-rw-r--r-- 1 root root    0 May 16 16:40 drupal.conf
root@oyeweb-Latitude-3540:/etc/apache2/sites-available# vi drupal
root@oyeweb-Latitude-3540:/etc/apache2/sites-available# vi drupal.conf
root@oyeweb-Latitude-3540:/etc/apache2/sites-available# service apache2 restart
* Restarting web server apache2                                                                                                                 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
                                                                                                                                         [ OK ]
root@oyeweb-Latitude-3540:/etc/apache2/sites-available# chown www-data:www-data -R /var/www/html/drupal/
root@oyeweb-Latitude-3540:/etc/apache2/sites-available#