コード例 #1
0
 function __construct()
 {
     global $config;
     global $_DB_DATAOBJECT;
     $sn = new Status_network();
     $sn->_connect();
     $config['db']['table_' . $this->__table] = $sn->_database;
     $this->_connect();
 }
コード例 #2
0
ファイル: allsites.php プロジェクト: bashrc/gnusocial-debian
function print_untagged_sites($tag)
{
    $sn = new Status_network();
    $sn->query('select status_network.nickname ' . 'from status_network ' . 'where not exists ' . '(select tag from status_network_tag ' . 'where site_id = status_network.site_id ' . 'and tag = "' . $tag . '")');
    while ($sn->fetch()) {
        print "{$sn->nickname}\n";
    }
    return;
}
コード例 #3
0
function sphinx_iterate_sites($callback)
{
    if (sphinx_use_network()) {
        // @fixme this should use, like, some kind of config
        Status_network::setupDB('localhost', 'statusnet', 'statuspass', 'statusnet');
        $sn = new Status_network();
        if (!$sn->find()) {
            die("Confused... no sites in status_network table or lookup failed.\n");
        }
        while ($sn->fetch()) {
            $callback($sn);
        }
    } else {
        if (preg_match('!^(mysqli?|pgsql)://(.*?):(.*?)@(.*?)/(.*?)$!', common_config('db', 'database'), $matches)) {
            list(, $dbtype, $dbuser, $dbpass, $dbhost, $dbname) = $matches;
            $sn = (object) array('sitename' => common_config('site', 'name'), 'dbhost' => $dbhost, 'dbuser' => $dbuser, 'dbpass' => $dbpass, 'dbname' => $dbname);
            $callback($sn);
        } else {
            print "Unrecognized database configuration string in config.php\n";
            exit(1);
        }
    }
}
コード例 #4
0
ファイル: Status_network.php プロジェクト: Br3nda/laconica
 static function setupDB($dbhost, $dbuser, $dbpass, $dbname, $servers)
 {
     global $config;
     $config['db']['database_' . $dbname] = "mysqli://{$dbuser}:{$dbpass}@{$dbhost}/{$dbname}";
     $config['db']['ini_' . $dbname] = INSTALLDIR . '/classes/statusnet.ini';
     $config['db']['table_status_network'] = $dbname;
     self::$cache = new Memcache();
     if (is_array($servers)) {
         foreach ($servers as $server) {
             self::$cache->addServer($server);
         }
     } else {
         self::$cache->addServer($servers);
     }
     self::$base = $dbname;
 }
コード例 #5
0
 /**
  * @param string $servername hostname
  * @param string $pathname URL base path
  * @param string $wildcard hostname suffix to match wildcard config
  */
 static function setupSite($servername, $pathname, $wildcard)
 {
     global $config;
     $sn = null;
     // XXX I18N, probably not crucial for hostnames
     // XXX This probably needs a tune up
     $sn = self::getFromHostname($servername, $wildcard);
     if (!empty($sn)) {
         // Redirect to the right URL
         if (!empty($sn->hostname) && empty($_SERVER['HTTPS']) && 0 != strcasecmp($sn->hostname, $servername)) {
             $sn->redirectTo('http://' . $sn->hostname . $_SERVER['REQUEST_URI']);
         } else {
             if (!empty($_SERVER['HTTPS']) && 0 != strcasecmp($sn->hostname, $servername) && 0 != strcasecmp($sn->nickname . '.' . $wildcard, $servername)) {
                 $sn->redirectTo('https://' . $sn->nickname . '.' . $wildcard . $_SERVER['REQUEST_URI']);
             }
         }
         $dbhost = empty($sn->dbhost) ? 'localhost' : $sn->dbhost;
         $dbuser = empty($sn->dbuser) ? $sn->nickname : $sn->dbuser;
         $dbpass = $sn->dbpass;
         $dbname = empty($sn->dbname) ? $sn->nickname : $sn->dbname;
         $config['db']['database'] = "mysqli://{$dbuser}:{$dbpass}@{$dbhost}/{$dbname}";
         $config['site']['name'] = $sn->sitename;
         $config['site']['nickname'] = $sn->nickname;
         self::$wildcard = $wildcard;
         $config['site']['wildcard'] =& self::$wildcard;
         if (!empty($sn->hostname)) {
             $config['site']['server'] = $sn->hostname;
         }
         if (!empty($sn->theme)) {
             $config['site']['theme'] = $sn->theme;
         }
         if (!empty($sn->logo)) {
             $config['site']['logo'] = $sn->logo;
         }
         return $sn;
     } else {
         return null;
     }
 }
コード例 #6
0
ファイル: allsites.php プロジェクト: microcosmx/experiments
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2009, StatusNet, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
# Abort if called from a web server
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$helptext = <<<ENDOFHELP
allsites.php - list all sites configured for multi-site use

returns the nickname of each site configured for multi-site use

ENDOFHELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
$sn = new Status_network();
if ($sn->find()) {
    while ($sn->fetch()) {
        print "{$sn->nickname}\n";
    }
}
コード例 #7
0
ファイル: HubSub.php プロジェクト: Br3nda/StatusNet
 /**
  * Schedule delivery of a 'fat ping' to the subscriber's callback
  * endpoint. If queues are disabled, this will run immediately.
  *
  * @param string $atom well-formed Atom feed
  * @param int $retries optional count of retries if POST fails; defaults to hub_retries from config or 0 if unset
  */
 function distribute($atom, $retries = null)
 {
     if ($retries === null) {
         $retries = intval(common_config('ostatus', 'hub_retries'));
     }
     if (common_config('ostatus', 'local_push_bypass')) {
         // If target is a local site, bypass the web server and drop the
         // item directly into the target's input queue.
         $url = parse_url($this->callback);
         $wildcard = common_config('ostatus', 'local_wildcard');
         $site = Status_network::getFromHostname($url['host'], $wildcard);
         if ($site) {
             if ($this->secret) {
                 $hmac = 'sha1=' . hash_hmac('sha1', $atom, $this->secret);
             } else {
                 $hmac = '';
             }
             // Hack: at the moment we stick the subscription ID in the callback
             // URL so we don't have to look inside the Atom to route the subscription.
             // For now this means we need to extract that from the target URL
             // so we can include it in the data.
             $parts = explode('/', $url['path']);
             $subId = intval(array_pop($parts));
             $data = array('feedsub_id' => $subId, 'post' => $atom, 'hmac' => $hmac);
             common_log(LOG_DEBUG, "Cross-site PuSH bypass enqueueing straight to {$site->nickname} feed {$subId}");
             $qm = QueueManager::get();
             $qm->enqueue($data, 'pushin', $site->nickname);
             return;
         }
     }
     // We dare not clone() as when the clone is discarded it'll
     // destroy the result data for the parent query.
     // @fixme use clone() again when it's safe to copy an
     // individual item from a multi-item query again.
     $sub = HubSub::staticGet($this->topic, $this->callback);
     $data = array('sub' => $sub, 'atom' => $atom, 'retries' => $retries);
     common_log(LOG_INFO, "Queuing PuSH: {$this->topic} to {$this->callback}");
     $qm = QueueManager::get();
     $qm->enqueue($data, 'hubout');
 }
コード例 #8
0
ファイル: gnusocial.php プロジェクト: phpsource/gnu-social
 /**
  * Pull all local sites from status_network table.
  *
  * Behavior undefined if site is not configured via Status_network.
  *
  * @return array of nicknames
  */
 public static function findAllSites()
 {
     $sites = array();
     $sn = new Status_network();
     $sn->find();
     while ($sn->fetch()) {
         $sites[] = $sn->nickname;
     }
     return $sites;
 }
コード例 #9
0
ファイル: settag.php プロジェクト: microcosmx/experiments
$shortoptions = 'd';
$longoptions = array('delete');
$helptext = <<<END_OF_SETTAG_HELP
settag.php [options] <site> <tag>
Set the tag <tag> for site <site>.

With -d, delete the tag.

END_OF_SETTAG_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
if (count($args) < 1) {
    show_help();
    exit(1);
}
$nickname = $args[0];
$sn = Status_network::memGet('nickname', $nickname);
if (empty($sn)) {
    print "No such site ({$nickname}).\n";
    exit(-1);
}
$tags = $sn->getTags();
if (count($args) == 1) {
    print implode(', ', $tags) . "\n";
    exit(0);
}
$tag = $args[1];
$i = array_search($tag, $tags);
if ($i !== false) {
    if (have_option('d', 'delete')) {
        // Delete
        unset($tags[$i]);
コード例 #10
0
    }
}
$reminders = array();
switch ($type) {
    case 'register':
        $reminders[] = $types['register'];
        break;
    case 'invite':
        $reminders[] = $types['invite'];
        break;
    case 'all':
        $reminders = $types;
        break;
}
if (have_option('u', 'universe')) {
    $sn = new Status_network();
    try {
        if ($sn->find()) {
            while ($sn->fetch()) {
                try {
                    $server = $sn->getServerName();
                    StatusNet::init($server);
                    // Different queue manager, maybe!
                    $qm = QueueManager::get();
                    foreach ($reminders as $reminder) {
                        extract($reminder);
                        $qm->enqueue(array($type, $opts), 'siterem');
                        if (!$quiet) {
                            print "Sent pending {$type} reminders for {$server}.\n";
                        }
                    }
コード例 #11
0
ファイル: Status_network.php プロジェクト: himmelex/NTW
 /**
  * @param string $servername hostname
  * @param string $pathname URL base path
  * @param string $wildcard hostname suffix to match wildcard config
  */
 static function setupSite($servername, $pathname, $wildcard)
 {
     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))) {
         // special case for exact match
         if (0 == strcasecmp($servername, $wildcard)) {
             $sn = self::memGet('nickname', '');
         } else {
             $parts = explode('.', $servername);
             $sn = self::memGet('nickname', strtolower($parts[0]));
         }
     } else {
         $sn = self::memGet('hostname', strtolower($servername));
         if (empty($sn)) {
             // Try for a no-www address
             if (0 == strncasecmp($servername, 'www.', 4)) {
                 $sn = self::memGet('hostname', strtolower(substr($servername, 4)));
             }
         }
     }
     if (!empty($sn)) {
         // Redirect to the right URL
         if (!empty($sn->hostname) && empty($_SERVER['HTTPS']) && 0 != strcasecmp($sn->hostname, $servername)) {
             $sn->redirectTo('http://' . $sn->hostname . $_SERVER['REQUEST_URI']);
         } else {
             if (!empty($_SERVER['HTTPS']) && 0 != strcasecmp($sn->hostname, $servername) && 0 != strcasecmp($sn->nickname . '.' . $wildcard, $servername)) {
                 $sn->redirectTo('https://' . $sn->nickname . '.' . $wildcard . $_SERVER['REQUEST_URI']);
             }
         }
         $dbhost = empty($sn->dbhost) ? 'localhost' : $sn->dbhost;
         $dbuser = empty($sn->dbuser) ? $sn->nickname : $sn->dbuser;
         $dbpass = $sn->dbpass;
         $dbname = empty($sn->dbname) ? $sn->nickname : $sn->dbname;
         $config['db']['database'] = "mysqli://{$dbuser}:{$dbpass}@{$dbhost}/{$dbname}";
         $config['site']['name'] = $sn->sitename;
         $config['site']['nickname'] = $sn->nickname;
         self::$wildcard = $wildcard;
         $config['site']['wildcard'] =& self::$wildcard;
         if (!empty($sn->hostname)) {
             $config['site']['server'] = $sn->hostname;
         }
         if (!empty($sn->theme)) {
             $config['site']['theme'] = $sn->theme;
         }
         if (!empty($sn->logo)) {
             $config['site']['logo'] = $sn->logo;
         }
         return $sn;
     } else {
         return null;
     }
 }
コード例 #12
0
ファイル: spawningdaemon.php プロジェクト: Grasia/bolotweet
 /**
  * Reconnect to the database for each child process,
  * or they'll get very confused trying to use the
  * same socket.
  */
 protected function resetDb()
 {
     // @fixme do we need to explicitly open the db too
     // or is this implied?
     global $_DB_DATAOBJECT;
     unset($_DB_DATAOBJECT['CONNECTIONS']);
     // Reconnect main memcached, or threads will stomp on
     // each other and corrupt their requests.
     $cache = Cache::instance();
     if ($cache) {
         $cache->reconnect();
     }
     // Also reconnect memcached for status_network table.
     if (!empty(Status_network::$cache)) {
         Status_network::$cache->close();
         Status_network::$cache = null;
     }
 }
コード例 #13
0
 /**
  * (Re)load runtime configuration for a given site by nickname,
  * triggered by a broadcast to the 'statusnet-control' topic.
  *
  * Configuration changes in database should update, but config
  * files might not.
  *
  * @param array $frame Stomp frame
  * @return bool true to continue; false to stop further processing.
  */
 protected function updateSiteConfig($nickname)
 {
     $sn = Status_network::getKV('nickname', $nickname);
     if ($sn) {
         $this->switchSite($nickname);
         if (!in_array($nickname, $this->sites)) {
             $this->addSite();
         }
         $this->stats('siteupdate');
     } else {
         $this->_log(LOG_ERR, "Ignoring ping for unrecognized new site {$nickname}");
     }
 }
コード例 #14
0
 static function registerEmail($email)
 {
     $domain = self::toDomain($email);
     if (FreeEmail::isFree($domain)) {
         throw new ClientException(_("Use your work email."));
     }
     $sn = self::siteForDomain($domain);
     if (empty($sn)) {
         $installer = new DomainStatusNetworkInstaller($domain);
         // Do the thing
         $installer->main();
         $sn = $installer->getStatusNetwork();
         $config = $installer->getConfig();
         Status_network::$wildcard = $config['WILDCARD'];
     }
     StatusNet::switchSite($sn->nickname);
     $confirm = EmailRegistrationPlugin::registerEmail($email);
     return $confirm;
 }
コード例 #15
0
 function checkSchema()
 {
     $config = $this->getConfig();
     Status_network::$wildcard = $config['WILDCARD'];
     StatusNet::switchSite($this->nickname);
     // We need to initialize the schema_version stuff to make later setup easier
     $schema = array();
     require INSTALLDIR . '/db/core.php';
     $tableDefs = $schema;
     $schema = Schema::get();
     $schemaUpdater = new SchemaUpdater($schema);
     foreach ($tableDefs as $table => $def) {
         $schemaUpdater->register($table, $def);
     }
     $schemaUpdater->checkSchema();
     Event::handle('CheckSchema');
 }
コード例 #16
0
<?php 
/*
 * StatusNet - the distributed open-source microblogging tool
 * Copyright (C) 2008, 2009, StatusNet, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
require_once INSTALLDIR . '/scripts/commandline.inc';
common_log(LOG_INFO, 'Beginning status_network conversion...');
$sn = new Status_network();
$sn->find();
while ($sn->fetch()) {
    try {
        $sn->setTags(explode('|', $sn->tags));
    } catch (Exception $e) {
        common_log(LOG_ERR, $e->getMessage());
    }
}
common_log(LOG_INFO, 'Completed status_network conversion...');