ShoutCast Playlist Problems – Resolved

Was checking over the auto-generated playlists earlier and noticed they wasn’t getting updated correctly from the cronjob this morning.

Then, had a look over the PHP logs and noticed it was complaining about “allow_url_include = 0” which wasn’t allowing:

$PlayList = parse_ini_file($this->TuneInURL . $this->TuneInBase . "?id=" . $ID, true, INI_SCANNER_RAW);

To execute and parse the stations returned playlists, and in turn stopped all the playlist creation. Simple fix to this problem was to keep the insecure allow_url_include disabled and switch to CURL for grabbing the playlist, then save it to disk and delete, after the ini file was loaded.
So it looks something like this now:

$this->get_ini_and_write_to_disk($this->TuneInURL . $this->TuneInBase . "?id=" . $ID);
$PlayList = parse_ini_file($this->StreamsFilename, true, INI_SCANNER_RAW);
unlink($this->StreamsFilename);

Another, simple addition was the function to download the file to disk using CURL:

/* Much more safer alternative to allow_url_include 1 */
function get_ini_and_write_to_disk ($URL){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $URL);
    $Data = curl_exec($ch);
    curl_close($ch);
    $fp = fopen($this->StreamsFilename, "w");
    fwrite($fp, $Data);
    fclose($fp);
}

Might be a better way to do this, but for now it works and parses the ini files correctly, without making the server insecure by enabling allow_url_include. Was a very bad idea to allow that feature in PHP to begin with, the possibility of code excution without unsanitized input would have been really easy, and left the server insecure as a whole. So never take the quick and lazy or inexperienced route and look at alternatives. Especially when it involves webservers.

Playlists creation should be working as intended again, but give it a bit of time to finish the cronjob. I add a sleep between most queries to the ShoutCast servers to avoid getting temp bans from too many queries in a short space, so playlists creation can take some time. Just keep checking for a later version of the playlist than “1476013698” from here.

Edit..
Playlists are working as intended again with the cronjob finished.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.