summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/access.php35
-rw-r--r--config/ampache.cfg.php.dist2
-rwxr-xr-xdocs/CHANGELOG3
-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
-rw-r--r--play/index.php2
-rw-r--r--templates/show_access_list.inc.php54
-rw-r--r--templates/show_add_access.inc.php13
-rw-r--r--templates/show_confirmation.inc.php6
-rw-r--r--templates/show_edit_access.inc.php (renamed from templates/show_edit_access.inc)33
15 files changed, 296 insertions, 322 deletions
diff --git a/admin/access.php b/admin/access.php
index b818328e..c96d0362 100644
--- a/admin/access.php
+++ b/admin/access.php
@@ -21,44 +21,39 @@
require '../lib/init.php';
-
if (!$GLOBALS['user']->has_access(100) || Config::get('demo_mode')) {
access_denied();
exit();
}
-
show_header();
switch ($_REQUEST['action']) {
- case 'show_confirm_delete':
- $title = _('Confirm Delete');
- $body = _('Do you really want to delete this Access Record?');
- show_confirmation($title,$body,'admin/access.php?access_id=' . scrub_out($_REQUEST['access_id']) . '&action=delete_host','1');
- break;
- case 'delete_host':
- $access->delete($_REQUEST['access_id']);
- $url = conf('web_path') . '/admin/access.php';
- show_confirmation(_('Entry Deleted'),_('Your Access List Entry has been removed'),$url);
+ case 'delete_record':
+ Access::delete($_REQUEST['access_id']);
+ $url = Config::get('web_path') . '/admin/access.php';
+ show_confirmation(_('Deleted'),_('Your Access List Entry has been removed'),$url);
break;
case 'add_host':
- $access->create($_REQUEST['name'],$_REQUEST['start'],$_REQUEST['end'],$_REQUEST['level'],$_REQUEST['user'],$_REQUEST['key'],$_REQUEST['type']);
- $url = conf('web_path') . '/admin/access.php';
- show_confirmation(_('Entry Added'),_('Your new Access List Entry has been created'),$url);
+ Access::create($_POST);
+ $url = Config::get('web_path') . '/admin/access.php';
+ show_confirmation(_('Added'),_('Your new Access List Entry has been created'),$url);
break;
- case 'update_host':
- $access->update($_REQUEST);
- show_confirmation(_('Entry Updated'),_('Access List Entry updated'),'admin/access.php');
+ case 'update_record':
+ $access = new Access($_REQUEST['access_id']);
+ $access->update($_POST);
+ show_confirmation(_('Updated'),_('Access List Entry updated'),'admin/access.php');
break;
case 'show_add_host':
require_once Config::get('prefix') . '/templates/show_add_access.inc.php';
break;
- case 'show_edit_host':
- include(conf('prefix') . '/templates/show_edit_access.inc');
+ case 'show_edit_record':
+ $access = new Access($_REQUEST['access_id']);
+ require_once Config::get('prefix') . '/templates/show_edit_access.inc.php';
break;
default:
$list = array();
-// $list = $access->get_access_list();
+ $list = Access::get_access_lists();
require_once Config::get('prefix') .'/templates/show_access_list.inc.php';
break;
} // end switch on action
diff --git a/config/ampache.cfg.php.dist b/config/ampache.cfg.php.dist
index 15ca4b5f..b6eaca10 100644
--- a/config/ampache.cfg.php.dist
+++ b/config/ampache.cfg.php.dist
@@ -50,7 +50,7 @@ database_password = password
session_length = 900
; Length that the session for a single streaming instance will last
-; the default is 15min. With some clients, and long songs this can
+; the default is one hour. With some clients, and long songs this can
; cause playback to stop, increase this value if you experience that
stream_length = 3600
diff --git a/docs/CHANGELOG b/docs/CHANGELOG
index 2ca9a0f0..541c723a 100755
--- a/docs/CHANGELOG
+++ b/docs/CHANGELOG
@@ -4,6 +4,9 @@
--------------------------------------------------------------------------
v.3.4-Alpha3
+ - Fixed ACL's
+ - Fixed incorrect Mime type being passed with transcoded songs due
+ to duplicate headers being passed
- Fixed an issue where MPD was clearing all but last song in submit
if its initial state was not play
- Added check for PHP5 to prevent ugly errors if missing
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
/**
diff --git a/play/index.php b/play/index.php
index 42641138..3d700678 100644
--- a/play/index.php
+++ b/play/index.php
@@ -250,7 +250,7 @@ if (Config::get('access_control') AND Config::get('downsample_remote')) {
// If they are downsampling, or if the song is not a native stream or it's non-local
if (($GLOBALS['user']->prefs['transcode'] == 'always' || !$song->native_stream() || $not_local) && $GLOBALS['user']->prefs['transcode'] != 'never') {
debug_event('downsample','Starting Downsample...','5');
- $results = start_downsample($song,$lastid,$song_name);
+ $results = Stream::start_downsample($song,$lastid,$song_name);
$fp = $results['handle'];
$song->size = $results['size'];
diff --git a/templates/show_access_list.inc.php b/templates/show_access_list.inc.php
index 15fb3417..1374b81a 100644
--- a/templates/show_access_list.inc.php
+++ b/templates/show_access_list.inc.php
@@ -26,7 +26,7 @@
*/
$web_path = Config::get('web_path');
?>
-<?php show_box_top(_('Host Access to Your Catalog')); ?>
+<?php show_box_top(_('Ampache Access Control')); ?>
<p>Since your catalog can be accessed remotely you may want to limit the access from
remote sources so you are not in violation of copyright laws. By default your
server will allow anyone with an account to stream music. It will not allow any
@@ -35,40 +35,38 @@ to add any server's IP address that you want to access your Ampache catalog or b
stream from this server.</p>
<p>
-<span class="text-action">
-<a href="<?php echo $web_path; ?>/admin/access.php?action=show_add_host"><?php echo _('Add Entry'); ?></a>
-</span>
+<a class="smallbutton" href="<?php echo $web_path; ?>/admin/access.php?action=show_add_host"><?php echo _('Add Entry'); ?></a>
</p>
<?php if (count($list)) { ?>
<table cellspacing="1" cellpadding="3" class="tabledata">
-<tr class="table-header" align="center">
- <td><?php echo _('Name'); ?></td>
- <td><?php echo _('Start Address'); ?></td>
- <td><?php echo _('End Address'); ?></td>
- <td><?php echo _('Level'); ?></td>
- <td><?php echo _('User'); ?></td>
- <td><?php echo _('Key'); ?></td>
- <td><?php echo _('Type'); ?></td>
- <td><?php echo _('Action'); ?></td>
+<tr class="table-data">
+ <th><?php echo _('Name'); ?></th>
+ <th><?php echo _('Start Address'); ?></th>
+ <th><?php echo _('End Address'); ?></th>
+ <th><?php echo _('Level'); ?></th>
+ <th><?php echo _('User'); ?></th>
+ <th><?php echo _('Key'); ?></th>
+ <th><?php echo _('Type'); ?></th>
+ <th><?php echo _('Action'); ?></th>
</tr>
<?php
/* Start foreach List Item */
- foreach ($list as $access) {
+ foreach ($list as $access_id) {
+ $access = new Access($access_id);
?>
- <tr class="<?php echo flip_class(); ?>">
- <td><?php echo scrub_out($access->name); ?></td>
- <td><?php echo int2ip($access->start); ?></td>
- <td><?php echo int2ip($access->end); ?></td>
- <td><?php echo $access->get_level_name(); ?></td>
- <td><?php echo $access->get_user_name(); ?></td>
- <td><?php echo $access->key; ?></td>
- <td><?php echo $access->get_type_name(); ?></td>
- <td>
- <a href="<?php echo $web_path; ?>/admin/access.php?action=show_edit_host&amp;access_id=<?php echo scrub_out($access->id); ?>"><?php echo _('Edit'); ?></a>
- |
- <a href="<?php echo $web_path; ?>/admin/access.php?action=show_confirm_delete&amp;access_id=<?php echo scrub_out($access->id); ?>"><?php print _("Revoke"); ?></a>
- </td>
- </tr>
+<tr class="<?php echo flip_class(); ?>">
+ <td><?php echo scrub_out($access->name); ?></td>
+ <td><?php echo int2ip($access->start); ?></td>
+ <td><?php echo int2ip($access->end); ?></td>
+ <td><?php echo $access->get_level_name(); ?></td>
+ <td><?php echo $access->get_user_name(); ?></td>
+ <td><?php echo $access->key; ?></td>
+ <td><?php echo $access->get_type_name(); ?></td>
+ <td>
+ <a href="<?php echo $web_path; ?>/admin/access.php?action=show_edit_record&amp;access_id=<?php echo scrub_out($access->id); ?>"><?php echo get_user_icon('edit'); ?></a>
+ <a href="<?php echo $web_path; ?>/admin/access.php?action=delete_record&amp;access_id=<?php echo scrub_out($access->id); ?>"><?php echo get_user_icon('delete'); ?></a>
+ </td>
+</tr>
<?php } // end foreach ?>
</table>
<?php } // end if count ?>
diff --git a/templates/show_add_access.inc.php b/templates/show_add_access.inc.php
index 81f6ccc1..506f9cda 100644
--- a/templates/show_add_access.inc.php
+++ b/templates/show_add_access.inc.php
@@ -1,7 +1,7 @@
<?php
/*
- Copyright (c) 2001 - 2006 Ampache.org
+ Copyright (c) 2001 - 2007 Ampache.org
All rights reserved.
This program is free software; you can redistribute it and/or
@@ -20,10 +20,7 @@
*/
?>
<?php show_box_top(_('Add Access for a Host')); ?>
-<p><?php echo _('Use the form below to add a host that you want to have access to your Ampache catalog.'); ?></p>
-
-
-<form name="update_catalog" method="post" enctype="multipart/form-data" action="<?php echo Config::get('web_path'); ?>/admin/access.php">
+<form name="update_catalog" method="post" enctype="multipart/form-data" action="<?php echo Config::get('web_path'); ?>/admin/access.php?action=add_host">
<table cellpadding="5" cellspacing="0">
<tr>
<td><?php echo _('Name'); ?>:</td>
@@ -45,8 +42,8 @@
</tr>
<tr>
<td><?php echo _('User'); ?>:</td>
- <!-- Stuff Goes Here -->
<td>
+ <?php show_user_select('user'); ?>
</td>
</tr>
<tr>
@@ -72,7 +69,7 @@
</td>
</tr>
<tr>
- <td colspan="2"><br /><?php echo _('XML-RPC Options'); ?>:</td>
+ <td colspan="2"><h4><?php echo _('XML-RPC Options'); ?></h4></td>
</tr>
<tr>
<td><?php echo _('Remote Key'); ?>:</td>
@@ -82,8 +79,6 @@
</tr>
<tr>
<td colspan="2">
- <br />
- <input type="hidden" name="action" value="add_host" />
<input class="button" type="submit" value="<?php echo _('Create ACL'); ?>" />
</td>
</tr>
diff --git a/templates/show_confirmation.inc.php b/templates/show_confirmation.inc.php
index 84a885d9..21b20ca3 100644
--- a/templates/show_confirmation.inc.php
+++ b/templates/show_confirmation.inc.php
@@ -22,10 +22,8 @@
<?php show_box_top(scrub_out($title)); ?>
<?php echo $text; ?>
<br />
-<div class="text-action">
- <a href="<?php echo $path; ?>"><?php echo _('Continue'); ?></a>
+ <a class="smallbutton" href="<?php echo $path; ?>"><?php echo _('Continue'); ?></a>
<?php if ($cancel) { ?>
- <a href="<?php echo Config::get('web_path') . "/" . return_referer(); ?>"><?php echo _('Cancel'); ?></a>
+ <a class="smallbutton" href="<?php echo Config::get('web_path') . "/" . return_referer(); ?>"><?php echo _('Cancel'); ?></a>
<?php } ?>
-</div>
<?php show_box_bottom(); ?>
diff --git a/templates/show_edit_access.inc b/templates/show_edit_access.inc.php
index 21794aaf..06a0feb8 100644
--- a/templates/show_edit_access.inc
+++ b/templates/show_edit_access.inc.php
@@ -1,13 +1,12 @@
<?php
/*
- Copyright (c) 2001 - 2006 Ampache.org
+ Copyright (c) 2001 - 2007 Ampache.org
All rights reserved.
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.
+ modify it under the terms of the GNU General Public License v2
+ as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,16 +19,25 @@
*/
?>
-<?php show_box_top(_('Edit Access List')); ?>
-<form name="edit_access" method="post" enctype="multipart/form-data" action="<?php echo conf('web_path'); ?>/admin/access.php">
-<table>
+<?php show_box_top(_('Edit ACL')); ?>
+<form name="edit_access" method="post" enctype="multipart/form-data" action="<?php echo Config::get('web_path'); ?>/admin/access.php?action=update_record&amp;access_id=<?php echo intval($access->id); ?>">
+<table class="table-data">
<tr>
<td><?php echo _('Name'); ?>: </td>
- <td><?php echo scrub_out($access->name); ?></td>
+ <td><input type="textbox" name="name" value="<?php echo scrub_out($access->name); ?>" /></td>
</tr>
<tr>
<td><?php echo _('ACL Type'); ?>: </td>
- <td><?php echo scrub_out($access->get_type_name()); ?></td>
+ <td>
+ <select name="type">
+ <?php $name = 'sl_' . $access->type; ${$name} = ' selected="selected"'; ?>
+ <option value="stream"<?php echo $sl_stream; ?>><?php echo _('Stream Access'); ?></option>
+ <option value="interface"<?php echo $sl_interface; ?>><?php echo _('Web Interface'); ?></option>
+ <option value="network"<?php echo $sl_network; ?>><?php echo _('Local Network Definition'); ?></option>
+ <option value="xml-rpc"<?php echo $sl_xml-rpc; ?>><?php echo _('XML-RPC'); ?></option>
+ </select>
+ </td>
+
</tr>
<tr>
<td><?php echo _('Start IP Address'); ?>:</td>
@@ -71,12 +79,7 @@
</td>
</tr>
<tr>
- <td>&nbsp;</td>
- <td>
- <input type="hidden" name="access_id" value="<?php echo scrub_out($access->id); ?>" />
- <input type="hidden" name="action" value="update_host" />
- <input type="submit" value="<?php echo _('Update'); ?>" />
- </td>
+ <td colspan="2"><input type="submit" value="<?php echo _('Update'); ?>" /></td>
</tr>
</table>
</form>