Skip to content

Instantly share code, notes, and snippets.

@the-dagger
Created August 1, 2016 17:27
Show Gist options
  • Select an option

  • Save the-dagger/a0772bd5ecc81e822f84116d849b18e9 to your computer and use it in GitHub Desktop.

Select an option

Save the-dagger/a0772bd5ecc81e822f84116d849b18e9 to your computer and use it in GitHub Desktop.
<?php
function sendResponse($data) {
header('Content-type: application/json');
echo json_encode($data);
die();
}
/* If the request isn't a POST request then send an error message*/
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
sendResponse([
"status"=>"error",
"code"=>405,
"message"=>"Method Not Allowed",
]);
}
/* Store the input received in a variable named body */
$body = json_decode(file_get_contents('php://input'), true);
/* If the user is nissing any important input parameters, don't process the request */
if (!array_key_exists('email', $body) || !array_key_exists('app_name', $body) || !array_key_exists('endpoint', $body)) {
sendResponse([
"status"=>"error",
"code"=>422,
"message"=>"Unprocessable entity",
]);
}
$uid = mt_rand(1000,9999). "_" .time(); //A random User ID
/* Extracting variables from the body */
$email = escapeshellcmd($body['email']);
$appName = escapeshellcmd($body["app_name"]);
$endpoint = escapeshellcmd($body["endpoint"]);
/* Run a script based on the input parameters */
exec("sudo python /var/www/html/api/appgenserver.py $email $appName $endpoint");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment