1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-03 01:39:28 +02:00

Close sql connection before sending media stream

Add cookie with authenticated username, for JavaScript use and better cache handling on visitors
This commit is contained in:
Afterster 2015-05-19 21:51:12 +02:00
parent 16d3cfa126
commit 517cef69b3
5 changed files with 44 additions and 9 deletions

View file

@ -331,7 +331,7 @@ class Ampache_RSS
$xml_array = array('title' => $artist->f_name,
'link' => $artist->link,
'description' => $artist->summary,
'image' => Art::url($artist->id, 'artist'),
'image' => Art::url($artist->id, 'artist', null, 2),
'comments' => '',
'pubDate' => ''
);
@ -365,7 +365,7 @@ class Ampache_RSS
$xml_array = array('title' => $user->username . ' ' . T_('on') . ' ' . $object->get_fullname(),
'link' => $object->link,
'description' => $shout->text,
'image' => Art::url($shout->object_id, $shout->object_type),
'image' => Art::url($shout->object_id, $shout->object_type, null, 2),
'comments' => '',
'pubDate' => date("c", $shout->date)
);

View file

@ -91,8 +91,14 @@ class Session
debug_event('SESSION', 'Deleting Session with key:' . $key, 6);
$session_name = AmpConfig::get('session_name');
$cookie_path = AmpConfig::get('cookie_path');
$cookie_domain = null;
$cookie_secure = AmpConfig::get('cookie_secure');
// Destroy our cookie!
setcookie(AmpConfig::get('session_name'), null, -1);
setcookie($session_name, null, -1, $cookie_path, $cookie_domain, $cookie_secure);
setcookie($session_name . '_user', null, -1, $cookie_path, $cookie_domain, $cookie_secure);
return true;
}
@ -440,6 +446,23 @@ class Session
session_start();
}
/**
* create_user_cookie
*
* This function just creates the user cookie wich contains current username.
* It must be used for information only.
*/
public static function create_user_cookie($username)
{
$cookie_life = AmpConfig::get('cookie_life');
$session_name = AmpConfig::get('session_name');
$cookie_path = AmpConfig::get('cookie_path');
$cookie_domain = null;
$cookie_secure = AmpConfig::get('cookie_secure');
setcookie($session_name . '_user', $username, $cookie_life, $cookie_path, $cookie_domain, $cookie_secure);
}
/**
* create_remember_cookie
*

View file

@ -152,8 +152,11 @@ if (isset($auth) && $auth['success'] && isset($user)) {
$user->insert_ip_history();
}
if ($_POST['rememberme'] && isset($username)) {
Session::create_remember_cookie($username);
if (isset($username)) {
Session::create_user_cookie($username);
if ($_POST['rememberme']) {
Session::create_remember_cookie($username);
}
}
// Update data from this auth if ours are empty

View file

@ -621,6 +621,14 @@ if ($transcode && isset($transcoder)) {
}
};
// If this is a democratic playlist remove the entry.
// We do this regardless of play amount.
if ($demo_id && isset($democratic)) { $democratic->delete_from_oid($oid, $type); }
// Close sql connection
// Warning: do not call functions requiring sql after this point
Dba::disconnect();
$browser->downloadHeaders($media_name, $mime, false, $stream_size);
$bytes_streamed = 0;
@ -667,10 +675,6 @@ if ($bytes_streamed < $stream_size && (connection_status() == 0)) {
$bytes_streamed = $stream_size;
}
// If this is a democratic playlist remove the entry.
// We do this regardless of play amount.
if ($demo_id && isset($democratic)) { $democratic->delete_from_oid($oid, $type); }
if ($transcode && isset($transcoder)) {
fclose($fp);
proc_terminate($transcoder['process']);

View file

@ -31,6 +31,11 @@
<td><?php echo AmpConfig::get('session_name'); ?></td>
<td><?php echo T_('Ampache session.'); ?></td>
</tr>
<tr>
<td>Session username</td>
<td><?php echo AmpConfig::get('session_name'); ?>_user</td>
<td><?php echo T_('Ampache session username (if authenticated, information only).'); ?></td>
</tr>
<tr>
<td>Remember Me</td>
<td><?php echo AmpConfig::get('session_name'); ?>_remember</td>