summaryrefslogtreecommitdiffstats
path: root/abs/core/local-website/htdocs/remote/backend.php
blob: 530d220d0a32d4556781d3bced3c05a160b70b1e (plain)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?
#
# Original code (c) 2006  Mike Poublon <poublon@geeksoft.dyndns.org>
#
# Enhancements (c) 2006 Steven Ellis <support@openmedia.co.nz> and
#              (c) 2006 Mike Poublon <poublon@geeksoft.dyndns.org>
#

#change the line below that has localhost pointing to the address of your frontend.
$HOSTNAME = "localhost";

$submit = $_POST['submit'];

#workaround for IE's image button wierdness
if ( $submit == "" )
{
	$submit = $_POST['buttonvalue'];
}

#if we aren't being posted to, then don't do anything useful
if ( $submit == "" )
{
	echo "Sorry, this file is meant to be called by one of the frontend ";
	echo "pages, please try using one of them instead.";
	exit();
}

# We set jump when we want to perform more complex commands
$jump="";

if ($submit == "Power"){
	#Power - not really used yet
	$key = "";
} else if ($submit == "TV"){
	$jump = "livetv";
} else if ($submit == "Music"){
	$jump = "playmusic";
} else if ($submit == "Video"){
	$jump = "mythvideo";
} else if ($submit == "Recordings"){
	$jump = "playbackrecordings";
} else if ($submit == "Guide"){
	$jump = "programguide";
} else if ($submit == "Pictures"){
	$jump = "mythgallery";
} else if ($submit == "Back") {
	$key = "escape";
} else if ($submit == "Info") {
	$key = "i";
} else if ($submit == "Menu") {
	#Menu
	$key = "m";
} else if ($submit == "U") {
	$key = "up";
} else if ($submit == "L") {
	$key = "left";
} else if ($submit == "D") {
	$key = "down";
} else if ($submit == "R") {
	$key = "right";
} else if ($submit == "OK") {
	$key = "enter";
} else if ($submit == "Page Up") {
	$key = "pageup";
} else if ($submit == "Page Dn") {
	$key = "pagedown";
} else if ($submit == "Vol Up") {
	$key = "bracketright";
} else if ($submit == "Vol Dn") {
	$key = "bracketleft";
} else if ($submit == "Mute") {
	$key = "f9";
} else if ($submit == "Pause") {
	$key = "p";
} else if ($submit == "Stop") {
	$key = "s";
} else if ($submit == "Play") {
	$key = "p";
} else if ($submit == "Rec") {
	$key = "r";
} else if ($submit == "<<") {
	$key = "left";
} else if ($submit == ">>") {
	$key = "right";
} else if ($submit == "|<") {
	#skip commercial back
	$key = "q";
} else if ($submit == ">|") {
	#skip commercial
	$key = "z";
# Special keys used by myPVR
} else if ($submit == "#") {
	# Change tuner
	$key = "y";
} else if ($submit == "*") {
	#skip commercial
	$key = "z";
} else if ($submit == "0" ||
           $submit == "1" ||
           $submit == "2" ||
           $submit == "3" ||
           $submit == "4" ||
           $submit == "5" ||
           $submit == "6" ||
           $submit == "7" ||
           $submit == "8" ||
           $submit == "9" ) {
	$key = $submit;
}

#set the maximum time to execute the page
set_time_limit (5);

#open the socket to the frontend
$fp = fsockopen($HOSTNAME, 6546, $errno, $errstr, 30);

if (!$fp) {
	#couldn't connect, print the error
	echo "ERROR: $errstr ($errno)<br />\n";
	exit();
} else {
	#set up a place for the banner to get read into
	$banner = "";

	#read through the banner, one char at a time and append
	#to the banner string until we see a '#'
	$c = fgetc($fp);
	while ($c !== false && $c != "#")
	{
		$banner .= $c;
		$c = fgetc($fp);
	}
	if ($c !== false)
	{
		#if the connection is still valid then read
		#in the extra space after the #
		$c = fgetc($fp);
	}

	#create the command to issue to the frontend based
	#on what the user clicked on
	if ($jump != "") {
		$cmd = "jump $jump\x0d\x0a";
		$jump="";
	} else {
		$cmd = "key $key\x0d\x0a";
	}

	#write the command to the socket
	fwrite($fp,$cmd);

	#close the socket
	fclose($fp);

	#get the specified page to redirect to
	$redirectpage = $_POST['redirectpage'];
	if ( $redirectpage == ""  ) 
	{
		#use the refering page if all else fails
		$redirectpage = getenv('HTTP_REFERER');
	}

	#redirect to the desired location
	header( "Location: $redirectpage" );
}

?>