From 3ac60598246cda6947a5ced173784c3ee25622c3 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Mon, 2 Jan 2017 15:32:12 +0100 Subject: Fixed redirect URL, added more mvn repos --- src/config/config.inc.php | 10 +++++++++- src/loadArtifact.php | 34 ---------------------------------- src/mvncache.php | 6 +++++- 3 files changed, 14 insertions(+), 36 deletions(-) delete mode 100644 src/loadArtifact.php diff --git a/src/config/config.inc.php b/src/config/config.inc.php index ac61c27..53dd491 100644 --- a/src/config/config.inc.php +++ b/src/config/config.inc.php @@ -4,7 +4,15 @@ */ return [ - 'mavenBaseUrls' => ['http://repo1.maven.org/maven2', ], + 'mavenBaseUrls' => [ + 'https://repo1.maven.org/maven2', + 'https://jcenter.bintray.com', + 'https://jitpack.io/', + 'https://repo.maven.apache.org/maven2/', + 'https://oss.sonatype.org/content/repositories/snapshots/', + 'https://oss.sonatype.org/content/repositories/releases/', + 'https://plugins.gradle.org/m2' //Gradle plugin repo + ], 'logfile' => 'logs/mvncache.log', ]; ?> \ No newline at end of file diff --git a/src/loadArtifact.php b/src/loadArtifact.php deleted file mode 100644 index 6205164..0000000 --- a/src/loadArtifact.php +++ /dev/null @@ -1,34 +0,0 @@ -"; -if (!is_dir($localFolder)) { - mkdir($localFolder, 0770, true); -} - -$srcUrl = $mvnBaseUrl.$requestedArtifact; -//echo $srcUrl."
"; -$src = fopen($srcUrl, 'r'); - -$dstPath = $baseLocalFolder.$requestedArtifact; -//echo $dstPath; -$dst = fopen($dstPath, 'w'); - -$filesize = stream_copy_to_stream($src, $dst); - -if (0 == $filesize) { - unlink($dstPath); - unlink($localFolder); -} - -if (is_file($dstPath)) { - chmod($dstPath, 0660); - header('Location: http://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]); -} else { - header('HTTP/1.0 404 Not Found'); -} -?> diff --git a/src/mvncache.php b/src/mvncache.php index ef75a16..7abb765 100644 --- a/src/mvncache.php +++ b/src/mvncache.php @@ -12,6 +12,10 @@ $requestedArtifact = str_replace('/mvn', '', $requestedArtifact); $baseLocalFolder = __DIR__.'/..'; $localFolder = $baseLocalFolder.substr($requestedArtifact, 0, strripos($requestedArtifact, '/')); +if ('' == $requestedArtifact) { // no artifact is requested - return + sendHttpReturnCodeAndMessage(403, 'Not allowed'); +} + $tempFile = tmpfile(); foreach ($config['mavenBaseUrls'] as $mvnBaseUrl) { $srcUrl = $mvnBaseUrl.$requestedArtifact; @@ -46,7 +50,7 @@ if (!$found) { stream_copy_to_stream($tempFile, $dst); if (is_file($dstPath)) { chmod($dstPath, 0660); - header('Location: http://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]); + header('Location: '.getServerProtocol().'://'.getRequestHostname().$_SERVER["REQUEST_URI"]); } else { header('HTTP/1.0 404 Not Found'); } -- cgit v1.2.3