<?php
	/*
	 * ==============================================================================
	 * BBC iPlayer for Xtreamer Media Player & Streamer
	 * ==============================================================================
	 *
	 * This project allows to watch content brom BBC iPlayer, which is supported
	 * on Linux by get_iplayer PERL script.
	 *
	 * Licence: GNU General Public License v2
	 * http://www.gnu.org/licenses/gpl.html
	 *
	 * Do not remove or change any header comments! Respect our work!
	 *
	 * If you are satisfied with my work you can support it with small donation                                                                                                                               
	 *   https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=SB8WDDAWY5YZE&lc=SI&item_name=xJukebox&item_number=ak5349jgdr&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted	 *
	 *
	 * Author: vpeter/misek
	 *
	 * ==============================================================================
	 */
	 
  $action = @$_GET['action'];
  if (is_null($action) || $action == '')
    $action = 'start';

	if ($action == 'stop') {
		stopHttpd();
	} else {
		stopHttpd();
		startHttpd();
		refreshTVcache();
	}

function stopHttpd() {
	$cmd = './bin/busybox ps w |grep "busybox httpd" |grep -v grep |awk \'{printf("%s", $1); exit}\' |xargs kill';
	system($cmd);
}

function startHttpd() {
	$cmd = "/tmp/usbmounts/sda1/scripts/BBC-iPlayer/bin/busybox httpd -p 8100 -h /tmp/usbmounts/sda1/scripts/BBC-iPlayer/ &";
	system($cmd);
}

function refreshTVcache() {
	$cmd = "/bin/sh refresh_cache_tv.sh >/dev/null 2>&1 &";
	system($cmd);
}

?>
