Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/istore/
Upload File :
Current File : /var/www/html/mmishra/istore/config.inc.php

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

function localAuth($uid, $pwd) {
       	$role = 'guest';
	if ($uid) {
       		//$pwd = "{SHA}" . base64_encode(pack("H*", sha1($pwd)));
		//$rs = mysql_query("select * from webusers where userid='$uid' and pwd='$pwd'");
		$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 accessLog($user, $referer, $url, $remoteip) {        
	$tbl = 'weblogs';
        
	if (!$user) $user = 'guest';
        if (!$referer) $referer = 'direct';
        if ($url == '/') $url = 'index.php';
        
        mysql_query("insert into $tbl(userID,referer,webURL,remoteIP)
        values('$user', '$referer', '$url','$remoteip')");
}

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 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/itransport/$dir/$uploadfile")) {
                	shell_exec("chmod -R 755 /var/www/html/itransport/$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;
}

function uniq_sid($uid, $pwd) {
        //$epwd = @mcrypt_ecb(MCRYPT_DES, "gravity", $pwd, MCRYPT_ENCRYPT);
        $epwd = base64_encode($pwd);
        //clear entry for ppl who havent done anything for past 20 minutes
        //$result = mysql_query("delete from auth where last_activity < now()-1200");
        srand((double)microtime()*100000000);
        //generate a unique s_id
        do {
                $ch = "";
                for($i=0; $i<20; $i++) $ch = $ch . chr(rand(65, 90));
                //loop until a uniq string is generated
        } while (!mysql_query("insert into auth values('$ch', '$uid','$epwd', NULL)"));
        return $ch;
}

function sendmail($email, $subject, $body) {
	$mail = new PHPMailer();
	$mail->IsHTML(true); // telling the class to use HML format
	$mail->IsSMTP(); // telling the class to use SMTP
	$mail->Host = 'smtp.gmail.com';
	$mail->Port = 465;
	$mail->SMTPSecure = 'ssl';
	$mail->SMTPAuth = true;
	$mail->FromName = "Director, IIIT-Allahabad";
	$mail->From = "dir.wish@iiita.ac.in";
	$mail->AddAddress($email, $email);
	$mail->AddBCC("director@iiita.ac.in","Director, IIIT-Allahabad");
	$mail->Username = "dir.wish@iiita.ac.in";
	$mail->Password = "wish@iiita";

	$mail->Subject = $subject;
	$mail->Body = $body;
	$mail->WordWrap = 75;

	if (!$mail->Send()) {
   		return $mail->ErrorInfo;
	} else {
   		return TRUE;
	}
}

function automailer($email, $subject, $body, $attachment='') {
	//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

	//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('istore@iiita.ac.in', 'iStore@IIITA');

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

	//Set who the message is to be sent to
	$mail->addAddress($email, $email);
	//$mail->addBCC('mmishra@iiita.ac.in', 'Mmishra');

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

	$mail->Body = $body . "<br>--<br>iStore@IIITA<br><br>
	Login at https://istore.iiita.ac.in using LDAP credentials for updated information on store & purchase.<br><br>
	(Automailer)";
	$mail->WordWrap = 75;

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

function get_enum_values($table, $field) {
        $rs = mysql_query("show columns from {$table} where field='{$field}'");
        $r = mysql_fetch_object($rs);
	$type = $r->Type;
	preg_match("/^enum\(\'(.*)\'\)$/", $type, $matches);
	$enum = explode("','", $matches[1]);

	return $enum;
}

function htmlsafe($str) {
        return trim(htmlspecialchars(stripslashes($str), ENT_QUOTES));
}

function unhtmlentities ($string) {
    $trans_tbl = get_html_translation_table (HTML_ENTITIES);
    $trans_tbl = array_flip ($trans_tbl);
    return strtr ($string, $trans_tbl);
}


function previous_month() {
        $pmonth = (int)(date("n"));
        if ($pmonth == 0) {
                $pmonth = 12;
                $pyear = date("Y") - 1;
        } else
                $pyear = date("Y");
        return date("M-Y",mktime(0,0,0,$pmonth,0,$pyear));
}

function previous_month1($cmonth) {
        $pmonth = (int)(date("n"));
        if ($pmonth == 0) {
                $pmonth = 12;
                $pyear = date("Y",strtotime($cmonth)) - 1;
        } else
                $pyear = date("Y",strtotime($cmonth));
        return date("M-Y",mktime(0,0,0,$pmonth,0,$pyear));
}

function next_month() {
        $nmonth = (int)(date("n"));
        if ($nmonth == 12) {
                $nmonth = 0;
                $nyear = date("Y") + 1;
        } else
                $nyear = date("Y");

        $nmonth = $nmonth + 1;
        return date("Y-m-d",mktime(0,0,0,$nmonth,25,$nyear));
}


function list_tabledata($sql) {
        $rs = mysql_query($sql);

        if (mysql_num_rows($rs)) {
                $colHeads = mysql_num_fields($rs);

                $str = "<table border='1' width='90%' style='border-collapse: collapse'>
		<tr><th>Sr</th>";
                for ($i=0; $i < $colHeads; $i++) { // Header
                        $str .= "<th>".ucwords(str_replace("_"," ",mysql_field_name($rs, $i)))."</th>";
                }
                $str .= "</tr>";
                $j = 0;        
                while ($row = mysql_fetch_row($rs)) { //data
                        $j++;
                        $str .= "<tr><td>$j</td><td>".implode($row,'</td><td>')."</td></tr>";
                }
                $str .= "</table>";
        } else {
                $str = "";
        }
	
	return $str;
}

?>