Bladeren bron

Readme

new-scoring
aeris 1 jaar geleden
bovenliggende
commit
3997ef769e
14 gewijzigde bestanden met toevoegingen van 268 en 88 verwijderingen
  1. 5
    5
      Guardfile
  2. 90
    0
      README.md
  3. 0
    28
      README.rdoc
  4. 0
    1
      app/controllers/check_controller.rb
  5. 104
    2
      bin/bundle
  6. 0
    1
      bin/enqueue
  7. 20
    0
      bin/enqueue
  8. 0
    20
      bin/enqueue.rb
  9. 21
    0
      bin/guard
  10. 0
    4
      bin/runner
  11. 0
    1
      bin/sidekiq
  12. 20
    0
      bin/sidekiq
  13. 0
    20
      bin/sidekiq.rb
  14. 8
    6
      config/puma.rb

+ 5
- 5
Guardfile Bestand weergeven

@@ -1,3 +1,8 @@
1
+guard :rails do
2
+	watch('Gemfile.lock')
3
+	watch(%r{^(config|lib)/.*})
4
+end
5
+
1 6
 guard :livereload do
2 7
 	watch(%r{app/views/.+\.(erb|haml|slim)$})
3 8
 	watch(%r{app/helpers/.+\.rb})
@@ -6,8 +11,3 @@ guard :livereload do
6 11
 	# Rails Assets Pipeline
7 12
 	watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg|coffee|scss))).*}) { |m| "/assets/#{m[3]}" }
8 13
 end
9
-
10
-#guard :rails do
11
-#	watch('Gemfile.lock')
12
-#	watch(%r{^(config|lib)/.*})
13
-#end

+ 90
- 0
README.md Bestand weergeven

@@ -0,0 +1,90 @@
1
+# Preliminary warning
2
+
3
+Cryptcheck relies on compiling a very unsecure version of OpenSSL.
4
+When manipulating such library, you need to be sure of what you are doing to
5
+never deploy it on a production grade system.
6
+Particularly, be sure to never hit `make install` during a manual build.
7
+
8
+Build process can be quiet hard, because relying on number of tricks to be able
9
+to use this weakened library not globally install on your system.
10
+`LD_LIBRARY_PATH`, `C_INCLUDE_PATH`, `LIBRARY_PATH` and other environment
11
+variables are used to inject what is needed during build process and at runtime
12
+to override system headers and libraries.
13
+
14
+Build process is at this time not garanteed to be reproductible.
15
+Because of above tricks, error can happen and you need to understand GNU
16
+internals and debug tools like `strace` to spot the cause of the trouble and to
17
+fix it.
18
+Given Makefiles are more generic guidelines and build recipes than fully
19
+automated build.
20
+
21
+# How to hack
22
+
23
+## Setup rbenv
24
+
25
+Because of the need of a weakened Ruby build, you need
26
+[`rbenv`](https://github.com/rbenv/rbenv) on your system to isolate this Ruby
27
+version from your eventual system version.
28
+
29
+See there readme and wiki for setup process.
30
+TL;DR;
31
+
32
+```bash
33
+export RBENV_ROOT="${HOME}/.rbenv"
34
+export PATH="${RBENV_ROOT}/bin:${PATH}"
35
+apt install -y autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev
36
+
37
+git clone https://github.com/rbenv/rbenv "${RBENV_ROOT}"
38
+
39
+mkdir -p "${RBENV_ROOT}/plugins"
40
+git clone https://github.com/rbenv/ruby-build "${RBENV_ROOT}/plugins/ruby-build"
41
+
42
+eval "$(rbenv init -)"
43
+```
44
+
45
+## Build the engine
46
+
47
+Goal is to build the weakened OpenSSL library, then a custom Ruby version based
48
+on it.
49
+
50
+```bash
51
+git clone https://git.imirhil.fr/aeris/cryptcheck
52
+cd cryptcheck
53
+make
54
+make install-rbenv-cryptcheck
55
+```
56
+
57
+## Setup the front-end
58
+
59
+```bash
60
+git clone https://git.imirhil.fr/aeris/cryptcheck-rails
61
+cd cryptcheck-rails
62
+rbenv local 2.3.3-cryptcheck
63
+export LD_LIBRARY_PATH=../cryptcheck/lib
64
+bundle install
65
+```
66
+
67
+## Mongo & Redis
68
+
69
+You need a [MongoDB](https://www.mongodb.com/) and a [Redis](https://redis.io/)
70
+server.
71
+
72
+```bash
73
+apt install -y mongodb-server redis-server
74
+```
75
+
76
+# Launch CryptCheck
77
+
78
+## Launch the front-end
79
+
80
+```bash
81
+export LD_LIBRARY_PATH=../cryptcheck/lib
82
+bin/guard -i
83
+```
84
+
85
+## Launch the worker
86
+
87
+```bash
88
+export LD_LIBRARY_PATH=../cryptcheck/lib
89
+bin/sidekiq
90
+```

+ 0
- 28
README.rdoc Bestand weergeven

@@ -1,28 +0,0 @@
1
-== README
2
-
3
-This README would normally document whatever steps are necessary to get the
4
-application up and running.
5
-
6
-Things you may want to cover:
7
-
8
-* Ruby version
9
-
10
-* System dependencies
11
-
12
-* Configuration
13
-
14
-* Database creation
15
-
16
-* Database initialization
17
-
18
-* How to run the test suite
19
-
20
-* Services (job queues, cache servers, search engines, etc.)
21
-
22
-* Deployment instructions
23
-
24
-* ...
25
-
26
-
27
-Please feel free to use a different markup language if you do not plan to run
28
-<tt>rake doc:app</tt>.

+ 0
- 1
app/controllers/check_controller.rb Bestand weergeven

@@ -10,7 +10,6 @@ class CheckController < ApplicationController
10 10
 				return render :processing if @result.pending
11 11
 			end
12 12
 			format.json do
13
-				ap @result
14 13
 				render json: JSON.pretty_generate(JSON.parse @result.to_json)
15 14
 			end
16 15
 		end

+ 104
- 2
bin/bundle Bestand weergeven

@@ -1,3 +1,105 @@
1 1
 #!/usr/bin/env ruby
2
-ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
-load Gem.bin_path('bundler', 'bundle')
2
+# frozen_string_literal: true
3
+
4
+#
5
+# This file was generated by Bundler.
6
+#
7
+# The application 'bundle' is installed as part of a gem, and
8
+# this file is here to facilitate running it.
9
+#
10
+
11
+require "rubygems"
12
+
13
+m = Module.new do
14
+    module_function
15
+
16
+  def invoked_as_script?
17
+    File.expand_path($0) == File.expand_path(__FILE__)
18
+  end
19
+
20
+  def env_var_version
21
+    ENV["BUNDLER_VERSION"]
22
+  end
23
+
24
+  def cli_arg_version
25
+    return unless invoked_as_script? # don't want to hijack other binstubs
26
+    return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+    bundler_version = nil
28
+    update_index = nil
29
+    ARGV.each_with_index do |a, i|
30
+      if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+        bundler_version = a
32
+      end
33
+      next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+      bundler_version = $1 || ">= 0.a"
35
+      update_index = i
36
+    end
37
+    bundler_version
38
+  end
39
+
40
+  def gemfile
41
+    gemfile = ENV["BUNDLE_GEMFILE"]
42
+    return gemfile if gemfile && !gemfile.empty?
43
+
44
+    File.expand_path("../../Gemfile", __FILE__)
45
+  end
46
+
47
+  def lockfile
48
+    lockfile =
49
+      case File.basename(gemfile)
50
+      when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+      else "#{gemfile}.lock"
52
+      end
53
+    File.expand_path(lockfile)
54
+  end
55
+
56
+  def lockfile_version
57
+    return unless File.file?(lockfile)
58
+    lockfile_contents = File.read(lockfile)
59
+    return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+    Regexp.last_match(1)
61
+  end
62
+
63
+  def bundler_version
64
+    @bundler_version ||= begin
65
+      env_var_version || cli_arg_version ||
66
+        lockfile_version || "#{Gem::Requirement.default}.a"
67
+    end
68
+  end
69
+
70
+  def load_bundler!
71
+    ENV["BUNDLE_GEMFILE"] ||= gemfile
72
+
73
+    # must dup string for RG < 1.8 compatibility
74
+    activate_bundler(bundler_version.dup)
75
+  end
76
+
77
+  def activate_bundler(bundler_version)
78
+    if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79
+      bundler_version = "< 2"
80
+    end
81
+    gem_error = activation_error_handling do
82
+      gem "bundler", bundler_version
83
+    end
84
+    return if gem_error.nil?
85
+    require_error = activation_error_handling do
86
+      require "bundler/version"
87
+    end
88
+    return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
89
+    warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
90
+    exit 42
91
+  end
92
+
93
+  def activation_error_handling
94
+    yield
95
+    nil
96
+  rescue StandardError, LoadError => e
97
+    e
98
+  end
99
+end
100
+
101
+m.load_bundler!
102
+
103
+if m.invoked_as_script?
104
+  load Gem.bin_path("bundler", "bundle")
105
+end

+ 0
- 1
bin/enqueue Bestand weergeven

@@ -1 +0,0 @@
1
-runner

+ 20
- 0
bin/enqueue Bestand weergeven

@@ -0,0 +1,20 @@
1
+#!/usr/bin/env ruby
2
+ENV['RAILS_ENV'] ||= 'development'
3
+require 'dotenv'
4
+Dotenv.load ".env.#{ENV['RAILS_ENV']}", '.env'
5
+
6
+if ENV['RAILS_ENV'] == 'development'
7
+	DIR = File.dirname File.dirname File.expand_path __FILE__
8
+	require File.join DIR, 'config/environment'
9
+	ENV['RAILS_ENV'] = 'test'
10
+	require 'sidekiq/testing/inline'
11
+end
12
+
13
+require 'sidekiq'
14
+redis = ENV['REDIS_URL']
15
+Sidekiq.configure_server { |c| c.redis = { url: redis } }
16
+Sidekiq.configure_client { |c| c.redis = { url: redis } }
17
+
18
+clazz, *args = ARGV
19
+clazz        += 'Worker'
20
+Sidekiq::Client.push({ 'class' => clazz, 'args' => args, 'retry' => false })

+ 0
- 20
bin/enqueue.rb Bestand weergeven

@@ -1,20 +0,0 @@
1
-#!/usr/bin/env ruby
2
-ENV['RAILS_ENV'] ||= 'development'
3
-require 'dotenv'
4
-Dotenv.load ".env.#{ENV['RAILS_ENV']}", '.env'
5
-
6
-if ENV['RAILS_ENV'] == 'development'
7
-	DIR = File.dirname File.dirname File.expand_path __FILE__
8
-	require File.join DIR, 'config/environment'
9
-	ENV['RAILS_ENV'] = 'test'
10
-	require 'sidekiq/testing/inline'
11
-end
12
-
13
-require 'sidekiq'
14
-redis = ENV['REDIS_URL']
15
-Sidekiq.configure_server { |c| c.redis = { url: redis } }
16
-Sidekiq.configure_client { |c| c.redis = { url: redis } }
17
-
18
-clazz, *args = ARGV
19
-clazz        += 'Worker'
20
-Sidekiq::Client.push({ 'class' => clazz, 'args' => args, 'retry' => false })

+ 21
- 0
bin/guard Bestand weergeven

@@ -0,0 +1,21 @@
1
+#!/usr/bin/env ruby
2
+# frozen_string_literal: true
3
+
4
+#
5
+# This file was generated by Bundler.
6
+#
7
+# The application 'guard' is installed as part of a gem, and
8
+# this file is here to facilitate running it.
9
+#
10
+
11
+bundle_binstub = File.expand_path("../bundle", __FILE__)
12
+load(bundle_binstub) if File.file?(bundle_binstub)
13
+
14
+require "pathname"
15
+ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
16
+  Pathname.new(__FILE__).realpath)
17
+
18
+require "rubygems"
19
+require "bundler/setup"
20
+
21
+load Gem.bin_path("guard", "guard")

+ 0
- 4
bin/runner Bestand weergeven

@@ -1,4 +0,0 @@
1
-#!/bin/bash
2
-DIR="$(readlink -e "$(dirname "${0}")")"
3
-export LD_LIBRARY_PATH="$(readlink -e "${DIR}/../../cryptcheck/lib")"
4
-"${0}.rb" $*

+ 0
- 1
bin/sidekiq Bestand weergeven

@@ -1 +0,0 @@
1
-runner

+ 20
- 0
bin/sidekiq Bestand weergeven

@@ -0,0 +1,20 @@
1
+#!/usr/bin/env ruby
2
+$:.unshift File.expand_path File.join File.dirname(__FILE__), '../../cryptcheck/lib'
3
+require 'rubygems'
4
+require 'bundler/setup'
5
+
6
+$TESTING = false
7
+$CELLULOID_DEBUG = false
8
+
9
+require 'sidekiq/cli'
10
+
11
+begin
12
+	cli = Sidekiq::CLI.instance
13
+	cli.parse
14
+	cli.run
15
+rescue => e
16
+	raise e if $DEBUG
17
+	STDERR.puts e.message
18
+	STDERR.puts e.backtrace.join("\n")
19
+	exit 1
20
+end

+ 0
- 20
bin/sidekiq.rb Bestand weergeven

@@ -1,20 +0,0 @@
1
-#!/usr/bin/env ruby
2
-$:.unshift File.expand_path File.join File.dirname(__FILE__), '../../cryptcheck/lib'
3
-require 'rubygems'
4
-require 'bundler/setup'
5
-
6
-$TESTING = false
7
-$CELLULOID_DEBUG = false
8
-
9
-require 'sidekiq/cli'
10
-
11
-begin
12
-	cli = Sidekiq::CLI.instance
13
-	cli.parse
14
-	cli.run
15
-rescue => e
16
-	raise e if $DEBUG
17
-	STDERR.puts e.message
18
-	STDERR.puts e.backtrace.join("\n")
19
-	exit 1
20
-end

+ 8
- 6
config/puma.rb Bestand weergeven

@@ -14,16 +14,18 @@ unless Rails.root
14 14
 	end
15 15
 end
16 16
 
17
-workers 4 if env == 'production'
17
+workers ENV.fetch('WORKER', 4).to_i
18 18
 
19
-port = ENV['PORT']
20
-if port
21
-	port(port)
22
-else
19
+if env == 'production'
23 20
 	listen = ENV.fetch('LISTEN') { 'unix://' + File.join(Rails.root, 'tmp/sockets/puma.sock') }
24
-	bind listen
21
+	port   = ENV['PORT']
22
+else
23
+	listen = ENV['LISTEN']
24
+	port   = ENV.fetch 'PORT', 3000
25 25
 end
26 26
 
27
+port(port) if port
28
+bind listen if listen
27 29
 
28 30
 pidfile File.join Rails.root, 'tmp/pids/puma.pid'
29 31
 

Laden…
Annuleren
Opslaan