Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/iws8/html/indem/
Upload File :
Current File : /var/www/html/mmishra/iws8/html/indem/mail_alias.inc

<?php
  //if (!$_REQUEST["uid"]) header("location: applicants.php");
?>
<html>
<head><title>IIITA Mail Alias</title>
<link href="h.css" rel="stylesheet" type="text/css">
<style>
#alert{
  font-family: tahoma;
  color: orange;
  font-weight: bold;
  font-size: bigger;
} 
</style>
</head><body><center> 
<font size=+1>INDIAN INSTITUTE OF INFORMATION TECHNOLOGY, ALLAHABAD</font><br>
<b>Mail-alias Registration Form</b><br></center>
<a href='http://indem.iiita.ac.in'>Back</a><hr>
<?php
include "auth.php";
include "html.php";

$submit = $_POST["submit"];
$uid = $_POST["uid"];
$passwd = $_POST["passwd"];
$source_ip = $_SERVER["REMOTE_ADDR"];
$dated = date("Y-m-d H:i:s");
$mailalias = $_POST["mailalias"];
$forward = $_POST["forward"];
$mobile = $_POST["mobile"];
$postaladdress = $_POST["postaladdress"];
$labeleduri = $_POST["labeleduri"];
$url = $_REQUEST["url"];

if ($submit && $uid){
  $ds = ldap_connect("ldap.iiita.ac.in");  // must be a valid LDAP server!
  $user = authenticate($uid, $passwd);
  if ($user == "FAIL"){
    echo "<b id='alert'>Invalid</b> login... Try again but not again & again ...<br>";
    login($uid, $passwd);
    exit;
  }
  $z = ldap_bind($ds);
  $a = ldap_search($ds, "dc=iiita,dc=ac,dc=in", "uid=$uid");
  $b = ldap_get_entries($ds, $a);
  $dn = $b[0]["dn"];
  $r = ldap_bind($ds, $dn, $passwd);
  if ($r){
    $q = ldap_search($ds, "dc=iiita,dc=ac,dc=in", "(&(uid=$uid)(objectclass=posixAccount))");
    $info = ldap_get_entries($ds, $q);
    if ($info["count"] > 0){
      $uid1 = $info[0]["uid"][0];
      $cn1 = strtoupper($info[0]["cn"][0]);
      $name1 = ucwords(strtolower(strtr($info[0]["gecos"][0],"-"," ")));
      $givenname1 = $info[0]["givenName"][0];
      $sn1 = $info[0]["sn"][0];
      if (strpos($name1, " ")){
        $fullname = explode(" ", $name1);
        if ($fullname){
          if ($fullname[0]) $givenname1 = $fullname[0];
          if ($fullname[2]) $sn1 = $fullname[2];
          if (!$sn1) $givenname1 = $fullname[1];
        }else{
          $givenname1 = $info[0]["givenName"][0];
          $sn1 = $info[0]["sn"][0];
        }
      }
      $mail1 = $info[0]["mail"][0];
      $mailalias1 = $info[0]["mailalternateaddress"][0];
      $forward1 = $info[0]["mailforwardingaddress"][0];
      $mobile1 = $info[0]["mobile"][0];
      $postaladdress1 = $info[0]["postaladdress"][0];
      $labeleduri1 = $info[0]["labeleduri"][0];
      if ($submit == "SUBMIT"){
        $mailalias = htmlsafe($mailalias);
        $forward = htmlsafe($forward);
        $mobile = htmlsafe($mobile);
        $postaladdress = htmlsafe($postaladdress);
        $labeleduri = htmlsafe($labeleduri);
        if (strpos($labeleduri,"iiita.ac.in")) $labeleduri = "http://profile.iiita.ac.in/$uid1";
        $dup = ldap_search($ds, "dc=iiita,dc=ac,dc=in", "(&(mailAlternateAddress=$mailalias)(objectclass=posixAccount))");
        $dupmail = ldap_get_entries($ds, $dup);
        if ($dupmail["count"] > 0 && $uid1 <> $dupmail[0]["uid"][0]){
          echo "Mailalias is <b id='alert'>NOT Available</b>. Used by " . $dupmail[0]["mail"][0] . ". Try other.<br>";
          ldapform($uid1,$passwd,$name1,$mail1,$mailalias,$forward,$mobile,$postaladdress,$labeleduri);
        }else{
          if (!strpos($mailalias, "iiita.ac.in")){
            echo "Mailalias must be of <b id='alert'>IIITA mail server</b> only. Try other.<br>";
            ldapform($uid1,$passwd,$name1,$mail1,$mailalias,$forward,$mobile,$postaladdress,$labeleduri);
            exit;
          }
          if (strpos($forward, "iiita.ac.in")){
            echo "Forwarding address must be <b id='alert'>External Email</b> only. Try other.<br>";
            ldapform($uid1,$passwd,$name1,$mail1,$mailalias,$forward,$mobile,$postaladdress,$labeleduri);
            exit;
          }

          $bd = ldap_bind($ds, "cn=Manager,dc=iiita,dc=ac,dc=in","aksr2it");//$dn, $passwd);
          $info0["mailAlternateAddress"] = array();
          $info0["mailForwardingAddress"] = array();
          $info0["displayName"] = array();
          $r = @ldap_mod_del($ds, $dn, $info0);

          $info1["cn"][0] = $cn1;
          $info1["gecos"][0] = $name1;
          if ($givenname1) $info1["givenName"][0] = $givenname1;
          if ($sn1) $info1["sn"][0] = $sn1;
          if ($mailalias && !strpos($dn, "Alumni")) $info1["mailAlternateAddress"][0] = "$mailalias";
          if ($forward) $info1["mailForwardingAddress"][0] = "$forward";
          if ($mobile) $info1["mobile"][0] = "$mobile";
          if ($postaladdress) $info1["postalAddress"][0] = "$postaladdress";
          if ($labeleduri) $info1["labeledURI"][0] = "$labeleduri";
          $r = ldap_modify($ds, $dn, $info1);

          echo "Thanks <b id='alert'>$name1!</b> Mail-alias set successfully.<br>";
          ldapform($uid1,$passwd,$name1,$mail1,$mailalias,$forward,$mobile,$postaladdress,$labeleduri);
        }
      }else{
        ldapform($uid1,$passwd,$name1,$mail1,$mailalias1,$forward1,$mobile1,$postaladdress1,$labeleduri1);
      }
    }
  }
  ldap_close($ds);
}else{
  login($uid, $passwd);
}

function login($uid, $passwd){
  echo "<b>LDAP Information</b>
       <form method='post' action='" . $_SERVER["PHP_SELF"] . "'>
       <table class=normal border='0' bgcolor='white' cellspacing='0' width='100%'>
       <tr><td>Login ID *</td><td><input type='text' name='uid' value='$uid'></td></tr>
       <tr><td>Password *</td><td><input type='password' name='passwd' value='$passwd'></td></tr>
       <tr><td></td><td><input type='submit' name='submit' value='LOGIN'></td></tr>
       </table></form>Login to authenticate yourself.<br><br>
       <b><center>INDEM@IIITA</center></b>";
  return;
}

function ldapform($uid, $passwd, $name, $mail, $mailalias, $forward, $mobile, $postaladdress, $labeleduri){
  echo "<b>LDAP Information</b>
       <form method='post' action='" . $_SERVER["PHP_SELF"] . "'>
       <table class=normal border='0' bgcolor='white' cellspacing='0' width='100%'>
       <tr><td>Login ID *</td><td><input type='text' name='uid' value='$uid'></td></tr>
       <tr><td>Password *<br>&nbsp;</td><td><input type='password' name='passwd' value='$passwd'><br>&nbsp;</td></tr>
       <tr valign='top'><td>Full Name</td><td><b>$name</b></td></tr>
       <tr valign='top'><td>Mail Address</td><td><b>$mail</b></td></tr>
       <tr valign='top'><td>Mail-alias</td><td><input type='text' name='mailalias' value='$mailalias' size='40'> must be of IIITA mail server with @iiita.ac.in or @mba.iiita.ac.in etc.</td></tr>
       <tr valign='top'><td>Forwarding Address</td><td><input type='text' name='forward' value='$forward' size='40'> must be external email, mainly for ALUMNAE but other may also set</td></tr>
       <tr valign='top'><td>Contact No.</td><td><input type='text' name='mobile' value='$mobile' size='40'></td></tr>
       <tr valign='top'><td>Postal Address</td><td><textarea name='postaladdress' rows=3 cols=50>$postaladdress</textarea></td></tr>
       <tr valign='top'><td>Homepage URL</td><td><input type='text' name='labeleduri' value='$labeleduri' size='40'> other than IIITA profile server URL (http://profile.iiita.ac.in/UID)</td></tr>
       <tr><td></td><td><input type='submit' name='submit' value='SUBMIT'></td></tr>
       </table></form>Edit information and press button to update.<br>";
  note();
  return;
}


function note(){
  echo "<ol>
      <li>Blank fields may cause login problem on IIITA mail server.</li>
      <li>Official mail address is not editable iand it will remain forever.</li>
      <li>Only one mail-alias is provisioned at present and it should contain part of fullname.</li>
      <li>Mail-alias of ALUMNI would be revoked at due course of time. So use official address.</li>
      <li>Mail forwarding address is must for ALUMNI. If not set mail would be discarded.</li>
      <li>Contact no. is useful in communication when mail is not accessible.</li>
      <li>Homepage may be any url but could not be garbage.</li>
      </ol><br><br>
      <b><center>INDEM@IIITA</center></b>";
  return;
}
?>
</body></html>