proxes 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -1
- data/.travis.yml +0 -3
- data/Gemfile.ci +5 -2
- data/README.md +12 -9
- data/Rakefile +10 -5
- data/Vagrantfile +1 -4
- data/config.ru +32 -24
- data/lib/{proxes → ditty/components}/proxes.rb +26 -33
- data/lib/proxes/controllers/permissions.rb +4 -3
- data/lib/proxes/models/permission.rb +7 -5
- data/lib/proxes/policies/permission_policy.rb +4 -4
- data/lib/proxes/policies/request/index_policy.rb +1 -1
- data/lib/proxes/policies/request_policy.rb +3 -4
- data/lib/proxes/policies/token_policy.rb +1 -1
- data/lib/proxes/request/cat.rb +2 -2
- data/lib/proxes/request/index.rb +2 -2
- data/lib/proxes/request.rb +1 -1
- data/lib/proxes/security.rb +10 -12
- data/lib/proxes/version.rb +1 -1
- data/lib/proxes.rb +1 -3
- data/migrate/20170207_base_tables.rb +2 -1
- data/migrate/20170208_audit_log.rb +1 -0
- data/proxes.gemspec +15 -14
- data/public/js/bundle.js +44683 -23940
- data/public/js/vendors.js +1 -0
- data/views/permissions/form.haml +2 -2
- data/views/permissions/index.haml +14 -9
- metadata +69 -108
- data/lib/proxes/container.rb +0 -135
- data/lib/proxes/controllers/app.rb +0 -80
- data/lib/proxes/controllers/application.rb +0 -80
- data/lib/proxes/controllers/audit_logs.rb +0 -44
- data/lib/proxes/controllers/component.rb +0 -167
- data/lib/proxes/controllers/roles.rb +0 -16
- data/lib/proxes/controllers/users.rb +0 -183
- data/lib/proxes/db.rb +0 -18
- data/lib/proxes/helpers/authentication.rb +0 -58
- data/lib/proxes/helpers/component.rb +0 -49
- data/lib/proxes/helpers/pundit.rb +0 -40
- data/lib/proxes/helpers/views.rb +0 -42
- data/lib/proxes/helpers/wisper.rb +0 -15
- data/lib/proxes/listener.rb +0 -23
- data/lib/proxes/models/audit_log.rb +0 -14
- data/lib/proxes/models/base.rb +0 -9
- data/lib/proxes/models/identity.rb +0 -70
- data/lib/proxes/models/role.rb +0 -17
- data/lib/proxes/models/user.rb +0 -64
- data/lib/proxes/omniauth.rb +0 -4
- data/lib/proxes/policies/application_policy.rb +0 -21
- data/lib/proxes/policies/audit_log_policy.rb +0 -41
- data/lib/proxes/policies/identity_policy.rb +0 -25
- data/lib/proxes/policies/role_policy.rb +0 -37
- data/lib/proxes/policies/user_policy.rb +0 -43
- data/lib/proxes/rake_tasks.rb +0 -219
- data/lib/proxes/seed.rb +0 -5
- data/lib/proxes/services/logger.rb +0 -51
- data/views/404.haml +0 -1
- data/views/audit_logs/index.haml +0 -26
- data/views/error.haml +0 -4
- data/views/getting_started.haml +0 -16
- data/views/identity/login.haml +0 -19
- data/views/identity/register.haml +0 -14
- data/views/index.haml +0 -3
- data/views/layout.haml +0 -58
- data/views/partials/delete_form.haml +0 -4
- data/views/partials/form_control.haml +0 -20
- data/views/partials/navbar.haml +0 -25
- data/views/partials/notifications.haml +0 -24
- data/views/partials/pager.haml +0 -12
- data/views/partials/sidebar.haml +0 -54
- data/views/roles/display.haml +0 -38
- data/views/roles/edit.haml +0 -11
- data/views/roles/form.haml +0 -1
- data/views/roles/index.haml +0 -20
- data/views/roles/new.haml +0 -10
- data/views/users/display.haml +0 -69
- data/views/users/edit.haml +0 -11
- data/views/users/identity.haml +0 -3
- data/views/users/index.haml +0 -23
- data/views/users/new.haml +0 -11
- data/views/users/profile.haml +0 -39
- data/views/users/user.haml +0 -3
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'wisper'
|
4
|
-
require 'proxes/request'
|
5
|
-
|
6
|
-
module ProxES
|
7
|
-
module Helpers
|
8
|
-
module Wisper
|
9
|
-
def log_action(action, args = {})
|
10
|
-
args[:user] ||= current_user
|
11
|
-
broadcast(action, args)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/lib/proxes/listener.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'wisper'
|
2
|
-
|
3
|
-
module ProxES
|
4
|
-
class Listener
|
5
|
-
def initialize
|
6
|
-
@mutex = Mutex.new
|
7
|
-
end
|
8
|
-
|
9
|
-
def method_missing(method, *args)
|
10
|
-
vals = { action: method }
|
11
|
-
return unless args[0].is_a? Hash
|
12
|
-
vals[:user] = args[0][:user] if args[0] && args[0].key?(:user)
|
13
|
-
vals[:details] = args[0][:details] if args[0] && args[0].key?(:details)
|
14
|
-
@mutex.synchronize { AuditLog.create vals }
|
15
|
-
end
|
16
|
-
|
17
|
-
def respond_to_missing?(_method, _include_private = false)
|
18
|
-
true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
Wisper.subscribe(ProxES::Listener.new)
|
data/lib/proxes/models/base.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bcrypt'
|
4
|
-
require 'proxes/models/base'
|
5
|
-
require 'omniauth-identity'
|
6
|
-
require 'active_support'
|
7
|
-
require 'active_support/core_ext/object/blank'
|
8
|
-
|
9
|
-
module ProxES
|
10
|
-
class Identity < Sequel::Model
|
11
|
-
include ::ProxES::Base
|
12
|
-
many_to_one :user
|
13
|
-
|
14
|
-
attr_accessor :password, :password_confirmation
|
15
|
-
|
16
|
-
# OmniAuth Related
|
17
|
-
include OmniAuth::Identity::Model
|
18
|
-
|
19
|
-
def self.locate(conditions)
|
20
|
-
where(conditions).first
|
21
|
-
end
|
22
|
-
|
23
|
-
def authenticate(unencrypted)
|
24
|
-
self if ::BCrypt::Password.new(crypted_password) == unencrypted
|
25
|
-
end
|
26
|
-
|
27
|
-
def persisted?
|
28
|
-
!new? && @destroyed != true
|
29
|
-
end
|
30
|
-
|
31
|
-
# Return whatever we want to pass to the omniauth hash here
|
32
|
-
def info
|
33
|
-
{
|
34
|
-
email: username
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
# Validation
|
39
|
-
def validate
|
40
|
-
validates_presence :username
|
41
|
-
unless username.blank?
|
42
|
-
validates_unique :username
|
43
|
-
validates_format(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :username)
|
44
|
-
end
|
45
|
-
|
46
|
-
if password_required
|
47
|
-
validates_presence :password
|
48
|
-
validates_presence :password_confirmation
|
49
|
-
validates_min_length 8, :password
|
50
|
-
end
|
51
|
-
|
52
|
-
errors.add(:password_confirmation, 'must match password') if !password.blank? && password != password_confirmation
|
53
|
-
end
|
54
|
-
|
55
|
-
# Callbacks
|
56
|
-
def before_save
|
57
|
-
encrypt_password unless password == '' || password.nil?
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def encrypt_password
|
63
|
-
self.crypted_password = ::BCrypt::Password.create(password)
|
64
|
-
end
|
65
|
-
|
66
|
-
def password_required
|
67
|
-
crypted_password.blank? || !password.blank?
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
data/lib/proxes/models/role.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'proxes/models/base'
|
4
|
-
|
5
|
-
module ProxES
|
6
|
-
class Role < Sequel::Model
|
7
|
-
include ::ProxES::Base
|
8
|
-
|
9
|
-
many_to_many :users
|
10
|
-
one_to_many :permissions
|
11
|
-
|
12
|
-
def validate
|
13
|
-
validates_presence [:name]
|
14
|
-
validates_unique [:name]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/lib/proxes/models/user.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'proxes/models/base'
|
4
|
-
require 'digest/md5'
|
5
|
-
require 'active_support'
|
6
|
-
require 'active_support/core_ext/object/blank'
|
7
|
-
|
8
|
-
# Why not store this in Elasticsearch?
|
9
|
-
module ProxES
|
10
|
-
class User < Sequel::Model
|
11
|
-
include ::ProxES::Base
|
12
|
-
|
13
|
-
one_to_many :identity
|
14
|
-
many_to_many :roles
|
15
|
-
one_to_many :permissions
|
16
|
-
one_to_many :audit_logs
|
17
|
-
|
18
|
-
def role?(check)
|
19
|
-
!roles_dataset.first(name: check).nil?
|
20
|
-
end
|
21
|
-
|
22
|
-
def method_missing(method_sym, *arguments, &block)
|
23
|
-
if method_sym.to_s[-1] == '?'
|
24
|
-
role?(method_sym[0..-2])
|
25
|
-
else
|
26
|
-
super
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def respond_to_missing?(name, _include_private = false)
|
31
|
-
name[-1] == '?'
|
32
|
-
end
|
33
|
-
|
34
|
-
def gravatar
|
35
|
-
hash = Digest::MD5.hexdigest(email.downcase)
|
36
|
-
"https://www.gravatar.com/avatar/#{hash}"
|
37
|
-
end
|
38
|
-
|
39
|
-
def validate
|
40
|
-
validates_presence :email
|
41
|
-
return if email.blank?
|
42
|
-
validates_unique :email
|
43
|
-
validates_format(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :email)
|
44
|
-
end
|
45
|
-
|
46
|
-
# Add the basic roles and identity
|
47
|
-
def after_create
|
48
|
-
check_roles
|
49
|
-
end
|
50
|
-
|
51
|
-
def check_roles
|
52
|
-
return if role?('anonymous')
|
53
|
-
add_role Role.find_or_create(name: 'user') unless role?('user')
|
54
|
-
end
|
55
|
-
|
56
|
-
def index_prefix
|
57
|
-
email
|
58
|
-
end
|
59
|
-
|
60
|
-
def username
|
61
|
-
identity_dataset.first.username
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/lib/proxes/omniauth.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ProxES
|
4
|
-
class ApplicationPolicy
|
5
|
-
attr_reader :user, :record
|
6
|
-
|
7
|
-
def initialize(user, record)
|
8
|
-
@user = user
|
9
|
-
@record = record
|
10
|
-
end
|
11
|
-
|
12
|
-
class Scope
|
13
|
-
attr_reader :user, :scope
|
14
|
-
|
15
|
-
def initialize(user, scope)
|
16
|
-
@user = user
|
17
|
-
@scope = scope
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'proxes/policies/application_policy'
|
4
|
-
|
5
|
-
module ProxES
|
6
|
-
class AuditLogPolicy < ApplicationPolicy
|
7
|
-
def create?
|
8
|
-
user && user.super_admin?
|
9
|
-
end
|
10
|
-
|
11
|
-
def list?
|
12
|
-
create?
|
13
|
-
end
|
14
|
-
|
15
|
-
def read?
|
16
|
-
create?
|
17
|
-
end
|
18
|
-
|
19
|
-
def update?
|
20
|
-
read?
|
21
|
-
end
|
22
|
-
|
23
|
-
def delete?
|
24
|
-
create?
|
25
|
-
end
|
26
|
-
|
27
|
-
def permitted_attributes
|
28
|
-
[:action, :details]
|
29
|
-
end
|
30
|
-
|
31
|
-
class Scope < ApplicationPolicy::Scope
|
32
|
-
def resolve
|
33
|
-
if user && user.super_admin?
|
34
|
-
scope
|
35
|
-
else
|
36
|
-
scope.where(id: -1)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'application_policy'
|
4
|
-
|
5
|
-
module ProxES
|
6
|
-
class IdentityPolicy < ApplicationPolicy
|
7
|
-
def register?
|
8
|
-
true
|
9
|
-
end
|
10
|
-
|
11
|
-
def permitted_attributes
|
12
|
-
[:username, :password, :password_confirmation]
|
13
|
-
end
|
14
|
-
|
15
|
-
class Scope < ApplicationPolicy::Scope
|
16
|
-
def resolve
|
17
|
-
if user.super_admin?
|
18
|
-
scope.all
|
19
|
-
else
|
20
|
-
[]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'proxes/policies/application_policy'
|
4
|
-
|
5
|
-
module ProxES
|
6
|
-
class RolePolicy < ApplicationPolicy
|
7
|
-
def create?
|
8
|
-
user && user.super_admin?
|
9
|
-
end
|
10
|
-
|
11
|
-
def list?
|
12
|
-
create?
|
13
|
-
end
|
14
|
-
|
15
|
-
def read?
|
16
|
-
create?
|
17
|
-
end
|
18
|
-
|
19
|
-
def update?
|
20
|
-
read?
|
21
|
-
end
|
22
|
-
|
23
|
-
def delete?
|
24
|
-
create?
|
25
|
-
end
|
26
|
-
|
27
|
-
def permitted_attributes
|
28
|
-
[:name]
|
29
|
-
end
|
30
|
-
|
31
|
-
class Scope < ApplicationPolicy::Scope
|
32
|
-
def resolve
|
33
|
-
user && user.super_admin? ? scope : scope.where(id: -1)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'proxes/policies/application_policy'
|
4
|
-
|
5
|
-
module ProxES
|
6
|
-
class UserPolicy < ApplicationPolicy
|
7
|
-
def create?
|
8
|
-
user && user.super_admin?
|
9
|
-
end
|
10
|
-
|
11
|
-
def list?
|
12
|
-
create?
|
13
|
-
end
|
14
|
-
|
15
|
-
def read?
|
16
|
-
user && (record.id == user.id || user.super_admin?)
|
17
|
-
end
|
18
|
-
|
19
|
-
def update?
|
20
|
-
read?
|
21
|
-
end
|
22
|
-
|
23
|
-
def delete?
|
24
|
-
create?
|
25
|
-
end
|
26
|
-
|
27
|
-
def register?
|
28
|
-
true
|
29
|
-
end
|
30
|
-
|
31
|
-
def permitted_attributes
|
32
|
-
attribs = [:email, :name, :surname]
|
33
|
-
attribs << :role_id if user.super_admin?
|
34
|
-
attribs
|
35
|
-
end
|
36
|
-
|
37
|
-
class Scope < ApplicationPolicy::Scope
|
38
|
-
def resolve
|
39
|
-
user && user.super_admin? ? scope : scope.where(id: user.id)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/lib/proxes/rake_tasks.rb
DELETED
@@ -1,219 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rake'
|
4
|
-
require 'rake/tasklib'
|
5
|
-
require 'highline'
|
6
|
-
require 'yaml'
|
7
|
-
|
8
|
-
module ProxES
|
9
|
-
class Tasks < ::Rake::TaskLib
|
10
|
-
include ::Rake::DSL if defined?(::Rake::DSL)
|
11
|
-
|
12
|
-
CONFIG_PATH = File.expand_path('./config/config.yml')
|
13
|
-
|
14
|
-
POSTGRES_PACKAGES = [
|
15
|
-
'postgresql-common',
|
16
|
-
'postgresql-9.5',
|
17
|
-
'postgresql-client-9.5',
|
18
|
-
'postgresql-contrib-9.5',
|
19
|
-
'postgresql-9.5-plv8'
|
20
|
-
].freeze
|
21
|
-
|
22
|
-
def install_tasks
|
23
|
-
namespace :proxes do
|
24
|
-
task :config do
|
25
|
-
cli = HighLine.new
|
26
|
-
|
27
|
-
config = File.file?(CONFIG_PATH) ? YAML.load_file(CONFIG_PATH) : {}
|
28
|
-
config['install_folder'] = cli.ask('To which folder should we install', String) do |q|
|
29
|
-
q.default = config['install_folder'] || File.expand_path('~/proxes')
|
30
|
-
end.to_s
|
31
|
-
|
32
|
-
config['proxes_hostname'] = cli.ask('ProxES Hostname?', String).to_s
|
33
|
-
|
34
|
-
# Port Config
|
35
|
-
config['web_port'] = cli.ask('HTTP Port? [80]', Integer) { |q| q.default = config['web_port'] || 80 }.to_i
|
36
|
-
config['https_port'] = cli.ask('SSL Port? [443]', Integer) { |q| q.default = config['https_port'] || 443 }.to_i
|
37
|
-
|
38
|
-
# Certificate
|
39
|
-
config['ssl_key_path'] = cli.ask('Path to SSL key', String) { |q| q.default = config['ssl_key_path'] }.to_s
|
40
|
-
config['ssl_cert_path'] = cli.ask('Path to SSL certificate', String) { |q| q.default = config['ssl_cert_path'] }.to_s
|
41
|
-
|
42
|
-
config['redis_url'] = cli.ask('Redis URL', String) do |q|
|
43
|
-
q.default = config['redis_url'] || 'redis://localhost:6379'
|
44
|
-
end.to_s
|
45
|
-
config['elasticsearch_url'] = cli.ask('Elasticsearch URL', String) do |q|
|
46
|
-
q.default = config['elasticsearch_url'] || 'http://localhost:9200'
|
47
|
-
end.to_s
|
48
|
-
|
49
|
-
# Database Setup
|
50
|
-
config['db_name'] = cli.ask('Database Name', String) { |q| q.default = 'proxes' }.to_s
|
51
|
-
config['db_username'] = cli.ask('Database Username', String) { |q| q.default = 'proxes' }.to_s
|
52
|
-
config['db_password'] = cli.ask('Database Password', String).to_s
|
53
|
-
config['database_url'] = cli.ask('Database URL', String) do |q|
|
54
|
-
q.default = config['database_url'] || "postgres://#{config['db_username']}:#{config['db_password']}@localhost:5432/#{config['db_name']}"
|
55
|
-
end.to_s
|
56
|
-
|
57
|
-
File.open(CONFIG_PATH, 'w') { |f| f.write config.to_yaml }
|
58
|
-
end
|
59
|
-
|
60
|
-
task :setup_redhat do
|
61
|
-
cli = HighLine.new
|
62
|
-
config = YAML.load_file(CONFIG_PATH)
|
63
|
-
# Redis
|
64
|
-
if cli.ask('Install Redis Server? (y/n)') { |q| q.in = ['y', 'n']; q.default = ENV['REDIS_URL'].nil? ? 'y' : 'n' } == 'y'
|
65
|
-
system 'sudo yum install epel-release'
|
66
|
-
system 'sudo yum update'
|
67
|
-
system 'sudo yum install -y redis'
|
68
|
-
system 'sudo systemctl start redis'
|
69
|
-
system 'sudo systemctl enable redis'
|
70
|
-
end
|
71
|
-
|
72
|
-
# Postgres
|
73
|
-
if cli.ask('Install PostgreSQL Server? (y/n)') { |q| q.in = ['y', 'n']; q.default = ENV['REDIS_URL'].nil? ? 'y' : 'n'} == 'y'
|
74
|
-
system 'sudo yum install -y postgresql-server postgresql-contrib'
|
75
|
-
end
|
76
|
-
|
77
|
-
if cli.ask('Setup the PostgreSQL User & DB? (y/n)') { |q| q.in = ['y', 'n']; q.default = 'y'} == 'y'
|
78
|
-
system "sudo -u postgres createuser #{config['db_username']}"
|
79
|
-
system "sudo -u postgres createdb -O #{config['db_username']} #{config['db_name']}"
|
80
|
-
system "sudo -u postgres psql -c \"alter user #{config['db_username']} with encrypted password '#{config['db_password']}';\""
|
81
|
-
system "sudo -u postgres psql -c \"grant all privileges on database #{config['db_name']} to #{config['db_username']};\""
|
82
|
-
end
|
83
|
-
|
84
|
-
# Certs
|
85
|
-
if cli.ask('Get a cert through Lets Encrypt? (y/n)') { |q| q.in = ['y', 'n']; q.default = 'y'} == 'y'
|
86
|
-
system 'sudo yum install epel-release'
|
87
|
-
system 'sudo apt-get update'
|
88
|
-
system 'sudo apt-get install -y certbot'
|
89
|
-
system "sudo certbot -n certonly --standalone -d #{config['proxes_hostname']}"
|
90
|
-
config['ssl_key_path'] = "/etc/letsencrypt/live/#{config['proxes_hostname']}/privkey.pem"
|
91
|
-
config['ssl_cert_path'] = "/etc/letsencrypt/live/#{config['proxes_hostname']}/fullchain.pem"
|
92
|
-
end
|
93
|
-
|
94
|
-
# TODO: Write the .env file
|
95
|
-
|
96
|
-
File.open(CONFIG_PATH, 'w') { |f| f.write config.to_yaml }
|
97
|
-
end
|
98
|
-
|
99
|
-
task :setup_debian do
|
100
|
-
cli = HighLine.new
|
101
|
-
config = YAML.load_file(CONFIG_PATH)
|
102
|
-
|
103
|
-
# Redis
|
104
|
-
if cli.ask('Install Redis Server? (y/n)') { |q| q.in = ['y', 'n']; q.default = ENV['REDIS_URL'].nil? ? 'y' : 'n' } == 'y'
|
105
|
-
system 'sudo apt-get install -y redis-server'
|
106
|
-
end
|
107
|
-
|
108
|
-
# Postgres
|
109
|
-
if cli.ask('Install PostgreSQL Server? (y/n)') { |q| q.in = ['y', 'n']; q.default = ENV['REDIS_URL'].nil? ? 'y' : 'n'} == 'y'
|
110
|
-
system 'sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ACCC4CF8'
|
111
|
-
unless File.file? '/etc/apt/sources.list.d/pgdg.list'
|
112
|
-
system 'sudo sh -c \'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list\''
|
113
|
-
end
|
114
|
-
system 'sudo apt-get update'
|
115
|
-
system 'sudo apt-get install -y ' + POSTGRES_PACKAGES.join(' ')
|
116
|
-
end
|
117
|
-
|
118
|
-
if cli.ask('Setup the PostgreSQL User & DB? (y/n)') { |q| q.in = ['y', 'n']; q.default = 'y'} == 'y'
|
119
|
-
system "sudo -u postgres createuser #{config['db_username']}"
|
120
|
-
system "sudo -u postgres createdb -O #{config['db_username']} #{config['db_name']}"
|
121
|
-
system "sudo -u postgres psql -c \"alter user #{config['db_username']} with encrypted password '#{config['db_password']}';\""
|
122
|
-
system "sudo -u postgres psql -c \"grant all privileges on database #{config['db_name']} to #{config['db_username']};\""
|
123
|
-
end
|
124
|
-
|
125
|
-
# Certs
|
126
|
-
if cli.ask('Get a cert through Lets Encrypt? (y/n)') { |q| q.in = ['y', 'n']; q.default = 'y'} == 'y'
|
127
|
-
system 'sudo add-apt-repository ppa:certbot/certbot'
|
128
|
-
system 'sudo apt-get update'
|
129
|
-
system 'sudo apt-get install -y certbot'
|
130
|
-
system "sudo certbot -n certonly --standalone -d #{config['proxes_hostname']}"
|
131
|
-
config['ssl_key_path'] = "/etc/letsencrypt/live/#{config['proxes_hostname']}/privkey.pem"
|
132
|
-
config['ssl_cert_path'] = "/etc/letsencrypt/live/#{config['proxes_hostname']}/fullchain.pem"
|
133
|
-
end
|
134
|
-
|
135
|
-
# TODO: Write the .env file
|
136
|
-
|
137
|
-
File.open(CONFIG_PATH, 'w') { |f| f.write config.to_yaml }
|
138
|
-
end
|
139
|
-
|
140
|
-
desc 'Generate the needed tokens'
|
141
|
-
task :generate_tokens do
|
142
|
-
puts 'Generating the ProxES tokens'
|
143
|
-
require 'securerandom'
|
144
|
-
File.write('.session_secret', SecureRandom.random_bytes(40)) unless File.file?('.session_secret')
|
145
|
-
File.write('.token_secret', SecureRandom.random_bytes(40)) unless File.file?('.token_secret')
|
146
|
-
end
|
147
|
-
|
148
|
-
desc 'Seed the ProxES database'
|
149
|
-
task :seed do
|
150
|
-
puts 'Seeding the ProxES database'
|
151
|
-
require 'proxes/seed'
|
152
|
-
end
|
153
|
-
|
154
|
-
desc 'Prepare ProxES migrations'
|
155
|
-
task :prep do
|
156
|
-
puts 'Prepare the ProxES folders'
|
157
|
-
Dir.mkdir 'pids' unless File.exist?('pids')
|
158
|
-
|
159
|
-
puts 'Preparing the ProxES public folder'
|
160
|
-
::ProxES::Container.public.each do |path|
|
161
|
-
FileUtils.cp_r "#{path}/.", 'public'
|
162
|
-
end
|
163
|
-
|
164
|
-
puts 'Preparing the ProxES migrations folder'
|
165
|
-
Dir.mkdir 'migrations' unless File.exist?('migrations')
|
166
|
-
::ProxES::Container.migrations.each do |path|
|
167
|
-
FileUtils.cp_r "#{path}/.", 'migrations'
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
desc 'Migrate ProxES database to latest version'
|
172
|
-
task :migrate do
|
173
|
-
puts 'Running the ProxES migrations'
|
174
|
-
Rake::Task['proxes:migrate:up'].invoke
|
175
|
-
end
|
176
|
-
|
177
|
-
namespace :migrate do
|
178
|
-
require_relative './db' if ENV['DATABASE_URL']
|
179
|
-
folder = 'migrations'
|
180
|
-
|
181
|
-
desc 'Check if the migration is current'
|
182
|
-
task :check do
|
183
|
-
require 'sequel'
|
184
|
-
puts 'Running ProxES Migrations check'
|
185
|
-
::Sequel.extension :migration
|
186
|
-
::Sequel::Migrator.check_current(::DB, folder)
|
187
|
-
end
|
188
|
-
|
189
|
-
desc 'Migrate ProxES database to latest version'
|
190
|
-
task :up do
|
191
|
-
require 'sequel'
|
192
|
-
puts 'Running ProxES Migrations up'
|
193
|
-
::Sequel.extension :migration
|
194
|
-
::Sequel::Migrator.apply(::DB, folder)
|
195
|
-
end
|
196
|
-
|
197
|
-
desc 'Roll back the ProxES database'
|
198
|
-
task :down do
|
199
|
-
require 'sequel'
|
200
|
-
puts 'Running ProxES Migrations down'
|
201
|
-
::Sequel.extension :migration
|
202
|
-
::Sequel::Migrator.apply(::DB, folder, 0)
|
203
|
-
end
|
204
|
-
|
205
|
-
desc 'Reset the ProxES database'
|
206
|
-
task :bounce do
|
207
|
-
require 'sequel'
|
208
|
-
puts 'Running ProxES Migrations bounce'
|
209
|
-
::Sequel.extension :migration
|
210
|
-
::Sequel::Migrator.apply(::DB, folder, 0)
|
211
|
-
::Sequel::Migrator.apply(::DB, folder)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
ProxES::Tasks.new.install_tasks
|
data/lib/proxes/seed.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'logger'
|
4
|
-
require 'yaml'
|
5
|
-
require 'singleton'
|
6
|
-
require 'active_support/inflector'
|
7
|
-
require 'proxes/loggers/elasticsearch'
|
8
|
-
|
9
|
-
# ProxES::Services::Logger.instance
|
10
|
-
|
11
|
-
module ProxES
|
12
|
-
module Services
|
13
|
-
class Logger
|
14
|
-
include Singleton
|
15
|
-
|
16
|
-
CONFIG = './config/logger.yml'.freeze
|
17
|
-
attr_reader :loggers
|
18
|
-
|
19
|
-
def initialize
|
20
|
-
@loggers = []
|
21
|
-
config.each do |values|
|
22
|
-
klass = values['class'].constantize
|
23
|
-
opts = values['options'] || nil
|
24
|
-
logger = klass.new(opts)
|
25
|
-
if values['level']
|
26
|
-
logger.level = klass.const_get(values['level'].to_sym)
|
27
|
-
end
|
28
|
-
@loggers << logger
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def method_missing(method, *args, &block)
|
33
|
-
loggers.each { |logger| logger.send(method, *args, &block) }
|
34
|
-
end
|
35
|
-
|
36
|
-
def respond_to_missing?(method, _include_private = false)
|
37
|
-
loggers.any? { |logger| logger.respond_to?(method) }
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def config
|
43
|
-
@config ||= File.exist?(CONFIG) ? YAML.load_file(CONFIG) : default
|
44
|
-
end
|
45
|
-
|
46
|
-
def default
|
47
|
-
[{ 'name' => 'default', 'class' => 'Logger' }]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
data/views/404.haml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
%h2 4 oh 4
|