private function initRepo()
 {
     if (!class_exists("Git")) {
         require 'Git.php/Git.php';
     }
     $this->pullOnChange = c::get('gcapc-pull', false);
     $this->pushOnChange = c::get('gcapc-push', false);
     $this->commitOnChange = c::get('gcapc-commit', false);
     $this->gitBin = c::get('gcapc-gitBin', '');
     $this->windowsMode = c::get('gcapc-windowsMode', false);
     if ($this->windowsMode) {
         Git::windows_mode();
     }
     if ($this->gitBin) {
         Git::set_bin($this->gitBin);
     }
     $this->repo = Git::open($this->repoPath);
     if (!$this->repo->test_git()) {
         trigger_error('git could not be found or is not working properly. ' . Git::get_bin());
     }
 }
Ejemplo n.º 2
0
function gitpush($strRepo)
{
    global $repo_dir, $eqdkp_dir, $git_path, $isWindows;
    try {
        if ($isWindows) {
            Git::windows_mode();
        }
        Git::set_bin($git_path);
        $repoPath = $strRepo == 'local_core' ? $eqdkp_dir : $repo_dir . $strRepo;
        $repo = Git::open($repoPath);
        notify($repo->status(true), 'Git Status before push');
        $repo->push('origin', 'master');
        notify($repo->status(true), 'Git Status after push');
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}
Ejemplo n.º 3
0
         echo "<div id=\"checkwithfailed\">\r\n                                            <span id=\"titleresult\">评估结果:</span>\r\n                                            <span id=\"resultsentence\">没有通过评估</span>\r\n                                        </div>\r\n                                        <div id=\"declare\">\r\n                                            <p>原因: 您的许可证文件已经被检测到, 但是内容并没有完全匹配到由OSI批准的";
         echo substr($keyFiles[$minKey], 0, strrpos($keyFiles[$minKey], "."));
         echo "许可证文件内容, 详细文本之间的差别请看下面:</p>\r\n                                <p><span style=\"background-color:#005500\">&nbsp;&nbsp;&nbsp;&nbsp;</span>代表比标准文本增加的部分</p><p><span style=\"background-color:#990000\">&nbsp;&nbsp;&nbsp;&nbsp;</span>代表比标准文本减少的部分</span></p>\r\n                                        </div>\r\n                                        <div id=\"originaldiv\">\r\n                                            <div>您的许可证比较结果</div>\r\n                                            <div id=\"originalcontent\"><pre>";
         echo $comparedStandardLicenseFileContent;
         echo "</pre></div>\r\n                                        </div>\r\n                                        <div id=\"standarddiv\">\r\n                                        <div>";
         echo substr($keyFiles[$minKey], 0, strrpos($keyFiles[$minKey], "."));
         echo "</div>\r\n                                            <div id=\"standardcontent\"><pre>";
         echo htmlspecialchars($licensecollection[$keyFiles[$minKey]]);
         echo "</pre></div>\r\n                                <div class=\"contact-us\">如果对检测结果有任何意见和反馈, 您可以<a href=\"http://www.kaiyuanshe.cn/feedback.php\">联系我们</a></div>\r\n                                <div class=\"page-jump\">\r\n                                    <input type=\"button\" value=\"完成\" class=\"resolver-next\" data-redirect=\"/index.php\">\r\n                                </div>\r\n                                        </div>\r\n                                        </div>";
         RemoveStatusRecords($sessionId, $conn, $logger, $loghelperArr);
     }
 } else {
     $logger->log('debug', 'License file not found', $loghelperArr);
     InsertStatusRecords($sessionId, "快速检测未找到许可文件,正在克隆代码仓库副本以便进一步检测", $conn, $logger, $loghelperArr);
     // Git clone the repository based on git URL
     Git::windows_mode();
     $repo = new GitRepo();
     // Get git client folder name
     $comresult = stripos($urlText, '.git');
     if ($comresult !== FALSE) {
         $indexOfLastSplash = strrpos($urlText, "/");
         $indexOfLastDot = strrpos($urlText, '.');
         $GitName = substr($urlText, $indexOfLastSplash + 1, $indexOfLastDot - $indexOfLastSplash - 1);
     } else {
         $indexOfLastSplash = strrpos($urlText, '/');
         $GitName = substr($urlText, $indexOfLastSplash + 1);
     }
     $logger->log('debug', 'GitName: ' . $GitName, $loghelperArr);
     $ran = rand();
     $timeparts = explode(' ', microtime());
     $etime = $timeparts[1] . substr($timeparts[0], 1);
Ejemplo n.º 4
0
function get_update($sname, $file_lock, $base_url, $path, $mail_lock, $remote_git = '', $remote_branch = '')
{
    session_name($sname);
    session_start();
    set_time_limit(300);
    ignore_user_abort(true);
    $stime = time();
    $work = false;
    //检测、设置工作标志,存在session里(同一个session_name在一个页面未结束前会保持读写锁状态)
    if (empty($_SESSION['working'])) {
        $work = true;
    }
    if (file_exists($file_lock)) {
        $last_work_time = filemtime($file_lock);
        if ($last_work_time > 0 && time() - $last_work_time < 120) {
            //上次更新至今有120秒
            echo "检测到正在进行工作中,本页面停止载入,请稍后再次访问。";
            return false;
            //exit;
        }
        $work = true;
        unlink($file_lock);
    } elseif (empty($_SESSION['work_time']) || $stime - $_SESSION['work_time'] > LOCK_TIME) {
        //保证 LOCK_TIME 秒内只访问一次
        $work = true;
    }
    if ($work && !file_exists($file_lock)) {
        $_SESSION['working'] = true;
        $_SESSION['work_time'] = $stime;
        file_put_contents($file_lock, $stime);
    } else {
        echo "距离上次获取请求时间间隔多短,请稍后再次访问。";
        return false;
        //exit;
    }
    echo date("Y-m-d H:i:s") . " 读取列表中...<br>";
    $list = get_list($base_url);
    //获取列表
    if (count($list) < 2) {
        echo "读取Wiki列表失败,等待下次检测。<br>";
        $_SESSION['work_time'] = $stime - LOCK_TIME;
        //取消检查时间,让检测可在稍后再次发起
        unlink($file_lock);
        return false;
    }
    session_write_close();
    //解除session,防止使其他访问页面一直等待session
    mk_dir($path);
    if (IS_WIN) {
        Git::windows_mode();
    }
    if (!file_exists($path . '.git')) {
        echo date("Y-m-d H:i:s") . " 没有git库,尝试创建...<br>";
        if ($remote_git) {
            //是否设置了远程仓库
            echo "尝试从远程仓库克隆数据...<br>";
            $ret = Git::clone_remote($path, $remote_git, $remote_branch);
            //从远程仓库clone(可指定分支)
            if (!Git::is_repo($ret) || !file_exists($path . '.git') || !$ret) {
                echo "从远程仓库克隆失败,本地创建...<br>";
                $ret = Git::create($path);
                //如果clone失败,则本地创建
            }
        } else {
            $ret = Git::create($path);
        }
        //直接本地创建
        echo date("Y-m-d H:i:s") . " 创建结果:" . (Git::is_repo($ret) ? '成功' : '失败') . "<br>";
    }
    $files = ls_file($path);
    foreach ($files as $file) {
        if (!is_dir($path . $file)) {
            unlink($path . $file);
        }
    }
    $tmp_arr = parse_url($base_url);
    $url_base = $tmp_arr['scheme'] . '://' . $tmp_arr['host'];
    write($path . 'list.txt', json($list));
    //写出列表
    echo date("Y-m-d H:i:s") . " 读取wiki列表完毕,开始读取内容页...<br>";
    $count = 0;
    $content = get_content($base_url);
    write($path . 'index.html', $content);
    $count++;
    foreach ($list as $arr) {
        if (isset($arr['ul'])) {
            foreach ($arr['ul'] as $a) {
                if (substr($a['url'], 0, 1) == '.' || substr($a['url'], 0, 1) == '/') {
                    //地址以.或/开头,则为wiki文档
                    $content = get_content((substr($a['url'], 0, 1) == '/' ? $url_base : (substr($a['url'], 0, 1) == '.' ? $url_base . $tmp_arr['path'] : '')) . $a['url']);
                    if ($content) {
                        write($path . $a['title'] . '.html', $content);
                        $count++;
                    }
                }
            }
        }
    }
    echo date("Y-m-d H:i:s") . " 获取操作完成,读取页面数量:" . $count . "<br>";
    $repo = Git::open($path);
    $ret = $repo->status(true);
    $no_commit = preg_match('/nothing to commit, working directory clean/', $ret);
    if ($no_commit) {
        echo " 未检测到更新,共计用时:" . (time() - $stime) . "秒<br>";
    } else {
        echo "待更新内容:<hr>" . $ret . "<hr>";
        $ret0 = $repo->add();
        $repo->run('config --global user.email "' . GIT_EMAIL . '"');
        //git config --global user.email "*****@*****.**"
        $repo->run('config --global user.name "' . GIT_NAME . '"');
        //git config --global user.name "Your Name"
        $repo->run('config --global core.quotepath false');
        //配置git显示中文不转码
        $ret = $repo->commit('check time: ' . date("Y-m-d H:i:s"));
        echo time() . " 已进行git提交,共计用时:" . (time() - $stime) . "秒<br><br>";
        if ($remote_git) {
            $branch = $repo->active_branch();
            echo "检测到远程仓库参数,提交到远程仓库...<br>";
            $repo->run("remote add {$stime} " . $remote_git);
            //添加远程仓库
            $repo->run("push -f {$stime} {$branch}:" . (empty($remote_branch) ? 'master' : "{$remote_branch}"));
            //强制覆盖远程仓库(可指定分支)
            $repo->run("remote remove {$stime}");
            //删除远程仓库
        }
        echo "提交git日志内容如下:<hr>" . nl2br(htmlspecialchars($ret));
        $ret2 = $repo->run('log --stat -p -1');
        echo "<hr>其他日志:<br>" . nl2br(htmlspecialchars($ret0)) . nl2br(htmlspecialchars($ret2));
        unlink($mail_lock);
    }
    unlink($file_lock);
    return !$no_commit;
}