<?php
//Remove (delete or comment out) this 'exit' call.
exit("Remove me");

$cpanel_username '';
$cpanel_password '';//this can also be the reseller password of course
$cpanel_domain 'www.mydomain.com';//this could be a remote server
$cpanel_theme 'x2';//only x2 has been tested

//these "could" be templates or includes, but you would need to alter some code near the bottom of this file "slightly"
$header_wrap '<html><body><div align="center" style="border:thin dashed black;background:#66CC99;padding:25px;">';
$footer_wrap '</div></body></html>';

/*
no need to touch anything below here
*/

function get_file($url)
{    
  return 
file_get_contents($url);
}

//image and href links, puts the cpanel url in a "uri" parameter
function alter_links($page
{
  
$search '#(href|src)\s*=\s*"(.*?)"#ise';
  
$replace "'\\1=\"{$_SERVER['PHP_SELF']}?uri='.urlencode('\\2').'\"'";
  return 
preg_replace($search$replace$page);
}

//changes post to get and action to this page and the original action to a hidden form variable
function alter_form($form
{
    
$search '@<form.*?action="(.*?)".*?>@';
    
$replace '<form method="get" action="'.$_SERVER['PHP_SELF'].'"><input type="hidden" name="uri" value="$1">';
  return 
preg_replace($search$replace$form);
}

//strip the cpanel header/footer
function extract_div($file)
{
    return 
preg_replace('@^.*?(<div .*?</div>).*$@s''$1'$file);
}


$base_url "http://$cpanel_username:$cpanel_password@$cpanel_domain:2082/frontend/$cpanel_theme/";

//the initial page
$cpanel_uri 'autores.html';
//which cpanel page to get? will be in the "uri" param
if(isset($_GET['uri']))
{
    
$cpanel_uri urldecode($_GET['uri']);
}
$base_file basename(strtok($cpanel_uri'?'));
list(
$file_name$file_type) = explode('.'$base_file);

switch(
$file_type
{
  case 
'jpg':
    
header('Content-type: image/jpg');
        
$base_url .= "images/$base_file";
        
$file get_file($base_url);
  break;
  case 
'html':
        
$base_url .= "mail/$cpanel_uri";
      if(
strpos($cpanel_url'?') === false$base_url .= '?';
        foreach(
$_GET as $var => $val)
      {
            if(
$var == 'uri') continue;
            
$base_url .= $var.'='.urlencode($val).'&';
        }
        
$base_url substr_replace($base_url'', -1);
        
    
$file alter_links(get_file($base_url));
        
$file extract_div($file);
        if(
$file_name == 'addars')
      {
            
$file alter_form($file);
        }
        if(
$file_name == 'autores')
      {
            
//Go Back link
            
$file preg_replace('@\|.*?\]</b>@s'''$file);
      }
        
$file $header_wrap $file $footer_wrap;
  break;
  default:
}


echo 
$file;
?>