c5_labsci/web/api/gitpull.php
2026-01-27 00:52:00 +08:00

55 lines
2.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* =================================================================================
* 版权声明:保留开源作者及版权声明前提下,开源代码可进行修改及用于任何商业用途。
* 开源作者:众产® http://ciy.cn/code
* 版本0.7.3
* ====================================================================================
*/
/*
* 支持github和码云需设置webhooks网址
* 运行原理:
* 先从git上拉取代码。手动在目录中成功执行git pull。
* 设置webhooks选择application/json
* 有push时git库访问本页面在ud目录下建立gitpull.x文件。
* crond定时执行<gitpull.sh 仓库目录>如果gitpull.x文件存在则执行git pull拉取成功后删除文件。
* gitpull.sh脚本将拉取记录将到ud/gitpull.log文件。
* 该方案无需增加php执行权限相对安全可以实现web集群部署。
* golang不适用。因源码也会被拉取。
*
* 服务器端安装git。
* 进入软件目录,拉取代码:
* git clone http://git.ciy.cn:4001/xxx.git .
* 在cron中定期执行:
* * * * * * /var/spool/cron/gitpull5.sh /软件目录 "http://访问域名/ajax/api/gitpull.result?data="
*/
//http://xxx.cn/ajax/api/gitpull.push
//http://xxx.cn/ajax/api/gitpull.result
namespace web\api;
class gitpull {
public static function json_push() {
$server = "\r\n\r\n\r\n\$_SERVER:\r\n";
foreach ($_SERVER as $k => $v)
$server .= $k . ': ' . $v . "\r\n";
savelogfile('gitpull', $server, true);
if (@$_SERVER['HTTP_X_GITHUB_EVENT'] != 'push' && @$_SERVER['HTTP_X_GITHUB_EVENT'] != 'release')
return errjson('http header error');
if(@$_SERVER['HTTP_AUTHORIZATION'] != 'Bearer token123456')
return errjson('http 授权标头 AUTHORIZATION error');
if ($fp = fopen(PATH_WEB . 'ud/gitpull.x', 'w')) {
@fwrite($fp, date('Y-m-d H:i:s'));
fclose($fp);
return succjson();
} else
return errjson('gitpull.x create error');
}
public static function json_result() {
$data = get('data');
if ($data == 'success') {
} else {
}
return succjson();
}
}