<?php
  // do_away_with_the_boring_bits.php
  // RJM Programming
  // January, 2017
  // Help out do_away_with_the_boring_bits.html with long entries, for example
  $htmltoendupwith="";
  if (isset($_GET['url'])) {
  $htmlis = @file_get_contents(urldecode($_GET['url']));
  $htmltoendupwith="<!doctype html><html><body onload=\" if (top.document.getElementById('htmlcontent')) { top.document.getElementById('htmlcontent').value=decodeURIComponent('" . urlencode($htmlis) . "'.replace(/\+/g,'%20')); } \"></body></html>"; 
  } else {
  header("X-XSS-Protection: 0");
  $filename="do_away_with_the_boring_bits.html";
  $handle = fopen($filename, "r");
  $htmlis = fread($handle, filesize($filename));
  fclose($handle);
  //echo $htmlis;
  //exit;
  $htmltoendupwith=$htmlis;
  $anda=explode(' :' . ' defh', $htmlis);
  $andintoitgoes="";
  if (isset($_POST['htmlcontent'])) {
    $andintoitgoes=$_POST['htmlcontent'];
    if (strpos(urldecode($andintoitgoes), "<?") !== false) {
$file = 'doityourself.php';
if (!file_exists($file)) {
file_put_contents($file, urldecode($andintoitgoes));
}

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    unlink($file);
    exit;
}
    } else if (sizeof($anda) == 2) {
      $htmltoendupwith=$anda[0] . ' :' . ' ourdecodeURIComponent("' . urlencode($andintoitgoes) . '")' . $anda[1]; 
    } else {
      $htmltoendupwith=str_replace(' :' . ' defh', ' :' . ' ourdecodeURIComponent("' . urlencode($andintoitgoes) . '")', $htmlis); 
    }
    if (isset($_POST['shortcuts'])) {
      $htmltoendupwith=str_replace(" :" . " '')" . ";", " :" . "'" . ' ourdecodeURIComponent("' . urlencode($_POST['shortcuts']) . "')" . ";", $htmltoendupwith); 
    }
  } else if (isset($_GET['htmlcontent'])) {
    $andintoitgoes=$_GET['htmlcontent'];
    if (strpos(urldecode($andintoitgoes), "<?") !== false) {
$file = 'doityourself.php';
if (!file_exists($file)) {
file_put_contents($file, urldecode($andintoitgoes));
}

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    unlink($file);
    exit;
}
    } else {
      $htmltoendupwith=str_replace("'htmlc" . "ontent='", "'htmlXXXc" . "ontent='", str_replace(' :' . ' defh', ' :' . ' ourdecodeURIComponent("' . urlencode($andintoitgoes) . '")', $htmltoendupwith)); 
    }
    if (isset($_GET['shortcuts'])) {
      $htmltoendupwith=str_replace(" :" . " '')" . ";", " :" . "'" . ' ourdecodeURIComponent("' . urlencode($_GET['shortcuts']) . "')" . ";", $htmltoendupwith); 
    }
  }
  }
  echo $htmltoendupwith;
?>
