Skip to content

Commit

Permalink
webinterface/daemon: change port, simplify configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
xkonni committed Nov 6, 2012
1 parent 367dcea commit 47e9447
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 99 deletions.
2 changes: 1 addition & 1 deletion daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ char nGroup[6];
int nSwitchNumber;
int nAction;
int nPlugs;
int PORT = 12345;
int PORT = 11337;

void error(const char *msg);
int getAddr(const char* nGroup, int nSwitchNumber);
14 changes: 14 additions & 0 deletions webinterface/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
$source = $_SERVER['SERVER_ADDR'];
$target = '192.168.11.124';
$port = 11337;

$config=array(
array("00001", "01", "Schreibtisch"),
array("00001", "02", "Sofa"),
array("00001", "03", "TV"),
array("00001", "04", "Verstaerker"),
array("00010", "05", "Bla"),
array("00011", "01", "Blob")
)
?>
90 changes: 39 additions & 51 deletions webinterface/index.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php
include("config.php");
// config
$source = $_SERVER['SERVER_ADDR'];
$target = '192.168.11.124';
$port = 12345;

$nGroup=$_GET['group'];
$nSwitch=$_GET['switch'];
$nAction=$_GET['action'];


// actually send
$output = $nGroup.$nSwitch.$nAction;
if (strlen($output) == 8) {
Expand Down Expand Up @@ -36,57 +35,46 @@
<?php


$names=array("Schreibtisch","Sofa", "TV", "Verstaerker", "e", "f", "g", "h", "i", "j", "k");
$groups=array("00001", "00010");
$index=0;
echo "<TABLE BORDER=\"0\"><TR>";
foreach($groups as $ig) {
for ($is=1; $is<=5; $is++) {
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n");
socket_bind($socket, $source) or die("Could not bind to socket\n");
socket_connect($socket, $target, $port) or die("Could not connect to socket\n");
echo "<TABLE BORDER=\"0\">\n";
foreach($config as $current) {
$ig = $current[0];
$is = $current[1];
$id = $current[2];

$output = $ig."0".$is."2";
socket_write($socket, $output, strlen ($output)) or die("Could not write output\n");
$state = socket_read($socket, 2048);
if ($state == 0) {
$color=" BGCOLOR=\"#C00000\"";
$action = 1;
$done="switch on";
}
if ($state == 1) {
$color=" BGCOLOR=\"#00C000\"";
$action = 0;
$done="switch off";
}
if (($ig == $nGroup) && ($is == $nSwitch)) {
if ($state == 1) {
$done="switched on";
$color=" BGCOLOR=\"#00FF00\"";
}
else if ($state == 0) {
$done="switched off";
$color=" BGCOLOR=\"#FF0000\"";
}
}
echo "<TD class=outer ".$color.">";
echo "<TABLE><TR><TD class=inner BGCOLOR=\"#000000\">";
echo "<A HREF=\"?group=".$ig;
echo "&switch=0".$is;
echo "&action=".$action."\">";
echo "<H3>".$names[$index]."</H3><BR />";
echo $ig.":".$is."<BR />";
echo $done;
echo "</A>";
echo "</TD></TR></TABLE>";
echo "</TD>";
// socket_close($socket);
if ($index%2 == 1) {
echo "</TR><TR>";
}
$index++;
socket_close($socket);
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Could not create socket\n");
socket_bind($socket, $source) or die("Could not bind to socket\n");
socket_connect($socket, $target, $port) or die("Could not connect to socket\n");

$output = $ig.$is."2";
socket_write($socket, $output, strlen ($output)) or die("Could not write output\n");
$state = socket_read($socket, 2048);
if ($state == 0) {
$color=" BGCOLOR=\"#C00000\"";
$ia = 1;
$direction="on";
}
if ($state == 1) {
$color=" BGCOLOR=\"#00C000\"";
$ia = 0;
$direction="off";
}
if ($index%2 == 0) echo "<TR>\n";
echo "<TD class=outer ".$color.">\n";
echo "<TABLE><TR><TD class=inner BGCOLOR=\"#000000\">";
echo "<A CLASS=\"".$direction."\" HREF=\"?group=".$ig;
echo "&switch=".$is;
echo "&action=".$ia."\">";
echo "<H3>".$id."</H3><BR />";
echo $ig.":".$is."<BR />";
echo "switch ".$direction;
echo "</A>";
echo "</TD>";
echo "</TR></TABLE>\n";
echo "</TD>\n";
if ($index%2 == 1) echo "</TR>\n";
$index++;
socket_close($socket);
}
echo "</TR></TABLE>";
?>
Expand Down
55 changes: 8 additions & 47 deletions webinterface/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,10 @@ body {
font-size: 26px;
}

h1 {
}

h2 {
}

h3 {
font-size: 30px;
}

p {
}

div {
width: 495px;
padding: 10px;
}

div.changelog {
color: #ffffff;
background-color: #14171b;
}

table {
vertical-align: middle;
text-align: center;
Expand Down Expand Up @@ -58,39 +39,19 @@ a:hover {
color: #298aad;
text-decoration: none;
}
a:active {
color: #ffffff; i
a.on:hover {
color: #00ff00;
text-decoration: none;
}

span {
color: #ffffff;
}


.ics {
color: #298aad;
}

ul {
list-style-type: circle;
color: #298aad;
a.off:hover {
color: #ff0000;
text-decoration: none;
}

li {
color: #ffffff;
a:active {
color: #ffffff; i
text-decoration: none;
}

/* Display */
.hidden { display: none; }
.visible { display: block; }

/* Visibility */
/*
.hidden { visibility: hidden; }
.visible { visibility: visible; }
*/

/* Android HDPI */
@media only screen and (-webkit-device-pixel-ratio:1.5) {
}
Expand Down

0 comments on commit 47e9447

Please sign in to comment.