<?php sendresponse(); //---------------------------------------------------------------- function sendresponse() { // om te testen even wat hardcoded gegevens gebruiken $matchresult = "1"; // 1 = geslaagde match, 0 = niet geslaagd $destination = "2"; // 1 = aanvraag 2 = aanbod $min = "3"; $sec = "20"; $adres = "Beatrixlaan 234"; $bestemming = "Dorpstraat 34"; $passagier = "Henk"; $telefoon = "0633223322"; $toegangscode = "BBB"; $fields = array("matchresult" => $matchresult, "destination" => $destination, "min" => $min, "sec" => $sec, "ophaaladres" => $adres, "bestemming" => $bestemming, "passagier" => $passagier, "telefoon" => $telefoon, "toegangscode" => $toegangscode); header("Content-type: application/json"); echo json_encode($fields); }
sendresponse($response); } else { if ($_POST['securitycode'] != 'foo' || $_POST['passkey'] != 'bar') { $response['code'] = 4; $response['status'] = $api_response_code[$response['code']]['HTTP Response']; $response['message'] = $api_response_code[$response['code']]['Message']; sendresponse($response); } } } /* we passed - send the data back */ $response['code'] = 1; $response['status'] = $api_response_code[$response['code']]['HTTP Response']; $response['message'] = $api_response_code[$response['code']]['Message']; $response['data'] = GetData(); sendresponse($response); function sendresponse($response) { header('HTTP/1.1 ' . $response['status'] . ' ' . $response['message']); header('Content-Type: application/json; charset=utf-8'); echo json_encode($response); exit; } function GetData() { $product_list = array(array('name' => "Callaway Driver", 'category' => "Golf", 'price' => 200.0, 'description' => "Fantastic driver. Used for hitting long!"), array('name' => "Lucky Jeans", 'category' => "Pants", 'price' => 100.0, 'description' => "Nice comfortable jeans."), array('name' => "Nord Fire 3", 'category' => "Musical Instruments", 'price' => 2500.0, 'description' => "Nords new B3 Organ simulator! Reach new heights!"), array('name' => "Zone Monitor Speakers", 'category' => "Electronics", 'price' => 500.0, 'description' => "Great quality sounding speakers. Turn them up for your next party!")); return $product_list; } ?>
$success = update_site_content($sql_select); if ($success == false) { sendresponse($response, 0, false, $api_response_code); } $response['data'] = $success; break; case 'POST': die("insert into table"); break; case 'DELETE': die("delete table where id=key"); break; } } /* we passed - send the data back */ sendresponse($response, 1, true, $api_response_code); function sendresponse($response, $code, $success, $api_response_code) { $response['code'] = $code; $response['status'] = $api_response_code[$response['code']]['HTTP Response']; $response['message'] = $api_response_code[$response['code']]['Message']; $response['success'] = $success; header('HTTP/1.1 ' . $response['status'] . ' ' . $response['message']); header('Content-Type: application/json; charset=utf-8'); echo json_encode($response); exit; } function get_site_data($sql_select) { global $connect; mysql_query("set character_set_server='utf8'");
function homeagent_handler($path_tail, $data) { log_message('info', "[hypergrid] homeagent_handler called"); $data = decodedata($data); $userid = $path_tail[0]; log_message('info', "homeagent_handler called for {$userid} with {$data}"); $osd = decode_recursive_json($data); if ($osd == null) { log_message('error', sprintf('[hypergrid] failed to decode foreignagent json string %s', $data)); sendresponse(false, 'failed to decode foreignagent string'); } $gatekeeper_uri = $osd['gatekeeper_serveruri']; if (!isset($osd['destination_x'])) { $osd['destination_x'] = 128; } if (!isset($osd['destination_y'])) { $osd['destination_y'] = 128; } if (!isset($osd['client_ip'])) { $session = get_session($userid); if (!isset($session['ExtraData']['ClientIP'])) { log_message('warn', "[hypergrid] no client ip found in session, this is going to fail"); sendresponse(false, 'no client ip found in the session'); } $osd['client_ip'] = $session['ExtraData']['ClientIP']; } if (!isset($osd['service_session_id'])) { log_message('debug', 'missing service_session_id, generating a new one'); $osd['service_session_id'] = $gatekeeper_uri . ';' . UUID::Random(); } /* $dest_uuid = $osd['destination_uuid']; */ /* $caps_path = $osd['caps_path']; */ /* $username = $osd['first_name'] . ' ' . $osd['last_name']; */ /* $circuit_code = $osd['circuit_code']; */ /* $session_id = $osd['session_id']; */ /* $secure_session_id = $osd['secure_session_id']; */ /* $start_pos = $osd['start_pos']; */ /* $appearance = $osd['packed_appearance']; */ /* $server_uri = $osd['destination_serveruri']; */ $data = json_encode($osd); log_message('info', "[hypergrid] login to region with {$data}"); $result = array(); if (hg_login($gatekeeper_uri, $userid, $data, $yourip)) { $result['success'] = true; $result['reason'] = "success"; $result['your_ip'] = $yourip; //echo '{"success": true, "reason": "success"}'; } else { $result['success'] = false; $result['reason'] = "hypergrid login failed"; $result['your_ip'] = $yourip; // echo '{"success": false, "reason": "hypergrid login failed"}'; } $jresult = json_encode($result); log_message('info', "[hypergrid] homeagent returns {$jresult}"); echo $jresult; exit; }
die; } if ($query) { $action = $query->request->intent->name; if ($action == "RandomProject") { $response = randomproject(); } elseif ($action == "GetProject") { $response = getproject($query); } elseif ($action = 'GetHelp') { $response = $help; } else { $response = $help; } sendresponse($response, $me); } else { sendresponse($help, $me); } /* 'Alexa, ask openstack to tell me about a random project' Returns info about a random openstack project */ function randomproject() { # Yes, I'm reading the file twice. Sue me. $yaml = file('./governance/reference/projects.yaml'); $projects = array(); foreach ($yaml as $line) { if (preg_match('/^\\w/', $line)) { $projects[] = $line;
} # Get a suggestion for dinner if ($action == 'GetVegetarian' || $action == 'GetMenu') { $response = getmenu($db, $vegetarian); } elseif ($action == 'AddMenu') { $response = addmenu($db, $query); } elseif ($action == 'GetRecipe') { $response = getrecipe($db, $query); } else { # if ( $action == 'AMAZON.HelpIntent' ) { $response = $help; } } else { $response = $help; } sendresponse($response, $me); echo json_encode($response); /* Get a menu recommendation getmenu( $db, $vegetarian ); */ function getmenu($db, $vegetarian = 0) { # various ways to say it $verb = array('Have', 'How about', 'Try', 'What about', 'You could have'); $dbq = "SELECT name FROM menu "; # Vegetarian? if ($vegetarian) { $dbq = $dbq . " WHERE vegetarian IS TRUE "; }
if ($action == "GetSaint") { $response = getsaint(); } elseif ($action == "GetFast") { $response = getfast(); } elseif ($action == "GetReading") { $response = getreading(); } elseif ($action = 'AMAZON.HelpIntent') { sendresponse($help, false); } else { sendresponse($help, false); } if ($response) { sendresponse($response, true); } } else { sendresponse($help, true); } } else { error_log('Request failed: ' . $valid['message']); // print $valid['message']; die; } /* Get today's saint from oca.org */ function getsaint() { # What's today $today = date('Y/m/d'); # Fetch, for example, https://oca.org/saints/lives/2016/02/14 $url = 'https://oca.org/saints/lives/' . $today;