Skip to content

Instantly share code, notes, and snippets.

@Phyks
Last active September 24, 2016 03:37
Show Gist options
  • Save Phyks/27d5d0f92a2f6920e2cb4a7db87070b3 to your computer and use it in GitHub Desktop.
Save Phyks/27d5d0f92a2f6920e2cb4a7db87070b3 to your computer and use it in GitHub Desktop.
<?php
$ampache_url = 'ampache.example.org:3689'; // EDIT ACCORDING TO YOUR NEEDS, DO NOT PUT ANY HTTP://
$request = $_SERVER['REQUEST_URI'];
$ch = curl_init();
// If there was a POST request, then forward that as well.
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
}
curl_setopt($ch, CURLOPT_URL, 'http://'.$ampache_url . $request);
curl_setopt($ch, CURLOPT_HEADER, true);
$headers = getallheaders();
// Forward cookie as it came.
$headers['Host'] = $ampache_url;
$curlHeaders = array();
foreach ($headers as $k=>$v) {
$curlHeaders[] = $k.': '.$v;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeaders);
if (isset($headers['Cookie'])) {
curl_setopt($ch, CURLOPT_COOKIE, $headers['Cookie']);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $header_size);
$body = substr($response, $header_size);
$headerArray = explode(PHP_EOL, $headers);
// Process response headers.
foreach ($headerArray as $header) {
$colonPos = strpos($header, ':');
if ($colonPos !== false) {
$headerName = substr($header, 0, $colonPos);
// Ignore content headers, let the webserver decide how to deal with the content.
if (trim($headerName) == 'Content-Encoding') {
continue;
}
if (trim($headerName) == 'Content-Length') {
continue;
}
if (trim($headerName) == 'Transfer-Encoding') {
continue;
}
}
header($header, false);
}
curl_close($ch);
echo $body;
return;
#!/bin/sh
php -S 0.0.0.0:3689 daap_server.php
<VirtualHost _default_:3690>
DocumentRoot /var/local/ampache/daap/
SetEnv nokeepalive
<Directory "/var/local/ampache/daap/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
</VirtualHost>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment