Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

theme issues with https site #251

Closed
rrossouw01 opened this issue Jul 6, 2023 · 14 comments
Closed

theme issues with https site #251

rrossouw01 opened this issue Jul 6, 2023 · 14 comments
Assignees
Labels

Comments

@rrossouw01
Copy link

In case anyone else has this issue. If you run your site on docker and probably kubermetes containers you likely run internal on http and external (load balancer) on https. Flatpress does not pull up any theme like this. So unless there is something more elegant to fix this here is a quick hacky diff in defaults.php to work around it. Probably should detect serverport from the config file not from PHP.

> diff flatpress-1.2.1/defaults.php ../web/defaults.php 
118c118,119
< if (isset($_SERVER ['HTTPS'])) {
---
> $serverport = "https://";
> if ($serverport == 'https://') {
121c122
< $serverport = "false";
---
> 
123,125c124
< if (isset($_SERVER ['HTTPS']) && ($_SERVER ['HTTPS'] == '1' || strtolower($_SERVER ['HTTPS']) == 'on')) {
< 	$serverport = "https://";
< 	// Uses a secure connection (HTTPS) if possible
---
> if ($serverport == 'https://') {
127,128d125
< } else {
< 	$serverport = "http://";
@DeltaLima
Copy link

Hi @rrossouw01 - I ran into the exact same problem. Not with docker, but with apache2 as reverse proxy and ssl terminator and a little arm box running flatpress on armbian on it. In my setup I workarounded this with giving the apache server on the armbox an snakeoil ssl cert , so the reverse proxy can talk via https with its backend. Far away from a good solution :D

When I remember right, in the actual master branch (1.3-dev ) I saw a fix for this problem in the commits? I can search later on for this, maybe i find it , if i saw it right. :)

@Fraenkiman
Copy link
Collaborator

@DeltaLima, is the issue with RC1 still valid?

@azett
Copy link
Member

azett commented Apr 21, 2024

@rrossouw01 @DeltaLima Thanks for reporting and testing!
Is this still reproducable with our current 1.3.1 Branch?

@azett azett added the More feedback required More feedback required label Apr 21, 2024
@rrossouw01
Copy link
Author

1.3.1 did not work for me. from Maintain > Updates
You have FlatPress version 1.3
...

diff below. same change as before.

diff defaults.php /tmp/defaults.1.3.1.php 
127d126
< $serverport = "https://";
131c130
< //$serverport = "false";
---
> $serverport = "false";
136c135
< /*if (isset($_SERVER ['HTTPS']) && ($_SERVER ['HTTPS'] == '1' || strtolower($_SERVER ['HTTPS']) == 'on')) {
---
> if (isset($_SERVER ['HTTPS']) && ($_SERVER ['HTTPS'] == '1' || strtolower($_SERVER ['HTTPS']) == 'on')) {
140c139
< }*/
---
> }

@rrossouw01
Copy link
Author

not sure this is much better but I tried instead of above to just set scheme (you have $serverport) to whatever the config is.

$ diff defaults.php /tmp/defaults.1.3.1.php 
131d130
< 
136,140c135
< 
< $configs = include(CONFIG_FILE);
< $url = $fp_config ['general'] ['www'];
< $serverport = parse_url($url, PHP_URL_SCHEME) . "://";
< /*if (isset($_SERVER ['HTTPS']) && ($_SERVER ['HTTPS'] == '1' || strtolower($_SERVER ['HTTPS']) == 'on')) {
---
> if (isset($_SERVER ['HTTPS']) && ($_SERVER ['HTTPS'] == '1' || strtolower($_SERVER ['HTTPS']) == 'on')) {
144c139
< }*/
---
> }

@Fraenkiman
Copy link
Collaborator

Fraenkiman commented Apr 22, 2024

Hello @rrossouw01,

Many thanks for your feedback.
What output do you get in current 1.3.1 branch if you insert

@ini_set('display_errors', 'on');
@error_reporting(E_ALL);
var_dump($_SERVER ['HTTPS']);
var_dump($serverport);

in the line below line 192?

Can you please replace lines 189 to 191 with

function is_https() {

function is_https() {
    return (!empty($_SERVER ['HTTPS']) && $_SERVER ['HTTPS'] != 'off' or $_SERVER ['SERVER_PORT'] == 443);
}
@ini_set('display_errors', 'on');
@error_reporting(E_ALL);
var_dump($_SERVER ['HTTPS']);
var_dump($serverport);

With best regards
Frank

@rrossouw01
Copy link
Author

$_SERVER['HTTPS'] is not set. so returns NULL and for $serverport returned http://

Warning: Undefined array key "HTTPS" in /var/www/html/defaults.php on line 180
NULL string(7) "http://"
Deprecated: Optional parameter $from declared before required parameter $message is implicitly treated as a required parameter in /var/www/html/fp-includes/core/core.utils.php on line 290
...<deleted some session warnings>

@Fraenkiman
Copy link
Collaborator

With both?

return (isset($_SERVER ['HTTPS']) && ($_SERVER ['HTTPS'] == '1' || strtolower($_SERVER ['HTTPS']) == 'on'));

and also:
return (!empty($_SERVER ['HTTPS']) && $_SERVER['HTTPS'] != 'off' or $_SERVER ['SERVER_PORT'] == 443);
?

@rrossouw01
Copy link
Author

I copied defaults.php from the repo and tweaked the function a little for my scenario. keep in mind I have not used php in almost 15 years so not good code here just demonstrating what works for me:

function is_https() {
    $configs = include(CONFIG_FILE);
    $url = $fp_config ['general'] ['www'];
    $config_schema = parse_url($url, PHP_URL_SCHEME);
    # running on http behind a load balancer with a certificate (offloaded). k8s/traefik etc
    # themes need https which is I derive from the config file but server is actually on http.
    //var_dump($config_schema);
    //var_dump($_SERVER);
    $server_scheme = explode("/", $_SERVER['SERVER_PROTOCOL']); 
    if ($config_schema == 'https' && $server_scheme[0] == 'HTTP' ) {
      return True;
    } else {
      return (!empty($_SERVER ['HTTPS']) && $_SERVER ['HTTPS'] != 'off' or $_SERVER ['SERVER_PORT'] == 443);
    }
}


@rrossouw01
Copy link
Author

With both?

return (isset($_SERVER ['HTTPS']) && ($_SERVER ['HTTPS'] == '1' || strtolower($_SERVER ['HTTPS']) == 'on'));

and also: return (!empty($_SERVER ['HTTPS']) && $_SERVER['HTTPS'] != 'off' or $_SERVER ['SERVER_PORT'] == 443); ?

not sure I understood what you asked. I have to move on to my job now. I can test tonight if you want me to plug anything into the defaults.php.

@Fraenkiman
Copy link
Collaborator

Fraenkiman commented Apr 22, 2024

@azett Apparently a load balancer $_SERVER ['HTTPS'] is not defined here. Can you please check the execution of @rrossouw01?

@rrossouw01 I will test your variant. Unfortunately, I do not have an environment with a load balancer available for testing.

Thank you in advance for testing.
With best regards
Frank

@rrossouw01
Copy link
Author

rrossouw01 commented Apr 22, 2024 via email

@Fraenkiman Fraenkiman assigned azett and unassigned DeltaLima Apr 22, 2024
@Fraenkiman Fraenkiman added bug and removed More feedback required More feedback required labels Apr 22, 2024
azett added a commit that referenced this issue Apr 27, 2024
@azett
Copy link
Member

azett commented Apr 27, 2024

Thank you all for testing and fixing! I put it all together in the issue371_httphttps branch.
Can you please perform a final test with the latest version of that branch? If all works fine, this will be released as FlatPress 1.3.1.
Thanks a lot!

@azett azett added this to the FlatPress 1.3.1 milestone Apr 27, 2024
@Fraenkiman
Copy link
Collaborator

Hello everyone,

I take the liberty of closing this issue with pleasure #371 (comment).
@rrossouw01, please check the master branch to see if the setup problem is still reproducible. We may have to create a new issue for this.

Note: The issue371_httphttps branch has Smarty version 4.3.1, the master branch 4.4.1 (e544ed6). If the path specification in the defaults.php file does not match Smarty, it will lead to a white page during setup.

define('SMARTY_DIR', ABS_PATH . FP_INCLUDES . 'smarty-4.4.1/libs/');

Have a good start into the new week
With best regards
Frank

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants