/
index.php
executable file
·143 lines (135 loc) · 3.69 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/*
* Raspberry Remote
* http://xkonni.github.com/raspberry-remote/
*
* webinterface
*
*/
/*
* get configuration
* don't forget to edit config.php
*/
include("config.php");
include("shutdown.php");
/*
* get parameters
*/
if (isset($_GET['sys'])) $nSys=$_GET['sys'];
else $nSys="";
if (isset($_GET['group'])) $nGroup=$_GET['group'];
else $nGroup="";
if (isset($_GET['switch'])) $nSwitch=$_GET['switch'];
else $nSwitch="";
if (isset($_GET['action'])) $nAction=$_GET['action'];
else $nAction="";
if (isset($_GET['delay'])) $nDelay=$_GET['delay'];
else $nDelay=0;
/*
* actually send to the daemon
* then reload the webpage without parameters
* except for delay
*/
$output = $nSys.$nGroup.$nSwitch.$nAction.$nDelay;
if (strlen($output) >= 5) {
$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");
socket_write($socket, $output, strlen ($output)) or die("Could not write output\n");
socket_close($socket);
header("Location: index.php?delay=$nDelay");
}
?>
<html>
<head>
<title>raspberry</title>
<link rel="stylesheet" href="style.css">
<link rel="icon"
type="image/png"
href="favicon.png">
<meta name="viewport"
content="
height = device-height,
width = device-width,
initial-scale = 1.0,
user-scalable = no ,
target-densitydpi = device-dpi
" />
</head>
<body>
<?php
/*
* links to change the delay
*/
echo "<P>Delay: ";
echo "<A";
if ($nDelay == 0) echo " class=\"bold\"";
echo " HREF=\"index.php?delay=0\">0</A> | ";
echo "<A";
if ($nDelay == 5) echo " class=\"bold\"";
echo " HREF=\"index.php?delay=5\">5</A> | ";
echo "<A";
if ($nDelay == 15) echo " class=\"bold\"";
echo " HREF=\"index.php?delay=15\">15</A> | ";
echo "<A";
if ($nDelay == 30) echo " class=\"bold\"";
echo " HREF=\"index.php?delay=30\">30</A> | ";
echo "<A";
if ($nDelay == 60) echo " class=\"bold\"";
echo " HREF=\"index.php?delay=60\">60</A> ";
echo "</P>";
/*
* table containing all configured sockets
*/
$index=0;
echo "<TABLE BORDER=\"0\">\n";
foreach($config as $current) {
if ($current != "") {
$iSys = $current[0];
$ig = $current[1];
$is = $current[2];
$id = $current[3];
if ($index%2 == 0) echo "<TR>\n";
$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 = $iSys.$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";
}
echo "<TD class=outer ".$color.">\n";
echo "<TABLE><TR><TD class=inner BGCOLOR=\"#000000\">";
echo "<A CLASS=\"".$direction."\" HREF=\"?group=".$ig;
echo "&sys=".$iSys;
echo "&switch=".$is;
echo "&action=".$ia;
echo "&delay=".$nDelay."\">";
echo "<H3>".$id."</H3><BR />";
echo $iSys.":".$ig.":".$is."<BR />";
echo "switch ".$direction;
echo "</A>";
echo "</TD>";
echo "</TR></TABLE>\n";
echo "</TD>\n";
socket_close($socket);
}
else {
echo "<TD></TD>\n";
}
if ($index%2 == 1) echo "</TR>\n";
$index++;
}
echo "</TR></TABLE>";
?>
<a id="shutdown" href='shutdown.php?shutdown=true'>Shutdown System</a>
</body>
</html>