greyhound.php
changeset 44 92dd253f501c
parent 40 bd3372a2afc1
child 45 7978f037eab3
equal deleted inserted replaced
43:2634d550a97b 44:92dd253f501c
     9  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
     9  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    10  *
    10  *
    11  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
    11  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
    12  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    12  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
    13  */
    13  */
       
    14 
       
    15 define('GREY_VERSION', '0.1a4');
    14 
    16 
    15 // Try to trap termination signals to cleanly close the socket when needed
    17 // Try to trap termination signals to cleanly close the socket when needed
    16 // AmaroK sends a SIGTERM when it is shut down or the user requests to stop
    18 // AmaroK sends a SIGTERM when it is shut down or the user requests to stop
    17 // the script
    19 // the script
    18 if ( function_exists('pcntl_signal') )
    20 if ( function_exists('pcntl_signal') )
    35 $public = true;
    37 $public = true;
    36 // Allow control of playback. By default this is turned on but if you
    38 // Allow control of playback. By default this is turned on but if you
    37 // set this to false, it will only display the playlist.
    39 // set this to false, it will only display the playlist.
    38 $allowcontrol = true;
    40 $allowcontrol = true;
    39 // The default theme. This should be a name of a directory in ./themes.
    41 // The default theme. This should be a name of a directory in ./themes.
    40 $theme = 'grey';
    42 $theme = 'funkymonkey';
    41 // Allow forking when an HTTP request is received. This has advantages
    43 // Allow forking when an HTTP request is received. This has advantages
    42 // and disadvantages. If this experimental option is enabled, it will
    44 // and disadvantages. If this experimental option is enabled, it will
    43 // result in faster responses and load times but more memory usage.
    45 // result in faster responses and load times but more memory usage.
    44 $allow_fork = true;
    46 $allow_fork = true;
    45 // set to true to enable authentication
    47 // set to true to enable authentication
    46 // WARNING: THIS HAS SOME SERIOUS SECURITY PROBLEMS RIGHT NOW. I don't
    48 // this uses cookies, so make sure they're enabled in your browser
    47 // know what's causing it to not prompt for authentication from any
       
    48 // client after the first successful auth.
       
    49 $use_auth = false;
    49 $use_auth = false;
    50 // valid users and passwords
    50 // valid users and passwords
    51 $auth_data = array(
    51 $auth_data = array(
    52     'funky' => 'monkey',
    52     'funky' => 'monkey',
    53     'fast' => 'forward'
    53     'fast' => 'forward'
    67 // what kind of terminal do we have?
    67 // what kind of terminal do we have?
    68 $use_colors = ( @in_array(@$_SERVER['TERM'], array('linux', 'xterm', 'vt100')) ) ? true : false;
    68 $use_colors = ( @in_array(@$_SERVER['TERM'], array('linux', 'xterm', 'vt100')) ) ? true : false;
    69 
    69 
    70 // start up...
    70 // start up...
    71 
    71 
    72 status('Starting Greyhound Web Control v0.1a3');
    72 status('Starting Greyhound Web Control v' . GREY_VERSION);
    73 status('loading files');
    73 status('loading files');
    74 
    74 
    75 require('webserver.php');
    75 require('webserver.php');
    76 define('SMARTY_DIR', GREY_ROOT . '/smarty/');
    76 define('SMARTY_DIR', GREY_ROOT . '/smarty/');
    77 require(GREY_ROOT . '/smarty/Smarty.class.php');
    77 require(GREY_ROOT . '/smarty/Smarty.class.php');
    78 require(GREY_ROOT . '/playlist.php');
    78 require(GREY_ROOT . '/playlist.php');
    79 require(GREY_ROOT . '/json.php');
    79 require(GREY_ROOT . '/json.php');
    80 require(GREY_ROOT . '/ajax.php');
    80 require(GREY_ROOT . '/ajax.php');
    81 require(GREY_ROOT . '/imagetools.php');
    81 require(GREY_ROOT . '/imagetools.php');
       
    82 require(GREY_ROOT . '/sessions.php');
    82 
    83 
    83 // signal handler
    84 // signal handler
    84 function sigterm($signal)
    85 function sigterm($signal)
    85 {
    86 {
    86   global $httpd;
    87   global $httpd;
   100 {
   101 {
   101   warning('Can\'t find support for SimpleXML, which is needed to parse the Amarok playlist file.');
   102   warning('Can\'t find support for SimpleXML, which is needed to parse the Amarok playlist file.');
   102   burnout('SimpleXML required to continue. You may have an outdated version of PHP; most versions of PHP 5 have SimpleXML built-in. Check your distribution\'s documentation to find out how to enable PHP\'s SimpleXML support.');
   103   burnout('SimpleXML required to continue. You may have an outdated version of PHP; most versions of PHP 5 have SimpleXML built-in. Check your distribution\'s documentation to find out how to enable PHP\'s SimpleXML support.');
   103 }
   104 }
   104 
   105 
       
   106 if ( !function_exists('imagepng') || !function_exists('imagecopyresampled') || !function_exists('imagecreatefromjpeg') || !function_exists('imagecreatefromwbmp') )
       
   107 {
       
   108   warning('Can\'t find support for GD 2.0. Artwork will not be displayed. Look around in your distro\'s package manager for php-gd or php5-gd.');
       
   109 }
       
   110 
   105 status('initializing playlist');
   111 status('initializing playlist');
   106 
   112 
   107 // init playlist object
   113 // init playlist object
   108 $playlist = array();
   114 $playlist = array();
   109 $amarok_home = false;
   115 $amarok_home = false;
   119   $httpd = new WebServer($ip, $port);
   125   $httpd = new WebServer($ip, $port);
   120   
   126   
   121   // setup handlers
   127   // setup handlers
   122   status('initializing handlers');
   128   status('initializing handlers');
   123   $httpd->add_handler('index',                'function', 'amarok_playlist');
   129   $httpd->add_handler('index',                'function', 'amarok_playlist');
       
   130   $httpd->add_handler('login',                'function', 'greyhound_login_page');
       
   131   $httpd->add_handler('logout',               'function', 'greyhound_logout');
   124   $httpd->add_handler('action.json',          'function', 'ajax_request_handler');
   132   $httpd->add_handler('action.json',          'function', 'ajax_request_handler');
   125   $httpd->add_handler('artwork',              'function', 'artwork_request_handler');
   133   $httpd->add_handler('artwork',              'function', 'artwork_request_handler');
   126   $httpd->add_handler('scripts',              'dir',      GREY_ROOT . '/scripts');
   134   $httpd->add_handler('scripts',              'dir',      GREY_ROOT . '/scripts');
   127   $httpd->add_handler('favicon.ico',          'file',     GREY_ROOT . '/amarok_icon.ico');
   135   $httpd->add_handler('favicon.ico',          'file',     GREY_ROOT . '/amarok_icon.ico');
   128   $httpd->add_handler('apple-touch-icon.png', 'file',     GREY_ROOT . '/apple-touch-icon.png');
   136   $httpd->add_handler('apple-touch-icon.png', 'file',     GREY_ROOT . '/apple-touch-icon.png');