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 |
14 |
|
15 // required for signal handling to work |
|
16 declare(ticks=1); |
|
17 |
|
18 // trap SIGTERM |
|
19 pcntl_signal(SIGTERM, 'sigterm'); |
|
20 pcntl_signal(SIGINT, 'sigterm'); |
|
21 |
15 $public = true; |
22 $public = true; |
16 $allowcontrol = true; |
23 $allowcontrol = true; |
17 $theme = 'funkymonkey'; |
24 $theme = 'funkymonkey'; |
18 |
25 |
19 @ini_set('display_errors', 'on'); |
26 @ini_set('display_errors', 'on'); |
20 |
27 |
21 // include files |
28 // include files |
22 require('functions.php'); |
29 require('functions.php'); |
23 |
30 |
|
31 // get the root |
|
32 define('GREY_ROOT', dirname(__FILE__)); |
|
33 |
|
34 // create directories |
|
35 @mkdir('./compiled'); |
|
36 |
24 // start up... |
37 // start up... |
25 |
38 |
26 status('Starting WebControl v0.1-hg'); |
39 status('Starting WebControl v0.1-hg'); |
27 status('loading files'); |
40 status('loading files'); |
28 |
41 |
29 require('webserver.php'); |
42 require('webserver.php'); |
30 define('SMARTY_DIR', './smarty/'); |
43 define('SMARTY_DIR', GREY_ROOT . '/smarty/'); |
31 require('smarty/Smarty.class.php'); |
44 require(GREY_ROOT . '/smarty/Smarty.class.php'); |
32 require('playlist.php'); |
45 require(GREY_ROOT . '/playlist.php'); |
33 require('json.php'); |
46 require(GREY_ROOT . '/json.php'); |
34 require('ajax.php'); |
47 require(GREY_ROOT . '/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 |
48 |
43 status('doing home directory detection'); |
49 status('doing home directory detection'); |
44 |
50 |
45 // get home directory |
51 // get home directory |
46 |
52 |
48 { |
54 { |
49 burnout('Could not get your home directory'); |
55 burnout('Could not get your home directory'); |
50 } |
56 } |
51 |
57 |
52 $homedir =& $_ENV['HOME']; |
58 $homedir =& $_ENV['HOME']; |
|
59 |
|
60 // signal handler |
|
61 function sigterm($signal) |
|
62 { |
|
63 global $httpd; |
|
64 status("Caught SIGTERM, cleaning up."); |
|
65 @socket_close($httpd->sock); |
|
66 exit(); |
|
67 } |
53 |
68 |
54 status('initializing playlist'); |
69 status('initializing playlist'); |
55 |
70 |
56 // init playlist object |
71 // init playlist object |
57 $playlist = array(); |
72 $playlist = array(); |
66 status('starting PhpHttpd'); |
81 status('starting PhpHttpd'); |
67 $httpd = new WebServer($ip, $port); |
82 $httpd = new WebServer($ip, $port); |
68 |
83 |
69 // setup handlers |
84 // setup handlers |
70 status('initializing handlers'); |
85 status('initializing handlers'); |
71 $httpd->add_handler('index', 'function', 'amarok_playlist'); |
86 $httpd->add_handler('index', 'function', 'amarok_playlist'); |
72 $httpd->add_handler('action.json', 'function', 'ajax_request_handler'); |
87 $httpd->add_handler('action.json', 'function', 'ajax_request_handler'); |
73 $httpd->add_handler('scripts', 'dir', './scripts'); |
88 $httpd->add_handler('scripts', 'dir', GREY_ROOT . '/scripts'); |
74 $httpd->add_handler('favicon.ico', 'file', './amarok_icon.ico'); |
89 $httpd->add_handler('favicon.ico', 'file', GREY_ROOT . '/amarok_icon.ico'); |
75 $httpd->add_handler('apple-touch-icon.png', 'file', './apple-touch-icon.png'); |
90 $httpd->add_handler('apple-touch-icon.png', 'file', GREY_ROOT . '/apple-touch-icon.png'); |
76 $httpd->add_handler("themes/$theme", 'dir', "./themes/$theme"); |
|
77 $httpd->allow_dir_list = true; |
91 $httpd->allow_dir_list = true; |
78 $httpd->default_document = 'index'; |
92 $httpd->default_document = 'index'; |
79 |
93 |
80 status("Entering main server loop - ^C to interrupt, listening on port $port"); |
94 status("Entering main server loop - ^C to interrupt, listening on port $port"); |
81 $httpd->serve(); |
95 $httpd->serve(); |