aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2017-01-02 15:32:12 +0100
committersteckbrief <steckbrief@chefmail.de>2017-01-02 15:32:12 +0100
commit3ac60598246cda6947a5ced173784c3ee25622c3 (patch)
tree4253037a48b907df8e89fd521c52b1ff61950c31
parent0549800afeb7b8db389d79a9fd48feecf875ab23 (diff)
Fixed redirect URL, added more mvn repos
-rw-r--r--src/config/config.inc.php10
-rw-r--r--src/loadArtifact.php34
-rw-r--r--src/mvncache.php6
3 files changed, 14 insertions, 36 deletions
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 @@
-<?php
-$mvnBaseUrl = 'http://repo1.maven.org/maven2';
-
-$requestedArtifact = $_SERVER["REQUEST_URI"];
-$requestedArtifact = str_replace('/mvn', '', $requestedArtifact);
-$baseLocalFolder = __DIR__;
-$localFolder = $baseLocalFolder.substr($requestedArtifact, 0, strripos($requestedArtifact, '/'));
-//echo $localFolder."<br>";
-if (!is_dir($localFolder)) {
- mkdir($localFolder, 0770, true);
-}
-
-$srcUrl = $mvnBaseUrl.$requestedArtifact;
-//echo $srcUrl."<br>";
-$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');
}