Page 1 of 1

Limited SSL Usage (original hook by ToonArmy)

Posted: Sun Nov 01, 2015 7:04 pm
by Pond Life
In my 3.0.x installation I have been using the hook created by ToonArmy,
https://github.com/cs278/phpbb3/blob/ho ... ontrol.php, but I've found it doesn't work with 3.1.x, I get the following error:

Code: Select all

Catchable fatal error: Argument 1 passed to phpbb_hook_ssl_control::setTemplate() must be an instance of template, instance of phpbb\template\twig\twig given, called in <removed>/includes/hooks/hook_ssl-control.php on line 101 and defined in <removed>/includes/hooks/hook_ssl-control.php on line 118
line 101 is

Code: Select all

		$this->setTemplate($template ? $template : $GLOBALS['template']);
and line 118 is

Code: Select all

	public function setTemplate(template $template)
Using https for all pages is not an option due to non https embeded images and the tinypic plugin.

Would someone be able to either help me to make the hook work for 3.1 or convert it into an extension please?

Re: Limited SSL Usage (original hook by ToonArmy)

Posted: Mon Nov 02, 2015 5:25 pm
by Pond Life
I have tried to figure out how to make the extension myself, I've read the guide on converting a MOD to an extension, but I'm struggling with it.

I have found a much simpler way around this for now, using .htaccess and a small core edit in includes/functions.php, but would still prefer an extension if possible.

Re: Limited SSL Usage (original hook by ToonArmy)

Posted: Mon Nov 02, 2015 5:58 pm
by 3Di
Yeah, you might be also interested in following this discussion.

Re: Limited SSL Usage (original hook by ToonArmy)

Posted: Sat Jan 09, 2016 8:14 pm
by wolfbeast
Pond Life wrote:I have tried to figure out how to make the extension myself, I've read the guide on converting a MOD to an extension, but I'm struggling with it.

I have found a much simpler way around this for now, using .htaccess and a small core edit in includes/functions.php, but would still prefer an extension if possible.
Would you mind sharing your workaround? I'm not using Apache but I can convert .htaccess rules to nginx if i know what's needed.

Re: Limited SSL Usage (original hook by ToonArmy)

Posted: Sat Jan 09, 2016 8:59 pm
by Pond Life
I'm no expert, I tinker with my own stuff at my own risk. If you use it you do so at your own risk. ;) It does involve editing a core file which tends to be frowned upon here. You have been warned.

includes/functions.php
find (around line 3134)

Code: Select all

		'S_LOGIN_ACTION'		=> build_url(array('f')),
replace with

Code: Select all

		'S_LOGIN_ACTION'      => 'https://<replace this with your forum url>' . build_url(array('f')),
find (around line 5203)

Code: Select all

			'S_LOGIN_ACTION'		=> ((!defined('ADMIN_START')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') : append_sid("{$phpbb_admin_path}index.$phpEx", false, true, $user->session_id)),
replace with

Code: Select all

		'S_LOGIN_ACTION'      => ((!defined('ADMIN_START')) ? append_sid("https://{$user->host}{$user->page['root_script_path']}ucp.$phpEx", 'mode=login') : append_sid("{$phpbb_admin_path}index.$phpEx", false, true, $user->session_id)),
.htaccess
I have included a bit of the original .htaccess here to show where the changes are.

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on

# The following 3 lines will rewrite URLs passed through the front controller
# to not require app.php in the actual URL. In other words, a controller is
# by default accessed at /app.php/my/controller, but can also be accessed at
# /my/controller
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app.php [QSA,L]

# SSL on selected pages
RewriteCond %{HTTPS} !=on
RewriteCond %{QUERY_STRING} mode=(login|reg_details|register) [OR]
RewriteCond %{QUERY_STRING} i=(pm|ucp_pm) [OR]
RewriteCond %{REQUEST_URI} adm/
RewriteRule (.+) https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !.*\.(js|css|gif|png|jpg|woff|ttf)
RewriteCond %{QUERY_STRING} !.*\.(gif|png|jpg)

RewriteCond %{HTTPS} on
RewriteCond %{QUERY_STRING} !mode=(login|reg_details|register)
RewriteCond %{QUERY_STRING} !i=(pm|ucp_pm) 
RewriteCond %{REQUEST_URI} !adm/
RewriteRule (.+) http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Options +FollowSymLinks
</IfModule>

Re: Limited SSL Usage (original hook by ToonArmy)

Posted: Sat Jan 09, 2016 10:20 pm
by wolfbeast
Thanks! the info is certainly appreciated :)
Looks like I might be able to construct a workaround with this.

EDIT: With the php edits in place, I've decided to actually simplify the rules.
Considering anything /adm/, /ucp.php and /posting.php is something that requires or triggers a login, I've simply added a location statement to my nginx http server block like so:

Code: Select all

    location ~ /(adm/|ucp\.php|posting\.php) {
        return         301 https://$server_name$request_uri;
    }
The only part I no longer have is switching back to http upon logout (since phpbb 3.1 no longer seems to have a mode=logout URI) but that's not really a big issue; people can stay on their SSL if they were previously logged in anyway.

This seems to work fine otherwise! Problem solved, for now! :)

Re: Limited SSL Usage (original hook by ToonArmy)

Posted: Mon Jan 11, 2016 1:32 am
by wolfbeast
Question: why is the core file edit needed?

Re: Limited SSL Usage (original hook by ToonArmy)

Posted: Mon Jan 11, 2016 1:49 am
by Pond Life
It's for the login form on the index page.

http://startrekguide.com/community/view ... 10#p117761

Re: Limited SSL Usage (original hook by ToonArmy)

Posted: Mon Jan 11, 2016 11:05 am
by RMcGirr83
Pond Life wrote:It's for the login form on the index page.

http://startrekguide.com/community/view ... 10#p117761

Code: Select all

		'S_LOGIN_ACTION'		=> ((!defined('ADMIN_START')) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login') : append_sid("{$phpbb_admin_path}index.$phpEx", false, true, $user->session_id)),
Doesn't have to edited at all as there is an event available to overwrite that.

Re: Limited SSL Usage (original hook by ToonArmy)

Posted: Mon Jan 11, 2016 11:27 am
by Pond Life
Thanks Rich, I have no idea how to use events or create extensions though, which is why I posted the request here. I had intended my work around to be temporary but it will have to stay unless someone with more ability than I have can convert the hook into an extension.