$v) { // error_log(" POST $k: $v"); //} try{ // Check data $data_request = filter_input(INPUT_POST, 'request'); $data_response= filter_input(INPUT_POST, 'response'); if ($data_request == null || $data_request == false || $data_response == null || $data_response == false){ error_log("error1"); http_response_code(400); return 400; } // Check API key. $key = filter_input(INPUT_POST, 'key'); if ($key == null || $key == false){ http_response_code(401); return 401; } // Check data format. $json_request = json_decode($data_request); $json_response = json_decode($data_response); if ($json_response === null | $json_request === null){ error_log("error2"); http_response_code(400); return 400; } // Authenticate $uid = $json_request->{"wizard_id"}; $uname = $json_response->{"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; } // Run dungeon run parser script $cmd = __DIR__ . "/bin/upload_run_dungeon.py " . $key . " " . escapeshellarg($data_request) . " " . escapeshellarg($data_response); $out = []; $ret = 0; //error_log($cmd); try{ exec($cmd, $out, $ret); } catch(Exception $e) { error_log("Error running dungeon run script: " . $e->getMessage()); http_response_code(500); return 500; } if ($ret != 201){ try{ http_response_code($ret); error_log("NO 201: $ret"); return $ret; } catch(Exception $e) { error_log("Dungeon run script returned an unexpected value $ret: " . $e->getMessage()); http_response_code(500); return 500; } } error_log("ACTUAL RET: " . $ret); // At this point, status code should be 200 http_response_code($ret); return $ret; } catch(Exception $e) { error_log("Unknown error parsing dungeon run: " . $e->getMessage()); http_response_code(500); return 500; } ?>