MISC-3: Adjust the cdnforjoomla plugin to optionally translate to a .onion



Issue Information

Issue Type: Sub-task
 
Priority: Major
Status: Closed

Reported By:
Ben Tasker
Assigned To:
Ben Tasker
Project: Miscellaneous (MISC)
Resolution: Done (2015-05-19 16:06:18)
Affects Version: Bentasker.co.uk via Tor,
Target version: Bentasker.co.uk via Tor,
Environment:
NoNumber.nl CDN For Joomla Plugin v 3.4.0PRO

Created: 2015-05-19 15:26:44
Time Spent Working
Child of: MISC-2: Make bentasker.co.uk Available as Tor Hidden Service


Description
When a visitor visits the site via the .onion, need to be sure that the URLs use the .onion domain instead of the www.

Will need to adjust the plugin so that it picks up on the indicator header and behaves accordingly.

Essentially, all we want to do is to rewrite the scheme (from https to http), domain name and the TLD


Issue Links

CDN For Joomla product page
Toggle State Changes

Activity


btasker changed status from 'Open' to 'In Progress'
Adding the additional config values is straightforward enough
I'm only using one static domain, so only need to make a change in one place.
# diff -u cdnforjoomla.xml.org cdnforjoomla.xml
--- cdnforjoomla.xml.org        2015-05-19 15:37:08.957712726 +0100
+++ cdnforjoomla.xml    2015-05-19 15:36:37.692710748 +0100
@@ -34,6 +34,9 @@
                                <field name="@block_cdn_1_a" type="nn_block" start="1" />
                                <field name="root" type="text" size="60" default="/" label="CDN_SITE_ROOT" description="CDN_SITE_ROOT_DESC" />
                                <field name="cdn" type="text" size="60" default="" label="CDN_DOMAIN" description="CDN_DOMAINS_DESC" />
+                               <field name="onion" type="text" size="60" default="" label="Onion Domain" />
+                               <field name="onion_header" type="text" size="60" default="" label="Onion Header" description="If this header is present, URLs will be translated to the Onion domain rather than the CDN domain (HTTPS will also be disabled in the output URL)" />
+
                                <field name="enable_https" type="radio" class="btn-group" default="0" label="CDN_ENABLE_HTTPS" description="CDN_ENABLE_HTTPS_DESC">
                                        <option value="0">JNO</option>
                                        <option value="1">JYES</option>

Just need to identify the best place to drop it into the helper now.
Given that's where most of the process happens, this seemed like the logical place
# diff -u helper.php.org helper.php
--- helper.php.org      2015-05-19 15:39:01.105718443 +0100
+++ helper.php  2015-05-19 15:51:52.960723647 +0100
@@ -132,7 +132,17 @@
                }
                $params->enable_versioning = $this->params->{'enable_versioning' . $setid};
 
-               $params->cdn = preg_replace('#/$#', '', $this->params->{'cdn' . $setid});
+
+               $onion_header=strtoupper(str_replace("-","_",$this->params->{'onion_header'}));
+
+               if (!empty($this->params->{'onion'}) && isset($_SERVER['HTTP_'.$onion_header]) && $_SERVER['HTTP_'.$onion_header] == ':true'){
+                       $params->cdn = preg_replace('#/$#', '', $this->params->{'onion'});
+                       $params->protocol = 'http://';
+               }else{
+                       $params->cdn = preg_replace('#/$#', '', $this->params->{'cdn' . $setid});
+               }
+
+#                $params->cdn = preg_replace('#/$#', '', $this->params->{'cdn' . $setid});
                $params->ignorefiles = explode(',', str_replace(array('\n', ' '), array(',', ''), $this->params->{'ignorefiles' . $setid}));
 
                $root = preg_replace(array('#^/#', '#/$#'), '', $this->params->{'root' . $setid}) . '/';

Tested with GET - the URL now rewrites correctly depending on whether or not that header is present.
btasker changed status from 'In Progress' to 'Resolved'
btasker added 'Done' to resolution
btasker changed status from 'Resolved' to 'Closed'
btasker removed 'Done' from resolution
btasker changed status from 'Closed' to 'Reopened'
btasker changed status from 'Reopened' to 'Resolved'
btasker added 'Done' to resolution
btasker changed status from 'Resolved' to 'Closed'