diff --git a/.gitignore b/.gitignore index 0d19f0bc..6fd2737a 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ files/map.txt files/sslsites.zip .tm_properties ./black_box.rb +.vagrant diff --git a/Gemfile b/Gemfile index 3f3cf2a9..6abc37bd 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,3 @@ -source 'https://code.stripe.com' source 'https://rubygems.org' gem 'sinatra' @@ -16,7 +15,7 @@ gem 'mail' gem 'google-api-client', require: 'google/api_client' gem 'tilt' gem 'erubis' -gem 'stripe' +gem 'stripe', source: 'https://code.stripe.com/' gem 'screencap' gem 'cocaine' gem 'zipruby' @@ -63,7 +62,6 @@ group :test do gem 'mocha', require: nil gem 'rake', require: nil gem 'poltergeist' - gem 'phantomjs', require: 'phantomjs/poltergeist' gem 'capybara_minitest_spec' gem 'rack_session_access', require: nil gem 'webmock', require: nil diff --git a/Gemfile.lock b/Gemfile.lock index 529cfeff..fd90fb5b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GEM - remote: https://code.stripe.com/ remote: https://rubygems.org/ + remote: https://code.stripe.com/ specs: activesupport (4.1.4) i18n (~> 0.6, >= 0.6.9) @@ -246,7 +246,6 @@ DEPENDENCIES minitest-reporters mocha pg - phantomjs poltergeist pry pry-byebug @@ -271,7 +270,7 @@ DEPENDENCIES sinatra sinatra-flash sinatra-xsendfile - stripe + stripe! stripe-ruby-mock (~> 2.0.1) thread tilt diff --git a/README.md b/README.md index bdc39371..5397c713 100644 --- a/README.md +++ b/README.md @@ -4,42 +4,23 @@ The web site for NeoCities! It's open source. Want a feature on the site? Send a pull request! -## Installation (OSX) +## Getting Started -Install homebrew: -``` -ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)" -``` - -Install deps: -``` -$ brew install redis postgresql phantomjs libmagic imagemagick -``` - -Fork the repository on Github. -Clone the forked repo to your local machine: git clone git@github.com:YOURUSERNAME/neocities.git -Install deps: +Neocities can be quickly launched in development mode with (Vagrant)[https://www.vagrantup.com]. Vagrant builds a virtual machine that automatically installs everything you need to run Neocities as a developer. Install Vagrant, then from the command line: ``` -$ cd neocities -$ gem install bundler -$ bundle install +vagrant up --provision ``` -Create postgres databases: +![Vagrant takes a while, make a pizza while waiting](http://i.imgur.com/vfIJPXP.png) ``` -createdb neocities_test -createdb neocities_dev +vagrant ssh +cd /vagrant +bundle exec rackup ``` -Copy config.yml.template to config.yml. - -Run the tests to see if they work: - -``` - bundle exec rake test -``` +Now you can access the running site from your browser: http://127.0.0.1:9292 ## Want to contribute? diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 00000000..59a70b4d --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,12 @@ +VAGRANTFILE_API_VERSION = '2' + +Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| + config.vm.box = 'ubuntu/trusty64' + config.vm.provision :shell, path: './vagrant/development.sh' + config.vm.network :forwarded_port, guest: 9292, host: 9292 + + config.vm.provider :virtualbox do |vb| + vb.customize ['modifyvm', :id, '--memory', '1536'] + vb.name = 'neocities' + end +end \ No newline at end of file diff --git a/config.yml.template b/config.yml.template index b939c853..9eaa29a9 100644 --- a/config.yml.template +++ b/config.yml.template @@ -1,24 +1,24 @@ development: - database: 'postgres://neocities@127.0.0.1/neocities' + database: 'postgres://neocities@localhost/neocities' database_pool: 1 - session_secret: SECRET GOES HERE - recaptcha_public_key: ENTER PUBLIC KEY HERE - recaptcha_private_key: ENTER PRIVATE KEY HERE - sidekiq_user: ENTER USER HERE - sidekiq_pass: ENTER PASS HERE - stripe_publishable_key: fillout - stripe_api_key: fillout + session_secret: "SECRET GOES HERE" + recaptcha_public_key: "ENTER PUBLIC KEY HERE" + recaptcha_private_key: "ENTER PRIVATE KEY HERE" + sidekiq_user: "ENTER USER HERE" + sidekiq_pass: "ENTER PASS HERE" + stripe_publishable_key: "ENTER KEY HERE" + stripe_api_key: "ENTER KEY HERE" ip_hash_salt: "400$8$1$fc21863da5d531c1" proxy_pass: 'somethinglongandrandom' test: - database: 'postgres://neocities@127.0.0.1/neocities_test' + database: 'postgres://neocities@localhost/neocities_test' database_pool: 1 - session_secret: SECRET GOES HERE - recaptcha_public_key: ENTER PUBLIC KEY HERE - recaptcha_private_key: ENTER PRIVATE KEY HERE - sidekiq_user: ENTER USER HERE - sidekiq_pass: ENTER PASS HERE - stripe_publishable_key: fillout - stripe_api_key: fillout + session_secret: "SECRET GOES HERE" + recaptcha_public_key: "ENTER PUBLIC KEY HERE" + recaptcha_private_key: "ENTER PRIVATE KEY HERE" + sidekiq_user: "ENTER USER HERE" + sidekiq_pass: "ENTER PASS HERE" + stripe_publishable_key: "ENTER KEY HERE" + stripe_api_key: "ENTER KEY HERE" ip_hash_salt: "400$8$1$fc21863da5d531c1" proxy_pass: 'somethinglongandrandom' \ No newline at end of file diff --git a/ext/phantomjs.rb b/ext/phantomjs.rb new file mode 100644 index 00000000..10407891 --- /dev/null +++ b/ext/phantomjs.rb @@ -0,0 +1,6 @@ +module Phantomjs + # Workaround for vagrant bug. + def self.path + '/usr/local/bin/phantomjs' + end +end \ No newline at end of file diff --git a/models/site.rb b/models/site.rb index 135483b0..b26c7ef8 100644 --- a/models/site.rb +++ b/models/site.rb @@ -509,7 +509,7 @@ class Site < Sequel::Model # clamdscan doesn't work on travis for testing return true if ENV['TRAVIS'] == 'true' - File.chmod 0640, uploaded_file[:tempfile].path + File.chmod 0666, uploaded_file[:tempfile].path line = Cocaine::CommandLine.new( "clamdscan", "-i --remove=no --no-summary --stdout :path", expected_outcodes: [0, 1] diff --git a/tests/api_tests.rb b/tests/api_tests.rb index 16c8f421..02b327cf 100644 --- a/tests/api_tests.rb +++ b/tests/api_tests.rb @@ -170,6 +170,7 @@ describe 'api upload' do post '/api/upload', { '' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') } + res[:error_type].must_equal 'missing_files' end diff --git a/vagrant/common.sh b/vagrant/common.sh new file mode 100644 index 00000000..65153ca2 --- /dev/null +++ b/vagrant/common.sh @@ -0,0 +1,23 @@ +# Quiets the TTY error message +#sed -i 's/^mesg n$/tty -s \&\& mesg n/g' /root/.profile + +DEBIAN_FRONTEND=noninteractive + +apt-get -y update +apt-get -y upgrade +apt-get install -y openntpd htop autossh sshfs vim + +echo 'UTC' | tee /etc/timezone +dpkg-reconfigure -f noninteractive tzdata + +update-alternatives --set editor /usr/bin/vim.basic + +ufw allow ssh +ufw --force enable +ufw logging off + +sed -i 's|[#]*PasswordAuthentication yes|PasswordAuthentication no|g' /etc/ssh/sshd_config +sed -i 's|UsePAM yes|UsePAM no|g' /etc/ssh/sshd_config +#sed -i 's|[#]*PermitRootLogin yes|PermitRootLogin no|g' /etc/ssh/sshd_config + +service ssh restart diff --git a/vagrant/database.sh b/vagrant/database.sh new file mode 100644 index 00000000..461dab13 --- /dev/null +++ b/vagrant/database.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +DEBIAN_FRONTEND=noninteractive + +apt-get -y install postgresql postgresql-contrib libpq-dev \ No newline at end of file diff --git a/vagrant/development.sh b/vagrant/development.sh new file mode 100644 index 00000000..30061fc4 --- /dev/null +++ b/vagrant/development.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +DEBIAN_FRONTEND=noninteractive +. /vagrant/vagrant/common.sh +. /vagrant/vagrant/database.sh +. /vagrant/vagrant/ruby.sh +. /vagrant/vagrant/webapp.sh + +ufw allow 9292 + +sudo su postgres -c "createuser -d vagrant" +sudo su vagrant -c "createdb neocities" +sudo su vagrant -c "createdb neocities_test" \ No newline at end of file diff --git a/vagrant/phantomjs.sh b/vagrant/phantomjs.sh new file mode 100644 index 00000000..0e578661 --- /dev/null +++ b/vagrant/phantomjs.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +DEBIAN_FRONTEND=noninteractive + +wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-x86_64.tar.bz2 +bzip2 -dc phantomjs-1.9.8-linux-x86_64.tar.bz2 | tar xf - +cp phantomjs-1.9.8-linux-x86_64/bin/phantomjs /usr/local/bin/ \ No newline at end of file diff --git a/vagrant/redis.sh b/vagrant/redis.sh new file mode 100644 index 00000000..9cb659a1 --- /dev/null +++ b/vagrant/redis.sh @@ -0,0 +1,6 @@ +apt-get install -y redis-server + +#sed -i 's|[#]*appendfsync everysec|appendfsync always|g' /etc/redis/redis.conf +sed -i 's|[#]*appendonly no|appendonly yes|g' /etc/redis/redis.conf + +service redis-server restart \ No newline at end of file diff --git a/vagrant/ruby.sh b/vagrant/ruby.sh new file mode 100644 index 00000000..853c0120 --- /dev/null +++ b/vagrant/ruby.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +apt-get -y install python-software-properties +apt-add-repository -y ppa:brightbox/ruby-ng +apt-get -y update +apt-get -y install ruby2.2 ruby2.2-dev +gem install bundler --no-rdoc --no-ri \ No newline at end of file diff --git a/vagrant/webapp.sh b/vagrant/webapp.sh new file mode 100644 index 00000000..1687177b --- /dev/null +++ b/vagrant/webapp.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +DEBIAN_FRONTEND=noninteractive + +. /vagrant/vagrant/phantomjs.sh +. /vagrant/vagrant/redis.sh + +apt-get install -y git curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev libffi-dev libpq-dev libmagickwand-dev imagemagick libmagickwand-dev libmagic-dev file clamav-daemon + +sed -i 's|[#]*DetectPUA false|DetectPUA true|g' /etc/clamav/clamd.conf + +freshclam +service clamav-freshclam start +service clamav-daemon start + +usermod -G vagrant clamav + +cd /vagrant +bundle install \ No newline at end of file