Antwort schreiben 
 
Themabewertung:
  • 0 Bewertungen - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
externe Einflußnahme z.B. via http(s)-URL
31-01-2019, 09:44
Beitrag: #10
RE: externe Einflußnahme z.B. via http(s)-URL
Ok, hier die Statusanzeige. Auch das ist runtergebrochen direkt auf meine Bedürfnisse. Wer ein bischen PHP/HTML kann, kann sich das natürlich weiter anpassen. (Hint: Credentials wie weiter oben erwähnt)

Code:
<html>
<head>
<META HTTP-EQUIV="refresh" CONTENT="60">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Lupusec XT2 Status</title>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#999999" vlink="#990000" alink="#666666"><!--mstheme--><font face="Arial, Arial, Helvetica">
  
<style type="text/css">    
    body  {
        background-color:#ddd;
        font-family: Arial, 'Arial', sans-serif;
    }
    
    .sensortable
    {
        width:100%;
        font-weight:normal;
        font-size:12;
        border: 1px solid black;
    }
    .statustable
    {
        width:100%;
        font-weight:bold;
        font-size:14;
        border: 1px solid black;
    }
    .armtable
    {
        width:100%;
        font-weight:bold;
        font-size:24;
        border: 1px solid black;
        padding: 30px;
    }
    
table {
    border-collapse: collapse;
}

table, th, td {
    border: 0px solid black;
}
th, td {
   padding: 0px 3px 0px 3px;
}
</style>  

<?
// Dieses Script liest die Sensoren und deren Daten aus einer Lupus XT2 Plus aus und stellt die Stati in einer Tabelle im Webfront dar


include 'LupusCredentials.php';

// Gerätetypen
$typen         = array("4" => "Türkontakt", "16" => "Tag Reader", "37" => "Keypad", "46" => "Sirene");

// -----------------------------------------------------------------------------
// ab hier ist nichts mehr anzupassen

// Login
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");

$result=curl_exec ($ch);

    if ( $result == false ) {

         $bkcolor="red";
         $color="white";
         $Modus = 'Anlage ausser Betrieb';

         $html .= "<table class='statustable'>";
         $html .= "<tr bgcolor='{$bkcolor}' style='font-size:24; color:{$color};'>";
         $html .= "<td align='center' ><b><br/>{$Modus}<br/>&nbsp;</b></td></tr>";      

         $html .= "</table>";

         echo $html;
         die;
    }


// Sensorliste lesen
$sensorliste = "http://".$ip."/action/deviceListGet";

curl_setopt($ch, CURLOPT_URL,$sensorliste);
$result=curl_exec ($ch);

// Umwandeln von JSON in ein Array
$result = str_replace("\t", "", $result);
$json_sens = json_decode($result, true);


$generalstatus = "http://".$ip."/action/panelCondGet";

curl_setopt($ch, CURLOPT_URL,$generalstatus);
$result=curl_exec ($ch);

curl_close ($ch);

$result = str_replace("\t", "", $result);
$json_stat = json_decode($result, true);

$updates = $json_stat['updates'];
$gsm_ok = $updates['sig_gsm_ok'];
$gsm_signal = $updates['sig_gsm'];
if ( $gsm_ok == "1" ) {
    $gsm_ok = 'Ok';
} else  {
    $gsm_ok = 'Fehler!';
    $gsm_signal = "0";
}
if ($gsm_signal == '{WEB_MSG_NA}' ){
    $gsm_ok = 'Fehler 2!';
    $gsm_signal = "0";
}


$Forms = $json_stat['forms'];
$Area1 = $Forms['pcondform1'];

$mode1 = $Area1['mode'];  // Modus: 0 unscharf, 1 scharf, 2 home1, 3 home2, 4 home3



// jeweilge Zone als Index des neuen Arrays $sensoren verwenden und dieses nach Index (=Zone) sortieren
foreach ($json_sens['senrows'] as $sensor)
    {
   $zone = $sensor['zone'];
   $sensoren[$zone] = $sensor;
     }
ksort($sensoren);



// HTML-Ausgabe erstellen
$html = "\n<table class='sensortable'>\n";
$html .= "\n<tr>\n<td><b>Sensor</b></td>\n<td><b>offen</b></td>\n<td><b>Batt.</b></td>\n<td><b>Funk</b></td>\n</tr>\n";

foreach ($sensoren as $sensor)
    {
        $status = @GetTextBetween($sensor['status'], '{WEB_MSG_DC_', '}');
        if ( $status != "" ) {
          $html .= SensorOut( 0, $sensor );
        }
    }
    $html .= "\n</table>\n";
    $html .= "\n<table class='sensortable'>\n";
    $html .= "\n<tr>\n<td><b>Sensor+Batt.</b></td>\n\n<td><b>Funk</b></td>\n<td style='border-left: 1px solid black;' ><b>Sensor+Batt.</b></td>\n\n<td><b>Funk</b></td>\n</tr>\n";

$col = 0;    
foreach ($sensoren as $sensor)
    {
        $status = @GetTextBetween($sensor['status'], '{WEB_MSG_DC_', '}');
        if ( $status == "" ) {
          if ( $col == 0 )  $html .= "\n<tr>";    
          $html .= SensorOut( 1, $sensor );
          if ( $col == 1 )  $html .= "\n</tr>\n";    
          $col = 1- $col;
        }
    }

    $html .= "\n</table>\n";


// Armierung Status
    $bkcolor="lime";
    $color="black";
    $Modus = "unscharf";
    switch ($mode1) {
        case "0":
            $bkcolor="red";
            $color="white";
            $Modus = "unscharf";
        break;
        case "1":
            $bkcolor="lime";
            $color="black";
            $Modus = "SCHARF!";
        break;
        case "2":
            $bkcolor="yellow";
            $color="black";
            $Modus = "Home1";
        break;
        case "3":
            $bkcolor="yellow";
            $color="black";
            $Modus = "Home2";
        break;
        case "4":
            $bkcolor="yellow";
            $color="black";
            $Modus = "Home3";
        break;
    }

    
    

$html .= "\n<table class='armtable'>";
$html .= "\n<tr bgcolor='{$bkcolor}' color:{$color}' style='padding: 10px;'>";
$html .= "\n<td style='padding: 10px;' align='center' ><b>{$Modus}&nbsp;</b></td></tr>";      
$html .= "\n</table>\n";
    
    // GSM-Status
    $html .= "\n<table class='statustable'>";
    $html .= "\n<tr>\n<td><b>Status</b></td>\n<td><b>Wert</b></td>\n</tr>";

    $html .= "\n<tr><td>GSM ok</td>\n<td>" . $gsm_ok . "</td>\n</tr>";      
    $html .= "\n<tr><td>GSM Signal</td>\n<td>" . $gsm_signal . "/9</td>\n</tr>";

    $html .= "\n</table>\n";
    //$html .= "<p></p>";


echo $html;

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function SensorOut( $SnsTyp, $sensor )
{
    $html = '';
    $fault = 0;    
    // Daten aus Array zur besseren Anzeige bearbeiten
    $status = @GetTextBetween($sensor['status'], '{WEB_MSG_DC_', '}');
    $status = str_replace("CLOSE", "nein", $status);
    $status = str_replace("OPEN", "ja", $status);
    if ($sensor['rssi']=='{WEB_MSG_NA}') {
        $rssi="n/a";
        $fault = 1;
    } else {
        $rssi = substr($sensor['rssi'], -1);
    }

    $name =  $sensor['name'];
    $battery = $sensor['battery_ok'];
    $battery = str_replace("1", "OK",      $battery );
    $battery = str_replace("0", "Schwach", $battery );
    
    
    if ($fault==1) {
        $battery = "unbek.";
        $status  = "unbek.";
    }


    
    $bkcolor="gray";
    $color="black";
    if ( strcasecmp($status, "nein"   )== 0 ) { SetColors( 2, $bkcolor, $color );}
    if (( strcasecmp($status, "ja" )== 0 ) or ( $fault == 1 )) { SetColors( 0, $bkcolor, $color );}
    
    if ( $SnsTyp == 1 ) {
        if ( $battery == "OK" ) {
            SetColors( 2, $bkcolor, $color );
        } else {
          SetColors( 0, $bkcolor, $color );
        }
        $html .= "\n<td  style='border-left: 1px solid black;' bgcolor='{$bkcolor}' style='color:{$color};'><b>" . $name . "</b></td>";        // battery_ok
    } else  {
    
    
        // SensorName
        $html .= "\n<tr bgcolor='{$bkcolor}' style='color:{$color};'>";
        $html .= "\n<td><b>" . $name . "</b></td>";        // name
        
        //Sensor Status
        $html .= "\n<td align='center' >" . $status . "</td>";        // status


        // Batterie
        if ( strcasecmp($battery, "OK" )== 0 )      
          SetColors( 2, $bkcolor, $color );
        else
          SetColors( 0, $bkcolor, $color );

        $html .= "\n<td align='center' bgcolor='{$bkcolor}' style='color:{$color};'>" . $battery . "</td>";        // battery_ok
    }

// Funkleistung
    SetColors( 2, $bkcolor, $color );
    
    if ( strcasecmp($rssi, "5" )== 0 )  SetColors( 1, $bkcolor, $color );
    if ( strcasecmp($rssi, "4" )== 0 )  SetColors( 1, $bkcolor, $color );
    if ( strcasecmp($rssi, "3" )== 0 )  SetColors( 0, $bkcolor, $color );
    if ( strcasecmp($rssi, "2" )== 0 )  SetColors( 0, $bkcolor, $color );
    if ( strcasecmp($rssi, "1" )== 0 )  SetColors( 0, $bkcolor, $color );
    if ( strcasecmp($rssi, "0" )== 0 )  SetColors( 0, $bkcolor, $color );
    if ( $fault == 1 )  SetColors( 0, $bkcolor, $color );
    

    $html .= "\n<td align='center' bgcolor='{$bkcolor}' style='color:{$color};'>";
    if ( $fault==1)  {
        $html .= "n/a";
    }else{
        $html .= "{$rssi}/9";
    }
    $html .="\n</td>";        // rssi
    if ( $SnsTyp <> 1 ) {
      $html .= "\n</tr>\n";
    }
    return $html;
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function SetColors( $level, &$backcolor, &$forecolor )
{
  switch ($level) {
      case 1:
        $backcolor="yellow";
        $forecolor="black";
      break;
      case 2:
        $backcolor="lime";
        $forecolor="black";
      break;
      default:
//      case 0:
        $backcolor="red";
        $forecolor="white";
      break;
  }
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
function GetTextBetween($string, $start, $end)
    {
   preg_match_all( "/$start(.*)$end/U", $string, $match );
   return $match[1][0];
    }
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
?>

</font></body>

</html>

Viel Spaß beim Weiterbasteln

Gruß, Christian
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
Antwort schreiben 


Nachrichten in diesem Thema
RE: externe Einflußnahme z.B. via http(s)-URL - chrissi099 - 31-01-2019 09:44

Möglicherweise verwandte Themen...
Thema: Verfasser Antworten: Ansichten: Letzter Beitrag
  Technaxx TX-83 Kamera HTTP Syntax Antonio 1 1.847 10-06-2021 16:32
Letzter Beitrag: ssb-security
  Apple Push Notification APNS HTTP/2 Fraggle 1 1.991 30-09-2020 22:27
Letzter Beitrag: bastelheini
  HTTP request von der Doorbird Timmei 5 3.438 31-08-2020 07:17
Letzter Beitrag: shortyHonk
  WLAN Kamera - Mit Action-URL aktuelles Bild per Mail versenden Fraggle 3 4.165 06-03-2020 10:27
Letzter Beitrag: peteralarm
  Klingelton externe Sirene PeterF 0 2.114 11-09-2019 14:31
Letzter Beitrag: PeterF
  Verzögerte Action URL & Shelly shortyHonk 6 9.054 17-06-2019 06:42
Letzter Beitrag: shortyHonk
  Action URL mit neuer Firmware: gelöst. tomleitner 5 5.237 15-04-2019 18:42
Letzter Beitrag: rubinho
  Acktion URL bei Fehler ausführen Detlef B. 1 2.091 09-04-2019 10:01
Letzter Beitrag: grelm
  SMS via GSM bei Netzwerkausfall. tomleitner 4 3.218 07-04-2019 06:53
Letzter Beitrag: tomleitner
  via SMS Commands an die Zentrale schicken nobody01 15 9.762 16-02-2019 18:11
Letzter Beitrag: seagull



Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste