예제 #1
0
 static function ensureProfileURI($uri)
 {
     $oprofile = null;
     // First, try to query it
     $oprofile = Ostatus_profile::staticGet('uri', $uri);
     // If unfound, do discovery stuff
     if (empty($oprofile)) {
         if (preg_match("/^(\\w+)\\:(.*)/", $uri, $match)) {
             $protocol = $match[1];
             switch ($protocol) {
                 case 'http':
                 case 'https':
                     $oprofile = Ostatus_profile::ensureProfileURL($uri);
                     break;
                 case 'acct':
                 case 'mailto':
                     $rest = $match[2];
                     $oprofile = Ostatus_profile::ensureWebfinger($rest);
                     break;
                 default:
                     // TRANS: Server exception.
                     // TRANS: %1$s is a protocol, %2$s is a URI.
                     throw new ServerException(sprintf(_m('Unrecognized URI protocol for profile: %1$s (%2$s).'), $protocol, $uri));
                     break;
             }
         } else {
             // TRANS: Server exception. %s is a URI.
             throw new ServerException(sprintf(_m('No URI protocol for profile: %s.'), $uri));
         }
     }
     return $oprofile;
 }
예제 #2
0
 /**
  * Pull data for a remote profile and check if it's valid.
  * Fills out error UI string in $this->error
  * Fills out $this->oprofile on success.
  *
  * @return boolean
  */
 function pullRemoteProfile()
 {
     $this->profile_uri = $this->trimmed('profile');
     try {
         if (Validate::email($this->profile_uri)) {
             $this->oprofile = Ostatus_profile::ensureWebfinger($this->profile_uri);
         } else {
             if (Validate::uri($this->profile_uri)) {
                 $this->oprofile = Ostatus_profile::ensureProfileURL($this->profile_uri);
             } else {
                 // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
                 // TRANS: and example.net, as these are official standard domain names for use in examples.
                 $this->error = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname.");
                 common_debug('Invalid address format.', __FILE__);
                 return false;
             }
         }
         return true;
     } catch (FeedSubBadURLException $e) {
         // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
         // TRANS: and example.net, as these are official standard domain names for use in examples.
         $this->error = _m('Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname.');
         common_debug('Invalid URL or could not reach server.', __FILE__);
     } catch (FeedSubBadResponseException $e) {
         // TRANS: Error text.
         $this->error = _m('Sorry, we could not reach that feed. Please try that OStatus address again later.');
         common_debug('Cannot read feed; server returned error.', __FILE__);
     } catch (FeedSubEmptyException $e) {
         // TRANS: Error text.
         $this->error = _m('Sorry, we could not reach that feed. Please try that OStatus address again later.');
         common_debug('Cannot read feed; server returned an empty page.', __FILE__);
     } catch (FeedSubBadHTMLException $e) {
         // TRANS: Error text.
         $this->error = _m('Sorry, we could not reach that feed. Please try that OStatus address again later.');
         common_debug('Bad HTML, could not find feed link.', __FILE__);
     } catch (FeedSubNoFeedException $e) {
         // TRANS: Error text.
         $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
         common_debug('Could not find a feed linked from this URL.', __FILE__);
     } catch (FeedSubUnrecognizedTypeException $e) {
         // TRANS: Error text.
         $this->error = _m("Sorry, we could not reach that feed. Please try that OStatus address again later.");
         common_debug('Not a recognized feed type.', __FILE__);
     } catch (Exception $e) {
         // Any new ones we forgot about
         // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
         // TRANS: and example.net, as these are official standard domain names for use in examples.
         $this->error = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname.");
         common_debug(sprintf('Bad feed URL: %s %s', get_class($e), $e->getMessage()), __FILE__);
     }
     return false;
 }
 /**
  * Create the initial admin user account.
  * Side effect: may load portions of StatusNet framework.
  * Side effect: outputs program info
  */
 function registerInitialUser()
 {
     define('STATUSNET', true);
     define('LACONICA', true);
     // compatibility
     require_once INSTALLDIR . '/lib/common.php';
     $data = array('nickname' => $this->adminNick, 'password' => $this->adminPass, 'fullname' => $this->adminNick);
     if ($this->adminEmail) {
         $data['email'] = $this->adminEmail;
     }
     $user = User::register($data);
     if (empty($user)) {
         return false;
     }
     // give initial user carte blanche
     $user->grantRole('owner');
     $user->grantRole('moderator');
     $user->grantRole('administrator');
     // Attempt to do a remote subscribe to update@status.net
     // Will fail if instance is on a private network.
     if ($this->adminUpdates && class_exists('Ostatus_profile')) {
         try {
             $oprofile = Ostatus_profile::ensureProfileURL('http://update.status.net/');
             Subscription::start($user->getProfile(), $oprofile->localProfile());
             $this->updateStatus("Set up subscription to <a href='http://update.status.net/'>update@status.net</a>.");
         } catch (Exception $e) {
             $this->updateStatus("Could not set up subscription to <a href='http://update.status.net/'>update@status.net</a>.", true);
         }
     }
     return true;
 }
예제 #4
0
 static function ensureProfileURI($uri)
 {
     $oprofile = null;
     // First, try to query it
     $oprofile = Ostatus_profile::staticGet('uri', $uri);
     // If unfound, do discovery stuff
     if (empty($oprofile)) {
         if (preg_match("/^(\\w+)\\:(.*)/", $uri, $match)) {
             $protocol = $match[1];
             switch ($protocol) {
                 case 'http':
                 case 'https':
                     $oprofile = Ostatus_profile::ensureProfileURL($uri);
                     break;
                 case 'acct':
                 case 'mailto':
                     $rest = $match[2];
                     $oprofile = Ostatus_profile::ensureWebfinger($rest);
                     break;
                 default:
                     throw new ServerException("Unrecognized URI protocol for profile: {$protocol} ({$uri})");
                     break;
             }
         } else {
             throw new ServerException("No URI protocol for profile: ({$uri})");
         }
     }
     return $oprofile;
 }
예제 #5
0
 protected function pullRemoteProfile($arg)
 {
     $oprofile = null;
     if (preg_match('!^((?:\\w+\\.)*\\w+@(?:\\w+\\.)*\\w+(?:\\w+\\-\\w+)*\\.\\w+)$!', $arg)) {
         // webfinger lookup
         try {
             return Ostatus_profile::ensureWebfinger($arg);
         } catch (Exception $e) {
             common_log(LOG_ERR, 'Webfinger lookup failed for ' . $arg . ': ' . $e->getMessage());
         }
     }
     // Look for profile URLs, with or without scheme:
     $urls = array();
     if (preg_match('!^https?://((?:\\w+\\.)*\\w+(?:\\w+\\-\\w+)*\\.\\w+(?:/\\w+)+)$!', $arg)) {
         $urls[] = $arg;
     }
     if (preg_match('!^((?:\\w+\\.)*\\w+(?:\\w+\\-\\w+)*\\.\\w+(?:/\\w+)+)$!', $arg)) {
         $schemes = array('http', 'https');
         foreach ($schemes as $scheme) {
             $urls[] = "{$scheme}://{$arg}";
         }
     }
     foreach ($urls as $url) {
         try {
             return Ostatus_profile::ensureProfileURL($url);
         } catch (Exception $e) {
             common_log(LOG_ERR, 'Profile lookup failed for ' . $arg . ': ' . $e->getMessage());
         }
     }
     return null;
 }
예제 #6
0
 /**
  *
  * @param string $url
  * @return Profile
  */
 protected function profileForFeed($url)
 {
     try {
         // Maybe we got a web page?
         $oprofile = Ostatus_profile::ensureProfileURL($url);
     } catch (Exception $e) {
         // Direct feed URL?
         $oprofile = Ostatus_profile::ensureFeedURL($url);
     }
     if ($oprofile->isGroup()) {
         // TRANS: Client error displayed when trying to mirror a StatusNet group feed.
         $this->clientError(_m('Cannot mirror a StatusNet group at this time.'));
     }
     $this->oprofile = $oprofile;
     // @todo FIXME: ugly side effect :D
     return $oprofile->localProfile();
 }
function updateOStatus($user)
{
    if (!have_option('q', 'quiet')) {
        echo "{$user->nickname}...";
    }
    $up = $user->getProfile();
    $sp = $user->getSubscriptions();
    $rps = array();
    while ($sp->fetch()) {
        $remote = Remote_profile::staticGet('id', $sp->id);
        if (!empty($remote)) {
            $rps[] = clone $sp;
        }
    }
    if (!have_option('q', 'quiet')) {
        echo count($rps) . "\n";
    }
    foreach ($rps as $rp) {
        try {
            if (!have_option('q', 'quiet')) {
                echo "Checking {$rp->nickname}...";
            }
            $op = Ostatus_profile::ensureProfileURL($rp->profileurl);
            if (empty($op)) {
                echo "can't convert.\n";
                continue;
            } else {
                if (!have_option('q', 'quiet')) {
                    echo "Converting...";
                }
                Subscription::start($up, $op->localProfile());
                Subscription::cancel($up, $rp);
                if (!have_option('q', 'quiet')) {
                    echo "done.\n";
                }
            }
        } catch (Exception $e) {
            if (!have_option('q', 'quiet')) {
                echo "fail.\n";
            }
            common_log(LOG_NOTICE, "Couldn't convert OMB subscription (" . $up->nickname . ", " . $rp->nickname . ") to OStatus: " . $e->getMessage());
            continue;
        }
    }
}
예제 #8
0
 /**
  *
  * @param string $url
  * @return Profile
  */
 protected function profileForFeed($url)
 {
     try {
         // Maybe we got a web page?
         $oprofile = Ostatus_profile::ensureProfileURL($url);
     } catch (Exception $e) {
         // Direct feed URL?
         $oprofile = Ostatus_profile::ensureFeedURL($url);
     }
     if ($oprofile->isGroup()) {
         $this->clientError(_m("Can't mirror a StatusNet group at this time."));
     }
     $this->oprofile = $oprofile;
     // @fixme ugly side effect :D
     return $oprofile->localProfile();
 }
예제 #9
0
 public static function onCheckActivityAuthorship(Activity $activity, Profile &$profile)
 {
     try {
         $oprofile = Ostatus_profile::ensureProfileURL($profile->getUrl());
         $profile = $oprofile->checkAuthorship($activity);
     } catch (Exception $e) {
         common_log(LOG_ERR, 'Could not get a profile or check authorship (' . get_class($e) . ': "' . $e->getMessage() . '") for activity ID: ' . $activity->id);
         $profile = null;
         return false;
     }
     return true;
 }