/
hcontrolclient.php
executable file
·85 lines (73 loc) · 1.37 KB
/
hcontrolclient.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
#! /usr/bin/php
<?
//lets look for arg
if(sizeof($argv) < 2)
{
sendcmd('-h');
die;
}
for($i=1;$i < sizeof($argv); $i++)
{
if ($i == 1)
{
$cstring=$argv[$i];
}else{
$cstring .= " " .$argv[$i];
}
}
sendcmd($cstring);
/*switch ($argv[1]) {
case 'test':
sendcmd('test');
break;
case '-D':
setsock();
$GLOBALS['debug'] = false;
main();
break;
default:
//showusage();
echo "thanks for playing\n\n";
return;
break;
}*/
function sendcmd($cmd)
{
// where is the socket server?
$host="127.0.0.1";
$port = 9900;
// open a client connection
$fp = fsockopen ($host, $port, $errno, $errstr);
if (!$fp)
{
$result = "Error: could not open socket connection";
$result .= "Check that rgbledsck.php is running";
}
else
{
// get the welcome message
//fgets ($fp, 1024);
// write the user string to the socket
fputs ($fp, $cmd);
// get the result
//$result = fgets ($fp, 100000);
$result = fread($fp, 100000);
// close the connection
fputs ($fp, "exit");
fclose ($fp);
// trim the result and remove the starting ?
//$result = trim($result);
//$result = substr($result, 2);
$r = explode("*", $result);
for($i =0;$i < sizeof($r); $i++)
{
echo $r[$i] ."\n";
}
// now print it to the browser
/*}
?>
Server said: <b><? echo $result; ?></b>
<?*/
}
}
?>