Skip to content

Instantly share code, notes, and snippets.

@shinji257
Last active June 29, 2018 02:52
Show Gist options
  • Save shinji257/54a64cff81843429f4de627482c7cd4f to your computer and use it in GitHub Desktop.
Save shinji257/54a64cff81843429f4de627482c7cd4f to your computer and use it in GitHub Desktop.
Patch for _h5ai to make it behave a bit better on Feral Hosting servers
diff -ur 1/_h5ai/private/php/core/class-setup.php 2/_h5ai/private/php/core/class-setup.php
--- 1/_h5ai/private/php/core/class-setup.php 2016-08-12 14:59:10.000000000 +0000
+++ 2/_h5ai/private/php/core/class-setup.php 2018-06-29 02:44:52.576068630 +0000
@@ -51,7 +51,12 @@
$this->set('PHP_ARCH', (PHP_INT_SIZE * 8) . '-bit');
$this->set('REQUEST_METHOD', $_SERVER['REQUEST_METHOD']);
- $this->set('REQUEST_HREF', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
+ if ($_SERVER['HTTP_X_HOST'] != $_SERVER['HTTP_HOST']){ // HTTP_HOST is always the same format username.server.feralhosting.com
+ $xproxy = "/" . getenv("USER"); // If the HOSTs don't match then insert this variable
+ } else { // If they do match then do this instead
+ $xproxy = ''; // insert nothing. Basically, do nothing
+ }
+ $this->set('REQUEST_HREF', $xproxy . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$this->set('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']);
$this->set('SERVER_SOFTWARE', $_SERVER['SERVER_SOFTWARE']);
$this->set('HTTP_USER_AGENT', $_SERVER['HTTP_USER_AGENT']);
@@ -95,7 +100,12 @@
$script_name = preg_replace('#^.*?//#', '/', $script_name);
}
- $this->set('H5AI_HREF', Util::normalize_path(dirname(dirname($script_name)), true));
+ if ($_SERVER['HTTP_X_HOST'] != $_SERVER['HTTP_HOST']){ // HTTP_HOST is always the same format username.server.feralhosting.com
+ $xproxy = "/" . getenv("USER"); // If the HOSTs don't match then insert this variable
+ } else { // If they do match then do this instead
+ $xproxy = ''; // insert nothing. Basically, do nothing
+ }
+ $this->set('H5AI_HREF', $xproxy . Util::normalize_path(dirname(dirname($script_name)), true));
$this->set('H5AI_PATH', Util::normalize_path(dirname(dirname(dirname(dirname(__FILE__)))), false));
$this->set('ROOT_HREF', Util::normalize_path(dirname($this->get('H5AI_HREF')), true));
@shinji257
Copy link
Author

Updated gist patch to also allow the setup info page to work as well.

For the second patch you have to do it there. If you try to do it in the same place as the first page the prepend gets duplicated (even though it seems to work a bit). The check is in class-bootstrap.php to see if it should show a directory or the info page. It passes to class-context.php is_info_request() and compares REQUEST_HREF from class-setup.php against PUBLIC_HREF in the same file. Since the latter is already set we just had to patch the first to match as needed. We used the same method of detecting how the url is being accessed in both routes in order to ensure it works via both url addresses without issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment