From 3e7d6e4b04bd8a4fd903a08ec737fb5ecd7ce176 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Sat, 22 Jul 2017 12:34:48 +0530 Subject: [PATCH 1/9] route to conference#show for custom domain --- app/controllers/conferences_controller.rb | 9 ++++++++- config/initializers/domain_constraint.rb | 6 ++++++ config/routes.rb | 4 ++++ .../20170721184810_add_custom_domain_to_conferences.rb | 5 +++++ db/schema.rb | 5 +++-- 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 config/initializers/domain_constraint.rb create mode 100644 db/migrate/20170721184810_add_custom_domain_to_conferences.rb diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 53e5bd6d..15a59a0c 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -9,10 +9,17 @@ class ConferencesController < ApplicationController @antiquated = @conferences - @current end - def show; end + def show + # have to change "localhost" to ENV['OSEM_HOSTNAME'] in production + check_custom_domain if request.host != 'localhost' + end private + def check_custom_domain + @conference = @conference.custom_domain.present? ? Conference.find_by(custom_domain: request.domain) : @conference + end + def respond_to_options respond_to do |format| format.html { head :ok } diff --git a/config/initializers/domain_constraint.rb b/config/initializers/domain_constraint.rb new file mode 100644 index 00000000..67e19a75 --- /dev/null +++ b/config/initializers/domain_constraint.rb @@ -0,0 +1,6 @@ +class DomainConstraint + def self.matches?(request) + @domains = Conference.pluck(:custom_domain).compact + @domains.include?(request.domain) + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5a17d314..381e55ee 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,9 @@ Osem::Application.routes.draw do + constraints DomainConstraint do + get '/', to: 'conferences#show' + end + if ENV['OSEM_ICHAIN_ENABLED'] == 'true' devise_for :users, controllers: { registrations: :registrations } else diff --git a/db/migrate/20170721184810_add_custom_domain_to_conferences.rb b/db/migrate/20170721184810_add_custom_domain_to_conferences.rb new file mode 100644 index 00000000..d5aef4fd --- /dev/null +++ b/db/migrate/20170721184810_add_custom_domain_to_conferences.rb @@ -0,0 +1,5 @@ +class AddCustomDomainToConferences < ActiveRecord::Migration + def change + add_column :conferences, :custom_domain, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index d49dfa03..797c1930 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,10 +11,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170721001700) do +ActiveRecord::Schema.define(version: 20170721184810) do create_table "ahoy_events", force: :cascade do |t| - t.integer "visit_id" + t.uuid "visit_id", limit: 16 t.integer "user_id" t.string "name" t.text "properties" @@ -127,6 +127,7 @@ ActiveRecord::Schema.define(version: 20170721001700) do t.integer "end_hour", default: 20 t.integer "organization_id" t.integer "ticket_layout", default: 0 + t.string "custom_domain" end add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id" From 19d4abb0c103055f5b158cbeef75ea9ab21564c2 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 25 Jul 2017 07:42:50 +0530 Subject: [PATCH 2/9] fix access denied error for program in custom domains --- app/controllers/conferences_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 15a59a0c..6e5dd5dd 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -2,7 +2,6 @@ class ConferencesController < ApplicationController protect_from_forgery with: :null_session before_action :respond_to_options load_and_authorize_resource find_by: :short_title - load_resource :program, through: :conference, singleton: true, except: :index def index @current = Conference.where('end_date >= ?', Date.current).reorder(start_date: :asc) @@ -10,14 +9,15 @@ class ConferencesController < ApplicationController end def show - # have to change "localhost" to ENV['OSEM_HOSTNAME'] in production + # have to change "localhost" to ENV['OSEM_HOSTNAME'] in production check_custom_domain if request.host != 'localhost' + @program = @conference.program end private def check_custom_domain - @conference = @conference.custom_domain.present? ? Conference.find_by(custom_domain: request.domain) : @conference + @conference = @conference.nil? ? Conference.find_by(custom_domain: request.domain) : @conference end def respond_to_options From e6f6a00d43bc015cef590039a308d2509c4ebd22 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 26 Jul 2017 09:04:07 +0530 Subject: [PATCH 3/9] controller tests for custom domain --- spec/controllers/conferences_controller_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/controllers/conferences_controller_spec.rb b/spec/controllers/conferences_controller_spec.rb index 6479eb34..dffae77a 100644 --- a/spec/controllers/conferences_controller_spec.rb +++ b/spec/controllers/conferences_controller_spec.rb @@ -23,6 +23,15 @@ describe ConferencesController do get :show, id: conference.short_title expect(response).to render_template :show end + + it 'assigns correct conference from a custom domain' do + conference.update_attribute(:custom_domain, 'lvh.me') + @request.host = 'lvh.me' + + get :show + expect(response).to render_template :show + expect(assigns(:conference)).to eq conference + end end end From ec435b65030e6dbd9a6f86baaa418dba87ae5a33 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Wed, 2 Aug 2017 20:16:50 +0530 Subject: [PATCH 4/9] refactored DomainConstraint and conference_controller_spec use params id instead of OSEM_HOSTNAME to load conference --- app/controllers/conferences_controller.rb | 14 +++++++++----- config/initializers/domain_constraint.rb | 6 +++--- spec/controllers/conferences_controller_spec.rb | 7 ++++++- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 6e5dd5dd..f141529d 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -1,7 +1,7 @@ class ConferencesController < ApplicationController protect_from_forgery with: :null_session before_action :respond_to_options - load_and_authorize_resource find_by: :short_title + load_and_authorize_resource find_by: :short_title, except: :show def index @current = Conference.where('end_date >= ?', Date.current).reorder(start_date: :asc) @@ -9,15 +9,19 @@ class ConferencesController < ApplicationController end def show - # have to change "localhost" to ENV['OSEM_HOSTNAME'] in production - check_custom_domain if request.host != 'localhost' + @conference = if params[:id] + Conference.find_by_short_title(params[:id]) + else + load_conference_by_domain + end + authorize! :show, @conference @program = @conference.program end private - def check_custom_domain - @conference = @conference.nil? ? Conference.find_by(custom_domain: request.domain) : @conference + def load_conference_by_domain + Conference.find_by(custom_domain: request.domain) end def respond_to_options diff --git a/config/initializers/domain_constraint.rb b/config/initializers/domain_constraint.rb index 67e19a75..5b35e5c7 100644 --- a/config/initializers/domain_constraint.rb +++ b/config/initializers/domain_constraint.rb @@ -1,6 +1,6 @@ class DomainConstraint def self.matches?(request) - @domains = Conference.pluck(:custom_domain).compact - @domains.include?(request.domain) + domains = Conference.where.not(custom_domain: nil).pluck(:custom_domain) + domains.include?(request.domain) end -end \ No newline at end of file +end diff --git a/spec/controllers/conferences_controller_spec.rb b/spec/controllers/conferences_controller_spec.rb index dffae77a..cdbebf9f 100644 --- a/spec/controllers/conferences_controller_spec.rb +++ b/spec/controllers/conferences_controller_spec.rb @@ -23,12 +23,17 @@ describe ConferencesController do get :show, id: conference.short_title expect(response).to render_template :show end + end - it 'assigns correct conference from a custom domain' do + context 'accessing conference via custom domain' do + before do conference.update_attribute(:custom_domain, 'lvh.me') @request.host = 'lvh.me' + end + it 'assigns correct conference' do get :show + expect(response).to render_template :show expect(assigns(:conference)).to eq conference end From 364adffdab2f266bb1802b228fb0911e7e467064 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Thu, 3 Aug 2017 00:07:38 +0530 Subject: [PATCH 5/9] added show page for custom domain --- .../admin/conferences_controller.rb | 2 + .../admin/conferences/custom_domain.html.haml | 76 +++++++++++++++++++ app/views/layouts/_admin_sidebar.html.haml | 5 ++ config/routes.rb | 3 + 4 files changed, 86 insertions(+) create mode 100644 app/views/admin/conferences/custom_domain.html.haml diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 6716a253..3c900a45 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -4,6 +4,8 @@ module Admin load_resource :program, through: :conference, singleton: true, except: :index load_resource :user, only: [:remove_user] + def cusrom_domain; end + def index # Redirect to new form if there is no conference if Conference.count == 0 diff --git a/app/views/admin/conferences/custom_domain.html.haml b/app/views/admin/conferences/custom_domain.html.haml new file mode 100644 index 00000000..7eb9d85a --- /dev/null +++ b/app/views/admin/conferences/custom_domain.html.haml @@ -0,0 +1,76 @@ +.row + .col-md-12 + %h1 + Custom domain + %p.text-muted + Point your own domain to #{@conference.title} +%hr +.row + .col-md-12 + %table.table + %thead + %th Domain Name + %th Correctly points to #{@conference.short_title} + %th Actions + %tbody + %tr + %td + = @conference.custom_domain + %td + = "" + %td + .btn-group + = link_to 'Edit', edit_admin_conference_path(@conference), + method: :get, class: 'btn btn-primary' + = link_to 'Delete', admin_conference_path(@conference), + method: :delete, class: 'btn btn-danger' +.row + .col-md-9.text-right + = link_to '#status-help', class: 'btn btn-default', "data-toggle"=>"collapse" do + Help? +.row + .col-md-12 + .collapse#status-help + %h2 + Instructions to add your own domain + %hr + %p + When you created the conference, the conference splash page is available in the following domain: + %strong + osem.io/conferences/#{@conference.short_title} + %p + However, we also provide support for hosting conferences on your own domain. + + Terms to get familiar with: + %p + %strong + Domain registrar: + Domain registrar is just another term used for providers who work on reserving domain names. + %p + %strong + CNAME: + A Canonical Name record is a resource used which defines that your domain name is an alias for another domain name. + %p + To add your own domain you can follow these + %i + three + steps: + %ol + %li + Pick a domain you want to host your conference on from a domain registrar or register it with a domain registrar. + %li + Add your own domain name to OSEM ( link to conference/custom_domain#create ) and select the conference it should belong to. + %li + The last step is adding a CNAME record in your registrar’s DNS Settings. Different registrars have different ways of adding a CNAME record. The following guides would help you setup a CNAME record depending upon the registrar of your domain. If it doesn’t, you probably should get in touch with your domain registrar and ask him how to register a CNAME record in their platform. + %ul + %li + = link_to 'GoDaddy', 'https://in.godaddy.com/help/add-a-cname-record-19236' + %li + = link_to 'Namecheap', 'https://www.namecheap.com/support/knowledgebase/article.aspx/9646/2237/how-can-i-set-up-a-cname-record-for-my-domain' + %li + = link_to 'BlueHost', 'https://my.bluehost.com/cgi/help/cname#creating_a_cname' + %li + = link_to '12-reg.co.uk', 'https://www.123-reg.co.uk/support/answers/Domains/Domain-Configuration/how-do-i-set-up-a-cname-record-on-my-domain-name-1198/' + + + diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index 1c7bac9a..a4f857fb 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -27,6 +27,11 @@ = link_to(admin_conference_path(@conference.short_title)) do %span.fa.fa-tachometer Dashboard + - if can? :edit, @conference + %li + = link_to(custom_domain_admin_conference_path(@conference.short_title)) do + %span.fa.fa-link + Custom domain - if can? :show, @conference %li{class: "#{active_nav_li(edit_admin_conference_path(@conference.short_title))}"} - if can? :edit, @conference diff --git a/config/routes.rb b/config/routes.rb index 381e55ee..380d9d43 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -32,6 +32,9 @@ Osem::Application.routes.draw do end resources :comments, only: [:index] resources :conferences do + member do + get :custom_domain + end resource :contact, except: [:index, :new, :create, :show, :destroy] resources :schedules, only: [:index, :create, :show, :update, :destroy] resources :event_schedules, only: [:create, :update, :destroy] From 52cdb41618b12e02b1f2e2f5938be62dca084978 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Thu, 3 Aug 2017 11:15:19 +0530 Subject: [PATCH 6/9] added feature test and permissions for custom_domain --- app/controllers/admin/conferences_controller.rb | 2 +- app/models/admin_ability.rb | 2 +- spec/features/conference_spec.rb | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 3c900a45..c4239394 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -4,7 +4,7 @@ module Admin load_resource :program, through: :conference, singleton: true, except: :index load_resource :user, only: [:remove_user] - def cusrom_domain; end + def custom_domain; end def index # Redirect to new form if there is no conference diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index 4244d049..52bc6a9d 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -110,7 +110,7 @@ class AdminAbility track_ids = Track.joins(:program).where('programs.conference_id IN (?)', conf_ids).pluck(:id) can :manage, Resource, conference_id: conf_ids - can [:read, :update, :destroy], Conference, id: conf_ids + can [:read, :update, :destroy, :custom_domin], Conference, id: conf_ids can :manage, Splashpage, conference_id: conf_ids can :manage, Contact, conference_id: conf_ids can :manage, EmailSettings, conference_id: conf_ids diff --git a/spec/features/conference_spec.rb b/spec/features/conference_spec.rb index d17ce5fc..4c0f0fd4 100644 --- a/spec/features/conference_spec.rb +++ b/spec/features/conference_spec.rb @@ -68,6 +68,15 @@ feature Conference do expect(conference.short_title).to eq('NewCon') expect(Conference.count).to eq(expected_count) end + + scenario 'show custom domain of a conference', feature: true, js: true do + conference = create(:conference, custom_domain: 'mydomain.conf') + sign_in user + + visit custom_domain_admin_conference_path(conference.short_title) + + expect(page).to have_text('mydomain.conf') + end end describe 'admin' do From a612c2e5ea505ffd1313b88e49dc484a14d48006 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Sat, 5 Aug 2017 01:53:59 +0530 Subject: [PATCH 7/9] added ability to attach a custom domain --- .../admin/conferences_controller.rb | 15 ++++++- .../attach_custom_domain.html.haml | 41 +++++++++++++++++++ .../admin/conferences/custom_domain.html.haml | 9 ++-- config/routes.rb | 2 + .../admin/conferences_controller_spec.rb | 9 ++++ 5 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 app/views/admin/conferences/attach_custom_domain.html.haml diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index c4239394..65def838 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -6,6 +6,19 @@ module Admin def custom_domain; end + def attach_custom_domain; end + + def update_domain + @conference.assign_attributes(conference_params) + if @conference.save + redirect_to custom_domain_admin_conference_path(id: @conference.short_title), + notice: 'Added new domain name to conference. This does not mean that the new domain should work. Please make sure you follow step 2 to point your domain to this hosted version' + else + redirect_to custom_domain_admin_conference_path(id: @conference.short_title), + notice: 'Failed to add the new domain as custom domain to the conference' + end + end + def index # Redirect to new form if there is no conference if Conference.count == 0 @@ -213,7 +226,7 @@ module Admin :vpositions_attributes, :use_volunteers, :color, :sponsorship_levels_attributes, :sponsors_attributes, :targets, :targets_attributes, - :campaigns, :campaigns_attributes, :registration_limit, :organization_id, :ticket_layout) + :campaigns, :campaigns_attributes, :registration_limit, :organization_id, :ticket_layout, :custom_domain) end end end diff --git a/app/views/admin/conferences/attach_custom_domain.html.haml b/app/views/admin/conferences/attach_custom_domain.html.haml new file mode 100644 index 00000000..42d91bbc --- /dev/null +++ b/app/views/admin/conferences/attach_custom_domain.html.haml @@ -0,0 +1,41 @@ +.row + .col-md-12 + %h1 + Custom Domain + %p.text-muted + Point your own domain to #{@conference.title} +%hr +.row + .col-md-12 + %h2 + Step 1: + %strong + Unfortunately, we can't do this for you and you have to perform this step with the help your domain registrar! + %p + Pick a domain you want to host your conference on from a domain registrar or register it with a domain registrar. + %h2 + Step 2: + %p + Enter your existing domain in the field below to point the domain to your conference splashpage. + = semantic_form_for(@conference, url: update_domain_admin_conference_path(@conference.short_title)) do |f| + = f.input :custom_domain, label: false + = f.action :submit, button_html: { class: 'btn btn-primary', value: 'Attach this domain' } + %h2 + Step 3: + %strong + Unfortunately, we can't do this for you and you have to perform this step with the help your domain registrar! + %p + The last step is adding a CNAME record in your registrar’s DNS Settings. Different registrars have different ways of adding a CNAME record. The following guides would help you setup a CNAME record depending upon the registrar of your domain. If it doesn’t, you probably should get in touch with your domain registrar and ask him how to register a CNAME record in their platform. + %ul + %li + = link_to 'GoDaddy', 'https://in.godaddy.com/help/add-a-cname-record-19236' + %li + = link_to 'Namecheap', 'https://www.namecheap.com/support/knowledgebase/article.aspx/9646/2237/how-can-i-set-up-a-cname-record-for-my-domain' + %li + = link_to 'BlueHost', 'https://my.bluehost.com/cgi/help/cname#creating_a_cname' + %li + = link_to '12-reg.co.uk', 'https://www.123-reg.co.uk/support/answers/Domains/Domain-Configuration/how-do-i-set-up-a-cname-record-on-my-domain-name-1198/' + %li + = link_to '1&1', 'https://help.1and1.com/domains-c36931/manage-domains-c79822/dns-c37586/enter-a-cname-for-your-subdomain-a643600.html' + .well.well-lg + It might take upto 24-48 hours depending upon your registrar to update your DNS Settings. diff --git a/app/views/admin/conferences/custom_domain.html.haml b/app/views/admin/conferences/custom_domain.html.haml index 7eb9d85a..17316550 100644 --- a/app/views/admin/conferences/custom_domain.html.haml +++ b/app/views/admin/conferences/custom_domain.html.haml @@ -20,9 +20,9 @@ = "" %td .btn-group - = link_to 'Edit', edit_admin_conference_path(@conference), + = link_to 'Edit', attach_custom_domain_admin_conference_path(@conference.short_title), method: :get, class: 'btn btn-primary' - = link_to 'Delete', admin_conference_path(@conference), + = link_to 'Delete', admin_conference_path(@conference.short_title), method: :delete, class: 'btn btn-danger' .row .col-md-9.text-right @@ -71,6 +71,5 @@ = link_to 'BlueHost', 'https://my.bluehost.com/cgi/help/cname#creating_a_cname' %li = link_to '12-reg.co.uk', 'https://www.123-reg.co.uk/support/answers/Domains/Domain-Configuration/how-do-i-set-up-a-cname-record-on-my-domain-name-1198/' - - - + %li + = link_to '1&1', 'https://help.1and1.com/domains-c36931/manage-domains-c79822/dns-c37586/enter-a-cname-for-your-subdomain-a643600.html' diff --git a/config/routes.rb b/config/routes.rb index 380d9d43..eca3f968 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -34,6 +34,8 @@ Osem::Application.routes.draw do resources :conferences do member do get :custom_domain + get :attach_custom_domain + patch :update_domain end resource :contact, except: [:index, :new, :create, :show, :destroy] resources :schedules, only: [:index, :create, :show, :update, :destroy] diff --git a/spec/controllers/admin/conferences_controller_spec.rb b/spec/controllers/admin/conferences_controller_spec.rb index 009e40ba..9019f250 100644 --- a/spec/controllers/admin/conferences_controller_spec.rb +++ b/spec/controllers/admin/conferences_controller_spec.rb @@ -135,6 +135,15 @@ describe Admin::ConferencesController do end end end + + describe 'GET #custom_domain', blah: true do + it 'render custom domain' do + get :custom_domain, id: conference.short_title + + expect(response).to render_template :custom_domain + expect(response).to be_success + end + end end shared_examples 'access as organization_admin' do From b1624a681298ee085f4d12a4aa16081dbb7545ed Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 8 Aug 2017 22:47:04 +0530 Subject: [PATCH 8/9] introduced ability to auto detect CNAME of custom domain --- .haml-lint_todo.yml | 2 ++ .../admin/conferences_controller.rb | 4 +++- app/models/conference.rb | 22 +++++++++++++++++++ .../attach_custom_domain.html.haml | 6 ++--- .../admin/conferences/custom_domain.html.haml | 15 +++++++++---- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index b42ccb06..21ad67ab 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -31,6 +31,8 @@ linters: - "app/views/admin/conferences/_targets.html.haml" - "app/views/admin/conferences/_todo_list.html.haml" - "app/views/admin/conferences/_top_submitter.html.haml" + - "app/views/admin/conferences/attach_custom_domain.html.haml" + - "app/views/admin/conferences/custom_domain.html.haml" - "app/views/admin/conferences/edit.html.haml" - "app/views/admin/conferences/index.html.haml" - "app/views/admin/conferences/new.html.haml" diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 65def838..ed8e6d02 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -4,7 +4,9 @@ module Admin load_resource :program, through: :conference, singleton: true, except: :index load_resource :user, only: [:remove_user] - def custom_domain; end + def custom_domain + redirect_to attach_custom_domain_admin_conference_path(@conference.short_title) unless @conference.custom_domain.present? + end def attach_custom_domain; end diff --git a/app/models/conference.rb b/app/models/conference.rb index b528d755..484e3a66 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -92,6 +92,28 @@ class Conference < ActiveRecord::Base user.present? && registrations.where(user_id: user.id).count > 0 end + ## + # Checks if domain correctly points to the hosted version + # This feature is enabled only if ENV['OSEM_HOSTNAME'] is present + # + # ====Returns + # * +true+ -> If the custom domain has a CNAME record for the hosted version + # * +false+ -> If the custom domain does not have a CNAME record for the hosted version + def check_custom_domain + require 'resolv' + + unless ENV['OSEM_HOSTNAME'].nil? + cname_record = Resolv::DNS.new.getresources(custom_domain, Resolv::DNS::Resource::IN::CNAME) + if cname_record.present? + return ENV['OSEM_HOSTNAME'] == Resolv::DNS.new.getresources(custom_domain, Resolv::DNS::Resource::IN::CNAME).first.name.to_s + else + return false + end + end + + '--feature disabled--' + end + ## # Delete all EventSchedules that are not in the hours range # After the conference has been successfully updated diff --git a/app/views/admin/conferences/attach_custom_domain.html.haml b/app/views/admin/conferences/attach_custom_domain.html.haml index 42d91bbc..9b389c80 100644 --- a/app/views/admin/conferences/attach_custom_domain.html.haml +++ b/app/views/admin/conferences/attach_custom_domain.html.haml @@ -23,13 +23,13 @@ %h2 Step 3: %strong - Unfortunately, we can't do this for you and you have to perform this step with the help your domain registrar! + Unfortunately, we can't do this for you and you have to perform this step with the help your domain registrar! %p The last step is adding a CNAME record in your registrar’s DNS Settings. Different registrars have different ways of adding a CNAME record. The following guides would help you setup a CNAME record depending upon the registrar of your domain. If it doesn’t, you probably should get in touch with your domain registrar and ask him how to register a CNAME record in their platform. %ul - %li + %li = link_to 'GoDaddy', 'https://in.godaddy.com/help/add-a-cname-record-19236' - %li + %li = link_to 'Namecheap', 'https://www.namecheap.com/support/knowledgebase/article.aspx/9646/2237/how-can-i-set-up-a-cname-record-for-my-domain' %li = link_to 'BlueHost', 'https://my.bluehost.com/cgi/help/cname#creating_a_cname' diff --git a/app/views/admin/conferences/custom_domain.html.haml b/app/views/admin/conferences/custom_domain.html.haml index 17316550..55aa4782 100644 --- a/app/views/admin/conferences/custom_domain.html.haml +++ b/app/views/admin/conferences/custom_domain.html.haml @@ -17,7 +17,14 @@ %td = @conference.custom_domain %td - = "" + - ck_domain = @conference.check_custom_domain + - if ck_domain == true + %span.glyphicon.glyphicon-ok + - elsif ck_domain == false + %span.glyphicon.glyphicon-remove + - else + %i + = ck_domain %td .btn-group = link_to 'Edit', attach_custom_domain_admin_conference_path(@conference.short_title), @@ -51,7 +58,7 @@ CNAME: A Canonical Name record is a resource used which defines that your domain name is an alias for another domain name. %p - To add your own domain you can follow these + To add your own domain you can follow these %i three steps: @@ -63,9 +70,9 @@ %li The last step is adding a CNAME record in your registrar’s DNS Settings. Different registrars have different ways of adding a CNAME record. The following guides would help you setup a CNAME record depending upon the registrar of your domain. If it doesn’t, you probably should get in touch with your domain registrar and ask him how to register a CNAME record in their platform. %ul - %li + %li = link_to 'GoDaddy', 'https://in.godaddy.com/help/add-a-cname-record-19236' - %li + %li = link_to 'Namecheap', 'https://www.namecheap.com/support/knowledgebase/article.aspx/9646/2237/how-can-i-set-up-a-cname-record-for-my-domain' %li = link_to 'BlueHost', 'https://my.bluehost.com/cgi/help/cname#creating_a_cname' From d2b5ec1770a42ac589a1e87bf8e4f4994de22b0b Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 8 Aug 2017 22:56:42 +0530 Subject: [PATCH 9/9] fix Hakiri security issue https://hakiri.io/github/openSUSE/osem/master/b1624a681298ee085f4d12a4aa16081dbb7545ed --- app/controllers/conferences_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index f141529d..d9521997 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -10,7 +10,7 @@ class ConferencesController < ApplicationController def show @conference = if params[:id] - Conference.find_by_short_title(params[:id]) + Conference.find_by(short_title: params[:id]) else load_conference_by_domain end