summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-10-10 07:30:15 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-10-10 07:30:15 +0000
commitff58181d5b4ddd10b34062a0ad2204435e698cae (patch)
tree60b4654309d0826c81411790efe8448675a038bb /lib
parent32349846fbd66e4ebc44e63d37fbcd8cff5a8a73 (diff)
downloadampache-ff58181d5b4ddd10b34062a0ad2204435e698cae.tar.gz
ampache-ff58181d5b4ddd10b34062a0ad2204435e698cae.tar.bz2
ampache-ff58181d5b4ddd10b34062a0ad2204435e698cae.zip
fixed acls, fixed transcoding issues
Diffstat (limited to 'lib')
-rw-r--r--lib/class/access.class.php205
-rw-r--r--lib/class/ajax.class.php25
-rw-r--r--lib/class/song.class.php2
-rw-r--r--lib/class/stream.class.php110
-rw-r--r--lib/preferences.php2
-rw-r--r--lib/stream.lib.php111
-rw-r--r--lib/ui.lib.php15
7 files changed, 226 insertions, 244 deletions
diff --git a/lib/class/access.class.php b/lib/class/access.class.php
index d3f01c2b..596f6c54 100644
--- a/lib/class/access.class.php
+++ b/lib/class/access.class.php
@@ -23,124 +23,111 @@
* This class handles the access list mojo for Ampache, it is ment to restrict
* access based on IP and maybe something else in the future
*/
-
class Access {
/* Variables from DB */
- var $id;
- var $name;
- var $start;
- var $end;
- var $level;
- var $user;
- var $type;
- var $key;
-
- /*!
- @function Access
- @discussion Access class, for modifing access rights
- @param $access_id The ID of access entry
+ public $id;
+ public $name;
+ public $start;
+ public $end;
+ public $level;
+ public $user;
+ public $type;
+ public $key;
+
+ /**
+ * constructor
+ * Takes an ID of the access_id dealie :)
*/
- function Access($access_id = 0) {
+ public function __construct($access_id='') {
if (!$access_id) { return false; }
-
/* Assign id for use in get_info() */
$this->id = intval($access_id);
- $info = $this->get_info();
- $this->name = $info->name;
- $this->start = $info->start;
- $this->end = $info->end;
- $this->level = $info->level;
- $this->key = $info->key;
- $this->user = $info->user;
- $this->type = $info->type;
+ $info = $this->_get_info();
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
return true;
- } //Access
+ } // Constructor
- /*!
- @function get_info
- @discussion get's the vars for $this out of the database
- @param $this->id Taken from the object
- */
- function get_info() {
+ /**
+ * _get_info
+ * get's the vars for $this out of the database
+ * Taken from the object
+ */
+ private function _get_info() {
/* Grab the basic information from the catalog and return it */
- $sql = "SELECT * FROM access_list WHERE id='" . sql_escape($this->id) . "'";
- $db_results = mysql_query($sql, dbh());
+ $sql = "SELECT * FROM `access_list` WHERE `id`='" . Dba::escape($this->id) . "'";
+ $db_results = Dba::query($sql);
- $results = mysql_fetch_object($db_results);
+ $results = Dba::fetch_assoc($db_results);
return $results;
- } //get_info
+ } // _get_info
/**
* update
* This function takes a named array as a datasource and updates the current access list entry
*/
- function update($data) {
+ public function update($data) {
+ $name = Dba::escape($data['name']);
+ $type = self::validate_type($data['type']);
$start = ip2int($data['start']);
$end = ip2int($data['end']);
- $level = sql_escape($data['level']);
- $user = sql_escape($data['user']);
- $key = sql_escape($data['key']);
+ $level = Dba::escape($data['level']);
+ $user = $data['user'] ? Dba::escape($data['user']) : '-1';
+ $key = Dba::escape($data['key']);
- if (!$user) { $user = '-1'; }
-
- $sql = "UPDATE access_list " .
- "SET start='$start', end='$end', level='$level', user='$user', `key`='$key' " .
- "WHERE id='" . sql_escape($this->id) . "'";
-
- $db_results = mysql_query($sql, dbh());
+ $sql = "UPDATE `access_list` " .
+ "SET `start`='$start', `end`='$end', `level`='$level', `user`='$user', `key`='$key', " .
+ "`name`='$name', `type`='$type' WHERE `id`='" . Dba::escape($this->id) . "'";
+ $db_results = Dba::query($sql);
return true;
} // update
- /*!
- @function create
- @discussion creates a new entry
- */
- function create($name,$start,$end,$level,$user,$key,$type) {
+ /**
+ * create
+ * This takes a key'd array of data and trys to insert it as a
+ * new ACL entry
+ */
+ public static function create($data) {
/* We need to verify the incomming data a littlebit */
- $start = ip2int($start);
- $end = ip2int($end);
- $name = sql_escape($name);
- $key = sql_escape($key);
- $user = sql_escape($user);
- $level = intval($level);
- $type = $this->validate_type($type);
-
- if (!$user) { $user = '-1'; }
-
- $sql = "INSERT INTO access_list (`name`,`level`,`start`,`end`,`key`,`user`,`type`) " .
+ $start = ip2int($data['start']);
+ $end = ip2int($data['end']);
+ $name = Dba::escape($data['name']);
+ $key = Dba::escape($data['key']);
+ $user = $data['user'] ? Dba::escaep($data['user']) : '-1';
+ $level = intval($data['level']);
+ $type = self::validate_type($data['type']);
+
+ $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`key`,`user`,`type`) " .
"VALUES ('$name','$level','$start','$end','$key','$user','$type')";
- $db_results = mysql_query($sql, dbh());
+ $db_results = Dba::query($sql);
return true;
} // create
- /*!
- @function delete
- @discussion deletes $this access_list entry
- */
- function delete($access_id=0) {
-
- if (!$access_id) {
- $access_id = $this->id;
- }
+ /**
+ * delete
+ * deletes the specified access_list entry
+ */
+ public static function delete($access_id) {
- $sql = "DELETE FROM access_list WHERE id='" . sql_escape($access_id) . "'";
- $db_results = mysql_query($sql, dbh());
+ $sql = "DELETE FROM `access_list` WHERE `id`='" . Dba::escape($access_id) . "'";
+ $db_results = Dba::query($sql);
} // delete
@@ -193,11 +180,11 @@ class Access {
* however we don't have the key that was passed yet so we've got to do just ip
*/
case 'init-xml-rpc':
- $sql = "SELECT id FROM access_list" .
+ $sql = "SELECT `id` FROM `access_list`" .
" WHERE `start` <= '$ip' AND `end` >= '$ip' AND `type`='xml-rpc' AND `level` >= '$level'";
break;
case 'xml-rpc':
- $sql = "SELECT id FROM access_list" .
+ $sql = "SELECT `id` FROM `access_list`" .
" WHERE `start` <= '$ip' AND `end` >= '$ip'" .
" AND `key` = '$key' AND `level` >= '$level' AND `type`='xml-rpc'";
break;
@@ -205,7 +192,7 @@ class Access {
case 'interface':
case 'stream':
default:
- $sql = "SELECT id FROM access_list" .
+ $sql = "SELECT `id` FROM `access_list`" .
" WHERE `start` <= '$ip' AND `end` >= '$ip'" .
" AND `level` >= '$level' AND `type` = '$type'";
if (strlen($user)) { $sql .= " AND (`user` = '$user' OR `user` = '-1')"; }
@@ -231,7 +218,7 @@ class Access {
* validate_type
* This cleans up and validates the specified type
*/
- function validate_type($type) {
+ public static function validate_type($type) {
switch($type) {
case 'xml-rpc':
@@ -243,72 +230,63 @@ class Access {
return 'stream';
break;
} // end switch
+
} // validate_type
- /*!
- @function get_access_list
- @discussion returns a full listing of all access
- rules on this server
- */
- function get_access_list() {
+ /**
+ * get_access_lists
+ * returns a full listing of all access rules on this server
+ */
+ public static function get_access_lists() {
- $sql = "SELECT * FROM access_list";
- $db_results = mysql_query($sql, dbh());
-
+ $sql = "SELECT `id` FROM `access_list`";
+ $db_results = Dba::query($sql);
+
+ $results = array();
+
// Man this is the wrong way to do it...
- while ($r = mysql_fetch_object($db_results)) {
- $obj = new Access();
- $obj->id = $r->id;
- $obj->start = $r->start;
- $obj->end = $r->end;
- $obj->name = $r->name;
- $obj->level = $r->level;
- $obj->user = $r->user;
- $obj->key = $r->key;
- $obj->type = $r->type;
- $results[] = $obj;
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
} // end while access list mojo
return $results;
- } // get_access_list
+ } // get_access_lists
- /*!
- @function get_level_name
- @discussion take the int level and return a
- named level
- */
- function get_level_name() {
+ /**
+ * get_level_name
+ * take the int level and return a named level
+ */
+ public function get_level_name() {
if ($this->level == '75') {
- return "Read/Write/Modify";
+ return _('All');
}
if ($this->level == '5') {
- return "View";
+ return _('View');
}
if ($this->level == '25') {
- return "Read";
+ return _('Read');
}
if ($this->level == '50') {
- return "Read/Write";
+ return _('Read/Write');
}
-
} // get_level_name
/**
* get_user_name
* Take a user and return their full name
*/
- function get_user_name() {
+ public function get_user_name() {
$user = new User($this->user);
if ($user->username) {
return $user->fullname . " (" . $user->username . ")";
}
- return false;
+ return _('All');
} // get_user_name
@@ -316,7 +294,7 @@ class Access {
* get_type_name
* This function returns the pretty name for our current type
*/
- function get_type_name() {
+ public function get_type_name() {
switch ($this->type) {
case 'xml-rpc':
@@ -333,6 +311,7 @@ class Access {
return 'Stream Access';
break;
} // end switch
+
} // get_type_name
} //end of access class
diff --git a/lib/class/ajax.class.php b/lib/class/ajax.class.php
index d0bf4eee..2c0c9aff 100644
--- a/lib/class/ajax.class.php
+++ b/lib/class/ajax.class.php
@@ -40,7 +40,7 @@ class Ajax {
* observe
* This returns a string with the correct and full ajax 'observe' stuff from prototype
*/
- public static function observe($source,$method,$action) {
+ public static function observe($source,$method,$action,$post='') {
$non_quoted = array('document','window');
@@ -51,8 +51,13 @@ class Ajax {
$source_txt = "'$source'";
}
+ // If it's a post then we need to stop events
+ if ($post) {
+ $action = 'Event.stop(e); ' . $action;
+ }
+
$observe = "<script type=\"text/javascript\">";
- $observe .= "Event.observe($source_txt,'$method',function(){" . $action . ";});";
+ $observe .= "Event.observe($source_txt,'$method',function(e){" . $action . ";});";
$observe .= "</script>";
return $observe;
@@ -98,7 +103,7 @@ class Ajax {
// Get the correct action
$ajax_string = self::action($action,$source,$post);
- // If they passed a span class
+ // If they passed a span class
if ($class) {
$class_txt = ' class="' . $class . '"';
}
@@ -106,13 +111,13 @@ class Ajax {
$string = get_user_icon($icon,$alt);
- // Generate a <a> so that it's more compliant with older browsers
- // (ie :hover actions) and also to unify linkbuttons (w/o ajax) display
- $string = "<a href=\"javascript:void(0);\" id=\"$source\" $class_txt>".$string."</a>\n";
+ // Generate a <a> so that it's more compliant with older browsers
+ // (ie :hover actions) and also to unify linkbuttons (w/o ajax) display
+ $string = "<a href=\"javascript:void(0);\" id=\"$source\" $class_txt>".$string."</a>\n";
$string .= self::observe($source,'click',$ajax_string);
- return $string;
+ return $string;
} // button
@@ -126,17 +131,13 @@ class Ajax {
// Format the string we wanna use
$ajax_string = self::action($action,$source,$post);
- //$class.= ($class?' ':'') . 'link';
-
// If they passed a span class
if ($class) {
$class_txt = ' class="' . $class . '"';
}
// If we pass a source put it in the ID
- //$string = "<div id=\"$source\" $class_txt>$text</div>\n";
-
- $string = "<a href=\"javascript:void(0);\" id=\"$source\" $class_txt>$text</a>\n";
+ $string = "<a href=\"javascript:void(0);\" id=\"$source\" $class_txt>$text</a>\n";
$string .= self::observe($source,'click',$ajax_string);
diff --git a/lib/class/song.class.php b/lib/class/song.class.php
index 732a0539..d39aef1a 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -129,7 +129,7 @@ class Song {
* play, used to set mime headers and to trick
* players into playing them correctly
*/
- function format_type($override='') {
+ public function format_type($override='') {
// If we pass an override for downsampling or whatever then use it
if (!empty($override)) {
diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php
index 34c15113..72cafa33 100644
--- a/lib/class/stream.class.php
+++ b/lib/class/stream.class.php
@@ -509,6 +509,116 @@ class Stream {
} // create_ram
/**
+ * start_downsample
+ * This is a rather complext function that starts the downsampling of a song and returns the
+ * opened file handled a reference to the song object is passed so that the changes we make
+ * in here affect the external object, References++
+ */
+ public static function start_downsample(&$song,$now_playing_id=0,$song_name=0) {
+
+ /* Check to see if bitrates are set if so let's go ahead and optomize! */
+ $max_bitrate = Config::get('max_bit_rate');
+ $min_bitrate = Config::get('min_bit_rate');
+ $time = time();
+ $user_sample_rate = $GLOBALS['user']->prefs['sample_rate'];
+ $browser = new Browser();
+
+ if (!$song_name) {
+ $song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type;
+ }
+
+ if ($max_bitrate > 1 AND $min_bitrate < $max_bitrate) {
+ $last_seen_time = $time - 1200; //20 min.
+
+ $sql = "SELECT COUNT(*) FROM now_playing, user_preference, preference " .
+ "WHERE preference.name = 'play_type' AND user_preference.preference = preference.id " .
+ "AND now_playing.user = user_preference.user AND user_preference.value='downsample'";
+ $db_results = Dba::query($sql);
+ $results = Dba::fetch_row($db_results);
+
+ // Current number of active streams (current is already in now playing)
+ $active_streams = $results[0];
+
+ /* If only one user, they'll get all available. Otherwise split up equally. */
+ $sample_rate = floor($max_bitrate/$active_streams);
+
+ /* If min_bitrate is set, then we'll exit if the bandwidth would need to be split up smaller than the min. */
+ if ($min_bitrate > 1 AND ($max_bitrate/$active_streams) < $min_bitrate) {
+
+ /* Log the failure */
+ debug_event('downsample',"Error: Max bandwidith already allocated. $active_streams Active Streams",'2');
+
+ /* Toast the now playing entry, then tell em to try again later */
+ delete_now_playing($now_playing_id);
+ echo "Maximum bandwidth already allocated. Try again later.";
+ exit();
+
+ }
+ else {
+ $sample_rate = floor($max_bitrate/$active_streams);
+ } // end else
+
+ // Never go over the users sample rate
+ if ($sample_rate > $user_sample_rate) { $sample_rate = $user_sample_rate; }
+
+ debug_event('downsample',"Downsampled: $active_streams current active streams, downsampling to $sample_rate",'2');
+
+ } // end if we've got bitrates
+
+ else {
+ $sample_rate = $user_sample_rate;
+ }
+
+ /* Validate the bitrate */
+ $sample_rate = validate_bitrate($sample_rate);
+
+ /* Never Upsample a song */
+ if (($sample_rate*1000) > $song->bitrate) {
+ $sample_rate = validate_bitrate($song->bitrate)/1000;
+ $sample_ratio = '1';
+ }
+ else {
+ /* Set the Sample Ratio */
+ $sample_ratio = $sample_rate/($song->bitrate/1000);
+ }
+
+ // Set the new size for the song
+ $song->size = floor($sample_ratio*$song->size);
+
+ /* Get Offset */
+ $offset = ( $start*$song->time )/( $sample_ratio*$song->size );
+ $offsetmm = floor($offset/60);
+ $offsetss = floor($offset-$offsetmm*60);
+ $offset = sprintf("%02d.%02d",$offsetmm,$offsetss);
+
+ /* Get EOF */
+ $eofmm = floor($song->time/60);
+ $eofss = floor($song->time-$eofmm*60);
+ $eof = sprintf("%02d.%02d",$eofmm,$eofss);
+
+ $song_file = escapeshellarg($song->file);
+
+ /* Replace Variables */
+ $downsample_command = Config::get($song->stream_cmd());
+ $downsample_command = str_replace("%FILE%",$song_file,$downsample_command);
+ $downsample_command = str_replace("%OFFSET%",$offset,$downsample_command);
+ $downsample_command = str_replace("%EOF%",$eof,$downsample_command);
+ $downsample_command = str_replace("%SAMPLE%",$sample_rate,$downsample_command);
+
+ // If we are debugging log this event
+ $message = "Start Downsample: $downsample_command";
+ debug_event('downsample',$message,'3');
+
+ $fp = @popen($downsample_command, 'rb');
+
+ /* We need more than just the handle here */
+ $return_array['handle'] = $fp;
+
+ return ($return_array);
+
+ } // start_downsample
+
+ /**
* auto_init
* This is called on class load it sets the session
*/
diff --git a/lib/preferences.php b/lib/preferences.php
index b017803f..c7f503c1 100644
--- a/lib/preferences.php
+++ b/lib/preferences.php
@@ -294,13 +294,13 @@ function create_preference_input($name,$value) {
case 'localplay_controller':
$controllers = Localplay::get_controllers();
echo "<select name=\"$name\">\n";
+ echo "\t<option value=\"\">" . _('None') . "</option>\n";
foreach ($controllers as $controller) {
if (!Localplay::is_enabled($controller)) { continue; }
$is_selected = '';
if ($value == $controller) { $is_selected = 'selected="selected"'; }
echo "\t<option value=\"" . $controller . "\" $is_selected>" . ucfirst($controller) . "</option>\n";
} // end foreach
- echo "\t<option value=\"\">" . _('None') . "</option>\n";
echo "</select>\n";
break;
case 'localplay_level':
diff --git a/lib/stream.lib.php b/lib/stream.lib.php
index f6554e8b..5d6448c0 100644
--- a/lib/stream.lib.php
+++ b/lib/stream.lib.php
@@ -135,117 +135,6 @@ function check_lock_songs($song_id) {
} // check_lock_songs
-/**
- * start_downsample
- * This is a rather complext function that starts the downsampling of a song and returns the
- * opened file handled
- */
-function start_downsample($song,$now_playing_id=0,$song_name=0) {
-
- /* Check to see if bitrates are set if so let's go ahead and optomize! */
- $max_bitrate = Config::get('max_bit_rate');
- $min_bitrate = Config::get('min_bit_rate');
- $time = time();
- $user_sample_rate = $GLOBALS['user']->prefs['sample_rate'];
- $browser = new Browser();
-
- if (!$song_name) {
- $song_name = $song->f_artist_full . " - " . $song->title . "." . $song->type;
- }
-
- if ($max_bitrate > 1 AND $min_bitrate < $max_bitrate) {
- $last_seen_time = $time - 1200; //20 min.
-
- $sql = "SELECT COUNT(*) FROM now_playing, user_preference, preferences " .
- "WHERE preferences.name = 'play_type' AND user_preference.preference = preferences.id " .
- "AND now_playing.user = user_preference.user AND user_preference.value='downsample'";
- $db_results = Dba::query($sql);
- $results = Dba::fetch_row($db_results);
-
- // Current number of active streams (current is already in now playing)
- $active_streams = $results[0];
-
- /* If only one user, they'll get all available. Otherwise split up equally. */
- $sample_rate = floor($max_bitrate/$active_streams);
-
- /* If min_bitrate is set, then we'll exit if the bandwidth would need to be split up smaller than the min. */
- if ($min_bitrate > 1 AND ($max_bitrate/$active_streams) < $min_bitrate) {
-
- /* Log the failure */
- debug_event('downsample',"Error: Max bandwidith already allocated. $active_streams Active Streams",'2');
-
- /* Toast the now playing entry, then tell em to try again later */
- delete_now_playing($now_playing_id);
- echo "Maximum bandwidth already allocated. Try again later.";
- exit();
-
- }
- else {
- $sample_rate = floor($max_bitrate/$active_streams);
- } // end else
-
- // Never go over the users sample rate
- if ($sample_rate > $user_sample_rate) { $sample_rate = $user_sample_rate; }
-
- debug_event('downsample',"Downsampled: $active_streams current active streams, downsampling to $sample_rate",'2');
-
- } // end if we've got bitrates
-
- else {
- $sample_rate = $user_sample_rate;
- }
-
- /* Validate the bitrate */
- $sample_rate = validate_bitrate($sample_rate);
-
- /* Never Upsample a song */
- if (($sample_rate*1000) > $song->bitrate) {
- $sample_rate = validate_bitrate($song->bitrate)/1000;
- $sample_ratio = '1';
- }
- else {
- /* Set the Sample Ratio */
- $sample_ratio = $sample_rate/($song->bitrate/1000);
- }
-
-
- header("Content-Length: " . intval($sample_ratio*$song->size));
- $browser->downloadHeaders($song_name, $song->mime, false,$sample_ratio*$song->size);
-
- /* Get Offset */
- $offset = ( $start*$song->time )/( $sample_ratio*$song->size );
- $offsetmm = floor($offset/60);
- $offsetss = floor($offset-$offsetmm*60);
- $offset = sprintf("%02d.%02d",$offsetmm,$offsetss);
-
- /* Get EOF */
- $eofmm = floor($song->time/60);
- $eofss = floor($song->time-$eofmm*60);
- $eof = sprintf("%02d.%02d",$eofmm,$eofss);
-
- $song_file = escapeshellarg($song->file);
-
- /* Replace Variables */
- $downsample_command = Config::get($song->stream_cmd());
- $downsample_command = str_replace("%FILE%",$song_file,$downsample_command);
- $downsample_command = str_replace("%OFFSET%",$offset,$downsample_command);
- $downsample_command = str_replace("%EOF%",$eof,$downsample_command);
- $downsample_command = str_replace("%SAMPLE%",$sample_rate,$downsample_command);
-
- // If we are debugging log this event
- $message = "Start Downsample: $downsample_command";
- debug_event('downsample',$message,'3');
-
- $fp = @popen($downsample_command, 'rb');
-
- /* We need more than just the handle here */
- $return_array['handle'] = $fp;
- $return_array['size'] = $sample_ratio*$song->size;
-
- return ($return_array);
-
-} // start_downsample
-
/**
* validate_bitrate
* this function takes a bitrate and returns a valid one
diff --git a/lib/ui.lib.php b/lib/ui.lib.php
index efdaa736..d785431f 100644
--- a/lib/ui.lib.php
+++ b/lib/ui.lib.php
@@ -891,19 +891,22 @@ function show_user_select($name,$selected='',$style='') {
echo "<select name=\"$name\" style=\"$style\">\n";
echo "\t<option value=\"\">" . _('None') . "</option>\n";
- $sql = "SELECT username as id,fullname FROM user ORDER BY fullname";
- $db_results = mysql_query($sql, dbh());
+ $sql = "SELECT `id`,`username`,`fullname` FROM `user` ORDER BY `fullname`";
+ $db_results = Dba::query($sql);
- while ($r = mysql_fetch_assoc($db_results)) {
+ while ($row = Dba::fetch_assoc($db_results)) {
$select_txt = '';
- if ($r['id'] == $selected) {
+ if ($row['id'] == $selected) {
$select_txt = 'selected="selected"';
}
+ // If they don't have a full name, revert to the username
+ $row['fullname'] = $row['fullname'] ? $row['fullname'] : $row['username'];
- echo "\t<option value=\"" . $r['id'] . "\" $select_txt>" . scrub_out($r['fullname']) . "</option>\n";
-
+ echo "\t<option value=\"" . $row['id'] . "\" $select_txt>" . scrub_out($row['fullname']) . "</option>\n";
} // end while users
+ echo "</select>\n";
+
} // show_user_select
/**