Schupp

Curl Fritzbox

Jan 7th, 2019
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1.  <?
  2.  
  3. if($_IPS['SENDER'] == "Execute")
  4. {
  5.     $fritzbox_ip = 'fritz.box';
  6.     $password    = 'xxxxx';
  7.  
  8.     $ch = curl_init('http://' . $fritzbox_ip . '/cgi-bin/webcm?getpage=../html/login_sid.xml');
  9.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  10.     $login = curl_exec($ch);
  11.     $session_status_simplexml = simplexml_load_string($login);
  12.  
  13.     if ($session_status_simplexml->iswriteaccess == 1)
  14.     {
  15.        $SID = $session_status_simplexml->SID;
  16.     }
  17.     else
  18.     {
  19.        $challenge = $session_status_simplexml->Challenge;
  20.        $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $password, "UCS-2LE", "UTF-8"));
  21.         curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/response={$response}&getpage=../html/de/menus/menu2.html");
  22.         preg_match('/name="sid" value="([0-9a-f]*)"/', curl_exec($ch), $matches);
  23.        if(isset($matches[1]) && $matches[1] != '0000000000000000')
  24.        {
  25.           $SID = $matches[1];
  26.        }
  27.        else
  28.        {
  29.           echo "Fehler: Login fehlgeschlagen";
  30.           return;
  31.         }
  32.         curl_setopt($ch, CURLOPT_POSTFIELDS, "sid={$SID}&telcfg:settings/DialPort=60"); // Nebenstellennummer eintragen!
  33.         curl_exec($ch);
  34.         curl_setopt($ch, CURLOPT_POSTFIELDS, "sid={$SID}&telcfg:command/Dial=**612"); // Rufnummer eintragen!
  35.         curl_exec($ch);
  36.         curl_close($ch);
  37.     }
  38. }
  39.  
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment