Created
January 23, 2012 00:31
-
-
Save mahata/1659633 to your computer and use it in GitHub Desktop.
PHP Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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