diff --git a/README.md b/README.md index b857f86..0b5f003 100644 --- a/README.md +++ b/README.md @@ -53,14 +53,31 @@ MariaDB have been tested) database, username, and password and put them in a lobsters$ rake db:schema:load -* Create a `config/initializers/secret_token.rb` file, using a randomly generated key from the output of `rake secret`: +* Create a `config/initializers/secret_token.rb` file, using a randomly +generated key from the output of `rake secret`: Lobsters::Application.config.secret_token = 'your random secret here' -* (Optional, only needed for the search engine) Install Sphinx. Build Sphinx config and start server: +* (Optional, only needed for the search engine) Install Sphinx. Build Sphinx +config and start server: lobsters$ rake thinking_sphinx:rebuild +* Define your site's name and default domain, which are used in various places, +in a `config/initializers/production.rb` or similar file: + + class << Rails.application + def domain + "example.com" + end + + def name + "Example News" + end + end + + Rails.application.routes.default_url_options[:host] = Rails.application.domain + * Create an initial administrator user and at least one tag: lobsters$ rails console @@ -74,11 +91,7 @@ MariaDB have been tested) database, username, and password and put them in a irb(main):006:0> t.tag = "test" irb(main):007:0> t.save -* The default development hostname is defined as `lobsters.localhost:3000`. -You should define this in `/etc/hosts` (or through DNS) to point to -`127.0.0.1`. - * Run the Rails server in development mode. You should be able to login to -`http://lobsters.localhost:3000` with your `test` user: +`http://localhost:3000` with your new `test` user: lobsters$ rails server diff --git a/app/controllers/signup_controller.rb b/app/controllers/signup_controller.rb index 9a67e93..d735696 100644 --- a/app/controllers/signup_controller.rb +++ b/app/controllers/signup_controller.rb @@ -43,9 +43,10 @@ class SignupController < ApplicationController if @new_user.save @invitation.destroy session[:u] = @new_user.session_token - flash[:success] = "Welcome to Lobsters, #{@new_user.username}!" + flash[:success] = "Welcome to #{Rails.application.name}, " << + "#{@new_user.username}!" - Countinual.count!("lobsters.users.created", "+1") + Countinual.count!("#{Rails.application.shortname}.users.created", "+1") return redirect_to "/signup/invite" else diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index d75f1f0..4cb8571 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -20,7 +20,8 @@ class StoriesController < ApplicationController Vote.vote_thusly_on_story_or_comment_for_user_because(1, @story.id, nil, @user.id, nil) - Countinual.count!("lobsters.stories.submitted", "+1") + Countinual.count!("#{Rails.application.shortname}.stories.submitted", + "+1") return redirect_to @story.comments_url diff --git a/app/mailers/email_message.rb b/app/mailers/email_message.rb index 75bb3be..76fa853 100644 --- a/app/mailers/email_message.rb +++ b/app/mailers/email_message.rb @@ -1,12 +1,15 @@ class EmailMessage < ActionMailer::Base - default :from => "nobody@lobste.rs" + default :from => "#{Rails.application.name} " << + "" def notify(message, user) @message = message @user = user - mail(:to => user.email, :from => "Lobsters ", - :subject => "[Lobsters] Private Message from " << - "#{message.author.username}: #{message.subject}") + mail( + :to => user.email, + :subject => "[#{Rails.application.name}] Private Message from " << + "#{message.author.username}: #{message.subject}" + ) end end diff --git a/app/mailers/email_reply.rb b/app/mailers/email_reply.rb index cecb027..5c9869a 100644 --- a/app/mailers/email_reply.rb +++ b/app/mailers/email_reply.rb @@ -1,21 +1,26 @@ class EmailReply < ActionMailer::Base - default :from => "nobody@lobste.rs" + default :from => "#{Rails.application.name} " << + "" def reply(comment, user) @comment = comment @user = user - mail(:to => user.email, :from => "Lobsters ", - :subject => "[Lobsters] Reply from #{comment.user.username} on " << - "#{comment.story.title}") + mail( + :to => user.email, + :subject => "[#{Rails.application.name}] Reply from " << + "#{comment.user.username} on #{comment.story.title}" + ) end def mention(comment, user) @comment = comment @user = user - mail(:to => user.email, :from => "Lobsters ", - :subject => "[Lobsters] Mention from #{comment.user.username} on " << - "#{comment.story.title}") + mail( + :to => user.email, + :subject => "[#{Rails.application.name}] Mention from " << + "#{comment.user.username} on #{comment.story.title}" + ) end end diff --git a/app/mailers/invitation_mailer.rb b/app/mailers/invitation_mailer.rb index 48a30b9..b77662e 100644 --- a/app/mailers/invitation_mailer.rb +++ b/app/mailers/invitation_mailer.rb @@ -1,9 +1,14 @@ class InvitationMailer < ActionMailer::Base + default :from => "#{Rails.application.name} " << + "" + def invitation(invitation) @invitation = invitation - mail(:to => invitation.email, - :from => "Lobsters Invitation ", - subject: "[Lobsters] Welcome to Lobsters") + mail( + :to => invitation.email, + subject: "[#{Rails.application.name}] Welcome to " << + Rails.application.name + ) end end diff --git a/app/mailers/password_reset.rb b/app/mailers/password_reset.rb index b993ed9..5868ec2 100644 --- a/app/mailers/password_reset.rb +++ b/app/mailers/password_reset.rb @@ -1,9 +1,14 @@ class PasswordReset < ActionMailer::Base + default :from => "#{Rails.application.name} " << + "" + def password_reset_link(user, ip) @user = user @ip = ip - mail(:to => user.email, :from => "Lobsters ", - :subject => "[Lobsters] Reset your password") + mail( + :to => user.email, + :subject => "[#{Rails.application.name}] Reset your password" + ) end end diff --git a/app/models/comment.rb b/app/models/comment.rb index d1dcce4..8c3bc71 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -139,8 +139,8 @@ class Comment < ActiveRecord::Base if u.pushover_mentions? && u.pushover_user_key.present? Pushover.push(u.pushover_user_key, u.pushover_device, { - :title => "Lobsters mention by #{self.user.username} on " << - self.story.title, + :title => "#{Rails.application.name} mention by " << + "#{self.user.username} on #{self.story.title}", :message => self.plaintext_comment, :url => self.url, :url_title => "Reply to #{self.user.username}", @@ -164,8 +164,8 @@ class Comment < ActiveRecord::Base if u.pushover_replies? && u.pushover_user_key.present? Pushover.push(u.pushover_user_key, u.pushover_device, { - :title => "Lobsters reply from #{self.user.username} on " << - "#{self.story.title}", + :title => "#{Rails.application.name} reply from " << + "#{self.user.username} on #{self.story.title}", :message => self.plaintext_comment, :url => self.url, :url_title => "Reply to #{self.user.username}", @@ -179,7 +179,7 @@ class Comment < ActiveRecord::Base end def log_to_countinual - Countinual.count!("lobsters.comments.submitted", "+1") + Countinual.count!("#{Rails.application.shortname}.comments.submitted", "+1") end def delete_for_user(user) @@ -289,7 +289,7 @@ class Comment < ActiveRecord::Base end def mailing_list_message_id - "comment.#{short_id}.#{created_at.to_i}@lobste.rs" + "comment.#{short_id}.#{created_at.to_i}@#{Rails.application.domain}" end def plaintext_comment diff --git a/app/models/message.rb b/app/models/message.rb index a4a1846..06865aa 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -45,8 +45,8 @@ class Message < ActiveRecord::Base self.recipient.pushover_user_key.present? Pushover.push(self.recipient.pushover_user_key, self.recipient.pushover_device, { - :title => "Lobsters message from #{self.author.username}: " << - "#{self.subject}", + :title => "#{Rails.application.name} message from " << + "#{self.author.username}: #{self.subject}", :message => self.plaintext_body, :url => self.url, :url_title => "Reply to #{self.author.username}", diff --git a/app/models/story.rb b/app/models/story.rb index 3cdeaf2..b501e22 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -229,7 +229,8 @@ class Story < ActiveRecord::Base s = Sponge.new s.timeout = 3 @fetched_content = s.fetch(self.url, :get, nil, nil, - { "User-agent" => "lobste.rs! for #{for_remote_ip}" }, 3) + { "User-agent" => "#{Rails.application.domain} for #{for_remote_ip}" }, + 3) rescue end @@ -284,7 +285,7 @@ class Story < ActiveRecord::Base end def mailing_list_message_id - "story.#{short_id}.#{created_at.to_i}@lobste.rs" + "story.#{short_id}.#{created_at.to_i}@#{Rails.application.domain}" end @_tags_a = [] diff --git a/app/models/user.rb b/app/models/user.rb index e4a609d..6a3984d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -133,7 +133,7 @@ class User < ActiveRecord::Base def linkified_about # most users are probably mentioning "@username" to mean a twitter url, not - # a link to a lobste.rs profile + # a link to a profile on this site Markdowner.to_html(self.about, { :disable_profile_links => true }) end diff --git a/app/views/comments/index.rss b/app/views/comments/index.rss index e262c1e..d124d1f 100644 --- a/app/views/comments/index.rss +++ b/app/views/comments/index.rss @@ -2,7 +2,8 @@ <% coder = HTMLEntities.new %> - lobste.rs<%= @title.present? ? ": " + h(@title) : "" %> + <%= Rails.application.name %><%= @title.present? ? + ": " + h(@title) : "" %> <%= @title %> <%= root_url %>comments diff --git a/app/views/home/rss.erb b/app/views/home/rss.erb index 287539d..7d65b52 100644 --- a/app/views/home/rss.erb +++ b/app/views/home/rss.erb @@ -2,7 +2,8 @@ <% coder = HTMLEntities.new %> - lobste.rs<%= @title.present? ? ": " + h(@title) : "" %> + <%= Rails.application.name %><%= @title.present? ? + ": " + h(@title) : "" %> <%= @title %> <%= root_url + (@newest ? "newest" : "") %> diff --git a/app/views/invitation_mailer/invitation.text.erb b/app/views/invitation_mailer/invitation.text.erb index 16f764d..5612f53 100644 --- a/app/views/invitation_mailer/invitation.text.erb +++ b/app/views/invitation_mailer/invitation.text.erb @@ -1,6 +1,6 @@ Hello <%= @invitation.email %>, -The user <%= @invitation.user.username %> has invited you to the website Lobsters<%= @invitation.memo.present? ? raw(":\n\n #{@invitation.memo}") : "." %> +The user <%= @invitation.user.username %> has invited you to the website <%= Rails.application.name %><%= @invitation.memo.present? ? raw(":\n\n #{@invitation.memo}") : "." %> To create an account, visit the URL below: diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 4af486b..d26fd12 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,7 +14,8 @@ <% end %> - <%= @title.present? ? "#{@title} | Lobsters" : "Lobsters" %> + <%= @title.present? ? "#{@title} | " : "" %><%= + Rails.application.name %> <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> @@ -33,7 +34,7 @@
;" href="/" - title="Lobsters (<%= @traffic.to_i %>)"> + title="<%= Rails.application.name %> (<%= @traffic.to_i %>)"> <% links = { "/" => "Home", diff --git a/app/views/password_reset/password_reset_link.text.erb b/app/views/password_reset/password_reset_link.text.erb index 985d829..e3ea49b 100644 --- a/app/views/password_reset/password_reset_link.text.erb +++ b/app/views/password_reset/password_reset_link.text.erb @@ -1,7 +1,7 @@ Hello <%= @user.email %>, Someone at <%= @ip %> requested to reset your account password -on lobste.rs. If you submitted this request, visit the link below to +on <%= Rails.application.name %>. If you submitted this request, visit the link below to set a new password. If not, you can disregard this e-mail. <%= root_url %>login/set_new_password?token=<%= @user.password_reset_token %> diff --git a/app/views/settings/index.html.erb b/app/views/settings/index.html.erb index 9ec5a8c..52447e6 100644 --- a/app/views/settings/index.html.erb +++ b/app/views/settings/index.html.erb @@ -152,7 +152,8 @@ <%= f.label :pushover_messages, "List Address:", :class => "required" %> - lobsters-<%= @edit_user.mailing_list_token %>@lobste.rs + <%= Rails.application.shortname %>-<%= + @edit_user.mailing_list_token %>@<%= Rails.application.domain %>
diff --git a/app/views/stories/new.html.erb b/app/views/stories/new.html.erb index 4141f9e..9de2bb7 100644 --- a/app/views/stories/new.html.erb +++ b/app/views/stories/new.html.erb @@ -21,16 +21,16 @@ Submit to - Lobsters + <%= Rails.application.name %>
  • To be able to easily submit a page you're viewing in your browser - to Lobsters, drag the bookmarklet to the right to your bookmark - bar. You'll be taken to this page with the viewed page's URL and - title. + to <%= Rails.application.name %>, drag the bookmarklet to the right + to your bookmark bar. You'll be taken to this page with the viewed + page's URL and title.

  • diff --git a/config/application.rb b/config/application.rb index bb3f863..d6fc54a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -55,15 +55,33 @@ module Lobsters # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' - + config.cache_store = :memory_store end end +# disable yaml/xml/whatever input parsing silence_warnings do ActionDispatch::ParamsParser::DEFAULT_PARSERS = {} end -Rails.application.routes.default_url_options[:host] = "lobste.rs" +# define site name and domain to be used globally, can be overridden in +# config/initializers/production.rb +class << Rails.application + def domain + "lobste.rs" + end + + def name + "Lobsters" + end + + # used as mailing list prefix and countinual prefix, cannot have spaces + def shortname + name.downcase.gsub(/[^a-z]/, "") + end +end + +Rails.application.routes.default_url_options[:host] = Rails.application.domain require "#{Rails.root}/lib/monkey" diff --git a/config/environments/development.rb b/config/environments/development.rb index 9733c26..430e967 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -35,5 +35,3 @@ Lobsters::Application.configure do # Expands the lines which load the assets config.assets.debug = true end - -Rails.application.routes.default_url_options[:host] = "lobsters.localhost:3000" diff --git a/config/initializers/email.rb b/config/initializers/email.rb index cb6312f..d71e250 100644 --- a/config/initializers/email.rb +++ b/config/initializers/email.rb @@ -1,6 +1,6 @@ ActionMailer::Base.smtp_settings = { :address => "127.0.0.1", :port => 25, - :domain => "lobste.rs", + :domain => Rails.application.domain, :enable_starttls_auto => false, } diff --git a/script/mail_new_activity b/script/mail_new_activity index e85b7f5..732541c 100755 --- a/script/mail_new_activity +++ b/script/mail_new_activity @@ -43,20 +43,26 @@ last_story_id = (Keystore.value_for(LAST_STORY_KEY) || Story.last.id).to_i Story.where("id > ?", last_story_id).order(:id).each do |s| s.fetch_story_cache! s.save - + mailing_list_users.each do |u| if (s.tags.map{|t| t.id } & u.tag_filters.map{|t| t.tag_id }).any? next end - IO.popen([ {}, "/usr/sbin/sendmail", "-i", "-f", "nobody@lobste.rs", - u.email ], "w") do |mail| - mail.puts "From: #{s.user.username} <#{s.user.username}@lobste.rs>" - mail.puts "Reply-To: lobsters-#{u.mailing_list_token}@lobste.rs" - mail.puts "To: lobsters-#{u.mailing_list_token}@lobste.rs" - mail.puts "X-BeenThere: lobsters-#{u.mailing_list_token}.lobste.rs" - mail.puts "List-Id: Lobsters " - mail.puts "List-Unsubscribe: " + domain = Rails.application.domain + list = "#{Rails.application.shortname}-#{u.mailing_list_token}@" << + Rails.application.domain + + IO.popen([ {}, "/usr/sbin/sendmail", "-i", "-f", + "nobody@#{Rails.application.domain}", u.email ], "w") do |mail| + mail.puts "From: #{s.user.username} <#{s.user.username}@" << + "#{Rails.application.domain}>" + mail.puts "Reply-To: #{list}" + mail.puts "To: #{list}" + mail.puts "X-BeenThere: #{list}" + mail.puts "List-Id: #{Rails.application.name} <#{list}>" + mail.puts "List-Unsubscribe: <" << + "#{Rails.application.routes.url_helpers.root_url}settings>" mail.puts "Precedence: list" mail.puts "Content-Type: text/plain; charset=\"us-ascii\"" mail.puts "Message-ID: <#{s.mailing_list_message_id}>" @@ -105,13 +111,18 @@ Comment.where("id > ?", last_comment_id).order(:id).each do |c| next end - IO.popen([ {}, "/usr/sbin/sendmail", "-i", "-f", "nobody@lobste.rs", - u.email ], "w") do |mail| - mail.puts "From: #{c.user.username} <#{c.user.username}@lobste.rs>" - mail.puts "Reply-To: lobsters-#{u.mailing_list_token}@lobste.rs" - mail.puts "To: lobsters-#{u.mailing_list_token}@lobste.rs" - mail.puts "List-Id: Lobsters " - mail.puts "List-Unsubscribe: " + domain = Rails.application.domain + list = "#{Rails.application.shortname}-#{u.mailing_list_token}@" << + Rails.application.domain + + IO.popen([ {}, "/usr/sbin/sendmail", "-i", "-f", + "nobody@#{domain}", u.email ], "w") do |mail| + mail.puts "From: #{c.user.username} <#{c.user.username}@#{domain}>" + mail.puts "Reply-To: #{list}" + mail.puts "To: #{list}" + mail.puts "List-Id: #{Rails.application.name} <#{list}>" + mail.puts "List-Unsubscribe: <" << + "#{Rails.application.routes.url_helpers.root_url}settings>" mail.puts "Precedence: list" mail.puts "Content-Type: text/plain; charset=\"us-ascii\"" mail.puts "Message-ID: <#{c.mailing_list_message_id}>" diff --git a/script/parse_inbound_mail b/script/parse_inbound_mail index e3a535f..2560fdb 100755 --- a/script/parse_inbound_mail +++ b/script/parse_inbound_mail @@ -1,12 +1,12 @@ #!/usr/bin/env ruby # # postfix main.cf: -# relay_domains = lobste.rs +# relay_domains = example.com # transport_maps = hash:/etc/postfix/transport # defer_transports = # # postfix transports: -# lobste.rs lobsters: +# example.com lobsters: # # postfix master.cf: # lobsters unix - n n - 2 pipe @@ -25,7 +25,8 @@ EX_TEMPFAIL = 75 EX_UNAVAILABLE = 69 recipient = ARGV[0] -user_token = recipient.gsub(/^lobsters-/, "").gsub(/@.*/, "") +user_token = recipient.gsub(/^#{Rails.application.shortname}-/, ""). + gsub(/@.*/, "") sender = ARGV[1] message = "" email = nil @@ -34,7 +35,7 @@ while !STDIN.eof? message += STDIN.gets.to_s end -if message.match(/^X-BeenThere: lobsters-/i) +if message.match(/^X-BeenThere: #{Rails.application.shortname}-/i) # avoid looping exit end @@ -47,7 +48,7 @@ if !sending_user # if this looks like a user token but invalid, generate a bounce to be # helpful. otherwise supress it to avoid talking back to spammers - exit(recipient.match(/^lobsters-/) ? EX_NOUSER : 0) + exit(recipient.match(/^#{Rails.application.shortname}-/) ? EX_NOUSER : 0) end # the mail gem stupidly spams STDERR while parsing e-mail, so silence that