spark-o-matic
Group: Members
Posts: 68
Joined: Jan. 2008 |
|
Posted: Nov. 16 2008,19:40 |
|
Morning all,
I use my DSL/Apache computer and xmms to play music. Aumix works great but it's a pain to run to that computer to change volume or log in on ssh all the time. So I spent last night and this morning working on this little bit of code to set volumes from a web page.
This is the part written in PERL.
Code Sample | #!/usr/bin/perl
$cmd="aumix"; @validappend=('w', 'v', 'l', 'i' );
$postcmd="aumix -q >aumix.html";
if ($ENV{'REQUEST_METHOD'} eq 'GET') { @pairs = split(/&/, $ENV{'QUERY_STRING'}); } elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); } else { print "Content-Type: text/html\n\n"; print "ERROR READING FORM DATA\n\n"; exit; } foreach $pair (@pairs) { local($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/<!--(.|\n)*-->//g; if ($data{$name} && $value) { $data{$name} = "$data{$name}, $value"; } elsif ($value) { push(@Field_Order,$name); $data{$name} = $value; }}
$nappend=@validappend; for ($cc0=0;$cc0<=$nappend;$cc0++) { if ($data{$validappend[$cc0]}) { $cmd="$cmd \-$validappend[$cc0] $data{$validappend[$cc0]}"; }
} $ti=time();
system "$cmd";
system "$postcmd";
print "location: aumix.html?$ti\n\n";
exit; |
This is an example of what you might include in an html page.
Code Sample | MASTER VOLUME <a href="aumix.cgi?v=1" target="plist">MUTE</a> <a href="aumix.cgi?v=-1" target="plist">-1</a> <a href="aumix.cgi?v=-3" target="plist">-3</a> <a href="aumix.cgi?v=-7" target="plist">-7</a> <a href="aumix.cgi?v=80" target="plist">80</a> <a href="aumix.cgi?v=95" target="plist">95</a> <a href="aumix.cgi?v=%2b7" target="plist">+7</a> <a href="aumix.cgi?v=%2b3" target="plist">+3</a> <a href="aumix.cgi?v=%2b1" target="plist">+1</a><br> PCM WAVE <a href="aumix.cgi?w=1" target="plist">MUTE</a> <a href="aumix.cgi?w=-1" target="plist">-1</a> <a href="aumix.cgi?w=-3" target="plist">-3</a> <a href="aumix.cgi?w=-7" target="plist">-7</a> <a href="aumix.cgi?w=35" target="plist">35</a> <a href="aumix.cgi?w=50" target="plist">50</a> <a href="aumix.cgi?w=85" target="plist">85</a> <a href="aumix.cgi?w=99" target="plist">99</a> <a href="aumix.cgi?w=%2b7" target="plist">+7</a> <a href="aumix.cgi?w=%2b3" target="plist">+3</a> <a href="aumix.cgi?w=%2b1" target="plist">+1</a><br> <a href="aumix.cgi?w=55&v=80" target="plist">low</a> <a href="aumix.cgi?w=85&v=80" target="plist">high</a> <a href="aumix.cgi?w=95&v=95" target="plist">Crank It Up!!</a> <br>
|
This also works directly typing in something like
Code Sample | http://192.168.1.2/aumix.cgi?v=80&w=75 | which sets volume to 80 and pcm to 75.I designed this to use two frames and work without Java. aumix -q shows up in the second frame. I wrote it to be flexible and at least a little secure. By changing the values of $cmd and @validappend I suppose most any command can be executed but they also limit what can be done. $postcmd will change what shows up on the html page. I used html because I am going to be doing more with this in the grander scheme of things. It displays better as a txt and thats easy enough by changing the file name in two places.
I have only tested this with the Apache extention. If someone gets it working with Monkey I'd be interested to know.
-------------- The smartest person is not the person who knows the most. The smartest person is the one who knows which book to look in. Community knowledge can be the sum of it's knowledge or the sum of it's ignorance The Definition of a 'Brain Fart': When something comes out of my brain that Stinks!
|