{"wizard_id"}; $uname = $json->{"wizard_info"}->{"wizard_name"}; $s = "SELECT COUNT(uid) AS c FROM player WHERE uid = $uid AND api_key = '$key';"; if (1 != $db->query($s)->fetchArray(SQLITE3_ASSOC)["c"]){ http_response_code(401); return 401; } // Write data file $dtime = (new DateTime())->format('Y-m-dTH:i:s'); $fname = ($_SERVER["DOCUMENT_ROOT"] . "/../data/profile_" . $uid . "_" . $uname . "_" . $dtime . ".json"); try{ file_put_contents($fname, $data); } catch(Exception $e) { error_log("Unable to write profile data to '$fname': " . $e->getMessage()); http_response_code(500); return 500; } // Run profile parser script $cmd = __DIR__ . "/bin/upload_profile.py " . $key . " " . $fname; $out = []; $ret = 0; try{ error_log ($cmd); exec($cmd, $out, $ret); } catch(Exception $e) { error_log("Error running profile script '$cmd': " . $e->getMessage()); http_response_code(500); return 500; } if ($ret != 204){ try{ http_response_code($ret); return $ret; } catch(Exception $e) { error_log("Profile script '$cmd' returned an unexpected value $ret: " . $e->getMessage()); http_response_code(500); return 500; } } // At this point, status code should be 200 http_response_code($ret); return $ret; } catch(Exception $e) { error_log("Unknown error parsing profile: " . $e->getMessage()); http_response_code(500); return 500; } ?>