Scripts für Fritzbox/Repeater/Fritzfon ab V2.5 und PHP 5.4.x

Ab Version 2.5 gibt es einige Neuerungen. In diesem Zusammenhang hab ich die Scripts umgeschrieben.

[b]Scripts ab Version sind mit „Ab V2.5“ gekennzeichnet. Alle anderen sollten normal laufen.

[/b]Für einige Scripts werden 2 Extension benötigt. php_curl.dll und php_mbstring.dll

Für Fragen, macht bitte einen eigenen Thread auf. Wer Scripts beisteuern will, nur zu. Ich füge sie gerne ein. :wink:

Extension.zip (641 KB)

<?
$fritzbox_ip = 'fritz.box'; // Name oder IP eintragen
$password    = 'xxxxx'; // Passwort eintragen

$ch = curl_init('http://' . $fritzbox_ip . '/cgi-bin/webcm?getpage=../html/login_sid.xml');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$login = curl_exec($ch);
$session_status_simplexml = simplexml_load_string($login);


if ($session_status_simplexml->iswriteaccess == 1)
{
   $SID = $session_status_simplexml->SID;
}
else
{
   $challenge = $session_status_simplexml->Challenge;
   $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $password, "UCS-2LE", "UTF-8"));
    curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/response={$response}&getpage=../html/de/menus/menu2.html");
    preg_match('/name="sid" value="([0-9a-f]*)"/', curl_exec($ch), $matches);
   if (isset($matches[1]) && $matches[1] != '0000000000000000')
   {
      $SID = $matches[1];
   }
   else
   {
      echo "Fehler: Login fehlgeschlagen";
      return;
    }
}
curl_close($ch);

// Log auslesen. Das gewünschte Log aktiviren.

//$log = file("http://fritz.box/system/syslog.lua?tab=telefon&sid=".$SID); // Telefonie
//$log = file("http://fritz.box/system/syslog.lua?tab=usb&sid=".$SID); // USB-Geräte
//$log = file("http://fritz.box/system/syslog.lua?tab=internet&sid=".$SID); // Internetverbindung
//$log = file("http://fritz.box/system/syslog.lua?tab=system&sid=".$SID); // System
$log = file("http://fritz.box/system/syslog.lua?tab=wlan&sid=".$SID); // Wlan

print_r(utf8_decode($log)); // Ausgabe zum weiterverarbeiten

?>
<?
ini_set("max_execution_time", 15);

if($_IPS['SENDER'] == "Variable" || $_IPS['SENDER'] == "Execute")
{
    $fritzbox_ip = 'fritz.box'; // Name oder IP eingeben
    $fritzCfg    = 'http://fritz.box/cgi-bin/firmwarecfg';
    $telefonbuch = 2; // Auswahl des Telefonbuches
    $password    = 'xxxxx';

    $ch = curl_init('http://' . $fritzbox_ip . '/cgi-bin/webcm?getpage=../html/login_sid.xml');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $login = curl_exec($ch);
    $session_status_simplexml = simplexml_load_string($login);

    if ($session_status_simplexml->iswriteaccess == 1)
    {
       $SID = $session_status_simplexml->SID;
    }
    else
    {
       $challenge = $session_status_simplexml->Challenge;
       $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $password, "UCS-2LE", "UTF-8"));
        curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/response={$response}&getpage=../html/de/menus/menu2.html");
        preg_match('/name="sid" value="([0-9a-f]*)"/', curl_exec($ch), $matches);
       if (isset($matches[1]) && $matches[1] != '0000000000000000')
       {
          $SID = $matches[1];
       }
       else
       {
          echo "Fehler: Login fehlgeschlagen";
          return;
        }
    }

    curl_setopt($ch, CURLOPT_URL, $fritzCfg);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array("sid" => $SID, "PhonebookId" => $telefonbuch, "PhonebookExportName" => "Telefonbuch", "PhonebookExport" => ""));
    $book = curl_exec($ch);
   curl_close($ch);
}

$xml = simplexml_load_string($book);

foreach($xml->phonebook->contact as $nummer => $value)
{
    $nummer0 = $value->telephony->number[0]."
";
   $nummer1 = $value->telephony->number[1]."
";
   $nummer2 = $value->telephony->number[2]."
";
    $namen = $value->person->realName."
";
    $daten[] = array(trim($nummer0),trim($nummer1),trim($nummer2),trim($namen));
}
//print_r($daten);
$rufnummer = GetValue(30553 /*[Fritzbox\Anrufe\Anruf]*/); // Nummer vom Anrufer, Variable z.B. mit GetValue und Trigger auf das Script

for($i=0; $i<count($daten); $i++)
{
    if(($daten[$i][0] == $rufnummer) || ($daten[$i][1] == $rufnummer) || ($daten[$i][2] == $rufnummer))
    {
        SetValue(10528 /*[Fritzbox\Anrufe\Name]*/, utf8_decode($daten[$i][3])); // Ausgabe des Namen, z.B in Variable schreiben mit SetValue(xxxxx, utf8_decode($daten[$i][3]));
        echo utf8_decode($daten[$i][3]);
    }
}

?>
<?
if($_IPS['SENDER'] == "WebFront")
{
    $fritzbox_ip = 'fritz.box';
    $password    = 'xxxxxx';
    $ein         = '1';
    $aus         = '0';

    $ch = curl_init('http://' . $fritzbox_ip . '/cgi-bin/webcm?getpage=../html/login_sid.xml');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $login = curl_exec($ch);
    $session_status_simplexml = simplexml_load_string($login);

    if ($session_status_simplexml->iswriteaccess == 1)
    {
       $SID = $session_status_simplexml->SID;
    }
    else
    {
       $challenge = $session_status_simplexml->Challenge;
       $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $password, "UCS-2LE", "UTF-8"));
        curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/response={$response}&getpage=../html/de/menus/menu2.html");
        preg_match('/name="sid" value="([0-9a-f]*)"/', curl_exec($ch), $matches);
       if(isset($matches[1]) && $matches[1] != '0000000000000000')
       {
          $SID = $matches[1];
       }
       else
       {
          echo "Fehler: Login fehlgeschlagen";
          return;
        }
    }

    if($_IPS['VALUE'])
    {
        curl_setopt($ch, CURLOPT_POSTFIELDS, "sid={$SID}&tam:settings/TAM1/Active={$ein}");
        curl_exec($ch);
    }
    else
    {
       curl_setopt($ch, CURLOPT_POSTFIELDS, "sid={$SID}&tam:settings/TAM1/Active={$aus}");
       curl_exec($ch);
    }
    curl_close($ch);
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
}

?>
<?
if($_IPS['SENDER'] == "WebFront")
{
    $fritzbox_ip = 'fritz.box';
    $password    = 'xxxxxx';
    $ein         = '1';
    $aus         = '0';

    $ch = curl_init('http://' . $fritzbox_ip . '/cgi-bin/webcm?getpage=../html/login_sid.xml');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $login = curl_exec($ch);
    $session_status_simplexml = simplexml_load_string($login);

    if ($session_status_simplexml->iswriteaccess == 1)
    {
       $SID = $session_status_simplexml->SID;
    }
    else
    {
       $challenge = $session_status_simplexml->Challenge;
       $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $password, "UCS-2LE", "UTF-8"));
        curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/response={$response}&getpage=../html/de/menus/menu2.html");
        preg_match('/name="sid" value="([0-9a-f]*)"/', curl_exec($ch), $matches);
       if(isset($matches[1]) && $matches[1] != '0000000000000000')
       {
          $SID = $matches[1];
       }
       else
       {
          echo "Fehler: Login fehlgeschlagen";
          return;
        }
    }

    if($_IPS['VALUE'])
    {
        curl_setopt($ch, CURLOPT_POSTFIELDS, "sid={$SID}&wlan:settings/ap_enabled={$ein}");
        curl_exec($ch);
    }
    else
    {
       curl_setopt($ch, CURLOPT_POSTFIELDS, "sid={$SID}&wlan:settings/ap_enabled={$aus}");
       curl_exec($ch);
    }
    curl_close($ch);
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
}

?>
<?
if($_IPS['SENDER'] == "WebFront")
{
    $fritzbox_ip = 'fritz.box';
    $password    = 'xxxxx';
    $ein         = '1';
    $aus         = '0';

    $ch = curl_init('http://' . $fritzbox_ip . '/cgi-bin/webcm?getpage=../html/login_sid.xml');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $login = curl_exec($ch);
    $session_status_simplexml = simplexml_load_string($login);

    if ($session_status_simplexml->iswriteaccess == 1)
    {
       $SID = $session_status_simplexml->SID;
    }
    else
    {
       $challenge = $session_status_simplexml->Challenge;
       $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $password, "UCS-2LE", "UTF-8"));
        curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/response={$response}&getpage=../html/de/menus/menu2.html");
        preg_match('/name="sid" value="([0-9a-f]*)"/', curl_exec($ch), $matches);
       if(isset($matches[1]) && $matches[1] != '0000000000000000')
       {
          $SID = $matches[1];
       }
       else
       {
          echo "Fehler: Login fehlgeschlagen";
          return;
        }
    }

    if($_IPS['VALUE'])
    {
        curl_setopt($ch, CURLOPT_POSTFIELDS, "sid={$SID}&aura:settings/enabled={$ein}");
        curl_exec($ch);
    }
    else
    {
       curl_setopt($ch, CURLOPT_POSTFIELDS, "sid={$SID}&aura:settings/enabled={$aus}");
       curl_exec($ch);
    }
    curl_close($ch);
    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
}

?>
<?

if($_IPS['SENDER'] == "Execute")
{
    $fritzbox_ip = 'fritz.box';
    $password    = 'xxxxx';

    $ch = curl_init('http://' . $fritzbox_ip . '/cgi-bin/webcm?getpage=../html/login_sid.xml');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $login = curl_exec($ch);
    $session_status_simplexml = simplexml_load_string($login);

    if ($session_status_simplexml->iswriteaccess == 1)
    {
       $SID = $session_status_simplexml->SID;
    }
    else
    {
       $challenge = $session_status_simplexml->Challenge;
       $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $password, "UCS-2LE", "UTF-8"));
        curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/response={$response}&getpage=../html/de/menus/menu2.html");
        preg_match('/name="sid" value="([0-9a-f]*)"/', curl_exec($ch), $matches);
       if(isset($matches[1]) && $matches[1] != '0000000000000000')
       {
          $SID = $matches[1];
       }
       else
       {
          echo "Fehler: Login fehlgeschlagen";
          return;
        }
        curl_setopt($ch, CURLOPT_POSTFIELDS, "sid={$SID}&telcfg:settings/DialPort=60"); // Nebenstellennummer eintragen!
        curl_exec($ch);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "sid={$SID}&telcfg:command/Dial=**612"); // Rufnummer eintragen!
        curl_exec($ch);
        curl_close($ch);
    }
}

?>
<?
$fritzbox_ip = 'fritz.box';
$fritzseite  = '../html/de/menus/menu2.html';
$filename    = IPS_GetKernelDir()."\\webfront\\user\\Fritzbox\\DslDetails.txt";// anpassen
$password    = 'xxxxx';

$ch = curl_init('http://' . $fritzbox_ip . '/cgi-bin/webcm?getpage=../html/login_sid.xml');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$login = curl_exec($ch);
$session_status_simplexml = simplexml_load_string($login);

if ($session_status_simplexml->iswriteaccess == 1)
{
   $SID = $session_status_simplexml->SID;
}
else
{
   $challenge = $session_status_simplexml->Challenge;
   $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $password, "UCS-2LE", "UTF-8"));
    curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/response={$response}&getpage=../html/de/menus/menu2.html");
    preg_match('/name="sid" value="([0-9a-f]*)"/', curl_exec($ch), $matches);
   if (isset($matches[1]) && $matches[1] != '0000000000000000')
   {
      $SID = $matches[1];
   }
   else
   {
      echo "Fehler: Login fehlgeschlagen";
      return;
    }
}

curl_setopt($ch, CURLOPT_POSTFIELDS, "getpage={$fritzseite}&sid={$SID}&var:menu=internet&var:pagename=adsl");
$getDslDetails = curl_exec($ch);
curl_close($ch);

$fileHandle = @fopen($filename, 'wb+');
fwrite($fileHandle, $getDslDetails);
fclose($fileHandle);

$lines = file("../webfront/user/Fritzbox/DslDetails.txt");
//print_r($lines);

SetValue(28656 /*[Fritzbox\DSL Details\Datenrate empfangen]*/, strip_tags($lines[3008])." ".strip_tags($lines[3007]));
SetValue(56839 /*[Fritzbox\DSL Details\Datenrate senden]*/, strip_tags($lines[3009])." ".strip_tags($lines[3007]));
SetValue(46032 /*[Fritzbox\DSL Details\Dämpfung Empfangen]*/, strip_tags($lines[3075])." dB");
SetValue(27847 /*[Fritzbox\DSL Details\Dämpfung Senden]*/, strip_tags($lines[3076])." dB");

?>
<?
$address = "Fritz.box";

$contentRecv = 'POST /upnp/control/WANIPConn1  HTTP/1.1
Cache-Control: no-cache
Connection: Close
Pragma: no-cache
Content-Type: text/xml; charset="utf-8"
User-Agent: Microsoft-Windows/6.1 UPnP/1.0
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination"
Content-Length: '.(287+strlen($address)).'
Host: '.$address.':49000

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><m:ForceTermination xmlns:m="urn:schemas-upnp-org:service:WANIPConnection:1"/></SOAP-ENV:Body></SOAP-ENV:Envelope>
';

SendPacket($contentRecv);

function SendPacket($content)
{
   global $address;
   $port = 49000 /*[Objekt #49000 existiert nicht]*/;

   $fp = fsockopen ($address, $port, $errno, $errstr, 10);
   if (!$fp)
   {
       echo "$errstr ($errno)<br />
";
   }
   else
   {
       fputs ($fp, $content);
      $ret = "";
      while (!feof($fp))
      {
          $ret.= fgets($fp,128);
      }
      //echo $ret;
      fclose($fp);
   }
   if(!(strpos($ret, "200 OK") === false))
   {
       return $ret;
   }
   else
   {
       die("Invalid Response: ".$ret);
   }
}

function GetTextBetween($string, $start, $end)
{
   preg_match_all("/$start(.*)$end/i", $string, $match);
   return $match[1][0];
}

?>
<?
$address = "Fritz.box";

$contentRecv = 'POST /upnp/control/WANIPConn1  HTTP/1.1
Cache-Control: no-cache
Connection: Close
Pragma: no-cache
Content-Type: text/xml; charset="utf-8"
User-Agent: Microsoft-Windows/6.1 UPnP/1.0
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#RequestConnection"
Content-Length: '.(289+strlen($address)).'
Host: '.$address.':49000

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><m:RequestConnection xmlns:m="urn:schemas-upnp-org:service:WANIPConnection:1"/></SOAP-ENV:Body></SOAP-ENV:Envelope>
';

SendPacket($contentRecv);

function SendPacket($content)
{
    global $address;
   $port = 49000 /*[Objekt #49000 existiert nicht]*/;

   $fp = fsockopen ($address, $port, $errno, $errstr, 10);
   if (!$fp)
    {
       echo "$errstr ($errno)<br />
";
   }
    else
    {
        fputs ($fp, $content);
      $ret = "";
      while (!feof($fp))
        {
         $ret.= fgets($fp,128);
      }
      //echo $ret;
      fclose($fp);
    }
   if(!(strpos($ret, "200 OK") === false))
    {
        return $ret;
   }
    else
    {
       die("Invalid Response: ".$ret);
   }
}

function GetTextBetween($string, $start, $end)
{
    preg_match_all("/$start(.*)$end/i", $string, $match);
   return $match[1][0];
}

?>
<?
$fritzbox_ip = 'fritz.box';
$fritzseite  = '../html/de/menus/menu2.html';
$password    = 'xxxxx';
$clear         = '0';

$ch = curl_init('http://' . $fritzbox_ip . '/cgi-bin/webcm?getpage=../html/login_sid.xml');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$login = curl_exec($ch);
$session_status_simplexml = simplexml_load_string($login);

if ($session_status_simplexml->iswriteaccess == 1)
{
   $SID = $session_status_simplexml->SID;
}
else
{
   $challenge = $session_status_simplexml->Challenge;
   $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $password, "UCS-2LE", "UTF-8"));
    curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/response={$response}&getpage=../html/de/menus/menu2.html");
    preg_match('/name="sid" value="([0-9a-f]*)"/', curl_exec($ch), $matches);
   if (isset($matches[1]) && $matches[1] != '0000000000000000')
   {
      $SID = $matches[1];
   }
   else
   {
      echo "Fehler: Login fehlgeschlagen";
      return;
    }
}
curl_setopt($ch, CURLOPT_POSTFIELDS, "getpage={$fritzseite}&sid={$SID}&var:pagename=rulall&telcfg:settings/ClearJournal={$clear}");
curl_exec($ch);
curl_close($ch);

?>
<?

$fritzrepeatergui = 'fritz.repeater'; // Name oder IP eintragen
$password = "xxxxx"; 

$text = "Ich bin ein Teststring";
$ch   = curl_init($fritzrepeatergui . '?getpage=../html/index_inhalt.html');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);

curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/password={$password}");
curl_exec($ch);
curl_setopt($ch, CURLOPT_POSTFIELDS, "getpage={$fritzrepeatergui}&var:pagename=infoled&nlr:settings/TDS_ScrollText={$text}");
curl_exec($ch);
curl_close($ch);

?>
<?
$address = "Fritz.box";

$contentRecv = 'POST /upnp/control/WANCommonIFC1 HTTP/1.1
Cache-Control: no-cache
Connection: Close
Pragma: no-cache
Content-Type: text/xml; charset="utf-8"
User-Agent: Microsoft-Windows/6.1 UPnP/1.0
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"
Content-Length: '.(292+strlen($address)).'
Host: '.$address.':49000

<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><m:GetExternalIPAddress xmlns:m="urn:schemas-upnp-org:service:WANIPConnection:1"/></SOAP-ENV:Body></SOAP-ENV:Envelope>
';

$data = SendPacket($contentRecv);
$wanIP = GetTextBetween($data, "<NewExternalIPAddress>", "<\/NewExternalIPAddress>");
SetValue(58757 /*[Objekt #21456 existiert nicht]*/, $wanIP);

function SendPacket($content)
{
    global $address;
   $port = 49000 /*[Objekt #49000 existiert nicht]*/;

   $fp = fsockopen ($address, $port, $errno, $errstr, 10);
   if (!$fp)
    {
       echo "$errstr ($errno)<br />
";
   }
    else
    {
        fputs ($fp, $content);
      $ret = "";
      while (!feof($fp))
        {
         $ret.= fgets($fp,128);
      }
      fclose($fp);
    }
   if(!(strpos($ret, "200 OK") === false))
    {
        return $ret;
   }
    else
    {
       die("Invalid Response: ".$ret);
   }
}

function GetTextBetween($string, $start, $end)
{
    preg_match_all("/$start(.*)$end/i", $string, $match);
   return $match[1][0];
}

?>

Hier kann man diverse Informationen erhalten.

Im Beispiel, die Zeit seit die Box mit dem Internet verbunden ist.

<?
$fritzbox_ip = 'fritz.box';
$password    = 'xxxxxx';

$ch = curl_init('http://' . $fritzbox_ip . '/cgi-bin/webcm?getpage=../html/login_sid.xml');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$login = curl_exec($ch);
$session_status_simplexml = simplexml_load_string($login);

if ($session_status_simplexml->iswriteaccess == 1)
{
   $SID = $session_status_simplexml->SID;
}
else
{
   $challenge = $session_status_simplexml->Challenge;
   $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $password, "UCS-2LE", "UTF-8"));
    curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/response={$response}&getpage=../html/de/menus/menu2.html");
    preg_match('/name="sid" value="([0-9a-f]*)"/', curl_exec($ch), $matches);
   if(isset($matches[1]) && $matches[1] != '0000000000000000')
   {
      $SID = $matches[1];
   }
   else
   {
      echo "Fehler: Login fehlgeschlagen";
      return;
    }
}
curl_close($ch);
$home = file("http://fritz.box/home/home.lua?sid=".$SID);
//print_r($home);
$tag = substr(trim($home[567]), -10);
$time = substr(trim($home[568]), -5);
echo "Verbunden seit ".$tag." ".$time;

?>
<?
//IPS_SetScriptTimer(40694 /*[Fritzbox\Anruferliste]*/, 20);

$fritzbox = 'fritz.box';
$fritzseite  = '../html/de/menus/menu2.html';
$filename    = IPS_GetKernelDir()."\\webfront\\user\\Fritzbox\\Anrufliste.csv";// anpassen
$password    = 'xxxxx';

$ch = curl_init('http://' . $fritzbox . '/cgi-bin/webcm?getpage=../html/login_sid.xml');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$login = curl_exec($ch);
$session_status_simplexml = simplexml_load_string($login);

if ($session_status_simplexml->iswriteaccess == 1)
{
   $SID = $session_status_simplexml->SID;
}
else
{
   $challenge = $session_status_simplexml->Challenge;
   $response = $challenge . '-' . md5(mb_convert_encoding($challenge . '-' . $password, "UCS-2LE", "UTF-8"));
    curl_setopt($ch, CURLOPT_POSTFIELDS, "login:command/response={$response}&getpage=../html/de/menus/menu2.html");
    preg_match('/name="sid" value="([0-9a-f]*)"/', curl_exec($ch), $matches);
   if (isset($matches[1]) && $matches[1] != '0000000000000000')
   {
      $SID = $matches[1];
   }
   else
   {
      echo "Fehler: Login fehlgeschlagen";
      return;
    }
}

//Anrufliste aktualisieren
curl_setopt($ch, CURLOPT_POSTFIELDS, "getpage={$fritzseite}&sid={$SID}&var:menu=home&var:pagename=foncalls");
curl_exec($ch);

curl_setopt($ch, CURLOPT_POSTFIELDS, "getpage=../html/de/FRITZ!Box_Anrufliste.csv&sid={$SID}");
$anrufliste = curl_exec($ch);
$anrufliste = explode(';', $anrufliste, 4);
$anrufliste = $anrufliste[3];
//print_r($anrufliste);
$fileHandle = @fopen($filename, 'wb+');
@fwrite($fileHandle, $anrufliste);
@fclose($fileHandle);

curl_close($ch);

?>