<?php /** * Retrieves match information of one json file and stores the data in MongoDB. * Automatically detects region from filename. */ require "classes/riot-league-api.php"; require "classes/rate-limit.php"; require "classes/settings.php"; $api = new RiotLeagueAPI("na", $league_api_key); $time = new RateLimit(); $mongo = new MongoClient(); $db = $mongo->{"build-ap"}; // Add champions to database $champions = $db->{"STATIC.CHAMPIONS"}; $champions->drop(); $success = false; while (!$success) { $data = $api->getChampions(); $success = $api->getSuccess(); if (!$success) { $time->exceed(); } $time->delay(); } $document = json_decode($data); foreach ($document->{"data"} as $name => $data) { $champions->insert($data); } // Add items to database $items = $db->{"STATIC.ITEMS"};
$paths[] = $path; } if ($best != NULL) { $bestpath = $paths[$best]; $paths[$best] = $paths[0]; $paths[0] = $bestpath; } $data = array(Config::NODE_NAME => $paths); return htmlspecialchars(json_encode($data)); } if (isset($_GET['cmd']) && isset($_GET['arg'])) { // available commands $cmds = array('whois', 'ping', 'ping6', 'traceroute', 'traceroute6', 'summary', 'summary6', 'route', 'route6', 'bgpmap', 'bgpmap6', 'as', 'as6'); if (in_array($_GET['cmd'], $cmds)) { // instantiate RateLimit $limit = new RateLimit(Config::RATE_LIMIT); // check IP against database $limit->rateLimit(Config::RATE_LIMIT); // connect to remote lg daemon $addr = gethostbyname(Config::LG_SERVER); $lg_sock = stream_socket_client("tcp://" . $addr . ":" . Config::LG_PORT, $errno, $errorMessage); if ($lg_sock === false) { throw new Exception("Internal error"); } if ($_GET['cmd'] == "bgpmap") { $json = generateJsonV4($lg_sock); print '<img id="bgpmap" src="map.php?json=' . $json . '">'; } else { if ($_GET['cmd'] == "bgpmap6") { // TODO print ".";
public function submitQuery() { $validator = Validator::make(Input::all(), array('query' => array('required', 'query'), 'servers' => array('required', 'array'), 'type' => array('required', 'type'))); if ($validator->fails()) { return Response::json(array('success' => false, 'error' => $validator->messages()->first())); } // Validate rate limit $ip = Request::getClientIp(); $querylimit = Config::get('lowendping.ratelimit.queries'); if (!empty($querylimit)) { $limit = RateLimit::find($ip); if ($limit) { $time = time(); $expiration = (int) ($limit->time + Config::get('lowendping.ratelimit.timespan')); if ($expiration > $time) { if ($limit->hits >= $querylimit) { $reset = ($expiration - $time) / 60; if ($reset <= 1) { return Response::json(array('success' => false, 'error' => 'Rate limit exceeded, please try again in 1 minute.')); } return Response::json(array('success' => false, 'error' => 'Rate limit exceeded, please try again in ' . $reset . ' minutes.')); } $limit->hits++; $limit->save(); } else { $limit->time = time(); $limit->hits = 1; $limit->save(); } } else { $limit = new RateLimit(); $limit->ip = $ip; $limit->hits = 1; $limit->time = time(); $limit->save(); } } $servers = Config::get('lowendping.servers'); $serverIds = array(); // Validate servers foreach (Input::get('servers') as $id => $val) { if (!isset($servers[$id])) { return Response::json(array('success' => false, 'error' => 'Invalid server ' . $id)); } $serverIds[] = $id; } // Process the query $query = Input::get('query'); $q = new Query(); $q->query = $query; $q->servers = serialize($serverIds); $q->save(); Queue::push('QueryJob', array('id' => $q->id, 'query' => $query, 'type' => Input::get('type'), 'servers' => $serverIds)); $response = array('success' => true, 'queryid' => $q->id, 'serverCount' => count($serverIds)); if (Config::get('lowendping.websocket.enabled', false)) { $response['websocket'] = websocket_url(Config::get('lowendping.websocket.path', ''), Config::get('lowendping.websocket.proxied', false) ? false : Config::get('lowendping.websocket.port', 8080)); } if (Config::get('lowendping.archive.enabled', false)) { $response['resultLink'] = action('HomeController@showResult', array('query' => $q->id)); } return Response::json($response); }