foxygit / foxygit Log in
A tiny read-only git web frontend — browse bare repos with just PHP and git, no database, no framework.
commits tags

/server/verify-api-key.php · 930 B

raw
#!/usr/bin/env php
<?php
declare(strict_types=1);

/*
 * CLI shim for server/git-http-backend-auth: reads a raw API key from
 * stdin, exits 0 if it's valid, 1 otherwise. Deliberately thin — the actual
 * hashing/lookup is verify_api_key() in inc/auth.php, the same function the
 * web app's ?a=account page uses, so there is exactly one place that knows
 * what makes a key valid.
 *
 * Installed alongside server/git-http-backend-auth at
 * /usr/local/lib/foxygit/verify-api-key.php by server/setup-http-push.sh.
 * Hardcodes the deployed web root below -- if foxygit is ever deployed
 * somewhere other than /var/www/foxygit, update both this path and
 * deploy.sh/setup-http-push.sh together.
 */

const FOXYGIT_ROOT = '/var/www/foxygit';

require FOXYGIT_ROOT . '/inc/config.php';
require FOXYGIT_ROOT . '/inc/auth.php';

$rawKey = trim((string) stream_get_contents(STDIN));
exit(verify_api_key($rawKey) !== null ? 0 : 1);