$options]); $url = 'https://api.github.com'.$endpoint; $s = @file_get_contents($url, false, $ctxt); if ($s === false) { die('Request to GitHub failed. Endpoint: '.$endpoint); } $retval = json_decode($s); return $retval; } function github_current_user($access_token = false) { if (!$access_token) { $access_token = $_SESSION['github']['access_token']; } if (empty($_SESSION['github']['current_user'])) { $user = github_api('/user?access_token='.urlencode($access_token)); if (!$user->login) { die('Failed to get current user'); } $_SESSION['github']['current_user'] = $user; } return $_SESSION['github']['current_user']; } function github_require_valid_user() { if (isset($_SESSION['github']['access_token'])) { return true; } if (isset($_GET['code'])) { $data = [ 'client_id' => GITHUB_CLIENT_ID, 'client_secret' => GITHUB_CLIENT_SECRET, 'code' => $_GET['code'] ]; $data_encoded = http_build_query($data); $opts = [ 'method' => 'POST', 'user_agent' => GITHUB_USER_AGENT, 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $data_encoded, ]; $ctxt = stream_context_create(['http' => $opts]); $s = @file_get_contents('https://github.com/login/oauth/access_token', false, $ctxt); if (!$s) { die('Failed while checking with GitHub,either you are trying to hack us or our configuration is wrong (GITHUB_CLIENT_SECRET outdated?)'); } $gh = []; parse_str($s, $gh); if (empty($gh['access_token'])) { die("GitHub responded but didn't send an access_token"); } $user = github_current_user($gh['access_token']); $endpoint = '/teams/'.urlencode((string)GITHUB_PHP_OWNER_TEAM_ID).'/members/'.urlencode($user->login); $opts = ['user_agent' => GITHUB_USER_AGENT]; $ctxt = stream_context_create(['http' => $opts]); $is_member = file_get_contents('https://api.github.com'.$endpoint.'?access_token='.urlencode($gh['access_token']), false, $ctxt); if ($is_member === false) { head("github administration"); echo '
Please contact an existing member if you see need.
'; foot(); exit; } // SUCCESS $_SESSION['github']['access_token'] = $gh['access_token']; header('Location: github.php'); exit; } // Start oauth header('Location: https://github.com/login/oauth/authorize?scope=repo&client_id='.urlencode(GITHUB_CLIENT_ID)); exit; } if (isset($_POST['description']) && isset($_SESSION['github']['access_token'])) { action_create_repo(); } elseif (isset($_GET['login']) || isset($_GET['code']) || isset($_SESSION['github']['access_token'])) { action_form(); } else { action_default(); } function action_default() { head("github administration"); echo 'This tool is for administrating PHP repos on GitHub. Currently it is used for adding repos only.
'; echo 'NOTE: Only members of the PHP organisation on GitHub can use this tool. We try to keep the number of members limited.
'; echo 'In case you are a member you can login using GitHub.
'; foot(); } function action_form() { github_require_valid_user(); $user = $_SESSION['github']['current_user']; head("github administration"); ?>GitHub user: login); ?>
Creating a GitHub repo using this form ensures the proper configuration. This includes disabling the GitHub wiki and issue tracker as well as enabling the php-pulls user to push changes made on git.php.net.
The name, description and homepage should follow other existing repositories.