Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/iws8/html/iport/
Upload File :
Current File : /var/www/html/mmishra/iws8/html/iport/config.inc

<?php

function dbConnect($db) {
        $con = mysql_connect("localhost", "root", "irp2015");
        if (!$con) die('Could not connect: ' . mysql_error());
	mysql_select_db($db);
        return $con;
}

function localAuth($uid, $pwd) {
       	$role = 'user';
	if ($uid) {
		$rs = mysql_query("select * from webusers where userid='$uid'");
		if (mysql_num_rows($rs)) {
               		$o = mysql_fetch_object($rs);
               		$role = $o->role;
       		}
	}
        return $role;
}

function ldapAuth($uid, $pwd) {
	if ($uid && $pwd) {
		//$ds = ldap_connect("ldaps://172.31.1.41:636");
		if (!$ds) $ds = ldap_connect("ldap://172.31.1.41:389");
		ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
		$a = ldap_search($ds, "dc=iiita,dc=ac,dc=in", "uid=$uid");
		$b = ldap_get_entries($ds, $a);
		$dn = $b[0]["dn"];
		//******************************************************
		$flag = (ldap_bind($ds, $dn, $pwd) ? TRUE : FALSE);
		ldap_close($ds);
	} else
			$flag = FALSE;

	return $flag;
}

function checkEmail($email) {
	if (eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email)) {
		return FALSE;
	}
	list($Username, $Domain) = split("@",$email);
	if (getmxrr($Domain, $MXHost)) {
		return TRUE;
	} else {
		if (fsockopen($Domain, 25, $errno, $errstr, 30)) {
			return TRUE;
		} else {
			return FALSE;
		}
	}
}

function checkAbuser($message, $name, $email, $systemip) {
	$tbl = 'abusers';
	if (mysql_num_rows(mysql_query("select * from $tbl where systemip='$ip' or email='$email' or name='$name'"))) {
		return TRUE;
	} else {
		$abuses = array('nude','teen','www','url','sex','suck','fuck','xxx','pussy','penis','hotty','sexual','porn','movie');
		foreach ($abuses as $abuse) {
			if (stristr($message, $abuse)) {
				mysql_query("insert into $tbl(name,email,systemip,datecreation) values('$name','$email','$systemip',now())");
				return TRUE;
			}
		}
		return FALSE;
	}
}

function getIP() {
        //Just get the headers if we can or else use the SERVER global
        if ( function_exists( 'apache_request_headers' ) ) {
                $headers = apache_request_headers();
        } else {
                $headers = $_SERVER;
        }
        //Get the forwarded IP if it exists
        if ( array_key_exists( 'X-Forwarded-For', $headers ) && filter_var( $headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) {
                $the_ip = $headers['X-Forwarded-For'];
        } elseif ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $headers ) && filter_var( $headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 )) {
                $the_ip = $headers['HTTP_X_FORWARDED_FOR'];
        } else {
                $the_ip = filter_var( $_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 );
        }
        return $the_ip;

}

function ajax() {

	$str = "<script language=\"javascript\">
	function GetXmlHttpObject() {
        	var xmlHttp = null;
        	try {
                	// Firefox, Opera 8.0+, Safari
                	xmlHttp = new XMLHttpRequest();
        	} catch (e) {
                	// Internet Explorer
                	try {
                        	xmlHttp = new ActiveXObject(\"Msxml2.XMLHTTP\");
                	} catch (e) {
                        	xmlHttp = new ActiveXObject(\"Microsoft.XMLHTTP\");
                	}
        	}
        	return xmlHttp;
	}

	function showPage(uri, task, query) {
        	if (task.length < 1 || query.length < 3) {
                	document.getElementById('ajax').innerHTML='';
                	document.getElementById('ajax').style.visibility = 'hidden';
                	return;
        	} else
                	document.getElementById('ajax').style.visibility = 'visible';
        	xmlHttp=GetXmlHttpObject()
        	if (xmlHttp == null) {
                	alert ('Your browser does not support AJAX!');
                	return;
        	}
        	var url = uri; //+'?task='+task+'&query='+query;
        	alert(url);
        	xmlHttp.onreadystatechange = stateChanged;
        	xmlHttp.open('GET', url, true);
        	xmlHttp.send(null);
	}

	function stateChanged() {
        	if (xmlHttp.readyState==4) {
                	document.getElementById('ajax').innerHTML=xmlHttp.responseText;
        	}
	}
	</script>";

	return $str;
}

function autoMailer($emails, $subject, $body) {
	//SMTP needs accurate times, and the PHP time zone MUST be set
	//This should be done in your php.ini, but this is how to do it if you don't have access to that

	//extarct email addresses
	$emails1 = explode(',', $emails);
	
	//Create a new PHPMailer instance
	$mail = new PHPMailer();

	//Tell PHPMailer to use SMTP
	$mail->isSMTP();

	//Tell PHPMailer to use SMTP
	$mail->isHTML(true);

	//Set the hostname of the mail server
	$mail->Host = 'smtp.gmail.com';

	//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
	$mail->Port = 465;

	//Set the encryption system to use - ssl (deprecated) or tls
	$mail->SMTPSecure = 'ssl';

	//Whether to use SMTP authentication
	$mail->SMTPAuth = true;

	//Username to use for SMTP authentication - use full email address for gmail
	$mail->Username = "istore@iiita.ac.in";

	//Password to use for SMTP authentication
	$mail->Password = "irp@2015";

	//Set who the message is to be sent from
	$mail->setFrom('iport@iiita.ac.in', 'iPort@IIITA');

	//Set an alternative reply-to address
	$mail->addReplyTo('iport@iiita.ac.in', 'iPort@IIITA');

	//Set who the message is to be sent to
	$mail->addAddress('erp.support@iiita.ac.in', 'ERP Support');
	
	foreach ($emails1 as $em) {
		$mail->addCC($em, $em);
	}
	//$mail->addBCC('mmishra@iiita.ac.in', 'Mmishra');

	//Add attachement
	//if ($attachment) $mail->addAttachment($attachment, 'Transport Schedule');
	
	//Set the subject line
	$mail->Subject = $subject;

	$mail->Body = $body . "<br><br>--<br>iPort@IIITA<br><br>
	Login at https://iport.iiita.ac.in using LDAP credentials for updated information on transport services.<br><br>
	(Automailer)";
	$mail->WordWrap = 75;

	//send the message, check for errors
	if ($mail->send()) {
		return "OK";
	} else {
		return "XX";
	}
}

function upload($dir='uploads') {
	$maxsize = 90998860800;
	$uploadfile = strtolower(basename($_FILES['userfile']['name']));
	$tempfile = $_FILES['userfile']['tmp_name'];
	$filesize = $_FILES["userfile"]["size"];
	$uploadfile = str_replace(" ","-",$uploadfile);
	$uploadfile = str_replace("'","",$uploadfile);
	$uploadfile = str_replace('"',"",$uploadfile);
	$uploadfile = str_replace('(',"",$uploadfile);
	$uploadfile = strtolower(str_replace(')',"",$uploadfile));
	if ($uploadfile && $filesize < $maxsize) {
	$filename = explode(".", $uploadfile);
	$ext = $filename[count($filename)-1];

	if (move_uploaded_file($tempfile, "/var/www/html/iport/$dir/$uploadfile")) {
			shell_exec("chmod -R 755 /var/www/html/iport/$dir/$uploadfile");
			//echo "<p>$uploadfile file has successfully been uploaded.</p>";
			return "$dir/$uploadfile";
	} else {
			//echo "<p>$dir/$uploadfile ($tempfile) file could not be uploaded.</p>";
			return "Error: system problem";
	}
	} else {
		//echo "<div>Oops! either file name is missing or file size exceeds the max. limit of 10 MB.</div>";
		return "Error: filesize > 10 MB";
	}
}


function text2image($str) {
	Header ("Content-type: image/png");
	putenv('GDFONTPATH=' . realpath('.'));
	$font = 'arial.ttf';
	$fontSize = 80;//in point;
	$onecharwidth  = imagefontwidth($font)*($fontSize/8);
	$totalwidth  = $onecharwidth * strlen($str);
	$height = (imagefontheight($font)*($fontSize/8))*2;
	$img_handle = imagecreatetruecolor($totalwidth, $height);
	$white = imagecolorallocate($img_handle, 255, 255, 255);
	imagefill($img_handle, 0, 0, $white);
	$black = imagecolorallocate ($img_handle, 0, 0, 0);
	$gray = imagecolorallocate ($img_handle, 100, 100, 100);
	imagettftext($img_handle, 20, 0, 10, 20, $black, $font, $title1);
	$posarr=imagettfbbox(20, 0,$font, $title1);
	imagettftext($img_handle, 20, 0, $posarr[2]+$onecharwidth, 20, $gray, $font, $title2);
	imagepng ($img_handle);
	imagedestroy ($img_handle);
}


function ReplaceBadWords($str, $bad_words, $replace_str){
	if (!is_array($bad_words)){ 
		$bad_words = explode(',', $bad_words); 
	}
	for ($x=0; $x < count($bad_words); $x++){
		$fix = isset($bad_words[$x]) ? $bad_words[$x] : '';
		$_replace_str = $replace_str;
		if (strlen($replace_str)==1){
			$_replace_str = str_pad($_replace_str, strlen($fix), $replace_str);
		}
		$str = preg_replace('/'.$fix.'/i', $_replace_str, $str);
	}

	return $str;
}

?>