Beispiel #1
0
function valid_link()
{
    $CI =& get_instance();
    $token = $CI->config->item('token');
    if (!validateSignature($token)) {
        exit('签名验证失败');
    }
    if (isValid()) {
        // 网址接入验证
        exit($_GET['echostr']);
    }
    if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
        exit('缺少数据');
    }
}
ini_set('display_errors', 1);
// Init vars
$LIVE = "/var/www/LIVE";
$USER = '******';
$PASS = '******';
$REMOTE_REPO = "https://{$USER}:{$PASS}@github.com/{$USER}/yourrepo.git";
$SECRET_KEY = 'yoursecret';
$signature = $_SERVER['HTTP_X_HUB_SIGNATURE'];
$event = $_SERVER['HTTP_X_GITHUB_EVENT'];
$delivery = $_SERVER['HTTP_X_GITHUB_DELIVERY'];
if (!isset($signature, $event, $delivery)) {
    echo 'Undefined payloads';
    return false;
}
$payload = file_get_contents('php://input');
if (!validateSignature($signature, $payload, $SECRET_KEY)) {
    echo 'Invalid signature';
    return false;
}
if (file_exists($LIVE . '/.git')) {
    // If there is already a repo, just run a git pull to grab the latest changes
    $res = shell_exec("cd {$LIVE} && git pull");
} else {
    // If the repo does not exist, then clone it into the parent directory
    $res = shell_exec("cd {$LIVE} && git clone {$REMOTE_REPO} .");
}
print_r($res);
die("done " . time());
function validateSignature($gitHubSignatureHeader, $payload, $SECRET_KEY)
{
    list($algo, $gitHubSignature) = explode("=", $gitHubSignatureHeader);