' : ' <-- ') . $var_uri . "\n"); function wget($u) { $cu = curl_init(); curl_setopt($cu, CURLOPT_URL, $u); curl_setopt($cu, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($cu, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cu, CURLOPT_CONNECTTIMEOUT, 9); curl_setopt($cu, CURLOPT_TIMEOUT, 180); curl_setopt($cu, CURLOPT_HEADER, false); curl_setopt($cu, CURLOPT_USERAGENT, 'git'); if (TOR_PROXY_USE) { curl_setopt($cu, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($cu, CURLOPT_PROXY, TOR_PROXY_IPPORT); curl_setopt($cu, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME); } $g = curl_exec($cu); return $g === false ? '' : $g; } function gitea_query($u, $m = 'GET', $a = [], $i = false) { $cu = curl_init(); curl_setopt($cu, CURLOPT_URL, $u); curl_setopt($cu, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($cu, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); if ($m != 'GET') { curl_setopt($cu, CURLOPT_CUSTOMREQUEST, $m); curl_setopt($cu, CURLOPT_POSTFIELDS, json_encode($a)); } curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1); curl_setopt($cu, CURLOPT_CONNECTTIMEOUT, 9); curl_setopt($cu, CURLOPT_TIMEOUT, 180); curl_setopt($cu, CURLOPT_HEADER, false); curl_setopt($cu, CURLOPT_HTTPHEADER, $i ? ['Content-Type: application/json'] : ['Content-Type: application/json', 'Authorization: token ' . ACCESS_API_KEY]); curl_setopt($cu, CURLOPT_USERAGENT, 'git'); if (TOR_PROXY_USE) { curl_setopt($cu, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($cu, CURLOPT_PROXY, TOR_PROXY_IPPORT); curl_setopt($cu, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME); } $g = curl_exec($cu); return $g === false ? '' : $g; } function gitea_file_upload($f, $d) { $got = @json_decode(gitea_query(GITEA_SERVER . '/api/v1/repos/' . GITEA_SPACE . '/contents' . $f, 'GET', [], true), true); if (isset($got['sha']) && file_exists($d)) { echo("upload..."); gitea_query(GITEA_SERVER . '/api/v1/repos/' . GITEA_SPACE . '/contents' . $f, 'PUT', ['author' => ['email' => GIT_COMMIT_MAIL, 'name' => GIT_COMMIT_NAME], 'committer' => ['email' => GIT_COMMIT_MAIL, 'name' => GIT_COMMIT_NAME], 'message' => basename($f), 'branch' => 'master', 'sha' => $got['sha'], 'content' => base64_encode(file_get_contents($d)) ]); } else { echo("error!\n"); } } if ($opmode == 'u') { gitea_file_upload($var_uri, $var_file); } else { echo("download..."); $got = wget(GITEA_SERVER . '/' . GITEA_SPACE . '/raw/branch/master' . $var_uri); if (strlen($got) >= 1) { file_put_contents($var_file, $got); } else { echo("error!\n"); } } echo("ok\n");