zoukankan      html  css  js  c++  java
  • gitlab+webhook

    <?php
    #项目
    $project = trim($_GET['project']); if (empty($project)) { return json_encode(['msg' => "project not exist."]); } #你的项目地址 $wwwFile = '/server/webroot/' . $project . '/';
    #钩子日志
    $fs = fopen('./hooks.log', 'a'); fwrite($fs, '================ Update Start ===============' . PHP_EOL . PHP_EOL); $accessToken = 'QhNO8YHqym5PHQQsexapF7041xOhzm62DRH';
    #白名单服务器执行ip
    $accessIp = ['192.168.0.174', '192.168.2.204', '192.168.3.222']; $clientToken = trim($_GET['token']); $clientIp = $_SERVER['REMOTE_ADDR']; fwrite($fs, 'Request on [' . date("Y-m-d H:i:s") . '] from [' . $clientIp . ']' . PHP_EOL); #密匙验证 if ($clientToken !== $accessToken) { fwrite($fs, "Invalid token [{$clientToken}]" . PHP_EOL); return json_encode(['msg' => "error 403"]); } #ip白名单验证 if (!in_array($clientIp, $accessIp)) { fwrite($fs, "Invalid ip [{$clientIp}]" . PHP_EOL); return json_encode(['msg' => "error 503"]); } //命令执行$output = shell_exec("cd {$wwwFile} && git stash && git pull && chown nginx. ./* -R 2>&1");
    fwrite($fs, 'Info:' . $output . PHP_EOL); fwrite($fs, PHP_EOL . '================ Update End ===============' . PHP_EOL . PHP_EOL);
    $fs and fclose($fs);

    您的资助是我最大的动力!
    金额随意,欢迎来赏!

    如果,您认为阅读这篇博客让您有些收获,不妨点击一下右下角的推荐按钮。
    如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的关注我

    如果,想给予我更多的鼓励,求打

    因为,我的写作热情也离不开您的肯定支持,感谢您的阅读!

  • 相关阅读:
    Stream 和 byte[] 之间的转换
    C# Process类_进程_应用程序域与上下文之间的关系
    C# Process类_进程管理器Demo
    C# attribute_特性
    SqlDataAdapter类
    SqlDataReader类
    SqlCommand类
    SqlConnection类
    DataTable类
    C# 语法技巧_三目运算_switch_case
  • 原文地址:https://www.cnblogs.com/GreenForestQuan/p/10522206.html
Copyright © 2011-2022 走看看