<?php
// http_methods.php
// RJM Programming
// May, 2024
// exec calls curl
// eg. curl -X OPTIONS https://www.rjmprogramming.com.au -i

$res="";
$url_get_contents_data="";
$cisis="";

function nocaret($invx) {
  if (2 == 2) {
$html = '<body>' . $invx . '</body>';

// Create a new DOMDocument instance
$dom = new DOMDocument();

// Load the HTML string (suppress warnings caused by partial HTML structures)
@$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);

$outvx = str_replace("\t"," ",str_replace("\\", "\\\\", $dom->textContent));
// Get the element text content
if (strpos($outvx, 'From Wikipedia, the free encyclopedia') !== false) {
$outvx = '<details><summary></summary>' . explode('From Wikipedia, the free encyclopedia', $outvx)[0] . '</details><br>' . 'From Wikipedia, the free encyclopedia' . explode('From Wikipedia, the free encyclopedia', $outvx)[1];
}
  } else { 
  $lastsuffix='';
  $outvx=str_replace('&apos;',"'",str_replace('”','"',str_replace('&lt;br>',"\n",str_replace('&lt;/ref>','',str_replace('/>','',str_replace("\t"," ",$invx)))))); 
  while (strpos($outvx,'<sty' . 'le') < strpos($outvx,'</sty' . 'le>')) { 
    $outvx=str_replace('<sty' . 'le' . explode('<sty' . 'le',explode('</sty' . 'le>',$outvx)[0])[1] . '</sty' . 'le>','', $outvx);  
  }  
  while (strpos($outvx,'<scr' . 'ipt') < strpos($outvx,'</scr' . 'ipt>')) { 
    $outvx=str_replace('<scr' . 'ipt' . explode('<scr' . 'ipt',explode('</scr' . 'ipt>',$outvx)[0])[1] . '</scr' . 'ipt>','', $outvx);  
  }  
  while (strpos($outvx,'<') !== false && strpos($outvx,'>') !== false) {
  while (strpos($outvx,'<') < strpos($outvx,'>')) { 
    $lastsuffix=explode('>',explode('<' . explode('<',explode('>',$outvx)[0])[1] . '>', $outvx)[1])[0];
    $outvx=str_replace('<' . explode('<',explode('>',$outvx)[0])[1] . '>','', $outvx);  
  } 
  if (strpos($outvx,'<') !== false && strpos($outvx,'>') !== false) {
    //return explode('>', $outvx)[0];
    $outvx=str_replace(explode('>', $outvx)[0] . '>',explode('>', $outvx)[0] . '&GT;', $outvx);  
  }
  }
  return str_replace('&GT;','>',str_replace('&LT;','<',$outvx)); 
  }
  return $outvx; 
} 
 
function url_get_contents($url) { // thanks to https://stackoverflow.com/questions/3979802/alternative-to-file-get-contents
    global $url_get_contents_data, $cisis;
    if (strpos($url,"_(disambiguXation)") !== false) {
        $url_get_contents_data = file_get_contents(str_replace("(disambiguation)",urlencode("(disambiguation)"),$url));
    //echo $url . " inUoUt" . strlen($url_get_contents_data) . ' ';
    } else if (function_exists('curl_exec') && strpos($url, 'wikipedia.') !== false) { 
        $conn = curl_init(str_replace("(disambiguation)",urlencode("(disambiguation)"),$url));
        curl_setopt($conn, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36');
        curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($conn, CURLOPT_FRESH_CONNECT,  true);
        curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);
        $url_get_contents_data = (curl_exec($conn));
        curl_close($conn);
    } else if (5 == 5) {
        $url_get_contents_data=shell_exec('curl ' . str_replace("(disambiguation)",urlencode("(disambiguation)"),str_replace('http:','https:',$url)));
    //echo  str_replace("(disambiguation)",urlencode("(disambiguation)"),str_replace('http:','https:',$url)) . " inUout" . strlen($url_get_contents_data) . ' ';
    } else if (function_exists('curl_exec')) { 
        $conn = curl_init(str_replace("(disambiguation)",urlencode("(disambiguation)"),$url));
        curl_setopt($conn, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36');
        curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($conn, CURLOPT_FRESH_CONNECT,  true);
        curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);
        $url_get_contents_data = (curl_exec($conn));
        curl_close($conn);
    } else if (4 == 4) {
        $url_get_contents_data=shell_exec('curl ' . str_replace("(disambiguation)",urlencode("(disambiguation)"),str_replace('http:','https:',$url)));
    } else if (function_exists('file_get_contents')) {
        $url_get_contents_data = file_get_contents(str_replace("(disambiguation)",urlencode("(disambiguation)"),$url));
    } else if (function_exists('fopen') && function_exists('stream_get_contents')) {
        $handle = fopen (str_replace("(disambiguation)",urlencode("(disambiguation)"),$url), "r");
        $url_get_contents_data = stream_get_contents($handle);
    } else {
        $url_get_contents_data = false;
    }
    
    //if (strpos($url, '/Chevy_Van_(song)') !== false) {
if (isset($_GET['song'])) {
   $bbit="<body" . explode(">", explode("<body", $url_get_contents_data)[1])[0] . ">";
   echo "<html><body onload=\" if (window.parent) { if (parent.document.getElementById('ovdiv')) { parent.document.getElementById('ovdiv').style.top='200px';  parent.document.getElementById('ovdiv').style.left='200px';  parent.document.getElementById('ovdiv').style.backgroundColor='rgba(255,255,255,0.8)';   parent.document.getElementById('ovdiv').style.visibility='visible'; parent.document.getElementById('ovdiv').innerHTML='" . str_replace('<br><br>','<br>',str_replace('<br><br>','<br>',str_replace(' <br>','<br>',str_replace(' <br>','<br>',str_replace(' <br>','<br>',str_replace(' <br>','<br>',str_replace("script","scr' + 'ipt",str_replace(" + ' + "," + ",str_replace("\n","<br>",str_replace("'", "' + String.fromCharCode(39) + '", str_replace('"', "' + String.fromCharCode(34) + '", explode("<scr" . "ipt", nocaret(explode("</body>", explode($bbit, $url_get_contents_data)[1])[0]))[0]))))))))))) . "';  } } \"></body></html>";
   exit;
}
    //}
return $url_get_contents_data;
}

function server_remote_addr() {
    $rma = $_SERVER['REMOTE_ADDR'];
    $ua = strtolower($_SERVER['HTTP_USER_AGENT']);
    // you can add different browsers with the same way ..
    if(preg_match('/(chromium)[ \/]([\w.]+)/', $ua))
            $rma = '000000'.$rma;
    elseif(preg_match('/(chrome)[ \/]([\w.]+)/', $ua))
            $rma = '00000'.$rma;
    elseif(preg_match('/(safari)[ \/]([\w.]+)/', $ua))
            $rma = '0000'.$rma;
    elseif(preg_match('/(opera)[ \/]([\w.]+)/', $ua))
            $rma = '000'.$rma;
    elseif(preg_match('/(msie)[ \/]([\w.]+)/', $ua))
            $rma = '00'.$rma;
    elseif(preg_match('/(mozilla)[ \/]([\w.]+)/', $ua))
            $rma = '0'.$rma;
    return '_' . str_replace(":", "_", $rma);
}


if (isset($_POST['incont']) && isset($_POST['inhi'])) {
         while (file_exists("/home/rjmprogr/public_html/ITblog/payloadv.dot")) {
          sleep(5);
         }
  file_put_contents(str_replace('+',' ',urldecode($_POST['inhi'])), explode('##',str_replace('`','#',str_replace("~~","\n",str_replace('+',' ',urldecode($_POST['incont'])))))[0]);
  file_put_contents(str_replace('+',' ',urldecode($_POST['inhi'])) . 'x', explode('##',str_replace('`','#',str_replace("~~","\n",str_replace('+',' ',urldecode($_POST['incont'])))))[0]);
         while (file_exists("/home/rjmprogr/public_html/ITblog/payloadv.dot")) {
          sleep(5);
         }
  if (isset($_POST['insuffix'])) {
    if (file_exists("/home/rjmprogr/public_html/ITblog/renderv.svg")) {
     if (file_exists("/home/rjmprogr/public_html/ITblog/renderv" . str_replace('+',' ',urldecode($_POST['insuffix'])) . ".svg")) {
       unlink("/home/rjmprogr/public_html/ITblog/renderv" . str_replace('+',' ',urldecode($_POST['insuffix'])) . ".svg");
     }
     copy("/home/rjmprogr/public_html/ITblog/renderv.svg", "/home/rjmprogr/public_html/ITblog/renderv" . str_replace('+',' ',urldecode($_POST['insuffix'])) . ".svg");
    }
    if (file_exists("/home/rjmprogr/public_html/ITblog/renderv.png")) {
     if (file_exists("/home/rjmprogr/public_html/ITblog/renderv" . str_replace('+',' ',urldecode($_POST['insuffix'])) . ".png")) {
       unlink("/home/rjmprogr/public_html/ITblog/renderv" . str_replace('+',' ',urldecode($_POST['insuffix'])) . ".png");
     }
     copy("/home/rjmprogr/public_html/ITblog/renderv.png", "/home/rjmprogr/public_html/ITblog/renderv" . str_replace('+',' ',urldecode($_POST['insuffix'])) . ".png");
    }
  }
  echo "<html><body onload=\" parent.document.getElementById('myvenn').src='/ITblog/renderv.png?rand=" . rand(567,26789056) . "'; \"></body></html>";
  exit;
}

if (isset($_GET['url'])) {
 $theurl=str_replace('+',' ',urldecode($_GET['url']));
 if (strlen(trim($theurl)) > 0) {
    if (strpos(strtolower($theurl), 'http') !== false) {
     if (strpos($theurl, 'wikipedia.') !== false) {
     $res=url_get_contents($theurl);
 if ($res != '') {
   echo $res;
 }
 exit;
     } else {
     $res=shell_exec('curl -X OPTIONS ' . $theurl . ' -i');
 if ($res != '') {
   echo $res;
 }
 exit;
     }
    } else if (strpos(strtolower($theurl), '//') === false) {
     $res=shell_exec('curl -X OPTIONS http:' . $theurl . ' -i');
 if ($res != '') {
   echo $res;
 }
 exit;
    } else if (strpos(strtolower($theurl), '//') !== false) {
     $res=shell_exec('curl -X OPTIONS http://' . $theurl . ' -i');
 if ($res != '') {
   echo $res;
 }
 exit;
    }
 }
 if ($res != '') {
   echo '<p>' . str_replace("\n", "<br>", $res) . '</p>';
 }
 exit;
}
if (isset($_GET['posturl'])) {
 if (1 != 2) {
   echo "<html><body onload=\" if (window.parent) { if (parent.document.getElementById('insuffix')) { parent.document.getElementById('insuffix').value='" . server_remote_addr() . "';  } } \"><p>" . str_replace("\n", "<br>", $res) . "</p></body></html>";
 } else {
   echo "<html><body onload=\" if (window.parent) { if (parent.document.getElementById('insuffix')) { parent.document.getElementById('insuffix').value='" . server_remote_addr() . "';  } } \"></body></html>";
 }
 exit;
} else {
 echo "<html>
<body onload=\" if (window.parent) { if (parent.document.getElementById('insuffix')) { parent.document.getElementById('insuffix').value='" . server_remote_addr() . "';  }  \"> 
<h1>HTTP Methods for Website via Curl</h1>
<h3>RJM Programming - May, 2024</h3>
<form target=ifcurl action=./http_methods.php method=GET>
<input style=width:90%; type=url name=url value='' placeholder='Place website URL here eg. http://www.rjmprogramming.com.au'></input><br><br>
<input type=submit value=Show></input>
</form>
<iframe style=width:90%;height:300px; name=ifcurl id=ifcurl src='./http_methods.php?song=y&url=http%3A%2F%2Fwww.rjmprogramming.com.au'></iframe>
</body>
</html>";
}

?>
