webcontrol.php
changeset 0 c63de9eb7045
child 2 860ba7141641
equal deleted inserted replaced
-1:000000000000 0:c63de9eb7045
       
     1 <?php
       
     2 
       
     3 /**
       
     4  * Web control interface script for Amarok
       
     5  * Written by Dan Fuhry - 2008
       
     6  *
       
     7  * This script is in the public domain. Use it for good, not evil.
       
     8  */
       
     9 
       
    10 $public = true;
       
    11 $allowcontrol = false;
       
    12 $theme = 'funkymonkey';
       
    13 
       
    14 @ini_set('display_errors', 'on');
       
    15 
       
    16 // include files
       
    17 require('functions.php');
       
    18 
       
    19 // start up...
       
    20 
       
    21 status('Starting WebControl v0.1-hg');
       
    22 status('loading files');
       
    23 
       
    24 require('webserver.php');
       
    25 define('SMARTY_DIR', './smarty/');
       
    26 require('smarty/Smarty.class.php');
       
    27 require('playlist.php');
       
    28 require('ajax.php');
       
    29 
       
    30 status('initializing Smarty');
       
    31 $smarty = new Smarty();
       
    32 $smarty->template_dir = "./themes/$theme";
       
    33 $smarty->compile_dir = "./themes/$theme/compiled";
       
    34 $smarty->cache_dir = "./cache";
       
    35 $smarty->config_dir = "./config";
       
    36 
       
    37 status('doing home directory detection');
       
    38 
       
    39 // get home directory
       
    40 
       
    41 if ( !isset($_ENV['HOME']) )
       
    42 {
       
    43   burnout('Could not get your home directory');
       
    44 }
       
    45 
       
    46 $homedir =& $_ENV['HOME'];
       
    47 
       
    48 status('initializing playlist');
       
    49 
       
    50 // init playlist object
       
    51 $playlist = array();
       
    52 rebuild_playlist();
       
    53 
       
    54 // startup webserver
       
    55 $ip = ( $public ) ? '0.0.0.0' : '127.0.0.1';
       
    56 $port = mt_rand(1025, 65534); // 7447;
       
    57 
       
    58 try
       
    59 {
       
    60   status('starting PhpHttpd');
       
    61   $httpd = new WebServer($ip, $port);
       
    62   
       
    63   // setup handlers
       
    64   status('initializing handlers');
       
    65   $httpd->add_handler('index', 'function', 'amarok_playlist');
       
    66   $httpd->add_handler('scripts', 'dir', './scripts');
       
    67   $httpd->add_handler("themes/$theme", 'dir', "./themes/$theme");
       
    68   $httpd->allow_dir_list = true;
       
    69   $httpd->default_document = 'index';
       
    70   
       
    71   status("Entering main server loop - ^C to interrupt, listening on port $port");
       
    72   $httpd->serve();
       
    73 }
       
    74 catch( Exception $e )
       
    75 {
       
    76   burnout("Exception caught while running webserver:\n$e");
       
    77 }
       
    78