Friday, January 29, 2016

Migrating Mail Server from old server to new server

Postfix Mail Server Migration from old server to new server
***************************************************
First of all we will archive all existing mail userid and password.

old_server: 192.168.1.76
#########################

export UGIDLIMIT=500
#create a folder where we will store all existing mail,userid and their password. 
mkdir -p /root/migrate
cd /root/migrate

awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/passwd > /root/passfile/passwd.mig
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534)' /etc/group > /root/passfile/group.mig
awk -v LIMIT=$UGIDLIMIT -F: '($3>=LIMIT) && ($3!=65534) {print $1}' /etc/passwd | tee - |egrep -f - /etc/shadow > /root/passfile/shadow.mig
cp /etc/gshadow /root/passfile/gshadow.mig

tar -zcvpf /root/migrate/home.tar.gz /home
tar -zcvpf /root/migrate/mail.tar.gz /var/spool/mail

##########################################

After that the migrate folder will be copied to New server. We will configure postfix in new server.

new_server: 192.168.1.98
#########################################


export UGIDLIMIT=500
mkdir -p /root/backup
cd /root/backup
scp 192.168.1.76:/root/migrate/* .
cat passwd.mig >> /etc/passwd
cat group.mig >> /etc/group
cat shadow.mig >> /etc/shadow
cp gshadow.mig /etc/gshadow
cd /
tar -zxvf /root/backup/home.tar.gz
tar -zxvf /root/backup/mail.tar.gz



PPTP VPN Configuration in Ubuntu and Redhat 6/7 with web console (html and php)

First of all we need to configure VPN. After that we will create a web console by which user or client username and password will be created.  So  After Configuring yum

1. For Redhat 

#yum -y install pptpd*

For Ubuntu( We must update apt through internet)

#sudo su
 #apt-get install pptpd


2. Add we have to append or edit these three lines below in the file /etc/pptpd.conf 
 

       #vi /etc/pptpd.conf
 
       localip 192.168.1.242      ### LAN IP
       localip 203.76.98.155      ### WAN IP
       remote ip 172.16.255.1-20  ### IP range for client


3. We will add client username,protocol,password and client IP to /etc/ppp/chap.secrets file 

 
      #vi /etc/ppp/chap.secrets

      #username       pptpd password ip
      branch1         pptpd vpn1    172.16.255.1
      branch2         pptpd vpn2    172.16.255.2
 
4. If we want to set dns for client then we need to edit the file /etc/ppp/pptpd-options and Uncomment the ms-dns and add google like below or OpenDNS 
  
     # vi /etc/ppp/pptpd-options
 
          ms-dns 8.8.8.8
          ms-dns 8.8.4.4

5. for IPv4 forwardig we need to  Change /etc/sysctl.conf file, add forward rule below

     # vi /etc/sysctl.conf

          ##Uncomment the line and change 0 to 1
 
     net.ipv4.ip_forward=1
 
6. Now we will make a web form for taking username, Password and ip for client. 
<html>
 <body> 
  <div><table>
  <form action=2nd.php method=post>
   <tr><td width=20px></td><td>UserName:</td><td> <input type=text, name=n></td></tr>
   <tr><td></td><td>Password:</td><td><input type=password, name=p></td></tr>
   <tr><td></td><td>IP Addss:</td><td><table><tr><td>172.16.255.</td><td><input 
   type=text, name=ip size=6 placeholder="40-50" maxlength=2></td></tr></table>
   </td></tr>
   <tr><td></td><td></td><td></td></tr>
   <tr><td></td><td></td><td><input type=submit value=create></td></tr>
  </form></table>
  <br><br>
  </div>
 </body>
</html> 
 
7. After that  we will make a php script containing shell script which will sent
 username,password and ip to the /etc/ppp/chap-secret file
 
<?php
  //session_start(); 
  //$abc=$_SESSION['username']; 
  $name=$_POST['n']; 
  $pass=$_POST['p']; 
  $ip=$_POST['ip'];

if(isset($name,$pass,$ip))
  {
   include ('header.php');
   include ('menu.php');
   echo  shell_exec("echo '$name pptpd $pass 172.16.255.$ip'>>/etc/ppp/chap-secrets");
   echo shell_exec("echo ''>>/var/www/html/vpn/log");
   echo shell_exec("echo '####" . date("Y/m/d H:i:s") . "###'>>/var/www/html/vpn/log");
   echo shell_exec("echo '$name pptpd $pass 172.16.255.$ip created by $abc'>>/var/www/html/vpn/log");
   echo "<b>$name user is Created</b><br>";
   echo "<br>";
   echo "<b><pre>&nbsp&nbspAdded Users are :</b><br>";
   echo shell_exec("cat /etc/ppp/chap-secrets");
   echo "</pre>";
   include ('footer.php');
  }
 else
  {
 include ('home.php'); 
  } 
?>
 
For displaying Connected user we can use this script
 
<?php
include ('header.php');
include ('menu.php');
echo "<br><br><b>Existing Users Are :</b>";
echo "<br>";
echo "<br>";
echo shell_exec("cat /etc/ppp/chap-secrets");
echo "<br>";
include ('footer.php');
?>
  
 
Lets play