Server : Apache System : Linux profile 3.10.0-1160.88.1.el7.x86_64 #1 SMP Tue Mar 7 15:41:52 UTC 2023 x86_64 User : apache ( 48) PHP Version : 8.0.28 Disable Function : NONE Directory : /var/www/html/mmishra/ |
#!/usr/bin/php
<?php
//require('classes/PHPMailerAutoload.php');
date_default_timezone_set('Asia/Kolkata');
$stdin = fopen("php://stdin", "rb");
$stdout = fopen("php://stdout", "rw");
$content = "No content";
$tm = str_replace("\"","",str_replace("'","",'<meta name="Obsolescence-Filter" content="time">'));
$dt = str_replace("\"","",str_replace("'","",'<meta name="Obsolescence-Filter" content="date">'));
$dttm = str_replace("\"","",str_replace("'","",'<meta name="Obsolescence-Filter" content="datetime">'));
if ($stdin) {
$content = stream_get_contents($stdin);
fclose($stdin);
}
if (strpos(str_replace("\"","",str_replace("'","",$content)), $tm)) {
//filter web obsolescence on time
$content = obsolescence_filter_on_time($content);
} elseif (strpos(str_replace("\"","",str_replace("'","",$content)), $dt)) {
//filter web obsolescence on date
$content = obsolescence_filter_on_date($content);
} elseif (strpos(str_replace("\"","",str_replace("'","",$content)), $dttm)) {
//filter web obsolescence on datetime
$content = obsolescence_filter_on_time($content);
$content = obsolescence_filter_on_date($content);
}
if ($stdout) {
fwrite($stdout, $content, strlen($content));
}
//function to locate date attribute in HTML tag
function obsolescence_filter_on_time($str) {
//time format hh:ii:ss 24 hours clock
date_default_timezone_set('Asia/Kolkata');
$now = date("H:i:s");
//trim string
$str = str_replace("\"", "", str_replace("'", "", trim(preg_replace('/\s+/', ' ', $str))));
$attr = 'Time=';
$timeAttr = '';
$timeValue = '';
$i = 0; $j = 0; $k = 0;
$slen = 0;
$totWO = 0;
$oTAG = '';
$cTAG = '';
$obsolescence = '';
while (($i = @strpos($str, $attr, $k)) !== false) {
//while (($i = @strpos($str, $attr, $k)) !== false) {
//find value of pub/exp Time
$timeAttr = substr($str, $i - 3, 3);
$timeValue = substr($str, $i + strlen($attr), 8);
//if value of pub/exp Time is found in string, check its value against system time
if (($timeAttr == 'pub' && (strtotime($timeValue) > strtotime($now))) || ($timeAttr == 'exp' && (strtotime($timeValue) < strtotime($now)))) {
//find position of opening TAG
$j = $i;
while ($str[$j] != '<') {
$j--;
}
//find opening TAG name
$oTAG = substr($str, $j, strpos($str, ' ', $j) - $j);
//find closing TAG name
$cTAG = str_replace('<', '</', $oTAG) .'>';
//find position of closing TAG
$k = strpos($str, $cTAG, $i) + strlen($cTAG);
//number of obsolete characters
$slen = $k - $j;
$totWO = $totWO + $slen;
//chop obsolescence
$obsolete = substr($str, $j, $slen);
//accumulate obsolete content
$obsolescence .= "<li>$obsolete</li>";
//filter obsolescence
$str = str_replace($obsolete, '', $str);
$k = $j;
}
if ($i >= strlen($str)) break;
$k = $k + strlen($attr);
}
//web obsolescence list
$str .= "<hr> <font size='-2x' color='red'>Total $totWO bytes web obsolescence has been filtered on pub/exp time values of content.</font> <hr>";
return $str;
}
//function to locate date attribute in HTML tag
function obsolescence_filter_on_date($str) {
//date format dd/mm/yyyy
date_default_timezone_set('Asia/Kolkata');
$today = date("d-m-Y");
//trim string
//$str = trim(preg_replace('/\s+/', ' ', $str));
$str = str_replace("\"", "", str_replace("'", "", trim(preg_replace('/\s+/', ' ', $str))));
$attr = 'Date=';
$dateAttr = '';
$dateValue = '';
$i = 0; $j = 0; $k = 0;
$slen = 0;
$totWO = 0;
$oTAG = '';
$cTAG = '';
$obsolescence = '';
while (($i = @strpos($str, $attr, $k)) !== false) {
//find value of pub/exp Date
$dateAttr = substr($str, $i - 3, 3);
$dateValue = substr($str, $i + strlen($attr), 10);
//if value of pubDate or expDate is found in string, check its value against system date
if (($dateAttr == 'pub' && (strtotime($dateValue) > strtotime($today))) || ($dateAttr == 'exp' && (strtotime($dateValue) < strtotime($today)))) {
//find position of opening TAG
$j = $i;
while ($str[$j] != '<') {
$j--;
}
//find opening TAG name
$oTAG = substr($str, $j, strpos($str, ' ', $j) - $j);
//find closing TAG name
$cTAG = str_replace('<', '</', $oTAG) .'>';
//find position of closing TAG
$k = strpos($str, $cTAG, $i) + strlen($cTAG);
//number of obsolete characters
$slen = $k - $j;
$totWO = $totWO + $slen;
//chop obsolescence
$obsolete = substr($str, $j, $slen);
//accumulate obsolete content
$obsolescence .= "<li>$obsolete</li>";
//filter obsolescence
$str = str_replace($obsolete, '', $str);
$k = $j;
}
$k = $k + strlen($attr);
if ($i >= strlen($str)) break;
}
//web obsolescence list
$str .= "<hr> <font size='-2x' color='red'>Total $totWO bytes web obsolescence has been filtered on pub/exp date values of content.</font> <hr>";
//<font size='-2x' color='red'>Total $totWO bytes web obsolescence as listed below have been filtered</font>.
//<ol id='wo' style='font-size:-2x'>$obsolescence</ol>
//sent alert mail to webmaster
//if ($obsolescence) {
//automailer('mmishra@iiita.ac.in','Web obsolescence',$obsolescence);
//}
return $str;
}
/*
//function to locate HTML tag opening
function tagStart($str, $j) {
while ($j >= 0 && $str[$j] != '<'){
$j--;
}
return $j;
}
//function to locate HTML tag closing
function tagEnd($str, $k) {
$open = 1;
$close = 0;
$slen = strlen($str);
while ($k < $slen) {
if ($str[$k] == '<') {
//$check = 0;
while ($k < $slen && $str[$k] != '>') {
if ($str[$k] == '<' && $str[$k+1] == '/') {
return $k+4;
//$check = 1;
}
$k++;
}
//if ($check) {
// $close++;
//} else {
// $open++;
//}
//if ($open == $close) {
// return ($k+1);
//}
}
$k++;
}
}
function tagFilter1($str) {
$i = 0;
while($i < $httplen) {
if($httpbuffer[i] == $str[0]) {
$j = i;
$k = 0;
$check = 0;
while($j < $httplen && $str[$k] != '\0') {
if($str[$k] != $httpbuffer[$j]) {
$check = 1;
break;
}
$j++;
$k++;
}
if(!$check) {
$ax=0;
$date[8]='';
$ax = $j + 2;
//Assuming date format as exp="dd/mm/yyyy"
$date[0] = $httpbuffer[$ax] - 48;
$date[1] = $httpbuffer[$ax+1] - 48;
$date[2] = $httpbuffer[$ax+3] - 48;
$date[3] = $httpbuffer[$ax+4] - 48;
$date[4] = $httpbuffer[$ax+6] - 48;
$date[5] = $httpbuffer[$ax+7] - 48;
$date[6] = $httpbuffer[$ax+8] - 48;
$date[7] = $httpbuffer[$ax+9] - 48;
//Catched_date contains the date extracted from the HTML.
$catched_date = (struct tm *)malloc(sizeof(struct tm));
$catched_date -> tm_mday = (date[0] * 10) + date[1];
$catched_date -> tm_mon = (date[2] * 10) + date[3];
$catched_date -> tm_year = (date[4] * 1000) + (date[5] * 100) + (date[6] * 10) + date[7];
if(dateisexpired($catched_date)) {
$start = tagStart($i);
$end = tagEnd($j);
tagDelete($start,$end);
}
}
}
$i++;
}
}
*/
function automailer($email, $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
//date_default_timezone_set('Asia/Culcutta');
date_default_timezone_set('Asia/Kolkata');
//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 = "icure@iiita.ac.in";
//Password to use for SMTP authentication
$mail->Password = "irp@2015";
//Set who the message is to be sent from
$mail->setFrom('icure@iiita.ac.in','Automailer');
//Set who the message is to be sent to
$mail->addAddress($email, $email);
//Set the subject line
$mail->Subject = $subject;
$mail->Body = $body;
$mail->WordWrap = 75;
//send the message, check for errors
if (!$mail->send()) {
echo "<div>Automailer Said: ".$mail->ErrorInfo."</div>";
} else {
echo "<div>Automailer Said: OK</div>";
}
}
?>