diff --git a/.gitignore b/.gitignore index 3a14f421..24a7610a 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ files/letsencrypt.key files/tor.txt .bundle ext/black_box.rb +files/trumpplan.txt diff --git a/app/index.rb b/app/index.rb index 1b26cccf..6e2d3280 100644 --- a/app/index.rb +++ b/app/index.rb @@ -54,10 +54,41 @@ get '/?' do @blog_feed_html = SimpleCache.get :blog_feed_html end + if params[:trumpplan] + flash[:is_trump_plan] = true + end + erb :index, layout: :index_layout end +def trump_plan_eligible? + trumpplan_path = File.join 'files', 'trumpplan.txt' + + ranges = [] + + if File.exist? trumpplan_path + File.readlines(trumpplan_path).each do |range| + ranges << IPAddress.parse(range.strip) + end + + parsed_ip = IPAddress.parse(request.ip) + + matched_ip = false + ranges.each do |range| + if range.include? parsed_ip + matched_ip = true + end + end + return matched_ip + end + false +end + get '/welcome' do + if params[:trumpplan] || flash[:is_trump_plan] || trump_plan_eligible? + @is_trump_plan = true + end + require_login redirect '/' if current_site.supporter? erb :'welcome', locals: {site: current_site} diff --git a/app/supporter.rb b/app/supporter.rb index 39a5fa24..bf67ac5d 100644 --- a/app/supporter.rb +++ b/app/supporter.rb @@ -14,7 +14,12 @@ end post '/supporter/update' do require_login - plan_type = 'supporter' + + if params[:plan_type] == 'trumpplan' + plan_type = 'trumpplan' + else + plan_type = 'supporter' + end if is_special_upgrade require_admin diff --git a/models/site.rb b/models/site.rb index d7ca6926..b224742f 100644 --- a/models/site.rb +++ b/models/site.rb @@ -112,6 +112,14 @@ class Site < Sequel::Model maximum_site_files: 100_000 } + PLAN_FEATURES[:trumpplan] = PLAN_FEATURES[:supporter].merge( + name: 'Trump Plan', + price: 100, + space: Filesize.from('2MB').to_i, + no_file_restrictions: false, + bandwidth: Filesize.from('604800KB').to_i + ) + PLAN_FEATURES[:free] = PLAN_FEATURES[:supporter].merge( name: 'Free', space: Filesize.from('1GB').to_i, diff --git a/views/site.erb b/views/site.erb index 177d0f6d..c0e399fb 100644 --- a/views/site.erb +++ b/views/site.erb @@ -19,7 +19,7 @@
-

<%= site.title %> <% if site.supporter? %> <% end %>

+

<%= site.title %> <% if site.supporter? %> <% end %> <% if site.plan_type == 'trumpplan' %>FAT CAT
FAT CAT SUPPORTER
Tips really well at Sarge's Deli<% end %>

<%= site.host %>