summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-03-26 15:03:59 -0400
committerEvan Prodromou <evan@controlyourself.ca>2009-03-30 17:12:02 -0400
commite149f3d64b5c0a58b299fb607824a1cd515836a4 (patch)
treeddbbd8953ef55888474a56a8f92e6f14203ebea3 /lib
parent47b89aa2c3a3e07d6dc63cd5be1d558af8ece233 (diff)
Support SSL for some, all, or no pages
Support SSL URLs either for all pages; no pages; or for sensitive pages accepting passwords, like login, registration, API, and others.
Diffstat (limited to 'lib')
-rw-r--r--lib/common.php2
-rw-r--r--lib/util.php31
2 files changed, 28 insertions, 5 deletions
diff --git a/lib/common.php b/lib/common.php
index caad705a4..c2037c3ad 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -87,6 +87,8 @@ $config =
'closed' => false,
'inviteonly' => false,
'private' => false,
+ 'ssl' => 'never',
+ 'sslserver' => null,
'dupelimit' => 60), # default for same person saying the same thing
'syslog' =>
array('appname' => 'laconica', # for syslog
diff --git a/lib/util.php b/lib/util.php
index ef73adc36..fdcae0aca 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -721,25 +721,46 @@ function common_relative_profile($sender, $nickname, $dt=null)
function common_local_url($action, $args=null, $params=null, $fragment=null)
{
+ static $sensitive = array('login', 'register', 'passwordsettings',
+ 'twittersettings', 'finishopenidlogin',
+ 'api');
+
$r = Router::get();
$path = $r->build($action, $args, $params, $fragment);
+ $ssl = in_array($action, $sensitive);
+
if (common_config('site','fancy')) {
- $url = common_path(mb_substr($path, 1));
+ $url = common_path(mb_substr($path, 1), $ssl);
} else {
if (mb_strpos($path, '/index.php') === 0) {
- $url = common_path(mb_substr($path, 1));
+ $url = common_path(mb_substr($path, 1), $ssl);
} else {
- $url = common_path('index.php'.$path);
+ $url = common_path('index.php'.$path, $ssl);
}
}
return $url;
}
-function common_path($relative)
+function common_path($relative, $ssl=false)
{
$pathpart = (common_config('site', 'path')) ? common_config('site', 'path')."/" : '';
- return "http://".common_config('site', 'server').'/'.$pathpart.$relative;
+
+ if (($ssl && (common_config('site', 'ssl') === 'sometimes'))
+ || common_config('site', 'ssl') === 'always') {
+ $proto = 'https';
+ if (is_string(common_config('site', 'sslserver')) &&
+ mb_strlen(common_config('site', 'sslserver')) > 0) {
+ $serverpart = common_config('site', 'sslserver');
+ } else {
+ $serverpart = common_config('site', 'server');
+ }
+ } else {
+ $proto = 'http';
+ $serverpart = common_config('site', 'server');
+ }
+
+ return $proto.'://'.$serverpart.'/'.$pathpart.$relative;
}
function common_date_string($dt)