<?php

$cmd = $_GET['command'];
$code = $_GET['code'];

if ($code != "nocode") {
	echo "Invalid code";
	return;
}

preg_match('/menu\.(\d+)\.icon\.(\d+)\.index\.(\d+)/', $cmd, $match);

$menu = $match[1];
$icon = $match[2];
$index = $match[3];

$minbin = "/usr/local/minerva/bin/";

$menuActions = array();

// Main menu screen
$menuActions[0] = array(
 10=>'media default next music 5',
 16=>'media default next music 5',
 19=>'mixer default toggle', 20=>'mixer default quiet', 21=>'mixer default loud', 
 25=>'weatherstatus', 26=>'ldbquery get lut stp', 27=>'todo list steev', 28=>'getcalendar steev 1',
 29=>'media default status',
 30=>'media default stop', 31=>'media default toggle', 32=>'manifest default next music',  33=>'housenight', 34=>'homedevice default on bedroom',
);

// ... other menu actions here ...

$result = "Unknown command";
if (array_key_exists($menu, $menuActions)) {
	if (array_key_exists($index, $menuActions[$menu])) {
		$command = $menuActions[$menu][$index];
		$command = $minbin.$command;
		$command .= " >&1";

		$output = array();
		exec($command, $output);

		$result = join("\n", $output);
	}
}

print $result;
?>
