[code=php]
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<title>Heimautomation via Raspberry</title>
</head>
<body>
Lampen schalten
<form method="get" action="Heimautomation.php">
<input type="submit" value="Lampen an" name="Lampenein">
<input type="submit" value="Lampen aus" name="Lampenaus">
</form>
<br/>
<br/>
Musik
<form method="get" action="Heimautomation.php">
<input type="submit" value="Musik an/aus" name="togglemusic">
<input type="submit" value="Musik lauter" name="volumeup">
<input type="submit" value="Musik leiser" name="volumedown">
<input type="submit" value="Nächstes Lied" name="nexttrack">
</form>
<?php
#$PREcmd = 'sudo ';
#$SudoWebScript = '/var/sudowebscript.sh ';
if (isset($_GET["Lampenein"])) {
exec('sudo /var/sudowebscript.sh remote 11100 1 1', $output, $return_var);
}
if (isset($_GET["Lampenaus"])) {
exec('sudo /var/sudowebscript.sh remote 11100 1 0', $output, $return_var);
}
if(isset($_GET["togglemusic"])){
exec("mpc toggle");
echo "Musik an/aus";
}
if(isset($_GET["volumeup"])){
exec("mpc volume +5");
echo "Volume +5";
}
if(isset($_GET["volumedown"])){
exec("mpc volume -5");
echo "Volume -5";
}
if(isset($_GET["nexttrack"])){
exec("mpc next");
echo "Nächstes Lied";
}
# Error/Output Handling
if (isset($return_var) AND $return_var >= 1) {
echo "<font face='Arial, Helvetica, sans-serif' size='3' color='FF0000'>ERROR: </font>\n";
echo "<font face='Arial, Helvetica, sans-serif' size='3' color='009900'>".exitcode($return_var)."<br/>\n";
}
if (isset($output) AND !empty($output)) {
foreach($output AS $line) { echo $line."<br/>\n"; }
}
// Function to handle $return_var (exit codes)
/*
An exit status of zero indicates success. A non-zero exit status indicates failure.
When a command terminates on a fatal signal N, bash uses the value of 128+N as the exit status.
If a command is not found, the child process created to execute it returns a status of 127. If a com-
mand is found but is not executable, the return status is 126.
If a command fails because of an error during expansion or redirection, the exit status is greater than
zero.
Shell builtin commands return a status of 0 (true) if successful, and non-zero (false) if an error
occurs while they execute. All builtins return an exit status of 2 to indicate incorrect usage.
Bash itself returns the exit status of the last command executed, unless a syntax error occurs, in
which case it exits with a non-zero value.
source: http://tldp.org/LDP/abs/html/exitcodes.html
*/
function exitcode($code) {
$ReturnCode['0'] = "Successful";
$ReturnCode['1'] = "General Error (Miscellaneous errors, such as 'divide by zero' and other impermissible operations)";
$ReturnCode['2'] = "Incorrect Usage";
$ReturnCode['126'] = "Command found but not executable (Permission problem)";
$ReturnCode['127'] = "Command not found (Possible problem with PATH or a typo)";
$ReturnCode['128'] = "Invalid argument to exit (exit takes only integer args in the range 0 - 255)";
$ReturnCode['130'] = "Script terminated by Control-C";
return $ReturnCode[$code];
}
?>
</body>
</html>
[/php]