-
Notifications
You must be signed in to change notification settings - Fork 22
/
index.php
350 lines (303 loc) · 12.1 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
define('ROMPR_IS_LOADING', true);
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0");
header("Content-Type: text/html; charset=UTF-8");
require_once ("includes/vars.php");
require_once ("includes/functions.php");
//
// Do some important pre-load checks
//
if (!is_dir('prefs')) {
big_bad_fail('The prefs directory does not exist. Please check the installation instructions');
}
if (!is_dir('albumart')) {
big_bad_fail('The albumart directory does not exist. Please check the installation instructions');
}
if (($f = @fopen('prefs/test.tmp', 'w')) == false) {
big_bad_fail('The web server does not have write access to the prefs directory. Please check the installation instructions');
} else {
fclose($f);
unlink('prefs/test.tmp');
}
if (($f = @fopen('albumart/test.tmp', 'w')) == false) {
big_bad_fail('The web server does not have write access to the albumart directory. Please check the installation instructions');
} else {
fclose($f);
unlink('albumart/test.tmp');
}
if (file_exists('collection/collection.php') || is_dir('themes/fruit') || file_exists('radios/musicfromspotify.js')) {
big_bad_fail('Remains of an earlier installation still exist. To install this version of RompЯ you must
delete <b>everything except your albumart and prefs directories</b> and then copy the new version
into your rompr directory.');
}
check_php_installation();
//
// Has the user asked for the setup screen?
//
if (array_key_exists('setup', $_REQUEST)) {
logger::mark('INIT', 'User asked for Setup Screen');
$title = language::gettext("setup_request");
include("setupscreen.php");
exit(0);
}
logger::debug('INIT', 'Got Past Setup Bit');
//
// Check to see if a specific player has been requested in the URL
//
if (isset($_GET['currenthost'])) {
prefs::set_pref([
'currenthost' => $_GET['currenthost'],
'player_backend' => null
]);
http_response_code(307);
header("Location: ".get_base_url());
exit;
}
logger::mark('INIT', php_uname());
set_version_string();
upgrade_old_collections();
//
// See if we can use the SQL backend
//
logger::mark('INIT', 'Checking Database Connection');
if (prefs::get_pref('collection_type') === null) {
list($success, $error_message) = data_base::probe_database();
if ($success) {
set_include_path('backends/sql/'.prefs::get_pref('collection_type').PATH_SEPARATOR.get_include_path());
} else {
sql_init_fail($error_message);
}
}
prefs::$database = new init_database();
// if (prefs::$database->test_error_handling() === false) {
// logger::info('INIT', 'Got database error');
// exit(0);
// } else {
// logger::info('INIT', 'Did NOT Got database error');
// exit(0);
// }
list($result, $message) = prefs::$database->check_sql_tables();
if ($result == false) {
sql_init_fail($message);
}
prefs::$database->check_setupscreen_actions();
if (array_key_exists('cacheclean', $_REQUEST)) {
$cleaner = new cache_cleaner();
$cleaner->clean_cache();
exit(0);
}
//
// Do some initialisation of the backend directories. Must do this now,
// since we almost immediately start calling spotify:: methods which require
// cache_handler, so these directories need to exist
//
include ("includes/firstrun.php");
//
// Set the country code from the browser (though this may not be accurate)
// - unless the user has already set it. Note, this is the Spotify 'market'
// code, not the interface language.
//
if (!prefs::get_pref('country_userset')) {
logger::info('INIT', 'Country Code not sent by user');
$browser_country = language::get_browser_country();
$markets = spotify::get_markets();
if (in_array($browser_country, $markets)) {
logger::info('INIT', 'Browser gave us',$browser_country,'which is valid for Spotify');
prefs::set_pref(['lastfm_country_code' => $browser_country]);
} else {
logger::info('INIT', 'Browser gave us',$browser_country,'which is NOT valid for Spotify');
}
}
logger::debug("INIT", $_SERVER['SCRIPT_FILENAME']);
logger::debug("INIT", $_SERVER['PHP_SELF']);
//
// Attempt a player connection. This will set player_backend if it is not already set
//
logger::mark('INIT','Attempting to connect to player',prefs::currenthost());
if (array_key_exists('player_backend', $_COOKIE) && $_COOKIE['player_backend'] != '') {
logger::info('INIT','Player backend cookie is',$_COOKIE['player_backend']);
} else {
logger::info('INIT','Player backend cookie is not set');
}
$player = new base_mpd_player();
if ($player->is_connected()) {
$mpd_status = $player->get_status();
if (array_key_exists('error', $mpd_status)) {
logger::warn("INIT", "MPD Password Failed or other status failure");
$player->clear_error();
if (strpos($mpd_status['error'], 'Failed to decode') !== false) {
logger::warn('INIT', 'Looks like the error is a stream decode error. Ignoring it');
} else {
connect_fail(language::gettext("setup_connecterror").$mpd_status['error']);
}
}
} else {
logger::error("INIT", "MPD Connection Failure");
connect_fail(language::gettext("setup_connectfail"));
}
// If we're connected by a local socket we can read the music directory
logger::log('INIT', 'Getting Player Config');
$arse = $player->get_config();
if (is_array($arse) && array_key_exists('music_directory', $arse)) {
prefs::set_music_directory($arse['music_directory']);
}
$player->close_mpd_connection();
// player_backend has now been worked out, so we can now probe the websocket
$player = new player();
// Always probe the websocket every time we load. This is a saved preference
// and it might have changed since last time we opened the page
$player->probe_websocket();
// This table has to exist because it's used in get_album_uri() but we
// can't create it until we know which player we're connected to.
prefs::$database->create_radio_uri_table(false);
//
// Check that the Backend Daemon is running and (re)start if it necessary.
// Add ?force_restart=1 to the URL to force the Daemon to Restart
//
check_backend_daemon();
prefs::save();
prefs::refresh_cookies();
logger::log("INIT", "Initialisation done. Let's Boogie!");
logger::mark("CREATING PAGE", "******++++++======------******------======++++++******");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>RompЯ</title>
<link rel="shortcut icon" sizes="196x196" href="newimages/favicon-196.png" />
<link rel="shortcut icon" sizes="128x128" href="newimages/favicon-128.png" />
<link rel="shortcut icon" sizes="64x64" href="newimages/favicon-64.png" />
<link rel="shortcut icon" sizes="48x48" href="newimages/favicon-48.png" />
<link rel="shortcut icon" sizes="32x32" href="newimages/favicon-32.png" />
<link rel="shortcut icon" sizes="16x16" href="newimages/favicon-16.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<meta name="mobile-web-app-capable" content="yes" />
<?php
print '<script type="application/json" name="custom_radio_items">'."\n".json_encode(CUSTOM_RADIO_ITEMS)."\n</script>\n";
print '<script type="application/json" name="radio_combine_options">'."\n".json_encode(RADIO_COMBINE_OPTIONS)."\n</script>\n";
print '<script type="application/json" name="font_sizes">'."\n".json_encode(FONT_SIZES)."\n</script>\n";
print '<script type="application/json" name="cover_sizes">'."\n".json_encode(COVER_SIZES)."\n</script>\n";
print '<script type="application/json" name="default_player">'."\n".json_encode(prefs::DEFAULT_PLAYER)."\n</script>\n";
print '<script type="application/json" name="player_connection_params">'."\n".json_encode(prefs::PLAYER_CONNECTION_PARAMS)."\n</script>\n";
print '<script type="application/json" name="browser_prefs">'."\n".json_encode(array_keys(prefs::BROWSER_PREFS))."\n</script>\n";
print '<script type="application/json" name="mopidy_collection_folders">'."\n".json_encode(MOPIDY_COLLECTION_FOLDERS)."\n</script>\n";
print '<script type="application/json" name="player_uri_schemes">'."\n".json_encode($player->get_uri_handlers())."\n</script>\n";
print '<link rel="stylesheet" type="text/css" href="get_css.php?version='.$version_string."&skin=".prefs::skin().'" />'."\n";
print '<link rel="stylesheet" type="text/css" href="css/scrollbars/jquery.mCustomScrollbar.css?version='.$version_string.'" />'."\n";
?>
<link rel="stylesheet" id="theme" type="text/css" />
<?php
logger::mark("INIT", "Reconfiguring the Forward Deflector Array");
$scripts = array(
"jquery/jquery-3.6.4.min.js",
// "jquery/jquery-migrate-3.3.2.min.js",
"ui/functions.js",
"ui/prefs.js",
"ui/language.php",
"jquery/jquery-ui.min.js",
"jshash-2.2/md5-min.js",
"jquery/imagesloaded.pkgd.min.js",
"jquery/masonry.pkgd.min.js",
"includes/globals.js",
"ui/widgets.js",
"ui/uihelper.js",
"ui/searchmanager.js",
"skins/".prefs::skin()."/skin.js",
"player/controller.js",
"ui/collectionhelper.js",
"player/player.js",
"ui/playlist.js",
"ui/readyhandlers.js",
"ui/debug.js",
"ui/uifunctions.js",
"ui/metahandlers.js",
"ui/clickfunctions.js",
"ui/nowplaying.js",
"ui/infobar2.js",
"ui/coverscraper.js",
// "ui/favefinder.js",
"ui/podcasts.js",
"browser/info.js",
"snapcast/snapcast.js",
"jquery/jquery.hotkeys.js",
"jquery/jquery.mCustomScrollbar.concat.min-3.1.5.js",
"ui/hotkeys.js",
"jquery/jquery.scrollTo.min.js"
);
foreach ($scripts as $i) {
logger::log("INIT", "Loading ".$i);
print '<script type="text/javascript" src="'.$i.'?version='.$version_string.'"></script>'."\n";
}
if (prefs::get_player_param('websocket') === false) {
logger::log("INIT", "Loading non-websocket player script");
print '<script type="text/javascript" src="player/mpd/checkprogress.js?version='.$version_string.'"></script>'."\n";
} else {
logger::log("INIT", "Loading Websocket player script");
print '<script type="text/javascript" src="player/mopidy/checkprogress.js?version='.$version_string.'"></script>'."\n";
}
$inc = glob("streamplugins/*.js");
foreach($inc as $i) {
logger::log("INIT", "Loading ".$i);
print '<script type="text/javascript" src="'.$i.'?version='.$version_string.'"></script>'."\n";
}
javascript_globals::print_globals();
$inc = glob("browser/helpers/*.js");
foreach($inc as $i) {
logger::log("INIT", "Including Browser Helper ".$i);
print '<script type="text/javascript" src="'.$i.'?version='.$version_string.'"></script>'."\n";
}
$inc = glob("browser/plugins/*.js");
ksort($inc);
foreach($inc as $i) {
logger::log("INIT", "Including Info Panel Plugin ".$i);
print '<script type="text/javascript" src="'.$i.'?version='.$version_string.'"></script>'."\n";
}
$inc = glob("radios/*.js");
ksort($inc);
foreach($inc as $i) {
logger::log("INIT", "Including Smart Radio Plugin ".$i);
print '<script type="text/javascript" src="'.$i.'?version='.$version_string.'"></script>'."\n";
}
$inc = glob("plugins/*.js");
foreach($inc as $i) {
logger::log("INIT", "Including Plugin ".$i);
print '<script type="text/javascript" src="'.$i.'?version='.$version_string.'"></script>'."\n";
}
if (prefs::get_pref('load_plugins_at_loadtime')) {
$inc = glob("plugins/code/*.js");
foreach($inc as $i) {
logger::info("INIT", "DEVELOPMENT MODE : Including Plugin ".$i);
print '<script type="text/javascript" src="'.$i.'?version='.$version_string.'"></script>'."\n";
}
}
?>
</head>
<?php
logger::log("LAYOUT", "Including skins/".prefs::skin().'/skin.php');
include('skins/'.prefs::skin().'/skin.php');
foreach (['post_max_size', 'max_file_uploads', 'upload_max_filesize'] as $i) {
print '<input type="hidden" name="'.$i.'" value="'.ini_get($i).'" />'."\n";
}
?>
</body>
</html>
<?php
logger::mark("INIT FINISHED", "******++++++======------******------======++++++******");
function check_php_installation() {
if (version_compare(phpversion(), ROMPR_MIN_PHP_VERSION, '<' )) {
big_bad_fail('Your version of PHP is too old. You need at least version '.ROMPR_MIN_PHP_VERSION);
}
foreach (['mbstring', 'PDO', 'curl', 'date', 'fileinfo', 'json', 'simpleXML'] as $x) {
check_php_extension($x);
}
}
function check_php_extension($x) {
if (phpversion($x) === false) {
big_bad_fail('Your installation of PHP is missing the '.$x.' extension');
}
}
?>