Skip to content

Instantly share code, notes, and snippets.

@thomaslorentsen
Created March 30, 2016 13:03
Show Gist options
  • Save thomaslorentsen/882e3233577e90adc34b0a31f46a6855 to your computer and use it in GitHub Desktop.
Save thomaslorentsen/882e3233577e90adc34b0a31f46a6855 to your computer and use it in GitHub Desktop.
<?php
require_once('vendor/autoload.php');
use Symfony\Component\Yaml\Yaml;
$config = Yaml::parse(file_get_contents('config.yaml'));
$json = file_get_contents('php://input');
$object = json_decode($json);
if ($object === false || !isset($object->action)) {
die(json_encode(['error' => 'What']));
}
$action = $object->action;
if (array_key_exists($action, $config['commands'])) {
$command = $config['commands'][$action];
$result = shell_exec($command);
die(json_encode(['success' => 'Ok']));
} else {
die(json_encode(['error' => 'Command not found']));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment