-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote_control.pl
More file actions
executable file
·178 lines (163 loc) · 5.61 KB
/
remote_control.pl
File metadata and controls
executable file
·178 lines (163 loc) · 5.61 KB
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
169
170
171
172
173
174
175
176
177
178
#
# Remote control v1.0
#
# This perl script is a simple web interface remote control for alsa sound and
# umplayer. Can be easily be adapt for other players.
#
# HOW TO USE:
#
# Run the script on your computer. open a web browser in your favorite mobile
# device and acess "http://computer.ip.adress:9000".
#
# Note that the computer and the mobile device must be in the same network
#
#
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# Copyright 2013 Raphael David François
#
# getIPAdress function by chrisjarzebiak on
# http://chrisjarzebiak.blogspot.com.br/2013/05/relearning-things-few-codes.html
#
#
#!/usr/bin/perl
use IO::Socket;
sub getIPAddress() {
my $ifconfig = `which ifconfig`
or return "UNDEFINED1";
chomp $ifconfig;
my @ifconfig_output = `$ifconfig -a 2>&1`
or return "UNDEFINED2";
my $interface;
my $STATE;
my $IP;
foreach (@ifconfig_output) {
$interface = $1 if /^(\S+?):?\s/;
next unless defined $interface;
$STATE = uc($1) if /\b(up|down)\b/i;
$IP = $1 if /inet\D+(\d+\.\d+\.\d+\.\d+)/i;
if ( defined $STATE and $STATE eq "UP" ) {
if ( defined $IP and $IP ne "0.0.0.0" and $IP ne "127.0.0.1" ) {
return $IP;
}
}
}
return "UNDEFINED3";
}
my $IP_LOCAL = getIPAddress();
my $HEADER = <<HTML_HEADER;
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
HTML_HEADER
my $PAGE1 = <<HTML_PAGE1;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body bgcolor="#000000" text="ffffff">
<div align="center">
<table style="height:200px; width:500x">
<tr>
<td colspan="3"><div style="text-align: center; font-size: 30px">Volume</div></td>
</tr>
HTML_PAGE1
my $PAGE3 = <<HTML_PAGE3;
<tr>
<td>
<div style="text-align: center"><a href="http://$IP_LOCAL:9000/vol_up_master" style="text-decoration: none"><input style="font-size: 180px; height: 200px; width: 200px" type="button" value="+" /></div>
<div style="text-align: center"><a href="http://$IP_LOCAL:9000/vol_down_master" style="text-decoration: none"><input style="font-size: 180px; height: 200px; width: 200px" type="button" value="-" /></div>
</td>
<td></td>
<td>
<div style="text-align: center"><a href="http://$IP_LOCAL:9000/vol_up_umplayer" style="text-decoration: none"><input style="font-size: 180px; height: 200px; width: 200px" type="button" value="+" /></div>
<div style="text-align: center"><a href="http://$IP_LOCAL:9000/vol_down_umplayer" style="text-decoration: none"><input style="font-size: 180px; height: 200px; width: 200px" type="button" value="-" /></div>
</td>
</tr>
<tr>
<td colspan="3"><div style="text-align: center; font-size: 30px"><br>Umplayer</div></td>
</tr>
<tr>
<td colspan="3"><div style="text-align: center"><a href="http://$IP_LOCAL:9000/play_pause_umplayer" style="text-decoration: none"><input style="font-size: 80px; height: 200px; width: 520px" type="button" value="PLAY/PAUSE" /></div></td>
</tr>
<tr>
<td colspan="3"><div style="text-align: center"><a href="http://$IP_LOCAL:9000/rewind_umplayer" style="text-decoration: none"><input style="font-size: 80px; height: 200px; width: 200px" type="button" value="<<" /><a href="http://$IP_LOCAL:9000/forward_umplayer" style="text-decoration: none"><input style="font-size: 80px; height: 200px; width: 200px" type="button" value=">>" /></div></td>
</tr>
</table>
</div>
</body>
</body>
</html>
HTML_PAGE3
$port = 9000;
$server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $port,
Listen => SOMAXCONN,
Reuse => 1 );
die "server error" unless $server;
while ($client = $server->accept()) {
$client->autoflush(1);
$i = 0;
while (<$client>) {
if ($i == 0) {
if ($_ =~ /vol_up_master/) {
print "VOL_UP\n";
$out = `amixer sset Master 5+`;
}
elsif ($_ =~ /vol_down_master/) {
print "VOL_DOWN\n";
$out = `amixer sset Master 5-`;
}
elsif ($_ =~ /vol_up_umplayer/) {
print "VOL_UP_UMPLAYER\n";
$out = `umplayer -send-action increase_volume`;
}
elsif ($_ =~ /vol_down_umplayer/) {
print "VOL_DOWN_UMPLAYER\n";
$out = `umplayer -send-action decrease_volume`;
}
elsif ($_ =~ /rewind_umplayer/) {
print "BACK_UMPLAYER\n";
$out = `umplayer -send-action rewind1`;
}
elsif ($_ =~ /forward_umplayer/) {
print "FORWARD_UMPLAYER\n";
$out = `umplayer -send-action forward1`;
}
elsif ($_ =~ /play_pause/) {
print "PLAY_PAUSE\n";
$out = `umplayer -send-action pause`;
}
else {
print ".\n";
}
my $MASTER_VOL = `amixer get Master | grep %| cut -d ' ' -f 6`;
$PAGE2 = <<HTML_PAGE2;
<tr>
<td width=40%><div style="text-align: center; font-size: 25px"> Master <b>$MASTER_VOL</b></div></td>
<td width=20%><div style="text-align: center"></div></td>
<td width=40%><div style="text-align: center; font-size: 25px"> Umplayer <b>?%</b></div></td>
</tr>
HTML_PAGE2
print $client "$HEADER $PAGE1.$PAGE2.$PAGE3";
$i=1;
close $client;
last;
}
}
}
close $client;