From c077ad0775218e6aa8660ba97129ad74b5d54773 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 10:45:50 -0700 Subject: [PATCH 01/12] Configurable avatar directory Avatar directory and path are configurable. --- README | 6 ++++++ classes/Avatar.php | 30 +++++++++++++++++++++++++++--- lib/common.php | 4 +++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/README b/README index 8fb4a941cf..5b6b847c89 100644 --- a/README +++ b/README @@ -1008,6 +1008,12 @@ avatar For configuring avatar access. +dir: Directory to look for avatar files and to put them into. + Defaults to avatar subdirectory of install directory; if + you change it, make sure to change path, too. +path: Path to avatars. Defaults to path for avatar subdirectory, + but you can change it if you wish. Note that this will + be included with the avatar server, too. server: If set, defines another server where avatars are stored in the root directory. Note that the 'avatar' subdir still has to be writeable. You'd typically use this to split HTTP requests on diff --git a/classes/Avatar.php b/classes/Avatar.php index db9d78e47f..5e8b315fe6 100644 --- a/classes/Avatar.php +++ b/classes/Avatar.php @@ -55,19 +55,43 @@ class Avatar extends Memcached_DataObject static function path($filename) { - return INSTALLDIR . '/avatar/' . $filename; + $dir = common_config('avatar', 'dir'); + + if ($dir[strlen($dir)-1] != '/') { + $dir .= '/'; + } + + return $dir . $filename; } static function url($filename) { - return common_path('avatar/'.$filename); + $path = common_config('avatar', 'path'); + + if ($path[strlen($path)-1] != '/') { + $path .= '/'; + } + + if ($path[0] != '/') { + $path = '/'.$path; + } + + $server = common_config('avatar', 'server'); + + if (empty($server)) { + $server = common_config('site', 'server'); + } + + // XXX: protocol + + return 'http://'.$server.$path.$filename; } function displayUrl() { $server = common_config('avatar', 'server'); if ($server) { - return 'http://'.$server.'/'.$this->filename; + return Avatar::url($this->filename); } else { return $this->url; } diff --git a/lib/common.php b/lib/common.php index b4e87445e6..ab61c812f5 100644 --- a/lib/common.php +++ b/lib/common.php @@ -108,7 +108,9 @@ $config = 'profile' => array('banned' => array()), 'avatar' => - array('server' => null), + array('server' => null, + 'dir' => INSTALLDIR . '/avatar/', + 'path' => $_path . '/avatar/'), 'public' => array('localonly' => true, 'blacklist' => array(), From d6ff702d7f0937451c8595c7b3cbfb9f2813a07b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 13:34:52 -0700 Subject: [PATCH 02/12] Return network from network setup function Return the network from the network setup function. Also, special-case for when we get a server name the same as the wildcard. --- classes/Status_network.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/classes/Status_network.php b/classes/Status_network.php index d2b942bfb1..96b6d9a05b 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -43,12 +43,19 @@ class Status_network extends DB_DataObject { global $config; + $sn = null; + // XXX I18N, probably not crucial for hostnames // XXX This probably needs a tune up if (0 == strncasecmp(strrev($wildcard), strrev($servername), strlen($wildcard))) { - $parts = explode('.', $servername); - $sn = Status_network::staticGet('nickname', strtolower($parts[0])); + // special case for exact match + if (0 == strncmp($servername, $wildcard)) { + $sn = Status_network::staticGet('nickname', ''); + } else { + $parts = explode('.', $servername); + $sn = Status_network::staticGet('nickname', strtolower($parts[0])); + } } else { $sn = Status_network::staticGet('hostname', strtolower($servername)); } @@ -70,9 +77,9 @@ class Status_network extends DB_DataObject $config['site']['logo'] = $sn->logo; } - return true; + return $sn; } else { - return false; + return null; } } } From 6532f0dff63576c94debe521d1ff8d9f594fe422 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 14:29:25 -0700 Subject: [PATCH 03/12] strncmp -> strcasecmp --- classes/Status_network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Status_network.php b/classes/Status_network.php index 96b6d9a05b..bf05ad61e0 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -50,7 +50,7 @@ class Status_network extends DB_DataObject if (0 == strncasecmp(strrev($wildcard), strrev($servername), strlen($wildcard))) { // special case for exact match - if (0 == strncmp($servername, $wildcard)) { + if (0 == strcasecmp($servername, $wildcard)) { $sn = Status_network::staticGet('nickname', ''); } else { $parts = explode('.', $servername); From 01c03223c2c559deec0191dd7a100e152981e1e2 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 15:13:24 -0700 Subject: [PATCH 04/12] Script to set up new status networks --- scripts/setup.cfg.sample | 11 +++++++++++ scripts/setup_status_network.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 scripts/setup.cfg.sample create mode 100644 scripts/setup_status_network.sh diff --git a/scripts/setup.cfg.sample b/scripts/setup.cfg.sample new file mode 100644 index 0000000000..4194bc146d --- /dev/null +++ b/scripts/setup.cfg.sample @@ -0,0 +1,11 @@ +# CONFIGURATION FILE for setup_status_network.sh + +# Base database name; full name will include nickname + +export DBBASE=_example_net +export USERBASE=_example_net +export ADMIN=root +export ADMINPASS=yourpassword +export SITEDB=example_net_site +export AVATARBASE=/var/www/avatar.example.net + diff --git a/scripts/setup_status_network.sh b/scripts/setup_status_network.sh new file mode 100644 index 0000000000..d80612b940 --- /dev/null +++ b/scripts/setup_status_network.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +source ./setup.cfg + +export nickname=$1 +export sitename=$2 + +export password=`pwgen 20` +export database=$nickname$DBBASE +export username=$nickname$USERBASE + +# Create the db + +mysqladmin -u $ADMIN --password=$ADMINPASS create $database + +for f in laconica.sql sms_carrier.sql foreign_services.sql notice_source.sql; do + mysql -u $ADMIN --password=$ADMINPASS $database < ../db/$f; +done + +mysql -u $ADMIN --password=$ADMINPASS $SITEDB << ENDOFCOMMANDS + +GRANT INSERT,SELECT,UPDATE,DELETE ON $database.* TO '$username'@'localhost' IDENTIFIED BY '$password'; +GRANT INSERT,SELECT,UPDATE,DELETE ON $database.* TO '$username'@'%' IDENTIFIED BY '$password'; +INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created) +VALUES ('$nickname', '$DBHOST', '$username', '$password', '$database', '$sitename', now()); + +ENDOFCOMMANDS + +mkdir $AVATARBASE/$nickname +chmod a+w $AVATARBASE/$nickname From 177e4adf40bd41fc711c91fc6d16729b7f1b5796 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 15:13:49 -0700 Subject: [PATCH 05/12] change mods for setup script --- scripts/setup_status_network.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/setup_status_network.sh diff --git a/scripts/setup_status_network.sh b/scripts/setup_status_network.sh old mode 100644 new mode 100755 From 12cd87cd7b7c207b6f9c30996f0fabb019d6fd76 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 15 Jun 2009 22:50:14 +0000 Subject: [PATCH 06/12] Missing call to getProfile() caused verify_credentials to fail. --- actions/twitapiusers.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/twitapiusers.php b/actions/twitapiusers.php index 13a8746cd0..21a56a9a58 100644 --- a/actions/twitapiusers.php +++ b/actions/twitapiusers.php @@ -58,7 +58,7 @@ class TwitapiusersAction extends TwitterapiAction return; } - $twitter_user = $this->twitter_user_array($profile, true); + $twitter_user = $this->twitter_user_array($user->getProfile(), true); if ($apidata['content-type'] == 'xml') { $this->init_document('xml'); From fd290fc3f9a40a0d3be4e4ffc7d11846bf5295b8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 16:09:40 -0700 Subject: [PATCH 07/12] allow a configured base for cache keys --- README | 7 +++++++ lib/common.php | 1 + lib/util.php | 8 +++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README b/README index 5b6b847c89..57ff72f665 100644 --- a/README +++ b/README @@ -1106,6 +1106,13 @@ database data in memcached . enabled: Set to true to enable. Default false. server: a string with the hostname of the memcached server. Can also be an array of hostnames, if you've got more than one server. +base: memcached uses key-value pairs to store data. We build long, + funny-looking keys to make sure we don't have any conflicts. The + base of the key is usually a simplified version of the site name + (like "Identi.ca" => "identica"), but you can overwrite this if + you need to. You can safely ignore it if you only have one + Laconica site using your memcached server. +port: Port to connect to; defaults to 11211. sphinx ------ diff --git a/lib/common.php b/lib/common.php index ab61c812f5..51204cedea 100644 --- a/lib/common.php +++ b/lib/common.php @@ -152,6 +152,7 @@ $config = 'memcached' => array('enabled' => false, 'server' => 'localhost', + 'base' => null, 'port' => 11211), 'ping' => array('notify' => array()), diff --git a/lib/util.php b/lib/util.php index 49c6ae108e..1d5708bd69 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1322,7 +1322,13 @@ function common_session_token() function common_cache_key($extra) { - return 'laconica:' . common_keyize(common_config('site', 'name')) . ':' . $extra; + $base_key = common_config('memcached', 'base'); + + if (empty($base_key)) { + $base_key = common_keyize(common_config('site', 'name')); + } + + return 'laconica:' . $base_key . ':' . $extra; } function common_keyize($str) From fbed704f3b6a8237e815be9586eb753cc78d20c3 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 16:22:08 -0700 Subject: [PATCH 08/12] don't show create-a-group link if not logged in --- actions/groups.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/actions/groups.php b/actions/groups.php index 26b52a5fcd..b49d80f377 100644 --- a/actions/groups.php +++ b/actions/groups.php @@ -100,11 +100,13 @@ class GroupsAction extends Action function showContent() { - $this->elementStart('p', array('id' => 'new_group')); - $this->element('a', array('href' => common_local_url('newgroup'), - 'class' => 'more'), - _('Create a new group')); - $this->elementEnd('p'); + if (common_logged_in()) { + $this->elementStart('p', array('id' => 'new_group')); + $this->element('a', array('href' => common_local_url('newgroup'), + 'class' => 'more'), + _('Create a new group')); + $this->elementEnd('p'); + } $offset = ($this->page-1) * GROUPS_PER_PAGE; $limit = GROUPS_PER_PAGE + 1; From 587b7a8b2ad0b260cc3159da260a4d439c2a5f0c Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 16:40:53 -0700 Subject: [PATCH 09/12] redirect on non-canonical server name --- classes/Status_network.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/classes/Status_network.php b/classes/Status_network.php index bf05ad61e0..eef27d7653 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -61,6 +61,9 @@ class Status_network extends DB_DataObject } if (!empty($sn)) { + if (!empty($sn->hostname) && 0 != strcasecmp($sn->hostname, $servername)) { + $sn->redirectToHostname(); + } $dbhost = (empty($sn->dbhost)) ? 'localhost' : $sn->dbhost; $dbuser = (empty($sn->dbuser)) ? $sn->nickname : $sn->dbuser; $dbpass = $sn->dbpass; @@ -82,4 +85,29 @@ class Status_network extends DB_DataObject return null; } } + + // Code partially mooked from http://www.richler.de/en/php-redirect/ + // (C) 2006 by Heiko Richler http://www.richler.de/ + // LGPL + + function redirectToHostname() + { + $destination = 'http://'.$this->hostname; + $destination .= $_SERVER['REQUEST_URI']. + $_SERVER['QUERY_STRING']; + + $old = 'http'. + (($_SERVER['HTTPS'] == 'on') ? 'S' : ''). + '://'. + $_SERVER['HTTP_HOST']. + $_SERVER['REQUEST_URI']. + $_SERVER['QUERY_STRING']; + if ($old == $destination) { // this would be a loop! + // error_log(...) ? + return false; + } + + common_redirect($destination, 301); + // shouldn't get here + } } From 2f82a3d44c4fbb0d9c552a2652e341ec882787c1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 16:43:39 -0700 Subject: [PATCH 10/12] forgot some functions aren't available at status time --- classes/Status_network.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/classes/Status_network.php b/classes/Status_network.php index eef27d7653..128721f41b 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -107,7 +107,11 @@ class Status_network extends DB_DataObject return false; } - common_redirect($destination, 301); - // shouldn't get here + header('HTTP/1.1 301 Moved Permanently'); + header("Location: $destination"); + + print "$destination\n"; + + exit; } } From f80966324560d4309b3bb2d6d357719e1e90e6aa Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 16:51:49 -0700 Subject: [PATCH 11/12] a little better query handling in redirect code --- classes/Status_network.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/classes/Status_network.php b/classes/Status_network.php index 128721f41b..03e8f45259 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -93,8 +93,19 @@ class Status_network extends DB_DataObject function redirectToHostname() { $destination = 'http://'.$this->hostname; - $destination .= $_SERVER['REQUEST_URI']. - $_SERVER['QUERY_STRING']; + $destination .= $_SERVER['REQUEST_URI']; + + $args = $_GET; + + if (isset($args['p'])) { + unset($args['p']); + } + + $query = http_build_query($args); + + if (strlen($query) > 0) { + $destination .= '?' . $query; + } $old = 'http'. (($_SERVER['HTTPS'] == 'on') ? 'S' : ''). From 8c24a3bc92484d19ed4ba489d2d7b1172f4b355d Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 15 Jun 2009 16:55:01 -0700 Subject: [PATCH 12/12] a little better query handling in redirect code --- classes/Status_network.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/classes/Status_network.php b/classes/Status_network.php index 03e8f45259..17b6887408 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -95,18 +95,6 @@ class Status_network extends DB_DataObject $destination = 'http://'.$this->hostname; $destination .= $_SERVER['REQUEST_URI']; - $args = $_GET; - - if (isset($args['p'])) { - unset($args['p']); - } - - $query = http_build_query($args); - - if (strlen($query) > 0) { - $destination .= '?' . $query; - } - $old = 'http'. (($_SERVER['HTTPS'] == 'on') ? 'S' : ''). '://'.