Пример #1
0
 /**
  * @param string $secret
  */
 public static function setSecret($secret)
 {
     self::$secret = $secret;
 }
Пример #2
0
 *
 * @link       https://freebsd.github.io/redports/
 */
namespace Redports\Master;

require_once __DIR__ . '/vendor/autoload.php';
$session = new Session();
$app = new \Slim\Slim();
$app->config('debug', Config::get('debug'));
$app->response->headers->set('Content-Type', 'text/plain');
$redis = new \Redis();
$redis->pconnect(Config::get('datasource'));
\Resque::setBackend(Config::get('datasource'));
/* GitHub Webhooks */
$app->post('/github/', function () use($app) {
    $github = new GitHubWebhook();
    $result = $github->handleEvent($app->request->headers->get('X-GitHub-Event'));
    textResponse($result['code'], $result['message']);
});
/* Authentication - Login */
$app->post('/auth/', function () use($app, $session) {
    if (!isset($_POST['machineid']) || !isset($_POST['secret'])) {
        textResponse(403, 'Authentication failed');
    } elseif (!$session->login($_POST['machineid'], $_POST['secret'])) {
        textResponse(403, 'Authentication failed');
    } else {
        jsonResponse(200, array('sessionid' => $session->getSessionId()));
    }
});
$app->get('/auth/', function () use($app) {
    textResponse(400, 'Only POST method allowed for authentication');