<?php // Janrain Random User Generator (J-RUG) // tsmith@janrain.com session_start(); include 'includes/functions/sendCurlRequest.php'; include 'includes/functions/errorChecking.php'; $captureServer = $_SESSION["captureServer"]; $params["client_id"] = $_SESSION['client_id']; $params["client_secret"] = $_SESSION['client_secret']; $params["type_name"] = "user"; $thisArray["name"] = "isAutogeneratedUser"; $thisArray["type"] = "boolean"; $params["attr_def"] = json_encode($thisArray); $jsonResponse = sendCurlRequest("entityType.addAttribute", $params, $captureServer); $jsonArray = json_decode($jsonResponse, true); $output = "<div class='divTable'>"; $output .= establishErrorCategory($captureServer . " schema OK?"); if ($jsonArray["stat"] == "ok") { $output .= keepGoing(); $thisArray["schemaStatus"] = "OK"; } else { exitWithOutput($output, $jsonResponse); } $output .= "</div>"; $thisArray["html"] = $output; echo json_encode($thisArray); exit;
exitWithOutput($output, "No"); } else { $output .= keepGoing(); } /*********************************************************************/ /***** Is the file valid JSON? ***/ $output .= establishErrorCategory("Is the file valid JSON?"); $thisArray = json_decode(fread($keyFileHandle, filesize($keyFilePath)), TRUE); if (json_last_error() == JSON_ERROR_NONE) { $output .= keepGoing(); } else { exitWithOutput($output, "No"); } /*********************************************************************/ /***** How many capture servers are in the file? ***/ $output .= establishErrorCategory("How many instances found?"); $output .= keepGoing(sizeof($thisArray["clients"])); /********************************************************************/ /****** Ask the user to choose a server ******/ if (sizeof($thisArray["clients"]) == 1) { // only one set of values, so just use this set of values. $_SESSION['captureServer']['value'] = $thisArray["apid_uri"]; $_SESSION['client_id'] = $thisArray["client_id"]; $_SESSION['client_secret'] = $thisArray["client_secret"]; } else { $_SESSION['listOfServers'] = $thisArray["clients"]; foreach ($thisArray["clients"] as $key => $values) { $output .= "<div class='divRow'>"; $output .= "<div class= 'serverNameCell'>" . $key . "</div>"; $output .= "<div class = 'divCell'>"; $output .= "<button class = 'client' id = '{$key}'>Select</button>";
$params["client_secret"] = $client_secret; $jsonResponse = sendCurlRequest("entityType", $params, $captureServer); $jsonArray = json_decode($jsonResponse, true); $output = "<div class='divTable'>"; /************** Check to see if Client_id and _secret work *********/ $output .= establishErrorCategory($thisArray["serverName"] . " credentials OK?"); if ($jsonArray["stat"] == "ok") { $output .= keepGoing(); $_SESSION["captureServer"] = $captureServer; $_SESSION['client_id'] = $client_id; $_SESSION['client_secret'] = $client_secret; } else { exitWithOutput($output); } /***** Check to see if schema has isAutogeneratedUser field *********/ $output .= establishErrorCategory($thisArray["serverName"] . " schema OK?"); if (strpos($jsonResponse, "isAutogeneratedUser") === FALSE) { exitWithOutput($output, "No isAutogeneratedUser field in schema."); } else { $output .= keepGoing(); $thisArray["schemaStatus"] = "OK"; /************* get total user count *****************/ $params["type_name"] = "user"; $thisArray["totalCount"] = getTotalUserCountInDB($params, $captureServer); /************* get autogen user count *******************/ $thisArray["autogenCount"] = getTotalUserCountInDB($params, $captureServer, "autogen"); } $output .= "</div>"; $thisArray["html"] = $output; echo json_encode($thisArray); exit;