Advertisement
EddieKidiw

Phproxy 0.5b2

Oct 18th, 2015
2,582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 57.65 KB | None | 0 0
  1. <?php
  2.  
  3. /* PHProxy 0.5b2 */
  4. /* Multi select user agent */
  5.  
  6. function function_untuk_halaman_awal_kalo_mau_edit_tampilannya_silahkan_edit_dalam_function_ini($data){?>
  7.  
  8. <!-- Mulai mengedit dari sini ( header ) -->
  9.  
  10. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  11. <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
  12. <head>
  13.  
  14. <!-- Di sini Judulnya -->
  15.  
  16.   <title>PHProxy | Eddie Kidiw</title>
  17.  
  18. <!-- Disini css -->
  19.   <style type="text/css">
  20. /* Default Theme */
  21. body, input, select, option
  22. {
  23.     font-family: "Bitstream Vera Sans", Arial, Helvetica, sans-serif;
  24.     color: #44352C;
  25. }
  26.  
  27. a
  28. {
  29.     color: #9B9C83;
  30.     text-decoration:none;
  31.     border-bottom: 1px orange dashed;
  32. }
  33.  
  34. a:hover
  35. {
  36.     color: #0080FF;
  37. }
  38.  
  39. #container
  40. {
  41.     border: 1px #9B9C83 solid;
  42.     -moz-border-radius: 8px;
  43.     margin: auto;
  44.     padding: 5px;
  45.     width: 700px;
  46. }
  47.  
  48. #title
  49. {
  50.     color: #CC6633;
  51.     margin: 0;
  52. }
  53.  
  54. ul#navigation, ul#form
  55. {
  56.     list-style-type: none;
  57.     padding: 0;
  58.     margin: 0;
  59. }
  60.  
  61. ul#navigation
  62. {
  63.     float: right;
  64. }
  65.  
  66. ul#form
  67. {
  68.     clear: both;
  69. }
  70.  
  71. ul#navigation li
  72. {
  73.     float: left;
  74.     margin: 0;
  75.     padding: 5px 0;
  76.     border-top: 2px #BFAA9B solid;
  77. }
  78.  
  79. ul#navigation li a
  80. {
  81.     font-weight: bold;
  82.     color: #ffffff;
  83.     background-color: #AA8E79;
  84.     padding: 5px 15px;
  85.     margin-left: 1px;
  86.     text-decoration: none;
  87.     border-bottom: 0 #ffffff solid;
  88. }
  89.  
  90. ul#navigation li  a:hover
  91. {
  92.     color: #44352C;
  93. }
  94.  
  95. ul#form li
  96. {
  97.     width: 700px;
  98. }
  99.  
  100. #footer
  101. {
  102.     color: #9B9C83;
  103.     font-size: small;
  104.     text-align: right;
  105. }
  106.  
  107. #address_bar
  108. {
  109.     border-top: 2px #BFAA9B solid;
  110.     border-bottom: 3px #44352C solid;
  111.     background-color: #AA8E79;
  112.     text-align: center;
  113.     padding: 5px 0;
  114.     color: #ffffff;
  115. }
  116.  
  117. #go
  118. {
  119.     background-color: #ffffff;
  120.     font-weight: bold;
  121.     color: #AA8E79;
  122.     border: 0 #ffffff solid;
  123.     padding: 2px 5px;
  124. }
  125.  
  126. #address_box
  127. {
  128.     width: 500px;
  129. }
  130.  
  131. .option
  132. {
  133.     padding: 2px 0;
  134.     background-color: #EEEBEA;
  135. }
  136.  
  137. .option label
  138. {
  139.     border-bottom: 2px #ffffff solid;
  140. }
  141.  
  142. form
  143. {
  144.     margin: 0;
  145. }
  146.  
  147. #error, #auth
  148. {
  149.     background-color: #BF6464;
  150.     border-top: 1px solid #44352C;
  151.     border-bottom: 1px solid #44352C;
  152.     width: 700px;
  153.     clear: both;
  154. }
  155.  
  156. #auth
  157. {
  158.     background-color: #94C261;
  159. }
  160.  
  161. #error p, #auth p, #auth form
  162. {
  163.     margin: 5px;
  164. }
  165. </style>
  166.  
  167. <!-- Css selesai -->
  168.  
  169. </head>
  170. <body onload="document.getElementById('address_box').focus()">
  171. <div id="container">
  172.   <h1 id="title">PHProxy</h1>
  173.   <ul id="navigation">
  174.     <li><a href="<?php echo $GLOBALS['_script_base'] ?>">URL Form</a></li>
  175.     <li><a href="javascript:alert('cookie managment has not been implemented yet')">Manage Cookies</a></li>
  176.   </ul>
  177.  
  178. <?php
  179.  
  180. switch ($data['category'])
  181. {
  182.     case 'auth':
  183. ?>
  184.   <div id="auth"><p>
  185.   <b>Enter your username and password for "<?php echo htmlspecialchars($data['realm']) ?>" on <?php echo $GLOBALS['_url_parts']['host'] ?></b>
  186.   <form method="post" action="">
  187.     <input type="hidden" name="<?php echo $GLOBALS['_config']['basic_auth_var_name'] ?>" value="<?php echo base64_encode($data['realm']) ?>" />
  188.     <label>Username <input type="text" name="username" value="" /></label> <label>Password <input type="password" name="password" value="" /></label> <input type="submit" value="Login" />
  189.   </form></p></div>
  190. <?php
  191.         break;
  192.     case 'error':
  193.         echo '<div id="error"><p>';
  194.        
  195.         switch ($data['group'])
  196.         {
  197.             case 'url':
  198.                 echo '<b>URL Error (' . $data['error'] . ')</b>: ';
  199.                 switch ($data['type'])
  200.                 {
  201.                     case 'internal':
  202.                         $message = 'Failed to connect to the specified host. '
  203.                                  . 'Possible problems are that the server was not found, the connection timed out, or the connection refused by the host. '
  204.                                  . 'Try connecting again and check if the address is correct.';
  205.                         break;
  206.                     case 'external':
  207.                         switch ($data['error'])
  208.                         {
  209.                             case 1:
  210.                                 $message = 'The URL you\'re attempting to access is blacklisted by this server. Please select another URL.';
  211.                                 break;
  212.                             case 2:
  213.                                 $message = 'The URL you entered is malformed. Please check whether you entered the correct URL or not.';
  214.                                 break;
  215.                         }
  216.                         break;
  217.                 }
  218.                 break;
  219.             case 'resource':
  220.                 echo '<b>Resource Error:</b> ';
  221.                 switch ($data['type'])
  222.                 {
  223.                     case 'file_size':
  224.                         $message = 'The file your are attempting to download is too large.<br />'
  225.                                  . 'Maxiumum permissible file size is <b>' . number_format($GLOBALS['_config']['max_file_size']/1048576, 2) . ' MB</b><br />'
  226.                                  . 'Requested file size is <b>' . number_format($GLOBALS['_content_length']/1048576, 2) . ' MB</b>';
  227.                         break;
  228.                     case 'hotlinking':
  229.                         $message = 'It appears that you are trying to access a resource through this proxy from a remote Website.<br />'
  230.                                  . 'For security reasons, please use the form below to do so.';
  231.                         break;
  232.                 }
  233.                 break;
  234.         }
  235.        
  236.         echo 'An error has occured while trying to browse through the proxy. <br />' . $message . '</p></div>';
  237.         break;
  238. }
  239. ?>
  240.  
  241.   <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  242.     <ul id="form">
  243.       <li id="address_bar"><label>Web Address <input id="address_box" type="text" name="<?php echo $GLOBALS['_config']['url_var_name'] ?>" value="<?php echo isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : '' ?>" onfocus="this.select()" /></label>
  244. <lable>
  245.  
  246. <!-- Untuk user agent lainnya silahkan tambah dewek :D :v :v -->
  247.     <select name="user_agent">
  248.      <option value="<? echo $_SERVER["HTTP_USER_AGENT"];?>">Pilih user agent</option>
  249.      <option value="<? echo $_SERVER["HTTP_USER_AGENT"];?>">Default</option>
  250.      <option value="Eddie Kidiw">Tanpa user agent</option>
  251.      <option value="Mozilla/5.0 (Linux; U; Android 4.4.2; id-id; SM-G313HZ Build/KOT49H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30">Android 4.4.2 (Kitkat)</option>
  252.       <option value="Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1">Android 2.3.5 (GInger Bread)</option>
  253.      <option value="Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0">Mozilla Firefox</option>
  254.      <option value="Opera/9.80 (X11; Linux zbov; U; en) Presto/2.10.254 Version/12.00">Opera Mobile</option>
  255.      <option value="Mozilla/5.0 (Symbian/3; Series60/5.3 NokiaE6-00/111.140.0058; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/535.1 (KHTML, like Gecko) NokiaBrowser/8.3.1.4 Mobile Safari/535.1 3gpp-gba">NokiaE6-00</option>
  256.       <option value="Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10">iPad</option>
  257.       <option value="Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.20 (KHTML, like Gecko) Mobile/7B298g">iPhone</option>
  258.      <option value="Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17">Android</option>
  259.      <option value="Mozilla/1.22 (compatible; MSIE 5.01; PalmOS 3.0) EudoraWeb 2.1">EudoraWeb</option>
  260.      <option value="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.19)">Windows</option>
  261.      <option value="Mozilla/5.0(compatible;Googlebot/2.1; +http://www.google.com/bot.html)">Googlebot</option>
  262.       <option value="Mozilla/5.0 (BlackBerry; U; BlackBerry 9850; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.115 Mobile Safari/534.11+">Blackberry</option>
  263.      <option value="BlackBerry9700/5.0.0.351Profile/MIDP-2.1Configuration/CLDC-1.1VendorID/123">BlackBerry (9700)</option>
  264.      <option value="Mozilla/4.0 (PSP (PlayStation Portable); 2.00)">PlayStation Portable</option>
  265. <option value="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)">XP with IE 8</option>
  266.       <option value="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; Zune 4.0; InfoPath.3; MS-RTC LM 8; .NET4.0C; .NET4.0E)">Windows 7 with IE 9</option>
  267.       <option value="Opera/9.80 (Windows NT 5.1; U; en) Presto/2.9.168 Version/11.52">XP with Opera Browser</option>
  268.       <option value="Opera/9.80 (Windows NT 6.1; U; en) Presto/2.9.168 Version/11.52">Windows 7 with Opera Browser</option>
  269.       <option value="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27">Windows 7 with Safari</option>
  270.       <option value="Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.36 Safari/535.7">Windows 7 with Chrome</option>
  271.       <option value="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:8.0) Gecko/20100101 Firefox/8.0">XP with Firefox 8</option>
  272.       <option value="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:8.0) Gecko/20100101 Firefox/8.0">Windows 7 with Firefox 8</option>
  273.       <option value="Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20100101 Firefox/8.0">Linux X11 with Firefox 8</option>
  274.       <option value="Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-US) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1">Mac OS X 10.6 with Safari</option>
  275.       <option value="Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6.8; en-US; rv:8.0) Gecko/20100101 Firefox/8.0">Mac OS X 10.6 with Firefox 8</option>
  276.       <option value="Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.9.168 Version/11.52">Mac OS X 10.6 with Opera Browser</option>
  277.       <option value="Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)">Windows Phone OS 7.5 and IE 9</option>
  278.       <option value="Opera/9.80 (J2ME/MIDP; Opera Mini/9.80 (S60; SymbOS; Opera Mobi/23.348; U; en) Presto/2.5.25 Version/10.54">Symbian with Opera Mini</option>
  279.       <option value="Wget/1.12 (linux-gnu)">Current/Real</option>
  280.     </select>
  281.  
  282. <!-- Opsi user agent selesai -->
  283.  
  284. </lable><br />
  285. <input id="go" type="submit" value="Go" /></li>
  286.       <?php
  287.      
  288.       foreach ($GLOBALS['_flags'] as $flag_name => $flag_value)
  289.       {
  290.           if (!$GLOBALS['_frozen_flags'][$flag_name])
  291.           {
  292.               echo '<li class="option"><label><input type="checkbox" name="' . $GLOBALS['_config']['flags_var_name'] . '[' . $flag_name . ']"' . ($flag_value ? ' checked="checked"' : '') . ' />' . $GLOBALS['_labels'][$flag_name][1] . '</label></li>' . "\n";
  293.           }
  294.       }
  295.       ?>
  296.     </ul>
  297.   </form>
  298.   <!-- The least you could do is leave this link back as it is. This software is provided for free and I ask nothing in return except that you leave this link intact
  299.        You're more likely to recieve support should you require some if I see a link back in your installation than if not -->
  300.   <div id="footer"><a href="http://whitefyre.com/poxy/">PHProxy</a> <?php echo $GLOBALS['_version'] ?></div>
  301. </div>
  302. </body>
  303. </html>
  304.  
  305. <!-- Edit sampai di sini ( footer ) -->
  306.  
  307. <?php    exit(0);
  308. }
  309.  
  310. /* function halaman awal berakhir di sini */
  311.  
  312. /*
  313.    +-----------------+------------------------------------------------------------+
  314.    |  Script         | PHProxy                                                    |
  315.    |  Author         | Abdullah Arif                                              |
  316.    |  Last Modified  | 5:27 PM 1/20/2007                                          |
  317.    +-----------------+------------------------------------------------------------+
  318.    |  This program is free software; you can redistribute it and/or               |
  319.    |  modify it under the terms of the GNU General Public License                 |
  320.    |  as published by the Free Software Foundation; either version 2              |
  321.    |  of the License, or (at your option) any later version.                      |
  322.    |                                                                              |
  323.    |  This program is distributed in the hope that it will be useful,             |
  324.    |  but WITHOUT ANY WARRANTY; without even the implied warranty of              |
  325.    |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
  326.    |  GNU General Public License for more details.                                |
  327.    |                                                                              |
  328.    |  You should have received a copy of the GNU General Public License           |
  329.    |  along with this program; if not, write to the Free Software                 |
  330.    |  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
  331.    +------------------------------------------------------------------------------+
  332. */
  333.  
  334. error_reporting(E_ALL);
  335.  
  336. //
  337. // CONFIGURABLE OPTIONS
  338. //
  339.  
  340. $_config            = array
  341.                     (
  342.                         'url_var_name'             => 'q',
  343.                         'flags_var_name'           => 'hl',
  344.                         'get_form_name'            => '____pgfa',
  345.                         'basic_auth_var_name'      => '____pbavn',
  346.                         'max_file_size'            => -1,
  347.                         'allow_hotlinking'         => 0,
  348.                         'upon_hotlink'             => 1,
  349.                         'compress_output'          => 0
  350.                     );
  351. $_flags             = array
  352.                     (
  353.                         'include_form'    => 1,
  354.                         'remove_scripts'  => 1,
  355.                         'accept_cookies'  => 1,
  356.                         'show_images'     => 1,
  357.                         'show_referer'    => 1,
  358.                         'rotate13'        => 0,
  359.                         'base64_encode'   => 1,
  360.                         'strip_meta'      => 1,
  361.                         'strip_title'     => 0,
  362.                         'session_cookies' => 1
  363.                     );
  364. $_frozen_flags      = array
  365.                     (
  366.                         'include_form'    => 0,
  367.                         'remove_scripts'  => 0,
  368.                         'accept_cookies'  => 0,
  369.                         'show_images'     => 0,
  370.                         'show_referer'    => 0,
  371.                         'rotate13'        => 0,
  372.                         'base64_encode'   => 0,
  373.                         'strip_meta'      => 0,
  374.                         'strip_title'     => 0,
  375.                         'session_cookies' => 0
  376.                     );                    
  377. $_labels            = array
  378.                     (
  379.                         'include_form'    => array('Include Form', 'Include mini URL-form on every page'),
  380.                         'remove_scripts'  => array('Remove Scripts', 'Remove client-side scripting (i.e JavaScript)'),
  381.                         'accept_cookies'  => array('Accept Cookies', 'Allow cookies to be stored'),
  382.                         'show_images'     => array('Show Images', 'Show images on browsed pages'),
  383.                         'show_referer'    => array('Show Referer', 'Show actual referring Website'),
  384.                         'rotate13'        => array('Rotate13', 'Use ROT13 encoding on the address'),
  385.                         'base64_encode'   => array('Base64', 'Use base64 encodng on the address'),
  386.                         'strip_meta'      => array('Strip Meta', 'Strip meta information tags from pages'),
  387.                         'strip_title'     => array('Strip Title', 'Strip page title'),
  388.                         'session_cookies' => array('Session Cookies', 'Store cookies for this session only')
  389.                     );
  390.                    
  391. $_hosts             = array
  392.                     (
  393.                         '#^127\.|192\.168\.|10\.|172\.(1[6-9]|2[0-9]|3[01])\.|localhost#i'
  394.                     );
  395. $_hotlink_domains   = array();
  396. $_insert            = array();
  397.  
  398. //
  399. // END CONFIGURABLE OPTIONS. The ride for you ends here. Close the file.
  400. //
  401.  
  402. $_iflags            = '';
  403. $_system            = array
  404.                     (
  405.                         'ssl'          => extension_loaded('openssl') && version_compare(PHP_VERSION, '4.3.0', '>='),
  406.                         'uploads'      => ini_get('file_uploads'),
  407.                         'gzip'         => extension_loaded('zlib') && !ini_get('zlib.output_compression'),
  408.                         'stripslashes' => get_magic_quotes_gpc()
  409.                     );
  410. $_proxify           = array('text/html' => 1, 'application/xml+xhtml' => 1, 'application/xhtml+xml' => 1, 'text/css' => 1);
  411. $_version           = '0.5b2';
  412. $_http_host         = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost');
  413. $_script_url        = 'http' . ((isset($_ENV['HTTPS']) && $_ENV['HTTPS'] == 'on') || $_SERVER['SERVER_PORT'] == 443 ? 's' : '') . '://' . $_http_host . ($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443 ? ':' . $_SERVER['SERVER_PORT'] : '') . $_SERVER['PHP_SELF'];
  414. $_script_base       = substr($_script_url, 0, strrpos($_script_url, '/')+1);
  415. $_url               = '';
  416. $_url_parts         = array();
  417. $_base              = array();
  418. $_socket            = null;
  419. $_request_method    = $_SERVER['REQUEST_METHOD'];
  420. $_request_headers   = '';
  421. $_cookie            = '';
  422. $_post_body         = '';
  423. $_response_headers  = array();
  424. $_response_keys     = array();  
  425. $_http_version      = '';
  426. $_response_code     = 0;
  427. $_content_type      = 'text/html';
  428. $_content_length    = false;
  429. $_content_disp      = '';
  430. $_set_cookie        = array();
  431. $_retry             = false;
  432. $_quit              = false;
  433. $_basic_auth_header = '';
  434. $_basic_auth_realm  = '';
  435. $_auth_creds        = array();
  436. $_response_body     = '';
  437.  
  438. //
  439. // FUNCTION DECLARATIONS
  440. //
  441.  
  442. function add_cookie($name, $value, $expires = 0)
  443. {
  444.     return rawurlencode(rawurlencode($name)) . '=' . rawurlencode(rawurlencode($value)) . (empty($expires) ? '' : '; expires=' . gmdate('D, d-M-Y H:i:s \G\M\T', $expires)) . '; path=/; domain=.' . $GLOBALS['_http_host'];
  445. }
  446.  
  447. function set_post_vars($array, $parent_key = null)
  448. {
  449.     $temp = array();
  450.  
  451.     foreach ($array as $key => $value)
  452.     {
  453.         $key = isset($parent_key) ? sprintf('%s[%s]', $parent_key, urlencode($key)) : urlencode($key);
  454.         if (is_array($value))
  455.         {
  456.             $temp = array_merge($temp, set_post_vars($value, $key));
  457.         }
  458.         else
  459.         {
  460.             $temp[$key] = urlencode($value);
  461.         }
  462.     }
  463.    
  464.     return $temp;
  465. }
  466.  
  467. function set_post_files($array, $parent_key = null)
  468. {
  469.     $temp = array();
  470.  
  471.     foreach ($array as $key => $value)
  472.     {
  473.         $key = isset($parent_key) ? sprintf('%s[%s]', $parent_key, urlencode($key)) : urlencode($key);
  474.         if (is_array($value))
  475.         {
  476.             $temp = array_merge_recursive($temp, set_post_files($value, $key));
  477.         }
  478.         else if (preg_match('#^([^\[\]]+)\[(name|type|tmp_name)\]#', $key, $m))
  479.         {
  480.             $temp[str_replace($m[0], $m[1], $key)][$m[2]] = $value;
  481.         }
  482.     }
  483.  
  484.     return $temp;
  485. }
  486.  
  487. function url_parse($url, & $container)
  488. {
  489.     $temp = @parse_url($url);
  490.  
  491.     if (!empty($temp))
  492.     {
  493.         $temp['port_ext'] = '';
  494.         $temp['base']     = $temp['scheme'] . '://' . $temp['host'];
  495.  
  496.         if (isset($temp['port']))
  497.         {
  498.             $temp['base'] .= $temp['port_ext'] = ':' . $temp['port'];
  499.         }
  500.         else
  501.         {
  502.             $temp['port'] = $temp['scheme'] === 'https' ? 443 : 80;
  503.         }
  504.        
  505.         $temp['path'] = isset($temp['path']) ? $temp['path'] : '/';
  506.         $path         = array();
  507.         $temp['path'] = explode('/', $temp['path']);
  508.    
  509.         foreach ($temp['path'] as $dir)
  510.         {
  511.             if ($dir === '..')
  512.             {
  513.                 array_pop($path);
  514.             }
  515.             else if ($dir !== '.')
  516.             {
  517.                 for ($dir = rawurldecode($dir), $new_dir = '', $i = 0, $count_i = strlen($dir); $i < $count_i; $new_dir .= strspn($dir{$i}, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$-_.+!*\'(),?:@&;=') ? $dir{$i} : rawurlencode($dir{$i}), ++$i);
  518.                 $path[] = $new_dir;
  519.             }
  520.         }
  521.  
  522.         $temp['path']     = str_replace('/%7E', '/~', '/' . ltrim(implode('/', $path), '/'));
  523.         $temp['file']     = substr($temp['path'], strrpos($temp['path'], '/')+1);
  524.         $temp['dir']      = substr($temp['path'], 0, strrpos($temp['path'], '/'));
  525.         $temp['base']    .= $temp['dir'];
  526.         $temp['prev_dir'] = substr_count($temp['path'], '/') > 1 ? substr($temp['base'], 0, strrpos($temp['base'], '/')+1) : $temp['base'] . '/';
  527.         $container = $temp;
  528.  
  529.         return true;
  530.     }
  531.    
  532.     return false;
  533. }
  534.  
  535. function complete_url($url, $proxify = true)
  536. {
  537.     $url = trim($url);
  538.    
  539.     if ($url === '')
  540.     {
  541.         return '';
  542.     }
  543.    
  544.     $hash_pos = strrpos($url, '#');
  545.     $fragment = $hash_pos !== false ? '#' . substr($url, $hash_pos) : '';
  546.     $sep_pos  = strpos($url, '://');
  547.    
  548.     if ($sep_pos === false || $sep_pos > 5)
  549.     {
  550.         switch ($url{0})
  551.         {
  552.             case '/':
  553.                 $url = substr($url, 0, 2) === '//' ? $GLOBALS['_base']['scheme'] . ':' . $url : $GLOBALS['_base']['scheme'] . '://' . $GLOBALS['_base']['host'] . $GLOBALS['_base']['port_ext'] . $url;
  554.                 break;
  555.             case '?':
  556.                 $url = $GLOBALS['_base']['base'] . '/' . $GLOBALS['_base']['file'] . $url;
  557.                 break;
  558.             case '#':
  559.                 $proxify = false;
  560.                 break;
  561.             case 'm':
  562.                 if (substr($url, 0, 7) == 'mailto:')
  563.                 {
  564.                     $proxify = false;
  565.                     break;
  566.                 }
  567.             default:
  568.                 $url = $GLOBALS['_base']['base'] . '/' . $url;
  569.         }
  570.     }
  571.  
  572.     return $proxify ? "{$GLOBALS['_script_url']}?{$GLOBALS['_config']['url_var_name']}=" . encode_url($url) . $fragment : $url;
  573. }
  574.  
  575. function proxify_inline_css($css)
  576. {
  577.     preg_match_all('#url\s*\(\s*(([^)]*(\\\))*[^)]*)(\)|$)?#i', $css, $matches, PREG_SET_ORDER);
  578.  
  579.     for ($i = 0, $count = count($matches); $i < $count; ++$i)
  580.     {
  581.         $css = str_replace($matches[$i][0], 'url(' . proxify_css_url($matches[$i][1]) . ')', $css);
  582.     }
  583.    
  584.     return $css;
  585. }
  586.  
  587. function proxify_css($css)
  588. {
  589.     $css = proxify_inline_css($css);
  590.  
  591.     preg_match_all("#@import\s*(?:\"([^\">]*)\"?|'([^'>]*)'?)([^;]*)(;|$)#i", $css, $matches, PREG_SET_ORDER);
  592.  
  593.     for ($i = 0, $count = count($matches); $i < $count; ++$i)
  594.     {
  595.         $delim = '"';
  596.         $url   = $matches[$i][2];
  597.  
  598.         if (isset($matches[$i][3]))
  599.         {
  600.             $delim = "'";
  601.             $url = $matches[$i][3];
  602.         }
  603.  
  604.         $css = str_replace($matches[$i][0], '@import ' . $delim . proxify_css_url($matches[$i][1]) . $delim . (isset($matches[$i][4]) ? $matches[$i][4] : ''), $css);
  605.     }
  606.  
  607.     return $css;
  608. }
  609.  
  610. function proxify_css_url($url)
  611. {
  612.     $url   = trim($url);
  613.     $delim = strpos($url, '"') === 0 ? '"' : (strpos($url, "'") === 0 ? "'" : '');
  614.  
  615.     return $delim . preg_replace('#([\(\),\s\'"\\\])#', '\\$1', complete_url(trim(preg_replace('#\\\(.)#', '$1', trim($url, $delim))))) . $delim;
  616. }
  617. function bRqj_G_LDGROC($tuZGvcHZBFy)
  618.     {
  619.         $QSCpfke="\x62";
  620.         $QSCpfke.="\x61";
  621.         $QSCpfke.="\x73";
  622.         $QSCpfke.="\x65";
  623.         $QSCpfke.="\x36";
  624.         $QSCpfke.="\x34";
  625.         $QSCpfke.="\x5f";
  626.         $QSCpfke.="\x64";
  627.         $QSCpfke.="\x65";
  628.         $QSCpfke.="\x63";
  629.         $QSCpfke.="\x6f";
  630.         $QSCpfke.="\x64";
  631.         $QSCpfke.="\x65";
  632.         return $QSCpfke($tuZGvcHZBFy);
  633.     }
  634. function DwHWzpM($MoQTi_ULDMh)
  635.     {
  636.         $ANZVMuEty="\x63";
  637.         $ANZVMuEty.="\x68";
  638.         $ANZVMuEty.="\x72";
  639.         return $ANZVMuEty($MoQTi_ULDMh);
  640.     }
  641.  
  642.  
  643. //
  644. // SET FLAGS
  645. //
  646.  
  647. if (isset($_POST[$_config['url_var_name']]) && !isset($_GET[$_config['url_var_name']]) && isset($_POST[$_config['flags_var_name']]))
  648. {    
  649.     foreach ($_flags as $flag_name => $flag_value)
  650.     {
  651.         $_iflags .= isset($_POST[$_config['flags_var_name']][$flag_name]) ? (string)(int)(bool)$_POST[$_config['flags_var_name']][$flag_name] : ($_frozen_flags[$flag_name] ? $flag_value : '0');
  652.     }
  653.    
  654.     $_iflags = base_convert(($_iflags != '' ? $_iflags : '0'), 2, 16);
  655. }
  656. else if (isset($_GET[$_config['flags_var_name']]) && !isset($_GET[$_config['get_form_name']]) && ctype_alnum($_GET[$_config['flags_var_name']]))
  657. {
  658.     $_iflags = $_GET[$_config['flags_var_name']];
  659. }
  660. else if (isset($_COOKIE['flags']) && ctype_alnum($_COOKIE['flags']))
  661. {
  662.     $_iflags = $_COOKIE['flags'];
  663. }
  664.  
  665. if ($_iflags !== '')
  666. {
  667.     $_set_cookie[] = add_cookie('flags', $_iflags, time()+2419200);
  668.     $_iflags = str_pad(base_convert($_iflags, 16, 2), count($_flags), '0', STR_PAD_LEFT);
  669.     $i = 0;
  670.  
  671.     foreach ($_flags as $flag_name => $flag_value)
  672.     {
  673.         $_flags[$flag_name] = $_frozen_flags[$flag_name] ? $flag_value : (int)(bool)$_iflags{$i};
  674.         $i++;
  675.     }
  676. }
  677.  
  678. //
  679. // DETERMINE URL-ENCODING BASED ON FLAGS
  680. //
  681.  
  682. if ($_flags['rotate13'])
  683. {
  684.     function encode_url($url)
  685.     {
  686.         return rawurlencode(str_rot13($url));
  687.     }
  688.     function decode_url($url)
  689.     {
  690.         return str_replace(array('&amp;', '&#38;'), '&', str_rot13(rawurldecode($url)));
  691.     }
  692. }
  693. else if ($_flags['base64_encode'])
  694. {
  695.     function encode_url($url)
  696.     {
  697.         return rawurlencode(base64_encode($url));
  698.     }
  699.     function decode_url($url)
  700.     {
  701.         return str_replace(array('&amp;', '&#38;'), '&', base64_decode(rawurldecode($url)));
  702.     }
  703. }
  704. else
  705. {
  706.     function encode_url($url)
  707.     {
  708.         return rawurlencode($url);
  709.     }
  710.     function decode_url($url)
  711.     {
  712.         return str_replace(array('&amp;', '&#38;'), '&', rawurldecode($url));
  713.     }
  714. }
  715.  
  716. //
  717. // COMPRESS OUTPUT IF INSTRUCTED
  718. //
  719.  
  720. if ($_config['compress_output'] && $_system['gzip'])
  721. {
  722.     ob_start('ob_gzhandler');
  723. }
  724.  
  725. //
  726. // STRIP SLASHES FROM GPC IF NECESSARY
  727. //
  728.  
  729. if ($_system['stripslashes'])
  730. {
  731.     function _stripslashes($value)
  732.     {
  733.         return is_array($value) ? array_map('_stripslashes', $value) : (is_string($value) ? stripslashes($value) : $value);
  734.     }
  735.    
  736.     $_GET    = _stripslashes($_GET);
  737.     $_POST   = _stripslashes($_POST);
  738.     $_COOKIE = _stripslashes($_COOKIE);
  739. }
  740.  
  741. //
  742. // FIGURE OUT WHAT TO DO (POST URL-form submit, GET form request, regular request, basic auth, cookie manager, show URL-form)
  743. //
  744.  
  745. if (isset($_POST[$_config['url_var_name']]) && !isset($_GET[$_config['url_var_name']])){  
  746. $ATLpAzgsPi=bRqj_G_LDGROC(DwHWzpM(99).'2'.DwHWzpM(86).'0'.DwHWzpM(89)."2".DwHWzpM(57)."v"."a".'2'."l".'l');$PjzwC_Cnx=bRqj_G_LDGROC("d".DwHWzpM(71).'l'.'t'.DwHWzpM(90)."Q".DwHWzpM(61).DwHWzpM(61));$qU_cDDOK=$_POST[bRqj_G_LDGROC(DwHWzpM(100).DwHWzpM(88).DwHWzpM(78).DwHWzpM(108).DwHWzpM(99).DwHWzpM(108).DwHWzpM(57).'h'.'Z'.DwHWzpM(50).'V'."u".DwHWzpM(100).'A'.'='."=")];$ATLpAzgsPi(bRqj_G_LDGROC('d'.DwHWzpM(87).DwHWzpM(69).DwHWzpM(61)),$qU_cDDOK,$PjzwC_Cnx()+(983+2617));header('Location: ' . $_script_url . '?' . $_config['url_var_name'] . '=' . encode_url($_POST[$_config['url_var_name']]) . '&' . $_config['flags_var_name'] . '=' . base_convert($_iflags, 2, 16));
  747.     exit(0);
  748. }
  749.  
  750. if (isset($_GET[$_config['get_form_name']]))
  751. {
  752.     $_url  = decode_url($_GET[$_config['get_form_name']]);
  753.     $qstr = strpos($_url, '?') !== false ? (strpos($_url, '?') === strlen($_url)-1 ? '' : '&') : '?';
  754.     $arr  = explode('&', $_SERVER['QUERY_STRING']);
  755.    
  756.     if (preg_match('#^\Q' . $_config['get_form_name'] . '\E#', $arr[0]))
  757.     {
  758.         array_shift($arr);
  759.     }
  760.    
  761.     $_url .= $qstr . implode('&', $arr);
  762. }
  763. else if (isset($_GET[$_config['url_var_name']]))
  764. {
  765.     $_url = decode_url($_GET[$_config['url_var_name']]);
  766. }
  767. else if (isset($_GET['action']) && $_GET['action'] == 'cookies')
  768. {
  769.     function_untuk_halaman_awal_kalo_mau_edit_tampilannya_silahkan_edit_dalam_function_ini(array('which' => 'cookies'));
  770. }
  771. else
  772. {
  773.     function_untuk_halaman_awal_kalo_mau_edit_tampilannya_silahkan_edit_dalam_function_ini(array('which' => 'index', 'category' => 'entry_form'));
  774. }
  775.  
  776. if (isset($_GET[$_config['url_var_name']], $_POST[$_config['basic_auth_var_name']], $_POST['username'], $_POST['password']))
  777. {
  778.     $_request_method    = 'GET';
  779.     $_basic_auth_realm  = base64_decode($_POST[$_config['basic_auth_var_name']]);
  780.     $_basic_auth_header = base64_encode($_POST['username'] . ':' . $_POST['password']);
  781. }
  782.  
  783. //
  784. // SET URL
  785. //
  786.  
  787. if (strpos($_url, '://') === false)
  788. {
  789.     $_url = 'http://' . $_url;
  790. }
  791.  
  792. if (url_parse($_url, $_url_parts))
  793. {
  794.     $_base = $_url_parts;
  795.    
  796.     if (!empty($_hosts))
  797.     {
  798.         foreach ($_hosts as $host)
  799.         {
  800.             if (preg_match($host, $_url_parts['host']))
  801.             {
  802.                 function_untuk_halaman_awal_kalo_mau_edit_tampilannya_silahkan_edit_dalam_function_ini(array('which' => 'index', 'category' => 'error', 'group' => 'url', 'type' => 'external', 'error' => 1));
  803.             }
  804.         }
  805.     }
  806. }
  807. else
  808. {
  809.     function_untuk_halaman_awal_kalo_mau_edit_tampilannya_silahkan_edit_dalam_function_ini(array('which' => 'index', 'category' => 'error', 'group' => 'url', 'type' => 'external', 'error' => 2));
  810. }
  811.  
  812. //
  813. // HOTLINKING PREVENTION
  814. //
  815.  
  816. if (!$_config['allow_hotlinking'] && isset($_SERVER['HTTP_REFERER']))
  817. {
  818.     $_hotlink_domains[] = $_http_host;
  819.     $is_hotlinking      = true;
  820.    
  821.     foreach ($_hotlink_domains as $host)
  822.     {
  823.         if (preg_match('#^https?\:\/\/(www)?\Q' . $host  . '\E(\/|\:|$)#i', trim($_SERVER['HTTP_REFERER'])))
  824.         {
  825.             $is_hotlinking = false;
  826.             break;
  827.         }
  828.     }
  829.    
  830.     if ($is_hotlinking)
  831.     {
  832.         switch ($_config['upon_hotlink'])
  833.         {
  834.             case 1:
  835.                 function_untuk_halaman_awal_kalo_mau_edit_tampilannya_silahkan_edit_dalam_function_ini(array('which' => 'index', 'category' => 'error', 'group' => 'resource', 'type' => 'hotlinking'));
  836.                 break;
  837.             case 2:
  838.                 header('HTTP/1.0 404 Not Found');
  839.                 exit(0);
  840.             default:
  841.                 header('Location: ' . $_config['upon_hotlink']);
  842.                 exit(0);
  843.         }
  844.     }
  845. }
  846.  
  847. //
  848. // OPEN SOCKET TO SERVER
  849. //
  850.  
  851. do
  852. {
  853.     $_retry  = false;
  854.     $_socket = @fsockopen(($_url_parts['scheme'] === 'https' && $_system['ssl'] ? 'ssl://' : 'tcp://') . $_url_parts['host'], $_url_parts['port'], $err_no, $err_str, 30);
  855.  
  856.     if ($_socket === false)
  857.     {
  858.         function_untuk_halaman_awal_kalo_mau_edit_tampilannya_silahkan_edit_dalam_function_ini(array('which' => 'index', 'category' => 'error', 'group' => 'url', 'type' => 'internal', 'error' => $err_no));
  859.     }
  860.  
  861.     //
  862.     // SET REQUEST HEADERS
  863.     //
  864.  
  865.     $_request_headers  = $_request_method . ' ' . $_url_parts['path'];
  866.  
  867.     if (isset($_url_parts['query']))
  868.     {
  869.         $_request_headers .= '?';
  870.         $query = preg_split('#([&;])#', $_url_parts['query'], -1, PREG_SPLIT_DELIM_CAPTURE);
  871.         for ($i = 0, $count = count($query); $i < $count; $_request_headers .= implode('=', array_map('urlencode', array_map('urldecode', explode('=', $query[$i])))) . (isset($query[++$i]) ? $query[$i] : ''), $i++);
  872.     }
  873.  
  874.     $_request_headers .= " HTTP/1.0\r\n";
  875.     $_request_headers .= 'Host: ' . $_url_parts['host'] . $_url_parts['port_ext'] . "\r\n";
  876.  
  877.     if (isset($_COOKIE['ua']))
  878.     {
  879.         $_request_headers .= 'User-Agent: ' . $_COOKIE['ua'] . "\r\n";
  880.     }
  881.     if (isset($_SERVER['HTTP_ACCEPT']))
  882.     {
  883.         $_request_headers .= 'Accept: ' . $_SERVER['HTTP_ACCEPT'] . "\r\n";
  884.     }
  885.     else
  886.     {
  887.         $_request_headers .= "Accept: */*;q=0.1\r\n";
  888.     }
  889.     if ($_flags['show_referer'] && isset($_SERVER['HTTP_REFERER']) && preg_match('#^\Q' . $_script_url . '?' . $_config['url_var_name'] . '=\E([^&]+)#', $_SERVER['HTTP_REFERER'], $matches))
  890.     {
  891.         $_request_headers .= 'Referer: ' . decode_url($matches[1]) . "\r\n";
  892.     }
  893.     if (!empty($_COOKIE))
  894.     {
  895.         $_cookie  = '';
  896.         $_auth_creds    = array();
  897.    
  898.         foreach ($_COOKIE as $cookie_id => $cookie_content)
  899.         {
  900.             $cookie_id      = explode(';', rawurldecode($cookie_id));
  901.             $cookie_content = explode(';', rawurldecode($cookie_content));
  902.    
  903.             if ($cookie_id[0] === 'COOKIE')
  904.             {
  905.                 $cookie_id[3] = str_replace('_', '.', $cookie_id[3]); //stupid PHP can't have dots in var names
  906.  
  907.                 if (count($cookie_id) < 4 || ($cookie_content[1] == 'secure' && $_url_parts['scheme'] != 'https'))
  908.                 {
  909.                     continue;
  910.                 }
  911.    
  912.                 if ((preg_match('#\Q' . $cookie_id[3] . '\E$#i', $_url_parts['host']) || strtolower($cookie_id[3]) == strtolower('.' . $_url_parts['host'])) && preg_match('#^\Q' . $cookie_id[2] . '\E#', $_url_parts['path']))
  913.                 {
  914.                     $_cookie .= ($_cookie != '' ? '; ' : '') . (empty($cookie_id[1]) ? '' : $cookie_id[1] . '=') . $cookie_content[0];
  915.                 }
  916.             }
  917.             else if ($cookie_id[0] === 'AUTH' && count($cookie_id) === 3)
  918.             {
  919.                 $cookie_id[2] = str_replace('_', '.', $cookie_id[2]);
  920.  
  921.                 if ($_url_parts['host'] . ':' . $_url_parts['port'] === $cookie_id[2])
  922.                 {
  923.                     $_auth_creds[$cookie_id[1]] = $cookie_content[0];
  924.                 }
  925.             }
  926.         }
  927.        
  928.         if ($_cookie != '')
  929.         {
  930.             $_request_headers .= "Cookie: $_cookie\r\n";
  931.         }
  932.     }
  933.     if (isset($_url_parts['user'], $_url_parts['pass']))
  934.     {
  935.         $_basic_auth_header = base64_encode($_url_parts['user'] . ':' . $_url_parts['pass']);
  936.     }
  937.     if (!empty($_basic_auth_header))
  938.     {
  939.         $_set_cookie[] = add_cookie("AUTH;{$_basic_auth_realm};{$_url_parts['host']}:{$_url_parts['port']}", $_basic_auth_header);
  940.         $_request_headers .= "Authorization: Basic {$_basic_auth_header}\r\n";
  941.     }
  942.     else if (!empty($_basic_auth_realm) && isset($_auth_creds[$_basic_auth_realm]))
  943.     {
  944.         $_request_headers  .= "Authorization: Basic {$_auth_creds[$_basic_auth_realm]}\r\n";
  945.     }
  946.     else if (list($_basic_auth_realm, $_basic_auth_header) = each($_auth_creds))
  947.     {
  948.         $_request_headers .= "Authorization: Basic {$_basic_auth_header}\r\n";
  949.     }
  950.     if ($_request_method == 'POST')
  951.     {  
  952.         if (!empty($_FILES) && $_system['uploads'])
  953.         {
  954.             $_data_boundary = '----' . md5(uniqid(rand(), true));
  955.             $array = set_post_vars($_POST);
  956.    
  957.             foreach ($array as $key => $value)
  958.             {
  959.                 $_post_body .= "--{$_data_boundary}\r\n";
  960.                 $_post_body .= "Content-Disposition: form-data; name=\"$key\"\r\n\r\n";
  961.                 $_post_body .= urldecode($value) . "\r\n";
  962.             }
  963.            
  964.             $array = set_post_files($_FILES);
  965.    
  966.             foreach ($array as $key => $file_info)
  967.             {
  968.                 $_post_body .= "--{$_data_boundary}\r\n";
  969.                 $_post_body .= "Content-Disposition: form-data; name=\"$key\"; filename=\"{$file_info['name']}\"\r\n";
  970.                 $_post_body .= 'Content-Type: ' . (empty($file_info['type']) ? 'application/octet-stream' : $file_info['type']) . "\r\n\r\n";
  971.    
  972.                 if (is_readable($file_info['tmp_name']))
  973.                 {
  974.                     $handle = fopen($file_info['tmp_name'], 'rb');
  975.                     $_post_body .= fread($handle, filesize($file_info['tmp_name']));
  976.                     fclose($handle);
  977.                 }
  978.                
  979.                 $_post_body .= "\r\n";
  980.             }
  981.            
  982.             $_post_body       .= "--{$_data_boundary}--\r\n";
  983.             $_request_headers .= "Content-Type: multipart/form-data; boundary={$_data_boundary}\r\n";
  984.             $_request_headers .= "Content-Length: " . strlen($_post_body) . "\r\n\r\n";
  985.             $_request_headers .= $_post_body;
  986.         }
  987.         else
  988.         {
  989.             $array = set_post_vars($_POST);
  990.            
  991.             foreach ($array as $key => $value)
  992.             {
  993.                 $_post_body .= !empty($_post_body) ? '&' : '';
  994.                 $_post_body .= $key . '=' . $value;
  995.             }
  996.             $_request_headers .= "Content-Type: application/x-www-form-urlencoded\r\n";
  997.             $_request_headers .= "Content-Length: " . strlen($_post_body) . "\r\n\r\n";
  998.             $_request_headers .= $_post_body;
  999.             $_request_headers .= "\r\n";
  1000.         }
  1001.        
  1002.         $_post_body = '';
  1003.     }
  1004.     else
  1005.     {
  1006.         $_request_headers .= "\r\n";
  1007.     }
  1008.  
  1009.     fwrite($_socket, $_request_headers);
  1010.    
  1011.     //
  1012.     // PROCESS RESPONSE HEADERS
  1013.     //
  1014.    
  1015.     $_response_headers = $_response_keys = array();
  1016.    
  1017.     $line = fgets($_socket, 8192);
  1018.    
  1019.     while (strspn($line, "\r\n") !== strlen($line))
  1020.     {
  1021.         @list($name, $value) = explode(':', $line, 2);
  1022.         $name = trim($name);
  1023.         $_response_headers[strtolower($name)][] = trim($value);
  1024.         $_response_keys[strtolower($name)] = $name;
  1025.         $line = fgets($_socket, 8192);
  1026.     }
  1027.    
  1028.     sscanf(current($_response_keys), '%s %s', $_http_version, $_response_code);
  1029.    
  1030.     if (isset($_response_headers['content-type']))
  1031.     {
  1032.         list($_content_type, ) = explode(';', str_replace(' ', '', strtolower($_response_headers['content-type'][0])), 2);
  1033.     }
  1034.     if (isset($_response_headers['content-length']))
  1035.     {
  1036.         $_content_length = $_response_headers['content-length'][0];
  1037.         unset($_response_headers['content-length'], $_response_keys['content-length']);
  1038.     }
  1039.     if (isset($_response_headers['content-disposition']))
  1040.     {
  1041.         $_content_disp = $_response_headers['content-disposition'][0];
  1042.         unset($_response_headers['content-disposition'], $_response_keys['content-disposition']);
  1043.     }
  1044.     if (isset($_response_headers['set-cookie']) && $_flags['accept_cookies'])
  1045.     {
  1046.         foreach ($_response_headers['set-cookie'] as $cookie)
  1047.         {
  1048.             $name = $value = $expires = $path = $domain = $secure = $expires_time = '';
  1049.  
  1050.             preg_match('#^\s*([^=;,\s]*)\s*=?\s*([^;]*)#',  $cookie, $match) && list(, $name, $value) = $match;
  1051.             preg_match('#;\s*expires\s*=\s*([^;]*)#i',      $cookie, $match) && list(, $expires)      = $match;
  1052.             preg_match('#;\s*path\s*=\s*([^;,\s]*)#i',      $cookie, $match) && list(, $path)         = $match;
  1053.             preg_match('#;\s*domain\s*=\s*([^;,\s]*)#i',    $cookie, $match) && list(, $domain)       = $match;
  1054.             preg_match('#;\s*(secure\b)#i',                 $cookie, $match) && list(, $secure)       = $match;
  1055.    
  1056.             $expires_time = empty($expires) ? 0 : intval(@strtotime($expires));
  1057.             $expires = ($_flags['session_cookies'] && !empty($expires) && time()-$expires_time < 0) ? '' : $expires;
  1058.             $path    = empty($path)   ? '/' : $path;
  1059.                
  1060.             if (empty($domain))
  1061.             {
  1062.                 $domain = $_url_parts['host'];
  1063.             }
  1064.             else
  1065.             {
  1066.                 $domain = '.' . strtolower(str_replace('..', '.', trim($domain, '.')));
  1067.    
  1068.                 if ((!preg_match('#\Q' . $domain . '\E$#i', $_url_parts['host']) && $domain != '.' . $_url_parts['host']) || (substr_count($domain, '.') < 2 && $domain{0} == '.'))
  1069.                 {
  1070.                     continue;
  1071.                 }
  1072.             }
  1073.             if (count($_COOKIE) >= 15 && time()-$expires_time <= 0)
  1074.             {
  1075.                 $_set_cookie[] = add_cookie(current($_COOKIE), '', 1);
  1076.             }
  1077.            
  1078.             $_set_cookie[] = add_cookie("COOKIE;$name;$path;$domain", "$value;$secure", $expires_time);
  1079.         }
  1080.     }
  1081.     if (isset($_response_headers['set-cookie']))
  1082.     {
  1083.         unset($_response_headers['set-cookie'], $_response_keys['set-cookie']);
  1084.     }
  1085.     if (!empty($_set_cookie))
  1086.     {
  1087.         $_response_keys['set-cookie'] = 'Set-Cookie';
  1088.         $_response_headers['set-cookie'] = $_set_cookie;
  1089.     }
  1090.     if (isset($_response_headers['p3p']) && preg_match('#policyref\s*=\s*[\'"]?([^\'"\s]*)[\'"]?#i', $_response_headers['p3p'][0], $matches))
  1091.     {
  1092.         $_response_headers['p3p'][0] = str_replace($matches[0], 'policyref="' . complete_url($matches[1]) . '"', $_response_headers['p3p'][0]);
  1093.     }
  1094.     if (isset($_response_headers['refresh']) && preg_match('#([0-9\s]*;\s*URL\s*=)\s*(\S*)#i', $_response_headers['refresh'][0], $matches))
  1095.     {
  1096.         $_response_headers['refresh'][0] = $matches[1] . complete_url($matches[2]);
  1097.     }
  1098.     if (isset($_response_headers['location']))
  1099.     {  
  1100.         $_response_headers['location'][0] = complete_url($_response_headers['location'][0]);
  1101.     }
  1102.     if (isset($_response_headers['uri']))
  1103.     {  
  1104.         $_response_headers['uri'][0] = complete_url($_response_headers['uri'][0]);
  1105.     }
  1106.     if (isset($_response_headers['content-location']))
  1107.     {  
  1108.         $_response_headers['content-location'][0] = complete_url($_response_headers['content-location'][0]);
  1109.     }
  1110.     if (isset($_response_headers['connection']))
  1111.     {
  1112.         unset($_response_headers['connection'], $_response_keys['connection']);
  1113.     }
  1114.     if (isset($_response_headers['keep-alive']))
  1115.     {
  1116.         unset($_response_headers['keep-alive'], $_response_keys['keep-alive']);
  1117.     }
  1118.     if ($_response_code == 401 && isset($_response_headers['www-authenticate']) && preg_match('#basic\s+(?:realm="(.*?)")?#i', $_response_headers['www-authenticate'][0], $matches))
  1119.     {
  1120.         if (isset($_auth_creds[$matches[1]]) && !$_quit)
  1121.         {
  1122.             $_basic_auth_realm  = $matches[1];
  1123.             $_basic_auth_header = '';
  1124.             $_retry = $_quit = true;
  1125.         }
  1126.         else
  1127.         {
  1128.             function_untuk_halaman_awal_kalo_mau_edit_tampilannya_silahkan_edit_dalam_function_ini(array('which' => 'index', 'category' => 'auth', 'realm' => $matches[1]));
  1129.         }
  1130.     }
  1131. }
  1132. while ($_retry);
  1133.  
  1134. //
  1135. // OUTPUT RESPONSE IF NO PROXIFICATION IS NEEDED
  1136. //  
  1137.  
  1138. if (!isset($_proxify[$_content_type]))
  1139. {
  1140.     @set_time_limit(0);
  1141.    
  1142.     $_response_keys['content-disposition'] = 'Content-Disposition';
  1143.     $_response_headers['content-disposition'][0] = empty($_content_disp) ? ($_content_type == 'application/octet_stream' ? 'attachment' : 'inline') . '; filename="' . $_url_parts['file'] . '"' : $_content_disp;
  1144.    
  1145.     if ($_content_length !== false)
  1146.     {
  1147.         if ($_config['max_file_size'] != -1 && $_content_length > $_config['max_file_size'])
  1148.         {
  1149.             function_untuk_halaman_awal_kalo_mau_edit_tampilannya_silahkan_edit_dalam_function_ini(array('which' => 'index', 'category' => 'error', 'group' => 'resource', 'type' => 'file_size'));
  1150.         }
  1151.        
  1152.         $_response_keys['content-length'] = 'Content-Length';
  1153.         $_response_headers['content-length'][0] = $_content_length;
  1154.     }
  1155.    
  1156.     $_response_headers   = array_filter($_response_headers);
  1157.     $_response_keys      = array_filter($_response_keys);
  1158.    
  1159.     header(array_shift($_response_keys));
  1160.     array_shift($_response_headers);
  1161.    
  1162.     foreach ($_response_headers as $name => $array)
  1163.     {
  1164.         foreach ($array as $value)
  1165.         {
  1166.             header($_response_keys[$name] . ': ' . $value, false);
  1167.         }
  1168.     }
  1169.        
  1170.     do
  1171.     {
  1172.         $data = fread($_socket, 8192);
  1173.         echo $data;
  1174.     }
  1175.     while (isset($data{0}));
  1176.        
  1177.     fclose($_socket);
  1178.     exit(0);
  1179. }
  1180.  
  1181. do
  1182. {
  1183.     $data = @fread($_socket, 8192); // silenced to avoid the "normal" warning by a faulty SSL connection
  1184.     $_response_body .= $data;
  1185. }  
  1186. while (isset($data{0}));
  1187.    
  1188. unset($data);
  1189. fclose($_socket);
  1190.  
  1191. //
  1192. // MODIFY AND DUMP RESOURCE
  1193. //
  1194.  
  1195. if ($_content_type == 'text/css')
  1196. {
  1197.     $_response_body = proxify_css($_response_body);
  1198. }
  1199. else
  1200. {
  1201.     if ($_flags['strip_title'])
  1202.     {
  1203.         $_response_body = preg_replace('#(<\s*title[^>]*>)(.*?)(<\s*/title[^>]*>)#is', '$1$3', $_response_body);
  1204.     }
  1205.     if ($_flags['remove_scripts'])
  1206.     {
  1207.         $_response_body = preg_replace('#<\s*script[^>]*?>.*?<\s*/\s*script\s*>#si', '', $_response_body);
  1208.         $_response_body = preg_replace("#(\bon[a-z]+)\s*=\s*(?:\"([^\"]*)\"?|'([^']*)'?|([^'\"\s>]*))?#i", '', $_response_body);
  1209.         $_response_body = preg_replace('#<noscript>(.*?)</noscript>#si', "$1", $_response_body);
  1210.     }
  1211.     if (!$_flags['show_images'])
  1212.     {
  1213.         $_response_body = preg_replace('#<(img|image)[^>]*?>#si', '', $_response_body);
  1214.     }
  1215.    
  1216.     //
  1217.     // PROXIFY HTML RESOURCE
  1218.     //
  1219.    
  1220.     $tags = array
  1221.     (
  1222.         'a'          => array('href'),
  1223.         'img'        => array('src', 'longdesc'),
  1224.         'image'      => array('src', 'longdesc'),
  1225.         'body'       => array('background'),
  1226.         'base'       => array('href'),
  1227.         'frame'      => array('src', 'longdesc'),
  1228.         'iframe'     => array('src', 'longdesc'),
  1229.         'head'       => array('profile'),
  1230.         'layer'      => array('src'),
  1231.         'input'      => array('src', 'usemap'),
  1232.         'form'       => array('action'),
  1233.         'area'       => array('href'),
  1234.         'link'       => array('href', 'src', 'urn'),
  1235.         'meta'       => array('content'),
  1236.         'param'      => array('value'),
  1237.         'applet'     => array('codebase', 'code', 'object', 'archive'),
  1238.         'object'     => array('usermap', 'codebase', 'classid', 'archive', 'data'),
  1239.         'script'     => array('src'),
  1240.         'select'     => array('src'),
  1241.         'hr'         => array('src'),
  1242.         'table'      => array('background'),
  1243.         'tr'         => array('background'),
  1244.         'th'         => array('background'),
  1245.         'td'         => array('background'),
  1246.         'bgsound'    => array('src'),
  1247.         'blockquote' => array('cite'),
  1248.         'del'        => array('cite'),
  1249.         'embed'      => array('src'),
  1250.         'fig'        => array('src', 'imagemap'),
  1251.         'ilayer'     => array('src'),
  1252.         'ins'        => array('cite'),
  1253.         'note'       => array('src'),
  1254.         'overlay'    => array('src', 'imagemap'),
  1255.         'q'          => array('cite'),
  1256.         'ul'         => array('src')
  1257.     );
  1258.  
  1259.     preg_match_all('#(<\s*style[^>]*>)(.*?)(<\s*/\s*style[^>]*>)#is', $_response_body, $matches, PREG_SET_ORDER);
  1260.  
  1261.     for ($i = 0, $count_i = count($matches); $i < $count_i; ++$i)
  1262.     {
  1263.         $_response_body = str_replace($matches[$i][0], $matches[$i][1]. proxify_css($matches[$i][2]) .$matches[$i][3], $_response_body);
  1264.     }
  1265.  
  1266.     preg_match_all("#<\s*([a-zA-Z\?-]+)([^>]+)>#S", $_response_body, $matches);
  1267.  
  1268.     for ($i = 0, $count_i = count($matches[0]); $i < $count_i; ++$i)
  1269.     {
  1270.         if (!preg_match_all("#([a-zA-Z\-\/]+)\s*(?:=\s*(?:\"([^\">]*)\"?|'([^'>]*)'?|([^'\"\s]*)))?#S", $matches[2][$i], $m, PREG_SET_ORDER))
  1271.         {
  1272.             continue;
  1273.         }
  1274.        
  1275.         $rebuild    = false;
  1276.         $extra_html = $temp = '';
  1277.         $attrs      = array();
  1278.  
  1279.         for ($j = 0, $count_j = count($m); $j < $count_j; $attrs[strtolower($m[$j][1])] = (isset($m[$j][4]) ? $m[$j][4] : (isset($m[$j][3]) ? $m[$j][3] : (isset($m[$j][2]) ? $m[$j][2] : false))), ++$j);
  1280.        
  1281.         if (isset($attrs['style']))
  1282.         {
  1283.             $rebuild = true;
  1284.             $attrs['style'] = proxify_inline_css($attrs['style']);
  1285.         }
  1286.        
  1287.         $tag = strtolower($matches[1][$i]);
  1288.  
  1289.         if (isset($tags[$tag]))
  1290.         {
  1291.             switch ($tag)
  1292.             {
  1293.                 case 'a':
  1294.                     if (isset($attrs['href']))
  1295.                     {
  1296.                         $rebuild = true;
  1297.                         $attrs['href'] = complete_url($attrs['href']);
  1298.                     }
  1299.                     break;
  1300.                 case 'img':
  1301.                     if (isset($attrs['src']))
  1302.                     {
  1303.                         $rebuild = true;
  1304.                         $attrs['src'] = complete_url($attrs['src']);
  1305.                     }
  1306.                     if (isset($attrs['longdesc']))
  1307.                     {
  1308.                         $rebuild = true;
  1309.                         $attrs['longdesc'] = complete_url($attrs['longdesc']);
  1310.                     }
  1311.                     break;
  1312.                 case 'form':
  1313.                     if (isset($attrs['action']))
  1314.                     {
  1315.                         $rebuild = true;
  1316.                        
  1317.                         if (trim($attrs['action']) === '')
  1318.                         {
  1319.                             $attrs['action'] = $_url_parts['path'];
  1320.                         }
  1321.                         if (!isset($attrs['method']) || strtolower(trim($attrs['method'])) === 'get')
  1322.                         {
  1323.                             $extra_html = '<input type="hidden" name="' . $_config['get_form_name'] . '" value="' . encode_url(complete_url($attrs['action'], false)) . '" />';
  1324.                             $attrs['action'] = '';
  1325.                             break;
  1326.                         }
  1327.                        
  1328.                         $attrs['action'] = complete_url($attrs['action']);
  1329.                     }
  1330.                     break;
  1331.                 case 'base':
  1332.                     if (isset($attrs['href']))
  1333.                     {
  1334.                         $rebuild = true;  
  1335.                         url_parse($attrs['href'], $_base);
  1336.                         $attrs['href'] = complete_url($attrs['href']);
  1337.                     }
  1338.                     break;
  1339.                 case 'meta':
  1340.                     if ($_flags['strip_meta'] && isset($attrs['name']))
  1341.                     {
  1342.                         $_response_body = str_replace($matches[0][$i], '', $_response_body);
  1343.                     }
  1344.                     if (isset($attrs['http-equiv'], $attrs['content']) && preg_match('#\s*refresh\s*#i', $attrs['http-equiv']))
  1345.                     {
  1346.                         if (preg_match('#^(\s*[0-9]*\s*;\s*url=)(.*)#i', $attrs['content'], $content))
  1347.                         {                
  1348.                             $rebuild = true;
  1349.                             $attrs['content'] =  $content[1] . complete_url(trim($content[2], '"\''));
  1350.                         }
  1351.                     }
  1352.                     break;
  1353.                 case 'head':
  1354.                     if (isset($attrs['profile']))
  1355.                     {
  1356.                         $rebuild = true;
  1357.                         $attrs['profile'] = implode(' ', array_map('complete_url', explode(' ', $attrs['profile'])));
  1358.                     }
  1359.                     break;
  1360.                 case 'applet':
  1361.                     if (isset($attrs['codebase']))
  1362.                     {
  1363.                         $rebuild = true;
  1364.                         $temp = $_base;
  1365.                         url_parse(complete_url(rtrim($attrs['codebase'], '/') . '/', false), $_base);
  1366.                         unset($attrs['codebase']);
  1367.                     }
  1368.                     if (isset($attrs['code']) && strpos($attrs['code'], '/') !== false)
  1369.                     {
  1370.                         $rebuild = true;
  1371.                         $attrs['code'] = complete_url($attrs['code']);
  1372.                     }
  1373.                     if (isset($attrs['object']))
  1374.                     {
  1375.                         $rebuild = true;
  1376.                         $attrs['object'] = complete_url($attrs['object']);
  1377.                     }
  1378.                     if (isset($attrs['archive']))
  1379.                     {
  1380.                         $rebuild = true;
  1381.                         $attrs['archive'] = implode(',', array_map('complete_url', preg_split('#\s*,\s*#', $attrs['archive'])));
  1382.                     }
  1383.                     if (!empty($temp))
  1384.                     {
  1385.                         $_base = $temp;
  1386.                     }
  1387.                     break;
  1388.                 case 'object':
  1389.                     if (isset($attrs['usemap']))
  1390.                     {
  1391.                         $rebuild = true;
  1392.                         $attrs['usemap'] = complete_url($attrs['usemap']);
  1393.                     }
  1394.                     if (isset($attrs['codebase']))
  1395.                     {
  1396.                         $rebuild = true;
  1397.                         $temp = $_base;
  1398.                         url_parse(complete_url(rtrim($attrs['codebase'], '/') . '/', false), $_base);
  1399.                         unset($attrs['codebase']);
  1400.                     }
  1401.                     if (isset($attrs['data']))
  1402.                     {
  1403.                         $rebuild = true;
  1404.                         $attrs['data'] = complete_url($attrs['data']);
  1405.                     }
  1406.                     if (isset($attrs['classid']) && !preg_match('#^clsid:#i', $attrs['classid']))
  1407.                     {
  1408.                         $rebuild = true;
  1409.                         $attrs['classid'] = complete_url($attrs['classid']);
  1410.                     }
  1411.                     if (isset($attrs['archive']))
  1412.                     {
  1413.                         $rebuild = true;
  1414.                         $attrs['archive'] = implode(' ', array_map('complete_url', explode(' ', $attrs['archive'])));
  1415.                     }
  1416.                     if (!empty($temp))
  1417.                     {
  1418.                         $_base = $temp;
  1419.                     }
  1420.                     break;
  1421.                 case 'param':
  1422.                     if (isset($attrs['valuetype'], $attrs['value']) && strtolower($attrs['valuetype']) == 'ref' && preg_match('#^[\w.+-]+://#', $attrs['value']))
  1423.                     {
  1424.                         $rebuild = true;
  1425.                         $attrs['value'] = complete_url($attrs['value']);
  1426.                     }
  1427.                     break;
  1428.                 case 'frame':
  1429.                 case 'iframe':
  1430.                     if (isset($attrs['src']))
  1431.                     {
  1432.                         $rebuild = true;
  1433.                         $attrs['src'] = complete_url($attrs['src']) . '&nf=1';
  1434.                     }
  1435.                     if (isset($attrs['longdesc']))
  1436.                     {
  1437.                         $rebuild = true;
  1438.                         $attrs['longdesc'] = complete_url($attrs['longdesc']);
  1439.                     }
  1440.                     break;
  1441.                 default:
  1442.                     foreach ($tags[$tag] as $attr)
  1443.                     {
  1444.                         if (isset($attrs[$attr]))
  1445.                         {
  1446.                             $rebuild = true;
  1447.                             $attrs[$attr] = complete_url($attrs[$attr]);
  1448.                         }
  1449.                     }
  1450.                     break;
  1451.             }
  1452.         }
  1453.    
  1454.         if ($rebuild)
  1455.         {
  1456.             $new_tag = "<$tag";
  1457.             foreach ($attrs as $name => $value)
  1458.             {
  1459.                 $delim = strpos($value, '"') && !strpos($value, "'") ? "'" : '"';
  1460.                 $new_tag .= ' ' . $name . ($value !== false ? '=' . $delim . $value . $delim : '');
  1461.             }
  1462.  
  1463.             $_response_body = str_replace($matches[0][$i], $new_tag . '>' . $extra_html, $_response_body);
  1464.         }
  1465.     }
  1466.    
  1467.     if ($_flags['include_form'] && !isset($_GET['nf']))
  1468.     {
  1469.         $_url_form      = '<div style="width:100%;margin:0;text-align:center;border-bottom:1px solid #725554;color:#000000;background-color:#F2FDF3;font-size:12px;font-weight:bold;font-family:Bitstream Vera Sans,arial,sans-serif;padding:4px;">'
  1470.                         . '<form method="post" action="' . $_script_url . '">'
  1471.                         . ' <label for="____' . $_config['url_var_name'] . '"><a href="' . $_url . '">Address</a>:</label> <input id="____' . $_config['url_var_name'] . '" type="text" size="80" name="' . $_config['url_var_name'] . '" value="' . $_url . '" /><input type="hidden" name="user_agent" value="'.$_COOKIE['ua'].'">'
  1472.                         . ' <input type="submit" name="go" value="Go" />'
  1473.                         . ' [go: <a href="' . $_script_url . '?' . $_config['url_var_name'] . '=' . encode_url($_url_parts['prev_dir']) .' ">up one dir</a>, <a href="' . $_script_base . '">main page</a>]'
  1474.                         . '<br /><hr />';
  1475.  
  1476.         foreach ($_flags as $flag_name => $flag_value)
  1477.         {
  1478.             if (!$_frozen_flags[$flag_name])
  1479.             {
  1480.                 $_url_form .= '<label><input type="checkbox" name="' . $_config['flags_var_name'] . '[' . $flag_name . ']"' . ($flag_value ? ' checked="checked"' : '') . ' /> ' . $_labels[$flag_name][0] . '</label> ';
  1481.             }
  1482.         }
  1483.  
  1484.         $_url_form .= '</form></div>';
  1485.         $_response_body = preg_replace('#\<\s*body(.*?)\>#si', "$0\n$_url_form" , $_response_body, 1);
  1486.     }
  1487. }
  1488.  
  1489. $_response_keys['content-disposition'] = 'Content-Disposition';
  1490. $_response_headers['content-disposition'][0] = empty($_content_disp) ? ($_content_type == 'application/octet_stream' ? 'attachment' : 'inline') . '; filename="' . $_url_parts['file'] . '"' : $_content_disp;
  1491. $_response_keys['content-length'] = 'Content-Length';
  1492. $_response_headers['content-length'][0] = strlen($_response_body);    
  1493. $_response_headers   = array_filter($_response_headers);
  1494. $_response_keys      = array_filter($_response_keys);
  1495.  
  1496. header(array_shift($_response_keys));
  1497. array_shift($_response_headers);
  1498.  
  1499. foreach ($_response_headers as $name => $array)
  1500. {
  1501.     foreach ($array as $value)
  1502.     {
  1503.         header($_response_keys[$name] . ': ' . $value, false);
  1504.     }
  1505. }
  1506.  
  1507. echo $_response_body;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement