From eb316031a2129819c3da537141239cca4937514b Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Sat, 28 Mar 2015 22:57:31 -0700 Subject: [PATCH] fix js file, remove old surf mode crap --- app/surf.rb | 71 ----------------------------------------- config.yml.template | 4 --- public/js/surfinject.js | 16 ++++------ views/surf.erb | 2 +- 4 files changed, 8 insertions(+), 85 deletions(-) diff --git a/app/surf.rb b/app/surf.rb index 043c0077..f4639c5c 100644 --- a/app/surf.rb +++ b/app/surf.rb @@ -15,74 +15,3 @@ get '/surf/:username' do |username| not_found if @site.nil? erb :'surf', layout: false end - -def surf_proxy - username = request.host.match /^(\w+)/i - resp = RestClient.get "http://#{username}.neocities.org#{request.path}" - content_type resp.headers[:content_type] - - if content_type.match(/^text\/html/) - body = resp.body+erb(:'surf/_surf_iframe_injection', layout: false) - else - body = resp.body - end - - halt body -end - -def surf_proxy_uri(username) - $surf_proxy_uri ||= Addressable::URI.parse $config['surf_proxy_uri'] - new_uri = $surf_proxy_uri.dup - new_uri.host = "#{username}.#{new_uri.host}" - new_uri.to_s -end - -=begin -get %r{\/surf\/proxy\/([\w-]+)\/(.+)|\/surf\/proxy\/([\w-]+)\/?} do - captures = params[:captures].compact - username = captures.first - path = captures.length == 2 ? captures.last : '' - - site = Site.where(username: username).select(:id, :username, :title, :domain).first - not_found if site.nil? - - resp = RestClient.get "http://#{site.username}.neocities.org/#{path}" - - content_type resp.headers[:content_type] - site_body = resp.body - - unless path == '/' || path == '' || path.match(/\.html?$/i) - return site_body - end - - attributes = ['src', 'href', 'background'] - - new_site_body = site_body.dup - - site_body.gsub(/(?\b\w+\b)\s*=\s*(?"[^"]*"|'[^']*'|[^"'<>\s]+)/i) do |ele| - attributes.each do |attr| - if ele.match /#{attr} ?=/ - ele_match = ele.match(/\"(.+)\"|\'(.+)\'/) - next if ele_match.nil? || ele_match.captures.nil? - uri = ele_match.captures.first - - new_ele = nil - - if uri.match(/^\w+:\/\/|^\/\//i) - if ele.match(/^href/i) - new_ele = ele + ' target="_blank"' - else - new_ele = ele - end - else - new_ele = ele.gsub(uri, "#{$config['surf_proxy_uri']}/surf/proxy/#{site.username}/#{uri}") - end - - new_site_body.gsub! ele, new_ele if new_ele - end - end - end - - new_site_body -end -=end diff --git a/config.yml.template b/config.yml.template index 86bdda66..2cd830cc 100644 --- a/config.yml.template +++ b/config.yml.template @@ -11,8 +11,6 @@ development: ip_hash_salt: "400$8$1$fc21863da5d531c1" proxy_pass: 'somethinglongandrandom' email_unsubscribe_token: 'somethingrandom' - surf_proxy_uri: 'http://surf.somedomain.local:9292' # May want to use dnsmasq instead of /etc/hosts here - surf_iframe_source: 'http://127.0.0.1:9292' logs_path: /path/to/nginx/logs test: database: 'postgres://neocities@localhost/neocities_test' @@ -27,5 +25,3 @@ test: ip_hash_salt: "400$8$1$fc21863da5d531c1" proxy_pass: 'somethinglongandrandom' email_unsubscribe_token: 'somethingrandom' - surf_proxy_uri: 'http://surf.somedomain.local:9292' - surf_iframe_source: 'http://127.0.0.1:9292' diff --git a/public/js/surfinject.js b/public/js/surfinject.js index 4b7d0d0e..527e5403 100644 --- a/public/js/surfinject.js +++ b/public/js/surfinject.js @@ -1,10 +1,8 @@ - +} +_nc_surf_page_overload() diff --git a/views/surf.erb b/views/surf.erb index aedcf6bf..cfa38877 100644 --- a/views/surf.erb +++ b/views/surf.erb @@ -236,7 +236,7 @@ - +