<?php
/* ===========================================================================
* PERSONALIZATION
* You can alter these entries to personalize your Fritzbox SmartHome Interface.
* Requires Fritz!OS 6.10 or better.
* Don't forget to verify your server port in case of https:
* (c)2014 robw
* =========================================================================== */
define("FBX","IP");
define("LIN",FBX."/login_sid.lua");
define("WEB",FBX."/webservices/homeautoswitch.lua");
if ($_SERVER['HTTPS'] == "on") {
define("BOX","https://".$_SERVER['HTTP_HOST'].":443/net/home_auto_overview.lua");
} else {
define("BOX",FBX."/net/home_auto_overview.lua");
}
define("USR","NAME");
define("PAS","PASSWORT");
define("IMG","web_images/"); //Image-Path with trailing slash!
define("CTON","4"); //Temp-Korrektur 'On'
define("CTOFF","0"); //Temp-Korrektur 'Off'
define("SID",GetSid());
define("CMD",WEB."?sid=".SID."&switchcmd=");
/* ================= NO NEED TO CHANGE ANYTHING BENEATH THIS LINE ============== */
switch($_GET['task']){case "AN":$a=file_get_contents(CMD.'setswitchon&ain='.$_GET['ain']);break;default:$a=file_get_contents(CMD.'setswitchoff&ain='.$_GET['ain']);}function GetSid(){$b=simplexml_load_string(file_get_contents(LIN));$c=$b->SID;if($c=="0000000000000000"){$d=$b->Challenge;$a=$d."-".md5(mb_convert_encoding($d."-".PAS,"UCS-2LE","UTF-8"));$e=LIN."?username=".USR."&response=$a";$b=simplexml_load_string(file_get_contents($e));$c=$b->SID;}return $c;}?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="content-type" content="text/html;charset=UTF-8"><meta name="viewport" content="width=device-width, initial-scale=0.95, user-scalable=yes"><meta http-equiv="expires" content="0"><meta http-equiv="cache-control" content="no-cache"><title>Fritz-Dect</title><link rel="shortcut icon" href="favicon.ico"><style type="text/css">body{font-family:'Trebuchet MS','Segoe UI',Tahoma,Arial;font-size:15pt;text-align:left;}table{width:expression(document.body.clientWidth < 800? "400px":"50%" && document.body.clientWidth > 1220? "600px":"60%");}th,td{margin-top:0;margin-bottom:0;}img{border:none;}input{font-family:'Trebuchet MS','Segoe UI';font-size:14pt;width:180px;height:37px;padding-left:20px;padding-right:20px;background:"#DDDDDD";}.blue{color:#0000AF;}.green{color:#008C3F;}.gray{color:#A0A0A0;}a:link{color:#0000AF;text-decoration:none;}a:visited{color:#0000AF;text-decoration:none;}a:active{color:#0000AF;text-decoration:none;}a:hover{color:#2020FF;text-decoration:underline;}</style><script type="text/javascript">setTimeout(function(){window.location.reload(true);},60000);function Frage(akt,ziel,wie,zahl){if (confirm(akt+' '+wie+'\u2002>\u2002OK?')==true){window.location.href='?ain='+ziel+'&task='+wie;if (wie=="AN"){document.getElementById("schieb"+zahl).innerHTML="<img src='<?php echo IMG;?>switch_on.jpg'>";document.getElementById("knopf"+zahl).innerHTML="<input type='button' value='"+akt+"' style='background:#31CF70;font-weight:bold;color:white;'>";}else{document.getElementById("schieb"+zahl).innerHTML="<img src='<?php echo IMG;?>switch_off.jpg'>";document.getElementById("knopf"+zahl).innerHTML="<input type='button' value='"+akt+"'>";}}}</script></head><body><table border="0" cellspacing="6" cellpadding="0" style="max-width:430px;"><tr><th colspan="5" align="center"><a href="<?php echo BOX;?>" target="_blank">Die Netzwerk-Steckdosen</a></th></tr><tr class="green"><td width="2%"> </td><td width="45%" align="center">Geräte</td><td width="15%" align="center">An/Aus</td><td width="15%" align="right">W </td><td width="20%" align="right">°C </td><td width="2%"></td></tr><tr><td colspan="5"><hr size="1" noshade></td></tr>
<?php $a=1;$b=simplexml_load_string(file_get_contents(CMD."getdevicelistinfos"));foreach($b->device as $c){$d=$c->name;$e=$c->switch->state;$f=str_replace(' ','',$c->attributes()->identifier);if($e==1){$g="'".$d."','".$f."','AUS',".$a;$h='switch_on.jpg';$j='style="background:#31CF70;font-weight:bold;color:white;"';$k=sprintf('%.1f',($c->temperature->celsius/10)-CTON);$l=sprintf('%.1f',($c->powermeter->power/1000));$watt+=$l;}else{$g="'".$d."','".$f."','AN',".$a;$h='switch_off.jpg';$j='';$k=sprintf('%.1f',($c->temperature->celsius/10)-CTOFF);$l='';}echo '<tr><td align="right" class="gray">'.$a.'</td>';echo '<td id="knopf'.$a.'" align="center" nowrap><input type="button" value="'.$d.'" onclick="javascript:Frage('.$g.')" '.$j.'></td>';echo '<td id="schieb'.$a.'" nowrap><a href="javascript:Frage('.$g.')"><img src="'.IMG.$h.'"></a></td>';echo '<td align="right" nowrap>'.$l.'</td>';echo '<td align="right" nowrap>'.$k.'</td></tr>';$a+=1;}?>
<tr><td colspan="5"><hr size="1" noshade></td></tr><tr class="green"><td></td><td align="center">Gesamt</td><td align="right" nowrap></td><td align="right"><?php echo sprintf('%.1f',$watt);?></td><td align="left" nowrap>W</td><td align="right" nowrap></td></tr></table></body></html>