ajax.php
changeset 21 74edc873234f
parent 18 69af47034212
child 44 92dd253f501c
--- a/ajax.php	Fri Apr 25 14:56:52 2008 -0400
+++ b/ajax.php	Mon Jun 30 12:36:13 2008 -0400
@@ -34,9 +34,32 @@
   return true;
 }
 
-function ajax_request_handler($httpd)
+function ajax_request_handler($httpd, $socket)
 {
   global $playlist, $mime_types, $json, $allowcontrol;
+  global $use_auth, $auth_data;
+  
+  if ( $use_auth )
+  {
+    if ( !isset($_SERVER['PHP_AUTH_USER']) )
+    {
+      $httpd->header('WWW-Authenticate: basic');
+      $httpd->send_http_error($socket, 401, "A username and password are required to access this resource. Either you did not specify a username and password, or the supplied credentials were incorrect.");
+      return true;
+    }
+    if ( !isset($auth_data[$_SERVER['PHP_AUTH_USER']]) )
+    {
+      $httpd->header('WWW-Authenticate: basic');
+      $httpd->send_http_error($socket, 401, "A username and password are required to access this resource. Either you did not specify a username and password, or the supplied credentials were incorrect.");
+      return true;
+    }
+    else if ( $_SERVER['PHP_AUTH_PW'] !== $auth_data[$_SERVER['PHP_AUTH_USER']] )
+    {
+      $httpd->header('WWW-Authenticate: basic');
+      $httpd->send_http_error($socket, 401, "A username and password are required to access this resource. Either you did not specify a username and password, or the supplied credentials were incorrect.");
+      return true;
+    }
+  }
   
   // Set content type
   $httpd->header("Content-type: {$mime_types['js']}");
@@ -117,8 +140,11 @@
         rebuild_playlist();
       }
       $current_track = dcop_action('playlist', 'getActiveIndex');
+      $current_time = dcop_action('player', 'trackCurrentTime');
+      $is_playing = dcop_action('player', 'isPlaying');
       $return = array(
-          'is_playing' => dcop_action('player', 'isPlaying'),
+          'is_playing' => $is_playing,
+          'is_paused' => $current_time > 0 && !$is_playing,
           'current_track' => $current_track,
           'volume' => dcop_action('player', 'getVolume'),
           // include the MD5 of the playlist so that if it changes, the
@@ -131,7 +157,7 @@
       if ( isset($playlist[$current_track]) )
       {
         $return['current_track_length'] = $playlist[$current_track]['length_int'];
-        $return['current_track_pos'] = dcop_action('player', 'trackCurrentTime');
+        $return['current_track_pos'] = $current_time;
         $return['current_track_title'] = $playlist[$current_track]['title'];
         $return['current_track_artist'] = $playlist[$current_track]['artist'];
         $return['current_track_album'] = $playlist[$current_track]['album'];