Anrufliste auslesen aus FB und Prob beim Visualisieren

Hallo,

bin nun auch IPS Besitzer :slight_smile:

Der Umstieg von EZ XS1+FS20 auf HM ist nun fast abgeschlossen.

Habe auch schon recht viel mit IPS experimentiert, aber ein paar Fragen habe ich trotz der Anleitung und des Forums doch noch…

Hier mal ein Überblick über meine bisherige Baumstruktur…

Jetzt zu meinen Fragen…

  1. Ich habe dank einen Skripts aus diesem Forum ein Skript erstellt um die Anrufliste aus der FB auszulesen. Dieses funktioniert auch und shreibt in einen Ordner eine csv Datei. Jetzt weiß ich aber nicht, wie ich dieses Skript „visualisieren“ kann. Also ich hätte gerne einen Punkt „Fritzbox“ und dann eben dort eine ansprechende Oberfläche.

Es ist bestimmt total einfach, ich brauche nur einen kleinen Denkanstoß…

Ich habe bisher eine Kategorie „Fritzbox“ erstellt. Unter diesem Punkt soll dann diese Anrufliste erscheinen.

Vielen Dank für eure Hilfe…

PS: Hier noch der Code, den ich Zum Auslesen nutze…

 <?
//IPS_SetScriptTimer(40694 /*[Objekt #40694 existiert nicht]*/, 20);

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

$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&varagename=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);

?>

Probiert mal das: http://www.ip-symcon.de/forum/threads/9948-Anruferliste-aus-FritzBox-auslesen?highlight=fritzbox

paresy

perfekt…ich weiß nicht wie, aber ich hab es geschafft…:smiley: vielen Dank paresy :slight_smile:

Nur bekomme ich lediglich zwei verschiedene Symbole…

Einmal blau für ankommend und einmal grün für abgehend…leider bekomme ich aber keine Meldung bzw. Anzeige der verpassten Anrufe…

Auch wenn ich in die Oberfläche der FB gehe, dann bekomme ich unter dme Punkt alle Anrufe nur einen blauen und einen grünen Hörer…

EDIT: Jetzt geht es…Vielen Dank…

Mist leider zu früh gefreut…

Ich bekomme jetzt immer wieder einen neuen String Content geschrieben…

Hier das Skript:

 <?

//Konfiguration
$fritzbox = 'fritz.box';
$fritzgui = 'http://' . $fritzbox . '/cgi-bin/webcm';
$password = 'xxx';
$anzeigen = array(1, 2, 3); //1 = Kommend, 2 = Kommend (Fehler), 3 = Gehend
$anzahl = 10;

//Ab hier nichts mehr ändern
$object = IPS_GetObject($IPS_SELF);
$parentID = $object['ParentID'];

//Installer
if ($IPS_SENDER == "Execute")
{

    IPS_SetHidden($IPS_SELF, true);
    IPS_SetName($IPS_SELF, "Auslese-Skript");

    $parentObject = IPS_GetObject($parentID);
    if ($parentObject['ObjectType'] !== 1)
    {
        $instanceID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");
        IPS_SetParent($instanceID, $parentID);
        $parentID = $instanceID;
        IPS_SetParent($IPS_SELF, $parentID);
        IPS_SetName($instanceID, "Anruferliste");
    }

    IPS_SetScriptTimer($IPS_SELF, 300);

}

$login = file_get_contents('http://' . $fritzbox . '/cgi-bin/webcm?getpage=../html/login_sid.xml');

$session_status_simplexml = @simplexml_load_string($login);

if($session_status_simplexml === false)
{
    die("Fehler beim einlesen der XML Daten. Wahrscheinlich ist eine zu alte Firmware installiert");
}
else if ($session_status_simplexml->iswriteaccess == 1)
{
    $SID = $session_status_simplexml->SID;
}
else
{
   $challenge = $session_status_simplexml->Challenge;
    $response = $challenge . '-' . md5(iconv("UTF-8", "UCS-2LE", $challenge . '-' . $password));
   $postdata = http_build_query(array('getpage' => '../html/de/menus/menu2.html', 'login:command/response' => $response));

    $opts = array('http' =>
                                array(
                                    'method' => 'POST',
                                 'header' => 'Content-Length: '.strlen($postdata)."
".
                                                'Content-Type: application/x-www-form-urlencoded',
                                    'content'=> $postdata
            )
    );

    $context  = stream_context_create($opts);
   $sendlogin = file_get_contents($fritzgui, false, $context);

   preg_match('@<input type="hidden" name="sid" value="([A-Fa-f0-9]{16})" id="uiPostSid">@i', $sendlogin, $matches);
   if (isset($matches[1]) && $matches[1] != '0000000000000000')
   {
      $SID = $matches[1];
   }
   else
   {
      echo "Fehler: Login fehlgeschlagen";
      return;
    }
}

//Anrufliste aktualisieren
$postdata = http_build_query(array('getpage' => '../html/de/menus/menu2.html','sid' => $SID, 'var:menu' => 'home', 'varagename' => 'foncalls'));

$opts = array('http' =>
                            array(
                                'method'  => 'POST',
                             'header'=> 'Content-Length: '.strlen($postdata)."
".
                                           'Content-Type: application/x-www-form-urlencoded',
                                'content' => $postdata
        )
);

$context  = stream_context_create($opts);
$getnewlist = file_get_contents($fritzgui, false, $context);

//Anrufliste abholen
$postdata = http_build_query(array('getpage' => '../html/de/FRITZ!Box_Anrufliste.csv', 'sid' => $SID));

$opts = array('http' =>
                            array(
                                'method'  => 'POST',
                             'header'=> 'Content-Length: '.strlen($postdata)."
".
                                           'Content-Type: application/x-www-form-urlencoded',
                                'content' => $postdata
        )
);

$context  = stream_context_create($opts);
$anrufliste = file_get_contents($fritzgui, false, $context);
$anrufliste = explode("
", $anrufliste);

$str = "<table width='90%' align='center'>"; // Farbe anpassen oder style entfernen
$str .= "<tr><td></td><td><b>Datum</b></td><td><b>Name/Rufnummer</b></td><td><b>Nebenstelle</b></td><td><b>Zeit</b></td></tr>";

$pos = 0;
for($i=3; $i<=sizeof($anrufliste); $i++)
{
    $eintrag = explode(";", $anrufliste[$i]);
    if(strlen($eintrag[2]) > 0)
      $eintrag[3] = $eintrag[2];
    unset($eintrag[2]);
    if(strlen($eintrag[4]) > 0)
      $eintrag[5] = $eintrag[4];
    if(strlen($eintrag[3]) == 0)
      $eintrag[3] = "Unbekannt";
    unset($eintrag[4]);
    $caller = $eintrag[0];
    switch($caller) {
       case 1:
          $eintrag[0] = "<img src=/user/fritz/Callin.png>";
          break;
       case 2:
          $eintrag[0] = "<img src=/user/fritz/Callinfailed.png>";
          break;
       case 3:
          $eintrag[0] = "<img src=/user/fritz/Callout.png>";
          break;
        default:
           $eintrag[0] = "";
           break;
    }
    if(in_array($caller, $anzeigen))
    {
        $str .= "<tr>";
        foreach($eintrag as $data)
            $str .= '<td>'.$data.'</td>';
        $str .= "</tr>";

        $pos++;
    }
    if($pos >= $anzahl)
        break;
}
$str .= "</table>";

$vid = CreateVariableByName($parentID, "Content", 3);
IPS_SetIcon($vid, "Speaker");
IPS_SetVariableCustomProfile($vid, "~HTMLBox");
SetValue($vid, $str);

$postdata = http_build_query(array('getpage' => '../html/de/menus/menu2.html', 'sid' => $SID, 'security:command/logout' => 'logout'));

$opts = array('http' =>
                            array(
                                'method'  => 'POST',
                             'header'=> 'Content-Length: '.strlen($postdata)."
".
                                           'Content-Type: application/x-www-form-urlencoded',
                                'content' => $postdata
        )
);

$context  = stream_context_create($opts);
$logout = file_get_contents($fritzgui, false, $context);

function CreateVariableByName($id, $name, $type)
{
    global $IPS_SELF;
    $vid = @IPS_GetVariableIDByName($name, $id);
    if($vid === false)
    {
        $vid = IPS_CreateVariable($type);
        IPS_SetParent($vid, $id);
        IPS_SetName($vid, $name);
        IPS_SetInfo($vid, "this variable was created by script #$IPS_SELF");
    }
    return $vid;
}

?>

Woran könnte das liegen?

Außerdem würde ich gerne den Punkt Telefon als eigenen Punkt haben. Also wie auf den Bildern zu sehen, wie bspw. Maxdome oder der Punkt „Haus“
Wie müsste ich da die Ordnerstruktur ändern bzw. das Webfront anpassen?

Besten Dank

Setze dein PHP-Code doch mal in PHP-Tags. Ist dann besser lesbar.


<?

//Konfiguration
$fritzbox = 'fritz.box';
$fritzgui = 'http://' . $fritzbox . '/cgi-bin/webcm';
$password = 'xxx';
$anzeigen = array(1, 2, 3); //1 = Kommend, 2 = Kommend (Fehler), 3 = Gehend
$anzahl = 10;

//Ab hier nichts mehr ändern
$object = IPS_GetObject($IPS_SELF);
$parentID = $object['ParentID'];

//Installer
if ($IPS_SENDER == "Execute")
{

    IPS_SetHidden($IPS_SELF, true);
    IPS_SetName($IPS_SELF, "Auslese-Skript");

    $parentObject = IPS_GetObject($parentID);
    if ($parentObject['ObjectType'] !== 1)
    {
        $instanceID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");
        IPS_SetParent($instanceID, $parentID);
        $parentID = $instanceID;
        IPS_SetParent($IPS_SELF, $parentID);
        IPS_SetName($instanceID, "Anruferliste");
    }

    IPS_SetScriptTimer($IPS_SELF, 300);

}

$login = file_get_contents('http://' . $fritzbox . '/cgi-bin/webcm?getpage=../html/login_sid.xml');

$session_status_simplexml = @simplexml_load_string($login);

if($session_status_simplexml === false)
{
    die("Fehler beim einlesen der XML Daten. Wahrscheinlich ist eine zu alte Firmware installiert");
}
else if ($session_status_simplexml->iswriteaccess == 1)
{
    $SID = $session_status_simplexml->SID;
}
else
{
   $challenge = $session_status_simplexml->Challenge;
    $response = $challenge . '-' . md5(iconv("UTF-8", "UCS-2LE", $challenge . '-' . $password));
   $postdata = http_build_query(array('getpage' => '../html/de/menus/menu2.html', 'login:command/response' => $response));

    $opts = array('http' =>
                                array(
                                    'method' => 'POST',
                                 'header' => 'Content-Length: '.strlen($postdata)."
".
                                                'Content-Type: application/x-www-form-urlencoded',
                                    'content'=> $postdata
            )
    );

    $context  = stream_context_create($opts);
   $sendlogin = file_get_contents($fritzgui, false, $context);

   preg_match('@<input type="hidden" name="sid" value="([A-Fa-f0-9]{16})" id="uiPostSid">@i', $sendlogin, $matches);
   if (isset($matches[1]) && $matches[1] != '0000000000000000')
   {
      $SID = $matches[1];
   }
   else
   {
      echo "Fehler: Login fehlgeschlagen";
      return;
    }
}

//Anrufliste aktualisieren
$postdata = http_build_query(array('getpage' => '../html/de/menus/menu2.html','sid' => $SID, 'var:menu' => 'home', 'varagename' => 'foncalls'));

$opts = array('http' =>
                            array(
                                'method'  => 'POST',
                             'header'=> 'Content-Length: '.strlen($postdata)."
".
                                           'Content-Type: application/x-www-form-urlencoded',
                                'content' => $postdata
        )
);

$context  = stream_context_create($opts);
$getnewlist = file_get_contents($fritzgui, false, $context);

//Anrufliste abholen
$postdata = http_build_query(array('getpage' => '../html/de/FRITZ!Box_Anrufliste.csv', 'sid' => $SID));

$opts = array('http' =>
                            array(
                                'method'  => 'POST',
                             'header'=> 'Content-Length: '.strlen($postdata)."
".
                                           'Content-Type: application/x-www-form-urlencoded',
                                'content' => $postdata
        )
);

$context  = stream_context_create($opts);
$anrufliste = file_get_contents($fritzgui, false, $context);
$anrufliste = explode("
", $anrufliste);

$str = "<table width='90%' align='center'>"; // Farbe anpassen oder style entfernen
$str .= "<tr><td></td><td><b>Datum</b></td><td><b>Name/Rufnummer</b></td><td><b>Nebenstelle</b></td><td><b>Zeit</b></td></tr>";

$pos = 0;
for($i=3; $i<=sizeof($anrufliste); $i++)
{
    $eintrag = explode(";", $anrufliste[$i]);
    if(strlen($eintrag[2]) > 0)
      $eintrag[3] = $eintrag[2];
    unset($eintrag[2]);
    if(strlen($eintrag[4]) > 0)
      $eintrag[5] = $eintrag[4];
    if(strlen($eintrag[3]) == 0)
      $eintrag[3] = "Unbekannt";
    unset($eintrag[4]);
    $caller = $eintrag[0];
    switch($caller) {
       case 1:
          $eintrag[0] = "<img src=/user/fritz/Callin.png>";
          break;
       case 2:
          $eintrag[0] = "<img src=/user/fritz/Callinfailed.png>";
          break;
       case 3:
          $eintrag[0] = "<img src=/user/fritz/Callout.png>";
          break;
        default:
           $eintrag[0] = "";
           break;
    }
    if(in_array($caller, $anzeigen))
    {
        $str .= "<tr>";
        foreach($eintrag as $data)
            $str .= '<td>'.$data.'</td>';
        $str .= "</tr>";

        $pos++;
    }
    if($pos >= $anzahl)
        break;
}
$str .= "</table>";

$vid = CreateVariableByName($parentID, "Content", 3);
IPS_SetIcon($vid, "Speaker");
IPS_SetVariableCustomProfile($vid, "~HTMLBox");
SetValue($vid, $str);

$postdata = http_build_query(array('getpage' => '../html/de/menus/menu2.html', 'sid' => $SID, 'security:command/logout' => 'logout'));

$opts = array('http' =>
                            array(
                                'method'  => 'POST',
                             'header'=> 'Content-Length: '.strlen($postdata)."
".
                                           'Content-Type: application/x-www-form-urlencoded',
                                'content' => $postdata
        )
);

$context  = stream_context_create($opts);
$logout = file_get_contents($fritzgui, false, $context);

function CreateVariableByName($id, $name, $type)
{
    global $IPS_SELF;
    $vid = @IPS_GetVariableIDByName($name, $id);
    if($vid === false)
    {
        $vid = IPS_CreateVariable($type);
        IPS_SetParent($vid, $id);
        IPS_SetName($vid, $name);
        IPS_SetInfo($vid, "this variable was created by script #$IPS_SELF");
    }
    return $vid;
}

?>

Mach einen Link auf deinen Content. Den kannste dann auch umbenennen.

Wie meinst du das?

 <?

//Konfiguration
$fritzbox = 'fritz.box';
$fritzgui = 'http://' . $fritzbox . '/cgi-bin/webcm';
$password = 'xxx';
$anzeigen = array(1, 2, 3); //1 = Kommend, 2 = Kommend (Fehler), 3 = Gehend
$anzahl = 10;

//Ab hier nichts mehr ändern
$object = IPS_GetObject($IPS_SELF);
$parentID = $object['ParentID'];

//Installer
if ($IPS_SENDER == "Execute")
{

    IPS_SetHidden($IPS_SELF, true);
    IPS_SetName($IPS_SELF, "Auslese-Skript");

    $parentObject = IPS_GetObject($parentID);
    if ($parentObject['ObjectType'] !== 1)
    {
        $instanceID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");
        IPS_SetParent($instanceID, $parentID);
        $parentID = $instanceID;
        IPS_SetParent($IPS_SELF, $parentID);
        IPS_SetName($instanceID, "Anruferliste");
    }

    IPS_SetScriptTimer($IPS_SELF, 300);

}

$login = file_get_contents('http://' . $fritzbox . '/cgi-bin/webcm?getpage=../html/login_sid.xml');

$session_status_simplexml = @simplexml_load_string($login);

if($session_status_simplexml === false)
{
    die("Fehler beim einlesen der XML Daten. Wahrscheinlich ist eine zu alte Firmware installiert");
}
else if ($session_status_simplexml->iswriteaccess == 1)
{
    $SID = $session_status_simplexml->SID;
}
else
{
   $challenge = $session_status_simplexml->Challenge;
    $response = $challenge . '-' . md5(iconv("UTF-8", "UCS-2LE", $challenge . '-' . $password));
   $postdata = http_build_query(array('getpage' => '../html/de/menus/menu2.html', 'login:command/response' => $response));

    $opts = array('http' =>
                                array(
                                    'method' => 'POST',
                                 'header' => 'Content-Length: '.strlen($postdata)."
".
                                                'Content-Type: application/x-www-form-urlencoded',
                                    'content'=> $postdata
            )
    );

    $context  = stream_context_create($opts);
   $sendlogin = file_get_contents($fritzgui, false, $context);

   preg_match('@<input type="hidden" name="sid" value="([A-Fa-f0-9]{16})" id="uiPostSid">@i', $sendlogin, $matches);
   if (isset($matches[1]) && $matches[1] != '0000000000000000')
   {
      $SID = $matches[1];
   }
   else
   {
      echo "Fehler: Login fehlgeschlagen";
      return;
    }
}

//Anrufliste aktualisieren
$postdata = http_build_query(array('getpage' => '../html/de/menus/menu2.html','sid' => $SID, 'var:menu' => 'home', 'var:pagename' => 'foncalls'));

$opts = array('http' =>
                            array(
                                'method'  => 'POST',
                             'header'=> 'Content-Length: '.strlen($postdata)."
".
                                           'Content-Type: application/x-www-form-urlencoded',
                                'content' => $postdata
        )
);

$context  = stream_context_create($opts);
$getnewlist = file_get_contents($fritzgui, false, $context);

//Anrufliste abholen
$postdata = http_build_query(array('getpage' => '../html/de/FRITZ!Box_Anrufliste.csv', 'sid' => $SID));

$opts = array('http' =>
                            array(
                                'method'  => 'POST',
                             'header'=> 'Content-Length: '.strlen($postdata)."
".
                                           'Content-Type: application/x-www-form-urlencoded',
                                'content' => $postdata
        )
);

$context  = stream_context_create($opts);
$anrufliste = file_get_contents($fritzgui, false, $context);
$anrufliste = explode("
", $anrufliste);

$str = "<table width='90%' align='center'>"; // Farbe anpassen oder style entfernen
$str .= "<tr><td></td><td><b>Datum</b></td><td><b>Name/Rufnummer</b></td><td><b>Nebenstelle</b></td><td><b>Zeit</b></td></tr>";

$pos = 0;
for($i=3; $i<=sizeof($anrufliste); $i++)
{
    $eintrag = explode(";", $anrufliste[$i]);
    if(strlen($eintrag[2]) > 0)
      $eintrag[3] = $eintrag[2];
    unset($eintrag[2]);
    if(strlen($eintrag[4]) > 0)
      $eintrag[5] = $eintrag[4];
    if(strlen($eintrag[3]) == 0)
      $eintrag[3] = "Unbekannt";
    unset($eintrag[4]);
    $caller = $eintrag[0];
    switch($caller) {
       case 1:
          $eintrag[0] = "<img src=/user/fritz/Callin.png>";
          break;
       case 2:
          $eintrag[0] = "<img src=/user/fritz/Callinfailed.png>";
          break;
       case 3:
          $eintrag[0] = "<img src=/user/fritz/Callout.png>";
          break;
        default:
           $eintrag[0] = "";
           break;
    }
    if(in_array($caller, $anzeigen))
    {
        $str .= "<tr>";
        foreach($eintrag as $data)
            $str .= '<td>'.$data.'</td>';
        $str .= "</tr>";

        $pos++;
    }
    if($pos >= $anzahl)
        break;
}
$str .= "</table>";

$vid = CreateVariableByName($parentID, "Content", 3);
IPS_SetIcon($vid, "Speaker");
IPS_SetVariableCustomProfile($vid, "~HTMLBox");
SetValue($vid, $str);

$postdata = http_build_query(array('getpage' => '../html/de/menus/menu2.html', 'sid' => $SID, 'security:command/logout' => 'logout'));

$opts = array('http' =>
                            array(
                                'method'  => 'POST',
                             'header'=> 'Content-Length: '.strlen($postdata)."
".
                                           'Content-Type: application/x-www-form-urlencoded',
                                'content' => $postdata
        )
);

$context  = stream_context_create($opts);
$logout = file_get_contents($fritzgui, false, $context);

function CreateVariableByName($id, $name, $type)
{
    global $IPS_SELF;
    $vid = @IPS_GetVariableIDByName($name, $id);
    if($vid === false)
    {
        $vid = IPS_CreateVariable($type);
        IPS_SetParent($vid, $id);
        IPS_SetName($vid, $name);
        IPS_SetInfo($vid, "this variable was created by script #$IPS_SELF");
    }
    return $vid;
}

?>

Ich bekomme jetzt alle 5 Minuten in der Baumübersicht eine aktualisierte Content Datei. Das hat zur Folfe, dass ich auch im Webfront eben 2x die Liste habe.