- Copy the example iceplex.conf to /etc/iceplex.conf and modify the settings
as appropriate:
- Database location/user/pass
- - Path to mp3 file storage on the icecast servers.
+ - Path to mp3 file storage on the icecast servers
- Icecast port number
- -
+ - Optional database query for file number override
+ - Normal database query for filen number
- Run iceplexd and configure your init scripts to start it upon boot.
- Create an "iceplex" user.
- Run "ssh-keygen -t dsa" as the "iceplex" user to genarate SSH keys.
#database connection info
$dsn = 'DBI:mysql:imedia';
-$user = 'imedia';
-$pass = 'imedia';
+$user = 'ivan';
+$pass = '';
#path to mp3 files on icecast servers
$mp3path = '/home/ivan/plexmp3';
# the same terms as Perl itself.
use strict;
-use subs qw(pick_server);
+use subs qw(suidsetup pick_server);
use CGI;
use CGI::Carp qw(fatalsToBrowser);
-use Digest::MD5;
+use Digest::MD5 qw(md5_hex);
+use DBI;
use Net::SSH qw(ssh);
+suidsetup();
+
# pull in configuration
use vars qw($dsn $user $pass $mp3path $port);
use vars qw($override_query $fileno_query);
$dbh->disconnect;
#generate a mountpoint
-my $mountpoint = md5_hex($cgi->remote_host. $$. time. int(rand(4294967296)));
+md5_hex($cgi->remote_host. $$. time. int(rand(4294967296))) =~ /^(\w+)$/;
+my $mountpoint = $1;
#signal encoder to start streaming to mountpoint & wait for confirmation
+warn "ssh $server yashout $filename $mountpoint $port\n";
ssh($server, 'yashout', $filename, $mountpoint, $port );
#send file back to client browser
print $cgi->header( -type => $extension2type{$extension} );
-print "[playlist]\nNumberOfEntries=1\n" if $extension eq 'pls';
+print "[playlist]\nNumberOfEntries=1\nFile1=" if $extension eq 'pls';
print "http://$server:$port/$mountpoint\n";
###
# subroutiens
###
+sub suidsetup {
+ $ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin';
+ $ENV{'SHELL'} = '/bin/sh';
+ $ENV{'IFS'} = " \t\n";
+ $ENV{'CDPATH'} = '';
+ $ENV{'ENV'} = '';
+ $ENV{'BASH_ENV'} = '';
+
+ $< = $>; #correct uid for spawned ssh process
+}
+
sub pick_server {
my $sth = $dbh->prepare(
"SELECT servername FROM iceplex_servers ".
use strict;
use subs qw(daemonize);
+use POSIX qw(:sys_wait_h setsid);
use Shout;
+my $encoder_password = 'haze420';
+
#read options from commandline
my($filename, $mountpoint, $port) = @ARGV;
ip => 'localhost',
port => $port || 8000,
mount => $mountpoint,
+ password => $encoder_password,
icy_compat => 0,
dumpfile => undef,
name => 'Fonestream audio',
url => 'http://www.fonestream.com/',
genre => 'talk',
description => 'The easiest way to webcast.',
- bitrate => 64,
+ bitrate => 16,
ispublic => 0,
);
$conn->connect or die "Failed to connect: ". $conn->error;
+open(SFILE,"</home/ivan/plexmp3/silence.mp3") or die "Can't open silence.mp3: $!";
open(FILE,"<$filename") or die "Can't open $filename: $!";
daemonize(); #fork/disconnect so plex.pls will return to client
+if ( 0 ) {
+
+ #send silence header to server
+ my( $sbuffer, $sbytes ) = ( '', 0 );
+ while ( ( $sbytes = read( SFILE, $sbuffer, 4096 ) ) > 0 ) {
+ $conn->sendData( $sbuffer ) && next;
+ # error handling???
+ print STDERR "Error while sending: ", $conn->error, "\n";
+ last;
+ } continue {
+ $conn->sleep;
+ }
+
+}
+
+sleep 10;
+
#spool file to server
my( $buffer, $bytes ) = ( '', 0 );
while ( ( $bytes = read( FILE, $buffer, 4096 ) ) > 0 ) {
defined(my $pid = fork) or die "Can't fork: $!";
if ( $pid ) {
#print "yashout started with pid $pid\n"; #logging to $log_file\n";
- exit unless $pid_file;
+ #exit unless $pid_file;
#my $pidfh = new IO::File ">$pid_file" or exit;
#print $pidfh "$pid\n";
exit;