<?php $settings = HubgraphConfiguration::instance(); ?> <form action="/hubgraph" method="post"> <?php foreach ($settings as $k => $v) { ?> <p><label><?php echo h($settings->niceKey($k)); ?> : <input name="<?php echo $k; ?> " value="<?php echo a($v); ?> " /></label></p> <?php } ?> <p> <input type="hidden" name="task" value="updateSettings" /> <input type="hidden" name="nonce" value="<?php echo createNonce(); ?> " /> <button type="submit" value="submit">Save</button> </p> </form>
Db::execute('INSERT INTO jos_oauthp_nonces(created, nonce, stamp) VALUES (CURRENT_TIMESTAMP, ?, 0)', array($_SESSION['hg_nonce'])); return $_SESSION['hg_nonce']; } function consumeNonce($form) { $now = time(); if (!isset($form['nonce']) || $form['nonce'] != $_SESSION['hg_nonce'] || !preg_match('/^\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\dZ/', $form['nonce'], $ma) || !($timestamp = strtotime($ma[0])) || $timestamp > $now || $timestamp < $now - 60 * 60 || Db::scalarQuery('SELECT stamp FROM jos_oauthp_nonces WHERE nonce = ?', array($form['nonce']))) { //throw new Exception('Bad token', 405); } Db::execute('UPDATE jos_oauthp_nonces SET stamp = 1 WHERE nonce = ?', array($form['nonce'])); unset($_SESSION['hg_nonce']); } require_once 'client.php'; require_once 'request.php'; $req = new HubgraphRequest($_GET); $conf = HubgraphConfiguration::instance(); $perPage = 40; try { switch ($task = !defined('HG_INLINE') && isset($_REQUEST['task']) ? $_REQUEST['task'] : 'index') { case 'complete': hgView('complete', array('limit' => 20, 'threshold' => 3, 'tagLimit' => 100)); case 'getRelated': hgView('related', $req->getTransportCriteria(array('limit' => 5, 'domain' => $_GET['domain'], 'id' => $_GET['id']))); case 'index': case 'page': $results = $req->anyCriteria() ? json_decode(HubgraphClient::execView('search', $req->getTransportCriteria(array('limit' => $perPage))), TRUE) : NULL; $tags = $req->getTags(); $users = $req->getContributors(); $groups = $req->getGroup(); $domainMap = $req->getDomainMap(); $loggedIn = (bool) User::get('id');
private static function http($method, $url, $entity = NULL) { $conf = HubgraphConfiguration::instance(); if (!($sock = @fsockopen($conf['host'], $conf['port'], $_errno, $errstr, 1))) { throw new HubGraphConnectionError('unable to establish HubGraph connection using ' . $conf['host'] . ': ' . $errstr); } fwrite($sock, "{$method} {$url} HTTP/1.1\r\n"); fwrite($sock, "Host: localhost\r\n"); fwrite($sock, "X-HubGraph-Request: " . sha1(uniqid()) . "\r\n"); if ($entity) { fwrite($sock, "Content-Length: " . strlen($entity) . "\r\n"); } fwrite($sock, "Connection: close\r\n\r\n"); if ($entity) { fwrite($sock, $entity); } $first = true; $inHeaders = true; $status = NULL; $body = ''; while ($chunk = fgets($sock, self::CHUNK_LEN)) { if ($first && !preg_match('/^HTTP\\/1\\.1\\ (\\d{3})/', $chunk, $code)) { throw new \Exception('Unable to determine response status'); } elseif ($first) { if (($status = intval($code[1])) === 204) { break; } $first = false; } elseif ($inHeaders && preg_match('/^[\\r\\n]+$/', $chunk)) { $inHeaders = false; } elseif (!$inHeaders) { $body .= $chunk; } } fclose($sock); return array($status, $body); }