Commit 663835ed authored by Benjamin Neff's avatar Benjamin Neff Committed by Jonne Haß
Browse files

remove old webfinger/hcard code

closes #6310
parent d28e03f0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
* Extract StatusMessageService from StatusMessagesController [#6280](https://github.com/diaspora/diaspora/pull/6280)
* Refactor HomeController#toggle\_mobile [#6260](https://github.com/diaspora/diaspora/pull/6260)
* Extract CommentService from CommentsController [#6307](https://github.com/diaspora/diaspora/pull/6307)
* Extract user/profile discovery into the diaspora\_federation-rails gem [#6310](https://github.com/diaspora/diaspora/pull/6310)

## Bug fixes
* Fix indentation and a link title on the default home page [#6212](https://github.com/diaspora/diaspora/pull/6212)
+0 −26
Original line number Diff line number Diff line
@@ -265,32 +265,6 @@ class Person < ActiveRecord::Base
    where(guid: guid, closed_account: false).where.not(owner: nil).take
  end

  def self.create_from_webfinger(profile, hcard)
    return nil if profile.nil? || !profile.valid_diaspora_profile?
    new_person = Person.new
    new_person.serialized_public_key = profile.public_key
    new_person.guid = profile.guid
    new_person.diaspora_handle = profile.account
    new_person.url = profile.seed_location

    #hcard_profile = HCard.find profile.hcard.first[:href]
    ::Logging::Logger[self].info "event=webfinger_marshal valid=#{new_person.valid?} " \
                                 "target=#{new_person.diaspora_handle}"
    new_person.assign_new_profile_from_hcard(hcard)
    new_person.save!
    new_person.profile.save!
    new_person
  end

  def assign_new_profile_from_hcard(hcard)
    self.profile = Profile.new(:first_name => hcard[:given_name],
                              :last_name  => hcard[:family_name],
                              :image_url  => hcard[:photo],
                              :image_url_medium  => hcard[:photo_medium],
                              :image_url_small  => hcard[:photo_small],
                              :searchable => hcard[:searchable])
  end

  def remote?
    owner_id.nil?
  end
+0 −3
Original line number Diff line number Diff line
@@ -14,13 +14,10 @@ require 'diaspora'
require 'direction_detector'
require 'email_inviter'
require 'evil_query'
require 'h_card'
require 'hydra_wrapper'
require 'postzord'
require 'publisher'
require 'pubsubhubbub'
require 'salmon'
require 'stream'
require 'webfinger'
require 'webfinger_profile'
require 'account_deleter'

lib/h_card.rb

deleted100644 → 0
+0 −21
Original line number Diff line number Diff line
#   Copyright (c) 2010-2011, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

module HCard
  def self.parse(doc)
    {
      given_name:   doc.css(".given_name").text,
      family_name:  doc.css(".family_name").text,
      url:          doc.css("#pod_location").text,
      photo:        doc.css(".entity_photo .photo[src]").attribute("src").text,
      photo_small:  doc.css(".entity_photo_small .photo[src]").attribute("src").text,
      photo_medium: doc.css(".entity_photo_medium .photo[src]").attribute("src").text,
      searchable:   doc.css(".searchable").text == "true"
    }
  end

  def self.build(raw_hcard)
    parse Nokogiri::HTML(raw_hcard)
  end
end

lib/webfinger.rb

deleted100644 → 0
+0 −123
Original line number Diff line number Diff line
#   Copyright (c) 2010-2012, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class Webfinger
  include Diaspora::Logging

  attr_accessor :host_meta_xrd, :webfinger_profile_xrd,
                :webfinger_profile, :hcard, :hcard_xrd, :person,
                :account, :ssl

  def initialize(account)
    self.account = account
    self.ssl = true
  end


  def fetch
    return person if existing_person_with_profile?
    create_or_update_person_from_webfinger_profile!
  end

  def self.in_background(account, opts={})
    Workers::FetchWebfinger.perform_async(account)
  end

  #everything below should be private I guess
  def account=(str)
    @account = str.strip.gsub('acct:','').to_s.downcase
  end

  def get(url)
    logger.info "Getting: #{url} for #{account}"
    begin
      res = Faraday.get(url)
      unless res.success?
        raise "Failed to fetch #{url}: #{res.status}"
      end
      res.body
    rescue OpenSSL::SSL::SSLError => e
      logger.error "Failed to fetch #{url}: SSL setup invalid"
      raise e
    rescue => e
      logger.error "Failed to fetch: #{url} for #{account}; #{e.message}"
      raise e
    end
  end

  def existing_person_with_profile?
    cached_person.present? && cached_person.profile.present?
  end

  def cached_person
    self.person ||= Person.by_account_identifier(account)
  end

  def create_or_update_person_from_webfinger_profile!
    logger.info "webfingering #{account}, it is not known or needs updating"
    if person #update my profile please
      person.assign_new_profile_from_hcard(self.hcard)
    else
      person = make_person_from_webfinger
    end
    logger.info "successfully webfingered #{@account}" if person
    person
  end

  #this tries the xrl url with https first, then falls back to http
  def host_meta_xrd
    begin
      get(host_meta_url)
    rescue => e
      if self.ssl
        self.ssl = false
        retry
      else
        raise "there was an error getting the xrd from account #{@account}: #{e.message}"
      end
    end
  end


  def hcard
    @hcard ||= HCard.build(hcard_xrd)
  end

  def webfinger_profile
    @webfinger_profile ||= WebfingerProfile.new(account, webfinger_profile_xrd)
  end

  def hcard_url
    self.webfinger_profile.hcard
  end

  def webfinger_profile_url
    doc = Nokogiri::XML(self.host_meta_xrd)
    return nil if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0"
    swizzle doc.search('Link').find{|x| x['rel']=='lrdd'}['template']
  end

  def webfinger_profile_xrd
    @webfinger_profile_xrd ||= get(webfinger_profile_url)
    logger.warn "#{@account} doesn't exists anymore" if @webfinger_profile_xrd == false
    @webfinger_profile_xrd
  end

  def hcard_xrd
    @hcard_xrd ||= get(hcard_url)
  end

  def make_person_from_webfinger
    Person.create_from_webfinger(webfinger_profile, hcard) unless webfinger_profile_xrd == false
  end

  def host_meta_url
    domain = account.split('@')[1]
    "http#{'s' if self.ssl}://#{domain}/.well-known/host-meta"
  end

  def swizzle(template)
    template.gsub('{uri}', account)
  end
end
Loading