2020-12-11 14:34:54 +01:00
|
|
|
<?php
|
|
|
|
error_reporting(0);set_time_limit(240);
|
|
|
|
// ============ CONFIG ============
|
|
|
|
define('ACCESS_API_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
|
|
|
|
define('TOR_PROXY_USE', false);// true if you have tor
|
|
|
|
define('TOR_PROXY_IPPORT', '127.0.0.1:9050');
|
|
|
|
define('GITEA_SERVER', 'https://git.fuwafuwa.moe');// http://git.fuwafuwaqtlkkxwc.onion
|
|
|
|
define('GITEA_SPACE', 'you/stop_cloudflare');
|
|
|
|
define('GIT_COMMIT_NAME', ['Aakash Shah','Aamir Thoker','Aanchal Gupta','Aanchal Malhotra','Aaran McGuire','Aaron Fiorucci','Aaron McGuire','Aaron Trott','Abby Carrales McNertney','Abby Morrill','Abdulrahim Harara','Abida Ali','Achiel van der Mandele','Adam Chalmers','Adam Martinetti','Adam Schwartz','Adam Shea','Adam Winter','Adam Woss','Adarsh Seetharam','Addis Sendaba','Adena Kirkbride','Adrian Phillips','Aerene Aphiwatudomkun','Ahamed Nafeez','Ahrenn Sivananthan','Alan Braithwaite','Albert Moore','Albert Strasheim','Albina Sultangulova','Alejandra Quevedo','Alejandro Diehl','Alejandro Ramirez','Alek Amrani','Alessandro Ghedini','Alex Chan','Alex Cruz Farmer','Alex Davidson','Alex Dyner','Alex Forster','Alex Krawiec','Alex Krivit','Alex Musgrove','Alex Odagiu','Alex Robinson','Alex Ta','Alex Tasioulis','Alex Thiang','Alex Vidal','Alexander Bocharov','Alexander Dwyer','Alexander Huynh','Alexander Palaistras','Alexandra Logan','Algin Martin','Alice Yang','Alison Baum','Alissa Starzak','Aliza Knox','Aljona Tcherniavskaia','Allati El Henson','Allen Lai','Allen Rinehart','Alon Gavrielov','Alonso Bustamante','Alonso Quiroz Herrera','Alvin Khor','Alvin Lin','Alvin Tai','Alvis Duong','Amin Fawzi','Amir Tahsini','Amit Lift','Amy Bibeau','Amy Cebrian','Amy Kux','An Nguyen','Ana Hagerup','Anand Guruprasad','Anca Hurduc','Andre Bluehs','Andrea Miller','Andrei Aleksejevs','Andres de Fuenzalida','Andrew Fitch','Andrew Galloni','Andrew Geiser','Andrew Horton','Andrew Kennedy','Andrew Li','Andrew Plunk','Andrew Sharp','Andrew Shifflett','Andria Bouskos','Andria Jones','Andronicus Riyono','Andy Jordan','Andy Lockhart','Andy Parker','Andy Silverstein','Andy Wang','Andy Wimmer','Ane Kallmyr Lerheim','Angela Huang','Angie Kim','Anil Karavadra','Anil Savaliya','Anil Somaney','Anirban Banerjee','Anjum Ahuja','Ankur Aggarwal','Anna Ko','Anna Wolf','Annelise Dutcher','Annie Yichen Tang','Annika Garbers','Anthony Chobanian','Anthony Davanzo','Anthony Hatley','Anthony Leong','Antonia Tran','Antonio Cocera','Anurag Reddy','Anushka Aggarwal','Anwar Karzazi','Apoorv Goel','Apoorva Wadehra','Ardi Judanto','Arjunan Rajeswaran','Arman Baratifar','Arman Rye','Armando Faz','Arthur Fabre','Arvind Singh','Arwa Ginwala','Ash DSouza','Ashcon Partovi','Ashish Gandhi','Ashley Eining','Ashley Gorringe','Ashley Lewis','Ashley McClain','Ashley Williams','Aurora Lian Zhang','Austin Cherry','Austin McKinley','Austin Stanford','Austin Urraca','Avery Harnish','Ayako Kobayashi','Barrett Thies','Barton Pickett','Bas Westerbaan','Ben Bradley','Ben Burkert','Ben Fathi','Ben Filreis','Ben Han','Ben Peera','Ben Solomon','Benedikt Christoph Wolters','Beth Watson','Bethany Sonefeld','Betsy Sedlak','Bhavin Tailor','Bill Phillips','Billy Kander','Blake Mattos','Blake Williams','Bo Li','Bob Kuo','Bob Zavala','Bobby Lam','Boris Yanovsky','Brad Carey','Braden Ehrat','Brady Gentile','Brandon Crowe','Brandon Huang','Brandon Nelson','Brendan McMillion','Brent Coco','Brett Erilane','Brett Hoerner','Brian Carbone','Brian Harring','Brian Mgrdichian','Brian Mitchell','Brittany Brown','Brittany Thai','Bruce Li','Bruce Rabinowitz','Bryan Vale','Buck Wallander','Caitlin Magat','Cale Quasha','Calvin Scherle','Candice Madruga Knoll','Carl Garcia','Caroline Greer','Carson Andorf','Cassy Olson','Catherine Flagler','Cathy Hsu','Cavin Kindsvogel','Chaat Butsunturn','Chad Schaefer','Chad Skinner','Chad Toerien','Chandra Mohan Raju','Charlie Andrews','Chase Robinson','Chloe Chang','Chloe Medosch','Chris Adam','Chris Branch','Chris Broglie','Chris Chua','Chris Conanan','Chris Howells','Chris Jones','Chris Kenney','Chris Merritt','Chris Scharff','Chris Snook','Chris Snowdon','Chris Wang','Chris Wong','Christian Antonow','Christian Elmerot','Christian Elsen','Christian Paulus','Christie Draper','Christina Briscoe','Christina Reip','Christina Tanoto','Christine Hu','Christine Lam','Christopher Federico','Christopher Martin','Christopher Patton','Christopher Rotas','Christopher Shelley','Christopher Teaney','Cina Saffary','Claire Tsai','Colin Douch','Colin Lim','Colin Murray','Colleen Noonan','Conl
|
|
|
|
define('GIT_COMMIT_MAIL', substr(sha1(gmdate('U').$d),mt_rand(1,7),mt_rand(4,18)).'@cloudflare.com');
|
|
|
|
// ============ CONFIG ============
|
|
|
|
/*
|
|
|
|
: EditFile
|
|
|
|
: php -f ef.php [--up|upload|down|download FILE] [--to|from /PATH]
|
2020-12-11 14:38:59 +01:00
|
|
|
: or php -f ef.php -- [--up|upload|down|download FILE] [--to|from /PATH]
|
2020-12-11 14:34:54 +01:00
|
|
|
:
|
|
|
|
: php -f ef.php --up PATH_TO_FILE --to /FILENAME.md
|
|
|
|
: Upload & Overwrite PATH_TO_FILE to {master branch} /FILENAME.md.
|
2020-12-11 14:38:59 +01:00
|
|
|
: example: --to /HISTORY.md --upload "my edit.txt"
|
2020-12-11 14:34:54 +01:00
|
|
|
:
|
|
|
|
: php -f ef.php --down PATH_TO_FILE --from /FILENAME.md
|
|
|
|
: Download /FILENAME.md and Save(overwrite) to PATH_TO_FILE.
|
|
|
|
: example: --from /readme/en.md --download export.txt
|
|
|
|
*/
|
|
|
|
if (strlen(ACCESS_API_KEY) != 40) {
|
|
|
|
echo('[ERROR] ACCESS_API_KEY is empty!');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if (strlen(GIT_COMMIT_NAME) < 1 || strpos(GIT_COMMIT_MAIL, '@') === false) {
|
|
|
|
echo('[ERROR] GIT_COMMIT is empty!');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
$opts = getopt('', ['up:', 'to:', 'down:', 'from:', 'upload:', 'download:']);
|
|
|
|
$opmode = '';
|
|
|
|
if (count($opts) == 2) {
|
|
|
|
if (isset($opts['to'])) {
|
|
|
|
$var_file = $opts['up']??$opts['upload'];
|
|
|
|
$var_uri = $opts['to'];
|
|
|
|
$opmode = 'u';
|
|
|
|
} else {
|
|
|
|
$var_file = $opts['down']??$opts['download'];
|
|
|
|
$var_uri = $opts['from'];
|
|
|
|
$opmode = 'd';
|
|
|
|
}
|
|
|
|
if (strlen($var_file) < 1) {
|
|
|
|
echo('[ERROR] file path is empty!');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if ($opmode == 'u' && (!file_exists($var_file) || filesize($var_file) < 1)) {
|
|
|
|
echo('[ERROR] file not exist!');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
if (strpos($var_uri, '/') !== 0 || $var_uri == '/' || strpos(strrev($var_uri), '/') === 0) {
|
|
|
|
echo('[ERROR] invalid path!');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count($opts) != 2) {
|
|
|
|
$istart = false;
|
|
|
|
foreach (explode("\n", file_get_contents($_SERVER['PHP_SELF'])) as $line) {
|
|
|
|
if (strpos($line, '/*') === 0) {
|
|
|
|
$istart = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strpos($line, '*/') === 0) {
|
|
|
|
$istart = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($istart) {
|
|
|
|
echo($line . "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
echo('git: ' . GIT_COMMIT_NAME . ' [' . GIT_COMMIT_MAIL . "]\n");
|
|
|
|
echo(($opmode == 'u' ? '[Upload] ' : '[Download] ') . $var_file . ($opmode == 'u' ? ' --> ' : ' <-- ') . $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 {
|
2020-12-11 14:38:59 +01:00
|
|
|
echo("error!\n");
|
2020-12-11 14:34:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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 {
|
2020-12-11 14:38:59 +01:00
|
|
|
echo("error!\n");
|
2020-12-11 14:34:54 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-11 14:38:59 +01:00
|
|
|
echo("ok\n");
|