Skip to content

Instantly share code, notes, and snippets.

@mahata
Created January 23, 2012 00:31
Show Gist options
  • Save mahata/1659633 to your computer and use it in GitHub Desktop.
Save mahata/1659633 to your computer and use it in GitHub Desktop.
PHP Bot
<?php
$input = json_decode(file_get_contents("php://input"), true);
$source = $input["events"][0]["message"]["text"];
define("PHP_SIGN", "<?");
define("LLEVAL_ENDPOINT", "http://api.dan.co.jp/lleval.cgi");
if (0 === strpos($source, PHP_SIGN)) {
echo prep($source);
$resp = json_decode(file_get_contents(LLEVAL_ENDPOINT . "?s=" . urlencode(prep($source))), true);
if (isset($resp["stderr"]) && "" !== $resp["stderr"]) {
echo $resp["stderr"] . "\n";
} else {
echo $resp["stdout"] . "\n";
}
}
function prep($source) {
return "#!/usr/bin/php\n<?php " . trim(substr($source, strlen(PHP_SIGN))) . " ?>\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment