Sunday, November 27, 2016

Posted in My Programming Skill

OwnCloud 8 installation on Ubuntu 14.04


For the people who don't know, OwnCloud is a free and open-source software which enables you to create a private “file-hosting” cloud. Owncloud is made by PHP and backend database MySQL (MariaDB), SQLLite or PostgreSQL. OwnCloud also enables you to easily view and sync address book, calendar events, tasks and bookmarks. People access it via the easy web interface or install OwnCloud client on your machine.

Here step by step installation of OwnCloud 8 on Ubuntu 14.04.

To install OwnCloud on your system, go through following steps:

Step 1. First of all log in to your server as root and make sure that all packages are up to date.


# apt-get update
# apt-get upgrade
 
Step 2. Instal Apache web server on your Ubuntu 14.04 LTS if it is not already installed.

# apt-get install apache2

Step 3. Next, install PHP on your server.

# apt-get install php5 php5-mysql

Once the installation is done install the following PHP modules required by OwnCloud:

# apt-get install php5-gd php5-json php5-curl php5-intl php5-mcrypt php5-imag

Step 4. Install MySQL database server.

# apt-get install mysql-server

By default, MySQL is not very much secured. You can secure MySQL using the mysql_secure_installation script. you should read and follow each steps carefully which will set root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MySQL.

# mysql_secure_installation

Step 5. Create a new MySQL database for OwnCloud using the following commands.

#mysql -u root -p
Enter password:
mysql>
CREATE USER 'ownclouduser'@'localhost' IDENTIFIED BY 'YOURPASSWORD';
mysql> CREATE DATABASE ownclouddb;
mysql>
GRANT ALL ON ownclouddb.* TO 'ownclouduser'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql>
exit

Step 6. Installing Owncloud 8.

To download the latest stable release of OwnCloud on your server (at the time of version 8.0.0).

# wget https://download.owncloud.org/community/owncloud-8.0.0.tar.bz2
# tar -xvf owncloud-8.0.0.tar.bz2 -C /var/www/html/

Set the directory permissions:

# chown www-data:www-data -R /var/www/html/owncloud/

Step 7. Configuring Apache for OwnCloud.

While configuring Apache web server, it is recommended that you to enable .htaccess to get a enhanced security features, by default .htaccess is disabled in Apache server. To enable it, open your virtual host file and make AllowOverride is set to All.For example, here i used external config file instead of modifying main file.

### nano /etc/apache2/sites-available/owncloud.conf

<IfModule mod_alias.c>
Alias /owncloud /var/www/html/owncloud
</IfModule>
<Directory “/var/www/html/owncloud”>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>

Remember to restart all services related to Apache server.

# service apache2 restart

Step 8. Access OwnCloud application.

Navigate to http://your-domain.com/ and follow the easy instructions. Enter username and password for the administrator user account, click on the ‘Advanced options’ hyperlink and enter the data directory (or leave the default setting), then enter database username, database password, database name, host (localhost) and click ‘Finish setup’.


Saturday, November 26, 2016

Posted in My Programming Skill

Virtualization on Ubuntu using KVM

KVM is stand for  Kernel-based Virtual Machine which turns linux kernel into hypervisor. Hypervisor is nothing but the virtual machine manager program.

To create virtualization on Ubuntu using KVM use the following step

1) Check whether CPU has hardware virtualization support.

KVM only works if your CPU has hardware virtualization support – either Intel VT-x or AMD-V. To determine whether your CPU includes these features, run the following command:

#sudo grep -c "svm\|vmx" /proc/cpuinfo


A 0 indicates that your CPU doesn’t support hardware virtualization, while a 1 or more indicates that it does.

2) Install KVM and supporting packages.

Virt-Manager is a graphical application for managing your virtual machines.you can use the kvm command directly, but libvirt and Virt-Manager simplify the process.

#sudo apt-get install qemu-kvm libvirt-bin bridge-utils virt-manager

3) Create User.

Only the root user and users in the libvirtd group have permission to use KVM virtual machines. Run the following command to add your user account to the libvirtd group:

#sudo adduser tsec
#sudo adduser tsec libvirtd

After running this command, log out and log back in as tsec

4) Check whether everything is working correctly.

Run following command after logging back in as tsec and you should see an empty list of virtual machines. This indicates that everything is working correctly.

#virsh -c qemu:///system list


5)Open Virtual Machine Manager application and Create Virtual Machine

#virt-manager

6) Create and run Virtual Machines





7) # ls /var/lib/libvirt/images/
ubuntu-vm.img

8) # ls /var/lib/libvirt/quem
dump save snapshot ubuntu-vm.monitor


9) # apt-get install virt-viewer virt-top virt-what

10) # virsh list --all
Posted in My Programming Skill

Online Bill Payment using JAVA

This is the simple code for online bill payment portal using java. To run this code successfully, you will need itext.jar library file for pdf which is used in this code for pdf creation.
you can download this file from here.
extract this zip file in java >> bin folder and run following code.

=================  OnlineBillPay.java     ================ 
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class OnlineBillPay extends JFrame
{
JButton b1,b2;
JLabel l1,l2,l3,l4,l5;
TextField jtf1,jtf2;
    public OnlineBillPay()
    {
    setTitle("BillPay...Online Bill Payment Portal");
    setSize(385,310);
    setLocationRelativeTo(null);
        setResizable(false);
    setVisible(true);
    setLayout(new FlowLayout(FlowLayout.CENTER,100,10));
        Font f = new Font("Times New Roman",Font.BOLD,60);
    l1=new JLabel("PayBill\n");
        l1.setHorizontalAlignment(SwingConstants.CENTER);
        l1.setFont(f);
        l2 = new JLabel("Pay your Telephone Bill Online here...");
        l2.setForeground(Color.red);
    b1=new JButton("LOGIN");
    add(l1);
        add(l2);
        jtf1 = new TextField(10);jtf2 = new TextField(10);
        jtf2.setEchoChar('*');
        l3 = new JLabel("LOGIN_ID:");l4 = new JLabel("PASSWORD:");
        l5 = new JLabel("Click Below to Pay without Login");
        b2 = new JButton("PayDirect");
        add(l3);add(jtf1);add(l4);add(jtf2);add(b1);add(l5);add(b2);
    setSize(385,310);setSize(385,310);   
        b1.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae) {
                String id = jtf1.getText();
                String pwd = jtf2.getText();
                if(id.equals("Admin") && pwd.equals("admin")) {
                    dispose();
                    new AnotherJFrame();
                }
                else {
                    jtf1.setText(null);jtf2.setText(null);
                    JOptionPane.showMessageDialog(rootPane, "Wrong LOGIN_ID and PASSWORD Combination", "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
        });  
        b2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent ae) {
                dispose();
                new Payment();
            }
        });  
       }
    public static void main(String args[])
    {
    new OnlineBillPay();
    }
}

===================  Payment.java  ===================

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Payment extends JFrame implements ActionListener
{
    TextField t1,t2,t3,t4,t5,t6,t7;
    Demo d;
    public Payment()
    {
        super("Payment Portal");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(700,500);
        setLocationRelativeTo(null);
        setResizable(true);
        setVisible(true);
        JLabel l0 = new JLabel("Payment Details");
        Font f = new Font("Cambria",Font.BOLD,40);
        l0.setFont(f);
        JLabel l00 = new JLabel("       ");
        setLayout(new GridLayout(11,2));
        Choice type = new Choice();
        type.add("VISA");type.add("MasterCard");type.add("Rupay");
        JLabel l1 = new JLabel("Your Name :");
        JLabel l2 = new JLabel("Email Id :");
        JLabel l3 = new JLabel("Telephone Number :");
        JLabel l4 = new JLabel("Credit/Debit Card Number :");
        JLabel l5 = new JLabel("CVC Number :");
        JLabel l6 = new JLabel("Pin Number :");
        JLabel l7 = new JLabel("Card Type :");
        JLabel l9 = new JLabel("Amount :");
        JLabel l8 = new JLabel("NOTE* : All Fields are Mandotory");
        JLabel l10 = new JLabel("         ");
        Font f1 = new Font("Cambria",Font.BOLD,15);
        l8.setFont(f1);
        l8.setForeground(Color.red);
        t1 = new TextField(20);    t2 = new TextField(20);    t3 = new TextField(20);
        t4 = new TextField(20);    t5 = new TextField(20);    t6 = new TextField(20);
    t7 = new TextField(20);
        JButton jb1 = new JButton("SUBMIT"); JButton jb2 = new JButton("RESET");                add(l0);add(l00);add(l1);add(t1);add(l2);add(t2);add(l3);add(t3);add(l4);add(t4);add(l7);add(type);add(l5);
    add(t5);add(l6);add(t6);add(l9);add(t7);add(l8);add(l10);add(jb1);add(jb2);
    jb1.addActionListener(this);       jb2.addActionListener(this);
    }
    public void actionPerformed(ActionEvent ae)
    {
        String s = ae.getActionCommand();
        if(s.equals("SUBMIT"))
        {
            String s1 = t1.getText();String s2 = t2.getText();String s3 = t3.getText();
            String s4 = t4.getText();String s5 = t5.getText();String s6 = t6.getText();
            String s7 = t7.getText();
if(s1.length() == 0 || s2.length() == 0 || s3.length() == 0 || s4.length() == 0 || s5.length() == 0 || s6.length() == 0 || s7.length() == 0)
{
    JOptionPane.showMessageDialog(rootPane,"Please Fill all the Fields","Error",JOptionPane.ERROR_MESSAGE);
}
            else {
                d = new Receipt(s1,s2,s3,s4);
                this.setVisible(false);
            }
        }
        if(s.equals("RESET")) {
            t1.setText("");    t2.setText("");    t3.setText("");    t4.setText("");
            t5.setText("");    t6.setText("");    t7.setText("");
        }
    }
    public static void main(String args[]) {
        new Payment();
    }
}

=================   Receipt.java  ===================

import java.awt.*;
import java.awt.event.*;
import javax.swing.*; 
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import java.io.*;
public class Receipt extends JFrame implements ActionListener
{
    JLabel l1,l2,l3,l4,l5,l6,l7,l8;
        public Receipt(String x, String y, String z, String w)
    {
        super("Receipt");
        setVisible(true);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(600,400);
            setLocationRelativeTo(null);
            setResizable(false);
        setLayout(new GridLayout(5,1));
            l1 = new JLabel("Name: ");
            l2 = new JLabel(x);
                l3 = new JLabel("EMAIL ID: ");
            l4 = new JLabel(y);
            l5 = new JLabel("Telephone Number : ");
            l6 = new JLabel(z);
                l7 = new JLabel("Amount Received");
                l8 = new JLabel(w);
            add(l1);add(l2);add(l3);add(l4);add(l5);add(l6);add(l7);add(l8);
            JButton jb1 = new JButton("SAVE");
            JButton jb2 = new JButton("OK");
            add(jb1);add(jb2);
        jb1.addActionListener(this);
        jb2.addActionListener(this);
    }
    public void actionPerformed(ActionEvent ae)
    {
            String s = ae.getActionCommand();
            if(s.equals("OK"))
            System.exit(0);
            else {
                try {
                    Document document = new Document();
                    try {
                        PdfWriter.getInstance(document, new FileOutputStream ("sample.pdf"));
                    } catch (FileNotFoundException ex) {
                        System.out.println("File Can not be created");
                    }
                    document.open();
                    document.add(new Paragraph(".........................Payment Receipt........................."));
                    document.add(new Paragraph(l1.getText()+"  "+l2.getText()));
                    document.add(new Paragraph(l3.getText()+"  "+l4.getText()));
                    document.add(new Paragraph(l5.getText()+"  "+l6.getText()));
                    document.add(new Paragraph(l7.getText()+"  "+l8.getText()));
                    document.close();
                    this.setVisible(false);
                } catch (DocumentException ex) {
                    System.out.println("File Can not be Opened");
                }
            }
    }
}

===================OUTPUT===================






 



 

 


    Translate

    Protected by Copyscape