|
1 #!/usr/bin/env php |
|
2 <?php |
|
3 |
|
4 /** |
|
5 * Greyhound - real web management for Amarok |
|
6 * Copyright (C) 2008 Dan Fuhry |
|
7 * |
|
8 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License |
|
9 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. |
|
10 * |
|
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. |
|
13 */ |
|
14 |
|
15 $public = true; |
|
16 $allowcontrol = true; |
|
17 $theme = 'funkymonkey'; |
|
18 |
|
19 @ini_set('display_errors', 'on'); |
|
20 |
|
21 // include files |
|
22 require('functions.php'); |
|
23 |
|
24 // start up... |
|
25 |
|
26 status('Starting WebControl v0.1-hg'); |
|
27 status('loading files'); |
|
28 |
|
29 require('webserver.php'); |
|
30 define('SMARTY_DIR', './smarty/'); |
|
31 require('smarty/Smarty.class.php'); |
|
32 require('playlist.php'); |
|
33 require('json.php'); |
|
34 require('ajax.php'); |
|
35 |
|
36 status('initializing Smarty'); |
|
37 $smarty = new Smarty(); |
|
38 $smarty->template_dir = "./themes/$theme"; |
|
39 $smarty->compile_dir = "./themes/$theme/compiled"; |
|
40 $smarty->cache_dir = "./cache"; |
|
41 $smarty->config_dir = "./config"; |
|
42 |
|
43 status('doing home directory detection'); |
|
44 |
|
45 // get home directory |
|
46 |
|
47 if ( !isset($_ENV['HOME']) ) |
|
48 { |
|
49 burnout('Could not get your home directory'); |
|
50 } |
|
51 |
|
52 $homedir =& $_ENV['HOME']; |
|
53 |
|
54 status('initializing playlist'); |
|
55 |
|
56 // init playlist object |
|
57 $playlist = array(); |
|
58 rebuild_playlist(); |
|
59 |
|
60 // startup webserver |
|
61 $ip = ( $public ) ? '0.0.0.0' : '127.0.0.1'; |
|
62 $port = 7447; |
|
63 |
|
64 try |
|
65 { |
|
66 status('starting PhpHttpd'); |
|
67 $httpd = new WebServer($ip, $port); |
|
68 |
|
69 // setup handlers |
|
70 status('initializing handlers'); |
|
71 $httpd->add_handler('index', 'function', 'amarok_playlist'); |
|
72 $httpd->add_handler('action.json', 'function', 'ajax_request_handler'); |
|
73 $httpd->add_handler('scripts', 'dir', './scripts'); |
|
74 $httpd->add_handler('favicon.ico', 'file', './amarok_icon.ico'); |
|
75 $httpd->add_handler('apple-touch-icon.png', 'file', './apple-touch-icon.png'); |
|
76 $httpd->add_handler("themes/$theme", 'dir', "./themes/$theme"); |
|
77 $httpd->allow_dir_list = true; |
|
78 $httpd->default_document = 'index'; |
|
79 |
|
80 status("Entering main server loop - ^C to interrupt, listening on port $port"); |
|
81 $httpd->serve(); |
|
82 } |
|
83 catch( Exception $e ) |
|
84 { |
|
85 burnout("Exception caught while running webserver:\n$e"); |
|
86 } |
|
87 |