|
SwitchToSSLMode<< Discussions | Cookbook-V1 | Graph Viz >> Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.
GoalForce PmWiki to use an HTTPS (SSL-encrypted HTTP) connection or, conversly, force the connection to use an unencrypted HTTP connection. SolutionFist, if you're impatient, here are lines to put in a local customization file that will cause PmWiki pages to be delivered over an SSL-encrypted connection:
# Force to SSL mode.
$ScriptUrl = str_replace('http:','https:',$ScriptUrl,1);
$PubDirUrl = str_replace('http:','https:',$PubDirUrl,1);
if ($_SERVER['SERVER_PORT'] != 443) {
if (!@$pagename) { header("Location: $ScriptUrl");
} else { Redirect($pagename); }
}
Now for the full explanation. By default, PmWiki will happily deliver pages via SSL (HTTPS). This recipe explains how to force PmWiki to switch to HTTPS (or to HTTP). Switching to SSL mode is done in two steps:
You can specify secure paths for # $ScriptUrl is your preferred URL for accessing wiki pages # $PubDirUrl is the URL for the pub directory. $ScriptUrl = 'https://your/secure/path/to/pmwiki.php'; $PubDirUrl = 'https://your/secure/path/to/pub'; Another way to set a secure path for
# Automatically adjust $ScriptUrl to use HTTPS.
$ScriptUrl = str_replace('http:','https:',$ScriptUrl,1);
$PubDirUrl = str_replace('http:','https:',$PubDirUrl,1);
Once
# Redirect http: request to https: using PmWiki's
# Redirect-to-page function.
# Force to SSL mode.
if ($_SERVER['SERVER_PORT'] != 443) {
if (!@$pagename) { header("Location: $ScriptUrl");
} else { Redirect($pagename); }
}
You can also force pages not to be served via SSL by essentially using the recipe in reverse:
# Force HTTP (non-SSL) mode.
$ScriptUrl = str_replace('https:','http:',$ScriptUrl,1);
$PubDirUrl = str_replace('https:','http:',$PubDirUrl,1);
if ($_SERVER['SERVER_PORT'] != 80) {
if (!@$pagename) { header("Location: $ScriptUrl");
} else { Redirect($pagename); }
}
Q & AQ: How do I use SSL to avoid sending passwords in the clear. A: This was discussed on the pmwiki-users mailing list ( <#> <#> <#> <#> <#> ). You can use HTTPS-only when editing pages or performing other actions where your password wold be sent in the clear.
# Switch to SSL mode when password wold be sent in the clear.
if( $action=='edit'
|| $action=='post'
|| $action=='postattr'
|| $action=='attr'
|| $action=='upload'
|| $action=='loginadmin' )
{
$ScriptUrl = 'https://your/secure/path/to/pmwiki.php';
$PubDirUrl = 'https://your/secure/path/to/pub';
if ($_SERVER['SERVER_PORT'] != 443)
{
//this will copy all GET request parameters, and fix the problem with empty filename on upload page
$url = array();
reset($_GET);
while(list($name,$value) = each($_GET))
if(!empty($value))
$url[$name] = $name."=".urlencode($value);
Redirect($pagename,'$PageUrl?'.implode("&",$url));
}
Q: Why directly specify a secure path rather than using str_replace?
Q: Why not always use SSL?
Discussion(None yet) See Also-- History(None yet) Comments & Bugs(None yet) Contributorspmwiki-2.2.0-beta68 -- Last modified by {{Viliam Simko}}?
|