码云配置webhook

版权声明:转载请注明作者和出处! 作者QQ 152910000 https://blog.csdn.net/icodestechnology/article/details/88671710

1、编写webhook内容

<?php
    // function writelog($message,$logFileDir){
    //     $logFile = 'git_info.log';
    //     $log = date('Y-m-d H:i:s') . ' - ' . $message . "\n";
    //     $fp = fopen($logFileDir.$logFile, 'a+');
    //     fwrite($fp, $log);
    //     fclose($fp);
    // }
    $target = dirname(__FILE__);
    $json = json_decode(file_get_contents('php://input'), true);
    $password='yourPassoword';
    // writelog(json_encode($json));
    if (empty($json['password']) || $json['password'] !== $password) {
        exit('error request');
    }
    $cmd=" cd {$target} ;sudo -Hu www git pull 2<&1";
    $r= shell_exec($cmd);
    print_r($r);
    echo date('Y-m-d H:i:s');

2、linux将www用户加入sudoers并赋予无密码执行git命令权限

(1)为当前用户添加写入sudoers的权限
	chmod u+w /etc/sudoers
(2)编辑sudoers
	vim /etc/sudoers
(3)搜索Allow root to run any commands anywhere,插入模式在root用户对应行下写入如下内容:
	www     ALL=(ALL)       NOPASSWD:/usr/bin/git
(4)收回对sudoers的写入权限
	chmod u-w /etc/sudoers

3、编辑php.ini,搜索disable_functions删掉shell_exec

vim /usr/local/php/etc/php.ini

没有更多推荐了,返回首页