Skip to content

Commit

Permalink
fixes #869 - Installation - detect presence of a reverse proxy and wa…
Browse files Browse the repository at this point in the history
…rn if mismatch with $_SERVER['HTTPS']; add 'reverse_proxy' config setting
  • Loading branch information
vipsoft committed Dec 14, 2009
1 parent ab9e2b5 commit 512c240
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
3 changes: 3 additions & 0 deletions config/global.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@
; If set to 1, Piwik uses a single HTTP request per Flash widget to serve both the widget and data
serve_widget_and_data = 1

; If set to 1, Piwik adds a response header to workaround the IE+Flash+HTTPS bug.
reverse_proxy = 0

[Tracker]
; set to 0 if you want to stop tracking the visitors. Useful if you need to stop all the connections on the DB.
record_statistics = 1
Expand Down
7 changes: 4 additions & 3 deletions core/Visualization/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ public function setTitle($text, $css)

public function render()
{
if(Piwik_Url::getCurrentScheme() == 'https')
if(Piwik_Url::getCurrentScheme() == 'https' ||
Zend_Registry::get('config')->General->reverse_proxy)
{
@header("Pragma: ");
@header("Cache-Control: must-revalidate");
@header("Pragma: ");
@header("Cache-Control: must-revalidate");
}
return $this->chart->toPrettyString();
}
Expand Down
2 changes: 2 additions & 0 deletions lang/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,8 @@
'Installation_SystemCheckMailHelp' => 'Feedback and Lost Password messages will not be sent without mail().',
'Installation_SystemCheckError' => 'An error occured - must be fixed before you proceed',
'Installation_SystemCheckWarning' => 'Piwik will work normally but some features may be missing',
'Installation_SystemCheckProtocol' => 'Protocol',
'Installation_SystemCheckProtocolHelp' => 'If you are behind a reverse proxy, add these lines to config/config.ini.php:',
'Installation_Tables' => 'Creating the tables',
'Installation_TablesWithSameNamesFound' => 'Some %s tables in your database %s have the same names as the tables Piwik is trying to create',
'Installation_TablesFound' => 'The following tables have been found in the database',
Expand Down
39 changes: 39 additions & 0 deletions plugins/Installation/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ function generalSetup()
'login' => $form->getSubmitValue('login'),
'password' => md5( $form->getSubmitValue('password') ),
'email' => $form->getSubmitValue('email'),
'salt' => Piwik_Common::generateUniqId(),
);

$this->session->superuser_infos = $superUserInfos;
Expand Down Expand Up @@ -637,9 +638,47 @@ public static function getSystemInformation()

$infos['isWindows'] = substr(PHP_OS, 0, 3) == 'WIN';

$infos['protocol_ok'] = true;
$infos['protocol'] = self::getProtocolInformation();
if(Piwik_Url::getCurrentScheme() == 'http' &&
$infos['protocol'] !== null)
{
$infos['protocol_ok'] = false;
}

return $infos;
}

public static function getProtocolInformation()
{
if(Piwik_Common::getRequestVar('clientProtocol', 'http', 'string') == 'https')
{
return 'https';
}

if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)
{
return 'SERVER_PORT=443';
}

if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https')
{
return 'X-Forwarded-Proto';
}

if(isset($_SERVER['HTTP_X_FORWARDED_SCHEME']) && strtolower($_SERVER['HTTP_X_FORWARDED_SCHEME']) == 'https')
{
return 'X-Forwarded-Scheme';
}

if(isset($_SERVER['HTTP_X_URL_SCHEME']) && strtolower($_SERVER['HTTPS']) == 'HTTP_X_URL_SCHEME')
{
return 'X-Url-Scheme';
}

return null;
}

protected function skipThisStep( $step )
{
if(isset($this->session->skipThisStep[$step])
Expand Down
6 changes: 6 additions & 0 deletions plugins/Installation/templates/systemCheck.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@
{/foreach}
</td>
</tr>
<tr>
<td class="label">{'Installation_SystemCheckProtocol'|translate}</td>
<td>
{if $infos.protocol_ok}{$ok}{else}{$warning} {$infos.protocol}<br /><i>{'Installation_SystemCheckProtocolHelp'|translate}</i><br /><br /><code>[General]</code><br /><code>reverse_proxy = 1</code><br />{/if}
</td>
</tr>
</table>

<p>
Expand Down
11 changes: 11 additions & 0 deletions plugins/Installation/templates/welcome.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@

{'Installation_WelcomeHelp'|translate:$totalNumberOfSteps}

{literal}
<script type="text/javascript">
<!--
$(function() {
if (document.location.protocol === 'https:') {
$('p.nextStep a').attr('href', $('p.nextStep a').attr('href') + '&clientProtocol=https');
}
});
//-->
</script>
{/literal}

0 comments on commit 512c240

Please sign in to comment.